|
| 1 | +const summary = require("./trivy"); |
| 2 | + |
| 3 | +const tests = [ |
| 4 | + { |
| 5 | + title: "invalid report", |
| 6 | + report: null, |
| 7 | + expected: undefined, |
| 8 | + }, |
| 9 | + { |
| 10 | + title: "critical report", |
| 11 | + report: [ |
| 12 | + { |
| 13 | + name: "app", |
| 14 | + url: "https://github.com//orgs/SocialGouv/packages/container/package/sample-next-app%2Fapp", |
| 15 | + image: "ghcr.io/socialgouv/sample-next-app/app", |
| 16 | + trivy: { |
| 17 | + Target: |
| 18 | + "ghcr.io/socialgouv/sample-next-app/app:latest (alpine 3.11.12)", |
| 19 | + Vulnerabilities: [ |
| 20 | + { |
| 21 | + VulnerabilityID: "CVE-2018-17360", |
| 22 | + PkgName: "binutils", |
| 23 | + PrimaryURL: "https://avd.aquasec.com/nvd/cve-2018-17360", |
| 24 | + Title: |
| 25 | + "binutils: heap-based buffer over-read in bfd_getl32 in libbfd.c", |
| 26 | + Severity: "MEDIUM", |
| 27 | + }, |
| 28 | + ], |
| 29 | + }, |
| 30 | + }, |
| 31 | + { |
| 32 | + name: "hasura", |
| 33 | + url: "https://github.com//orgs/SocialGouv/packages/container/package/sample-next-app%2Fhasura", |
| 34 | + image: "ghcr.io/socialgouv/sample-next-app/hasura", |
| 35 | + trivy: { |
| 36 | + Target: |
| 37 | + "ghcr.io/socialgouv/sample-next-app/hasura:latest (debian 10.9)", |
| 38 | + Vulnerabilities: [ |
| 39 | + { |
| 40 | + VulnerabilityID: "CVE-2019-18276", |
| 41 | + PkgName: "bash", |
| 42 | + PrimaryURL: "https://avd.aquasec.com/nvd/cve-2019-18276", |
| 43 | + Title: |
| 44 | + "bash: when effective UID is not equal to its real UID the saved UID is not dropped", |
| 45 | + Severity: "HIGH", |
| 46 | + }, |
| 47 | + { |
| 48 | + VulnerabilityID: "CVE-2018-12699", |
| 49 | + PkgName: "binutils", |
| 50 | + PrimaryURL: "https://avd.aquasec.com/nvd/cve-2018-12699", |
| 51 | + Title: |
| 52 | + "binutils: heap-based buffer overflow in finish_stab in stabs.c", |
| 53 | + Severity: "CRITICAL", |
| 54 | + }, |
| 55 | + ], |
| 56 | + }, |
| 57 | + }, |
| 58 | + ], |
| 59 | + expected: { |
| 60 | + trivy: 3, |
| 61 | + trivyGrade: "F", |
| 62 | + }, |
| 63 | + }, |
| 64 | + { |
| 65 | + title: "medium report", |
| 66 | + report: [ |
| 67 | + { |
| 68 | + name: "app", |
| 69 | + url: "https://github.com//orgs/SocialGouv/packages/container/package/sample-next-app%2Fapp", |
| 70 | + image: "ghcr.io/socialgouv/sample-next-app/app", |
| 71 | + trivy: { |
| 72 | + Target: |
| 73 | + "ghcr.io/socialgouv/sample-next-app/app:latest (alpine 3.11.12)", |
| 74 | + Vulnerabilities: [ |
| 75 | + { |
| 76 | + VulnerabilityID: "CVE-2018-17360", |
| 77 | + PkgName: "binutils", |
| 78 | + PrimaryURL: "https://avd.aquasec.com/nvd/cve-2018-17360", |
| 79 | + Title: |
| 80 | + "binutils: heap-based buffer over-read in bfd_getl32 in libbfd.c", |
| 81 | + Severity: "MEDIUM", |
| 82 | + }, |
| 83 | + ], |
| 84 | + }, |
| 85 | + }, |
| 86 | + { |
| 87 | + name: "hasura", |
| 88 | + url: "https://github.com//orgs/SocialGouv/packages/container/package/sample-next-app%2Fhasura", |
| 89 | + image: "ghcr.io/socialgouv/sample-next-app/hasura", |
| 90 | + trivy: { |
| 91 | + Target: |
| 92 | + "ghcr.io/socialgouv/sample-next-app/hasura:latest (debian 10.9)", |
| 93 | + }, |
| 94 | + }, |
| 95 | + ], |
| 96 | + expected: { |
| 97 | + trivy: 1, |
| 98 | + trivyGrade: "C", |
| 99 | + }, |
| 100 | + }, |
| 101 | +]; |
| 102 | + |
| 103 | +describe("trivy", () => { |
| 104 | + tests.forEach((t) => { |
| 105 | + test(`${t.title} should return ${JSON.stringify(t.expected)}`, () => { |
| 106 | + //@ts-expect-error |
| 107 | + expect(summary(t.report)).toEqual(t.expected); |
| 108 | + }); |
| 109 | + }); |
| 110 | +}); |
0 commit comments