Commit 94b08103 authored by Fernando's avatar Fernando

Code review feedback changes

* Refactor to add computed props
* Update order of http respone message fields
* Update unit tests
parent c7646a2c
...@@ -57,9 +57,14 @@ export default { ...@@ -57,9 +57,14 @@ export default {
properties: {}, properties: {},
}; };
}, },
assert() { assertion() {
return this.vulnerability.evidence_source?.name; return this.vulnerability.evidence_source?.name;
}, },
recordedMessage() {
return this.vulnerability?.supporting_messages?.find(
msg => msg.name === SUPPORTING_MESSAGE_TYPES.RECORDED,
)?.response;
},
getConstructedRequest() { getConstructedRequest() {
const { body, method, url, headers = [] } = this.vulnerability.request; const { body, method, url, headers = [] } = this.vulnerability.request;
const headerLines = this.getHeadersAsCodeBlockLines(headers); const headerLines = this.getHeadersAsCodeBlockLines(headers);
...@@ -78,7 +83,7 @@ export default { ...@@ -78,7 +83,7 @@ export default {
const headerLines = this.getHeadersAsCodeBlockLines(headers); const headerLines = this.getHeadersAsCodeBlockLines(headers);
return statusCode && reasonPhrase && headerLines return statusCode && reasonPhrase && headerLines
? [`${reasonPhrase} ${statusCode}\n`, headerLines, '\n\n', body].join('') ? [`${statusCode} ${reasonPhrase}\n`, headerLines, '\n\n', body].join('')
: ''; : '';
}, },
getConstructedRecordedResponse() { getConstructedRecordedResponse() {
...@@ -87,13 +92,11 @@ export default { ...@@ -87,13 +92,11 @@ export default {
status_code: statusCode, status_code: statusCode,
reason_phrase: reasonPhrase, reason_phrase: reasonPhrase,
headers = [], headers = [],
} = this.vulnerability?.supporting_messages?.find( } = this.recordedMessage;
msg => msg.name === SUPPORTING_MESSAGE_TYPES.RECORDED,
).response;
const headerLines = this.getHeadersAsCodeBlockLines(headers); const headerLines = this.getHeadersAsCodeBlockLines(headers);
return statusCode && reasonPhrase && headerLines return statusCode && reasonPhrase && headerLines
? [`${reasonPhrase} ${statusCode}\n`, headerLines, '\n\n', body].join('') ? [`${statusCode} ${reasonPhrase}\n`, headerLines, '\n\n', body].join('')
: ''; : '';
}, },
requestData() { requestData() {
...@@ -123,11 +126,7 @@ export default { ...@@ -123,11 +126,7 @@ export default {
].filter(x => x.content); ].filter(x => x.content);
}, },
recordedResponseData() { recordedResponseData() {
if ( if (!this.recordedMessage) {
!this.vulnerability?.supporting_messages?.find(
msg => msg.name === SUPPORTING_MESSAGE_TYPES.RECORDED,
)
) {
return []; return [];
} }
...@@ -149,6 +148,18 @@ export default { ...@@ -149,6 +148,18 @@ export default {
this.location.operating_system this.location.operating_system
); );
}, },
hasRequest() {
return Boolean(this.requestData.length);
},
hasResponse() {
return Boolean(this.responseData.length);
},
hasRecordedResponse() {
return Boolean(this.recordedResponseData.length);
},
hasResponses() {
return Boolean(this.hasResponse || this.hasRecordedResponse);
},
}, },
methods: { methods: {
getHeadersAsCodeBlockLines(headers) { getHeadersAsCodeBlockLines(headers) {
...@@ -287,7 +298,7 @@ export default { ...@@ -287,7 +298,7 @@ export default {
</ul> </ul>
</template> </template>
<section v-if="requestData.length" data-testid="request"> <section v-if="hasRequest" data-testid="request">
<h3>{{ s__('Vulnerability|Request/Response') }}</h3> <h3>{{ s__('Vulnerability|Request/Response') }}</h3>
<ul> <ul>
<detail-item <detail-item
...@@ -303,10 +314,10 @@ export default { ...@@ -303,10 +314,10 @@ export default {
</ul> </ul>
</section> </section>
<div v-if="responseData.length || recordedResponseData.length" class="row"> <div v-if="hasResponses" class="row">
<section <section
v-if="recordedResponseData.length" v-if="hasRecordedResponse"
:class="responseData.length ? 'col-6' : 'col'" :class="hasResponse ? 'col-6' : 'col'"
data-testid="recorded-response" data-testid="recorded-response"
> >
<ul> <ul>
...@@ -334,8 +345,8 @@ export default { ...@@ -334,8 +345,8 @@ export default {
</section> </section>
<section <section
v-if="responseData.length" v-if="hasResponse"
:class="recordedResponseData.length ? 'col-6' : 'col'" :class="hasRecordedResponse ? 'col-6' : 'col'"
data-testid="response" data-testid="response"
> >
<ul> <ul>
...@@ -347,7 +358,6 @@ export default { ...@@ -347,7 +358,6 @@ export default {
<gl-icon <gl-icon
v-gl-tooltip v-gl-tooltip
name="information-o" name="information-o"
:size="16"
class="gl-hover-cursor-pointer gl-mr-3" class="gl-hover-cursor-pointer gl-mr-3"
:title=" :title="
s__( s__(
...@@ -364,11 +374,11 @@ export default { ...@@ -364,11 +374,11 @@ export default {
</section> </section>
</div> </div>
<template v-if="assert"> <template v-if="assertion">
<h3>{{ __('Additional Info') }}</h3> <h3>{{ s__('Vulnerability|Additional Info') }}</h3>
<ul> <ul>
<detail-item :sprintf-message="__('%{labelStart}Assert:%{labelEnd} %{assert}')" <detail-item :sprintf-message="__('%{labelStart}Assert:%{labelEnd} %{assertion}')"
>{{ assert }} >{{ assertion }}
</detail-item> </detail-item>
</ul> </ul>
</template> </template>
......
...@@ -182,13 +182,13 @@ describe('Vulnerability Details', () => { ...@@ -182,13 +182,13 @@ describe('Vulnerability Details', () => {
const EXPECT_RESPONSE = { const EXPECT_RESPONSE = {
label: 'Actual response:', label: 'Actual response:',
content: 'INTERNAL SERVER ERROR 500\nName1: Value1\nName2: Value2\n\n[{"user_id":1,}]', content: '500 INTERNAL SERVER ERROR\nName1: Value1\nName2: Value2\n\n[{"user_id":1,}]',
isCode: true, isCode: true,
}; };
const EXPECT_RECORDED_RESPONSE = { const EXPECT_RECORDED_RESPONSE = {
label: 'Unmodified response:', label: 'Unmodified response:',
content: 'OK 200\nName1: Value1\nName2: Value2\n\n[{"user_id":1,}]', content: '200 OK\nName1: Value1\nName2: Value2\n\n[{"user_id":1,}]',
isCode: true, isCode: true,
}; };
......
...@@ -535,7 +535,7 @@ msgstr "" ...@@ -535,7 +535,7 @@ msgstr ""
msgid "%{labelStart}Actual response:%{labelEnd} %{headers}" msgid "%{labelStart}Actual response:%{labelEnd} %{headers}"
msgstr "" msgstr ""
msgid "%{labelStart}Assert:%{labelEnd} %{assert}" msgid "%{labelStart}Assert:%{labelEnd} %{assertion}"
msgstr "" msgstr ""
msgid "%{labelStart}Class:%{labelEnd} %{class}" msgid "%{labelStart}Class:%{labelEnd} %{class}"
...@@ -1802,9 +1802,6 @@ msgstr "" ...@@ -1802,9 +1802,6 @@ msgstr ""
msgid "Adding new applications is disabled in your GitLab instance. Please contact your GitLab administrator to get the permission" msgid "Adding new applications is disabled in your GitLab instance. Please contact your GitLab administrator to get the permission"
msgstr "" msgstr ""
msgid "Additional Info"
msgstr ""
msgid "Additional Metadata" msgid "Additional Metadata"
msgstr "" msgstr ""
...@@ -21948,6 +21945,9 @@ msgstr "" ...@@ -21948,6 +21945,9 @@ msgstr ""
msgid "Reconfigure" msgid "Reconfigure"
msgstr "" msgstr ""
msgid "Recorded"
msgstr ""
msgid "Recover hidden stage" msgid "Recover hidden stage"
msgstr "" msgstr ""
...@@ -29703,6 +29703,9 @@ msgstr "" ...@@ -29703,6 +29703,9 @@ msgstr ""
msgid "Vulnerability|Actual received response is the one received when this fault was detected" msgid "Vulnerability|Actual received response is the one received when this fault was detected"
msgstr "" msgstr ""
msgid "Vulnerability|Additional Info"
msgstr ""
msgid "Vulnerability|Class" msgid "Vulnerability|Class"
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