Commit 1e5704bf authored by Fernando's avatar Fernando

Add unit tests

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