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
import ConfigurationSnippetModal from 'ee/security_configuration/components/configuration_snippet_modal.vue';
import { CONFIGURATION_SNIPPET_MODAL_ID } from 'ee/security_configuration/components/constants';
import ConfigurationForm from 'ee/security_configuration/dast/components/configuration_form.vue';
import { scannerProfiles } from 'ee_jest/security_configuration/dast_profiles/mocks/mock_data';
import { siteProfiles } from 'ee_jest/on_demand_scans_form/mocks/mock_data';
import {
scannerProfiles,
siteProfiles,
} from 'ee_jest/security_configuration/dast_profiles/mocks/mock_data';
import { extendedWrapper } from 'helpers/vue_test_utils_helper';
import { CODE_SNIPPET_SOURCE_DAST } from '~/pipeline_editor/components/code_snippet_alert/constants';
import { DAST_HELP_PATH } from '~/security_configuration/components/constants';
......
......@@ -4,7 +4,7 @@ import { mount, shallowMount, createWrapper } from '@vue/test-utils';
import { merge } from 'lodash';
import DastProfilesList from 'ee/security_configuration/dast_profiles/components/dast_profiles_list.vue';
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';
......@@ -259,7 +259,7 @@ describe('EE - DastProfilesList', () => {
describe('profile referenced in a security policy', () => {
it('disables the delete button', () => {
createFullComponent({ propsData: { profiles: policySiteProfile } });
createFullComponent({ propsData: { profiles: policySiteProfiles } });
const disabledRow = getAllTableRows()[0];
const deleteButton = getDeleteButtonWithin(disabledRow);
expect(deleteButton.attributes('disabled')).toBe('disabled');
......@@ -267,7 +267,7 @@ describe('EE - DastProfilesList', () => {
});
it('shows the correct tooltip text', () => {
createFullComponent({ propsData: { profiles: policySiteProfile } });
createFullComponent({ propsData: { profiles: policySiteProfiles } });
expect(getBinding(getDeleteTooltip().element, 'gl-tooltip')).not.toBe(undefined);
expect(getDeleteTooltip().attributes('title')).toBe(
'This profile is currently being used in a policy.',
......
......@@ -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 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 { policyScannerProfile } from 'ee_jest/on_demand_scans_form/mocks/mock_data';
import { scannerProfiles } from 'ee_jest/security_configuration/dast_profiles/mocks/mock_data';
import {
scannerProfiles,
policyScannerProfiles,
} from 'ee_jest/security_configuration/dast_profiles/mocks/mock_data';
import { TEST_HOST } from 'helpers/test_constants';
import { mountExtended, shallowMountExtended } from 'helpers/vue_test_utils_helper';
......@@ -179,7 +181,7 @@ describe('DastScannerProfileForm', () => {
beforeEach(() => {
createShallowComponent({
propsData: {
profile: policyScannerProfile,
profile: policyScannerProfiles[0],
},
});
});
......
import { GlForm } from '@gitlab/ui';
import { within } from '@testing-library/dom';
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 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 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 { 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 { mountExtended, shallowMountExtended } from 'helpers/vue_test_utils_helper';
const [siteProfileOne] = siteProfiles;
const projectFullPath = 'group/project';
const profilesLibraryPath = `${TEST_HOST}/${projectFullPath}/-/security/configuration/dast_scans`;
const onDemandScansPath = `${TEST_HOST}/${projectFullPath}/-/on_demand_scans`;
......@@ -59,7 +59,7 @@ describe('DastSiteProfileForm', () => {
await setFieldValue(findTargetUrlInput(), targetUrl);
await setFieldValue(findExcludedUrlsInput(), excludedUrls);
await setFieldValue(findRequestHeadersInput(), requestHeaders);
await setAuthFieldsValues(siteProfileOne.auth);
await setAuthFieldsValues(siteProfileWithSecrets.auth);
};
const setTargetType = async (type) => {
......@@ -158,17 +158,19 @@ describe('DastSiteProfileForm', () => {
it('when updating an existing profile', () => {
createComponent({
propsData: {
profile: siteProfileOne,
profile: siteProfileWithSecrets,
},
});
expect(findRequestHeadersInput().element.value).toBe(siteProfileOne.requestHeaders);
expect(findByNameAttribute('password').element.value).toBe(siteProfileOne.auth.password);
expect(findRequestHeadersInput().element.value).toBe(siteProfileWithSecrets.requestHeaders);
expect(findByNameAttribute('password').element.value).toBe(
siteProfileWithSecrets.auth.password,
);
});
it('when updating an existing profile with no request-header & password', () => {
createComponent({
propsData: {
profile: { ...siteProfileOne, requestHeaders: null, auth: { enabled: true } },
profile: { ...siteProfileWithSecrets, requestHeaders: null, auth: { enabled: true } },
},
});
expect(findRequestHeadersInput().element.value).toBe('');
......@@ -186,9 +188,9 @@ describe('DastSiteProfileForm', () => {
});
describe.each`
title | profile | mutationVars | mutation | mutationKind
${'New site profile'} | ${{}} | ${{ fullPath: projectFullPath }} | ${dastSiteProfileCreateMutation} | ${'dastSiteProfileCreate'}
${'Edit site profile'} | ${siteProfileOne} | ${{ id: siteProfileOne.id }} | ${dastSiteProfileUpdateMutation} | ${'dastSiteProfileUpdate'}
title | profile | mutationVars | mutation | mutationKind
${'New site profile'} | ${{}} | ${{ fullPath: projectFullPath }} | ${dastSiteProfileCreateMutation} | ${'dastSiteProfileCreate'}
${'Edit site profile'} | ${siteProfileWithSecrets} | ${{ id: siteProfileWithSecrets.id }} | ${dastSiteProfileUpdateMutation} | ${'dastSiteProfileUpdate'}
`('$title', ({ profile, mutationVars, mutation, mutationKind }) => {
beforeEach(() => {
createComponent({
......@@ -208,7 +210,7 @@ describe('DastSiteProfileForm', () => {
expect(baseDastProfileForm.props('mutationVariables')).toEqual({
profileName,
targetUrl,
excludedUrls: siteProfileOne.excludedUrls,
excludedUrls: excludedUrls.split(', '),
requestHeaders,
targetType: 'API',
...mutationVars,
......@@ -219,9 +221,9 @@ describe('DastSiteProfileForm', () => {
});
describe.each`
title | profile | mutationVars | mutationKind
${'New site profile'} | ${{}} | ${{}} | ${'dastSiteProfileCreate'}
${'Edit site profile'} | ${siteProfileOne} | ${{ id: siteProfileOne.id }} | ${'dastSiteProfileUpdate'}
title | profile | mutationVars | mutationKind
${'New site profile'} | ${{}} | ${{}} | ${'dastSiteProfileCreate'}
${'Edit site profile'} | ${siteProfileWithSecrets} | ${{ id: siteProfileWithSecrets.id }} | ${'dastSiteProfileUpdate'}
`('$title', ({ profile, title, mutationVars, mutationKind }) => {
beforeEach(() => {
createComponent({
......@@ -252,7 +254,7 @@ describe('DastSiteProfileForm', () => {
beforeEach(() => {
createShallowComponent({
propsData: {
profile: siteProfileOne,
profile: siteProfileWithSecrets,
},
});
});
......@@ -266,7 +268,7 @@ describe('DastSiteProfileForm', () => {
beforeEach(() => {
createShallowComponent({
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 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(
({ node }) => node,
......@@ -12,54 +16,19 @@ export const validatedSiteProfile = siteProfiles.find(
({ validationStatus }) => validationStatus === 'PASSED_VALIDATION',
);
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',
referencedInSecurityPolicies: ['some_policy'],
},
];
export const policySiteProfiles = policySiteProfilesFixtures.data.project.siteProfiles.edges.map(
({ node }) => node,
);
export const policyScannerProfiles = policyScannerProfilesFixtures.data.project.scannerProfiles.edges.map(
({ node }) => node,
);
export const scannerProfiles = scannerProfilesFixtures.data.project.scannerProfiles.edges.map(
({ node }) => node,
);
export const savedScans = [
{
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 savedScans = profilesFixtures.data.project.dastProfiles.edges.map(({ node }) => node);
export const failedSiteValidations = [
{
id: '1',
normalizedTargetUrl: 'http://example.com:80',
},
{
id: '2',
normalizedTargetUrl: 'https://example.com:443',
},
];
export const failedSiteValidations =
dastFailedSiteValidationsFixtures.data.project.validations.nodes;
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