Skip to content

Commit

Permalink
fix failing e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Yibaebi committed Oct 7, 2024
1 parent 2fb83a9 commit 7063e26
Show file tree
Hide file tree
Showing 14 changed files with 126 additions and 78 deletions.
10 changes: 0 additions & 10 deletions app/components/file-details/api-scan/captured-apis/index.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,6 @@
</AkStack>
{{else}}
<div local-class='captured-api-list-container'>
<AkTypography
data-test-fileDetails-apiScan-capturedApi-desc
@color='textSecondary'
class='p-2'
>
{{t 'capturedApiListDesc'}}
</AkTypography>

<AkDivider @color='dark' />

<AkPaginationProvider
@results={{this.capturedApiList}}
@onItemPerPageChange={{this.handleItemPerPageChange}}
Expand Down
9 changes: 8 additions & 1 deletion app/components/file-details/dynamic-scan/manual/index.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
@alignItems='center'
@justifyContent='center'
class='my-2'
data-test-cy='manualDast-headerContainer'
>
<AkStack
local-class='manual-dast-header'
Expand All @@ -20,12 +21,17 @@
{{t 'realDevice'}}
</AkTypography>

<AkStack @spacing='1' @alignItems='center'>
<AkStack
@spacing='1'
@alignItems='center'
data-test-cy='manualDast-statusChipAndScanCTAContainer'
>
{{#if this.showStatusChip}}
<FileDetails::DynamicScan::StatusChip
@file={{@file}}
@dynamicScan={{this.dynamicScan}}
/>

{{/if}}

{{#if this.showActionButton}}
Expand All @@ -39,6 +45,7 @@

{{#if (and @file.isReady (not this.isFullscreenView))}}
<AkIconButton
data-test-cy='manualDast-fullscreenBtn'
data-test-fileDetails-dynamicScan-manualDast-fullscreenBtn
{{on 'click' this.toggleFullscreenView}}
>
Expand Down
2 changes: 1 addition & 1 deletion app/components/file-details/scan-actions/index.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<FileDetails::ScanActions::StaticScan @file={{@file}} />
</div>

<div local-class='scan-status-card'>
<div local-class='scan-status-card' data-test-cy='dynamicScan-infoContainer'>
<FileDetails::ScanActions::DynamicScan @file={{@file}} />
</div>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
@alignItems='center'
@flexWrap='wrap'
class='p-2'
data-test-cy='staticScan-infoContainer'
>
<AkTypography @variant='h5' data-test-fileDetailScanActions-staticScanTitle>
{{t 'sast'}}
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified cypress/snapshots/base/dynamic-scan.spec.ts/dvia_open_menu.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 10 additions & 5 deletions cypress/support/Actions/common/DynamicScanActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,7 @@ export default class DynamicScanActions {
// check completed static scan info
cy.findByTestId('staticScan-infoContainer', DEFAULT_ASSERT_OPTS).within(
() => {
cy.findByText(cyTranslate('staticScan'), DEFAULT_ASSERT_OPTS).should(
'exist'
);
cy.findByText(cyTranslate('sast'), DEFAULT_ASSERT_OPTS).should('exist');

cy.findByText(cyTranslate('completed'), DEFAULT_ASSERT_OPTS).should(
'exist'
Expand Down Expand Up @@ -146,7 +144,7 @@ export default class DynamicScanActions {

// wait for page to fully reload
cy.document()
.findByTestId('dynamicScan-infoContainer', {
.findByTestId('manualDast-statusChipAndScanCTAContainer', {
timeout: DYNAMIC_SCAN_STATUS_TIMEOUT,
})
.findByRole('button', {
Expand All @@ -156,6 +154,13 @@ export default class DynamicScanActions {
.should('exist')
.as(DYNAMIC_SCAN_STOP_BTN_ALIAS);

// check different status of dynamic scan status chip while starting
cy.findByTestId('manualDast-statusChipAndScanCTAContainer').within(() => {
cy.findByTestId('manualDast-fullscreenBtn', DEFAULT_ASSERT_OPTS)
.should('exist')
.click();
});

// wait for device screen to render
cy.wait(3000);
}
Expand Down Expand Up @@ -287,7 +292,7 @@ export default class DynamicScanActions {
// restart same interaction
this.interactWithApp(interactions, appInfo, actionIndex, retries - 1);
} else {
expect(result.error).to.be.undefined;
expect(result.error, 'Result Error').to.be.undefined;

expect(result.percentage).to.be.below(appInfo.errorThreshold ?? 0.05);

Expand Down
2 changes: 1 addition & 1 deletion cypress/support/Actions/common/UploadAppActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ export default class UploadAppActions {
(el) => {
const assertOpts = { container: el, timeout: 30000 };

cy.findByText(cyTranslate('staticScan'), assertOpts).should('exist');
cy.findByText(cyTranslate('sast'), assertOpts).should('exist');

// Check if static scan has completed or is in progress
if (file.is_static_done) {
Expand Down
139 changes: 99 additions & 40 deletions cypress/tests/dynamic-scan.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const dynamicScanActions = new DynamicScanActions();
// User credentials
const username = Cypress.env('TEST_USERNAME');
const password = Cypress.env('TEST_PASSWORD');
const API_HOST = Cypress.env('API_HOST');

const MFVA_INTERACTIONS: AppInteraction[] = [
{
Expand Down Expand Up @@ -135,6 +136,8 @@ Cypress.on('uncaught:exception', () => {

describe('Dynamic Scan', () => {
beforeEach(() => {
cy.viewport(1450, 962);

// Hide websocket and analyses logs
networkActions.hideNetworkLogsFor({ ...API_ROUTES.websockets });

Expand Down Expand Up @@ -180,6 +183,9 @@ describe('Dynamic Scan', () => {
`it tests dynamic scan for an ${app.type} file: ${app.fileId}`,
{ scrollBehavior: false, retries: { runMode: 1 } },
() => {
cy.wrap(app.fileId).as('DYNAMIC_SCAN_FILE_ID');
cy.wrap(false).as('testCompleted');

// intercept file request
cy.intercept(`${API_ROUTES.file.route}/${app.fileId}`).as(
'currentFileRequest'
Expand Down Expand Up @@ -219,23 +225,55 @@ describe('Dynamic Scan', () => {
).within(() => {
const assertOpts = { ...DEFAULT_ASSERT_OPTS };

cy.findByText(cyTranslate('dynamicScan'), assertOpts).should(
'exist'
);
cy.findByText(cyTranslate('dast'), assertOpts).should('exist');

if (file.is_dynamic_done) {
cy.findByRole('button', {
name: cyTranslate('completed'),
}).should('exist');
cy.findByText(
file.is_dynamic_done
? cyTranslate('completed')
: cyTranslate('notStarted')
).should('exist');

cy.findByTestId('dynamicScan-restartBtn')
.should('exist')
.as('startRestartdynamicScanBtn');
} else {
cy.findByRole('button', { name: cyTranslate('start') })
.should('exist')
.as('startRestartdynamicScanBtn');
}
cy.findByRole('link', { name: cyTranslate('viewDetails') })
.should('exist')
.click();
});

// Check if in manual DAST page
cy.url().should('contain', '/dynamic-scan/manual');

cy.get<MirageFactoryDefProps['file']>('@currentFile').then((file) => {
// Check tabs info
cy.findByRole('link', {
name: cyTranslate('dastTabs.manualDAST'),
}).should('exist');

cy.findByRole('link', {
name: new RegExp(cyTranslate('dastTabs.dastResults'), 'i'),
}).should('exist');

cy.findByText(cyTranslate('realDevice')).should('exist');

cy.findAllByTestId('manualDast-headerContainer')
.should('exist')
.within(() => {
cy.findByText(
file.is_dynamic_done
? cyTranslate('completed')
: cyTranslate('notStarted')
).should('exist');

if (file.is_dynamic_done) {
cy.findByTestId('dynamicScan-restartBtn')
.should('exist')
.as('startRestartdynamicScanBtn');
} else {
cy.findByRole('button', {
name: cyTranslate('modalCard.dynamicScan.title'),
})
.should('exist')
.as('startRestartdynamicScanBtn');
}
});
});

// open dynamic scan modal
Expand Down Expand Up @@ -315,43 +353,64 @@ describe('Dynamic Scan', () => {
'not.exist'
);

// check different status of dynamic scan btn while stating
cy.findByTestId('dynamicScan-infoContainer').within(() => {
DynamicStatusTexts.forEach((status) => {
cy.findByRole('button', {
name: status,
timeout: DYNAMIC_SCAN_STATUS_TIMEOUT,
}).should('exist');
});
// check different status of dynamic scan status chip while starting
cy.findByTestId('manualDast-statusChipAndScanCTAContainer').within(
() => {
DynamicStatusTexts.forEach((status) => {
cy.findByText(status, {
timeout: DYNAMIC_SCAN_STATUS_TIMEOUT,
}).should('exist');
});
}
);

// when dynamic started running
cy.findByRole('button', {
name: cyTranslate('stop'),
timeout: DYNAMIC_SCAN_STATUS_TIMEOUT,
})
.should('exist')
.as(DYNAMIC_SCAN_STOP_BTN_ALIAS);
});
// when dynamic started running
cy.findByRole('button', {
name: cyTranslate('stop'),
timeout: DYNAMIC_SCAN_STATUS_TIMEOUT,
})
.should('exist')
.as(DYNAMIC_SCAN_STOP_BTN_ALIAS);

// wait for screen to load
cy.wait(5000);

cy.findByTestId('manualDast-fullscreenBtn').should('exist').click();

// trigger app interaction
app.performInteraction(app.interactions, app);

// stop dynamic scan
cy.findByRole('button', {
name: cyTranslate('stop'),
timeout: DYNAMIC_SCAN_STATUS_TIMEOUT,
})
.should('exist')
.click({ force: true });

// check status of dynamic while stopping
cy.findByTestId('manualDast-statusChipAndScanCTAContainer')
.within(() => {
cy.findByText(cyTranslate('deviceShuttingDown'), {
timeout: DYNAMIC_SCAN_STATUS_TIMEOUT,
}).should('exist');
})
.then(() => cy.wrap(true).as('testCompleted'));
});
}
)
);

afterEach(() => {
// stop dynamic scan
cy.get(`@${DYNAMIC_SCAN_STOP_BTN_ALIAS}`).click({ force: true });

// dynamic scan btn while stoping
cy.findByTestId('dynamicScan-infoContainer')
.findByRole('button', {
name: cyTranslate('deviceShuttingDown'),
})
.should('exist');
cy.get<boolean>('@testCompleted').then((testCompleted) => {
if (!testCompleted) {
cy.get('@DYNAMIC_SCAN_FILE_ID').then((fileId) =>
cy.makeAuthenticatedAPIRequest({
method: 'DELETE',
url: `${API_HOST}/api/dynamicscan/${fileId}`,
})
);
}
});
});
});
12 changes: 0 additions & 12 deletions tests/acceptance/file-details/api-scan-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,10 +201,6 @@ module('Acceptance | file-details/api-scan', function (hooks) {
.dom('[data-test-fileDetails-apiScan-tabs="api-scan-tab"]')
.hasText(t('apiScan'));

assert
.dom('[data-test-fileDetails-apiScan-capturedApi-desc]')
.hasText(t('capturedApiListDesc'));

assert
.dom('[data-test-fileDetails-apiScan-capturedApi-title]')
.hasText(t('capturedApiListTitle'));
Expand Down Expand Up @@ -296,10 +292,6 @@ module('Acceptance | file-details/api-scan', function (hooks) {
.dom('[data-test-fileDetails-apiScan-tabs="api-scan-tab"]')
.hasText(t('apiScan'));

assert
.dom('[data-test-fileDetails-apiScan-capturedApi-desc]')
.hasText(t('capturedApiListDesc'));

assert
.dom('[data-test-fileDetails-apiScan-capturedApi-title]')
.hasText(t('capturedApiListTitle'));
Expand Down Expand Up @@ -426,10 +418,6 @@ module('Acceptance | file-details/api-scan', function (hooks) {
.dom('[data-test-fileDetails-apiScan-tabs="api-scan-tab"]')
.hasText(t('apiScan'));

assert
.dom('[data-test-fileDetails-apiScan-capturedApi-desc]')
.hasText(t('capturedApiListDesc'));

assert
.dom('[data-test-fileDetails-apiScan-capturedApi-title]')
.hasText(t('capturedApiListTitle'));
Expand Down
7 changes: 3 additions & 4 deletions translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
"apiScanResults": "API Scan Results",
"apiScanResultsDesc": "Here are the data from this particular API scan.",
"apiScanInProgress": "API Scan in progress",
"apiScanProgressStatusHelper": "{status, select, completed {} other {Once the scan is completed.}} View the results in <strong>API Results Tab</strong>",
"apiScanProgressStatusHelper": "{status, select, completed {} other {Once the scan is completed.}} View the results in <strong>API Scan Results Tab</strong>",
"apiURLFilter": "API URL Filter",
"app": "app",
"appCenterPipeline": "App Center Build",
Expand Down Expand Up @@ -176,8 +176,7 @@
"capturedApiEmptyTitle": "No APIs captured during the last dynamic scan. Please try again",
"capturedApiSaveSuccessMsg": "Successfully saved the captured api status",
"capturedApiTitle": "Captured APIs",
"capturedApiListTitle": "List of API's",
"capturedApiListDesc": "Here are the view all the API's captured in the last dynamic scan.",
"capturedApiListTitle": "APIs from last Dynamic Scan",
"capturedApiSelectedTitle": "API's Selected",
"capturedApiSelectedDesc": "We will run API scan for web vulnerabilities on the selected list of requests captured during the dynamic scan.",
"capturedApiSelectedTotalCount": "({selectedCount}/{totalCount} have been selected)",
Expand Down Expand Up @@ -850,7 +849,7 @@
"scanInProgressDescription": "The file is currently being assessed by our security researchers.",
"requestSubmittedDescription": "Manual Scan for this file has been requested.",
"resultsDescription": "Here are the data from this particular Manual Scan.",
"viewResultsInTab": "View the results in <strong>Manual Results Tab</strong>"
"viewResultsInTab": "View the results in <strong>Manual Scan Results Tab</strong>"
},
"rescan": {
"title": "Restart Static Scan",
Expand Down
7 changes: 3 additions & 4 deletions translations/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
"apiScanResults": "API Scan Results",
"apiScanResultsDesc": "Here are the data from this particular API scan.",
"apiScanInProgress": "API Scan in progress",
"apiScanProgressStatusHelper": "{status, select, completed {} other {Once the scan is completed.}} View the results in <strong>API Results Tab</strong>",
"apiScanProgressStatusHelper": "{status, select, completed {} other {Once the scan is completed.}} View the results in <strong>API Scan Results Tab</strong>",
"apiURLFilter": "API URLフィルタ",
"app": "アプリ",
"appCenterPipeline": "App Center Build",
Expand Down Expand Up @@ -176,8 +176,7 @@
"capturedApiEmptyTitle": "No APIs captured during the last dynamic scan. Please try again",
"capturedApiSaveSuccessMsg": "Successfully saved the captured api status",
"capturedApiTitle": "Captured APIs",
"capturedApiListTitle": "List of API's",
"capturedApiListDesc": "Here are the view all the API's captured in the last dynamic scan.",
"capturedApiListTitle": "APIs from last Dynamic Scan",
"capturedApiSelectedTitle": "API's Selected",
"capturedApiSelectedDesc": "We will run API scan for web vulnerabilities on the selected list of requests captured during the dynamic scan.",
"capturedApiSelectedTotalCount": "({selectedCount}/{totalCount} have been selected)",
Expand Down Expand Up @@ -850,7 +849,7 @@
"scanInProgressDescription": "The file is currently being assessed by our security researchers.",
"requestSubmittedDescription": "Manual Scan for this file has been requested.",
"resultsDescription": "Here are the data from this particular Manual Scan.",
"viewResultsInTab": "View the results in <strong>Manual Results Tab</strong>"
"viewResultsInTab": "View the results in <strong>Manual Scan Results Tab</strong>"
},
"rescan": {
"title": "Restart Static Scan",
Expand Down

0 comments on commit 7063e26

Please sign in to comment.