Commit 9e54cb00 authored by Kushal Pandya's avatar Kushal Pandya

Merge branch '326356-on-demand-scans-alert-render-markup' into 'master'

Render markup in on-demand scans errors

See merge request gitlab-org/gitlab!58815
parents d749256a da318d19
......@@ -10,6 +10,7 @@ import {
GlLink,
GlSkeletonLoader,
GlSprintf,
GlSafeHtmlDirective,
GlTooltipDirective,
} from '@gitlab/ui';
import * as Sentry from '@sentry/browser';
......@@ -90,6 +91,7 @@ export default {
LocalStorageSync,
},
directives: {
SafeHtml: GlSafeHtmlDirective,
GlTooltip: GlTooltipDirective,
validation: validation(),
},
......@@ -375,7 +377,7 @@ export default {
>
{{ errorMessage }}
<ul v-if="errors.length" class="gl-mt-3 gl-mb-0">
<li v-for="error in errors" :key="error">{{ error }}</li>
<li v-for="error in errors" :key="error" v-safe-html="error"></li>
</ul>
</gl-alert>
......
......@@ -5,6 +5,7 @@ import {
GlModal,
GlSkeletonLoader,
GlTable,
GlSafeHtmlDirective,
GlTooltipDirective,
GlDropdown,
GlDropdownItem,
......@@ -26,6 +27,7 @@ export default {
GlIcon,
},
directives: {
SafeHtml: GlSafeHtmlDirective,
GlTooltip: GlTooltipDirective,
},
props: {
......@@ -164,7 +166,11 @@ export default {
:aria-label="__('DastProfiles|Error Details')"
class="gl-p-0 gl-m-0"
>
<li v-for="errorDetail in errorDetails" :key="errorDetail">{{ errorDetail }}</li>
<li
v-for="errorDetail in errorDetails"
:key="errorDetail"
v-safe-html="errorDetail"
></li>
</ul>
</gl-alert>
</td>
......
---
title: Render links in DAST scans errors
merge_request: 58815
author:
type: fixed
......@@ -431,22 +431,27 @@ describe('OnDemandScansForm', () => {
});
describe('on errors as data', () => {
const errors = ['error#1', 'error#2', 'error#3'];
beforeEach(async () => {
createShallowComponent();
const submitWithError = async (errors) => {
wrapper.vm.$apollo.mutate.mockResolvedValue({
data: { dastProfileCreate: { pipelineUrl: null, errors } },
});
await setValidFormData();
submitForm();
await submitForm();
};
beforeEach(async () => {
createShallowComponent();
});
it('resets loading state', () => {
it('resets loading state', async () => {
await submitWithError(['error']);
expect(wrapper.vm.loading).toBe(false);
});
it('shows an alert with the returned errors', () => {
it('shows an alert with the returned errors', async () => {
const errors = ['error#1', 'error#2', 'error#3'];
await submitWithError(errors);
const alert = findAlert();
expect(alert.exists()).toBe(true);
......@@ -454,6 +459,14 @@ describe('OnDemandScansForm', () => {
expect(alert.text()).toContain(error);
});
});
it('properly renders errors containing markup', async () => {
await submitWithError(['an error <a href="#" data-testid="error-link">with a link</a>']);
const alert = findAlert();
expect(alert.text()).toContain('an error with a link');
expect(alert.find('[data-testid="error-link"]').exists()).toBe(true);
});
});
});
......
......@@ -244,6 +244,17 @@ describe('EE - DastProfilesList', () => {
expect(within(getErrorDetails()).getByText(errorDetails[0])).not.toBe(null);
expect(within(getErrorDetails()).getByText(errorDetails[1])).not.toBe(null);
});
it('properly renders errors containing markup', () => {
const errorDetails = ['an error <a href="#">with a link</a>'];
createFullComponent({
propsData: { errorMessage: TEST_ERROR_MESSAGE, errorDetails },
});
expect(getErrorMessage()).not.toBe(null);
expect(getErrorDetails()).not.toBe(null);
expect(within(getErrorDetails()).getByRole('link', { name: 'with a link' })).not.toBe(null);
});
});
describe('profile referenced in a security policy', () => {
......
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