Polish SSL internals

This commit is contained in:
Scott Frederick
2023-11-02 13:53:08 -05:00
parent d3f177be71
commit 99986a2fdd
4 changed files with 26 additions and 34 deletions

View File

@@ -51,11 +51,6 @@ record BundleContentProperty(String name, String value) {
return StringUtils.hasText(this.value);
}
private URL toUrl() throws FileNotFoundException {
Assert.state(!isPemContent(), "Value contains PEM content");
return ResourceUtils.getURL(this.value);
}
Path toWatchPath() {
return toPath();
}
@@ -63,15 +58,22 @@ record BundleContentProperty(String name, String value) {
private Path toPath() {
try {
URL url = toUrl();
Assert.state(isFileUrl(url), () -> "Vaule '%s' is not a file URL".formatted(url));
Assert.state(isFileUrl(url), () -> "Value '%s' is not a file URL".formatted(url));
return Path.of(url.toURI()).toAbsolutePath();
}
catch (Exception ex) {
throw new IllegalStateException("Unable to convert '%s' property to a path".formatted(this.name), ex);
throw new IllegalStateException("Unable to convert value of property '%s' to a path".formatted(this.name),
ex);
}
}
private URL toUrl() throws FileNotFoundException {
Assert.state(!isPemContent(), "Value contains PEM content");
return ResourceUtils.getURL(this.value);
}
private boolean isFileUrl(URL url) {
return "file".equalsIgnoreCase(url.getProtocol());
}
}

View File

@@ -74,7 +74,7 @@ class BundleContentPropertyTests {
void toWatchPathWhenNotPathThrowsException() {
BundleContentProperty property = new BundleContentProperty("name", PEM_TEXT);
assertThatIllegalStateException().isThrownBy(property::toWatchPath)
.withMessage("Unable to convert 'name' property to a path");
.withMessage("Unable to convert value of property 'name' to a path");
}
@Test