|
| 1 | +import { scan } from "../../../lib"; |
| 2 | +import { getFixture } from "../../util"; |
| 3 | + |
| 4 | +describe("include-system-jars flag", () => { |
| 5 | + it("excludes system JARs by default", async () => { |
| 6 | + const fixturePath = getFixture("docker-archives/docker-save/java.tar"); |
| 7 | + const imageNameAndTag = `docker-archive:${fixturePath}`; |
| 8 | + |
| 9 | + const pluginResult = await scan({ |
| 10 | + path: imageNameAndTag, |
| 11 | + }); |
| 12 | + |
| 13 | + expect(pluginResult.scanResults).toBeDefined(); |
| 14 | + |
| 15 | + // Verify that no system JARs from /usr/lib are included |
| 16 | + const javaResults = pluginResult.scanResults.filter( |
| 17 | + (result) => result.identity.type === "maven", |
| 18 | + ); |
| 19 | + |
| 20 | + for (const result of javaResults) { |
| 21 | + if (result.identity?.targetFile) { |
| 22 | + expect(result.identity.targetFile).not.toContain("/usr/lib"); |
| 23 | + } |
| 24 | + } |
| 25 | + }); |
| 26 | + |
| 27 | + it("includes system JARs when --include-system-jars is true", async () => { |
| 28 | + const fixturePath = getFixture("docker-archives/docker-save/java.tar"); |
| 29 | + const imageNameAndTag = `docker-archive:${fixturePath}`; |
| 30 | + |
| 31 | + const pluginResult = await scan({ |
| 32 | + path: imageNameAndTag, |
| 33 | + "include-system-jars": true, |
| 34 | + }); |
| 35 | + |
| 36 | + // Verify the scan runs successfully and that the option is properly processed |
| 37 | + expect(pluginResult.scanResults).toBeDefined(); |
| 38 | + |
| 39 | + // Since the test fixture doesn't contain /usr/lib JARs, we verify the flag is processed |
| 40 | + // by checking that Maven results are still present (confirms our logic didn't break anything) |
| 41 | + const javaResults = pluginResult.scanResults.filter( |
| 42 | + (result) => result.identity.type === "maven", |
| 43 | + ); |
| 44 | + expect(javaResults.length).toBeGreaterThan(0); |
| 45 | + }); |
| 46 | + |
| 47 | + it("excludes system JARs when --include-system-jars is false", async () => { |
| 48 | + const fixturePath = getFixture("docker-archives/docker-save/java.tar"); |
| 49 | + const imageNameAndTag = `docker-archive:${fixturePath}`; |
| 50 | + |
| 51 | + const pluginResult = await scan({ |
| 52 | + path: imageNameAndTag, |
| 53 | + "include-system-jars": false, |
| 54 | + }); |
| 55 | + |
| 56 | + expect(pluginResult.scanResults).toBeDefined(); |
| 57 | + |
| 58 | + // Verify that no system JARs from /usr/lib are included |
| 59 | + const javaResults = pluginResult.scanResults.filter( |
| 60 | + (result) => result.identity.type === "maven", |
| 61 | + ); |
| 62 | + |
| 63 | + for (const result of javaResults) { |
| 64 | + if (result.identity?.targetFile) { |
| 65 | + expect(result.identity.targetFile).not.toContain("/usr/lib"); |
| 66 | + } |
| 67 | + } |
| 68 | + }); |
| 69 | + |
| 70 | + it("handles string values for include-system-jars flag", async () => { |
| 71 | + const fixturePath = getFixture("docker-archives/docker-save/java.tar"); |
| 72 | + const imageNameAndTag = `docker-archive:${fixturePath}`; |
| 73 | + |
| 74 | + const pluginResultTrue = await scan({ |
| 75 | + path: imageNameAndTag, |
| 76 | + "include-system-jars": "true", |
| 77 | + }); |
| 78 | + |
| 79 | + const pluginResultFalse = await scan({ |
| 80 | + path: imageNameAndTag, |
| 81 | + "include-system-jars": "false", |
| 82 | + }); |
| 83 | + |
| 84 | + // Both should run successfully with proper flag handling |
| 85 | + expect(pluginResultTrue.scanResults).toBeDefined(); |
| 86 | + expect(pluginResultFalse.scanResults).toBeDefined(); |
| 87 | + |
| 88 | + // Verify both produce Maven scan results |
| 89 | + const javaResultsTrue = pluginResultTrue.scanResults.filter( |
| 90 | + (result) => result.identity.type === "maven", |
| 91 | + ); |
| 92 | + const javaResultsFalse = pluginResultFalse.scanResults.filter( |
| 93 | + (result) => result.identity.type === "maven", |
| 94 | + ); |
| 95 | + |
| 96 | + expect(javaResultsTrue.length).toBeGreaterThan(0); |
| 97 | + expect(javaResultsFalse.length).toBeGreaterThan(0); |
| 98 | + }); |
| 99 | +}); |
0 commit comments