Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change SAST log messages and update config default root #433

Merged
merged 6 commits into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion 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.AnalyzeApplicability, logManager, new AppsConfigModule(), binary);
super(connectionManager, ScanType.AnalyzeApplicability, logManager, new AppsConfigModule(__dirname), binary);
}

/** @override */
Expand Down
6 changes: 3 additions & 3 deletions src/main/scanLogic/scanRunners/jasRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ 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
public static readonly TIMEOUT_MILLISECS: number = 1000 * 60 * 5;
// 8 min
public static readonly TIMEOUT_MILLISECS: number = 1000 * 60 * 8;

public static readonly NOT_ENTITLED: number = 31;
public static readonly NOT_SUPPORTED: number = 13;
Expand Down Expand Up @@ -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'
);
}
Expand Down
9 changes: 8 additions & 1 deletion src/main/scanLogic/scanRunners/sastScan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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
Expand Down
12 changes: 6 additions & 6 deletions src/main/utils/jfrogAppsConfig/jfrogAppsConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ export class JFrogAppsConfig {
this._version = jfrogAppsConfig.version;
if (jfrogAppsConfig.modules) {
for (let module of jfrogAppsConfig.modules) {
this._modules.push(new AppsConfigModule(module));
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));
}
}

Expand All @@ -45,10 +45,10 @@ export class AppsConfigModule {
private _excludeScanners: ScanType[] = [];
private _scanners: Map<ScanType, Scanner> = new Map<ScanType, Scanner>();

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) {
Expand Down Expand Up @@ -127,12 +127,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);
}
}

Expand Down
13 changes: 8 additions & 5 deletions src/test/tests/appsConfig.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]);

Expand All @@ -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('', { exclude_scanners: testCase.excludeScanners } as Module);
assert.equal(module.ShouldSkipScanner(ScanType.AnalyzeApplicability), testCase.shouldSkip);
});
});
Expand All @@ -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]);
Expand All @@ -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]);
Expand All @@ -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('', {
exclude_patterns: ['exclude-root'],
scanners: { secrets: testCase?.scanner }
} as Module);
Expand Down
2 changes: 1 addition & 1 deletion src/test/tests/iacScan.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ describe('Iac Scan Tests', () => {
createTestStepProgress(),
{} as ConnectionManager,
logManager,
new AppsConfigModule()
new AppsConfigModule('')
);
}
});
2 changes: 1 addition & 1 deletion src/test/tests/integration/iac.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ describe('Iac Integration Tests', async () => {
createTestStepProgress(),
integrationManager.connectionManager,
integrationManager.logManager,
new AppsConfigModule(),
new AppsConfigModule(testDataRoot),
integrationManager.resource
);
runner.verbose = true;
Expand Down
2 changes: 1 addition & 1 deletion src/test/tests/integration/secrets.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ describe('Secrets Scan Integration Tests', async () => {
createTestStepProgress(),
integrationManager.connectionManager,
integrationManager.logManager,
new AppsConfigModule(),
new AppsConfigModule(testDataRoot),
integrationManager.resource
);
runner.verbose = true;
Expand Down
2 changes: 1 addition & 1 deletion src/test/tests/sastScan.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ describe('Sast Tests', () => {
createTestStepProgress(),
{} as ConnectionManager,
logManager,
new AppsConfigModule()
new AppsConfigModule('')
);
}
});
2 changes: 1 addition & 1 deletion src/test/tests/scanAnlayzerRunner.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ describe('Analyzer BinaryRunner tests', async () => {
): Promise<void> {
await RunUtils.runWithTimeout(timeout, checkCancel, dummyAction());
}
})(connection, dummyName, logManager, new AppsConfigModule());
})(connection, dummyName, logManager, new AppsConfigModule(''));
}

[
Expand Down
2 changes: 1 addition & 1 deletion src/test/tests/secretsScan.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ describe('Secrets Scan Tests', () => {
createTestStepProgress(),
{} as ConnectionManager,
logManager,
new AppsConfigModule()
new AppsConfigModule('')
);
}
});
Loading