From 13a931656f233e019812c55c4d31e062afaaf24b Mon Sep 17 00:00:00 2001 From: Assaf Attias <49212512+attiasas@users.noreply.github.com> Date: Wed, 31 Jul 2024 14:00:31 +0300 Subject: [PATCH] Update analyzer manager to v1.8.9 (#488) --- .github/workflows/test.yml | 4 + .../scanLogic/scanRunners/analyzerManager.ts | 2 +- .../tests/integration/applicability.test.ts | 5 ++ src/test/tests/integration/secrets.test.ts | 84 +++++++++++-------- 4 files changed, 61 insertions(+), 34 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 65e62897..321cfeb9 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -26,6 +26,10 @@ jobs: # Fix 'nvm is not compatible with the npm config "prefix" option' error on macOS run: unset npm_config_prefix if: runner.os == 'macOS' + - name: Install Go + uses: actions/setup-go@v3 + with: + go-version: 1.22.x - name: Setup Python3 uses: actions/setup-python@v4 with: diff --git a/src/main/scanLogic/scanRunners/analyzerManager.ts b/src/main/scanLogic/scanRunners/analyzerManager.ts index 1710a187..ac45b3b5 100644 --- a/src/main/scanLogic/scanRunners/analyzerManager.ts +++ b/src/main/scanLogic/scanRunners/analyzerManager.ts @@ -17,7 +17,7 @@ import { LogUtils } from '../../log/logUtils'; export class AnalyzerManager { private static readonly RELATIVE_DOWNLOAD_URL: string = '/xsc-gen-exe-analyzer-manager-local/v1'; private static readonly BINARY_NAME: string = 'analyzerManager'; - public static readonly ANALYZER_MANAGER_VERSION: string = '1.8.8'; + public static readonly ANALYZER_MANAGER_VERSION: string = '1.8.9'; public static readonly ANALYZER_MANAGER_PATH: string = Utils.addWinSuffixIfNeeded( path.join(ScanUtils.getIssuesPath(), AnalyzerManager.BINARY_NAME, AnalyzerManager.BINARY_NAME) ); diff --git a/src/test/tests/integration/applicability.test.ts b/src/test/tests/integration/applicability.test.ts index f7bbb652..347f7312 100644 --- a/src/test/tests/integration/applicability.test.ts +++ b/src/test/tests/integration/applicability.test.ts @@ -1,5 +1,6 @@ import { assert } from 'chai'; import * as fs from 'fs'; +import * as os from 'os'; import * as path from 'path'; import { ApplicabilityRunner, @@ -31,6 +32,10 @@ describe('Applicability Integration Tests', async () => { ['npm', 'python'].forEach(async packageType => { let directoryToScan: string = path.join(testDataRoot, packageType); + if (os.platform() === 'win32') { + // make the first char uppercase + directoryToScan = directoryToScan.charAt(0).toUpperCase() + directoryToScan.slice(1); + } runScanAndAssert(packageType, directoryToScan, path.join(directoryToScan, 'expectedScanResponse.json')); }); diff --git a/src/test/tests/integration/secrets.test.ts b/src/test/tests/integration/secrets.test.ts index a6f7d710..a1444a53 100644 --- a/src/test/tests/integration/secrets.test.ts +++ b/src/test/tests/integration/secrets.test.ts @@ -1,5 +1,6 @@ import { assert } from 'chai'; import * as fs from 'fs'; +import * as os from 'os'; import * as path from 'path'; import { AnalyzeScanRequest } from '../../../main/scanLogic/scanRunners/analyzerModels'; @@ -30,48 +31,65 @@ describe('Secrets Scan Integration Tests', async () => { // Integration initialization await integrationManager.initialize(testDataRoot); runner = integrationManager.entitledJasRunnerFactory.createSecretsRunners()[0]; - - // Get expected partial result that the scan should contain - let dataPath: string = path.join(testDataRoot, 'expectedScanResponse.json'); - expectedContent = JSON.parse(fs.readFileSync(dataPath, 'utf8').toString()); - assert.isDefined(expectedContent, 'Failed to read expected SecretsScanResponse content from ' + dataPath); - // Run scan - // Try/Catch (with skip) should be removed after Secrets scan is released - response = await runner - .executeRequest(() => undefined, { roots: [testDataRoot] } as AnalyzeScanRequest) - .then(runResult => runner.convertResponse(runResult)); + let directoryToScan: string = testDataRoot; + if (os.platform() === 'win32') { + // make the first char uppercase + directoryToScan = directoryToScan.charAt(0).toUpperCase() + directoryToScan.slice(1); + } + runScanAndAssert(directoryToScan); }); - it('Check response defined', () => { - assert.isDefined(response); - }); + async function runScanAndAssert(directoryToScan: string) { + describe('Run tests in ' + directoryToScan + ' workspace for secrets issues', () => { + before(async () => { + // Get expected partial result that the scan should contain + let dataPath: string = path.join(directoryToScan, 'expectedScanResponse.json'); + expectedContent = JSON.parse(fs.readFileSync(dataPath, 'utf8').toString()); + assert.isDefined(expectedContent, 'Failed to read expected SecretsScanResponse content from ' + dataPath); + // Run scan + // Try/Catch (with skip) should be removed after Secrets scan is released + response = await runner + .executeRequest(() => undefined, { roots: [directoryToScan] } as AnalyzeScanRequest) + .then(runResult => runner.convertResponse(runResult)); + }); - it('Check response attributes defined', () => { - assert.isDefined(response.filesWithIssues); - }); + it('Check response defined', () => { + assert.isDefined(response); + }); - it('Check all expected files with issues detected', () => - assertFileIssuesExist(testDataRoot, response.filesWithIssues, expectedContent.filesWithIssues)); + it('Check response attributes defined', () => { + assert.isDefined(response.filesWithIssues); + }); - it('Check all expected issues detected', () => assertIssuesExist(testDataRoot, response.filesWithIssues, expectedContent.filesWithIssues)); + it('Check all expected files with issues detected', () => + assertFileIssuesExist(directoryToScan, response.filesWithIssues, expectedContent.filesWithIssues)); - it('Check all expected locations detected', () => - assertIssuesLocationsExist(testDataRoot, response.filesWithIssues, expectedContent.filesWithIssues)); + it('Check all expected issues detected', () => + assertIssuesExist(directoryToScan, response.filesWithIssues, expectedContent.filesWithIssues)); - it('Check calculateNumberOfTasks detected', () => - assert.equal( - ScanManager.calculateNumberOfTasks(integrationManager.entitledJasRunnerFactory.createSecretsRunners(), new Map()), - 1 - )); + it('Check all expected locations detected', () => + assertIssuesLocationsExist(directoryToScan, response.filesWithIssues, expectedContent.filesWithIssues)); - describe('Detected issues validations', () => { - it('Check rule-name', () => assertIssuesRuleNameExist(testDataRoot, response.filesWithIssues, expectedContent.filesWithIssues)); + it('Check calculateNumberOfTasks detected', () => + assert.equal( + ScanManager.calculateNumberOfTasks( + integrationManager.entitledJasRunnerFactory.createSecretsRunners(), + new Map() + ), + 1 + )); - it('Check rule full description', () => - assertIssuesFullDescriptionExist(testDataRoot, response.filesWithIssues, expectedContent.filesWithIssues)); + describe('Detected issues validations', () => { + it('Check rule-name', () => assertIssuesRuleNameExist(directoryToScan, response.filesWithIssues, expectedContent.filesWithIssues)); - it('Check severity', () => assertIssuesSeverityExist(testDataRoot, response.filesWithIssues, expectedContent.filesWithIssues)); + it('Check rule full description', () => + assertIssuesFullDescriptionExist(directoryToScan, response.filesWithIssues, expectedContent.filesWithIssues)); - it('Check snippet', () => assertIssuesLocationSnippetsExist(testDataRoot, response.filesWithIssues, expectedContent.filesWithIssues)); - }); + it('Check severity', () => assertIssuesSeverityExist(directoryToScan, response.filesWithIssues, expectedContent.filesWithIssues)); + + it('Check snippet', () => + assertIssuesLocationSnippetsExist(directoryToScan, response.filesWithIssues, expectedContent.filesWithIssues)); + }); + }); + } });