-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Configuration model now supports secret, license and codescan #2441
- Loading branch information
Showing
3 changed files
with
353 additions
and
41 deletions.
There are no files selected for viewing
252 changes: 243 additions & 9 deletions
252
github-actions/scan/__test__/configuration-builder.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,271 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
import * as configBuilder from '../src/configuration-builder'; | ||
import { SecHubConfigurationModel, ContentType, ScanType } from '../src/configuration-model'; | ||
import { SecHubConfigurationModelBuilderData } from '../src/configuration-builder'; | ||
|
||
jest.mock('@actions/core'); | ||
|
||
|
||
function dumpModel(model: SecHubConfigurationModel){ | ||
const json = JSON.stringify(model, null, 2); // pretty printed output | ||
|
||
console.log('json='+json); | ||
} | ||
|
||
describe('configuration-builder', function() { | ||
test('null parameters - a model is created with api version 1.0.0', function () { | ||
/* execute */ | ||
const data = new SecHubConfigurationModelBuilderData(); | ||
const model= configBuilder.createSecHubConfigurationModel(data); | ||
const builderData = new SecHubConfigurationModelBuilderData(); | ||
const model= configBuilder.createSecHubConfigurationModel(builderData); | ||
|
||
/* test */ | ||
expect(model.apiVersion).toEqual('1.0'); | ||
expect(model.data.sources).toBeDefined(); | ||
expect(model.data.binaries).toBeUndefined(); | ||
}); | ||
|
||
test('codescan generated per default - source,one folder defined', () => { | ||
|
||
/* prepare */ | ||
const builderData = new SecHubConfigurationModelBuilderData(); | ||
builderData.includeFolders= ['folder1']; | ||
|
||
/* execute */ | ||
const model= configBuilder.createSecHubConfigurationModel(builderData); | ||
|
||
/* test */ | ||
dumpModel(model); | ||
|
||
expect(model.apiVersion).toEqual('1.0'); | ||
|
||
expect(model.data.sources).toBeDefined(); | ||
expect(model.data.binaries).toBeUndefined(); | ||
|
||
expect(model.data.sources?.length).toEqual(1); | ||
|
||
const firstSource = model.data.sources?.[0]; | ||
expect(firstSource?.fileSystem.folders?.length).toEqual(1); | ||
expect(firstSource?.fileSystem.folders?.[0]).toEqual('folder1'); | ||
|
||
expect(model.codeScan).toBeDefined(); | ||
expect(model.codeScan?.use.length).toEqual(1); | ||
expect(model.codeScan?.use[0]).toEqual('reference-data-1'); | ||
|
||
expect(model.secretScan).toBeUndefined(); | ||
expect(model.licenseScan).toBeUndefined(); | ||
|
||
}); | ||
|
||
test('codescan green', () => { | ||
test('codescan generated per default - source, two folders defined', () => { | ||
|
||
/* prepare */ | ||
const data = new SecHubConfigurationModelBuilderData(); | ||
data.includeFolders= ['folder1']; | ||
const builderData = new SecHubConfigurationModelBuilderData(); | ||
builderData.includeFolders= ['folder1','folder2']; | ||
|
||
/* execute */ | ||
const model= configBuilder.createSecHubConfigurationModel(builderData); | ||
|
||
/* test */ | ||
dumpModel(model); | ||
|
||
expect(model.apiVersion).toEqual('1.0'); | ||
|
||
expect(model.data.sources).toBeDefined(); | ||
expect(model.data.binaries).toBeUndefined(); | ||
|
||
expect(model.data.sources?.length).toEqual(1); | ||
|
||
const firstSource = model.data.sources?.[0]; | ||
expect(firstSource?.fileSystem.folders?.length).toEqual(2); | ||
expect(firstSource?.fileSystem.folders?.[0]).toEqual('folder1'); | ||
expect(firstSource?.fileSystem.folders?.[1]).toEqual('folder2'); | ||
expect(firstSource?.excludes?.length).toEqual(0); | ||
|
||
expect(model.codeScan).toBeDefined(); | ||
expect(model.codeScan?.use.length).toEqual(1); | ||
expect(model.codeScan?.use[0]).toEqual('reference-data-1'); | ||
|
||
expect(model.secretScan).toBeUndefined(); | ||
expect(model.licenseScan).toBeUndefined(); | ||
|
||
}); | ||
|
||
test('codescan generated per default - source, two folders defined, one excluded', () => { | ||
|
||
/* prepare */ | ||
const builderData = new SecHubConfigurationModelBuilderData(); | ||
builderData.includeFolders= ['folder1','folder2']; | ||
builderData.excludeFolders= ['folder3']; | ||
|
||
/* execute */ | ||
const model= configBuilder.createSecHubConfigurationModel(builderData); | ||
|
||
/* test */ | ||
dumpModel(model); | ||
|
||
expect(model.apiVersion).toEqual('1.0'); | ||
|
||
expect(model.data.sources).toBeDefined(); | ||
expect(model.data.binaries).toBeUndefined(); | ||
|
||
expect(model.data.sources?.length).toEqual(1); | ||
|
||
const firstSource = model.data.sources?.[0]; | ||
expect(firstSource?.fileSystem.folders?.length).toEqual(2); | ||
expect(firstSource?.fileSystem.folders?.[0]).toEqual('folder1'); | ||
expect(firstSource?.fileSystem.folders?.[1]).toEqual('folder2'); | ||
|
||
expect(firstSource?.excludes?.length).toEqual(1); | ||
expect(firstSource?.excludes?.[0]).toEqual('folder3'); | ||
|
||
expect(model.codeScan).toBeDefined(); | ||
expect(model.codeScan?.use.length).toEqual(1); | ||
expect(model.codeScan?.use[0]).toEqual('reference-data-1'); | ||
|
||
expect(model.secretScan).toBeUndefined(); | ||
expect(model.licenseScan).toBeUndefined(); | ||
|
||
const model= configBuilder.createSecHubConfigurationModel(data); | ||
}); | ||
|
||
test('codescan generated per default - binaries, two folders defined', () => { | ||
|
||
/* prepare */ | ||
const builderData = new SecHubConfigurationModelBuilderData(); | ||
builderData.includeFolders= ['folder1','folder2']; | ||
builderData.contentType=ContentType.BINARIES; | ||
|
||
/* execute */ | ||
const model= configBuilder.createSecHubConfigurationModel(builderData); | ||
|
||
/* test */ | ||
dumpModel(model); | ||
|
||
expect(model.apiVersion).toEqual('1.0'); | ||
|
||
expect(model.data.sources).toBeUndefined(); | ||
expect(model.data.binaries).toBeDefined(); | ||
|
||
expect(model.data.binaries?.length).toEqual(1); | ||
|
||
const firstBinary = model.data.binaries?.[0]; | ||
expect(firstBinary?.fileSystem.folders?.length).toEqual(2); | ||
expect(firstBinary?.fileSystem.folders?.[0]).toEqual('folder1'); | ||
expect(firstBinary?.fileSystem.folders?.[1]).toEqual('folder2'); | ||
expect(firstBinary?.excludes?.length).toEqual(0); | ||
|
||
expect(model.codeScan).toBeDefined(); | ||
expect(model.codeScan?.use.length).toEqual(1); | ||
expect(model.codeScan?.use[0]).toEqual('reference-data-1'); | ||
|
||
expect(model.secretScan).toBeUndefined(); | ||
expect(model.licenseScan).toBeUndefined(); | ||
}); | ||
|
||
test('codescan and license scan - two folders defined', () => { | ||
|
||
/* prepare */ | ||
const builderData = new SecHubConfigurationModelBuilderData(); | ||
builderData.includeFolders= ['folder1','folder2']; | ||
builderData.scanTypes=[ScanType.CODE_SCAN,ScanType.LICENSE_SCAN]; | ||
|
||
/* execute */ | ||
const model= configBuilder.createSecHubConfigurationModel(builderData); | ||
|
||
/* test */ | ||
dumpModel(model); | ||
|
||
expect(model.apiVersion).toEqual('1.0'); | ||
|
||
expect(model.data.sources); | ||
expect(model.data.sources?.length).toEqual(1); | ||
|
||
const firstSource = model.data.sources?.[0]; | ||
expect(firstSource?.fileSystem.folders?.length).toEqual(2); | ||
expect(firstSource?.fileSystem.folders?.[0]).toEqual('folder1'); | ||
expect(firstSource?.fileSystem.folders?.[1]).toEqual('folder2'); | ||
|
||
expect(model.codeScan).toBeDefined(); | ||
expect(model.codeScan?.use.length).toEqual(1); | ||
expect(model.codeScan?.use[0]).toEqual('reference-data-1'); | ||
|
||
expect(model.licenseScan).toBeDefined(); | ||
expect(model.licenseScan?.use.length).toEqual(1); | ||
expect(model.licenseScan?.use[0]).toEqual('reference-data-1'); // same data refererenced | ||
|
||
expect(model.secretScan).toBeUndefined(); | ||
|
||
}); | ||
test('codescan and secret scan - two folders defined', () => { | ||
|
||
/* prepare */ | ||
const builderData = new SecHubConfigurationModelBuilderData(); | ||
builderData.includeFolders= ['folder1','folder2']; | ||
builderData.scanTypes=[ScanType.CODE_SCAN,ScanType.SECRET_SCAN]; | ||
|
||
/* execute */ | ||
const model= configBuilder.createSecHubConfigurationModel(builderData); | ||
|
||
/* test */ | ||
dumpModel(model); | ||
|
||
expect(model.apiVersion).toEqual('1.0'); | ||
|
||
expect(model.data.sources); | ||
expect(model.data.sources?.length).toEqual(1); | ||
|
||
const firstSource = model.data.sources?.[0]; | ||
expect(firstSource?.fileSystem.folders?.length).toEqual(2); | ||
expect(firstSource?.fileSystem.folders?.[0]).toEqual('folder1'); | ||
expect(firstSource?.fileSystem.folders?.[1]).toEqual('folder2'); | ||
|
||
expect(model.codeScan).toBeDefined(); | ||
expect(model.codeScan?.use.length).toEqual(1); | ||
expect(model.codeScan?.use[0]).toEqual('reference-data-1'); | ||
|
||
expect(model.codeScan?.use.length).toEqual(1); | ||
expect(model.codeScan?.use[0]).toEqual('reference-data-1'); | ||
|
||
expect(model.secretScan).toBeDefined(); | ||
expect(model.secretScan?.use.length).toEqual(1); | ||
expect(model.secretScan?.use[0]).toEqual('reference-data-1'); // same data refererenced | ||
|
||
expect(model.licenseScan).toBeUndefined(); | ||
|
||
}); | ||
test('secret scan standalone - source, one folder defined, one excluded', () => { | ||
|
||
/* prepare */ | ||
const builderData = new SecHubConfigurationModelBuilderData(); | ||
builderData.includeFolders= ['folder1']; | ||
builderData.excludeFolders= ['folderX']; | ||
builderData.scanTypes=[ScanType.SECRET_SCAN]; | ||
|
||
/* execute */ | ||
const model= configBuilder.createSecHubConfigurationModel(builderData); | ||
|
||
/* test */ | ||
const json = JSON.stringify(model); | ||
dumpModel(model); | ||
|
||
console.log('json='+json); | ||
expect(model.apiVersion).toEqual('1.0'); | ||
expect(model.codeScan); | ||
|
||
expect(model.data.sources); | ||
expect(model.data.sources?.length).toEqual(1); | ||
|
||
const firstSource = model.data.sources?.[0]; | ||
expect(firstSource?.fileSystem.folders?.length).toEqual(1); | ||
expect(firstSource?.fileSystem.folders?.[0]).toEqual('folder1'); | ||
expect(firstSource?.excludes?.length).toEqual(1); | ||
expect(firstSource?.excludes?.[0]).toEqual('folderX'); | ||
|
||
expect(model.codeScan).toBeUndefined(); | ||
|
||
expect(model.secretScan).toBeDefined(); | ||
expect(model.secretScan?.use.length).toEqual(1); | ||
expect(model.secretScan?.use[0]).toEqual('reference-data-1'); // same data refererenced | ||
|
||
expect(model.licenseScan).toBeUndefined(); | ||
|
||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.