Commit 1e5704bf authored by Fernando's avatar Fernando

Add unit tests

* Update existing tests and add new ones
parent 8e76c5c8
<script> <script>
import { GlLink, GlSprintf, GlTooltipDirective, GlIcon } from '@gitlab/ui'; import { GlLink, GlSprintf, GlTooltipDirective, GlIcon } from '@gitlab/ui';
import { SUPPORTING_MESSAGE_TYPES } from 'ee/vulnerabilities/constants';
import SeverityBadge from 'ee/vue_shared/security_reports/components/severity_badge.vue'; import SeverityBadge from 'ee/vue_shared/security_reports/components/severity_badge.vue';
import CodeBlock from '~/vue_shared/components/code_block.vue'; import CodeBlock from '~/vue_shared/components/code_block.vue';
import { __ } from '~/locale'; import { __ } from '~/locale';
...@@ -63,7 +64,9 @@ export default { ...@@ -63,7 +64,9 @@ export default {
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);
return [`${method} ${url}\n`, headerLines, '\n\n', body].join(''); return method && url && headerLines
? [`${method} ${url}\n`, headerLines, '\n\n', body].join('')
: '';
}, },
getConstructedResponse() { getConstructedResponse() {
const { const {
...@@ -74,7 +77,9 @@ export default { ...@@ -74,7 +77,9 @@ export default {
} = this.vulnerability.response; } = this.vulnerability.response;
const headerLines = this.getHeadersAsCodeBlockLines(headers); const headerLines = this.getHeadersAsCodeBlockLines(headers);
return [`${reasonPhrase} ${statusCode}\n`, headerLines, '\n\n', body].join(''); return statusCode && reasonPhrase && headerLines
? [`${reasonPhrase} ${statusCode}\n`, headerLines, '\n\n', body].join('')
: '';
}, },
getConstructedRecordedResponse() { getConstructedRecordedResponse() {
const { const {
...@@ -82,10 +87,12 @@ export default { ...@@ -82,10 +87,12 @@ export default {
status_code: statusCode, status_code: statusCode,
reason_phrase: reasonPhrase, reason_phrase: reasonPhrase,
headers = [], headers = [],
} = this.vulnerability.supporting_messages[1].response; } = this.vulnerability?.supporting_messages[1].response;
const headerLines = this.getHeadersAsCodeBlockLines(headers); const headerLines = this.getHeadersAsCodeBlockLines(headers);
return [`${reasonPhrase} ${statusCode}\n`, headerLines, '\n\n', body].join(''); return statusCode && reasonPhrase && headerLines
? [`${reasonPhrase} ${statusCode}\n`, headerLines, '\n\n', body].join('')
: '';
}, },
requestData() { requestData() {
if (!this.vulnerability.request) { if (!this.vulnerability.request) {
...@@ -114,13 +121,18 @@ export default { ...@@ -114,13 +121,18 @@ export default {
].filter(x => x.content); ].filter(x => x.content);
}, },
recordedResponseData() { recordedResponseData() {
if (!this.vulnerability.supporting_messages[1].response) { if (
!(
this.vulnerability?.supporting_messages &&
this.vulnerability.supporting_messages[1]?.name === SUPPORTING_MESSAGE_TYPES.RECORDED
)
) {
return []; return [];
} }
return [ return [
{ {
label: __('%{labelStart}Unmodified Response%{labelEnd} %{headers}'), label: __('%{labelStart}Unmodified response:%{labelEnd} %{headers}'),
content: this.getConstructedRecordedResponse, content: this.getConstructedRecordedResponse,
isCode: true, isCode: true,
}, },
...@@ -294,7 +306,7 @@ export default { ...@@ -294,7 +306,7 @@ export default {
<section <section
v-if="recordedResponseData.length" v-if="recordedResponseData.length"
:class="responseData.length ? 'col-6' : 'col'" :class="responseData.length ? 'col-6' : 'col'"
data-testid="response" data-testid="recorded-response"
> >
<ul> <ul>
<detail-item <detail-item
......
import { s__ } from '~/locale'; import { s__, __ } from '~/locale';
export const VULNERABILITY_STATE_OBJECTS = { export const VULNERABILITY_STATE_OBJECTS = {
detected: { detected: {
...@@ -65,3 +65,7 @@ export const REGEXES = { ...@@ -65,3 +65,7 @@ export const REGEXES = {
ISSUE_FORMAT: /^#?(\d+)$/, // Matches '123' and '#123'. ISSUE_FORMAT: /^#?(\d+)$/, // Matches '123' and '#123'.
LINK_FORMAT: /\/(.+\/.+)\/-\/issues\/(\d+)/, // Matches '/username/project/-/issues/123'. LINK_FORMAT: /\/(.+\/.+)\/-\/issues\/(\d+)/, // Matches '/username/project/-/issues/123'.
}; };
export const SUPPORTING_MESSAGE_TYPES = {
RECORDED: __('Recorded'),
};
import { mount } from '@vue/test-utils'; import { mount } from '@vue/test-utils';
import { getAllByRole, getByTestId } from '@testing-library/dom'; import { getAllByRole, getByTestId } from '@testing-library/dom';
import { GlLink } from '@gitlab/ui'; import { GlLink } from '@gitlab/ui';
import { SUPPORTING_MESSAGE_TYPES } from 'ee/vulnerabilities/constants';
import SeverityBadge from 'ee/vue_shared/security_reports/components/severity_badge.vue'; import SeverityBadge from 'ee/vue_shared/security_reports/components/severity_badge.vue';
import VulnerabilityDetails from 'ee/vulnerabilities/components/details.vue'; import VulnerabilityDetails from 'ee/vulnerabilities/components/details.vue';
...@@ -173,10 +174,21 @@ describe('Vulnerability Details', () => { ...@@ -173,10 +174,21 @@ describe('Vulnerability Details', () => {
describe('http data', () => { describe('http data', () => {
const TEST_HEADERS = [{ name: 'Name1', value: 'Value1' }, { name: 'Name2', value: 'Value2' }]; const TEST_HEADERS = [{ name: 'Name1', value: 'Value1' }, { name: 'Name2', value: 'Value2' }];
const TEST_URL = 'http://foo.bar/test'; const EXPECT_REQUEST = {
const EXPECT_HEADERS = { label: 'Sent request:',
label: 'Headers:', content: 'GET http://www.gitlab.com\nName1: Value1\nName2: Value2\n\n[{"user_id":1,}]',
content: 'Name1: Value1\nName2: Value2', isCode: true,
};
const EXPECT_RESPONSE = {
label: 'Actual response:',
content: 'INTERNAL SERVER ERROR 500\nName1: Value1\nName2: Value2\n\n[{"user_id":1,}]',
isCode: true,
};
const EXPECT_RECORDED_RESPONSE = {
label: 'Unmodified response:',
content: 'OK 200\nName1: Value1\nName2: Value2\n\n[{"user_id":1,}]',
isCode: true, isCode: true,
}; };
...@@ -201,11 +213,11 @@ describe('Vulnerability Details', () => { ...@@ -201,11 +213,11 @@ describe('Vulnerability Details', () => {
request | expectedData request | expectedData
${null} | ${null} ${null} | ${null}
${{}} | ${null} ${{}} | ${null}
${{ headers: TEST_HEADERS }} | ${[EXPECT_HEADERS]} ${{ headers: TEST_HEADERS }} | ${null}
${{ headers: TEST_HEADERS, method: 'GET' }} | ${[{ label: 'Method:', content: 'GET' }, EXPECT_HEADERS]} ${{ method: 'GET' }} | ${null}
${{ headers: TEST_HEADERS, method: 'GET', url: TEST_URL }} | ${[{ label: 'Method:', content: 'GET' }, { label: 'URL:', content: TEST_URL }, EXPECT_HEADERS]} ${{ method: 'GET', url: 'http://www.gitlab.com' }} | ${null}
${{ url: TEST_URL }} | ${[{ label: 'URL:', content: TEST_URL }]} ${{ method: 'GET', url: 'http://www.gitlab.com', body: '[{"user_id":1,}]' }} | ${null}
${{ method: 'GET' }} | ${[{ label: 'Method:', content: 'GET' }]} ${{ headers: TEST_HEADERS, method: 'GET', url: 'http://www.gitlab.com', body: '[{"user_id":1,}]' }} | ${[EXPECT_REQUEST]}
`('shows request data for $request', ({ request, expectedData }) => { `('shows request data for $request', ({ request, expectedData }) => {
createWrapper({ request }); createWrapper({ request });
expect(getSectionData('request')).toEqual(expectedData); expect(getSectionData('request')).toEqual(expectedData);
...@@ -215,13 +227,29 @@ describe('Vulnerability Details', () => { ...@@ -215,13 +227,29 @@ describe('Vulnerability Details', () => {
response | expectedData response | expectedData
${null} | ${null} ${null} | ${null}
${{}} | ${null} ${{}} | ${null}
${{ headers: TEST_HEADERS }} | ${[EXPECT_HEADERS]} ${{ headers: TEST_HEADERS }} | ${null}
${{ headers: TEST_HEADERS, status_code: 200 }} | ${[EXPECT_HEADERS]} ${{ headers: TEST_HEADERS, body: '[{"user_id":1,}]' }} | ${null}
${{ headers: TEST_HEADERS, status_code: 200, reason_phrase: 'OK' }} | ${[{ label: 'Status:', content: '200 OK' }, EXPECT_HEADERS]} ${{ headers: TEST_HEADERS, body: '[{"user_id":1,}]', status_code: '500' }} | ${null}
${{ status_code: 400, reason_phrase: 'Something bad' }} | ${[{ label: 'Status:', content: '400 Something bad' }]} ${{ headers: TEST_HEADERS, body: '[{"user_id":1,}]', status_code: '500', reason_phrase: 'INTERNAL SERVER ERROR' }} | ${[EXPECT_RESPONSE]}
`('shows response data for $response', ({ response, expectedData }) => { `('shows response data for $response', ({ response, expectedData }) => {
createWrapper({ response }); createWrapper({ response });
expect(getSectionData('response')).toEqual(expectedData); expect(getSectionData('response')).toEqual(expectedData);
}); });
it.each`
supporting_messages | expectedData
${null} | ${null}
${[]} | ${null}
${[{}]} | ${null}
${[{}, { response: {} }]} | ${null}
${[{}, { response: { headers: TEST_HEADERS } }]} | ${null}
${[{}, { response: { headers: TEST_HEADERS, body: '[{"user_id":1,}]' } }]} | ${null}
${[{}, { response: { headers: TEST_HEADERS, body: '[{"user_id":1,}]', status_code: '200' } }]} | ${null}
${[{}, { response: { headers: TEST_HEADERS, body: '[{"user_id":1,}]', status_code: '200', reason_phrase: 'OK' } }]} | ${null}
${[{}, { name: SUPPORTING_MESSAGE_TYPES.RECORDED, response: { headers: TEST_HEADERS, body: '[{"user_id":1,}]', status_code: '200', reason_phrase: 'OK' } }]} | ${[EXPECT_RECORDED_RESPONSE]}
`('shows response data for $supporting_messages', ({ supporting_messages, expectedData }) => {
createWrapper({ supporting_messages });
expect(getSectionData('recorded-response')).toEqual(expectedData);
});
}); });
}); });
...@@ -532,6 +532,12 @@ msgstr "" ...@@ -532,6 +532,12 @@ msgstr ""
msgid "%{issuesSize} with a limit of %{maxIssueCount}" msgid "%{issuesSize} with a limit of %{maxIssueCount}"
msgstr "" msgstr ""
msgid "%{labelStart}Actual response:%{labelEnd} %{headers}"
msgstr ""
msgid "%{labelStart}Assert:%{labelEnd} %{assert}"
msgstr ""
msgid "%{labelStart}Class:%{labelEnd} %{class}" msgid "%{labelStart}Class:%{labelEnd} %{class}"
msgstr "" msgstr ""
...@@ -547,9 +553,6 @@ msgstr "" ...@@ -547,9 +553,6 @@ msgstr ""
msgid "%{labelStart}File:%{labelEnd} %{file}" msgid "%{labelStart}File:%{labelEnd} %{file}"
msgstr "" msgstr ""
msgid "%{labelStart}Headers:%{labelEnd} %{headers}"
msgstr ""
msgid "%{labelStart}Image:%{labelEnd} %{image}" msgid "%{labelStart}Image:%{labelEnd} %{image}"
msgstr "" msgstr ""
...@@ -565,13 +568,13 @@ msgstr "" ...@@ -565,13 +568,13 @@ msgstr ""
msgid "%{labelStart}Scanner:%{labelEnd} %{scanner}" msgid "%{labelStart}Scanner:%{labelEnd} %{scanner}"
msgstr "" msgstr ""
msgid "%{labelStart}Severity:%{labelEnd} %{severity}" msgid "%{labelStart}Sent request:%{labelEnd} %{headers}"
msgstr "" msgstr ""
msgid "%{labelStart}Status:%{labelEnd} %{status}" msgid "%{labelStart}Severity:%{labelEnd} %{severity}"
msgstr "" msgstr ""
msgid "%{labelStart}URL:%{labelEnd} %{url}" msgid "%{labelStart}Unmodified response:%{labelEnd} %{headers}"
msgstr "" msgstr ""
msgid "%{label_for_message} unavailable" msgid "%{label_for_message} unavailable"
...@@ -1799,6 +1802,9 @@ msgstr "" ...@@ -1799,6 +1802,9 @@ 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 ""
...@@ -29694,6 +29700,9 @@ msgstr "" ...@@ -29694,6 +29700,9 @@ msgstr ""
msgid "Vulnerability|Activity" msgid "Vulnerability|Activity"
msgstr "" msgstr ""
msgid "Vulnerability|Actual received response is the one received when this fault was detected"
msgstr ""
msgid "Vulnerability|Class" msgid "Vulnerability|Class"
msgstr "" msgstr ""
...@@ -29742,10 +29751,7 @@ msgstr "" ...@@ -29742,10 +29751,7 @@ msgstr ""
msgid "Vulnerability|Project" msgid "Vulnerability|Project"
msgstr "" msgstr ""
msgid "Vulnerability|Request" msgid "Vulnerability|Request/Response"
msgstr ""
msgid "Vulnerability|Response"
msgstr "" msgstr ""
msgid "Vulnerability|Scanner" msgid "Vulnerability|Scanner"
...@@ -29760,6 +29766,9 @@ msgstr "" ...@@ -29760,6 +29766,9 @@ msgstr ""
msgid "Vulnerability|Status" msgid "Vulnerability|Status"
msgstr "" msgstr ""
msgid "Vulnerability|The unmodified response is the original response that had no mutations done to the request"
msgstr ""
msgid "Wait for the file to load to copy its contents" msgid "Wait for the file to load to copy its contents"
msgstr "" msgstr ""
...@@ -31240,6 +31249,9 @@ msgstr "" ...@@ -31240,6 +31249,9 @@ msgstr ""
msgid "ciReport|(is loading, errors when loading results)" msgid "ciReport|(is loading, errors when loading results)"
msgstr "" msgstr ""
msgid "ciReport|API Fuzzing"
msgstr ""
msgid "ciReport|All projects" msgid "ciReport|All projects"
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