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
...@@ -7,100 +7,43 @@ RSpec.describe 'DAST profiles (GraphQL fixtures)' do ...@@ -7,100 +7,43 @@ RSpec.describe 'DAST profiles (GraphQL fixtures)' do
include ApiHelpers include ApiHelpers
include GraphqlHelpers include GraphqlHelpers
include JavaScriptFixturesHelpers include JavaScriptFixturesHelpers
include API::Helpers::GraphqlHelpers
include RepoHelpers
let_it_be(:current_user) { create(:user) } shared_examples 'dast_site_profiles.query.graphql' do |type|
let_it_be(:project) { create(:project, :repository, :public) } path = 'security_configuration/dast_profiles/graphql/dast_site_profiles.query.graphql'
# DAST site validations
let_it_be(:dast_site_validation_pending) do
create(
:dast_site_validation,
state: :pending,
dast_site_token: create(
:dast_site_token,
project: project
)
)
end
let_it_be(:dast_site_validation_inprogress) do it "graphql/#{path}.#{type}.json" do
create( query = get_graphql_query_as_string(path, ee: true)
:dast_site_validation,
state: :inprogress,
dast_site_token: create(
:dast_site_token,
project: project
)
)
end
let_it_be(:dast_site_validation_passed) do post_graphql(query, current_user: current_user, variables: {
create( fullPath: project.full_path,
:dast_site_validation, first: 20
state: :passed, })
dast_site_token: create(
:dast_site_token,
project: project
)
)
end
let_it_be(:dast_site_validation_failed) do expect_graphql_errors_to_be_empty
create( expect(graphql_data_at(:project, :siteProfiles, :edges)).to have_attributes(size: dast_site_profiles.length)
:dast_site_validation, end
state: :failed,
dast_site_token: create(
:dast_site_token,
project: project
)
)
end end
# DAST sites shared_examples 'dast_scanner_profiles.query.graphql' do |type|
let_it_be(:dast_site_pending) do path = 'security_configuration/dast_profiles/graphql/dast_scanner_profiles.query.graphql'
create(
:dast_site,
project: project,
url: 'http://pending.test',
dast_site_validation: dast_site_validation_pending
)
end
let_it_be(:dast_site_inprogress) do it "graphql/#{path}.#{type}.json" do
create( query = get_graphql_query_as_string(path, ee: true)
:dast_site,
project: project,
url: 'http://inprogress.test',
dast_site_validation: dast_site_validation_inprogress
)
end
let_it_be(:dast_site_passed) do post_graphql(query, current_user: current_user, variables: {
create( fullPath: project.full_path,
:dast_site, first: 20
project: project, })
url: 'http://passed.test',
dast_site_validation: dast_site_validation_passed
)
end
let_it_be(:dast_site_failed) do expect_graphql_errors_to_be_empty
create( expect(graphql_data_at(:project, :scannerProfiles, :edges)).to have_attributes(size: dast_scanner_profiles.length)
:dast_site, end
project: project,
url: 'http://failed.test',
dast_site_validation: dast_site_validation_failed
)
end end
let_it_be(:dast_site_none) do let_it_be(:current_user) { create(:user) }
create( let_it_be(:project) { create(:project, :repository, :public) }
:dast_site,
project: project,
url: 'http://none.test',
dast_site_validation: nil
)
end
before do before do
stub_licensed_features(security_on_demand_scans: true) stub_licensed_features(security_on_demand_scans: true)
...@@ -108,7 +51,96 @@ RSpec.describe 'DAST profiles (GraphQL fixtures)' do ...@@ -108,7 +51,96 @@ RSpec.describe 'DAST profiles (GraphQL fixtures)' do
end end
describe 'dast_site_profiles' do describe 'dast_site_profiles' do
path = 'security_configuration/dast_profiles/graphql/dast_site_profiles.query.graphql' # DAST site validations
let_it_be(:dast_site_validation_pending) do
create(
:dast_site_validation,
state: :pending,
dast_site_token: create(
:dast_site_token,
project: project
)
)
end
let_it_be(:dast_site_validation_inprogress) do
create(
:dast_site_validation,
state: :inprogress,
dast_site_token: create(
:dast_site_token,
project: project
)
)
end
let_it_be(:dast_site_validation_passed) do
create(
:dast_site_validation,
state: :passed,
dast_site_token: create(
:dast_site_token,
project: project
)
)
end
let_it_be(:dast_site_validation_failed) do
create(
:dast_site_validation,
state: :failed,
dast_site_token: create(
:dast_site_token,
project: project
)
)
end
# DAST sites
let_it_be(:dast_site_pending) do
create(
:dast_site,
project: project,
url: 'http://pending.test',
dast_site_validation: dast_site_validation_pending
)
end
let_it_be(:dast_site_inprogress) do
create(
:dast_site,
project: project,
url: 'http://inprogress.test',
dast_site_validation: dast_site_validation_inprogress
)
end
let_it_be(:dast_site_passed) do
create(
:dast_site,
project: project,
url: 'http://passed.test',
dast_site_validation: dast_site_validation_passed
)
end
let_it_be(:dast_site_failed) do
create(
:dast_site,
project: project,
url: 'http://failed.test',
dast_site_validation: dast_site_validation_failed
)
end
let_it_be(:dast_site_none) do
create(
:dast_site,
project: project,
url: 'http://none.test',
dast_site_validation: nil
)
end
context 'basic site profiles' do context 'basic site profiles' do
# DAST site profiles # DAST site profiles
...@@ -118,52 +150,77 @@ RSpec.describe 'DAST profiles (GraphQL fixtures)' do ...@@ -118,52 +150,77 @@ RSpec.describe 'DAST profiles (GraphQL fixtures)' do
:dast_site_profile, :dast_site_profile,
name: "Non-validated", name: "Non-validated",
auth_username: "non-validated@example.com", auth_username: "non-validated@example.com",
project: project, dast_site: dast_site_none project: project,
dast_site: dast_site_none
), ),
create( create(
:dast_site_profile, :dast_site_profile,
name: "Validation failed", name: "Validation failed",
auth_username: "validation-failed@example.com", auth_username: "validation-failed@example.com",
project: project, dast_site: dast_site_failed project: project,
dast_site: dast_site_failed
), ),
create( create(
:dast_site_profile, :dast_site_profile,
name: "Validation passed", name: "Validation passed",
auth_username: "validation-passed@example.com", auth_username: "validation-passed@example.com",
project: project, dast_site: dast_site_passed project: project,
dast_site: dast_site_passed
), ),
create( create(
:dast_site_profile, :dast_site_profile,
name: "Validation in progress", name: "Validation in progress",
auth_username: "validation-in-progress@example.com", auth_username: "validation-in-progress@example.com",
project: project, dast_site: dast_site_inprogress project: project,
dast_site: dast_site_inprogress
), ),
create( create(
:dast_site_profile, :dast_site_profile,
name: "Validation pending", name: "Validation pending",
auth_username: "validation-pending@example.com", auth_username: "validation-pending@example.com",
project: project, dast_site: dast_site_pending project: project,
dast_site: dast_site_pending
) )
] ]
end end
it "graphql/#{path}.basic.json" do it_behaves_like 'dast_site_profiles.query.graphql', "basic"
query = get_graphql_query_as_string(path, ee: true) end
post_graphql(query, current_user: current_user, variables: {
fullPath: project.full_path,
first: 20
})
expect_graphql_errors_to_be_empty context 'dast site profile with secret variables' do
expect(graphql_data_at(:project, :siteProfiles, :edges)).to have_attributes(size: 5) let(:response) { @site_profile.to_json }
let_it_be(:dast_site_profile) { create(:dast_site_profile, project: project) }
let_it_be(:request_headers_variable) { create(:dast_site_profile_secret_variable, :request_headers, dast_site_profile: dast_site_profile) }
let_it_be(:password_variable) { create(:dast_site_profile_secret_variable, :password, dast_site_profile: dast_site_profile) }
it "security_configuration/dast_profiles/dast_site_profile_with_secrets.json" do
query = %(
{
project(fullPath: "#{project.full_path}") {
dastSiteProfile(id: "#{Gitlab::GlobalId.as_global_id(dast_site_profile.id, model_name: 'DastSiteProfile')}") {
id
name: profileName
targetUrl
targetType
excludedUrls
requestHeaders
auth { enabled url username usernameField password passwordField }
referencedInSecurityPolicies
}
}
}
)
@site_profile = run_graphql!(
query: query,
context: { current_user: current_user },
transform: -> (result) { result.dig('data', 'project', 'dastSiteProfile') }
)
end end
end end
end end
describe 'dast_scanner_profiles' do describe 'dast_scanner_profiles' do
path = 'security_configuration/dast_profiles/graphql/dast_scanner_profiles.query.graphql'
# DAST scanner profiles # DAST scanner profiles
let_it_be(:dast_scanner_profiles) do let_it_be(:dast_scanner_profiles) do
[ [
...@@ -188,7 +245,78 @@ RSpec.describe 'DAST profiles (GraphQL fixtures)' do ...@@ -188,7 +245,78 @@ RSpec.describe 'DAST profiles (GraphQL fixtures)' do
] ]
end end
it "graphql/#{path}.basic.json" do it_behaves_like 'dast_scanner_profiles.query.graphql', "basic"
end
describe 'from policies' do
let_it_be(:policies_project) { create(:project, :repository) }
let_it_be(:security_orchestration_policy_configuration) do
create(
:security_orchestration_policy_configuration,
project: project,
security_policy_management_project: policies_project
)
end
let_it_be(:dast_site_profiles) do
[
create(
:dast_site_profile,
name: "From policy",
auth_username: "from-policy@example.com",
project: project
)
]
end
let_it_be(:dast_scanner_profiles) do
[
create(
:dast_scanner_profile,
name: "Active scanner",
spider_timeout: 5,
target_timeout: 10,
scan_type: 'active',
use_ajax_spider: true,
show_debug_messages: true,
project: project
)
]
end
let(:policy1) do
build(:scan_execution_policy, rules: [{ type: 'pipeline', branches: %w[master] }], actions: [
{ scan: 'dast', site_profile: dast_site_profiles.first.name, scanner_profile: dast_scanner_profiles.first.name }
])
end
let(:policy_yaml) { build(:orchestration_policy_yaml, scan_execution_policy: [policy1]) }
before do
create_file_in_repo(policies_project, 'master', 'master', Security::OrchestrationPolicyConfiguration::POLICY_PATH, policy_yaml)
end
context "site profiles" do
it_behaves_like 'dast_site_profiles.query.graphql', "from_policies"
end
context "scanner profiles" do
it_behaves_like 'dast_scanner_profiles.query.graphql', "from_policies"
end
end
describe 'scheduled_dast_profiles' do
path = 'on_demand_scans/graphql/scheduled_dast_profiles.query.graphql'
let_it_be(:dast_profile) { create(:dast_profile, project: project) }
let_it_be(:dast_profile_schedule) do
create(:dast_profile_schedule, project: project,
dast_profile: dast_profile)
end
it "graphql/#{path}.json" do
query = get_graphql_query_as_string(path, ee: true) query = get_graphql_query_as_string(path, ee: true)
post_graphql(query, current_user: current_user, variables: { post_graphql(query, current_user: current_user, variables: {
...@@ -197,15 +325,24 @@ RSpec.describe 'DAST profiles (GraphQL fixtures)' do ...@@ -197,15 +325,24 @@ RSpec.describe 'DAST profiles (GraphQL fixtures)' do
}) })
expect_graphql_errors_to_be_empty expect_graphql_errors_to_be_empty
expect(graphql_data_at(:project, :scannerProfiles, :edges)).to have_attributes(size: 2) expect(graphql_data_at(:project, :pipelines, :nodes)).to have_attributes(size: 1)
end end
end end
describe 'scheduled_dast_profiles' do describe 'dast_profiles' do
path = 'on_demand_scans/graphql/scheduled_dast_profiles.query.graphql' path = 'security_configuration/dast_profiles/graphql/dast_profiles.query.graphql'
let_it_be(:dast_profile) { create(:dast_profile, project: project) } let_it_be(:dast_profiles) do
let_it_be(:dast_profile_schedule) { create(:dast_profile_schedule, project: project, dast_profile: dast_profile)} [
create(:dast_profile, project: project),
create(:dast_profile, project: project)
]
end
before do
dast_profiles.first.branch_name = SecureRandom.hex
dast_profiles.first.save!(validate: false)
end
it "graphql/#{path}.json" do it "graphql/#{path}.json" do
query = get_graphql_query_as_string(path, ee: true) query = get_graphql_query_as_string(path, ee: true)
...@@ -216,7 +353,48 @@ RSpec.describe 'DAST profiles (GraphQL fixtures)' do ...@@ -216,7 +353,48 @@ RSpec.describe 'DAST profiles (GraphQL fixtures)' do
}) })
expect_graphql_errors_to_be_empty expect_graphql_errors_to_be_empty
expect(graphql_data_at(:project, :pipelines, :nodes)).to have_attributes(size: 1) expect(graphql_data_at(:project, :dastProfiles, :edges)).to have_attributes(size: dast_profiles.length)
end
end
describe 'dast_site_validations' do
context 'failed site validations' do
path = 'security_configuration/dast_profiles/graphql/dast_failed_site_validations.query.graphql'
let_it_be(:dast_site_validation_https) do
create(
:dast_site_validation,
state: :failed,
dast_site_token: create(
:dast_site_token,
url: 'https://example.com',
project: project
)
)
end
let_it_be(:dast_site_validation_http) do
create(
:dast_site_validation,
state: :failed,
dast_site_token: create(
:dast_site_token,
url: 'http://example.com',
project: project
)
)
end
it "graphql/#{path}.json" do
query = get_graphql_query_as_string(path, ee: true)
post_graphql(query, current_user: current_user, variables: {
fullPath: project.full_path
})
expect_graphql_errors_to_be_empty
expect(graphql_data_at(:project, :validations, :nodes)).to have_attributes(size: 2)
end
end end
end end
......
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('');
...@@ -186,9 +188,9 @@ describe('DastSiteProfileForm', () => { ...@@ -186,9 +188,9 @@ 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,
...@@ -219,9 +221,9 @@ describe('DastSiteProfileForm', () => { ...@@ -219,9 +221,9 @@ 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