|
| 1 | +import { scan } from "../../../lib"; |
| 2 | +import { getFixture } from "../../util"; |
| 3 | + |
| 4 | +describe("target-reference flag", () => { |
| 5 | + it("applies target-reference to OS scan result", async () => { |
| 6 | + const fixturePath = getFixture( |
| 7 | + "docker-archives/skopeo-copy/rpm-npm-yarn.tar", |
| 8 | + ); |
| 9 | + const imageNameAndTag = `docker-archive:${fixturePath}`; |
| 10 | + const targetReference = "my-custom-reference"; |
| 11 | + |
| 12 | + const pluginResult = await scan({ |
| 13 | + path: imageNameAndTag, |
| 14 | + "target-reference": targetReference, |
| 15 | + "exclude-app-vulns": true, |
| 16 | + }); |
| 17 | + |
| 18 | + expect(pluginResult.scanResults).toHaveLength(1); |
| 19 | + |
| 20 | + // OS scan result should have targetReference |
| 21 | + const osScanResult = pluginResult.scanResults[0]; |
| 22 | + expect(osScanResult.targetReference).toEqual(targetReference); |
| 23 | + }); |
| 24 | + |
| 25 | + it("applies target-reference to both OS and application scan results", async () => { |
| 26 | + const fixturePath = getFixture( |
| 27 | + "docker-archives/skopeo-copy/rpm-npm-yarn.tar", |
| 28 | + ); |
| 29 | + const imageNameAndTag = `docker-archive:${fixturePath}`; |
| 30 | + const targetReference = "my-custom-reference"; |
| 31 | + |
| 32 | + const pluginResult = await scan({ |
| 33 | + path: imageNameAndTag, |
| 34 | + "target-reference": targetReference, |
| 35 | + }); |
| 36 | + |
| 37 | + // Should have OS scan result + application scan results |
| 38 | + expect(pluginResult.scanResults.length).toBeGreaterThan(1); |
| 39 | + |
| 40 | + // All scan results should have the targetReference |
| 41 | + for (const scanResult of pluginResult.scanResults) { |
| 42 | + expect(scanResult.targetReference).toEqual(targetReference); |
| 43 | + } |
| 44 | + }); |
| 45 | + |
| 46 | + it("does not include targetReference when option is not provided", async () => { |
| 47 | + const fixturePath = getFixture( |
| 48 | + "docker-archives/skopeo-copy/rpm-npm-yarn.tar", |
| 49 | + ); |
| 50 | + const imageNameAndTag = `docker-archive:${fixturePath}`; |
| 51 | + |
| 52 | + const pluginResult = await scan({ |
| 53 | + path: imageNameAndTag, |
| 54 | + }); |
| 55 | + |
| 56 | + // Should have OS scan result + application scan results |
| 57 | + expect(pluginResult.scanResults.length).toBeGreaterThan(1); |
| 58 | + |
| 59 | + // No scan results should have targetReference |
| 60 | + for (const scanResult of pluginResult.scanResults) { |
| 61 | + expect(scanResult.targetReference).toBeUndefined(); |
| 62 | + } |
| 63 | + }); |
| 64 | +}); |
0 commit comments