From 3ca1ccc48b5c9fdb5ca7add6d9c59cf491a1506e Mon Sep 17 00:00:00 2001 From: jdalton Date: Mon, 9 Nov 2026 12:22:37 -0500 Subject: [PATCH] fix(scan): grade reports from alert actions --- requirements.json | 4 +- src/commands/scan/cmd-scan-report.test.mts | 4 +- src/commands/scan/fetch-report-data.mts | 173 ++---------- src/commands/scan/fetch-report-data.test.mts | 66 +++++ src/commands/scan/generate-report.mts | 61 ++--- src/commands/scan/generate-report.test.mts | 256 ++++++++---------- src/commands/scan/output-scan-report.mts | 3 - src/commands/scan/output-scan-report.test.mts | 4 +- 8 files changed, 230 insertions(+), 341 deletions(-) create mode 100644 src/commands/scan/fetch-report-data.test.mts diff --git a/requirements.json b/requirements.json index 9b858f4e81..bf47e89677 100644 --- a/requirements.json +++ b/requirements.json @@ -101,8 +101,8 @@ "permissions": ["full-scans:create"] }, "scan:report": { - "quota": 2, - "permissions": ["full-scans:list", "security-policy:read"] + "quota": 1, + "permissions": ["full-scans:list"] }, "scan:view": { "quota": 1, diff --git a/src/commands/scan/cmd-scan-report.test.mts b/src/commands/scan/cmd-scan-report.test.mts index ec8b6f4728..bffcc256ae 100644 --- a/src/commands/scan/cmd-scan-report.test.mts +++ b/src/commands/scan/cmd-scan-report.test.mts @@ -26,8 +26,8 @@ describe('socket scan report', async () => { $ socket scan report [options] [OUTPUT_PATH] API Token Requirements - - Quota: 2 units - - Permissions: full-scans:list and security-policy:read + - Quota: 1 unit + - Permissions: full-scans:list Options --fold Fold reported alerts to some degree (default 'none') diff --git a/src/commands/scan/fetch-report-data.mts b/src/commands/scan/fetch-report-data.mts index 175dfa81e9..6884fbbdcf 100644 --- a/src/commands/scan/fetch-report-data.mts +++ b/src/commands/scan/fetch-report-data.mts @@ -2,179 +2,66 @@ import { debugDir, debugFn } from '@socketsecurity/registry/lib/debug' import { logger } from '@socketsecurity/registry/lib/logger' import constants from '../../constants.mts' -import { handleApiCallNoSpinner, queryApiSafeText } from '../../utils/api.mts' +import { queryApiSafeText } from '../../utils/api.mts' import { formatErrorWithDetail } from '../../utils/errors.mts' -import { setupSdk } from '../../utils/sdk.mts' import type { CResult } from '../../types.mts' import type { SocketArtifact } from '../../utils/alert/artifact.mts' -import type { SetupSdkOptions } from '../../utils/sdk.mts' -import type { SocketSdkSuccessResult } from '@socketsecurity/sdk' export type FetchScanData = { includeLicensePolicy?: boolean | undefined - sdkOpts?: SetupSdkOptions | undefined } -/** - * This fetches all the relevant pieces of data to generate a report, given a - * full scan ID. - */ +/** Fetch the scan data needed to generate a report. */ export async function fetchScanData( orgSlug: string, scanId: string, options?: FetchScanData | undefined, -): Promise< - CResult<{ - scan: SocketArtifact[] - securityPolicy: SocketSdkSuccessResult<'getOrgSecurityPolicy'>['data'] - }> -> { - const { includeLicensePolicy, sdkOpts } = { - __proto__: null, - ...options, - } as FetchScanData - const sockSdkCResult = await setupSdk(sdkOpts) - if (!sockSdkCResult.ok) { - return sockSdkCResult - } - const sockSdk = sockSdkCResult.data - - let policyStatus = 'requested...' - let scanStatus = 'requested...' - let finishedFetching = false - +): Promise> { const { spinner } = constants + spinner.start('Scan result: requested...') - function updateScan(status: string) { - scanStatus = status - updateProgress() - } - - function updatePolicy(status: string) { - policyStatus = status - updateProgress() - } - - function updateProgress() { - if (finishedFetching) { - spinner.stop() - logger.info( - `Scan result: ${scanStatus}. Security policy: ${policyStatus}.`, - ) - } else { - spinner.start( - `Scan result: ${scanStatus}. Security policy: ${policyStatus}.`, - ) - } - } - - async function fetchScanResult(): Promise> { + try { const result = await queryApiSafeText( - `orgs/${orgSlug}/full-scans/${encodeURIComponent(scanId)}${includeLicensePolicy ? '?include_license_details=true' : ''}`, + `orgs/${orgSlug}/full-scans/${encodeURIComponent(scanId)}${options?.includeLicensePolicy ? '?include_license_details=true' : ''}`, ) - updateScan(`response received`) - if (!result.ok) { + spinner.stop() + logger.info('Scan result: request failed.') return result } - const ndJsonString = result.data - - // This is nd-json; each line is a json object. - const lines = ndJsonString.split('\n').filter(Boolean) - let ok = true - const data = lines.map(line => { + const data: SocketArtifact[] = [] + for (const line of result.data.split('\n').filter(Boolean)) { try { - return JSON.parse(line) - } catch (e) { - ok = false + data.push(JSON.parse(line)) + } catch (error) { debugFn('error', 'Failed to parse report data line as JSON') - debugDir('error', { error: e, line }) - return + debugDir('error', { error, line }) + spinner.stop() + logger.info('Scan result: received invalid JSON response.') + return { + ok: false, + message: 'Invalid Socket API response', + cause: + 'The Socket API responded with at least one line that was not valid JSON. Please report if this persists.', + } } - }) as unknown as SocketArtifact[] - - if (ok) { - updateScan('success') - return { ok: true, data } } - updateScan('received invalid JSON response') - + spinner.stop() + logger.info('Scan result: success.') + return { ok: true, data: { scan: data } } + } catch (error) { + spinner.stop() + logger.info('Scan result: request failed.') return { ok: false, - message: 'Invalid Socket API response', + message: 'Socket API error', cause: - 'The Socket API responded with at least one line that was not valid JSON. Please report if this persists.', + formatErrorWithDetail('Error requesting scan', error) || + 'Error requesting scan: (no error message found)', } } - - async function fetchSecurityPolicy(): Promise< - CResult['data']> - > { - const result = await handleApiCallNoSpinner( - sockSdk.getOrgSecurityPolicy(orgSlug), - 'GetOrgSecurityPolicy', - ) - - updatePolicy('received policy') - - return result - } - - updateProgress() - - const [scan, securityPolicy]: [ - CResult, - CResult['data']>, - ] = await Promise.all([ - fetchScanResult().catch(e => { - updateScan('failure; unknown blocking error occurred') - return { - ok: false as const, - message: 'Socket API error', - cause: - formatErrorWithDetail('Error requesting scan', e) || - 'Error requesting scan: (no error message found)', - } - }), - fetchSecurityPolicy().catch(e => { - updatePolicy('failure; unknown blocking error occurred') - return { - ok: false as const, - message: 'Socket API error', - cause: - formatErrorWithDetail('Error requesting policy', e) || - 'Error requesting policy: (no error message found)', - } - }), - ]).finally(() => { - finishedFetching = true - updateProgress() - }) - - if (!scan.ok) { - return scan - } - if (!securityPolicy.ok) { - return securityPolicy - } - - if (!Array.isArray(scan.data)) { - return { - ok: false, - message: 'Failed to fetch', - cause: 'Was unable to fetch scan result, bailing', - } - } - - return { - ok: true, - data: { - scan: scan.data satisfies SocketArtifact[], - securityPolicy: securityPolicy.data, - }, - } } diff --git a/src/commands/scan/fetch-report-data.test.mts b/src/commands/scan/fetch-report-data.test.mts new file mode 100644 index 0000000000..5aeecc952d --- /dev/null +++ b/src/commands/scan/fetch-report-data.test.mts @@ -0,0 +1,66 @@ +process.env['SOCKET_CLI_API_TOKEN'] = 'test-token' +process.env['SOCKET_CLI_API_BASE_URL'] = 'https://api.socket.dev/v0/' + +import nock from 'nock' +import { afterEach, beforeEach, describe, expect, it } from 'vitest' + +import { fetchScanData } from './fetch-report-data.mts' + +const BASE_HOST = 'https://api.socket.dev' + +describe('fetchScanData', () => { + beforeEach(() => { + nock.cleanAll() + nock.disableNetConnect() + }) + + afterEach(() => { + nock.cleanAll() + nock.enableNetConnect() + }) + + it('fetches scan alerts with resolved actions without requesting policy', async () => { + nock(BASE_HOST) + .get('/v0/orgs/test-org/full-scans/scan-1') + .reply( + 200, + `${JSON.stringify({ + type: 'npm', + name: 'lodash', + version: '4.17.21', + alerts: [{ type: 'envVars', action: 'error' }], + })}\n`, + ) + + const result = await fetchScanData('test-org', 'scan-1') + + expect(result).toEqual({ + ok: true, + data: { + scan: [ + { + type: 'npm', + name: 'lodash', + version: '4.17.21', + alerts: [{ type: 'envVars', action: 'error' }], + }, + ], + }, + }) + expect(nock.isDone()).toBe(true) + }) + + it('requests license details when the license option is enabled', async () => { + nock(BASE_HOST) + .get('/v0/orgs/test-org/full-scans/scan-2') + .query({ include_license_details: 'true' }) + .reply(200, '') + + const result = await fetchScanData('test-org', 'scan-2', { + includeLicensePolicy: true, + }) + + expect(result).toEqual({ ok: true, data: { scan: [] } }) + expect(nock.isDone()).toBe(true) + }) +}) diff --git a/src/commands/scan/generate-report.mts b/src/commands/scan/generate-report.mts index ecbc42fd05..f3fd17e988 100644 --- a/src/commands/scan/generate-report.mts +++ b/src/commands/scan/generate-report.mts @@ -3,9 +3,8 @@ import { getSocketDevPackageOverviewUrlFromPurl } from '../../utils/socket-url.m import type { FOLD_SETTING, REPORT_LEVEL } from './types.mts' import type { CResult } from '../../types.mts' -import type { SocketArtifact } from '../../utils/alert/artifact.mts' +import type { ALERT_ACTION, SocketArtifact } from '../../utils/alert/artifact.mts' import type { Spinner } from '@socketsecurity/registry/lib/spinner' -import type { SocketSdkSuccessResult } from '@socketsecurity/sdk' type AlertKey = string type EcoMap = Map @@ -40,7 +39,6 @@ export type ReportLeafNode = { // failed. It won't reflect the healthy state. export function generateReport( scan: SocketArtifact[], - securityPolicy: SocketSdkSuccessResult<'getOrgSecurityPolicy'>['data'], { fold, orgSlug, @@ -72,7 +70,7 @@ export function generateReport( // In the context of a report; // - the alert.severity is irrelevant - // - the securityPolicyDefault is irrelevant + // - policy defaults are irrelevant because the API resolves actions per alert // - the report defaults to healthy:true with no alerts // - the appearance of an alert will trigger the policy action; // - error: healthy will end up as false, add alerts to report @@ -92,22 +90,19 @@ export function generateReport( let healthy = true - const securityRules = securityPolicy.securityPolicyRules - if (securityRules) { - // Note: reportLevel: error > warn > monitor > ignore > defer - scan.forEach(artifact => { - const { - alerts, - name: pkgName = UNKNOWN_VALUE, - type: ecosystem, - version = UNKNOWN_VALUE, - } = artifact + // Note: reportLevel: error > warn > monitor > ignore > defer + scan.forEach(artifact => { + const { + alerts, + name: pkgName = UNKNOWN_VALUE, + type: ecosystem, + version = UNKNOWN_VALUE, + } = artifact - alerts?.forEach( - (alert: NonNullable[number]) => { - const alertName = alert.type as keyof typeof securityRules // => policy[type] - const action = securityRules[alertName]?.action || '' - switch (action) { + alerts?.forEach( + (alert: NonNullable[number]) => { + const action = alert.action as ALERT_ACTION | undefined + switch (action) { case constants.REPORT_LEVEL_ERROR: { healthy = false if (!short) { @@ -180,31 +175,13 @@ export function generateReport( break } - case constants.REPORT_LEVEL_DEFER: { - // Not sure but ignore for now. Defer to later ;) - if (!short && reportLevel === constants.REPORT_LEVEL_DEFER) { - addAlert( - artifact, - violations, - fold, - ecosystem, - pkgName, - version, - alert, - action, - ) - } - break - } - default: { - // This value was not emitted from the Socket API at the time of writing. + // Alerts without a resolved policy action are not reportable. } - } - }, - ) - }) - } + } + }, + ) + }) spinner?.successAndStop(`Generated reported in ${Date.now() - now} ms`) diff --git a/src/commands/scan/generate-report.test.mts b/src/commands/scan/generate-report.test.mts index 5e36e1119d..b8a476c6e9 100644 --- a/src/commands/scan/generate-report.test.mts +++ b/src/commands/scan/generate-report.test.mts @@ -1,25 +1,67 @@ import { describe, expect, it } from 'vitest' import { generateReport } from './generate-report.mts' -import { SocketArtifact } from '../../utils/alert/artifact.mts' import type { ScanReport } from './generate-report.mts' +import type { SocketArtifact } from '../../utils/alert/artifact.mts' import type { SocketSdkSuccessResult } from '@socketsecurity/sdk' type SecurityPolicyData = SocketSdkSuccessResult<'getOrgSecurityPolicy'>['data'] +// Existing fixtures model the policy response; translate it into the resolved +// per-alert actions returned by the full-scan API before exercising the report. +function withAlertActions( + scan: SocketArtifact[], + policy: SecurityPolicyData, +): SocketArtifact[] { + const rules = policy.securityPolicyRules as + | Record + | undefined + return scan.map(artifact => ({ + ...artifact, + alerts: artifact.alerts?.flatMap(alert => { + const action = rules?.[alert.type]?.action + return action ? [{ ...alert, action }] : [] + }), + })) +} + describe('generate-report', () => { + it('grades alerts using the resolved action on each alert', () => { + const scan = getScanWithEnvVars().map(artifact => ({ + ...artifact, + alerts: artifact.alerts?.map(alert => ({ ...alert, action: 'error' as const })), + })) + + const result = generateReport(scan, { + orgSlug: 'fakeOrg', + scanId: 'scan-ai-dee', + fold: 'none', + reportLevel: 'warn', + }) + + expect(result.ok && result.data.healthy).toBe(false) + }) + + it('skips alerts that have no resolved action', () => { + const result = generateReport(getScanWithEnvVars(), { + orgSlug: 'fakeOrg', + scanId: 'scan-ai-dee', + fold: 'none', + reportLevel: 'warn', + }) + + expect(result.ok && result.data.healthy).toBe(true) + expect(result.ok && 'alerts' in result.data && result.data.alerts.size).toBe(0) + }) + it('should accept empty args', () => { - const result = generateReport( - [], - { securityPolicyRules: [] } as SecurityPolicyData, - { + const result = generateReport(withAlertActions([], { securityPolicyRules: [] } as SecurityPolicyData), { orgSlug: 'fakeOrg', scanId: 'scan-ai-dee', fold: 'none', reportLevel: 'warn', - }, - ) + }) expect(result).toMatchInlineSnapshot(` { @@ -41,23 +83,19 @@ describe('generate-report', () => { describe('report shape', () => { describe('report-level=warn', () => { it('should return a healthy report without alerts when there are no violations', () => { - const result = generateReport( - getSimpleCleanScan(), - { + const result = generateReport(withAlertActions(getSimpleCleanScan(), { securityPolicyRules: { gptSecurity: { action: 'ignore', }, }, securityPolicyDefault: 'medium', - }, - { + }), { orgSlug: 'fakeOrg', scanId: 'scan-ai-dee', fold: 'none', reportLevel: 'warn', - }, - ) + }) expect(result).toMatchInlineSnapshot(` { @@ -80,23 +118,19 @@ describe('generate-report', () => { }) it('should return a sick report with alert when an alert violates at error', () => { - const result = generateReport( - getScanWithEnvVars(), - { + const result = generateReport(withAlertActions(getScanWithEnvVars(), { securityPolicyRules: { envVars: { action: 'error', }, }, securityPolicyDefault: 'medium', - }, - { + }), { orgSlug: 'fakeOrg', scanId: 'scan-ai-dee', fold: 'none', reportLevel: 'warn', - }, - ) + }) expect(result).toMatchInlineSnapshot(` { @@ -147,23 +181,19 @@ describe('generate-report', () => { }) it('should return a healthy report with alert when an alert violates at warn', () => { - const result = generateReport( - getScanWithEnvVars(), - { + const result = generateReport(withAlertActions(getScanWithEnvVars(), { securityPolicyRules: { envVars: { action: 'warn', }, }, securityPolicyDefault: 'medium', - }, - { + }), { orgSlug: 'fakeOrg', scanId: 'scan-ai-dee', fold: 'none', reportLevel: 'warn', - }, - ) + }) expect(result).toMatchInlineSnapshot(` { @@ -211,23 +241,19 @@ describe('generate-report', () => { }) it('should return a healthy report without alerts when an alert violates at monitor', () => { - const result = generateReport( - getScanWithEnvVars(), - { + const result = generateReport(withAlertActions(getScanWithEnvVars(), { securityPolicyRules: { envVars: { action: 'monitor', }, }, securityPolicyDefault: 'medium', - }, - { + }), { orgSlug: 'fakeOrg', scanId: 'scan-ai-dee', fold: 'none', reportLevel: 'warn', - }, - ) + }) expect(result).toMatchInlineSnapshot(` { @@ -250,23 +276,19 @@ describe('generate-report', () => { }) it('should return a healthy report without alerts when an alert violates at ignore', () => { - const result = generateReport( - getScanWithEnvVars(), - { + const result = generateReport(withAlertActions(getScanWithEnvVars(), { securityPolicyRules: { envVars: { action: 'ignore', }, }, securityPolicyDefault: 'medium', - }, - { + }), { orgSlug: 'fakeOrg', scanId: 'scan-ai-dee', fold: 'none', reportLevel: 'warn', - }, - ) + }) expect(result).toMatchInlineSnapshot(` { @@ -289,23 +311,19 @@ describe('generate-report', () => { }) it('should return a healthy report without alerts when an alert violates at defer', () => { - const result = generateReport( - getScanWithEnvVars(), - { + const result = generateReport(withAlertActions(getScanWithEnvVars(), { securityPolicyRules: { envVars: { action: 'defer', }, }, securityPolicyDefault: 'medium', - }, - { + }), { orgSlug: 'fakeOrg', scanId: 'scan-ai-dee', fold: 'none', reportLevel: 'warn', - }, - ) + }) expect(result).toMatchInlineSnapshot(` { @@ -328,21 +346,17 @@ describe('generate-report', () => { }) it('should return a healthy report without alerts when an alert has no policy value', () => { - const result = generateReport( - getScanWithEnvVars(), - { + const result = generateReport(withAlertActions(getScanWithEnvVars(), { securityPolicyRules: { envVars: {}, }, securityPolicyDefault: 'medium', - } as SecurityPolicyData, - { + } as SecurityPolicyData), { orgSlug: 'fakeOrg', scanId: 'scan-ai-dee', fold: 'none', reportLevel: 'warn', - }, - ) + }) expect(result).toMatchInlineSnapshot(` { @@ -365,19 +379,15 @@ describe('generate-report', () => { }) it('should return a healthy report without alerts when an alert has no policy entry', () => { - const result = generateReport( - getScanWithEnvVars(), - { + const result = generateReport(withAlertActions(getScanWithEnvVars(), { securityPolicyRules: {}, securityPolicyDefault: 'medium', - }, - { + }), { orgSlug: 'fakeOrg', scanId: 'scan-ai-dee', fold: 'none', reportLevel: 'warn', - }, - ) + }) expect(result).toMatchInlineSnapshot(` { @@ -402,23 +412,19 @@ describe('generate-report', () => { describe('report-level=ignore', () => { it('should return a healthy report without alerts when there are no violations', () => { - const result = generateReport( - getSimpleCleanScan(), - { + const result = generateReport(withAlertActions(getSimpleCleanScan(), { securityPolicyRules: { gptSecurity: { action: 'ignore', }, }, securityPolicyDefault: 'medium', - }, - { + }), { orgSlug: 'fakeOrg', scanId: 'scan-ai-dee', fold: 'none', reportLevel: 'ignore', - }, - ) + }) expect(result).toMatchInlineSnapshot(` { @@ -441,23 +447,19 @@ describe('generate-report', () => { }) it('should return a sick report with alert when an alert violates at error', () => { - const result = generateReport( - getScanWithEnvVars(), - { + const result = generateReport(withAlertActions(getScanWithEnvVars(), { securityPolicyRules: { envVars: { action: 'error', }, }, securityPolicyDefault: 'medium', - }, - { + }), { orgSlug: 'fakeOrg', scanId: 'scan-ai-dee', fold: 'none', reportLevel: 'ignore', - }, - ) + }) expect(result).toMatchInlineSnapshot(` { @@ -506,23 +508,19 @@ describe('generate-report', () => { }) it('should return a healthy report with alert when an alert violates at warn', () => { - const result = generateReport( - getScanWithEnvVars(), - { + const result = generateReport(withAlertActions(getScanWithEnvVars(), { securityPolicyRules: { envVars: { action: 'warn', }, }, securityPolicyDefault: 'medium', - }, - { + }), { orgSlug: 'fakeOrg', scanId: 'scan-ai-dee', fold: 'none', reportLevel: 'ignore', - }, - ) + }) expect(result).toMatchInlineSnapshot(` { @@ -570,23 +568,19 @@ describe('generate-report', () => { }) it('should return a healthy report with alert when an alert violates at monitor', () => { - const result = generateReport( - getScanWithEnvVars(), - { + const result = generateReport(withAlertActions(getScanWithEnvVars(), { securityPolicyRules: { envVars: { action: 'monitor', }, }, securityPolicyDefault: 'medium', - }, - { + }), { orgSlug: 'fakeOrg', scanId: 'scan-ai-dee', fold: 'none', reportLevel: 'ignore', - }, - ) + }) expect(result).toMatchInlineSnapshot(` { @@ -634,23 +628,19 @@ describe('generate-report', () => { }) it('should return a healthy report with alert when an alert violates at ignore', () => { - const result = generateReport( - getScanWithEnvVars(), - { + const result = generateReport(withAlertActions(getScanWithEnvVars(), { securityPolicyRules: { envVars: { action: 'ignore', }, }, securityPolicyDefault: 'medium', - }, - { + }), { orgSlug: 'fakeOrg', scanId: 'scan-ai-dee', fold: 'none', reportLevel: 'ignore', - }, - ) + }) expect(result).toMatchInlineSnapshot(` { @@ -698,23 +688,19 @@ describe('generate-report', () => { }) it('should return a healthy report without alerts when an alert violates at defer', () => { - const result = generateReport( - getScanWithEnvVars(), - { + const result = generateReport(withAlertActions(getScanWithEnvVars(), { securityPolicyRules: { envVars: { action: 'defer', }, }, securityPolicyDefault: 'medium', - }, - { + }), { orgSlug: 'fakeOrg', scanId: 'scan-ai-dee', fold: 'none', reportLevel: 'ignore', - }, - ) + }) expect(result).toMatchInlineSnapshot(` { @@ -737,21 +723,17 @@ describe('generate-report', () => { }) it('should return a healthy report without alerts when an alert has no policy value', () => { - const result = generateReport( - getScanWithEnvVars(), - { + const result = generateReport(withAlertActions(getScanWithEnvVars(), { securityPolicyRules: { envVars: {}, }, securityPolicyDefault: 'medium', - } as SecurityPolicyData, - { + } as SecurityPolicyData), { orgSlug: 'fakeOrg', scanId: 'scan-ai-dee', fold: 'none', reportLevel: 'ignore', - }, - ) + }) expect(result).toMatchInlineSnapshot(` { @@ -774,19 +756,15 @@ describe('generate-report', () => { }) it('should return a healthy report without alerts when an alert has no policy entry', () => { - const result = generateReport( - getScanWithEnvVars(), - { + const result = generateReport(withAlertActions(getScanWithEnvVars(), { securityPolicyRules: {}, securityPolicyDefault: 'medium', - }, - { + }), { orgSlug: 'fakeOrg', scanId: 'scan-ai-dee', fold: 'none', reportLevel: 'ignore', - }, - ) + }) expect(result).toMatchInlineSnapshot(` { @@ -812,23 +790,19 @@ describe('generate-report', () => { describe('fold', () => { it('should not fold anything when fold=none', () => { - const result = generateReport( - getScanWithEnvVars(), - { + const result = generateReport(withAlertActions(getScanWithEnvVars(), { securityPolicyRules: { envVars: { action: 'error', }, }, securityPolicyDefault: 'medium', - }, - { + }), { orgSlug: 'fakeOrg', scanId: 'scan-ai-dee', fold: 'none', reportLevel: 'warn', - }, - ) + }) expect(result).toMatchInlineSnapshot(` { @@ -874,23 +848,19 @@ describe('generate-report', () => { }) it('should fold the file locations when fold=file', () => { - const result = generateReport( - getScanWithEnvVars(), - { + const result = generateReport(withAlertActions(getScanWithEnvVars(), { securityPolicyRules: { envVars: { action: 'error', }, }, securityPolicyDefault: 'medium', - }, - { + }), { orgSlug: 'fakeOrg', scanId: 'scan-ai-dee', fold: 'file', reportLevel: 'warn', - }, - ) + }) expect(result).toMatchInlineSnapshot(` { @@ -926,23 +896,19 @@ describe('generate-report', () => { }) it('should fold the files up when fold=version', () => { - const result = generateReport( - getScanWithEnvVars(), - { + const result = generateReport(withAlertActions(getScanWithEnvVars(), { securityPolicyRules: { envVars: { action: 'error', }, }, securityPolicyDefault: 'medium', - }, - { + }), { orgSlug: 'fakeOrg', scanId: 'scan-ai-dee', fold: 'version', reportLevel: 'warn', - }, - ) + }) expect(result).toMatchInlineSnapshot(` { @@ -976,23 +942,19 @@ describe('generate-report', () => { }) it('should fold the versions up when fold=pkg', () => { - const result = generateReport( - getScanWithEnvVars(), - { + const result = generateReport(withAlertActions(getScanWithEnvVars(), { securityPolicyRules: { envVars: { action: 'error', }, }, securityPolicyDefault: 'medium', - }, - { + }), { orgSlug: 'fakeOrg', scanId: 'scan-ai-dee', fold: 'pkg', reportLevel: 'warn', - }, - ) + }) expect(result).toMatchInlineSnapshot(` { diff --git a/src/commands/scan/output-scan-report.mts b/src/commands/scan/output-scan-report.mts index 35965bf96f..b2e3a91124 100644 --- a/src/commands/scan/output-scan-report.mts +++ b/src/commands/scan/output-scan-report.mts @@ -19,7 +19,6 @@ import type { ReportLeafNode, ScanReport } from './generate-report.mts' import type { FOLD_SETTING, REPORT_LEVEL } from './types.mts' import type { CResult, OutputKind } from '../../types.mts' import type { SocketArtifact } from '../../utils/alert/artifact.mts' -import type { SocketSdkSuccessResult } from '@socketsecurity/sdk' export type OutputScanReportConfig = { orgSlug: string @@ -35,7 +34,6 @@ export type OutputScanReportConfig = { export async function outputScanReport( result: CResult<{ scan: SocketArtifact[] - securityPolicy: SocketSdkSuccessResult<'getOrgSecurityPolicy'>['data'] }>, { filepath, @@ -63,7 +61,6 @@ export async function outputScanReport( const scanReport = generateReport( result.data.scan, - result.data.securityPolicy, { orgSlug, scanId, diff --git a/src/commands/scan/output-scan-report.test.mts b/src/commands/scan/output-scan-report.test.mts index fba2735d53..38f813985e 100644 --- a/src/commands/scan/output-scan-report.test.mts +++ b/src/commands/scan/output-scan-report.test.mts @@ -169,7 +169,7 @@ describe('output-scan-report', () => { await outputScanReport( { ok: true, - data: { scan: [], securityPolicy: {} }, + data: { scan: [] }, } as any, { orgSlug: 'test-org', @@ -195,7 +195,7 @@ describe('output-scan-report', () => { await outputScanReport( { ok: true, - data: { scan: [], securityPolicy: {} }, + data: { scan: [] }, } as any, { orgSlug: 'test-org',