Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2119 from snyk/fix/yaml-doc-indexes
fix: IaC multi-doc yaml indexing
- Loading branch information
Showing
5 changed files
with
116 additions
and
34 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
--- | ||
apiVersion: v1 | ||
kind: Pod | ||
metadata: | ||
name: example1 | ||
spec: | ||
containers: | ||
- name: example | ||
image: example:latest | ||
securityContext: | ||
privileged: true | ||
--- | ||
apiVersion: v1 | ||
kind: Pod | ||
metadata: | ||
name: example2 | ||
spec: | ||
containers: | ||
- name: example | ||
image: example:latest | ||
securityContext: | ||
privileged: true |
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,34 @@ | ||
import { startMockServer } from './helpers'; | ||
import { MappedIacTestResponse } from '../../../../src/lib/snyk-test/iac-test-result'; | ||
jest.setTimeout(50000); | ||
|
||
describe('iac test --json file.yaml', () => { | ||
let run: ( | ||
cmd: string, | ||
) => Promise<{ stdout: string; stderr: string; exitCode: number }>; | ||
let teardown: () => void; | ||
|
||
beforeAll(async () => { | ||
({ run, teardown } = await startMockServer()); | ||
}); | ||
|
||
afterAll(async () => teardown()); | ||
|
||
it('supports the correct line numbers for multi-doc YAML files', async () => { | ||
// Test a multidoc YAML file with one "high" issue in each subdoc. | ||
const { stdout } = await run( | ||
`snyk iac test --json --severity-threshold=high ./iac/kubernetes/pod-privileged-multi.yaml`, | ||
); | ||
|
||
const result: MappedIacTestResponse = JSON.parse(stdout); | ||
const issues = result.infrastructureAsCodeIssues; | ||
|
||
expect(issues.length).toBe(2); | ||
|
||
expect(issues[0].lineNumber).toBe(11); | ||
expect(issues[1].lineNumber).toBe(22); | ||
|
||
expect(issues[0].path[0]).toBe('[DocId: 0]'); | ||
expect(issues[1].path[0]).toBe('[DocId: 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