我在本地主机上使用ssl运行Springboot应用程序。我有一些集成测试来验证ssl是否有效:
application.properties
server.ssl.key-store-type=PKCS12
server.ssl.key-store=classpath:ssl/localhost.p12
server.ssl.key-store-password=localhost_ssl
server.ssl.key-alias=localhost_ssl
server.ssl.enabled=true集成试验
@ParameterizedTest
@MethodSource("getSslTestParameters")
void onlyAllowSecureCallsToEndpoint(boolean includesSecure, ResultMatcher expectedStatus) throws Exception {
MockHttpServletRequestBuilder postCall = post("/api/tutors/register")
.content(objectMapper.writeValueAsString(TutorRegistrationDTO.builder().build()))
.contentType(APPLICATION_JSON)
.with(csrf());
if (includesSecure) {
postCall.secure(true);
}
mvc.perform(postCall).andExpect(expectedStatus);
}
private static Stream<Arguments> getSslTestParameters() {
return Stream.of(
Arguments.of(true, status().isOk()),
Arguments.of(false, status().isFound()));
}当我使用IntelliJ和Maven运行它时,这个测试在Java8中运行得很好。现在,我对Java 17进行了升级,当我使用IntelliJ运行它时,它仍然工作,但是当我运行Maven构建时,它就停止工作了。我得到以下错误:
IOException: Failed to load keystore type [PKCS12] with path [jar:file:/C:/mypath/target/app-1.0.0-SNAPSHOT.jar!/ssl/localhost.p12] due to [Illegal char <:> at index 3: jar:file:\C:\mypath\target\app-1.0.0-SNAPSHOT.jar!\ssl\localhost.p12]我可以确认localhost.p12在jar中是可用的,但是它在解析.p12文件时似乎有问题。我假设文件本身并没有错,因为测试仍然适用于IntelliJ。
我已经通过设置IntelliJ验证了postCall.secure(false)并没有给出错误的阳性结果,并验证了测试是否如预期的那样失败。
ssl在Java 8和17之间的工作方式是否发生了变化?我在文件里找不到任何相关的东西。
编辑:我应该补充说,应用程序仍然没有问题地运行。问题完全在于考试。
发布于 2022-06-19 06:27:10
它不再正确地从Maven解释到jar的路径。它抱怨路径jar:...,分号。
我通过将/ssl/localhost.p12复制到集成测试Maven模块的测试资源来解决这个问题。
我无法解释为什么它可以在Java 8而不是Java 17中解释jar路径。
https://stackoverflow.com/questions/72674646
复制相似问题