Commit 24233a3c authored by Phil Hughes's avatar Phil Hughes

Merge branch 'vulnerability-training-check-providers' into 'master'

Show vulnerability training for enable providers

See merge request gitlab-org/gitlab!80974
parents f925cd58 1e5d0cb7
...@@ -67,10 +67,13 @@ export default { ...@@ -67,10 +67,13 @@ export default {
showVulnerabilityTraining() { showVulnerabilityTraining() {
return ( return (
this.glFeatures.secureVulnerabilityTraining && this.glFeatures.secureVulnerabilityTraining &&
this.securityTrainingProviders?.length && this.enabledSecurityTrainingProviders?.length &&
this.identifiers?.length this.identifiers?.length
); );
}, },
enabledSecurityTrainingProviders() {
return this.securityTrainingProviders?.filter((provider) => provider.isEnabled);
},
supportedIdentifier() { supportedIdentifier() {
return this.identifiers?.find( return this.identifiers?.find(
({ externalType }) => externalType?.toLowerCase() === SUPPORTED_IDENTIFIER_TYPES.cwe, ({ externalType }) => externalType?.toLowerCase() === SUPPORTED_IDENTIFIER_TYPES.cwe,
......
...@@ -8,7 +8,7 @@ export default (el) => { ...@@ -8,7 +8,7 @@ export default (el) => {
return null; return null;
} }
const { falsePositiveDocUrl, canViewFalsePositive } = el.dataset; const { falsePositiveDocUrl, canViewFalsePositive, projectFullPath } = el.dataset;
const vulnerability = convertObjectPropsToCamelCase(JSON.parse(el.dataset.vulnerability), { const vulnerability = convertObjectPropsToCamelCase(JSON.parse(el.dataset.vulnerability), {
deep: true, deep: true,
...@@ -22,7 +22,6 @@ export default (el) => { ...@@ -22,7 +22,6 @@ export default (el) => {
newIssueUrl: vulnerability.newIssueUrl, newIssueUrl: vulnerability.newIssueUrl,
commitPathTemplate: el.dataset.commitPathTemplate, commitPathTemplate: el.dataset.commitPathTemplate,
projectFingerprint: vulnerability.projectFingerprint, projectFingerprint: vulnerability.projectFingerprint,
projectFullPath: vulnerability.project?.fullPath,
vulnerabilityId: vulnerability.id, vulnerabilityId: vulnerability.id,
issueTrackingHelpPath: vulnerability.issueTrackingHelpPath, issueTrackingHelpPath: vulnerability.issueTrackingHelpPath,
permissionsHelpPath: vulnerability.permissionsHelpPath, permissionsHelpPath: vulnerability.permissionsHelpPath,
...@@ -32,6 +31,7 @@ export default (el) => { ...@@ -32,6 +31,7 @@ export default (el) => {
jiraIntegrationSettingsPath: vulnerability.jiraIntegrationSettingsPath, jiraIntegrationSettingsPath: vulnerability.jiraIntegrationSettingsPath,
falsePositiveDocUrl, falsePositiveDocUrl,
canViewFalsePositive: parseBoolean(canViewFalsePositive), canViewFalsePositive: parseBoolean(canViewFalsePositive),
projectFullPath,
}, },
render: (h) => render: (h) =>
h(App, { h(App, {
......
...@@ -8,4 +8,5 @@ ...@@ -8,4 +8,5 @@
#js-vulnerability-main{ data: { vulnerability: vulnerability_details_json(@vulnerability, @pipeline), #js-vulnerability-main{ data: { vulnerability: vulnerability_details_json(@vulnerability, @pipeline),
false_positive_doc_url: help_page_path('user/application_security/vulnerabilities/index'), false_positive_doc_url: help_page_path('user/application_security/vulnerabilities/index'),
can_view_false_positive: @project.licensed_feature_available?(:sast_fp_reduction).to_s, can_view_false_positive: @project.licensed_feature_available?(:sast_fp_reduction).to_s,
commit_path_template: commit_path_template(@project) } } commit_path_template: commit_path_template(@project),
project_full_path: @project.full_path } }
...@@ -17,7 +17,10 @@ import { SUPPORTED_IDENTIFIER_TYPES } from 'ee/vulnerabilities/constants'; ...@@ -17,7 +17,10 @@ import { SUPPORTED_IDENTIFIER_TYPES } from 'ee/vulnerabilities/constants';
import { TRACK_CLICK_TRAINING_LINK } from '~/security_configuration/constants'; import { TRACK_CLICK_TRAINING_LINK } from '~/security_configuration/constants';
import createMockApollo from 'helpers/mock_apollo_helper'; import createMockApollo from 'helpers/mock_apollo_helper';
import waitForPromises from 'helpers/wait_for_promises'; import waitForPromises from 'helpers/wait_for_promises';
import { securityTrainingProvidersResponse } from 'jest/security_configuration/mock_data'; import {
securityTrainingProvidersResponse,
disabledSecurityTrainingProvidersResponse,
} from 'jest/security_configuration/mock_data';
const defaultProps = { const defaultProps = {
identifiers: [ identifiers: [
...@@ -84,24 +87,27 @@ describe('VulnerabilityTraining component', () => { ...@@ -84,24 +87,27 @@ describe('VulnerabilityTraining component', () => {
const findTrainingItemLinkIcon = () => wrapper.findComponent(GlIcon); const findTrainingItemLinkIcon = () => wrapper.findComponent(GlIcon);
describe('with the query being successful', () => { describe('with the query being successful', () => {
beforeEach(() => {
createApolloProvider();
});
describe('basic structure', () => { describe('basic structure', () => {
it('displays the description', async () => { it('displays the description', async () => {
createApolloProvider();
createComponent(); createComponent();
await waitForQueryToBeLoaded(); await waitForQueryToBeLoaded();
expect(findDescription().text()).toBe(i18n.trainingDescription); expect(findDescription().text()).toBe(i18n.trainingDescription);
}); });
it('does not render component when there are no identifiers', () => { it('does not render component when there are no identifiers', () => {
createApolloProvider();
createComponent({ identifiers: [] }); createComponent({ identifiers: [] });
expect(wrapper.html()).toBeFalsy(); expect(wrapper.html()).toBeFalsy();
}); });
it('does not render component when there are no securityTrainingProviders', () => { it('does not render component when there are no enabled securityTrainingProviders', async () => {
createApolloProvider({
queryHandler: jest.fn().mockResolvedValue(disabledSecurityTrainingProvidersResponse),
});
createComponent(); createComponent();
await waitForQueryToBeLoaded();
expect(wrapper.html()).toBeFalsy(); expect(wrapper.html()).toBeFalsy();
}); });
}); });
......
...@@ -30,6 +30,15 @@ export const securityTrainingProvidersResponse = { ...@@ -30,6 +30,15 @@ export const securityTrainingProvidersResponse = {
}, },
}; };
export const disabledSecurityTrainingProvidersResponse = {
data: {
project: {
id: 1,
securityTrainingProviders: [securityTrainingProviders[0]],
},
},
};
export const dismissUserCalloutResponse = { export const dismissUserCalloutResponse = {
data: { data: {
userCalloutCreate: { userCalloutCreate: {
......
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