Skip to content

Commit 06e67e7

Browse files
authored
Merge pull request #117 from snyk/feat/include-snyk-details-url-in-error-messages
feat: include snyk details URL in error messages
2 parents 40aed5f + ef73e17 commit 06e67e7

3 files changed

Lines changed: 35 additions & 8 deletions

File tree

core/pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@
4343
<version>5.4.0</version>
4444
<scope>test</scope>
4545
</dependency>
46+
<dependency>
47+
<groupId>org.assertj</groupId>
48+
<artifactId>assertj-core</artifactId>
49+
<version>3.26.3</version>
50+
<scope>test</scope>
51+
</dependency>
4652
</dependencies>
4753

4854
<build>

core/src/main/java/io/snyk/plugins/artifactory/scanner/PackageValidator.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,9 @@ private void validateIssues(IssueSummary summary, Severity threshold, boolean ig
5858
}
5959

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

6466
}

core/src/test/java/io/snyk/plugins/artifactory/scanner/PackageValidatorTest.java

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
import java.net.URI;
99
import java.util.stream.Stream;
1010

11-
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
12-
import static org.junit.jupiter.api.Assertions.assertThrows;
11+
import static org.assertj.core.api.AssertionsForClassTypes.assertThatCode;
12+
import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy;
1313

1414
class PackageValidatorTest {
1515

@@ -28,7 +28,7 @@ void validate_severityBelowThreshold_allowed() {
2828
new Ignores()
2929
);
3030

31-
assertDoesNotThrow(() -> validator.validate(artifact));
31+
assertThatCode(() -> validator.validate(artifact)).doesNotThrowAnyException();
3232
}
3333

3434
@Test
@@ -46,7 +46,7 @@ void validate_vulnIssueAboveThreshold_forbidden() {
4646
new Ignores()
4747
);
4848

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

5252
@Test
@@ -64,7 +64,7 @@ void validate_vulnIssuesIgnored_allowed() {
6464
new Ignores().withIgnoreVulnIssues(true)
6565
);
6666

67-
assertDoesNotThrow(() -> validator.validate(artifact));
67+
assertThatCode(() -> validator.validate(artifact)).doesNotThrowAnyException();
6868
}
6969

7070
@Test
@@ -82,7 +82,7 @@ void validate_licenseIssueAboveThreshold_forbidden() {
8282
new Ignores()
8383
);
8484

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

8888
@Test
@@ -100,6 +100,25 @@ void validate_licenseIssuesIgnored_allowed() {
100100
new Ignores().withIgnoreLicenseIssues(true)
101101
);
102102

103-
assertDoesNotThrow(() -> validator.validate(artifact));
103+
assertThatCode(() -> validator.validate(artifact)).doesNotThrowAnyException();
104+
}
105+
106+
@Test
107+
void validate_includesSnykDetailsUrlInCancelException() {
108+
ValidationSettings settings = new ValidationSettings()
109+
.withVulnSeverityThreshold(Severity.LOW);
110+
PackageValidator validator = new PackageValidator(settings);
111+
MonitoredArtifact artifact = new MonitoredArtifact("",
112+
new TestResult(
113+
IssueSummary.from(Stream.of(Severity.LOW)),
114+
IssueSummary.from(Stream.empty()),
115+
URI.create("https://snyk.io/package/details")
116+
),
117+
new Ignores()
118+
);
119+
120+
assertThatThrownBy(() -> validator.validate(artifact))
121+
.isExactlyInstanceOf(CancelException.class)
122+
.hasMessageContaining("https://snyk.io/package/details");
104123
}
105124
}

0 commit comments

Comments
 (0)