diff --git a/ee/app/assets/javascripts/security_configuration/dast_profiles/components/dast_variables_form_group.vue b/ee/app/assets/javascripts/security_configuration/dast_profiles/components/dast_variables_form_group.vue index 713db4893f1bbc885914ab6e819a0bffbbc30002..f74cd38271a57460e0a6c77b8d51c434fd6ff770 100644 --- a/ee/app/assets/javascripts/security_configuration/dast_profiles/components/dast_variables_form_group.vue +++ b/ee/app/assets/javascripts/security_configuration/dast_profiles/components/dast_variables_form_group.vue @@ -12,11 +12,6 @@ import { s__, __ } from '~/locale'; import { helpPagePath } from '~/helpers/help_page_helper'; import DastVariablesModal from './dast_variables_modal.vue'; -const mockVariables = [ - { variable: 'DAST_CHECKS_TO_EXCLUDE', value: '552.2,78.1' }, - { variable: 'DAST_CRAWL_GRAPH', value: 'true' }, -]; - export default { i18n: { label: s__('DastProfiles|Additional variables'), @@ -47,8 +42,7 @@ export default { }, value: { type: Array, - required: false, - default: () => mockVariables, + required: true, }, }, data() { diff --git a/ee/app/assets/javascripts/security_configuration/dast_profiles/dast_scanner_profiles/components/dast_scanner_profile_form.vue b/ee/app/assets/javascripts/security_configuration/dast_profiles/dast_scanner_profiles/components/dast_scanner_profile_form.vue index 5fe862700f1d33281906abc866914b88ee3ca7a4..04627d2476a092d542525f28b437e3d0c1699168 100644 --- a/ee/app/assets/javascripts/security_configuration/dast_profiles/dast_scanner_profiles/components/dast_scanner_profile_form.vue +++ b/ee/app/assets/javascripts/security_configuration/dast_profiles/dast_scanner_profiles/components/dast_scanner_profile_form.vue @@ -14,7 +14,6 @@ import { s__ } from '~/locale'; import glFeatureFlagsMixin from '~/vue_shared/mixins/gl_feature_flags_mixin'; import BaseDastProfileForm from '../../components/base_dast_profile_form.vue'; import dastProfileFormMixin from '../../dast_profile_form_mixin'; -import DastVariablesFormGroup from '../../components/dast_variables_form_group.vue'; import { SCAN_TYPE, SCAN_TYPE_OPTIONS } from '../constants'; import dastScannerProfileCreateMutation from '../graphql/dast_scanner_profile_create.mutation.graphql'; import dastScannerProfileUpdateMutation from '../graphql/dast_scanner_profile_update.mutation.graphql'; @@ -31,7 +30,6 @@ export default { name: 'DastScannerProfileForm', components: { BaseDastProfileForm, - DastVariablesFormGroup, GlFormCheckbox, GlFormGroup, GlFormInput, @@ -269,11 +267,6 @@ export default { }}</gl-form-checkbox> </gl-form-group> </div> - - <dast-variables-form-group - v-if="glFeatures.dastUiAdditionalVariables" - class="gl-mb-3 gl-mt-4" - /> </gl-form-group> </base-dast-profile-form> </template> diff --git a/ee/app/assets/javascripts/security_configuration/dast_profiles/dast_site_profiles/components/dast_site_profile_form.vue b/ee/app/assets/javascripts/security_configuration/dast_profiles/dast_site_profiles/components/dast_site_profile_form.vue index 13d8cb30b1f6a2dc7ed01a8467135770794639d6..1941674c20729ffc61f766fb86d77d6d3d6a7169 100644 --- a/ee/app/assets/javascripts/security_configuration/dast_profiles/dast_site_profiles/components/dast_site_profile_form.vue +++ b/ee/app/assets/javascripts/security_configuration/dast_profiles/dast_site_profiles/components/dast_site_profile_form.vue @@ -103,6 +103,7 @@ export default { targetType = TARGET_TYPES.WEBSITE.value, scanMethod = null, scanFilePath = '', + optionalVariables = [], } = this.profile; const form = { @@ -124,6 +125,11 @@ export default { targetType: initFormField({ value: targetType, skipValidation: true }), scanMethod: initFormField({ value: scanMethod, skipValidation: true }), scanFilePath: initFormField({ value: scanFilePath, skipValidation: true }), + optionalVariables: initFormField({ + value: optionalVariables, + required: false, + skipValidation: true, + }), }, }; @@ -201,8 +207,15 @@ export default { return this.$options.DAST_BROWSER_AVAILABLE_VARIABLES_PATH; }, mutationVariables() { - const { profileName, targetUrl, targetType, requestHeaders, scanMethod, scanFilePath } = - serializeFormObject(this.form.fields); + const { + profileName, + targetUrl, + targetType, + requestHeaders, + scanMethod, + scanFilePath, + optionalVariables, + } = serializeFormObject(this.form.fields); return { ...(this.isEdit ? { id: this.profile.id } : { fullPath: this.projectFullPath }), @@ -215,6 +228,7 @@ export default { requestHeaders, }), ...(this.isTargetAPI && { scanMethod, scanFilePath }), + ...(this.glFeatures.dastUiAdditionalVariables && { optionalVariables }), }; }, showWarningTextForTargetUrl() { @@ -456,6 +470,10 @@ export default { :stacked="stacked" /> - <dast-variables-form-group v-if="glFeatures.dastUiAdditionalVariables" class="gl-mb-6" /> + <dast-variables-form-group + v-if="glFeatures.dastUiAdditionalVariables" + v-model="form.fields.optionalVariables.value" + class="gl-mb-6" + /> </base-dast-profile-form> </template> diff --git a/ee/spec/frontend/security_configuration/dast_profiles/components/dast_variables_form_group_spec.js b/ee/spec/frontend/security_configuration/dast_profiles/components/dast_variables_form_group_spec.js index 81e3e9bbc9d1cd2713e4ec469e3340ca1581e110..80de279c62f2092d8a24224e0954dca3dc552a89 100644 --- a/ee/spec/frontend/security_configuration/dast_profiles/components/dast_variables_form_group_spec.js +++ b/ee/spec/frontend/security_configuration/dast_profiles/components/dast_variables_form_group_spec.js @@ -11,6 +11,7 @@ import DastVariablesFormGroup from 'ee/security_configuration/dast_profiles/comp import { helpPagePath } from '~/helpers/help_page_helper'; import DastVariablesModal from 'ee/security_configuration/dast_profiles/components/dast_variables_modal.vue'; import { stubComponent } from 'helpers/stub_component'; +import { mockVariables } from '../mocks/mock_data'; describe('DastVariablesFormGroup', () => { let wrapper; @@ -21,6 +22,7 @@ describe('DastVariablesFormGroup', () => { const createComponent = (props = {}) => { wrapper = shallowMountExtended(DastVariablesFormGroup, { propsData: { + value: mockVariables, ...props, }, stubs: { diff --git a/ee/spec/frontend/security_configuration/dast_profiles/dast_scanner_profiles_form/components/dast_scanner_profiles_form_spec.js b/ee/spec/frontend/security_configuration/dast_profiles/dast_scanner_profiles_form/components/dast_scanner_profiles_form_spec.js index 53d2f03a6a9a77b645e5390b8704128726e1d5dc..449f015fbaf55c2e5610ef127ee557faae70d4cd 100644 --- a/ee/spec/frontend/security_configuration/dast_profiles/dast_scanner_profiles_form/components/dast_scanner_profiles_form_spec.js +++ b/ee/spec/frontend/security_configuration/dast_profiles/dast_scanner_profiles_form/components/dast_scanner_profiles_form_spec.js @@ -1,7 +1,6 @@ import { GlForm } from '@gitlab/ui'; import { within } from '@testing-library/dom'; import merge from 'lodash/merge'; -import DastVariablesFormGroup from 'ee/security_configuration/dast_profiles/components/dast_variables_form_group.vue'; import BaseDastProfileForm from 'ee/security_configuration/dast_profiles/components/base_dast_profile_form.vue'; import DastScannerProfileForm from 'ee/security_configuration/dast_profiles/dast_scanner_profiles/components/dast_scanner_profile_form.vue'; import { SCAN_TYPE } from 'ee/security_configuration/dast_profiles/dast_scanner_profiles/constants'; @@ -40,7 +39,6 @@ describe('DastScannerProfileForm', () => { const findSpiderTimeoutInput = () => wrapper.findByTestId('spider-timeout-input'); const findTargetTimeoutInput = () => wrapper.findByTestId('target-timeout-input'); const findScanType = () => wrapper.findByTestId('scan-type-option'); - const findDastVariablesFormGroup = () => wrapper.findComponent(DastVariablesFormGroup); const setFieldValue = async (field, value) => { await field.setValue(value); @@ -199,25 +197,4 @@ describe('DastScannerProfileForm', () => { expect(findProfileNameInput().attributes('disabled')).toBeDefined(); }); }); - - it('does not render DastVariablesFormGroup', () => { - createShallowComponent(); - expect(findDastVariablesFormGroup().exists()).toBe(false); - }); - - describe('DastVariablesFormGroup', () => { - beforeEach(() => { - createShallowComponent({ - provide: { - glFeatures: { - dastUiAdditionalVariables: true, - }, - }, - }); - }); - - it('renders DastVariablesFormGroup when feature flag is enabled', () => { - expect(findDastVariablesFormGroup().exists()).toBe(true); - }); - }); }); diff --git a/ee/spec/frontend/security_configuration/dast_profiles/dast_site_profiles/components/dast_site_profile_form_spec.js b/ee/spec/frontend/security_configuration/dast_profiles/dast_site_profiles/components/dast_site_profile_form_spec.js index 2a151abeaa0e1a9aadcc26076f3b485235d587d8..c8538232f5084d4db6c38ccfbd8d27ac537a0239 100644 --- a/ee/spec/frontend/security_configuration/dast_profiles/dast_site_profiles/components/dast_site_profile_form_spec.js +++ b/ee/spec/frontend/security_configuration/dast_profiles/dast_site_profiles/components/dast_site_profile_form_spec.js @@ -10,7 +10,10 @@ import DastSiteAuthSection from 'ee/security_configuration/dast_profiles/dast_si import DastSiteProfileForm from 'ee/security_configuration/dast_profiles/dast_site_profiles/components/dast_site_profile_form.vue'; import dastSiteProfileCreateMutation from 'ee/security_configuration/dast_profiles/dast_site_profiles/graphql/dast_site_profile_create.mutation.graphql'; import dastSiteProfileUpdateMutation from 'ee/security_configuration/dast_profiles/dast_site_profiles/graphql/dast_site_profile_update.mutation.graphql'; -import { policySiteProfiles } from 'ee_jest/security_configuration/dast_profiles/mocks/mock_data'; +import { + policySiteProfiles, + mockVariables, +} from 'ee_jest/security_configuration/dast_profiles/mocks/mock_data'; import resolvers from 'ee/vue_shared/security_configuration/graphql/resolvers/resolvers'; import { typePolicies } from 'ee/vue_shared/security_configuration/graphql/provider'; import { TEST_HOST } from 'helpers/test_constants'; @@ -421,8 +424,15 @@ describe('DastSiteProfileForm', () => { }); describe('DastVariablesFormGroup', () => { + const optionalVariables = mockVariables; beforeEach(() => { createShallowComponent({ + propsData: { + profile: { + ...siteProfileWithSecrets, + optionalVariables, + }, + }, provide: { glFeatures: { dastUiAdditionalVariables: true, @@ -434,5 +444,14 @@ describe('DastSiteProfileForm', () => { it('renders DastVariablesFormGroup when feature flag is enabled', () => { expect(findDastVariablesFormGroup().exists()).toBe(true); }); + + it('passes correct props to base component', () => { + const baseDastProfileForm = findBaseDastProfileForm(); + expect(baseDastProfileForm.props('mutationVariables')).toEqual( + expect.objectContaining({ + optionalVariables, + }), + ); + }); }); }); diff --git a/ee/spec/frontend/security_configuration/dast_profiles/mocks/mock_data.js b/ee/spec/frontend/security_configuration/dast_profiles/mocks/mock_data.js index 7a43440d0499369277b5d54ffb9e826f6eb20051..a143fb2137275a4a345a72b4327944cb59ab59b1 100644 --- a/ee/spec/frontend/security_configuration/dast_profiles/mocks/mock_data.js +++ b/ee/spec/frontend/security_configuration/dast_profiles/mocks/mock_data.js @@ -38,3 +38,8 @@ export const mockSharedData = { resetAndClose: false, __typename: 'SharedData', }; + +export const mockVariables = [ + { variable: 'DAST_CHECKS_TO_EXCLUDE', value: '552.2,78.1' }, + { variable: 'DAST_CRAWL_GRAPH', value: 'true' }, +];