Skip to content

Commit 65fcf34

Browse files
committed
Merge branch '3.3.x'
Closes gh-42840
2 parents 0a1c65f + dcbf009 commit 65fcf34

File tree

3 files changed

+25
-12
lines changed

3 files changed

+25
-12
lines changed

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/ssl/BundleContentProperty.java

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818

1919
import java.nio.file.Path;
2020

21-
import org.springframework.boot.io.ApplicationResourceLoader;
2221
import org.springframework.boot.ssl.pem.PemContent;
2322
import org.springframework.core.io.Resource;
23+
import org.springframework.core.io.ResourceLoader;
2424
import org.springframework.util.Assert;
2525
import org.springframework.util.StringUtils;
2626

@@ -51,9 +51,10 @@ boolean hasValue() {
5151
return StringUtils.hasText(this.value);
5252
}
5353

54-
Path toWatchPath() {
54+
Path toWatchPath(ResourceLoader resourceLoader) {
5555
try {
56-
Resource resource = getResource();
56+
Assert.state(!isPemContent(), "Value contains PEM content");
57+
Resource resource = resourceLoader.getResource(this.value);
5758
if (!resource.isFile()) {
5859
throw new BundleContentNotWatchableException(this);
5960
}
@@ -68,9 +69,4 @@ Path toWatchPath() {
6869
}
6970
}
7071

71-
private Resource getResource() {
72-
Assert.state(!isPemContent(), "Value contains PEM content");
73-
return new ApplicationResourceLoader().getResource(this.value);
74-
}
75-
7672
}

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/ssl/SslPropertiesBundleRegistrar.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ private Set<Path> watchedPaths(String bundleName, List<BundleContentProperty> pr
111111
try {
112112
return properties.stream()
113113
.filter(BundleContentProperty::hasValue)
114-
.map(BundleContentProperty::toWatchPath)
114+
.map((content) -> content.toWatchPath(this.resourceLoader))
115115
.collect(Collectors.toSet());
116116
}
117117
catch (BundleContentNotWatchableException ex) {

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/ssl/BundleContentPropertyTests.java

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,15 @@
2222

2323
import org.junit.jupiter.api.Test;
2424

25+
import org.springframework.boot.io.ApplicationResourceLoader;
26+
import org.springframework.core.io.ResourceLoader;
27+
2528
import static org.assertj.core.api.Assertions.assertThat;
2629
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
2730
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
31+
import static org.mockito.BDDMockito.then;
32+
import static org.mockito.Mockito.atLeastOnce;
33+
import static org.mockito.Mockito.spy;
2834

2935
/**
3036
* Tests for {@link BundleContentProperty}.
@@ -72,7 +78,7 @@ void hasValueWhenHasEmptyValueReturnsFalse() {
7278
@Test
7379
void toWatchPathWhenNotPathThrowsException() {
7480
BundleContentProperty property = new BundleContentProperty("name", PEM_TEXT);
75-
assertThatIllegalStateException().isThrownBy(property::toWatchPath)
81+
assertThatIllegalStateException().isThrownBy(() -> property.toWatchPath(new ApplicationResourceLoader()))
7682
.withMessage("Unable to convert value of property 'name' to a path");
7783
}
7884

@@ -81,13 +87,24 @@ void toWatchPathWhenPathReturnsPath() throws URISyntaxException {
8187
URL resource = getClass().getResource("keystore.jks");
8288
Path file = Path.of(resource.toURI()).toAbsolutePath();
8389
BundleContentProperty property = new BundleContentProperty("name", file.toString());
84-
assertThat(property.toWatchPath()).isEqualTo(file);
90+
assertThat(property.toWatchPath(new ApplicationResourceLoader())).isEqualTo(file);
91+
}
92+
93+
@Test
94+
void toWatchPathUsesResourceLoader() throws URISyntaxException {
95+
URL resource = getClass().getResource("keystore.jks");
96+
Path file = Path.of(resource.toURI()).toAbsolutePath();
97+
BundleContentProperty property = new BundleContentProperty("name", file.toString());
98+
ResourceLoader resourceLoader = spy(new ApplicationResourceLoader());
99+
assertThat(property.toWatchPath(resourceLoader)).isEqualTo(file);
100+
then(resourceLoader).should(atLeastOnce()).getResource(file.toString());
85101
}
86102

87103
@Test
88104
void shouldThrowBundleContentNotWatchableExceptionIfContentIsNotWatchable() {
89105
BundleContentProperty property = new BundleContentProperty("name", "https://example.com/");
90-
assertThatExceptionOfType(BundleContentNotWatchableException.class).isThrownBy(property::toWatchPath)
106+
assertThatExceptionOfType(BundleContentNotWatchableException.class)
107+
.isThrownBy(() -> property.toWatchPath(new ApplicationResourceLoader()))
91108
.withMessageContaining("Only 'file:' resources are watchable");
92109
}
93110

0 commit comments

Comments
 (0)