From a70ab16a921ce7e32244505713b547675fa1bec9 Mon Sep 17 00:00:00 2001 From: Or Geva Date: Sun, 15 Oct 2023 18:10:45 +0300 Subject: [PATCH 1/6] Fix log messages --- src/main/scanLogic/scanRunners/jasRunner.ts | 4 ++-- src/main/scanLogic/scanRunners/sastScan.ts | 9 ++++++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/main/scanLogic/scanRunners/jasRunner.ts b/src/main/scanLogic/scanRunners/jasRunner.ts index db693353..5fe20bab 100644 --- a/src/main/scanLogic/scanRunners/jasRunner.ts +++ b/src/main/scanLogic/scanRunners/jasRunner.ts @@ -52,7 +52,7 @@ export abstract class JasRunner { private static readonly DOWNLOAD_URL: string = '/xsc-gen-exe-analyzer-manager-local/v1/'; // 5 min - public static readonly TIMEOUT_MILLISECS: number = 1000 * 60 * 5; + public static readonly TIMEOUT_MILLISECS: number = 1000 * 60 * 8; public static readonly NOT_ENTITLED: number = 31; public static readonly NOT_SUPPORTED: number = 13; @@ -186,7 +186,7 @@ export abstract class JasRunner { protected logStartScanning(request: AnalyzeScanRequest): void { this._logManager.logMessage( - `Scanning directories ' ${request.roots} + ', for ${this._scanType} issues. Skipping folders: ${request.skipped_folders}`, + `Scanning directories '${request.roots}', for ${this._scanType} issues. Skipping folders: ${request.skipped_folders}`, 'DEBUG' ); } diff --git a/src/main/scanLogic/scanRunners/sastScan.ts b/src/main/scanLogic/scanRunners/sastScan.ts index 02291912..61e6f0da 100644 --- a/src/main/scanLogic/scanRunners/sastScan.ts +++ b/src/main/scanLogic/scanRunners/sastScan.ts @@ -95,7 +95,7 @@ export class SastRunner extends JasRunner { excluded_rules: this._config.getExcludeRules(), exclude_patterns: this._config.GetExcludePatterns(this._scanType) } as SastScanRequest; - super.logStartScanning(request); + this.logStartScanning(request); let response: AnalyzerScanResponse | undefined = await this.executeRequest(this._progressManager.checkCancel, request); let sastScanResponse: SastScanResponse = this.generateScanResponse(response); if (response) { @@ -108,6 +108,13 @@ export class SastRunner extends JasRunner { this._progressManager.reportProgress(); } + /** @override */ + protected logStartScanning(request: SastScanRequest): void { + this._logManager.logMessage( + `Scanning directory ' ${request.roots}', for ${this._scanType} Skipping folders: ${request.exclude_patterns}`, + 'DEBUG' + ); + } /** * Generate response from the run results * @param response - Run results generated from the binary From 907ac9671c8c4915a5d6d7c6d5b7fc44c0b30587 Mon Sep 17 00:00:00 2001 From: Or Geva Date: Sun, 15 Oct 2023 18:11:47 +0300 Subject: [PATCH 2/6] Move config default root to ctor --- .../scanLogic/scanRunners/applicabilityScan.ts | 2 +- src/main/utils/jfrogAppsConfig/jfrogAppsConfig.ts | 15 +++++++++------ src/test/tests/appsConfig.test.ts | 11 +++++++---- src/test/tests/iacScan.test.ts | 2 +- src/test/tests/integration/iac.test.ts | 2 +- src/test/tests/integration/secrets.test.ts | 2 +- src/test/tests/sastScan.test.ts | 2 +- src/test/tests/scanAnlayzerRunner.test.ts | 2 +- src/test/tests/secretsScan.test.ts | 2 +- 9 files changed, 23 insertions(+), 17 deletions(-) diff --git a/src/main/scanLogic/scanRunners/applicabilityScan.ts b/src/main/scanLogic/scanRunners/applicabilityScan.ts index 8a724148..6acb23f8 100644 --- a/src/main/scanLogic/scanRunners/applicabilityScan.ts +++ b/src/main/scanLogic/scanRunners/applicabilityScan.ts @@ -56,7 +56,7 @@ export class ApplicabilityRunner extends JasRunner { logManager: LogManager, binary?: Resource ) { - super(connectionManager, ScanType.AnalyzeApplicability, logManager, new AppsConfigModule(), binary); + super(connectionManager, ScanType.AnalyzeApplicability, logManager, new AppsConfigModule(__dirname), binary); } /** @override */ diff --git a/src/main/utils/jfrogAppsConfig/jfrogAppsConfig.ts b/src/main/utils/jfrogAppsConfig/jfrogAppsConfig.ts index ac3f9659..b6c3c056 100644 --- a/src/main/utils/jfrogAppsConfig/jfrogAppsConfig.ts +++ b/src/main/utils/jfrogAppsConfig/jfrogAppsConfig.ts @@ -19,13 +19,16 @@ export class JFrogAppsConfig { this._version = jfrogAppsConfig.version; if (jfrogAppsConfig.modules) { for (let module of jfrogAppsConfig.modules) { - this._modules.push(new AppsConfigModule(module)); + if (module.source_root) { + module.source_root = workspace; + } + this._modules.push(new AppsConfigModule(workspace, module)); } } } // If no modules provides, push a default module if (this._modules.length === 0) { - this._modules.push(new AppsConfigModule({ source_root: workspace } as Module)); + this._modules.push(new AppsConfigModule(workspace)); } } @@ -45,10 +48,10 @@ export class AppsConfigModule { private _excludeScanners: ScanType[] = []; private _scanners: Map = new Map(); - constructor(module?: Module) { + constructor(defaultWorkspace: string, module?: Module) { module = module || ({} as Module); this._name = module.name; - this._sourceRoot = this.getModuleSourceRoot(module); + this._sourceRoot = this.getModuleSourceRoot(module, defaultWorkspace); this._excludePatterns = module.exclude_patterns || []; if (module.exclude_scanners) { for (let excludeScanner of module.exclude_scanners) { @@ -127,12 +130,12 @@ export class AppsConfigModule { return scanner.excluded_rules; } - private getModuleSourceRoot(module: Module) { + private getModuleSourceRoot(module: Module, defaultWorkspace: string) { let sourceRoot: string = module.source_root || ''; if (path.isAbsolute(sourceRoot)) { return sourceRoot; } else { - return path.join(__dirname, sourceRoot); + return path.join(defaultWorkspace, sourceRoot); } } diff --git a/src/test/tests/appsConfig.test.ts b/src/test/tests/appsConfig.test.ts index b3023d3a..00dd77e3 100644 --- a/src/test/tests/appsConfig.test.ts +++ b/src/test/tests/appsConfig.test.ts @@ -42,7 +42,7 @@ describe('JFrog Apps Config Tests', () => { { excludeScanners: [ExcludeScannerName.Secrets, ExcludeScannerName.ContextualAnalysis] as ExcludeScannerName[], shouldSkip: true } ].forEach(testCase => { it('Should skip scanner - ' + testCase.excludeScanners, () => { - let module: AppsConfigModule = new AppsConfigModule({ exclude_scanners: testCase.excludeScanners } as Module); + let module: AppsConfigModule = new AppsConfigModule(__dirname, { exclude_scanners: testCase.excludeScanners } as Module); assert.equal(module.ShouldSkipScanner(ScanType.AnalyzeApplicability), testCase.shouldSkip); }); }); @@ -56,7 +56,10 @@ describe('JFrog Apps Config Tests', () => { getSourceRootCases.forEach(testCase => { it('Get source roots - With module source - ' + testCase.scanner?.working_dirs, () => { let sourceRoot: string = path.join(__dirname, 'source-root'); - let module: AppsConfigModule = new AppsConfigModule({ source_root: sourceRoot, scanners: { iac: testCase?.scanner } } as Module); + let module: AppsConfigModule = new AppsConfigModule(sourceRoot, { + source_root: sourceRoot, + scanners: { iac: testCase?.scanner } + } as Module); let actualSourceRoots: string[] = module.GetSourceRoots(ScanType.Iac); if (!testCase.scanner) { assert.sameMembers(actualSourceRoots, [module.sourceRoot]); @@ -73,7 +76,7 @@ describe('JFrog Apps Config Tests', () => { getSourceRootCases.forEach(testCase => { it('Get source roots - With module source ' + testCase.scanner?.working_dirs, () => { let sourceRoot: string = path.join(__dirname, 'source-root'); - let module: AppsConfigModule = new AppsConfigModule({ source_root: sourceRoot, scanners: { iac: testCase?.scanner } } as Module); + let module: AppsConfigModule = new AppsConfigModule(sourceRoot, { scanners: { iac: testCase?.scanner } } as Module); let actualSourceRoots: string[] = module.GetSourceRoots(ScanType.Iac); if (!testCase.scanner) { assert.sameMembers(actualSourceRoots, [module.sourceRoot]); @@ -93,7 +96,7 @@ describe('JFrog Apps Config Tests', () => { { scanner: { exclude_patterns: ['exclude-dir-1', 'exclude-dir-2'] } as Scanner } ].forEach(testCase => { it('Get exclude patterns - ' + testCase.scanner?.exclude_patterns, () => { - let module: AppsConfigModule = new AppsConfigModule({ + let module: AppsConfigModule = new AppsConfigModule(__dirname, { exclude_patterns: ['exclude-root'], scanners: { secrets: testCase?.scanner } } as Module); diff --git a/src/test/tests/iacScan.test.ts b/src/test/tests/iacScan.test.ts index 5ec6f1a5..cc3de00f 100644 --- a/src/test/tests/iacScan.test.ts +++ b/src/test/tests/iacScan.test.ts @@ -129,7 +129,7 @@ describe('Iac Scan Tests', () => { createTestStepProgress(), {} as ConnectionManager, logManager, - new AppsConfigModule() + new AppsConfigModule(__dirname) ); } }); diff --git a/src/test/tests/integration/iac.test.ts b/src/test/tests/integration/iac.test.ts index 673e4be5..2c49584d 100644 --- a/src/test/tests/integration/iac.test.ts +++ b/src/test/tests/integration/iac.test.ts @@ -36,7 +36,7 @@ describe('Iac Integration Tests', async () => { createTestStepProgress(), integrationManager.connectionManager, integrationManager.logManager, - new AppsConfigModule(), + new AppsConfigModule(__dirname), integrationManager.resource ); runner.verbose = true; diff --git a/src/test/tests/integration/secrets.test.ts b/src/test/tests/integration/secrets.test.ts index 3f03a1f5..cf29fd73 100644 --- a/src/test/tests/integration/secrets.test.ts +++ b/src/test/tests/integration/secrets.test.ts @@ -36,7 +36,7 @@ describe('Secrets Scan Integration Tests', async () => { createTestStepProgress(), integrationManager.connectionManager, integrationManager.logManager, - new AppsConfigModule(), + new AppsConfigModule(__dirname), integrationManager.resource ); runner.verbose = true; diff --git a/src/test/tests/sastScan.test.ts b/src/test/tests/sastScan.test.ts index 7de99564..a67b4d5b 100644 --- a/src/test/tests/sastScan.test.ts +++ b/src/test/tests/sastScan.test.ts @@ -127,7 +127,7 @@ describe('Sast Tests', () => { createTestStepProgress(), {} as ConnectionManager, logManager, - new AppsConfigModule() + new AppsConfigModule(__dirname) ); } }); diff --git a/src/test/tests/scanAnlayzerRunner.test.ts b/src/test/tests/scanAnlayzerRunner.test.ts index 4230e076..71a67781 100644 --- a/src/test/tests/scanAnlayzerRunner.test.ts +++ b/src/test/tests/scanAnlayzerRunner.test.ts @@ -58,7 +58,7 @@ describe('Analyzer BinaryRunner tests', async () => { ): Promise { await RunUtils.runWithTimeout(timeout, checkCancel, dummyAction()); } - })(connection, dummyName, logManager, new AppsConfigModule()); + })(connection, dummyName, logManager, new AppsConfigModule(__dirname)); } [ diff --git a/src/test/tests/secretsScan.test.ts b/src/test/tests/secretsScan.test.ts index b9461945..2aa2a66c 100644 --- a/src/test/tests/secretsScan.test.ts +++ b/src/test/tests/secretsScan.test.ts @@ -127,7 +127,7 @@ describe('Secrets Scan Tests', () => { createTestStepProgress(), {} as ConnectionManager, logManager, - new AppsConfigModule() + new AppsConfigModule(__dirname) ); } }); From e1baf3eb3d70755a00c5804fe4f4376449659759 Mon Sep 17 00:00:00 2001 From: Or Geva Date: Sun, 15 Oct 2023 18:29:22 +0300 Subject: [PATCH 3/6] Remove __dirname --- src/test/tests/appsConfig.test.ts | 4 ++-- src/test/tests/iacScan.test.ts | 2 +- src/test/tests/integration/iac.test.ts | 2 +- src/test/tests/integration/secrets.test.ts | 2 +- src/test/tests/sastScan.test.ts | 2 +- src/test/tests/scanAnlayzerRunner.test.ts | 2 +- src/test/tests/secretsScan.test.ts | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/test/tests/appsConfig.test.ts b/src/test/tests/appsConfig.test.ts index 00dd77e3..cfbc8e03 100644 --- a/src/test/tests/appsConfig.test.ts +++ b/src/test/tests/appsConfig.test.ts @@ -42,7 +42,7 @@ describe('JFrog Apps Config Tests', () => { { excludeScanners: [ExcludeScannerName.Secrets, ExcludeScannerName.ContextualAnalysis] as ExcludeScannerName[], shouldSkip: true } ].forEach(testCase => { it('Should skip scanner - ' + testCase.excludeScanners, () => { - let module: AppsConfigModule = new AppsConfigModule(__dirname, { exclude_scanners: testCase.excludeScanners } as Module); + let module: AppsConfigModule = new AppsConfigModule('', { exclude_scanners: testCase.excludeScanners } as Module); assert.equal(module.ShouldSkipScanner(ScanType.AnalyzeApplicability), testCase.shouldSkip); }); }); @@ -96,7 +96,7 @@ describe('JFrog Apps Config Tests', () => { { scanner: { exclude_patterns: ['exclude-dir-1', 'exclude-dir-2'] } as Scanner } ].forEach(testCase => { it('Get exclude patterns - ' + testCase.scanner?.exclude_patterns, () => { - let module: AppsConfigModule = new AppsConfigModule(__dirname, { + let module: AppsConfigModule = new AppsConfigModule('', { exclude_patterns: ['exclude-root'], scanners: { secrets: testCase?.scanner } } as Module); diff --git a/src/test/tests/iacScan.test.ts b/src/test/tests/iacScan.test.ts index cc3de00f..2de60313 100644 --- a/src/test/tests/iacScan.test.ts +++ b/src/test/tests/iacScan.test.ts @@ -129,7 +129,7 @@ describe('Iac Scan Tests', () => { createTestStepProgress(), {} as ConnectionManager, logManager, - new AppsConfigModule(__dirname) + new AppsConfigModule('') ); } }); diff --git a/src/test/tests/integration/iac.test.ts b/src/test/tests/integration/iac.test.ts index 2c49584d..e6cd7c69 100644 --- a/src/test/tests/integration/iac.test.ts +++ b/src/test/tests/integration/iac.test.ts @@ -36,7 +36,7 @@ describe('Iac Integration Tests', async () => { createTestStepProgress(), integrationManager.connectionManager, integrationManager.logManager, - new AppsConfigModule(__dirname), + new AppsConfigModule(testDataRoot), integrationManager.resource ); runner.verbose = true; diff --git a/src/test/tests/integration/secrets.test.ts b/src/test/tests/integration/secrets.test.ts index cf29fd73..d5c58d66 100644 --- a/src/test/tests/integration/secrets.test.ts +++ b/src/test/tests/integration/secrets.test.ts @@ -36,7 +36,7 @@ describe('Secrets Scan Integration Tests', async () => { createTestStepProgress(), integrationManager.connectionManager, integrationManager.logManager, - new AppsConfigModule(__dirname), + new AppsConfigModule(testDataRoot), integrationManager.resource ); runner.verbose = true; diff --git a/src/test/tests/sastScan.test.ts b/src/test/tests/sastScan.test.ts index a67b4d5b..67d81ddd 100644 --- a/src/test/tests/sastScan.test.ts +++ b/src/test/tests/sastScan.test.ts @@ -127,7 +127,7 @@ describe('Sast Tests', () => { createTestStepProgress(), {} as ConnectionManager, logManager, - new AppsConfigModule(__dirname) + new AppsConfigModule('') ); } }); diff --git a/src/test/tests/scanAnlayzerRunner.test.ts b/src/test/tests/scanAnlayzerRunner.test.ts index 71a67781..71dd49b0 100644 --- a/src/test/tests/scanAnlayzerRunner.test.ts +++ b/src/test/tests/scanAnlayzerRunner.test.ts @@ -58,7 +58,7 @@ describe('Analyzer BinaryRunner tests', async () => { ): Promise { await RunUtils.runWithTimeout(timeout, checkCancel, dummyAction()); } - })(connection, dummyName, logManager, new AppsConfigModule(__dirname)); + })(connection, dummyName, logManager, new AppsConfigModule('')); } [ diff --git a/src/test/tests/secretsScan.test.ts b/src/test/tests/secretsScan.test.ts index 2aa2a66c..564c977a 100644 --- a/src/test/tests/secretsScan.test.ts +++ b/src/test/tests/secretsScan.test.ts @@ -127,7 +127,7 @@ describe('Secrets Scan Tests', () => { createTestStepProgress(), {} as ConnectionManager, logManager, - new AppsConfigModule(__dirname) + new AppsConfigModule('') ); } }); From 57806290dadc40f0c3efca44df3d40d09c413d20 Mon Sep 17 00:00:00 2001 From: Or Geva Date: Sun, 15 Oct 2023 18:40:49 +0300 Subject: [PATCH 4/6] Update appsConfig test --- src/test/tests/appsConfig.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/tests/appsConfig.test.ts b/src/test/tests/appsConfig.test.ts index cfbc8e03..0531adc7 100644 --- a/src/test/tests/appsConfig.test.ts +++ b/src/test/tests/appsConfig.test.ts @@ -17,7 +17,7 @@ describe('JFrog Apps Config Tests', () => { // Check module let module: AppsConfigModule = appsConfig!.modules[0]; assert.equal(module.name, 'FrogLeapApp'); - assert.include(module.sourceRoot, 'src'); + assert.include(module.sourceRoot, path.join(jfrogAppsConfigDir, 'src')); assert.deepEqual(module.excludePatterns, ['docs/']); assert.deepEqual(module.excludeScanners, [ScanType.Secrets]); From fbc2311044cd78b59d6db5644263bc5253c8ccd4 Mon Sep 17 00:00:00 2001 From: Or Geva Date: Sun, 15 Oct 2023 18:58:21 +0300 Subject: [PATCH 5/6] Update appsConfig test --- src/main/utils/jfrogAppsConfig/jfrogAppsConfig.ts | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/main/utils/jfrogAppsConfig/jfrogAppsConfig.ts b/src/main/utils/jfrogAppsConfig/jfrogAppsConfig.ts index b6c3c056..4e774c9d 100644 --- a/src/main/utils/jfrogAppsConfig/jfrogAppsConfig.ts +++ b/src/main/utils/jfrogAppsConfig/jfrogAppsConfig.ts @@ -19,9 +19,6 @@ export class JFrogAppsConfig { this._version = jfrogAppsConfig.version; if (jfrogAppsConfig.modules) { for (let module of jfrogAppsConfig.modules) { - if (module.source_root) { - module.source_root = workspace; - } this._modules.push(new AppsConfigModule(workspace, module)); } } From ec0a629dcb6cb9b3dd17f233dd5e405d5aa4f4b8 Mon Sep 17 00:00:00 2001 From: Or Geva Date: Tue, 7 Nov 2023 14:53:56 +0200 Subject: [PATCH 6/6] Fix typo --- src/main/scanLogic/scanRunners/jasRunner.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/scanLogic/scanRunners/jasRunner.ts b/src/main/scanLogic/scanRunners/jasRunner.ts index 5fe20bab..4a4e815d 100644 --- a/src/main/scanLogic/scanRunners/jasRunner.ts +++ b/src/main/scanLogic/scanRunners/jasRunner.ts @@ -51,7 +51,7 @@ export abstract class JasRunner { public static readonly RUNNER_VERSION: string = '1.3.2.2019257'; private static readonly DOWNLOAD_URL: string = '/xsc-gen-exe-analyzer-manager-local/v1/'; - // 5 min + // 8 min public static readonly TIMEOUT_MILLISECS: number = 1000 * 60 * 8; public static readonly NOT_ENTITLED: number = 31;