From cbb6c519460fca26d4d309bbb4be7c17e82e78a3 Mon Sep 17 00:00:00 2001 From: Avi Shah Date: Thu, 12 Dec 2024 12:43:36 +0530 Subject: [PATCH] added vulnerable api request response download raw button --- app/components/ak-divider/index.hbs | 18 ++- app/components/ak-divider/index.scss | 14 +++ app/components/ak-divider/index.stories.js | 20 ++++ app/components/ak-divider/index.ts | 7 +- .../edit-analysis-button/index.hbs | 2 +- .../edit-analysis-button/index.scss | 7 -- .../custom-vulnerabilities/index.scss | 2 +- .../findings/index.hbs | 89 +++++++------- .../findings/index.scss | 32 ++--- .../findings/index.ts | 38 ++++-- .../vulnerability-analysis-details/index.hbs | 59 ++++------ .../vulnerability-analysis-details/index.scss | 4 +- app/styles/_component-variables.scss | 3 + .../index-test.js | 109 ++++++++++-------- translations/en.json | 1 + translations/ja.json | 1 + 16 files changed, 234 insertions(+), 172 deletions(-) delete mode 100644 app/components/file-details/vulnerability-analysis-details/edit-analysis-button/index.scss diff --git a/app/components/ak-divider/index.hbs b/app/components/ak-divider/index.hbs index 5109e81b3..54cfba3d6 100644 --- a/app/components/ak-divider/index.hbs +++ b/app/components/ak-divider/index.hbs @@ -1,11 +1,21 @@ {{! @glint-nocheck : or}} -{{#let (element (or @tag 'hr')) as |Tag|}} - +{{else}} + {{#let (element (or @tag 'hr')) as |Tag|}} + -{{/let}} \ No newline at end of file + /> + {{/let}} +{{/if}} \ No newline at end of file diff --git a/app/components/ak-divider/index.scss b/app/components/ak-divider/index.scss index baea08b34..b741354bc 100644 --- a/app/components/ak-divider/index.scss +++ b/app/components/ak-divider/index.scss @@ -20,3 +20,17 @@ .ak-divider-color-dark { border-color: var(--ak-divider-color-dark); } + +.ak-divider-direction-vertical { + width: 1px; + height: auto; + align-self: stretch; +} + +.ak-divider-vertical-color-light { + background-color: var(--ak-divider-color-light); +} + +.ak-divider-vertical-color-dark { + background-color: var(--ak-divider-color-dark); +} \ No newline at end of file diff --git a/app/components/ak-divider/index.stories.js b/app/components/ak-divider/index.stories.js index c1b36410a..4831e0f89 100644 --- a/app/components/ak-divider/index.stories.js +++ b/app/components/ak-divider/index.stories.js @@ -52,3 +52,23 @@ Default.args = { variant: 'fullWidth', color: 'light', }; + +const VerticalTemplate = (args) => ({ + template: hbs` + Experiment with me + +
+ A + + B +
+ `, + context: { ...args }, +}); + +export const Vertical = VerticalTemplate.bind({}); + +Vertical.args = { + color: 'dark', + direction: 'vertical', +}; diff --git a/app/components/ak-divider/index.ts b/app/components/ak-divider/index.ts index fd45c1787..db566a57c 100644 --- a/app/components/ak-divider/index.ts +++ b/app/components/ak-divider/index.ts @@ -6,11 +6,16 @@ export interface AkDividerSignature { tag?: string; variant?: 'fullWidth' | 'middle'; color?: 'light' | 'dark'; + direction?: 'horizontal' | 'vertical'; }; Blocks: { default: [] }; } -export default class AkDividerComponent extends Component {} +export default class AkDividerComponent extends Component { + get isVertical() { + return this.args.direction === 'vertical'; + } +} declare module '@glint/environment-ember-loose/registry' { export default interface Registry { diff --git a/app/components/file-details/vulnerability-analysis-details/edit-analysis-button/index.hbs b/app/components/file-details/vulnerability-analysis-details/edit-analysis-button/index.hbs index faa93bce4..0b61a1a2f 100644 --- a/app/components/file-details/vulnerability-analysis-details/edit-analysis-button/index.hbs +++ b/app/components/file-details/vulnerability-analysis-details/edit-analysis-button/index.hbs @@ -1,7 +1,7 @@ {{#if this.me.org.is_admin}} {{#if (or @analysis.isRisky @analysis.isOverriddenAsPassed)}} -
+ - + - - {{pgc.startItemIdx}} - - - out of - - - {{pgc.totalItems}} - APIs' - - - - - <:leftIcon> + - - - <:default> - {{t 'previous'}} - - + - - <:default> - {{t 'next'}} - + + + {{pgc.startItemIdx}} + + + out of + + + {{pgc.totalItems}} + APIs' + + - <:rightIcon> + - - + + + + + + + + diff --git a/app/components/file-details/vulnerability-analysis-details/findings/index.scss b/app/components/file-details/vulnerability-analysis-details/findings/index.scss index d10a5cf16..2a99d8bb5 100644 --- a/app/components/file-details/vulnerability-analysis-details/findings/index.scss +++ b/app/components/file-details/vulnerability-analysis-details/findings/index.scss @@ -31,7 +31,7 @@ .analysis-content-title { position: sticky; - top: calc(172px + 1.5em); + top: calc(132px + 1.5em); z-index: 1; padding: 1em; background-color: var( @@ -54,14 +54,6 @@ } } -.ak-pagination-button-prev-icon { - margin-right: 0.214em; -} - -.ak-pagination-button-next-icon { - margin-left: 0.214em; -} - .ak-pagination-select { height: 30px !important; } @@ -75,20 +67,30 @@ min-width: unset; padding-left: 0.143em; padding-right: 0.857em; + + &:hover, + &:disabled { + background-color: var( + --file-details-vulnerability-analysis-details-pagination-button-background-color + ) !important; + } } -.ak-pagination-prev-button, .ak-pagination-next-button { - padding-left: 0.357em; - padding-right: 0.357em; + border-left: 1px solid var(--file-details-vulnerability-analysis-details-border-color-2); + border-radius: 0px !important; +} + +.ak-pagination-prev-button { + border-right: 1px solid var(--file-details-vulnerability-analysis-details-border-color-2); + border-radius: 0px !important; } .counter-container { - padding: 0.3em 0.75em; border: 1px solid - var(--file-details-vulnerability-analysis-details-border-color); + var(--file-details-vulnerability-analysis-details-border-color-2); + border-radius: var(--file-details-vulnerability-analysis-details-border-radius); background-color: var( --file-details-vulnerability-analysis-details-code-background-color ); - margin-right: 1em; } diff --git a/app/components/file-details/vulnerability-analysis-details/findings/index.ts b/app/components/file-details/vulnerability-analysis-details/findings/index.ts index 538ca60dd..49b161179 100644 --- a/app/components/file-details/vulnerability-analysis-details/findings/index.ts +++ b/app/components/file-details/vulnerability-analysis-details/findings/index.ts @@ -14,8 +14,6 @@ import { type VulnerableApiFinding, } from 'irene/utils/parse-vulnerable-api-finding'; -import styles from './index.scss'; - export interface FileDetailsVulnerabilityAnalysisDetailsFindingsSignature { Args: { analysis: AnalysisModel; @@ -42,14 +40,6 @@ export default class FileDetailsVulnerabilityAnalysisDetailsFindingsComponent ex this.parseCustomAndApiVulnerableFindings.perform(); } - get classes() { - return { - selectClass: styles['ak-pagination-select'], - prevButtonIconClass: styles['ak-pagination-button-prev-icon'], - nextButtonIconClass: styles['ak-pagination-button-next-icon'], - }; - } - get analysis() { return this.args.analysis; } @@ -73,6 +63,13 @@ export default class FileDetailsVulnerabilityAnalysisDetailsFindingsComponent ex ); } + get rawText() { + return this.analysis.findings + .map((finding) => finding.description) + .filter(Boolean) + .join('\n'); + } + @action handlePrevNextClick({ limit, offset }: { limit: number; offset: number }) { this.limit = limit; @@ -98,6 +95,27 @@ export default class FileDetailsVulnerabilityAnalysisDetailsFindingsComponent ex this.customVulnerableFindings = customVulnerableFindings; this.vulnerableApiFindings = vulnerableApiFindings; }); + + downloadRawText = task(async () => { + // Create a Blob with the raw text + const blob = new Blob([this.rawText], { type: 'text/plain' }); + + // Create a download link + const link = document.createElement('a'); + link.href = URL.createObjectURL(blob); + + // Generate a filename + const timestamp = new Date().toISOString().replace(/:/g, '-').split('.')[0]; + link.download = `analysis_raw_text_${timestamp}.txt`; + + // Append to body, click, and remove + document.body.appendChild(link); + link.click(); + document.body.removeChild(link); + + // Clean up the URL object + URL.revokeObjectURL(link.href); + }); } declare module '@glint/environment-ember-loose/registry' { diff --git a/app/components/file-details/vulnerability-analysis-details/index.hbs b/app/components/file-details/vulnerability-analysis-details/index.hbs index 14253dcb1..5550c03be 100644 --- a/app/components/file-details/vulnerability-analysis-details/index.hbs +++ b/app/components/file-details/vulnerability-analysis-details/index.hbs @@ -10,48 +10,29 @@ data-test-vulnerabilityAnalysisDetails-breadcrumbContainer /> - - - + + - - {{t 'testCase'}} - + {{@analysis.vulnerability.name}} + - - {{@analysis.vulnerability.name}} - - + - - - {{t 'typeOfScan'}} - - - - + diff --git a/app/components/file-details/vulnerability-analysis-details/index.scss b/app/components/file-details/vulnerability-analysis-details/index.scss index 32f8f42f7..b067e39e1 100644 --- a/app/components/file-details/vulnerability-analysis-details/index.scss +++ b/app/components/file-details/vulnerability-analysis-details/index.scss @@ -40,7 +40,7 @@ .analysis-details-header-container { display: flex; flex-direction: column; - height: 130px; + height: 90px; justify-content: space-between; } @@ -102,7 +102,7 @@ width: 100%; padding: 1em; position: sticky; - top: calc(172px + 1.5em); + top: calc(132px + 1.5em); z-index: 1; background-color: var( --file-details-vulnerability-analysis-details-background-main diff --git a/app/styles/_component-variables.scss b/app/styles/_component-variables.scss index ad60f6041..32e1f187a 100644 --- a/app/styles/_component-variables.scss +++ b/app/styles/_component-variables.scss @@ -1115,6 +1115,9 @@ body { --file-details-vulnerability-analysis-details-border-color: var( --border-color-1 ); + --file-details-vulnerability-analysis-details-border-color-2: var( + --border-color-2 + ); // variables for file-details/vulnerability-analysis-details/findings/vulnerable-api --file-details-vulnerability-analysis-details-findings-vulnerable-api-color-primary: var( diff --git a/tests/integration/components/file-details/vulnerability-analysis-details/index-test.js b/tests/integration/components/file-details/vulnerability-analysis-details/index-test.js index 342329e8b..69ed04d95 100644 --- a/tests/integration/components/file-details/vulnerability-analysis-details/index-test.js +++ b/tests/integration/components/file-details/vulnerability-analysis-details/index-test.js @@ -115,49 +115,6 @@ module( this.owner.register('service:browser/window', WindowStub); }); - this.headerAssertions = (assert, analysis) => { - const headerSummary = [ - { - title: t('testCase'), - assertValue: (container) => { - assert - .dom('[data-test-analysisDetails-headerSummaryValue]', container) - .hasText(analysis.vulnerability.get('name')); - }, - }, - { - title: t('typeOfScan'), - assertValue: (container) => { - analysis.vulnerabilityTypes.forEach((vt, i) => { - assert - .dom( - container.querySelectorAll( - '[data-test-vulnerability-analysis-scanTypeTag]' - )[i] - ) - .hasText(t(vulnerabilityTypeTextMap[vt])); - }); - }, - }, - ]; - - headerSummary.forEach((summary) => { - const container = find( - `[data-test-analysisDetails-headerSummaryGroup="${summary.title}"]` - ); - - assert - .dom('[data-test-analysisDetails-headerSummaryTitle]', container) - .hasText(summary.title); - - summary.assertValue(container); - }); - - assert.dom( - `[data-test-analysisRiskTag-root='${getRiskStatusObj(analysis.computedRisk, analysis.status, analysis.isOverriddenRisk).label}']` - ); - }; - // eslint-disable-next-line qunit/require-expect test('it renders analysis details header', async function (assert) { this.set('analysis', this.file.analyses.toArray()[0]); @@ -241,7 +198,27 @@ module( assert.dom('[data-test-analysisDetails-header]').exists(); - this.headerAssertions(assert, this.analysis); + assert + .dom('[data-test-analysisDetails-headerSummaryValue]') + .hasText(this.analysis.vulnerability.get('name')); + + assert.dom( + `[data-test-analysisRiskTag-root='${getRiskStatusObj(this.analysis.computedRisk, this.analysis.status, this.analysis.isOverriddenRisk).label}']` + ); + + const container = document.querySelector( + '[data-test-analysisDetails-headerSummaryContainer]' + ); + + this.analysis.vulnerabilityTypes.forEach((vt, i) => { + assert + .dom( + container.querySelectorAll( + '[data-test-vulnerability-analysis-scanTypeTag]' + )[i] + ) + .hasText(t(vulnerabilityTypeTextMap[vt])); + }); }); test.each( @@ -877,7 +854,27 @@ module( assert.dom('[data-test-analysisDetails-header]').exists(); - this.headerAssertions(assert, this.analysis); + assert + .dom('[data-test-analysisDetails-headerSummaryValue]') + .hasText(analysis.vulnerability.get('name')); + + assert.dom( + `[data-test-analysisRiskTag-root='${getRiskStatusObj(analysis.computedRisk, analysis.status, analysis.isOverriddenRisk).label}']` + ); + + const container = document.querySelector( + '[data-test-analysisDetails-headerSummaryContainer]' + ); + + analysis.vulnerabilityTypes.forEach((vt, i) => { + assert + .dom( + container.querySelectorAll( + '[data-test-vulnerability-analysis-scanTypeTag]' + )[i] + ) + .hasText(t(vulnerabilityTypeTextMap[vt])); + }); assert .dom('[data-test-analysisDetails-regulatory="cvssv3"]') @@ -933,7 +930,27 @@ module( assert.dom('[data-test-analysisDetails-header]').exists(); - this.headerAssertions(assert, this.analysis); + assert + .dom('[data-test-analysisDetails-headerSummaryValue]') + .hasText(analysis.vulnerability.get('name')); + + assert.dom( + `[data-test-analysisRiskTag-root='${getRiskStatusObj(analysis.computedRisk, analysis.status, analysis.isOverriddenRisk).label}']` + ); + + const container = document.querySelector( + '[data-test-analysisDetails-headerSummaryContainer]' + ); + + analysis.vulnerabilityTypes.forEach((vt, i) => { + assert + .dom( + container.querySelectorAll( + '[data-test-vulnerability-analysis-scanTypeTag]' + )[i] + ) + .hasText(t(vulnerabilityTypeTextMap[vt])); + }); assert .dom('[data-test-analysisDetails-regulatory="cvssv3"]') diff --git a/translations/en.json b/translations/en.json index 7b1633c2a..b9efb371c 100644 --- a/translations/en.json +++ b/translations/en.json @@ -370,6 +370,7 @@ "download": "Download", "downloadClientsStatData": "Download Clients Statistics Data", "downloadPrevReport": "Download Previous Report", + "downloadRawFile": "Download Raw File", "downloadReport": "Download Report", "downloadUrlNotFound": "Couldn't download the report!", "dragDropFile": "Drag & drop file", diff --git a/translations/ja.json b/translations/ja.json index 301ca6290..c2cb584ba 100644 --- a/translations/ja.json +++ b/translations/ja.json @@ -370,6 +370,7 @@ "download": "ダウンロード", "downloadClientsStatData": "Download Clients Statistics Data", "downloadPrevReport": "Download Previous Report", + "downloadRawFile": "Download Raw File", "downloadReport": "Download Report", "downloadUrlNotFound": "Couldn't download the report!", "dragDropFile": "Drag & drop file",