[release-2.17] Respond 404 for non-exist theme resources instead of 500 (#6355)

This is an automated cherry-pick of #6340

/assign JohnNiang

```release-note
修复访问不存在的主题资源时出现服务器异常的问题
```
pull/6374/head
Halo Dev Bot 2024-07-22 13:49:32 +08:00 committed by GitHub
parent 6d4beddaa9
commit 19e45e0d3c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 13 additions and 0 deletions

View File

@ -80,6 +80,9 @@ public class ThemeWebFluxConfigurer implements WebFluxConfigurer {
var assetsPath = themeRoot.resolve(themeName + "/templates/assets/" + resourcePaths);
FileUtils.checkDirectoryTraversal(themeRoot, assetsPath);
var location = new FileSystemResource(assetsPath);
if (!location.isReadable()) {
return Mono.empty();
}
return Mono.just(location);
}

View File

@ -144,4 +144,14 @@ class WebFluxConfigTest {
}
}
@Nested
class StaticResourcesTest {
@Test
void shouldRespond404WhenThemeResourceNotFound() {
webClient.get().uri("/themes/fake-theme/assets/favicon.ico")
.exchange()
.expectStatus().isNotFound();
}
}
}