Add test for ssl scheme
Closes gh-2232
This commit is contained in:
@@ -57,6 +57,7 @@ import org.springframework.util.SocketUtils;
|
||||
import org.springframework.util.StreamUtils;
|
||||
import org.springframework.util.concurrent.ListenableFuture;
|
||||
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.lessThan;
|
||||
import static org.hamcrest.Matchers.notNullValue;
|
||||
@@ -313,6 +314,24 @@ public abstract class AbstractEmbeddedServletContainerFactoryTests {
|
||||
testBasicSslWithKeyStore("src/test/resources/test.jks");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sslGetScheme() throws Exception { // gh-2232
|
||||
AbstractEmbeddedServletContainerFactory factory = getFactory();
|
||||
factory.setSsl(getSsl(null, "password", "src/test/resources/test.jks"));
|
||||
this.container = factory.getEmbeddedServletContainer(new ServletRegistrationBean(
|
||||
new ExampleServlet(true), "/hello"));
|
||||
this.container.start();
|
||||
SSLConnectionSocketFactory socketFactory = new SSLConnectionSocketFactory(
|
||||
new SSLContextBuilder().loadTrustMaterial(null,
|
||||
new TrustSelfSignedStrategy()).build());
|
||||
HttpClient httpClient = HttpClients.custom().setSSLSocketFactory(socketFactory)
|
||||
.build();
|
||||
HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory(
|
||||
httpClient);
|
||||
assertThat(getResponse(getLocalUrl("https", "/hello"), requestFactory),
|
||||
containsString("scheme=https"));
|
||||
}
|
||||
|
||||
protected final void testBasicSslWithKeyStore(String keyStore) throws Exception {
|
||||
AbstractEmbeddedServletContainerFactory factory = getFactory();
|
||||
addTestTxtFile(factory);
|
||||
|
||||
@@ -31,10 +31,24 @@ import javax.servlet.ServletResponse;
|
||||
@SuppressWarnings("serial")
|
||||
public class ExampleServlet extends GenericServlet {
|
||||
|
||||
private final boolean echoRequestInfo;
|
||||
|
||||
public ExampleServlet() {
|
||||
this(false);
|
||||
}
|
||||
|
||||
public ExampleServlet(boolean echoRequestInfo) {
|
||||
this.echoRequestInfo = echoRequestInfo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void service(ServletRequest request, ServletResponse response)
|
||||
throws ServletException, IOException {
|
||||
response.getWriter().write("Hello World");
|
||||
String content = "Hello World";
|
||||
if (this.echoRequestInfo) {
|
||||
content += " scheme=" + request.getScheme();
|
||||
}
|
||||
response.getWriter().write(content);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user