Skip to content

Commit

Permalink
Merge pull request #117 from snyk/feat/include-snyk-details-url-in-er…
Browse files Browse the repository at this point in the history
…ror-messages

feat: include snyk details URL in error messages
  • Loading branch information
jacek-rzrz authored Nov 13, 2024
2 parents 40aed5f + ef73e17 commit 06e67e7
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 8 deletions.
6 changes: 6 additions & 0 deletions core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@
<version>5.4.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>3.26.3</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ private void validateIssues(IssueSummary summary, Severity threshold, boolean ig
}

LOG.debug("Package has {} with severity {} or higher: {}", issueType, threshold, artifact.getPath());
throw new CancelException(format("Artifact has %s with severity %s or higher: %s", issueType, threshold, artifact.getPath()), 403);
throw new CancelException(format("Artifact has %s with severity %s or higher: %s. Details: %s",
issueType, threshold, artifact.getPath(), artifact.getTestResult().getDetailsUrl()
), 403);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
import java.net.URI;
import java.util.stream.Stream;

import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.assertj.core.api.AssertionsForClassTypes.assertThatCode;
import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy;

class PackageValidatorTest {

Expand All @@ -28,7 +28,7 @@ void validate_severityBelowThreshold_allowed() {
new Ignores()
);

assertDoesNotThrow(() -> validator.validate(artifact));
assertThatCode(() -> validator.validate(artifact)).doesNotThrowAnyException();
}

@Test
Expand All @@ -46,7 +46,7 @@ void validate_vulnIssueAboveThreshold_forbidden() {
new Ignores()
);

assertThrows(CancelException.class, () -> validator.validate(artifact));
assertThatThrownBy(() -> validator.validate(artifact)).isExactlyInstanceOf(CancelException.class);
}

@Test
Expand All @@ -64,7 +64,7 @@ void validate_vulnIssuesIgnored_allowed() {
new Ignores().withIgnoreVulnIssues(true)
);

assertDoesNotThrow(() -> validator.validate(artifact));
assertThatCode(() -> validator.validate(artifact)).doesNotThrowAnyException();
}

@Test
Expand All @@ -82,7 +82,7 @@ void validate_licenseIssueAboveThreshold_forbidden() {
new Ignores()
);

assertThrows(CancelException.class, () -> validator.validate(artifact));
assertThatThrownBy(() -> validator.validate(artifact)).isExactlyInstanceOf(CancelException.class);
}

@Test
Expand All @@ -100,6 +100,25 @@ void validate_licenseIssuesIgnored_allowed() {
new Ignores().withIgnoreLicenseIssues(true)
);

assertDoesNotThrow(() -> validator.validate(artifact));
assertThatCode(() -> validator.validate(artifact)).doesNotThrowAnyException();
}

@Test
void validate_includesSnykDetailsUrlInCancelException() {
ValidationSettings settings = new ValidationSettings()
.withVulnSeverityThreshold(Severity.LOW);
PackageValidator validator = new PackageValidator(settings);
MonitoredArtifact artifact = new MonitoredArtifact("",
new TestResult(
IssueSummary.from(Stream.of(Severity.LOW)),
IssueSummary.from(Stream.empty()),
URI.create("https://snyk.io/package/details")
),
new Ignores()
);

assertThatThrownBy(() -> validator.validate(artifact))
.isExactlyInstanceOf(CancelException.class)
.hasMessageContaining("https://snyk.io/package/details");
}
}

0 comments on commit 06e67e7

Please sign in to comment.