Commit fe93883e authored by Martin Wortschack's avatar Martin Wortschack

Merge branch 'fix-null-pipeline-url-231397' into 'master'

Show errors in flash if DAST on-demand scan fails

See merge request gitlab-org/gitlab!37783
parents a1245430 f71a7f75
<script> <script>
import * as Sentry from '@sentry/browser'; import * as Sentry from '@sentry/browser';
import { s__ } from '~/locale'; import { s__, sprintf } from '~/locale';
import createFlash from '~/flash'; import createFlash from '~/flash';
import { isAbsolute, redirectTo } from '~/lib/utils/url_utility'; import { isAbsolute, redirectTo } from '~/lib/utils/url_utility';
import { import {
...@@ -99,8 +99,17 @@ export default { ...@@ -99,8 +99,17 @@ export default {
mutation: runDastScanMutation, mutation: runDastScanMutation,
variables: this.formData, variables: this.formData,
}) })
.then(({ data: { runDastScan: { pipelineUrl } } }) => { .then(({ data: { runDastScan: { pipelineUrl, errors } } }) => {
redirectTo(pipelineUrl); if (errors?.length) {
createFlash(
sprintf(s__('OnDemandScans|Could not run the scan: %{backendErrorMessage}'), {
backendErrorMessage: errors.join(', '),
}),
);
this.loading = false;
} else {
redirectTo(pipelineUrl);
}
}) })
.catch(e => { .catch(e => {
Sentry.captureException(e); Sentry.captureException(e);
......
...@@ -13,5 +13,6 @@ mutation runDastScan( ...@@ -13,5 +13,6 @@ mutation runDastScan(
} }
) { ) {
pipelineUrl pipelineUrl
errors
} }
} }
...@@ -194,7 +194,7 @@ describe('OnDemandScansApp', () => { ...@@ -194,7 +194,7 @@ describe('OnDemandScansApp', () => {
beforeEach(async () => { beforeEach(async () => {
jest jest
.spyOn(wrapper.vm.$apollo, 'mutate') .spyOn(wrapper.vm.$apollo, 'mutate')
.mockResolvedValue({ data: { runDastScan: { pipelineUrl } } }); .mockResolvedValue({ data: { runDastScan: { pipelineUrl, errors: [] } } });
const input = findTargetUrlInput(); const input = findTargetUrlInput();
input.vm.$emit('input', targetUrl); input.vm.$emit('input', targetUrl);
submitForm(); submitForm();
...@@ -221,7 +221,7 @@ describe('OnDemandScansApp', () => { ...@@ -221,7 +221,7 @@ describe('OnDemandScansApp', () => {
}); });
}); });
describe('on error', () => { describe('on top-level error', () => {
beforeEach(async () => { beforeEach(async () => {
jest.spyOn(wrapper.vm.$apollo, 'mutate').mockRejectedValue(); jest.spyOn(wrapper.vm.$apollo, 'mutate').mockRejectedValue();
const input = findTargetUrlInput(); const input = findTargetUrlInput();
...@@ -237,5 +237,25 @@ describe('OnDemandScansApp', () => { ...@@ -237,5 +237,25 @@ describe('OnDemandScansApp', () => {
expect(createFlash).toHaveBeenCalledWith('Could not run the scan. Please try again.'); expect(createFlash).toHaveBeenCalledWith('Could not run the scan. Please try again.');
}); });
}); });
describe('on errors as data', () => {
beforeEach(async () => {
const errors = ['A', 'B', 'C'];
jest
.spyOn(wrapper.vm.$apollo, 'mutate')
.mockResolvedValue({ data: { runDastScan: { pipelineUrl: null, errors } } });
const input = findTargetUrlInput();
input.vm.$emit('input', targetUrl);
submitForm();
});
it('resets loading state', () => {
expect(wrapper.vm.loading).toBe(false);
});
it('shows an error flash', () => {
expect(createFlash).toHaveBeenCalledWith('Could not run the scan: A, B, C');
});
});
}); });
}); });
...@@ -16388,6 +16388,9 @@ msgstr "" ...@@ -16388,6 +16388,9 @@ msgstr ""
msgid "OnDemandScans|Could not run the scan. Please try again." msgid "OnDemandScans|Could not run the scan. Please try again."
msgstr "" msgstr ""
msgid "OnDemandScans|Could not run the scan: %{backendErrorMessage}"
msgstr ""
msgid "OnDemandScans|Create new DAST scan" msgid "OnDemandScans|Create new DAST scan"
msgstr "" msgstr ""
......
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