From ded7287f0468a9ba56a16f2825b65f71e3dc86bd Mon Sep 17 00:00:00 2001 From: Johan Wigert <45201794+jwigert@users.noreply.github.com> Date: Thu, 19 Oct 2023 08:39:13 +0200 Subject: [PATCH] restructure tests --- .../analysis/parser/GrypeParserTest.java | 30 ++++++++++++ .../parser/GrypeParserWoDescriptionTest.java | 46 ------------------- 2 files changed, 30 insertions(+), 46 deletions(-) delete mode 100644 src/test/java/edu/hm/hafner/analysis/parser/GrypeParserWoDescriptionTest.java diff --git a/src/test/java/edu/hm/hafner/analysis/parser/GrypeParserTest.java b/src/test/java/edu/hm/hafner/analysis/parser/GrypeParserTest.java index f4e77069e..d30c14973 100644 --- a/src/test/java/edu/hm/hafner/analysis/parser/GrypeParserTest.java +++ b/src/test/java/edu/hm/hafner/analysis/parser/GrypeParserTest.java @@ -5,6 +5,7 @@ import edu.hm.hafner.analysis.Report; import edu.hm.hafner.analysis.Severity; import edu.hm.hafner.analysis.assertions.SoftAssertions; +import org.junit.jupiter.api.Test; import static j2html.TagCreator.a; import static j2html.TagCreator.p; @@ -40,6 +41,35 @@ protected void assertThatIssuesArePresent(final Report report, final SoftAsserti .withText("https://nvd.nist.gov/vuln/detail/CVE-2016-8745")).render()); } + @Test + void assertThatVulnerabilityWithoutDescriptionCanBeParsed() { + var fileWithIssues = "grype-report-wo-description.json"; + var report = super.parse(fileWithIssues); + + try (var softly = new SoftAssertions()) { + softly.assertThat(report).hasSize(20).hasDuplicatesSize(13); + softly.assertThat(report.get(0)) + .hasFileName("/usr/local/bin/environment-to-ini") + .hasSeverity(Severity.ERROR) + .hasCategory("Critical") + .hasType("GHSA-pg38-r834-g45j") + .hasMessage("Improper Privilege Management in Gitea") + .hasDescription(p().with(a() + .withHref("https://github.com/advisories/GHSA-pg38-r834-g45j") + .withText("https://github.com/advisories/GHSA-pg38-r834-g45j")).render()); + + softly.assertThat(report.get(13)) + .hasFileName("/lib/apk/db/installed") + .hasSeverity(Severity.WARNING_HIGH) + .hasCategory("High") + .hasType("CVE-2023-38039") + .hasMessage("Unknown") + .hasDescription(p().with(a() + .withHref("http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2023-38039") + .withText("http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2023-38039")).render()); + } + } + @Override protected IssueParser createParser() { return new GrypeParser(); diff --git a/src/test/java/edu/hm/hafner/analysis/parser/GrypeParserWoDescriptionTest.java b/src/test/java/edu/hm/hafner/analysis/parser/GrypeParserWoDescriptionTest.java deleted file mode 100644 index c7a4aa7cd..000000000 --- a/src/test/java/edu/hm/hafner/analysis/parser/GrypeParserWoDescriptionTest.java +++ /dev/null @@ -1,46 +0,0 @@ -package edu.hm.hafner.analysis.parser; - -import edu.hm.hafner.analysis.AbstractParserTest; -import edu.hm.hafner.analysis.IssueParser; -import edu.hm.hafner.analysis.Report; -import edu.hm.hafner.analysis.Severity; -import edu.hm.hafner.analysis.assertions.SoftAssertions; - -import static j2html.TagCreator.a; -import static j2html.TagCreator.p; - -class GrypeParserWoDescriptionTest extends AbstractParserTest { - protected GrypeParserWoDescriptionTest() { - super("grype-report-wo-description.json"); - } - - @Override - protected void assertThatIssuesArePresent(final Report report, final SoftAssertions softly) { - softly.assertThat(report).hasSize(20).hasDuplicatesSize(13); - softly.assertThat(report.get(0)) - .hasFileName("/usr/local/bin/environment-to-ini") - .hasSeverity(Severity.ERROR) - .hasCategory("Critical") - .hasType("GHSA-pg38-r834-g45j") - .hasMessage("Improper Privilege Management in Gitea") - .hasDescription(p().with(a() - .withHref("https://github.com/advisories/GHSA-pg38-r834-g45j") - .withText("https://github.com/advisories/GHSA-pg38-r834-g45j")).render()); - - softly.assertThat(report.get(13)) - .hasFileName("/lib/apk/db/installed") - .hasSeverity(Severity.WARNING_HIGH) - .hasCategory("High") - .hasType("CVE-2023-38039") - .hasMessage("Unknown") - - .hasDescription(p().with(a() - .withHref("http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2023-38039") - .withText("http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2023-38039")).render()); - } - - @Override - protected IssueParser createParser() { - return new GrypeParser(); - } -}