Skip to content

Commit

Permalink
--wip-- [skip ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
avzz-19 committed Jan 9, 2025
1 parent 5cf783e commit 161d678
Show file tree
Hide file tree
Showing 7 changed files with 144 additions and 37 deletions.
6 changes: 5 additions & 1 deletion app/components/file-details/dynamic-scan/header/index.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@
</AkStack>
{{/if}}
{{#if item.inProgress}}
<AkLoader @size={{15}} @thickness={{6}} />
<AkLoader
data-test-fileDetails-dynamicScan-inProgress-loader
@size={{15}}
@thickness={{6}}
/>
{{/if}}
</:badge>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
local-class='schedule-automation-toggle'
>
<AkFormControlLabel
@label='Enable Automation'
@label={{t 'enableAutomation'}}
@labelTypographyFontWeight='medium'
@disabled={{this.toggleDsAutomationPreference.isRunning}}
data-test-genSettings-dynScanAutoSettings-dynamicscanAutomationToggleLabel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ export default class ProjectSettingsGeneralSettingsDyanmicscanAutomationSettings
return this.args.profileId;
}

get tAppiumScheduledAutomationSuccessOn() {
return this.intl.t('appiumScheduledAutomationSuccessOn');
get tScheduledAutomationSuccessOn() {
return this.intl.t('scheduledAutomationSuccessOn');
}

get tAppiumScheduledAutomationSuccessOff() {
return this.intl.t('appiumScheduledAutomationSuccessOff');
get tScheduledAutomationSuccessOff() {
return this.intl.t('scheduledAutomationSuccessOff');
}

get tSomethingWentWrong() {
Expand Down Expand Up @@ -77,8 +77,8 @@ export default class ProjectSettingsGeneralSettingsDyanmicscanAutomationSettings
await this.automationPreference?.save();

const successMsg = enabled
? this.tAppiumScheduledAutomationSuccessOn
: this.tAppiumScheduledAutomationSuccessOff;
? this.tScheduledAutomationSuccessOn
: this.tScheduledAutomationSuccessOff;

this.notify.success(successMsg);
} catch (err) {
Expand Down
99 changes: 94 additions & 5 deletions tests/acceptance/file-details/dynamic-scan-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -452,18 +452,86 @@ module('Acceptance | file-details/dynamic-scan', function (hooks) {
} else {
assert.dom('[data-test-NovncRfb-canvasContainer]').doesNotExist();
}

if (isManualMode) {
assert.dom('[data-test-vncViewer-automatedNote]').doesNotExist();
assert.dom('[data-test-vncViewer-scanTriggeredNote]').doesNotExist();

if (dynamicscan.isStarting) {
// Check manual note
assert
.dom('[data-test-vncViewer-manualScanNote]')
.exists()
.hasText(`${t('note')} - ${t('dynamicScanText')}`);
} else if (dynamicscan.isReadyOrRunning) {
assert.dom('[data-test-vncViewer-manualScanNote]').doesNotExist();
assert.dom('[data-test-fileDetails-dynamicScan-expiry]').exists();
}
} else {
if (
dynamicscan.isStartingOrShuttingInProgress ||
dynamicscan.isReadyOrRunning
) {
assert.dom('[data-test-vncViewer-manualScanNote]').doesNotExist();

assert
.dom('[data-test-fileDetails-dynamicScan-expiry]')
.doesNotExist();

// Check automated note
assert.dom('[data-test-vncViewer-automatedNote]').exists();

assert
.dom('[data-test-vncViewer-scanTriggeredAutomaticallyText]')
.exists()
.hasText(t('scanTriggeredAutomatically'));

if (dynamicscan.isInqueue) {
assert
.dom('[data-test-vncViewer-automatedNote]')
.hasText(`${t('note')} - ${t('automatedScanQueuedVncNote')}`);
} else {
assert
.dom('[data-test-vncViewer-automatedNote]')
.hasText(`${t('note')} - ${t('automatedScanRunningVncNote')}`);
}
}
}
}
);

test.each(
'it should start & stop/cancel dynamic scan',
[
{ mode: 'manual', cancelInBetween: false, expectedAssertions: 41 },
{ mode: 'manual', cancelInBetween: true, expectedAssertions: 35 },
{ mode: 'automated', cancelInBetween: false, expectedAssertions: 45 },
{ mode: 'automated', cancelInBetween: true, expectedAssertions: 38 },
{
mode: 'manual',
cancelInBetween: false,
expectedAssertions: 41,
startedBy: false,
},
{
mode: 'manual',
cancelInBetween: true,
expectedAssertions: 35,
startedBy: false,
},
{
mode: 'automated',
cancelInBetween: false,
expectedAssertions: 48,
startedBy: true,
},
{
mode: 'automated',
cancelInBetween: true,
expectedAssertions: 41,
startedBy: false,
},
],
async function (assert, { mode, cancelInBetween, expectedAssertions }) {
async function (
assert,
{ mode, cancelInBetween, expectedAssertions, startedBy }
) {
assert.expect(expectedAssertions);

const createDynamicscan = () =>
Expand All @@ -472,6 +540,7 @@ module('Acceptance | file-details/dynamic-scan', function (hooks) {
mode: ENUMS.DYNAMIC_MODE[mode.toUpperCase()],
status: ENUMS.DYNAMIC_SCAN_STATUS.NOT_STARTED,
ended_on: null,
started_by_user: startedBy ? this.profile.id : null,
});

const availableDevices = this.server.createList(
Expand Down Expand Up @@ -555,6 +624,10 @@ module('Acceptance | file-details/dynamic-scan', function (hooks) {
enabled: false,
}));

const user = this.server.create('user', {
id: this.profile.id,
});

await visit(`/dashboard/file/${this.file.id}/dynamic-scan/${mode}`);

assert
Expand Down Expand Up @@ -648,9 +721,25 @@ module('Acceptance | file-details/dynamic-scan', function (hooks) {

assert.dom('[data-test-vncViewer-scanTriggeredNote]').exists();

if (startedBy) {
assert
.dom('[data-test-vncViewer-scanStartedByText]')
.exists()
.hasText(`${t('scanStartedBy')} ${user.username}`);
} else {
assert
.dom('[data-test-vncViewer-scanTriggeredAutomaticallyText]')
.exists()
.hasText(t('scanTriggeredAutomatically'));
}

assert
.dom('[data-test-vncViewer-automatedNote]')
.hasText(`${t('note')} - ${t('automatedScanQueuedVncNote')}`);

assert
.dom('[data-test-fileDetails-dynamicScan-inProgress-loader]')
.exists();
} else {
assert.dom('[data-test-vncViewer-automatedNote]').doesNotExist();
assert.dom('[data-test-vncViewer-scanTriggeredNote]').doesNotExist();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ const selectors = {
dynScanAutoRoot:
'[data-test-projectSettings-genSettings-dynScanAutoSettings-root]',
dynScanAutoToggle:
'[data-test-genSettings-dynScanAutoSettings-dynamicscanModeToggle] [data-test-toggle-input]',
'[data-test-genSettings-dynScanAutoSettings-dynamicscanAutomationToggle] [data-test-toggle-input]',
dynamicscanModeToggleLabel:
'[data-test-genSettings-dynScanAutoSettings-dynamicscanModeToggleLabel]',
'[data-test-genSettings-dynScanAutoSettings-dynamicscanAutomationToggleLabel]',
};

module(
Expand All @@ -45,8 +45,26 @@ module(
return schema.files.find(`${req.params.id}`)?.toJSON();
});

this.server.get('/profiles/:id/dynamicscan_mode', (schema, req) =>
schema.dynamicscanModes.find(`${req.queryParams.id}`)?.toJSON()
this.server.create('ds-automation-preference', {
dynamic_scan_automation_enabled: false,
});

this.server.get(
'/v2/projects/:projectId/scan_parameter_groups',
function (schema) {
const results = schema.scanParameterGroups.all().models;

return {
count: results.length,
next: null,
previous: null,
results,
};
}
);

this.server.get('/v2/profiles/:id/automation_preference', (schema, req) =>
schema.dsAutomationPreferences.find(`${req.queryParams.id}`)?.toJSON()
);

this.owner.register('service:notifications', NotificationsStub);
Expand All @@ -68,11 +86,6 @@ module(
});

test('it renders', async function (assert) {
this.server.create('dynamicscan-mode', {
id: 1,
dynamicscan_mode: 'Manual',
});

await render(hbs`
<ProjectSettings::GeneralSettings::DynamicscanAutomationSettings
@project={{this.project}}
Expand Down Expand Up @@ -100,13 +113,12 @@ module(
});

test('it toggles scheduled automation', async function (assert) {
this.server.put('/profiles/:id/dynamicscan_mode', (schema, req) => {
this.server.put('v2/profiles/:id/automation_preference', (_, req) => {
const reqBody = JSON.parse(req.requestBody);

this.set('dynamicscan_mode', reqBody.dynamicscan_mode);

return {
dynamicscan_mode: reqBody.dynamicscan_mode,
dynamic_scan_automation_enabled:
reqBody.dynamic_scan_automation_enabled,
id: req.params.id,
};
});
Expand All @@ -124,21 +136,23 @@ module(
assert
.dom(selectors.dynamicscanModeToggleLabel)
.exists()
.containsText(t('appiumScheduledAutomation'));
.containsText(t('enableAutomation'));

assert.dom(selectors.dynScanAutoToggle).exists().isNotChecked();

await click(selectors.dynScanAutoToggle);

assert.dom(selectors.dynScanAutoToggle).isChecked();

assert.ok(this.dynamicscan_mode, 'Automated');
const notify = this.owner.lookup('service:notifications');

assert.strictEqual(notify.successMsg, t('scheduledAutomationSuccessOn'));

await click(selectors.dynScanAutoToggle);

assert.dom(selectors.dynScanAutoToggle).isNotChecked();

assert.ok(this.dynamicscan_mode, 'Manual');
assert.strictEqual(notify.successMsg, t('scheduledAutomationSuccessOff'));
});
}
);
8 changes: 4 additions & 4 deletions translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,6 @@
"appOrS": "app(s)",
"appSwitcher": "App Switcher",
"appiumFileUploadedSuccessfully": "File Uploaded Successfully",
"appiumScheduledAutomation": "Schedule Automation",
"appiumScheduledAutomationSuccessOff": "Scheduled dynamic scan automation turned OFF",
"appiumScheduledAutomationSuccessOn": "Scheduled dynamic scan automation turned ON",
"appiumScriptInvalid": "Invalid script file. Please upload a valid Appium project",
"appiumScripts": "Appium scripts",
"appiumScriptsDescription": "As a part of our upcoming automated dynamic scan feature, we are currently supporting <strong>scheduled dynamic scans</strong> option using Appium scripts. Upload your app's Appium test scripts here as a zip file, dynamic scans would be automatically scheduled for all your future app uploads in this project.",
Expand Down Expand Up @@ -355,7 +352,7 @@
"deviceLaunching": "Launching",
"deviceNotFound": "Hard time for us to find the device",
"devicePreferences": "Device Preferences",
"devicePreferencesAutomatedDast": "Device Preferences (Automated Dast)",
"devicePreferencesAutomatedDast": "Device Preferences (Automated DAST)",
"deviceSelected": "You have successfully selected the device",
"deviceShuttingDown": "Stopping",
"deviceType": "Device Type",
Expand Down Expand Up @@ -409,6 +406,7 @@
"emptyURLFilter": "Enter host name",
"enHTMLReport": "EN HTML Report",
"enable": "Enable",
"enableAutomation": "Enable Automation",
"enableMFA": "Enable MFA",
"enableMandatoryMFADescription": "By enabling this you are mandating multi factor authentication for all users in this organization. Users who do not have MFA enabled in their user account will receive OTP via the registered email.",
"enableMandatoryMFARequirement": "For enabling mandatory MFA for organization, you need to have MFA enabled for your user account. Enable it from here:",
Expand Down Expand Up @@ -1379,6 +1377,8 @@
"scheduleDynamicscan": "Schedule Automated Dynamic Scan",
"scheduleDynamicscanDesc": "Schedule an automated dynamic scan for this file by clicking on the button below. Once scheduled, the system will use the Active Scenarios on the Project Settings page to execute the Automated DAST. It may take up to 24hrs for this to be completed.",
"scheduleDynamicscanSuccess": "Automated dynamic scan scheduled successfully",
"scheduledAutomationSuccessOff": "Dynamic Scan Automation has been turned OFF for this project",
"scheduledAutomationSuccessOn": "Dynamic Scan Automation has been scheduled for this project",
"search": "Search",
"searchUser": "Search user",
"searchProject": "Search project",
Expand Down
8 changes: 4 additions & 4 deletions translations/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,6 @@
"appOrS": "アプリ",
"appSwitcher": "App Switcher",
"appiumFileUploadedSuccessfully": "File Uploaded Successfully",
"appiumScheduledAutomation": "Schedule Automation",
"appiumScheduledAutomationSuccessOff": "Scheduled dynamic scan automation turned OFF",
"appiumScheduledAutomationSuccessOn": "Scheduled dynamic scan automation turned ON",
"appiumScriptInvalid": "Invalid script file. Please upload a valid Appium project",
"appiumScripts": "Appium scripts",
"appiumScriptsDescription": "As a part of our upcoming automated dynamic scan feature, we are currently supporting <strong>scheduled dynamic scans</strong> option using Appium scripts. Upload your app's Appium test scripts here as a zip file, dynamic scans would be automatically scheduled for all your future app uploads in this project.",
Expand Down Expand Up @@ -355,7 +352,7 @@
"deviceLaunching": "開始中",
"deviceNotFound": "デバイスが見つかりませんでした",
"devicePreferences": "デバイスの設定",
"devicePreferencesAutomatedDast": "Device Preferences (Automated Dast)",
"devicePreferencesAutomatedDast": "Device Preferences (Automated DAST)",
"deviceSelected": "デバイスを選択しました",
"deviceShuttingDown": "停止中",
"deviceType": "デバイスタイプ",
Expand Down Expand Up @@ -409,6 +406,7 @@
"emptyURLFilter": "Enter host name",
"enHTMLReport": "EN HTML Report",
"enable": "Enable",
"enableAutomation": "Enable Automation",
"enableMFA": "MFAの有効化",
"enableMandatoryMFADescription": "By enabling this you are mandating multi factor authentication for all users in this organization. Users who do not have MFA enabled in their user account will receive OTP via the registered email.",
"enableMandatoryMFARequirement": "For enabling mandatory MFA for organization, you need to have MFA enabled for your user account. Enable it from here:",
Expand Down Expand Up @@ -1379,6 +1377,8 @@
"scheduleDynamicscan": "Schedule Automated Dynamic Scan",
"scheduleDynamicscanDesc": "Schedule an automated dynamic scan for this file by clicking on the button below. Once scheduled, the system will use the Active Scenarios on the Project Settings page to execute the Automated DAST. It may take up to 24hrs for this to be completed.",
"scheduleDynamicscanSuccess": "Automated dynamic scan scheduled successfully",
"scheduledAutomationSuccessOff": "Dynamic Scan Automation has been turned OFF for this project",
"scheduledAutomationSuccessOn": "Dynamic Scan Automation has been scheduled for this project",
"search": "検索",
"searchUser": "Search user",
"searchProject": "Search project",
Expand Down

0 comments on commit 161d678

Please sign in to comment.