Commit 52456cda authored by Alexander Turinske's avatar Alexander Turinske Committed by Michał Zając

Simplify vulnerability destructuring logic

- use convertObjectPropsToCamelCase to convert
  snake_case to camelCase
- update details page to use the new data model
parent 1bda826d
import Vue from 'vue'; import Vue from 'vue';
import { convertObjectPropsToCamelCase } from '~/lib/utils/common_utils';
import HeaderApp from 'ee/vulnerabilities/components/header.vue'; import HeaderApp from 'ee/vulnerabilities/components/header.vue';
import DetailsApp from 'ee/vulnerabilities/components/details.vue'; import DetailsApp from 'ee/vulnerabilities/components/details.vue';
import FooterApp from 'ee/vulnerabilities/components/footer.vue'; import FooterApp from 'ee/vulnerabilities/components/footer.vue';
...@@ -22,12 +23,11 @@ function createHeaderApp() { ...@@ -22,12 +23,11 @@ function createHeaderApp() {
function createDetailsApp() { function createDetailsApp() {
const el = document.getElementById('js-vulnerability-details'); const el = document.getElementById('js-vulnerability-details');
const vulnerability = JSON.parse(el.dataset.vulnerabilityJson); const vulnerability = JSON.parse(el.dataset.vulnerability);
const finding = JSON.parse(el.dataset.findingJson);
return new Vue({ return new Vue({
el, el,
render: h => h(DetailsApp, { props: { vulnerability, finding } }), render: h => h(DetailsApp, { props: { vulnerability } }),
}); });
} }
...@@ -39,15 +39,16 @@ function createFooterApp() { ...@@ -39,15 +39,16 @@ function createFooterApp() {
} }
const { const {
vulnerability_feedback_help_path: vulnerabilityFeedbackHelpPath, vulnerabilityFeedbackHelpPath,
has_mr: hasMr, hasMr,
discussions_url: discussionsUrl, discussionsUrl,
state, state,
issue_feedback: feedback, issueFeedback: feedback,
notesUrl,
project, project,
remediations, remediations,
solution, solution,
} = JSON.parse(el.dataset.vulnerability); } = convertObjectPropsToCamelCase(JSON.parse(el.dataset.vulnerability));
const remediation = remediations?.length ? remediations[0] : null; const remediation = remediations?.length ? remediations[0] : null;
const hasDownload = Boolean( const hasDownload = Boolean(
......
...@@ -11,14 +11,10 @@ export default { ...@@ -11,14 +11,10 @@ export default {
type: Object, type: Object,
required: true, required: true,
}, },
finding: {
type: Object,
required: true,
},
}, },
computed: { computed: {
location() { location() {
return this.finding.location || {}; return this.vulnerability.location || {};
}, },
scanner() { scanner() {
return this.finding.scanner || {}; return this.finding.scanner || {};
...@@ -60,7 +56,7 @@ export default { ...@@ -60,7 +56,7 @@ export default {
<div class="md" data-qa-selector="vulnerability_details"> <div class="md" data-qa-selector="vulnerability_details">
<h1 class="mt-3 mb-2 border-bottom-0" data-testid="title">{{ vulnerability.title }}</h1> <h1 class="mt-3 mb-2 border-bottom-0" data-testid="title">{{ vulnerability.title }}</h1>
<h3 class="mt-0">{{ __('Description') }}</h3> <h3 class="mt-0">{{ __('Description') }}</h3>
<p data-testid="description">{{ finding.description }}</p> <p data-testid="description">{{ vulnerability.description }}</p>
<ul> <ul>
<detail-item :sprintf-message="__('%{labelStart}Severity:%{labelEnd} %{severity}')"> <detail-item :sprintf-message="__('%{labelStart}Severity:%{labelEnd} %{severity}')">
...@@ -125,10 +121,10 @@ export default { ...@@ -125,10 +121,10 @@ export default {
</ul> </ul>
</template> </template>
<template v-if="finding.links && finding.links.length"> <template v-if="vulnerability.links && vulnerability.links.length">
<h3>{{ __('Links') }}</h3> <h3>{{ __('Links') }}</h3>
<ul> <ul>
<li v-for="link in finding.links" :key="link.url"> <li v-for="link in vulnerability.links" :key="link.url">
<gl-link <gl-link
:href="link.url" :href="link.url"
data-testid="link" data-testid="link"
...@@ -142,10 +138,10 @@ export default { ...@@ -142,10 +138,10 @@ export default {
</ul> </ul>
</template> </template>
<template v-if="finding.identifiers && finding.identifiers.length"> <template v-if="vulnerability.identifiers && vulnerability.identifiers.length">
<h3>{{ __('Identifiers') }}</h3> <h3>{{ __('Identifiers') }}</h3>
<ul> <ul>
<li v-for="identifier in finding.identifiers" :key="identifier.url"> <li v-for="identifier in vulnerability.identifiers" :key="identifier.url">
<gl-link :href="identifier.url" data-testid="identifier" target="_blank"> <gl-link :href="identifier.url" data-testid="identifier" target="_blank">
{{ identifier.name }} {{ identifier.name }}
</gl-link> </gl-link>
......
...@@ -11,16 +11,12 @@ describe('Vulnerability Details', () => { ...@@ -11,16 +11,12 @@ describe('Vulnerability Details', () => {
severity: 'bad severity', severity: 'bad severity',
confidence: 'high confidence', confidence: 'high confidence',
report_type: 'nice report_type', report_type: 'nice report_type',
description: 'vulnerability description',
}; };
const finding = { const createWrapper = vulnerabilityOverrides => {
description: 'finding description',
};
const createWrapper = findingOverrides => {
const propsData = { const propsData = {
vulnerability, vulnerability: { ...vulnerability, ...vulnerabilityOverrides },
finding: { ...finding, ...findingOverrides },
}; };
wrapper = mount(VulnerabilityDetails, { propsData }); wrapper = mount(VulnerabilityDetails, { propsData });
...@@ -37,7 +33,7 @@ describe('Vulnerability Details', () => { ...@@ -37,7 +33,7 @@ describe('Vulnerability Details', () => {
it('shows the properties that should always be shown', () => { it('shows the properties that should always be shown', () => {
createWrapper(); createWrapper();
expect(getText('title')).toBe(vulnerability.title); expect(getText('title')).toBe(vulnerability.title);
expect(getText('description')).toBe(finding.description); expect(getText('description')).toBe(vulnerability.description);
expect(wrapper.find(SeverityBadge).props('severity')).toBe(vulnerability.severity); expect(wrapper.find(SeverityBadge).props('severity')).toBe(vulnerability.severity);
expect(getText('reportType')).toBe(`Report Type: ${vulnerability.report_type}`); expect(getText('reportType')).toBe(`Report Type: ${vulnerability.report_type}`);
...@@ -62,12 +58,12 @@ describe('Vulnerability Details', () => { ...@@ -62,12 +58,12 @@ describe('Vulnerability Details', () => {
expect(getText('namespace')).toBe(`Namespace: linux`); expect(getText('namespace')).toBe(`Namespace: linux`);
}); });
it('shows the finding class if it exists', () => { it('shows the vulnerability class if it exists', () => {
createWrapper({ location: { file: 'file', class: 'class name' } }); createWrapper({ location: { file: 'file', class: 'class name' } });
expect(getText('class')).toBe(`Class: class name`); expect(getText('class')).toBe(`Class: class name`);
}); });
it('shows the finding method if it exists', () => { it('shows the vulnerability method if it exists', () => {
createWrapper({ location: { file: 'file', method: 'method name' } }); createWrapper({ location: { file: 'file', method: 'method name' } });
expect(getText('method')).toBe(`Method: method name`); expect(getText('method')).toBe(`Method: method name`);
}); });
...@@ -89,7 +85,7 @@ describe('Vulnerability Details', () => { ...@@ -89,7 +85,7 @@ describe('Vulnerability Details', () => {
}); });
}); });
it('shows the finding identifiers if they exist', () => { it('shows the vulnerability identifiers if they exist', () => {
createWrapper({ createWrapper({
identifiers: [{ url: '0', name: '00' }, { url: '1', name: '11' }, { url: '2', name: '22' }], identifiers: [{ url: '0', name: '00' }, { url: '1', name: '11' }, { url: '2', name: '22' }],
}); });
......
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