Skip to content

Commit

Permalink
Merge pull request #1532 from appknox/api-url-filters-new
Browse files Browse the repository at this point in the history
implement new api changes for API capture filters
  • Loading branch information
Yibaebi authored Feb 18, 2025
2 parents a554ee9 + e4879f9 commit ab90d7f
Show file tree
Hide file tree
Showing 20 changed files with 141 additions and 136 deletions.
30 changes: 16 additions & 14 deletions app/components/api-filter/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export default class ApiFilterComponent extends Component<ApiFilterSignature> {

@tracked newUrlFilter = '';
@tracked deletedURL = '';
@tracked updatedURLFilters = '';
@tracked updatedURLFilters: string[] = [];
@tracked showRemoveURLConfirmBox = false;
@tracked apiScanOptions?: ApiScanOptionsModel;

Expand All @@ -60,7 +60,7 @@ export default class ApiFilterComponent extends Component<ApiFilterSignature> {
}

get apiUrlFilters() {
return (this.apiScanOptions?.apiUrlFilterItems || []).map((url) => ({
return (this.apiScanOptions?.dsApiCaptureFilters || []).map((url) => ({
url,
}));
}
Expand All @@ -85,16 +85,18 @@ export default class ApiFilterComponent extends Component<ApiFilterSignature> {

@action
confirmCallback() {
const splittedURLs = this.apiScanOptions?.apiUrlFilters.split(',');
const currentURLs = this.apiScanOptions?.dsApiCaptureFilters;

if (splittedURLs) {
const index = splittedURLs.indexOf(this.deletedURL);
if (currentURLs) {
const index = currentURLs.indexOf(this.deletedURL);

splittedURLs.splice(index, 1);

this.updatedURLFilters = splittedURLs.join(',');
if (index !== -1) {
this.updatedURLFilters = currentURLs.filter(
(it) => it !== this.deletedURL
);

this.saveApiUrlFilter.perform();
this.saveApiUrlFilter.perform();
}
}
}

Expand All @@ -107,7 +109,7 @@ export default class ApiFilterComponent extends Component<ApiFilterSignature> {
].join('/');

const data = {
api_url_filters: this.updatedURLFilters,
ds_api_capture_filters: this.updatedURLFilters,
};

triggerAnalytics(
Expand All @@ -122,7 +124,7 @@ export default class ApiFilterComponent extends Component<ApiFilterSignature> {
if (!this.isDestroyed) {
this.closeRemoveURLConfirmBox();

this.apiScanOptions?.set('apiUrlFilters', this.updatedURLFilters);
this.apiScanOptions?.set('dsApiCaptureFilters', this.updatedURLFilters);

this.newUrlFilter = '';
}
Expand All @@ -149,12 +151,12 @@ export default class ApiFilterComponent extends Component<ApiFilterSignature> {
}
}

const apiUrlFilters = this.apiScanOptions?.apiUrlFilters;
const apiUrlFilters = this.apiScanOptions?.dsApiCaptureFilters;

const combinedURLS =
apiUrlFilters && !isEmpty(apiUrlFilters)
? apiUrlFilters.concat(',', this.newUrlFilter)
: this.newUrlFilter;
? [...apiUrlFilters, this.newUrlFilter]
: [this.newUrlFilter];

this.updatedURLFilters = combinedURLS;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,20 @@
<AkTypography>
{{@subText}}
</AkTypography>

<AkStack @spacing='1' @alignItems='flex-end'>
<AkLink
@color='primary'
@underline='always'
@route={{@link}}
@model={{@projectId}}
target='_blank'
rel='noopener noreferrer'
data-test-fileDetails-dynamicScanDrawer-settingsPageRedirectLink
>
{{@linkText}}
</AkLink>

<AkIcon @iconName='open-in-new' @size='small' @color='primary' />
</AkStack>
</AkStack>
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ export interface FileDetailsDynamicScanActionDrawerAutomatedDastEmptyListStateSi
Args: {
headerText: string;
subText: string;
projectId?: string;
link?: string;
linkText?: string;
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@
'modalCard.dynamicScan.emptyActiveScenariosHeaderText'
}}
@subText={{t 'modalCard.dynamicScan.emptyActiveScenariosSubText'}}
@projectId={{this.projectId}}
@link='authenticated.dashboard.project.settings.dast-automation'
@linkText={{t 'modalCard.dynamicScan.goToDastAutomationSettings'}}
data-test-fileDetails-dynamicScanDrawer-automatedDast-scenariosEmptyContainer
/>

Expand Down Expand Up @@ -196,6 +199,9 @@
<FileDetails::DynamicScan::Action::Drawer::AutomatedDast::EmptyListState
@headerText={{t 'modalCard.dynamicScan.emptyAPIListHeaderText'}}
@subText={{t 'modalCard.dynamicScan.emptyAPIListSubText'}}
@projectId={{this.projectId}}
@link='authenticated.dashboard.project.settings'
@linkText={{t 'modalCard.dynamicScan.goToGeneralSettings'}}
data-test-fileDetails-dynamicScanDrawer-automatedDast-apiURLFiltersEmptyContainer
/>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,12 @@ export default class FileDetailsDynamicScanDrawerAutomatedDastComponent extends
return this.file.profile.get('id');
}

get projectId() {
return this.file.project.get('id');
}

get apiUrlFilters() {
return (this.apiScanOptions?.apiUrlFilterItems || []).map((url) => ({
return (this.apiScanOptions?.dsApiCaptureFilters || []).map((url) => ({
url,
}));
}
Expand Down
33 changes: 9 additions & 24 deletions app/components/file-details/dynamic-scan/action/drawer/index.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -82,30 +82,15 @@
</:default>
</AkButton>

{{#if @isAutomatedScan}}
<AkButton
@variant='outlined'
@color='neutral'
@tag='a'
href='/dashboard/project/{{this.projectId}}/settings/dast-automation'
target='_blank'
rel='noopener noreferrer'
data-test-fileDetails-dynamicScanDrawer-settingsPageRedirectBtn
>
{{t 'modalCard.dynamicScan.goToGeneralSettings'}}
</AkButton>

{{else}}
<AkButton
@variant='outlined'
@color='neutral'
{{on 'click' @onClose}}
@disabled={{this.startDynamicScan.isRunning}}
data-test-fileDetails-dynamicScanDrawer-cancelBtn
>
{{t 'cancel'}}
</AkButton>
{{/if}}
<AkButton
@variant='outlined'
@color='neutral'
{{on 'click' @onClose}}
@disabled={{this.startDynamicScan.isRunning}}
data-test-fileDetails-dynamicScanDrawer-cancelBtn
>
{{t 'cancel'}}
</AkButton>
</AkStack>
</AkStack>
</AkDrawer>
10 changes: 3 additions & 7 deletions app/models/api-scan-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,11 @@ const inflector = Inflector.inflector;
inflector.irregular('api-scan-options', 'api-scan-options');

export default class ApiScanOptionsModel extends Model {
@attr('string')
declare apiUrlFilters: string;

get apiUrlFilterItems() {
return isEmpty(this.apiUrlFilters) ? [] : this.apiUrlFilters.split(',');
}
@attr
declare dsApiCaptureFilters: string[];

get hasApiUrlFilters() {
return !isEmpty(this.apiUrlFilterItems);
return !isEmpty(this.dsApiCaptureFilters);
}
}

Expand Down
16 changes: 0 additions & 16 deletions app/serializers/api-scan-options.js

This file was deleted.

6 changes: 4 additions & 2 deletions mirage/factories/api-scan-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { Factory } from 'miragejs';
import { faker } from '@faker-js/faker';

export default Factory.extend({
api_url_filters: () =>
[faker.internet.domainName(), faker.internet.domainName()].join(','),
ds_api_capture_filters: () => [
faker.internet.domainName(),
faker.internet.domainName(),
],
});
10 changes: 0 additions & 10 deletions mirage/factories/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,6 @@ export const PROJECT_FACTORY_DEF = {
return 'mobile';
}
},

api_url_filters() {
const desc = [];

for (let i = 0; i < 5; i++) {
desc.push(faker.internet.domainName().split(' ').join(' -> '));
}

return desc.join(',');
},
};

export default Base.extend(PROJECT_FACTORY_DEF);
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ module('Acceptance | projects redirect', function (hooks) {

this.server.get('/profiles/:id/api_scan_options', (_, req) => ({
id: req.params.id,
api_url_filters: '',
ds_api_capture_filters: [],
}));

this.server.get(
Expand Down
2 changes: 1 addition & 1 deletion tests/acceptance/file-compare-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ module('Acceptance | file compare', function (hooks) {
});

this.server.get('/profiles/:id/api_scan_options', (_, req) => {
return { api_url_filters: '', id: req.params.id };
return { ds_api_capture_filters: [], id: req.params.id };
});

this.server.get('/organizations/:id/jira_projects', () => {
Expand Down
21 changes: 4 additions & 17 deletions tests/acceptance/file-details/dynamic-scan-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -520,13 +520,13 @@ module('Acceptance | file-details/dynamic-scan', function (hooks) {
{
mode: 'automated',
// cancelInBetween: false, For now stop while running is not supported
expectedAssertions: 46,
expectedAssertions: 43,
startedBy: true,
},
{
mode: 'automated',
cancelInBetween: true,
expectedAssertions: 41,
expectedAssertions: 38,
startedBy: false,
},
],
Expand Down Expand Up @@ -619,7 +619,7 @@ module('Acceptance | file-details/dynamic-scan', function (hooks) {

this.server.get('/profiles/:id/api_scan_options', () => ({
id: '1',
api_url_filters: '',
ds_api_capture_filters: [],
}));

this.server.get('/profiles/:id/proxy_settings', () => ({
Expand Down Expand Up @@ -684,19 +684,6 @@ module('Acceptance | file-details/dynamic-scan', function (hooks) {
.isNotDisabled()
.hasText(mode === 'manual' ? t('start') : t('scheduleAutomation'));

if (mode === 'automated') {
assert
.dom(
'[data-test-fileDetails-dynamicScanDrawer-settingsPageRedirectBtn]'
)
.hasText(t('modalCard.dynamicScan.goToGeneralSettings'))
.hasAttribute('target', '_blank')
.hasAttribute(
'href',
`/dashboard/project/${this.file.project}/settings/dast-automation`
);
}

// start dynamic scan
await click('[data-test-fileDetails-dynamicScanDrawer-startBtn]');

Expand Down Expand Up @@ -908,7 +895,7 @@ module('Acceptance | file-details/dynamic-scan', function (hooks) {

this.server.get('/profiles/:id/api_scan_options', () => ({
id: '1',
api_url_filters: '',
ds_api_capture_filters: [],
}));

this.server.get('/profiles/:id/proxy_settings', () => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ module(

this.server.get('/profiles/:id/api_scan_options', (_, req) => ({
id: req.params.id,
api_url_filters: '',
ds_api_capture_filters: [],
}));

this.server.get(
Expand Down
16 changes: 8 additions & 8 deletions tests/integration/components/api-filter-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ module('Integration | Component | api-filter', function (hooks) {

test('it renders', async function (assert) {
this.server.get('/profiles/:id/api_scan_options', (_, req) => {
return { api_url_filters: '', id: req.params.id };
return { ds_api_capture_filters: [], id: req.params.id };
});

await render(hbs`<ApiFilter @profileId={{this.profile.id}} />`);
Expand Down Expand Up @@ -63,14 +63,14 @@ module('Integration | Component | api-filter', function (hooks) {

test('it handles URL validation and addition', async function (assert) {
this.server.get('/profiles/:id/api_scan_options', (_, req) => {
return { api_url_filters: '', id: req.params.id };
return { ds_api_capture_filters: [], id: req.params.id };
});

this.server.put('/profiles/:id/api_scan_options', (schema, req) => {
const { api_url_filters } = JSON.parse(req.requestBody);
const { ds_api_capture_filters } = JSON.parse(req.requestBody);

return {
api_url_filters,
ds_api_capture_filters,
id: this.profile.id,
};
});
Expand Down Expand Up @@ -134,16 +134,16 @@ module('Integration | Component | api-filter', function (hooks) {
test('it handles URL deletion', async function (assert) {
this.server.get('/profiles/:id/api_scan_options', (_, req) => {
return {
api_url_filters: 'api1.example.com,api2.example.com',
ds_api_capture_filters: ['api1.example.com', 'api2.example.com'],
id: req.params.id,
};
});

this.server.put('/profiles/:id/api_scan_options', (schema, req) => {
const { api_url_filters } = JSON.parse(req.requestBody);
const { ds_api_capture_filters } = JSON.parse(req.requestBody);

return {
api_url_filters,
ds_api_capture_filters,
id: this.profile.id,
};
});
Expand Down Expand Up @@ -191,7 +191,7 @@ module('Integration | Component | api-filter', function (hooks) {

test('it hides description when hideDescriptionText is true', async function (assert) {
this.server.get('/profiles/:id/api_scan_options', (_, req) => {
return { api_url_filters: '', id: req.params.id };
return { ds_api_capture_filters: [], id: req.params.id };
});

await render(
Expand Down
Loading

0 comments on commit ab90d7f

Please sign in to comment.