Skip to content

Commit

Permalink
CR
Browse files Browse the repository at this point in the history
  • Loading branch information
yahavi committed Oct 12, 2023
1 parent db359b8 commit 0ab640b
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/main/scanLogic/scanRunners/analyzerModels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ export interface AnalyzerRequest {
}

export enum ScanType {
ContextualAnalysis = 'analyze-applicability',
AnalyzeApplicability = 'analyze-applicability',
Iac = 'iac-scan-modules',
Sast = 'sast',
Secrets = 'secrets-scan'
Expand Down
4 changes: 2 additions & 2 deletions src/main/scanLogic/scanRunners/applicabilityScan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export class ApplicabilityRunner extends JasRunner {
logManager: LogManager,
binary?: Resource
) {
super(connectionManager, ScanType.ContextualAnalysis, logManager, new AppsConfigModule(), binary);
super(connectionManager, ScanType.AnalyzeApplicability, logManager, new AppsConfigModule(), binary);
}

/** @override */
Expand Down Expand Up @@ -94,7 +94,7 @@ export class ApplicabilityRunner extends JasRunner {
let startApplicableTime: number = Date.now();

const request: ApplicabilityScanArgs = {
type: ScanType.ContextualAnalysis,
type: ScanType.AnalyzeApplicability,
roots: [workspacePath],
cve_whitelist: Array.from(cveToScan),
skipped_folders: excludePatterns
Expand Down
17 changes: 10 additions & 7 deletions src/main/scanLogic/scanRunners/jasRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -398,25 +398,28 @@ export abstract class JasRunner {
this._logManager.debug('Input YAML:\n' + request);

// 2. Run the binary
await this.runBinary(requestPath, this._verbose ? undefined : path.dirname(requestPath), checkCancel, responsePath).catch(error => {
if (error.code) {
try {
await this.runBinary(requestPath, this._verbose ? undefined : path.dirname(requestPath), checkCancel, responsePath);
} catch (error) {
let code: number | undefined = (<any>error).code;
if (code) {
// Not entitled to run binary
if (error.code === JasRunner.NOT_ENTITLED) {
if (code === JasRunner.NOT_ENTITLED) {
throw new NotEntitledError();
}
if (error.code === JasRunner.NOT_SUPPORTED) {
if (code === JasRunner.NOT_SUPPORTED) {
throw new NotSupportedError(Translators.toAnalyzerTypeString(this._scanType));
}
if (error.code === JasRunner.OS_NOT_SUPPORTED) {
if (code === JasRunner.OS_NOT_SUPPORTED) {
throw new OsNotSupportedError(Translators.toAnalyzerTypeString(this._scanType));
}
this._logManager.logMessage(
"Binary '" + Translators.toAnalyzerTypeString(this._scanType) + "' task ended with status code: " + error.code,
"Binary '" + Translators.toAnalyzerTypeString(this._scanType) + "' task ended with status code: " + code,
'ERR'
);
}
throw error;
});
}
// 3. Collect responses
if (!fs.existsSync(responsePath)) {
throw new Error(
Expand Down
4 changes: 2 additions & 2 deletions src/main/utils/jfrogAppsConfig/jfrogAppsConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export class AppsConfigModule {
this._excludeScanners.push(ScanType.Secrets);
break;
case ExcludeScannerName.ContextualAnalysis:
this._excludeScanners.push(ScanType.ContextualAnalysis);
this._excludeScanners.push(ScanType.AnalyzeApplicability);
}
}
}
Expand Down Expand Up @@ -153,7 +153,7 @@ export class AppsConfigModule {
excludeScanners.push(ScanType.Secrets);
break;
case ExcludeScannerName.ContextualAnalysis:
excludeScanners.push(ScanType.ContextualAnalysis);
excludeScanners.push(ScanType.AnalyzeApplicability);
}
}
return excludeScanners;
Expand Down
2 changes: 1 addition & 1 deletion src/main/utils/translators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import { Utils } from './utils';
export class Translators {
public static toAnalyzerTypeString(type: ScanType): string {
switch (type) {
case ScanType.ContextualAnalysis:
case ScanType.AnalyzeApplicability:
return 'contextual-analysis';
case ScanType.Iac:
return 'iac-scan';
Expand Down
2 changes: 1 addition & 1 deletion src/test/tests/appsConfig.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ describe('JFrog Apps Config Tests', () => {
].forEach(testCase => {
it('Should skip scanner - ' + testCase.excludeScanners, () => {
let module: AppsConfigModule = new AppsConfigModule({ exclude_scanners: testCase.excludeScanners } as Module);
assert.equal(module.ShouldSkipScanner(ScanType.ContextualAnalysis), testCase.shouldSkip);
assert.equal(module.ShouldSkipScanner(ScanType.AnalyzeApplicability), testCase.shouldSkip);
});
});

Expand Down
4 changes: 2 additions & 2 deletions src/test/tests/scanAnlayzerRunner.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { Translators } from '../../main/utils/translators';
describe('Analyzer BinaryRunner tests', async () => {
let logManager: LogManager = new LogManager().activate();
let connectionManager: ConnectionManager = createBinaryRunnerConnectionManager('url', 'username', 'pass', 'token');
const dummyName: ScanType = ScanType.ContextualAnalysis;
const dummyName: ScanType = ScanType.AnalyzeApplicability;

function createBinaryRunnerConnectionManager(inputUrl: string, user: string, pass: string, token: string): ConnectionManager {
return {
Expand Down Expand Up @@ -161,7 +161,7 @@ describe('Analyzer BinaryRunner tests', async () => {
});
});

function getAnalyzeScanRequest(roots: string[], scanType: ScanType = ScanType.ContextualAnalysis): AnalyzeScanRequest {
function getAnalyzeScanRequest(roots: string[], scanType: ScanType = ScanType.AnalyzeApplicability): AnalyzeScanRequest {
return {
type: scanType,
output: '/path/to/output.json',
Expand Down

0 comments on commit 0ab640b

Please sign in to comment.