-
Notifications
You must be signed in to change notification settings - Fork 5
feat(scan): add ability to run broken access control test with required options #270
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
feat(scan): add ability to run broken access control test with required options #270
Conversation
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is the file name plural? It seems the main entry is not collection.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We will add more configurable tests in the future. BAC is not the only one test with options.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Neither BrokenAccessControlTest nor BrokenAccessControlOptions are not the main entry in this file. The only entry is Test, not even Tests. So, the file should correspond to that.
| mockedCi, | ||
| mockedConfiguration | ||
| ) | ||
| reset<ApiClient | Configuration>(mockedApiClient, mockedConfiguration) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now the tests is gonna behave incorrectly, CI mock is not being reset.
| mappedTests: string[], | ||
| testMetadata: Record<string, unknown> | ||
| ) { | ||
| if (!test.options?.auth) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lets TS enforce correctness instead of runtime checks
| typeof auth !== 'string' && | ||
| (!Array.isArray(auth) || auth.length !== 2) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
| continue; | ||
| } | ||
|
|
||
| if (test.name === 'broken_access_control') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This check is technically redundant today, compiler knows the only single test with options
| if (!config.tests) { | ||
| return { ...config }; | ||
| } | ||
|
|
||
| const { mappedTests, testMetadata } = this.mapTests(config.tests); | ||
| const { tests: originalTests, ...restConfig } = config; | ||
|
|
||
| if (Object.keys(testMetadata).length > 0) { | ||
| const result: Record<string, unknown> = { | ||
| ...restConfig, | ||
| tests: mappedTests, | ||
| testMetadata | ||
| }; | ||
|
|
||
| return result; | ||
| } | ||
|
|
||
| return { ...config }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The intent is unclear from both the name and implementation. Rename the method to reflect its role and avoid imperative style.
| if (!config.tests) { | |
| return { ...config }; | |
| } | |
| const { mappedTests, testMetadata } = this.mapTests(config.tests); | |
| const { tests: originalTests, ...restConfig } = config; | |
| if (Object.keys(testMetadata).length > 0) { | |
| const result: Record<string, unknown> = { | |
| ...restConfig, | |
| tests: mappedTests, | |
| testMetadata | |
| }; | |
| return result; | |
| } | |
| return { ...config }; | |
| const mapped = config.tests.map(test => this.mapTest(test)); | |
| const tests = mapped.map(t => t.name); | |
| const testMetadata = mapped.reduce<TestMetadata | undefined>( | |
| (acc, { metadata }) => | |
| metadata | |
| ? { ...acc, ...metadata } | |
| : acc, | |
| undefined | |
| ); | |
| return { | |
| ...config, | |
| tests, | |
| ...(testMetadata && { testMetadata }), | |
| }; |
| expect(result).toEqual({ id }); | ||
| }); | ||
|
|
||
| it('should throw error when broken_access_control test has no auth option', async () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This and tests below are no longer relevant due to https://github.com/NeuraLegion/sectester-js/pull/270/changes#r2692255661
| } | ||
|
|
||
| if (seenTestConfigurations.has(testName) || simpleTests.has(testName)) { | ||
| throw new Error(`Duplicate test configuration found: ${testName}`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Error messages should include CTA
| throw new Error(`Duplicate test configuration found: ${testName}`); | |
| throw new Error(`Please remove a duplicate for the ${testName} test`); |
No description provided.