From c1014f598916832a293ef40acc5a99765c242953 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Mon, 1 May 2023 00:01:49 +0200 Subject: [PATCH] Relax relative path existence assertion for parsed URIs See gh-29481 See gh-28522 --- .../web/reactive/resource/PathResourceResolverTests.java | 4 ---- .../web/reactive/resource/ResourceWebHandlerTests.java | 4 ---- .../web/servlet/resource/PathResourceResolverTests.java | 4 ---- .../web/servlet/resource/ResourceHttpRequestHandlerTests.java | 4 ---- 4 files changed, 16 deletions(-) diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/resource/PathResourceResolverTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/resource/PathResourceResolverTests.java index 9290981ce425..4b9ba4e800ee 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/resource/PathResourceResolverTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/resource/PathResourceResolverTests.java @@ -30,7 +30,6 @@ import org.springframework.core.io.UrlResource; import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.fail; /** * Unit tests for {@link PathResourceResolver}. @@ -101,9 +100,6 @@ public void checkResource() throws IOException { private void testCheckResource(Resource location, String requestPath) throws IOException { List locations = Collections.singletonList(location); Resource actual = this.resolver.resolveResource(null, requestPath, locations, null).block(TIMEOUT); - if (!location.createRelative(requestPath).exists() && !requestPath.contains(":")) { - fail(requestPath + " doesn't actually exist as a relative path"); - } assertThat(actual).isNull(); } diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/resource/ResourceWebHandlerTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/resource/ResourceWebHandlerTests.java index 15432ea1a666..5b4ec3cd3dec 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/resource/ResourceWebHandlerTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/resource/ResourceWebHandlerTests.java @@ -63,7 +63,6 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatExceptionOfType; import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; -import static org.assertj.core.api.Assertions.fail; import static org.mockito.ArgumentMatchers.any; import static org.mockito.BDDMockito.given; import static org.mockito.Mockito.mock; @@ -412,9 +411,6 @@ private void testResolvePathWithTraversal(HttpMethod httpMethod, String requestP assertThat(((ResponseStatusException) err).getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND); }) .verify(TIMEOUT); - if (!location.createRelative(requestPath).exists() && !requestPath.contains(":")) { - fail(requestPath + " doesn't actually exist as a relative path"); - } } @Test diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/resource/PathResourceResolverTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/resource/PathResourceResolverTests.java index 9ac37c3e9827..860a3e5c021f 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/resource/PathResourceResolverTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/resource/PathResourceResolverTests.java @@ -33,7 +33,6 @@ import org.springframework.web.util.UrlPathHelper; import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.fail; /** * Unit tests for {@link PathResourceResolver}. @@ -86,9 +85,6 @@ public void checkResource() throws IOException { private void testCheckResource(Resource location, String requestPath) throws IOException { List locations = Collections.singletonList(location); Resource actual = this.resolver.resolveResource(null, requestPath, locations, null); - if (!location.createRelative(requestPath).exists() && !requestPath.contains(":")) { - fail(requestPath + " doesn't actually exist as a relative path"); - } assertThat(actual).isNull(); } diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/resource/ResourceHttpRequestHandlerTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/resource/ResourceHttpRequestHandlerTests.java index 2fa3383bed50..a677cc685f38 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/resource/ResourceHttpRequestHandlerTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/resource/ResourceHttpRequestHandlerTests.java @@ -44,7 +44,6 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatExceptionOfType; import static org.assertj.core.api.Assertions.assertThatIllegalStateException; -import static org.assertj.core.api.Assertions.fail; import static org.mockito.ArgumentMatchers.any; import static org.mockito.BDDMockito.given; import static org.mockito.Mockito.mock; @@ -414,9 +413,6 @@ private void testResolvePathWithTraversal(Resource location, String requestPath) this.request.setAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE, requestPath); this.response = new MockHttpServletResponse(); this.handler.handleRequest(this.request, this.response); - if (!location.createRelative(requestPath).exists() && !requestPath.contains(":")) { - fail(requestPath + " doesn't actually exist as a relative path"); - } assertThat(this.response.getStatus()).isEqualTo(HttpStatus.NOT_FOUND.value()); }