Skip to content

Commit

Permalink
Add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Or-Geva committed Nov 7, 2023
1 parent aa3140e commit 23d0840
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 43 deletions.
25 changes: 3 additions & 22 deletions src/main/scanLogic/scanRunners/analyzerManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -32,7 +34,7 @@ export class AnalyzerManager {
private static FINISH_UPDATE_PROMISE: Promise<boolean>;

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();
}

Expand Down Expand Up @@ -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<boolean> {
if (await this._binary.isOutdated()) {
this._logManager.logMessage('Updating Advanced Security Features', 'INFO');
Expand All @@ -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<void> {
await AnalyzerManager.FINISH_UPDATE_PROMISE;
Expand Down
54 changes: 36 additions & 18 deletions src/test/tests/integration/externalResourcesRepository.test.ts
Original file line number Diff line number Diff line change
@@ -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);
});
});
3 changes: 0 additions & 3 deletions src/test/tests/utils/testIntegration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 23d0840

Please sign in to comment.