Add webmvc-undertow-tls smoke test
Closes gh-68
This commit is contained in:
@@ -549,6 +549,12 @@ h|nativeTest
|
||||
|image:https://ci.spring.io/api/v1/teams/spring-aot-smoke-tests/pipelines/spring-aot-smoke-tests-1.0.x/jobs/webmvc-undertow-test/badge[link=https://ci.spring.io/teams/spring-aot-smoke-tests/pipelines/spring-aot-smoke-tests-1.0.x/jobs/webmvc-undertow-test]
|
||||
|image:https://ci.spring.io/api/v1/teams/spring-aot-smoke-tests/pipelines/spring-aot-smoke-tests-1.0.x/jobs/webmvc-undertow-native-test/badge[link=https://ci.spring.io/teams/spring-aot-smoke-tests/pipelines/spring-aot-smoke-tests-1.0.x/jobs/webmvc-undertow-native-test]
|
||||
|
||||
|webmvc-undertow-tls
|
||||
|image:https://ci.spring.io/api/v1/teams/spring-aot-smoke-tests/pipelines/spring-aot-smoke-tests-1.0.x/jobs/webmvc-undertow-tls-app-test/badge[link=https://ci.spring.io/teams/spring-aot-smoke-tests/pipelines/spring-aot-smoke-tests-1.0.x/jobs/webmvc-undertow-tls-app-test]
|
||||
|image:https://ci.spring.io/api/v1/teams/spring-aot-smoke-tests/pipelines/spring-aot-smoke-tests-1.0.x/jobs/webmvc-undertow-tls-native-app-test/badge[link=https://ci.spring.io/teams/spring-aot-smoke-tests/pipelines/spring-aot-smoke-tests-1.0.x/jobs/webmvc-undertow-tls-native-app-test]
|
||||
|
|
||||
|
|
||||
|
||||
|websocket-jetty
|
||||
|image:https://ci.spring.io/api/v1/teams/spring-aot-smoke-tests/pipelines/spring-aot-smoke-tests-1.0.x/jobs/websocket-jetty-app-test/badge[link=https://ci.spring.io/teams/spring-aot-smoke-tests/pipelines/spring-aot-smoke-tests-1.0.x/jobs/websocket-jetty-app-test]
|
||||
|image:https://ci.spring.io/api/v1/teams/spring-aot-smoke-tests/pipelines/spring-aot-smoke-tests-1.0.x/jobs/websocket-jetty-native-app-test/badge[link=https://ci.spring.io/teams/spring-aot-smoke-tests/pipelines/spring-aot-smoke-tests-1.0.x/jobs/websocket-jetty-native-app-test]
|
||||
|
||||
@@ -267,6 +267,9 @@ groups:
|
||||
- name: webmvc-undertow
|
||||
app_test: true
|
||||
test: true
|
||||
- name: webmvc-undertow-tls
|
||||
app_test: true
|
||||
test: false
|
||||
- name: websocket-jetty
|
||||
app_test: true
|
||||
test: false
|
||||
|
||||
1
framework/webmvc-undertow-tls/README.adoc
Normal file
1
framework/webmvc-undertow-tls/README.adoc
Normal file
@@ -0,0 +1 @@
|
||||
Tests if WebMVC with Undertow with TLS is working
|
||||
25
framework/webmvc-undertow-tls/build.gradle
Normal file
25
framework/webmvc-undertow-tls/build.gradle
Normal file
@@ -0,0 +1,25 @@
|
||||
plugins {
|
||||
id 'java'
|
||||
id 'org.springframework.boot'
|
||||
id 'org.springframework.aot.smoke-test'
|
||||
id 'org.graalvm.buildtools.native'
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation(platform(org.springframework.boot.gradle.plugin.SpringBootPlugin.BOM_COORDINATES))
|
||||
implementation("org.springframework.boot:spring-boot-starter-web")
|
||||
implementation("org.springframework.boot:spring-boot-starter-undertow")
|
||||
modules {
|
||||
module("org.springframework.boot:spring-boot-starter-tomcat") {
|
||||
replacedBy("org.springframework.boot:spring-boot-starter-undertow", "Use Undertow instead of Tomcat")
|
||||
}
|
||||
}
|
||||
|
||||
testImplementation("org.springframework.boot:spring-boot-starter-test")
|
||||
|
||||
appTestImplementation(project(":aot-smoke-test-support"))
|
||||
}
|
||||
|
||||
aotSmokeTest {
|
||||
webApplication = true
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
* Copyright 2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.example.webmvc.undertow.tls;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.net.URI;
|
||||
import java.net.http.HttpClient;
|
||||
import java.security.KeyStore;
|
||||
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.TrustManagerFactory;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.aot.smoketest.support.junit.ApplicationTest;
|
||||
import org.springframework.aot.smoketest.support.junit.ApplicationUrl;
|
||||
import org.springframework.aot.smoketest.support.junit.ApplicationUrl.Scheme;
|
||||
import org.springframework.http.client.reactive.ClientHttpConnector;
|
||||
import org.springframework.http.client.reactive.JdkClientHttpConnector;
|
||||
import org.springframework.test.web.reactive.server.WebTestClient;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@ApplicationTest
|
||||
class WebMvcUndertowTlsApplicationAotTests {
|
||||
|
||||
@Test
|
||||
void stringResponseBody(@ApplicationUrl(scheme = Scheme.HTTPS) URI applicationUrl) throws Exception {
|
||||
WebTestClient client = buildWebClient(applicationUrl);
|
||||
|
||||
client.get().exchange().expectStatus().isOk().expectBody().consumeWith(
|
||||
(result) -> assertThat(new String(result.getResponseBodyContent())).isEqualTo("Hello World TLS"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds a web client for the running application. This web client is configured to
|
||||
* trust the TLS certificate of the server.
|
||||
* @param applicationUrl the URL to the application
|
||||
* @return web client
|
||||
* @throws Exception if something went wrong
|
||||
*/
|
||||
private static WebTestClient buildWebClient(URI applicationUrl) throws Exception {
|
||||
KeyStore trustStore = KeyStore.getInstance("jks");
|
||||
try (InputStream stream = WebMvcUndertowTlsApplicationAotTests.class.getResourceAsStream("/truststore.jks")) {
|
||||
assertThat(stream).as("Trust store on test classpath").isNotNull();
|
||||
trustStore.load(stream, null);
|
||||
}
|
||||
|
||||
TrustManagerFactory trustManagerFactory = TrustManagerFactory
|
||||
.getInstance(TrustManagerFactory.getDefaultAlgorithm());
|
||||
trustManagerFactory.init(trustStore);
|
||||
|
||||
SSLContext sslContext = SSLContext.getInstance("TLS");
|
||||
sslContext.init(null, trustManagerFactory.getTrustManagers(), null);
|
||||
|
||||
HttpClient httpClient = HttpClient.newBuilder().sslContext(sslContext).build();
|
||||
ClientHttpConnector connector = new JdkClientHttpConnector(httpClient);
|
||||
return WebTestClient.bindToServer(connector).baseUrl(applicationUrl.toString()).build();
|
||||
}
|
||||
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,15 @@
|
||||
package com.example.webmvc.undertow.tls;
|
||||
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
public class TestController {
|
||||
|
||||
@GetMapping(value = "/", produces = MediaType.TEXT_PLAIN_VALUE)
|
||||
public String index() {
|
||||
return "Hello World TLS";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.example.webmvc.undertow.tls;
|
||||
|
||||
import com.example.webmvc.undertow.tls.WebMvcUndertowTlsApplication.KeyStoreRuntimeHints;
|
||||
|
||||
import org.springframework.aot.hint.RuntimeHints;
|
||||
import org.springframework.aot.hint.RuntimeHintsRegistrar;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.context.annotation.ImportRuntimeHints;
|
||||
|
||||
@SpringBootApplication
|
||||
@ImportRuntimeHints(KeyStoreRuntimeHints.class)
|
||||
public class WebMvcUndertowTlsApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(WebMvcUndertowTlsApplication.class, args);
|
||||
}
|
||||
|
||||
static class KeyStoreRuntimeHints implements RuntimeHintsRegistrar {
|
||||
|
||||
@Override
|
||||
public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
|
||||
hints.resources().registerPattern("keystore.jks");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
server.ssl.key-store=classpath:keystore.jks
|
||||
server.ssl.key-store-password=secret
|
||||
server.ssl.key-alias=localhost
|
||||
server.ssl.key-password=secret
|
||||
BIN
framework/webmvc-undertow-tls/src/main/resources/keystore.jks
Normal file
BIN
framework/webmvc-undertow-tls/src/main/resources/keystore.jks
Normal file
Binary file not shown.
Reference in New Issue
Block a user