Commit b4c4b820 authored by Illya Klymov's avatar Illya Klymov

Merge branch '288337-dast-profiles-mocks' into 'master'

Harmonize DAST profiles mocks for frontend testing

See merge request gitlab-org/gitlab!76928
parents f4b2e5a8 e482b445
This diff is collapsed.
import {
REDACTED_PASSWORD,
REDACTED_REQUEST_HEADERS,
} from 'ee/security_configuration/dast_profiles/dast_site_profiles/constants';
export const policyScannerProfile = {
id: 'gid://gitlab/DastScannerProfile/3',
profileName: 'Scanner profile #3',
spiderTimeout: 20,
targetTimeout: 150,
scanType: 'ACTIVE',
useAjaxSpider: true,
showDebugMessages: true,
editPath: '/scanner_profile/edit/3',
referencedInSecurityPolicies: ['some_policy'],
};
export const siteProfiles = [
{
id: 'gid://gitlab/DastSiteProfile/1',
profileName: 'Site profile #1',
targetUrl: 'https://foo.com',
targetType: 'WEBSITE',
normalizedTargetUrl: 'https://foo.com:443',
editPath: '/site_profiles/edit/1',
validationStatus: 'PENDING_VALIDATION',
auth: {
enabled: true,
url: 'https://foo.com/login',
usernameField: 'username',
passwordField: 'password',
username: 'admin',
password: REDACTED_PASSWORD,
},
excludedUrls: ['https://foo.com/logout', 'https://foo.com/send_mail'],
requestHeaders: REDACTED_REQUEST_HEADERS,
referencedInSecurityPolicies: [],
},
{
id: 'gid://gitlab/DastSiteProfile/2',
profileName: 'Site profile #2',
targetUrl: 'https://bar.com',
targetType: 'API',
normalizedTargetUrl: 'https://bar.com:443',
editPath: '/site_profiles/edit/2',
validationStatus: 'PASSED_VALIDATION',
auth: {
enabled: false,
url: 'https://foo.com/login',
usernameField: 'username',
passwordField: 'password',
username: 'admin',
},
excludedUrls: ['https://bar.com/logout'],
requestHeaders: REDACTED_REQUEST_HEADERS,
referencedInSecurityPolicies: [],
},
];
export const policySiteProfile = {
id: 'gid://gitlab/DastSiteProfile/6',
profileName: 'Profile 6',
targetUrl: 'http://example-6.com',
normalizedTargetUrl: 'http://example-6.com',
editPath: '/6/edit',
validationStatus: 'NONE',
auth: {
enabled: false,
},
excludedUrls: ['https://bar.com/logout'],
referencedInSecurityPolicies: ['some_policy'],
targetType: 'WEBSITE',
};
...@@ -5,8 +5,10 @@ import DastProfilesSelector from 'ee/on_demand_scans_form/components/profile_sel ...@@ -5,8 +5,10 @@ import DastProfilesSelector from 'ee/on_demand_scans_form/components/profile_sel
import ConfigurationSnippetModal from 'ee/security_configuration/components/configuration_snippet_modal.vue'; import ConfigurationSnippetModal from 'ee/security_configuration/components/configuration_snippet_modal.vue';
import { CONFIGURATION_SNIPPET_MODAL_ID } from 'ee/security_configuration/components/constants'; import { CONFIGURATION_SNIPPET_MODAL_ID } from 'ee/security_configuration/components/constants';
import ConfigurationForm from 'ee/security_configuration/dast/components/configuration_form.vue'; import ConfigurationForm from 'ee/security_configuration/dast/components/configuration_form.vue';
import { scannerProfiles } from 'ee_jest/security_configuration/dast_profiles/mocks/mock_data'; import {
import { siteProfiles } from 'ee_jest/on_demand_scans_form/mocks/mock_data'; scannerProfiles,
siteProfiles,
} from 'ee_jest/security_configuration/dast_profiles/mocks/mock_data';
import { extendedWrapper } from 'helpers/vue_test_utils_helper'; import { extendedWrapper } from 'helpers/vue_test_utils_helper';
import { CODE_SNIPPET_SOURCE_DAST } from '~/pipeline_editor/components/code_snippet_alert/constants'; import { CODE_SNIPPET_SOURCE_DAST } from '~/pipeline_editor/components/code_snippet_alert/constants';
import { DAST_HELP_PATH } from '~/security_configuration/components/constants'; import { DAST_HELP_PATH } from '~/security_configuration/components/constants';
......
...@@ -4,7 +4,7 @@ import { mount, shallowMount, createWrapper } from '@vue/test-utils'; ...@@ -4,7 +4,7 @@ import { mount, shallowMount, createWrapper } from '@vue/test-utils';
import { merge } from 'lodash'; import { merge } from 'lodash';
import DastProfilesList from 'ee/security_configuration/dast_profiles/components/dast_profiles_list.vue'; import DastProfilesList from 'ee/security_configuration/dast_profiles/components/dast_profiles_list.vue';
import { createMockDirective, getBinding } from 'helpers/vue_mock_directive'; import { createMockDirective, getBinding } from 'helpers/vue_mock_directive';
import { siteProfiles as profiles, policySiteProfile } from '../mocks/mock_data'; import { siteProfiles as profiles, policySiteProfiles } from '../mocks/mock_data';
const TEST_ERROR_MESSAGE = 'something went wrong'; const TEST_ERROR_MESSAGE = 'something went wrong';
...@@ -259,7 +259,7 @@ describe('EE - DastProfilesList', () => { ...@@ -259,7 +259,7 @@ describe('EE - DastProfilesList', () => {
describe('profile referenced in a security policy', () => { describe('profile referenced in a security policy', () => {
it('disables the delete button', () => { it('disables the delete button', () => {
createFullComponent({ propsData: { profiles: policySiteProfile } }); createFullComponent({ propsData: { profiles: policySiteProfiles } });
const disabledRow = getAllTableRows()[0]; const disabledRow = getAllTableRows()[0];
const deleteButton = getDeleteButtonWithin(disabledRow); const deleteButton = getDeleteButtonWithin(disabledRow);
expect(deleteButton.attributes('disabled')).toBe('disabled'); expect(deleteButton.attributes('disabled')).toBe('disabled');
...@@ -267,7 +267,7 @@ describe('EE - DastProfilesList', () => { ...@@ -267,7 +267,7 @@ describe('EE - DastProfilesList', () => {
}); });
it('shows the correct tooltip text', () => { it('shows the correct tooltip text', () => {
createFullComponent({ propsData: { profiles: policySiteProfile } }); createFullComponent({ propsData: { profiles: policySiteProfiles } });
expect(getBinding(getDeleteTooltip().element, 'gl-tooltip')).not.toBe(undefined); expect(getBinding(getDeleteTooltip().element, 'gl-tooltip')).not.toBe(undefined);
expect(getDeleteTooltip().attributes('title')).toBe( expect(getDeleteTooltip().attributes('title')).toBe(
'This profile is currently being used in a policy.', 'This profile is currently being used in a policy.',
......
...@@ -6,8 +6,10 @@ import DastScannerProfileForm from 'ee/security_configuration/dast_profiles/dast ...@@ -6,8 +6,10 @@ import DastScannerProfileForm from 'ee/security_configuration/dast_profiles/dast
import { SCAN_TYPE } from 'ee/security_configuration/dast_profiles/dast_scanner_profiles/constants'; import { SCAN_TYPE } from 'ee/security_configuration/dast_profiles/dast_scanner_profiles/constants';
import dastScannerProfileCreateMutation from 'ee/security_configuration/dast_profiles/dast_scanner_profiles/graphql/dast_scanner_profile_create.mutation.graphql'; import dastScannerProfileCreateMutation from 'ee/security_configuration/dast_profiles/dast_scanner_profiles/graphql/dast_scanner_profile_create.mutation.graphql';
import dastScannerProfileUpdateMutation from 'ee/security_configuration/dast_profiles/dast_scanner_profiles/graphql/dast_scanner_profile_update.mutation.graphql'; import dastScannerProfileUpdateMutation from 'ee/security_configuration/dast_profiles/dast_scanner_profiles/graphql/dast_scanner_profile_update.mutation.graphql';
import { policyScannerProfile } from 'ee_jest/on_demand_scans_form/mocks/mock_data'; import {
import { scannerProfiles } from 'ee_jest/security_configuration/dast_profiles/mocks/mock_data'; scannerProfiles,
policyScannerProfiles,
} from 'ee_jest/security_configuration/dast_profiles/mocks/mock_data';
import { TEST_HOST } from 'helpers/test_constants'; import { TEST_HOST } from 'helpers/test_constants';
import { mountExtended, shallowMountExtended } from 'helpers/vue_test_utils_helper'; import { mountExtended, shallowMountExtended } from 'helpers/vue_test_utils_helper';
...@@ -179,7 +181,7 @@ describe('DastScannerProfileForm', () => { ...@@ -179,7 +181,7 @@ describe('DastScannerProfileForm', () => {
beforeEach(() => { beforeEach(() => {
createShallowComponent({ createShallowComponent({
propsData: { propsData: {
profile: policyScannerProfile, profile: policyScannerProfiles[0],
}, },
}); });
}); });
......
import { GlForm } from '@gitlab/ui'; import { GlForm } from '@gitlab/ui';
import { within } from '@testing-library/dom'; import { within } from '@testing-library/dom';
import merge from 'lodash/merge'; import merge from 'lodash/merge';
import siteProfileWithSecrets from 'test_fixtures/security_configuration/dast_profiles/dast_site_profile_with_secrets.json';
import BaseDastProfileForm from 'ee/security_configuration/dast_profiles/components/base_dast_profile_form.vue'; import BaseDastProfileForm from 'ee/security_configuration/dast_profiles/components/base_dast_profile_form.vue';
import DastSiteAuthSection from 'ee/security_configuration/dast_profiles/dast_site_profiles/components/dast_site_auth_section.vue'; import DastSiteAuthSection from 'ee/security_configuration/dast_profiles/dast_site_profiles/components/dast_site_auth_section.vue';
import DastSiteProfileForm from 'ee/security_configuration/dast_profiles/dast_site_profiles/components/dast_site_profile_form.vue'; 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 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 dastSiteProfileUpdateMutation from 'ee/security_configuration/dast_profiles/dast_site_profiles/graphql/dast_site_profile_update.mutation.graphql';
import { siteProfiles, policySiteProfile } from 'ee_jest/on_demand_scans_form/mocks/mock_data'; import { policySiteProfiles } from 'ee_jest/security_configuration/dast_profiles/mocks/mock_data';
import { TEST_HOST } from 'helpers/test_constants'; import { TEST_HOST } from 'helpers/test_constants';
import { mountExtended, shallowMountExtended } from 'helpers/vue_test_utils_helper'; import { mountExtended, shallowMountExtended } from 'helpers/vue_test_utils_helper';
const [siteProfileOne] = siteProfiles;
const projectFullPath = 'group/project'; const projectFullPath = 'group/project';
const profilesLibraryPath = `${TEST_HOST}/${projectFullPath}/-/security/configuration/dast_scans`; const profilesLibraryPath = `${TEST_HOST}/${projectFullPath}/-/security/configuration/dast_scans`;
const onDemandScansPath = `${TEST_HOST}/${projectFullPath}/-/on_demand_scans`; const onDemandScansPath = `${TEST_HOST}/${projectFullPath}/-/on_demand_scans`;
...@@ -59,7 +59,7 @@ describe('DastSiteProfileForm', () => { ...@@ -59,7 +59,7 @@ describe('DastSiteProfileForm', () => {
await setFieldValue(findTargetUrlInput(), targetUrl); await setFieldValue(findTargetUrlInput(), targetUrl);
await setFieldValue(findExcludedUrlsInput(), excludedUrls); await setFieldValue(findExcludedUrlsInput(), excludedUrls);
await setFieldValue(findRequestHeadersInput(), requestHeaders); await setFieldValue(findRequestHeadersInput(), requestHeaders);
await setAuthFieldsValues(siteProfileOne.auth); await setAuthFieldsValues(siteProfileWithSecrets.auth);
}; };
const setTargetType = async (type) => { const setTargetType = async (type) => {
...@@ -158,17 +158,19 @@ describe('DastSiteProfileForm', () => { ...@@ -158,17 +158,19 @@ describe('DastSiteProfileForm', () => {
it('when updating an existing profile', () => { it('when updating an existing profile', () => {
createComponent({ createComponent({
propsData: { propsData: {
profile: siteProfileOne, profile: siteProfileWithSecrets,
}, },
}); });
expect(findRequestHeadersInput().element.value).toBe(siteProfileOne.requestHeaders); expect(findRequestHeadersInput().element.value).toBe(siteProfileWithSecrets.requestHeaders);
expect(findByNameAttribute('password').element.value).toBe(siteProfileOne.auth.password); expect(findByNameAttribute('password').element.value).toBe(
siteProfileWithSecrets.auth.password,
);
}); });
it('when updating an existing profile with no request-header & password', () => { it('when updating an existing profile with no request-header & password', () => {
createComponent({ createComponent({
propsData: { propsData: {
profile: { ...siteProfileOne, requestHeaders: null, auth: { enabled: true } }, profile: { ...siteProfileWithSecrets, requestHeaders: null, auth: { enabled: true } },
}, },
}); });
expect(findRequestHeadersInput().element.value).toBe(''); expect(findRequestHeadersInput().element.value).toBe('');
...@@ -188,7 +190,7 @@ describe('DastSiteProfileForm', () => { ...@@ -188,7 +190,7 @@ describe('DastSiteProfileForm', () => {
describe.each` describe.each`
title | profile | mutationVars | mutation | mutationKind title | profile | mutationVars | mutation | mutationKind
${'New site profile'} | ${{}} | ${{ fullPath: projectFullPath }} | ${dastSiteProfileCreateMutation} | ${'dastSiteProfileCreate'} ${'New site profile'} | ${{}} | ${{ fullPath: projectFullPath }} | ${dastSiteProfileCreateMutation} | ${'dastSiteProfileCreate'}
${'Edit site profile'} | ${siteProfileOne} | ${{ id: siteProfileOne.id }} | ${dastSiteProfileUpdateMutation} | ${'dastSiteProfileUpdate'} ${'Edit site profile'} | ${siteProfileWithSecrets} | ${{ id: siteProfileWithSecrets.id }} | ${dastSiteProfileUpdateMutation} | ${'dastSiteProfileUpdate'}
`('$title', ({ profile, mutationVars, mutation, mutationKind }) => { `('$title', ({ profile, mutationVars, mutation, mutationKind }) => {
beforeEach(() => { beforeEach(() => {
createComponent({ createComponent({
...@@ -208,7 +210,7 @@ describe('DastSiteProfileForm', () => { ...@@ -208,7 +210,7 @@ describe('DastSiteProfileForm', () => {
expect(baseDastProfileForm.props('mutationVariables')).toEqual({ expect(baseDastProfileForm.props('mutationVariables')).toEqual({
profileName, profileName,
targetUrl, targetUrl,
excludedUrls: siteProfileOne.excludedUrls, excludedUrls: excludedUrls.split(', '),
requestHeaders, requestHeaders,
targetType: 'API', targetType: 'API',
...mutationVars, ...mutationVars,
...@@ -221,7 +223,7 @@ describe('DastSiteProfileForm', () => { ...@@ -221,7 +223,7 @@ describe('DastSiteProfileForm', () => {
describe.each` describe.each`
title | profile | mutationVars | mutationKind title | profile | mutationVars | mutationKind
${'New site profile'} | ${{}} | ${{}} | ${'dastSiteProfileCreate'} ${'New site profile'} | ${{}} | ${{}} | ${'dastSiteProfileCreate'}
${'Edit site profile'} | ${siteProfileOne} | ${{ id: siteProfileOne.id }} | ${'dastSiteProfileUpdate'} ${'Edit site profile'} | ${siteProfileWithSecrets} | ${{ id: siteProfileWithSecrets.id }} | ${'dastSiteProfileUpdate'}
`('$title', ({ profile, title, mutationVars, mutationKind }) => { `('$title', ({ profile, title, mutationVars, mutationKind }) => {
beforeEach(() => { beforeEach(() => {
createComponent({ createComponent({
...@@ -252,7 +254,7 @@ describe('DastSiteProfileForm', () => { ...@@ -252,7 +254,7 @@ describe('DastSiteProfileForm', () => {
beforeEach(() => { beforeEach(() => {
createShallowComponent({ createShallowComponent({
propsData: { propsData: {
profile: siteProfileOne, profile: siteProfileWithSecrets,
}, },
}); });
}); });
...@@ -266,7 +268,7 @@ describe('DastSiteProfileForm', () => { ...@@ -266,7 +268,7 @@ describe('DastSiteProfileForm', () => {
beforeEach(() => { beforeEach(() => {
createShallowComponent({ createShallowComponent({
propsData: { propsData: {
profile: policySiteProfile, profile: policySiteProfiles[0],
}, },
}); });
}); });
......
import siteProfilesFixture from 'test_fixtures/graphql/security_configuration/dast_profiles/graphql/dast_site_profiles.query.graphql.basic.json'; import siteProfilesFixture from 'test_fixtures/graphql/security_configuration/dast_profiles/graphql/dast_site_profiles.query.graphql.basic.json';
import scannerProfilesFixtures from 'test_fixtures/graphql/security_configuration/dast_profiles/graphql/dast_scanner_profiles.query.graphql.basic.json'; import scannerProfilesFixtures from 'test_fixtures/graphql/security_configuration/dast_profiles/graphql/dast_scanner_profiles.query.graphql.basic.json';
import profilesFixtures from 'test_fixtures/graphql/security_configuration/dast_profiles/graphql/dast_profiles.query.graphql.json';
import policySiteProfilesFixtures from 'test_fixtures/graphql/security_configuration/dast_profiles/graphql/dast_site_profiles.query.graphql.from_policies.json';
import policyScannerProfilesFixtures from 'test_fixtures/graphql/security_configuration/dast_profiles/graphql/dast_scanner_profiles.query.graphql.from_policies.json';
import dastFailedSiteValidationsFixtures from 'test_fixtures/graphql/security_configuration/dast_profiles/graphql/dast_failed_site_validations.query.graphql.json';
export const siteProfiles = siteProfilesFixture.data.project.siteProfiles.edges.map( export const siteProfiles = siteProfilesFixture.data.project.siteProfiles.edges.map(
({ node }) => node, ({ node }) => node,
...@@ -12,54 +16,19 @@ export const validatedSiteProfile = siteProfiles.find( ...@@ -12,54 +16,19 @@ export const validatedSiteProfile = siteProfiles.find(
({ validationStatus }) => validationStatus === 'PASSED_VALIDATION', ({ validationStatus }) => validationStatus === 'PASSED_VALIDATION',
); );
export const policySiteProfile = [ export const policySiteProfiles = policySiteProfilesFixtures.data.project.siteProfiles.edges.map(
{ ({ node }) => node,
id: 'gid://gitlab/DastSiteProfile/6', );
profileName: 'Profile 6',
targetUrl: 'http://example-6.com', export const policyScannerProfiles = policyScannerProfilesFixtures.data.project.scannerProfiles.edges.map(
normalizedTargetUrl: 'http://example-6.com', ({ node }) => node,
editPath: '/6/edit', );
validationStatus: 'NONE',
referencedInSecurityPolicies: ['some_policy'],
},
];
export const scannerProfiles = scannerProfilesFixtures.data.project.scannerProfiles.edges.map( export const scannerProfiles = scannerProfilesFixtures.data.project.scannerProfiles.edges.map(
({ node }) => node, ({ node }) => node,
); );
export const savedScans = [ export const savedScans = profilesFixtures.data.project.dastProfiles.edges.map(({ node }) => node);
{
id: 'gid://gitlab/DastProfile/1',
name: 'Scan 1',
dastSiteProfile: siteProfiles[0],
dastScannerProfile: scannerProfiles[0],
editPath: '/1/edit',
branch: {
name: 'main',
exists: true,
},
},
{
id: 'gid://gitlab/DastProfile/2',
name: 'Scan 2',
dastSiteProfile: siteProfiles[1],
dastScannerProfile: scannerProfiles[1],
editPath: '/2/edit',
branch: {
name: 'feature-branch',
exists: false,
},
},
];
export const failedSiteValidations = [ export const failedSiteValidations =
{ dastFailedSiteValidationsFixtures.data.project.validations.nodes;
id: '1',
normalizedTargetUrl: 'http://example.com:80',
},
{
id: '2',
normalizedTargetUrl: 'https://example.com:443',
},
];
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