|
|
|
|
@ -1,5 +1,5 @@
@@ -1,5 +1,5 @@
|
|
|
|
|
/* |
|
|
|
|
* Copyright 2012-2017 the original author or authors. |
|
|
|
|
* Copyright 2012-2018 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. |
|
|
|
|
@ -17,6 +17,7 @@
@@ -17,6 +17,7 @@
|
|
|
|
|
package org.springframework.boot.web.embedded.undertow; |
|
|
|
|
|
|
|
|
|
import java.net.InetAddress; |
|
|
|
|
import java.security.NoSuchProviderException; |
|
|
|
|
|
|
|
|
|
import javax.net.ssl.KeyManager; |
|
|
|
|
|
|
|
|
|
@ -26,6 +27,7 @@ import org.springframework.boot.web.server.Ssl;
@@ -26,6 +27,7 @@ import org.springframework.boot.web.server.Ssl;
|
|
|
|
|
import org.springframework.test.util.ReflectionTestUtils; |
|
|
|
|
|
|
|
|
|
import static org.assertj.core.api.Assertions.assertThat; |
|
|
|
|
import static org.junit.Assert.fail; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Tests for {@link SslBuilderCustomizer} |
|
|
|
|
@ -48,4 +50,42 @@ public class SslBuilderCustomizerTests {
@@ -48,4 +50,42 @@ public class SslBuilderCustomizerTests {
|
|
|
|
|
assertThat(keyManagers[0]).isNotInstanceOf(name); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void keyStoreProviderIsUsedWhenCreatingKeyStore() throws Exception { |
|
|
|
|
Ssl ssl = new Ssl(); |
|
|
|
|
ssl.setKeyPassword("password"); |
|
|
|
|
ssl.setKeyStore("src/test/resources/test.jks"); |
|
|
|
|
ssl.setKeyStoreProvider("com.example.KeyStoreProvider"); |
|
|
|
|
SslBuilderCustomizer customizer = new SslBuilderCustomizer(8080, |
|
|
|
|
InetAddress.getLocalHost(), ssl, null); |
|
|
|
|
try { |
|
|
|
|
ReflectionTestUtils.invokeMethod(customizer, "getKeyManagers", ssl, null); |
|
|
|
|
fail(); |
|
|
|
|
} |
|
|
|
|
catch (IllegalStateException ex) { |
|
|
|
|
Throwable cause = ex.getCause(); |
|
|
|
|
assertThat(cause).isInstanceOf(NoSuchProviderException.class); |
|
|
|
|
assertThat(cause).hasMessageContaining("com.example.KeyStoreProvider"); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void trustStoreProviderIsUsedWhenCreatingTrustStore() throws Exception { |
|
|
|
|
Ssl ssl = new Ssl(); |
|
|
|
|
ssl.setTrustStorePassword("password"); |
|
|
|
|
ssl.setTrustStore("src/test/resources/test.jks"); |
|
|
|
|
ssl.setTrustStoreProvider("com.example.TrustStoreProvider"); |
|
|
|
|
SslBuilderCustomizer customizer = new SslBuilderCustomizer(8080, |
|
|
|
|
InetAddress.getLocalHost(), ssl, null); |
|
|
|
|
try { |
|
|
|
|
ReflectionTestUtils.invokeMethod(customizer, "getTrustManagers", ssl, null); |
|
|
|
|
fail(); |
|
|
|
|
} |
|
|
|
|
catch (IllegalStateException ex) { |
|
|
|
|
Throwable cause = ex.getCause(); |
|
|
|
|
assertThat(cause).isInstanceOf(NoSuchProviderException.class); |
|
|
|
|
assertThat(cause).hasMessageContaining("com.example.TrustStoreProvider"); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|