Spring引导-使用HTTPS进行集成测试
我有一个通常在tomcat上运行的Spring启动应用程序(作为一个普通的WAR),对于一些URL模式,我有Spring安全设置,强制它使用HTTPS。所有HTTPS/证书的工作都是在我的应用程序之外完成的,所以这一步(至少看起来)要做的就是重定向到HTTPS地址(和端口) 我的安全配置:Spring引导-使用HTTPS进行集成测试,spring,groovy,spring-boot,integration-testing,Spring,Groovy,Spring Boot,Integration Testing,我有一个通常在tomcat上运行的Spring启动应用程序(作为一个普通的WAR),对于一些URL模式,我有Spring安全设置,强制它使用HTTPS。所有HTTPS/证书的工作都是在我的应用程序之外完成的,所以这一步(至少看起来)要做的就是重定向到HTTPS地址(和端口) 我的安全配置: http.requiresChannel().requestMatchers( "/**" ) .requiresSecure() 这一切在tomcat上都像预期的那样工作,我得到了正确的重定向 现在我想写
http.requiresChannel().requestMatchers( "/**" ) .requiresSecure()
这一切在tomcat上都像预期的那样工作,我得到了正确的重定向
现在我想写一些Spring@IntegrationTest
s,但无法让它向HTTPS URL发出请求-我怀疑我错过了一些相当明显的东西,但我的尝试没有带来任何乐趣
我的基本测试用例:
@RunWith( SpringJUnit4ClassRunner )
@SpringApplicationConfiguration( classes = Application )
@WebAppConfiguration
@IntegrationTest( [ "server.port:0" ] )
class MultipleUserAuthenticationTest {
@Value('${local.server.port}') private int port
private URL base
private RestTemplate template
@Before public void setUp() throws Exception {
this.base = new URL("https://localhost:" + port + "/api")
template = new RestTemplate()
}
@Test public void apiRequest() throws Exception {
HttpHeaders headers = //set custom headers
HttpEntity<String> entity = new HttpEntity<String>( headers )
ResponseEntity<String> exchange = template.exchange( base.toString(), HttpMethod.GET, entity, String )
}
我错过了什么明显的东西吗?有没有其他方法获取HTTPS端口(或者告诉spring使用一个)?我读到的错误消息是“你告诉我使用HTTPS,但你的启动应用程序只使用普通HTTP”。你能使用普通HTTP URL,
新URL(“http://localhost:“+端口+”/api“
?如果没有,你能在一个不启用RequireseCure策略的Spring配置文件中运行集成测试吗?@bdkosher好的,我可以尝试不同的配置文件,我希望不要用测试内容太多地污染我的配置文件,你知道测试配置是否可以在主源集之外运行吗?我读到了这个错误消息“您告诉我使用HTTPS,但您的启动应用程序只讲普通HTTP。”您能使用普通HTTP URL,新URL(”http://localhost:“+端口+”/api”)
?如果没有,您能在不启用RequireseCure策略的Spring配置文件中运行集成测试吗?@bdkosher好的,我可以尝试不同的配置文件,我希望不必用测试内容太多地污染我的配置文件,您知道是否有可能将测试配置文件放在主源代码集之外吗?
org.springframework.web.client.ResourceAccessException: I/O error on GET request for "https://localhost:52002/api":Unrecognized SSL message, plaintext connection?; nested exception is javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection?