Commit 8c4d1fb8 authored by Andrew Fontaine's avatar Andrew Fontaine

Merge branch 'revert-ba7ae3a3' into 'master'

Revert "Merge branch '246892-auto-select-dast-profile' into 'master'"

See merge request gitlab-org/gitlab!49401
parents 8662326a 7ef723e5
......@@ -30,7 +30,7 @@ import ProfileSelectorSummaryCell from './profile_selector/summary_cell.vue';
import ScannerProfileSelector from './profile_selector/scanner_profile_selector.vue';
import SiteProfileSelector from './profile_selector/site_profile_selector.vue';
const createProfilesApolloOptions = (name, field, { fetchQuery, fetchError }) => ({
const createProfilesApolloOptions = (name, { fetchQuery, fetchError }) => ({
query: fetchQuery,
variables() {
return {
......@@ -39,9 +39,6 @@ const createProfilesApolloOptions = (name, field, { fetchQuery, fetchError }) =>
},
update(data) {
const edges = data?.project?.[name]?.edges ?? [];
if (edges.length === 1) {
this[field] = edges[0].node.id;
}
return edges.map(({ node }) => node);
},
error(e) {
......@@ -69,16 +66,8 @@ export default {
},
mixins: [glFeatureFlagsMixin()],
apollo: {
scannerProfiles: createProfilesApolloOptions(
'scannerProfiles',
'selectedScannerProfileId',
SCANNER_PROFILES_QUERY,
),
siteProfiles: createProfilesApolloOptions(
'siteProfiles',
'selectedSiteProfileId',
SITE_PROFILES_QUERY,
),
scannerProfiles: createProfilesApolloOptions('scannerProfiles', SCANNER_PROFILES_QUERY),
siteProfiles: createProfilesApolloOptions('siteProfiles', SITE_PROFILES_QUERY),
},
props: {
helpPagePath: {
......@@ -115,8 +104,8 @@ export default {
return {
scannerProfiles: [],
siteProfiles: [],
selectedScannerProfileId: null,
selectedSiteProfileId: null,
selectedScannerProfile: null,
selectedSiteProfile: null,
loading: false,
errorType: null,
errors: [],
......@@ -124,16 +113,6 @@ export default {
};
},
computed: {
selectedScannerProfile() {
return this.selectedScannerProfileId
? this.scannerProfiles.find(({ id }) => id === this.selectedScannerProfileId)
: null;
},
selectedSiteProfile() {
return this.selectedSiteProfileId
? this.siteProfiles.find(({ id }) => id === this.selectedSiteProfileId)
: null;
},
errorMessage() {
return ERROR_MESSAGES[this.errorType] || null;
},
......@@ -259,37 +238,37 @@ export default {
</template>
<template v-else-if="!failedToLoadProfiles">
<scanner-profile-selector
v-model="selectedScannerProfileId"
v-model="selectedScannerProfile"
class="gl-mb-5"
:profiles="scannerProfiles"
>
<template v-if="selectedScannerProfile" #summary>
<template #summary="{ profile }">
<div class="row">
<profile-selector-summary-cell
:class="{ 'gl-text-red-500': hasProfilesConflict }"
:label="s__('DastProfiles|Scan mode')"
:value="$options.SCAN_TYPE_LABEL[selectedScannerProfile.scanType]"
:value="$options.SCAN_TYPE_LABEL[profile.scanType]"
/>
</div>
<div class="row">
<profile-selector-summary-cell
:label="s__('DastProfiles|Spider timeout')"
:value="n__('%d minute', '%d minutes', selectedScannerProfile.spiderTimeout)"
:value="n__('%d minute', '%d minutes', profile.spiderTimeout)"
/>
<profile-selector-summary-cell
:label="s__('DastProfiles|Target timeout')"
:value="n__('%d second', '%d seconds', selectedScannerProfile.targetTimeout)"
:value="n__('%d second', '%d seconds', profile.targetTimeout)"
/>
</div>
<div class="row">
<profile-selector-summary-cell
:label="s__('DastProfiles|AJAX spider')"
:value="selectedScannerProfile.useAjaxSpider ? __('On') : __('Off')"
:value="profile.useAjaxSpider ? __('On') : __('Off')"
/>
<profile-selector-summary-cell
:label="s__('DastProfiles|Debug messages')"
:value="
selectedScannerProfile.showDebugMessages
profile.showDebugMessages
? s__('DastProfiles|Show debug messages')
: s__('DastProfiles|Hide debug messages')
"
......@@ -297,17 +276,13 @@ export default {
</div>
</template>
</scanner-profile-selector>
<site-profile-selector
v-model="selectedSiteProfileId"
class="gl-mb-5"
:profiles="siteProfiles"
>
<template v-if="selectedSiteProfile" #summary>
<site-profile-selector v-model="selectedSiteProfile" class="gl-mb-5" :profiles="siteProfiles">
<template #summary="{ profile }">
<div class="row">
<profile-selector-summary-cell
:class="{ 'gl-text-red-500': hasProfilesConflict }"
:label="s__('DastProfiles|Target URL')"
:value="selectedSiteProfile.targetUrl"
:value="profile.targetUrl"
/>
</div>
</template>
......
......@@ -25,14 +25,14 @@ export default {
default: () => [],
},
value: {
type: String,
type: Object,
required: false,
default: null,
},
},
computed: {
selectedProfile() {
return this.value ? this.profiles.find(({ id }) => this.value === id) : null;
methods: {
isChecked({ id }) {
return this.value?.id === id;
},
},
};
......@@ -67,9 +67,7 @@ export default {
</template>
<gl-dropdown
:text="
selectedProfile
? selectedProfile.dropdownLabel
: s__('OnDemandScans|Select one of the existing profiles')
value ? value.dropdownLabel : s__('OnDemandScans|Select one of the existing profiles')
"
class="mw-460"
data-testid="profiles-dropdown"
......@@ -77,9 +75,9 @@ export default {
<gl-dropdown-item
v-for="profile in profiles"
:key="profile.id"
:is-checked="value === profile.id"
:is-checked="isChecked(profile)"
is-check-item
@click="$emit('input', profile.id)"
@click="$emit('input', profile)"
>
{{ profile.profileName }}
</gl-dropdown-item>
......@@ -89,7 +87,7 @@ export default {
data-testid="selected-profile-summary"
class="gl-mt-6 gl-pt-6 gl-border-t-solid gl-border-gray-100 gl-border-t-1"
>
<slot name="summary"></slot>
<slot name="summary" :profile="value"></slot>
</div>
</gl-form-group>
<template v-else>
......
......@@ -57,8 +57,8 @@ export default {
)
}}</template>
<template #new-profile>{{ s__('OnDemandScans|Create a new scanner profile') }}</template>
<template #summary>
<slot name="summary"></slot>
<template #summary="{ profile }">
<slot name="summary" :profile="profile"></slot>
</template>
</profile-selector>
</template>
......@@ -60,8 +60,8 @@ export default {
)
}}</template>
<template #new-profile>{{ s__('OnDemandScans|Create a new site profile') }}</template>
<template #summary>
<slot name="summary"></slot>
<template #summary="{ profile }">
<slot name="summary" :profile="profile"></slot>
</template>
</profile-selector>
</template>
---
title: 'On-demand scans: automatically select DAST profile when only one is available'
merge_request: 48940
author:
type: changed
import { GlForm, GlSkeletonLoader } from '@gitlab/ui';
import { shallowMount, mount, createLocalVue } from '@vue/test-utils';
import { shallowMount, mount } from '@vue/test-utils';
import { merge } from 'lodash';
import VueApollo from 'vue-apollo';
import createApolloProvider from 'helpers/mock_apollo_helper';
import OnDemandScansForm from 'ee/on_demand_scans/components/on_demand_scans_form.vue';
import ScannerProfileSelector from 'ee/on_demand_scans/components/profile_selector/scanner_profile_selector.vue';
import SiteProfileSelector from 'ee/on_demand_scans/components/profile_selector/site_profile_selector.vue';
import dastOnDemandScanCreate from 'ee/on_demand_scans/graphql/dast_on_demand_scan_create.mutation.graphql';
import dastScannerProfilesQuery from 'ee/security_configuration/dast_profiles/graphql/dast_scanner_profiles.query.graphql';
import dastSiteProfilesQuery from 'ee/security_configuration/dast_profiles/graphql/dast_site_profiles.query.graphql';
import * as responses from '../mocks/apollo_mocks';
import { scannerProfiles, siteProfiles } from '../mocks/mock_data';
import { redirectTo } from '~/lib/utils/url_utility';
import { scannerProfiles, siteProfiles } from '../mock_data';
const helpPagePath = '/application_security/dast/index#on-demand-scans';
const projectPath = 'group/project';
......@@ -27,6 +22,17 @@ const defaultProps = {
defaultBranch,
};
const defaultMocks = {
$apollo: {
mutate: jest.fn(),
queries: {
scannerProfiles: {},
siteProfiles: {},
},
addSmartQuery: jest.fn(),
},
};
const pipelineUrl = `/${projectPath}/pipelines/123`;
const [passiveScannerProfile, activeScannerProfile] = scannerProfiles;
const [nonValidatedSiteProfile, validatedSiteProfile] = siteProfiles;
......@@ -37,9 +43,7 @@ jest.mock('~/lib/utils/url_utility', () => ({
}));
describe('OnDemandScansForm', () => {
let localVue;
let subject;
let requestHandlers;
const findForm = () => subject.find(GlForm);
const findByTestId = testId => subject.find(`[data-testid="${testId}"]`);
......@@ -48,44 +52,13 @@ describe('OnDemandScansForm', () => {
const findSubmitButton = () => findByTestId('on-demand-scan-submit-button');
const setValidFormData = () => {
subject.find(ScannerProfileSelector).vm.$emit('input', passiveScannerProfile.id);
subject.find(SiteProfileSelector).vm.$emit('input', nonValidatedSiteProfile.id);
subject.find(ScannerProfileSelector).vm.$emit('input', passiveScannerProfile);
subject.find(SiteProfileSelector).vm.$emit('input', nonValidatedSiteProfile);
return subject.vm.$nextTick();
};
const submitForm = () => findForm().vm.$emit('submit', { preventDefault: () => {} });
const createMockApolloProvider = handlers => {
localVue.use(VueApollo);
requestHandlers = {
dastScannerProfiles: jest.fn().mockResolvedValue(responses.dastScannerProfiles()),
dastSiteProfiles: jest.fn().mockResolvedValue(responses.dastSiteProfiles()),
...handlers,
};
return createApolloProvider([
[dastScannerProfilesQuery, requestHandlers.dastScannerProfiles],
[dastSiteProfilesQuery, requestHandlers.dastSiteProfiles],
]);
};
const subjectMounterFactory = (mountFn = shallowMount) => (options = {}, withHandlers) => {
localVue = createLocalVue();
let defaultMocks = {
$apollo: {
mutate: jest.fn(),
queries: {
scannerProfiles: {},
siteProfiles: {},
},
addSmartQuery: jest.fn(),
},
};
let apolloProvider;
if (withHandlers) {
apolloProvider = createMockApolloProvider(withHandlers);
defaultMocks = {};
}
const subjectMounterFactory = (mountFn = shallowMount) => (options = {}) => {
subject = mountFn(
OnDemandScansForm,
merge(
......@@ -103,7 +76,7 @@ describe('OnDemandScansForm', () => {
},
},
},
{ ...options, localVue, apolloProvider },
options,
{
data() {
return { ...options.data };
......@@ -270,8 +243,8 @@ describe('OnDemandScansForm', () => {
'profiles conflict prevention',
({ description, selectedScannerProfile, selectedSiteProfile, hasConflict }) => {
const setFormData = () => {
subject.find(ScannerProfileSelector).vm.$emit('input', selectedScannerProfile.id);
subject.find(SiteProfileSelector).vm.$emit('input', selectedSiteProfile.id);
subject.find(ScannerProfileSelector).vm.$emit('input', selectedScannerProfile);
subject.find(SiteProfileSelector).vm.$emit('input', selectedSiteProfile);
return subject.vm.$nextTick();
};
......@@ -280,12 +253,7 @@ describe('OnDemandScansForm', () => {
? `warns about conflicting profiles when user selects ${description}`
: `does not report any conflict when user selects ${description}`,
async () => {
mountShallowSubject({
data: {
scannerProfiles,
siteProfiles,
},
});
mountShallowSubject();
await setFormData();
expect(findProfilesConflictAlert().exists()).toBe(hasConflict);
......@@ -301,10 +269,6 @@ describe('OnDemandScansForm', () => {
securityOnDemandScansSiteValidation: false,
},
},
data: {
scannerProfiles,
siteProfiles,
},
});
return setFormData();
});
......@@ -316,25 +280,4 @@ describe('OnDemandScansForm', () => {
});
},
);
describe.each`
profileType | query | selector | profiles
${'scanner'} | ${'dastScannerProfiles'} | ${ScannerProfileSelector} | ${scannerProfiles}
${'site'} | ${'dastSiteProfiles'} | ${SiteProfileSelector} | ${siteProfiles}
`('when there is a single $profileType profile', ({ query, selector, profiles }) => {
const [profile] = profiles;
beforeEach(() => {
mountShallowSubject(
{},
{
[query]: jest.fn().mockResolvedValue(responses[query]([profile])),
},
);
});
it('automatically selects the only available profile', () => {
expect(subject.find(selector).attributes('value')).toBe(profile.id);
});
});
});
......@@ -4,7 +4,7 @@ exports[`OnDemandScansScannerProfileSelector renders properly with profiles 1`]
<div
class="gl-card"
data-foo="bar"
value="gid://gitlab/DastScannerProfile/1"
value="[object Object]"
>
<div
class="gl-card-header"
......
......@@ -4,7 +4,7 @@ exports[`OnDemandScansSiteProfileSelector renders properly with profiles 1`] = `
<div
class="gl-card"
data-foo="bar"
value="gid://gitlab/DastSiteProfile/1"
value="[object Object]"
>
<div
class="gl-card-header"
......
......@@ -2,7 +2,7 @@ import { GlDropdownItem } from '@gitlab/ui';
import { mount } from '@vue/test-utils';
import { merge } from 'lodash';
import OnDemandScansProfileSelector from 'ee/on_demand_scans/components/profile_selector/profile_selector.vue';
import { scannerProfiles } from '../../mocks/mock_data';
import { scannerProfiles } from '../../mock_data';
describe('OnDemandScansProfileSelector', () => {
let wrapper;
......@@ -41,10 +41,12 @@ describe('OnDemandScansProfileSelector', () => {
slots: {
title: 'Section title',
label: 'Use existing scanner profile',
summary: `<div>Profile's summary</div>`,
'no-profiles': 'No profile yet',
'new-profile': 'Create a new profile',
},
scopedSlots: {
summary: "<div>{{ props.profile.profileName }}'s summary</div>",
},
},
options,
),
......@@ -103,7 +105,7 @@ describe('OnDemandScansProfileSelector', () => {
it('when a profile is selected, input event is emitted', async () => {
await selectFirstProfile();
expect(wrapper.emitted('input')).toEqual([[scannerProfiles[0].id]]);
expect(wrapper.emitted('input')).toEqual([[scannerProfiles[0]]]);
});
it('shows dropdown items for each profile', () => {
......@@ -128,7 +130,7 @@ describe('OnDemandScansProfileSelector', () => {
createFullComponent({
propsData: {
profiles: scannerProfiles,
value: selectedProfile.id,
value: selectedProfile,
},
});
});
......@@ -137,7 +139,7 @@ describe('OnDemandScansProfileSelector', () => {
const summary = findSelectedProfileSummary();
expect(summary.exists()).toBe(true);
expect(summary.text()).toContain(`Profile's summary`);
expect(summary.text()).toContain(`${scannerProfiles[0].profileName}'s summary`);
});
it('displays item as checked', () => {
......
......@@ -2,7 +2,7 @@ import { mount, shallowMount } from '@vue/test-utils';
import { merge } from 'lodash';
import ProfileSelector from 'ee/on_demand_scans/components/profile_selector/profile_selector.vue';
import OnDemandScansScannerProfileSelector from 'ee/on_demand_scans/components/profile_selector/scanner_profile_selector.vue';
import { scannerProfiles } from '../../mocks/mock_data';
import { scannerProfiles } from '../../mock_data';
const TEST_LIBRARY_PATH = '/test/scanner/profiles/library/path';
const TEST_NEW_PATH = '/test/new/scanner/profile/path';
......@@ -31,8 +31,8 @@ describe('OnDemandScansScannerProfileSelector', () => {
newScannerProfilePath: TEST_NEW_PATH,
glFeatures: { securityOnDemandScansSiteValidation: true },
},
slots: {
summary: `<div>${profiles[0].profileName}'s summary</div>`,
scopedSlots: {
summary: '<div slot-scope="{ profile }">{{ profile.profileName }}\'s summary</div>',
},
},
options,
......@@ -50,7 +50,7 @@ describe('OnDemandScansScannerProfileSelector', () => {
it('renders properly with profiles', () => {
createFullComponent({
propsData: { profiles, value: profiles[0].id },
propsData: { profiles, value: profiles[0] },
});
expect(wrapper.element).toMatchSnapshot();
......
......@@ -2,7 +2,7 @@ import { mount, shallowMount } from '@vue/test-utils';
import { merge } from 'lodash';
import ProfileSelector from 'ee/on_demand_scans/components/profile_selector/profile_selector.vue';
import OnDemandScansSiteProfileSelector from 'ee/on_demand_scans/components/profile_selector/site_profile_selector.vue';
import { siteProfiles } from '../../mocks/mock_data';
import { siteProfiles } from '../../mock_data';
const TEST_LIBRARY_PATH = '/test/site/profiles/library/path';
const TEST_NEW_PATH = '/test/new/site/profile/path';
......@@ -34,8 +34,8 @@ describe('OnDemandScansSiteProfileSelector', () => {
newSiteProfilePath: TEST_NEW_PATH,
glFeatures: { securityOnDemandScansSiteValidation: true },
},
slots: {
summary: `<div>${profiles[0].profileName}'s summary</div>`,
scopedSlots: {
summary: '<div slot-scope="{ profile }">{{ profile.profileName }}\'s summary</div>',
},
},
options,
......@@ -53,7 +53,7 @@ describe('OnDemandScansSiteProfileSelector', () => {
it('renders properly with profiles', () => {
createFullComponent({
propsData: { profiles, value: profiles[0].id },
propsData: { profiles, value: profiles[0] },
});
expect(wrapper.element).toMatchSnapshot();
......
......@@ -7,7 +7,6 @@ export const scannerProfiles = [
scanType: 'PASSIVE',
useAjaxSpider: false,
showDebugMessages: false,
editPath: '/scanner_profile/edit/1',
},
{
id: 'gid://gitlab/DastScannerProfile/2',
......@@ -17,7 +16,6 @@ export const scannerProfiles = [
scanType: 'ACTIVE',
useAjaxSpider: true,
showDebugMessages: true,
editPath: '/scanner_profile/edit/2',
},
];
......@@ -26,14 +24,12 @@ export const siteProfiles = [
id: 'gid://gitlab/DastSiteProfile/1',
profileName: 'Site profile #1',
targetUrl: 'https://foo.com',
editPath: '/site_profiles/edit/1',
validationStatus: 'PENDING_VALIDATION',
},
{
id: 'gid://gitlab/DastSiteProfile/2',
profileName: 'Site profile #2',
targetUrl: 'https://bar.com',
editPath: '/site_profiles/edit/2',
validationStatus: 'PASSED_VALIDATION',
},
];
import { scannerProfiles, siteProfiles } from './mock_data';
const defaults = {
pageInfo: {
hasNextPage: false,
hasPreviousPage: false,
startCursor: null,
endCursor: null,
},
};
export const dastScannerProfiles = (profiles = scannerProfiles) => ({
data: {
project: {
scannerProfiles: {
...defaults,
edges: profiles.map(profile => ({
cursor: '',
node: profile,
})),
},
},
},
});
export const dastSiteProfiles = (profiles = siteProfiles) => ({
data: {
project: {
siteProfiles: {
...defaults,
edges: profiles.map(profile => ({
cursor: '',
node: profile,
})),
},
},
},
});
......@@ -6,7 +6,7 @@ import DastScannerProfileForm from 'ee/security_configuration/dast_scanner_profi
import { SCAN_TYPE } from 'ee/security_configuration/dast_scanner_profiles/constants';
import dastScannerProfileCreateMutation from 'ee/security_configuration/dast_scanner_profiles/graphql/dast_scanner_profile_create.mutation.graphql';
import dastScannerProfileUpdateMutation from 'ee/security_configuration/dast_scanner_profiles/graphql/dast_scanner_profile_update.mutation.graphql';
import { scannerProfiles } from 'ee_jest/on_demand_scans/mocks/mock_data';
import { scannerProfiles } from 'ee_jest/on_demand_scans/mock_data';
import { TEST_HOST } from 'helpers/test_constants';
import { redirectTo } from '~/lib/utils/url_utility';
......
......@@ -7,7 +7,7 @@ import VueApollo from 'vue-apollo';
import DastSiteProfileForm from 'ee/security_configuration/dast_site_profiles_form/components/dast_site_profile_form.vue';
import dastSiteProfileCreateMutation from 'ee/security_configuration/dast_site_profiles_form/graphql/dast_site_profile_create.mutation.graphql';
import dastSiteProfileUpdateMutation from 'ee/security_configuration/dast_site_profiles_form/graphql/dast_site_profile_update.mutation.graphql';
import { siteProfiles } from 'ee_jest/on_demand_scans/mocks/mock_data';
import { siteProfiles } from 'ee_jest/on_demand_scans/mock_data';
import * as responses from 'ee_jest/security_configuration/dast_site_profiles_form/mock_data/apollo_mock';
import { TEST_HOST } from 'helpers/test_constants';
import waitForPromises from 'jest/helpers/wait_for_promises';
......
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