-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8fbeea7
commit 6e660f0
Showing
29 changed files
with
485 additions
and
93 deletions.
There are no files selected for viewing
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
File renamed without changes.
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
83 changes: 83 additions & 0 deletions
83
packages/validation/src/__tests__/sarif/suppression.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 |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import 'isomorphic-fetch'; | ||
import {expect, it} from 'vitest'; | ||
import {createDefaultMonokleValidator} from '../../index.js'; | ||
|
||
import {PRACTICES_ALL_DISABLED, extractK8sResources, readDirectory} from '../testUtils.js'; | ||
import {FakeSuppressor} from '../../sarif/suppressions/plugins/FakeSuppressor.js'; | ||
import YAML from 'yaml'; | ||
import {set} from 'lodash'; | ||
|
||
it('supports suppress requests', async () => { | ||
const suppressor = new FakeSuppressor(); | ||
const validator = createDefaultMonokleValidator(undefined, undefined, [suppressor]); | ||
|
||
await validator.preload({ | ||
plugins: { | ||
practices: true, | ||
}, | ||
rules: { | ||
...PRACTICES_ALL_DISABLED, | ||
'practices/no-latest-image': 'err', | ||
}, | ||
}); | ||
|
||
// Given a problem | ||
const files = await readDirectory('./src/__tests__/resources/basic-deployment'); | ||
const badResponse = await validator.validate({ | ||
resources: extractK8sResources(files), | ||
}); | ||
const problemCount = badResponse.runs[0].results.length; | ||
expect(problemCount).toBe(1); | ||
|
||
// When it is suppressed | ||
suppressor.addSuppressionRequest(badResponse.runs[0].results[0]); | ||
|
||
// Then the next validate response will mark the suppress request | ||
const editedResponse = await validator.validate({ | ||
resources: extractK8sResources(files), | ||
}); | ||
|
||
editedResponse.runs.forEach(r => | ||
r.results.forEach(result => { | ||
console.error(result.ruleId, result.suppressions); | ||
}) | ||
); | ||
|
||
const problem = editedResponse.runs[0].results[0]; | ||
expect(problem.suppressions?.length).toBe(1); | ||
}); | ||
|
||
it('in-line annotation suppressions by default', async () => { | ||
const validator = createDefaultMonokleValidator(); | ||
|
||
await validator.preload({ | ||
plugins: { | ||
practices: true, | ||
}, | ||
rules: { | ||
...PRACTICES_ALL_DISABLED, | ||
'practices/no-latest-image': 'err', | ||
}, | ||
}); | ||
|
||
// Given a problem | ||
const files = await readDirectory('./src/__tests__/resources/basic-deployment'); | ||
const badResponse = await validator.validate({ | ||
resources: extractK8sResources(files), | ||
}); | ||
const problemCount = badResponse.runs[0].results.length; | ||
expect(problemCount).toBe(1); | ||
|
||
// When an annotation is added | ||
const content = YAML.parse(files[0].content); | ||
set(content, 'metadata.annotations["monokle.io/suppress.kbp.no-latest-image"]', true); | ||
files[0].content = YAML.stringify(content); | ||
|
||
// Then the next validate response will mark the suppress request | ||
const editedResponse = await validator.validate({ | ||
resources: extractK8sResources(files), | ||
}); | ||
|
||
const problem = editedResponse.runs[0].results[0]; | ||
expect(problem.suppressions?.length).toBe(1); | ||
}); |
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
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
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
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
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
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
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
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
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.