diff --git a/src/main/scanLogic/scanRunners/analyzerManager.ts b/src/main/scanLogic/scanRunners/analyzerManager.ts index fa06804d..c7423f29 100644 --- a/src/main/scanLogic/scanRunners/analyzerManager.ts +++ b/src/main/scanLogic/scanRunners/analyzerManager.ts @@ -17,6 +17,8 @@ export class AnalyzerManager { public static readonly ANALYZER_MANAGER_VERSION: string = '1.3.2.2019257'; 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_PATH: string = Utils.addWinSuffixIfNeeded(path.join(ScanUtils.getIssuesPath(), AnalyzerManager.BINARY_NAME, AnalyzerManager.BINARY_NAME)); + private static readonly DOWNLOAD_URL: string = Utils.addZipSuffix(AnalyzerManager.RELATIVE_DOWNLOAD_URL + '/' + AnalyzerManager.ANALYZER_MANAGER_VERSION + '/' + Utils.getArchitecture() + '/' + AnalyzerManager.BINARY_NAME); private static readonly JFROG_RELEASES_URL: string = 'https://releases.jfrog.io'; public static readonly TIMEOUT_MILLISECS: number = 1000 * 60 * 5; public static readonly ENV_PLATFORM_URL: string = 'JF_PLATFORM_URL'; @@ -32,7 +34,7 @@ export class AnalyzerManager { private static FINISH_UPDATE_PROMISE: Promise; constructor(private _connectionManager: ConnectionManager, protected _logManager: LogManager) { - this._binary = new Resource(this.getUrlPath(), this.getDefaultTargetPath(), _logManager, this.createJFrogCLient()); + this._binary = new Resource(AnalyzerManager.DOWNLOAD_URL, AnalyzerManager.ANALYZER_MANAGER_PATH, _logManager, this.createJFrogCLient()); AnalyzerManager.FINISH_UPDATE_PROMISE = this.checkForUpdates(); } @@ -69,21 +71,6 @@ export class AnalyzerManager { return this._connectionManager.createJfrogClientWithRepository(releasesRepo + '/artifactory'); } - /** - * Build the path section for the analyzer manager download URL. - */ - public getUrlPath(): string { - return Utils.addZipSuffix( - AnalyzerManager.RELATIVE_DOWNLOAD_URL + - '/' + - AnalyzerManager.ANALYZER_MANAGER_VERSION + - '/' + - Utils.getArchitecture() + - '/' + - AnalyzerManager.BINARY_NAME - ); - } - private async checkForUpdates(): Promise { if (await this._binary.isOutdated()) { this._logManager.logMessage('Updating Advanced Security Features', 'INFO'); @@ -96,12 +83,6 @@ export class AnalyzerManager { return false; } - /** - * Get the default path to download the analyzer manager to - */ - public getDefaultTargetPath(): string { - return Utils.addWinSuffixIfNeeded(path.join(ScanUtils.getIssuesPath(), AnalyzerManager.BINARY_NAME, AnalyzerManager.BINARY_NAME)); - } public async runWithTimeout(checkCancel: () => void, args: string[], executionLogDirectory?: string): Promise { await AnalyzerManager.FINISH_UPDATE_PROMISE; diff --git a/src/test/tests/integration/externalResourcesRepository.test.ts b/src/test/tests/integration/externalResourcesRepository.test.ts index f9f87782..81e91cd0 100644 --- a/src/test/tests/integration/externalResourcesRepository.test.ts +++ b/src/test/tests/integration/externalResourcesRepository.test.ts @@ -1,41 +1,59 @@ import { assert } from 'chai'; -import * as fs from 'fs'; +import fs from 'fs-extra'; + import * as path from 'path'; import { AnalyzeScanRequest } from '../../../main/scanLogic/scanRunners/analyzerModels'; import { SecretsRunner, SecretsScanResponse } from '../../../main/scanLogic/scanRunners/secretsScan'; import { AnalyzerManagerIntegrationEnv } from '../utils/testIntegration.test'; import { Configuration } from '../../../main/utils/configuration'; +import { AnalyzerManager } from '../../../main/scanLogic/scanRunners/analyzerManager'; -describe.only('External Resources Repository Integration Tests', async () => { +describe('External Resources Repository Integration Tests', async () => { const integrationManager: AnalyzerManagerIntegrationEnv = new AnalyzerManagerIntegrationEnv(); const testDataRoot: string = path.join(__dirname, '..', '..', 'resources', 'secretsScan'); - let runner: SecretsRunner; - let response: SecretsScanResponse; - let expectedContent: SecretsScanResponse; + before(async function () { + fs.removeSync(path.dirname(AnalyzerManager.ANALYZER_MANAGER_PATH)); + }); - before(async function() { - process.env[Configuration.JFROG_IDE_RELEASES_REPO_ENV] = 'releases-proxy'; + after(() => { + delete process.env[Configuration.JFROG_IDE_RELEASES_REPO_ENV]; + }); - // Integration initialization + it('Should fail to download the analyzer manager from none existing repository', async () => { + process.env[Configuration.JFROG_IDE_RELEASES_REPO_ENV] = 'none-existing-releases-proxy'; + // Prepare await integrationManager.initialize(testDataRoot); - runner = integrationManager.entitledJasRunnerFactory.createSecretsRunners()[0]; - - // Get expected partial result that the scan should contain + const runner: SecretsRunner = integrationManager.entitledJasRunnerFactory.createSecretsRunners()[0]; let dataPath: string = path.join(testDataRoot, 'expectedScanResponse.json'); - expectedContent = JSON.parse(fs.readFileSync(dataPath, 'utf8').toString()); + const expectedContent: any = JSON.parse(fs.readFileSync(dataPath, 'utf8').toString()); assert.isDefined(expectedContent, 'Failed to read expected SecretsScanResponse content from ' + dataPath); - response = await runner + + // Run + const response: SecretsScanResponse = await runner .executeRequest(() => undefined, { roots: [testDataRoot] } as AnalyzeScanRequest) .then(runResult => runner.convertResponse(runResult)); - }); - after(() => { - delete process.env[Configuration.JFROG_IDE_RELEASES_REPO_ENV]; + // Assert + assert.isUndefined(response.filesWithIssues); }); - it('Check response defined', () => { - assert.isDefined(response); + it('Should download the analyzer manager from releases-proxy instead of direct releases.jfrog.io', async () => { + process.env[Configuration.JFROG_IDE_RELEASES_REPO_ENV] = 'releases-proxy'; + // Prepare + await integrationManager.initialize(testDataRoot); + const runner: SecretsRunner = integrationManager.entitledJasRunnerFactory.createSecretsRunners()[0]; + let dataPath: string = path.join(testDataRoot, 'expectedScanResponse.json'); + const expectedContent: any = JSON.parse(fs.readFileSync(dataPath, 'utf8').toString()); + assert.isDefined(expectedContent, 'Failed to read expected SecretsScanResponse content from ' + dataPath); + + // Run + const response: SecretsScanResponse = await runner + .executeRequest(() => undefined, { roots: [testDataRoot] } as AnalyzeScanRequest) + .then(runResult => runner.convertResponse(runResult)); + + // Assert + assert.isDefined(response.filesWithIssues); }); }); diff --git a/src/test/tests/utils/testIntegration.test.ts b/src/test/tests/utils/testIntegration.test.ts index 77536667..0f51d403 100644 --- a/src/test/tests/utils/testIntegration.test.ts +++ b/src/test/tests/utils/testIntegration.test.ts @@ -69,9 +69,6 @@ export class AnalyzerManagerIntegrationEnv extends BaseIntegrationEnv { /** @override */ public async initialize(rootTest?: string) { await super.initialize(); - if (this.entitledJasRunnerFactory) { - return; - } this.entitledJasRunnerFactory = new MockJasRunnerFactory( this.connectionManager, this.logManager,