Commit 655e07d1 authored by Phil Hughes's avatar Phil Hughes

Merge branch '13333-secure-open-help-links-in-new-tab' into 'master'

Make "Learn more about" links for security scanning popovers open in new tab

Closes #13333

See merge request gitlab-org/gitlab!20600
parents e44f84cc 6f6156f6
import { sprintf, s__ } from '~/locale'; import { sprintf, s__ } from '~/locale';
// Securely open external links in a new tab.
function getLinkStartTag(url) {
return `<a href="${url}" target="_blank" rel="noopener noreferrer">`;
}
// Add in the external link icon at the end of every link.
const linkEndTag = '<i class="fa fa-external-link" aria-hidden="true"></i></a>';
export default { export default {
computed: { computed: {
sastPopover() { sastPopover() {
...@@ -10,8 +18,8 @@ export default { ...@@ -10,8 +18,8 @@ export default {
content: sprintf( content: sprintf(
s__('ciReport|%{linkStartTag}Learn more about SAST %{linkEndTag}'), s__('ciReport|%{linkStartTag}Learn more about SAST %{linkEndTag}'),
{ {
linkStartTag: `<a href="${this.sastHelpPath}">`, linkStartTag: getLinkStartTag(this.sastHelpPath),
linkEndTag: '</a>', linkEndTag,
}, },
false, false,
), ),
...@@ -25,8 +33,8 @@ export default { ...@@ -25,8 +33,8 @@ export default {
content: sprintf( content: sprintf(
s__('ciReport|%{linkStartTag}Learn more about Container Scanning %{linkEndTag}'), s__('ciReport|%{linkStartTag}Learn more about Container Scanning %{linkEndTag}'),
{ {
linkStartTag: `<a href="${this.sastContainerHelpPath}">`, linkStartTag: getLinkStartTag(this.sastContainerHelpPath),
linkEndTag: '</a>', linkEndTag,
}, },
false, false,
), ),
...@@ -40,8 +48,8 @@ export default { ...@@ -40,8 +48,8 @@ export default {
content: sprintf( content: sprintf(
s__('ciReport|%{linkStartTag}Learn more about DAST %{linkEndTag}'), s__('ciReport|%{linkStartTag}Learn more about DAST %{linkEndTag}'),
{ {
linkStartTag: `<a href="${this.dastHelpPath}">`, linkStartTag: getLinkStartTag(this.dastHelpPath),
linkEndTag: '</a>', linkEndTag,
}, },
false, false,
), ),
...@@ -55,8 +63,8 @@ export default { ...@@ -55,8 +63,8 @@ export default {
content: sprintf( content: sprintf(
s__('ciReport|%{linkStartTag}Learn more about Dependency Scanning %{linkEndTag}'), s__('ciReport|%{linkStartTag}Learn more about Dependency Scanning %{linkEndTag}'),
{ {
linkStartTag: `<a href="${this.dependencyScanningHelpPath}">`, linkStartTag: getLinkStartTag(this.dependencyScanningHelpPath),
linkEndTag: '</a>', linkEndTag,
}, },
false, false,
), ),
......
---
title: Make "Learn more about" links for security scanning popovers on merge request
page open in new tab
merge_request: 13333
author: Daniel Tian
type: changed
import { shallowMount } from '@vue/test-utils';
import mixin from 'ee/vue_shared/security_reports/mixins/security_report_mixin';
describe('securityReportMixin', () => {
it.each`
key | link
${'sast'} | ${'http://fake.url/sast/help/path'}
${'sastContainer'} | ${'http://fake.url/sast/container/help/path'}
${'dast'} | ${'http://fake.url/dast/help/path'}
${'dependencyScanning'} | ${'http://fake.url/dependency/scanning/help/path'}
`('generates correct external link with icon', ({ key, link }) => {
// Create a fake component for the mixin with the mock help path data value.
const component = {
render() {},
data: () => ({ [`${key}HelpPath`]: link }), // 'key' -> 'keyHelpPath'
mixins: [mixin],
};
// Mount the component so that the mixin's computed properties are evaluated.
const { vm } = shallowMount(component);
// Get the link that the mixin generated.
const mixinLink = vm[`${key}Popover`].content; // 'key' -> 'keyPopover'
// Check that for each link, the expected strings exist.
expect(mixinLink).toContain(`href="${link}`);
expect(mixinLink).toContain('target="_blank"');
expect(mixinLink).toContain('rel="noopener noreferrer"');
expect(mixinLink).toContain('<i class="fa fa-external-link" aria-hidden="true"></i>');
});
});
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