Commit d90f39af authored by Mark Florian's avatar Mark Florian

Merge branch 'djadmin-dast-profile-populator' into 'master'

Populate On-demand Scan profiles using query params

See merge request gitlab-org/gitlab!50749
parents 20021be5 c923769b
...@@ -22,7 +22,8 @@ import { s__ } from '~/locale'; ...@@ -22,7 +22,8 @@ import { s__ } from '~/locale';
import validation from '~/vue_shared/directives/validation'; import validation from '~/vue_shared/directives/validation';
import * as Sentry from '~/sentry/wrapper'; import * as Sentry from '~/sentry/wrapper';
import glFeatureFlagsMixin from '~/vue_shared/mixins/gl_feature_flags_mixin'; import glFeatureFlagsMixin from '~/vue_shared/mixins/gl_feature_flags_mixin';
import { redirectTo } from '~/lib/utils/url_utility'; import { redirectTo, queryToObject } from '~/lib/utils/url_utility';
import { convertToGraphQLId } from '~/graphql_shared/utils';
import { import {
ERROR_RUN_SCAN, ERROR_RUN_SCAN,
ERROR_FETCH_SCANNER_PROFILES, ERROR_FETCH_SCANNER_PROFILES,
...@@ -31,6 +32,8 @@ import { ...@@ -31,6 +32,8 @@ import {
SCANNER_PROFILES_QUERY, SCANNER_PROFILES_QUERY,
SITE_PROFILES_QUERY, SITE_PROFILES_QUERY,
SITE_PROFILES_EXTENDED_QUERY, SITE_PROFILES_EXTENDED_QUERY,
TYPE_SITE_PROFILE,
TYPE_SCANNER_PROFILE,
} from '../settings'; } from '../settings';
import dastScanCreateMutation from '../graphql/dast_scan_create.mutation.graphql'; import dastScanCreateMutation from '../graphql/dast_scan_create.mutation.graphql';
import dastScanUpdateMutation from '../graphql/dast_scan_update.mutation.graphql'; import dastScanUpdateMutation from '../graphql/dast_scan_update.mutation.graphql';
...@@ -219,6 +222,16 @@ export default { ...@@ -219,6 +222,16 @@ export default {
return isFormInvalid || (loading && loading !== saveScanBtnId); return isFormInvalid || (loading && loading !== saveScanBtnId);
}, },
}, },
created() {
const params = queryToObject(window.location.search);
this.selectedSiteProfileId = params.site_profile_id
? convertToGraphQLId(TYPE_SITE_PROFILE, params.site_profile_id)
: this.selectedSiteProfileId;
this.selectedScannerProfileId = params.scanner_profile_id
? convertToGraphQLId(TYPE_SCANNER_PROFILE, params.scanner_profile_id)
: this.selectedScannerProfileId;
},
methods: { methods: {
onSubmit({ runAfterCreate = true, button = this.$options.saveAndRunScanBtnId } = {}) { onSubmit({ runAfterCreate = true, button = this.$options.saveAndRunScanBtnId } = {}) {
if (this.glFeatures.dastSavedScans) { if (this.glFeatures.dastSavedScans) {
......
...@@ -33,3 +33,6 @@ export const SITE_PROFILES_EXTENDED_QUERY = { ...@@ -33,3 +33,6 @@ export const SITE_PROFILES_EXTENDED_QUERY = {
...SITE_PROFILES_QUERY, ...SITE_PROFILES_QUERY,
fetchQuery: dastSiteProfilesExtendedQuery, fetchQuery: dastSiteProfilesExtendedQuery,
}; };
export const TYPE_SITE_PROFILE = 'DastSiteProfile';
export const TYPE_SCANNER_PROFILE = 'DastScannerProfile';
...@@ -14,8 +14,9 @@ import dastSiteProfilesQuery from 'ee/security_configuration/dast_profiles/graph ...@@ -14,8 +14,9 @@ import dastSiteProfilesQuery from 'ee/security_configuration/dast_profiles/graph
import { stubComponent } from 'helpers/stub_component'; import { stubComponent } from 'helpers/stub_component';
import * as responses from '../mocks/apollo_mocks'; import * as responses from '../mocks/apollo_mocks';
import { scannerProfiles, siteProfiles } from '../mocks/mock_data'; import { scannerProfiles, siteProfiles } from '../mocks/mock_data';
import { redirectTo } from '~/lib/utils/url_utility'; import { redirectTo, setUrlParams } from '~/lib/utils/url_utility';
const URL_HOST = 'https://localhost/';
const helpPagePath = '/application_security/dast/index#on-demand-scans'; const helpPagePath = '/application_security/dast/index#on-demand-scans';
const projectPath = 'group/project'; const projectPath = 'group/project';
const defaultBranch = 'master'; const defaultBranch = 'master';
...@@ -44,6 +45,8 @@ const dastScan = { ...@@ -44,6 +45,8 @@ const dastScan = {
jest.mock('~/lib/utils/url_utility', () => ({ jest.mock('~/lib/utils/url_utility', () => ({
isAbsolute: jest.requireActual('~/lib/utils/url_utility').isAbsolute, isAbsolute: jest.requireActual('~/lib/utils/url_utility').isAbsolute,
queryToObject: jest.requireActual('~/lib/utils/url_utility').queryToObject,
setUrlParams: jest.requireActual('~/lib/utils/url_utility').setUrlParams,
redirectTo: jest.fn(), redirectTo: jest.fn(),
})); }));
...@@ -504,4 +507,37 @@ describe('OnDemandScansForm', () => { ...@@ -504,4 +507,37 @@ describe('OnDemandScansForm', () => {
expect(summary).toMatch(authEnabledProfile.auth.passwordField); expect(summary).toMatch(authEnabledProfile.auth.passwordField);
}); });
}); });
describe('populate profiles from query params', () => {
const [siteProfile] = siteProfiles;
const [scannerProfile] = scannerProfiles;
it('scanner profile', () => {
global.jsdom.reconfigure({
url: setUrlParams({ scanner_profile_id: 1 }, URL_HOST),
});
mountShallowSubject();
expect(subject.find(ScannerProfileSelector).attributes('value')).toBe(scannerProfile.id);
});
it('site profile', () => {
global.jsdom.reconfigure({
url: setUrlParams({ site_profile_id: 1 }, URL_HOST),
});
mountShallowSubject();
expect(subject.find(SiteProfileSelector).attributes('value')).toBe(siteProfile.id);
});
it('both scanner & site profile', () => {
global.jsdom.reconfigure({
url: setUrlParams({ site_profile_id: 1, scanner_profile_id: 1 }, URL_HOST),
});
mountShallowSubject();
expect(subject.find(SiteProfileSelector).attributes('value')).toBe(siteProfile.id);
expect(subject.find(ScannerProfileSelector).attributes('value')).toBe(scannerProfile.id);
});
});
}); });
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment