Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
9001fc63
Commit
9001fc63
authored
4 years ago
by
Kev
Committed by
Kushal Pandya
4 years ago
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Prevent Download For Failed Vulnerability Export Jobs
parent
caae0ec3
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
44 additions
and
15 deletions
+44
-15
ee/app/assets/javascripts/security_dashboard/components/csv_export_button.vue
...ripts/security_dashboard/components/csv_export_button.vue
+3
-0
ee/changelogs/unreleased/220601-Prevent-Download-For-Failed-Vuln-Export-Jobs.yml
...d/220601-Prevent-Download-For-Failed-Vuln-Export-Jobs.yml
+5
-0
ee/spec/frontend/security_dashboard/components/csv_export_button_spec.js
...d/security_dashboard/components/csv_export_button_spec.js
+36
-15
No files found.
ee/app/assets/javascripts/security_dashboard/components/csv_export_button.vue
View file @
9001fc63
...
...
@@ -57,6 +57,9 @@ export default {
.
post
(
this
.
vulnerabilitiesExportEndpoint
)
.
then
(({
data
})
=>
pollUntilComplete
(
data
.
_links
.
self
))
.
then
(({
data
})
=>
{
if
(
data
.
status
!==
'
finished
'
)
{
throw
new
Error
();
}
download
({
fileName
:
`csv-export-
${
formatDate
(
new
Date
(),
'
isoDateTime
'
)}
.csv`
,
url
:
data
.
_links
.
download
,
...
...
This diff is collapsed.
Click to expand it.
ee/changelogs/unreleased/220601-Prevent-Download-For-Failed-Vuln-Export-Jobs.yml
0 → 100644
View file @
9001fc63
---
title
:
Prevent Download For Failed Vulnerability Export Jobs
merge_request
:
40656
author
:
Kev @KevSlashNull
type
:
fixed
This diff is collapsed.
Click to expand it.
ee/spec/frontend/security_dashboard/components/csv_export_button_spec.js
View file @
9001fc63
...
...
@@ -19,6 +19,7 @@ const vulnerabilitiesExportEndpoint = `${TEST_HOST}/vulnerability_findings.csv`;
describe
(
'
Csv Button Export
'
,
()
=>
{
let
mock
;
let
wrapper
;
let
spy
;
const
issueUrl
=
'
https://gitlab.com/gitlab-org/gitlab/issues/197111
'
;
const
findPopoverExternalLink
=
()
=>
wrapper
.
find
({
ref
:
'
popoverExternalLink
'
});
...
...
@@ -38,6 +39,23 @@ describe('Csv Button Export', () => {
});
};
const
setupMocksAndSpy
=
(
statusLink
,
downloadLink
,
downloadAnchor
,
status
=
'
finished
'
)
=>
{
mock
.
onPost
(
vulnerabilitiesExportEndpoint
)
.
reply
(
statusCodes
.
ACCEPTED
,
{
_links
:
{
self
:
statusLink
}
});
mock
.
onGet
(
statusLink
).
reply
(()
=>
{
// We need to mock it at this stage because vue internally uses
// document.createElement to mount the elements.
spy
=
jest
.
spyOn
(
document
,
'
createElement
'
).
mockImplementationOnce
(()
=>
{
// eslint-disable-next-line no-param-reassign
downloadAnchor
.
click
=
jest
.
fn
();
return
downloadAnchor
;
});
return
[
statusCodes
.
OK
,
{
_links
:
{
download
:
downloadLink
},
status
}];
});
};
afterEach
(()
=>
{
wrapper
.
destroy
();
localStorage
.
removeItem
(
STORAGE_KEY
);
...
...
@@ -61,21 +79,8 @@ describe('Csv Button Export', () => {
const
downloadAnchor
=
document
.
createElement
(
'
a
'
);
const
statusLink
=
'
/poll/until/complete
'
;
const
downloadLink
=
'
/link/to/download
'
;
let
spy
;
mock
.
onPost
(
vulnerabilitiesExportEndpoint
)
.
reply
(
statusCodes
.
ACCEPTED
,
{
_links
:
{
self
:
statusLink
}
});
mock
.
onGet
(
statusLink
).
reply
(()
=>
{
// We need to mock it at this stage because vue internally uses
// document.createElement to mount the elements.
spy
=
jest
.
spyOn
(
document
,
'
createElement
'
).
mockImplementationOnce
(()
=>
{
downloadAnchor
.
click
=
jest
.
fn
();
return
downloadAnchor
;
});
return
[
statusCodes
.
OK
,
{
_links
:
{
download
:
downloadLink
}
}];
});
setupMocksAndSpy
(
statusLink
,
downloadLink
,
downloadAnchor
);
findCsvExportButton
().
vm
.
$emit
(
'
click
'
);
...
...
@@ -89,6 +94,22 @@ describe('Csv Button Export', () => {
});
});
it
(
`shows the flash error when the export job status is 'failed'`
,
()
=>
{
setupMocksAndSpy
(
'
/poll/until/complete
'
,
'
/link/to/download
'
,
document
.
createElement
(
'
a
'
),
'
failed
'
,
);
findCsvExportButton
().
vm
.
$emit
(
'
click
'
);
return
axios
.
waitForAll
().
then
(()
=>
{
expect
(
spy
).
not
.
toHaveBeenCalled
();
expect
(
createFlash
).
toHaveBeenCalledWith
(
'
There was an error while generating the report.
'
);
});
});
it
(
'
shows the flash error when backend fails to generate the export
'
,
()
=>
{
mock
.
onPost
(
vulnerabilitiesExportEndpoint
).
reply
(
statusCodes
.
NOT_FOUND
,
{});
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment