Created
March 24, 2021 07:50
-
-
Save johanhammar/9d73a9db10784b704232b74ad2378dd2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
@Test | |
public void testSetSslEndpointIdentificationAlgorithm() throws Exception { | |
RestService restService = new RestService("https://localhost:8081"); | |
Map<String, Object> configs = new HashMap<>(); | |
configs.put(SslConfigs.SSL_ENDPOINT_IDENTIFICATION_ALGORITHM_CONFIG, ""); | |
restService.configure(configs); | |
HostnameVerifier hostnameVerifier = getHostnameVerifier(restService); | |
SSLSession sslSession = createMock(SSLSession.class); | |
assertNotNull(hostnameVerifier); | |
assertTrue(hostnameVerifier.verify("hostname", sslSession)); | |
} | |
@Test | |
public void testSetHttpsSslEndpointIdentificationAlgorithm() throws Exception { | |
RestService restService = new RestService("https://localhost:8081"); | |
Map<String, Object> configs = new HashMap<>(); | |
configs.put(SslConfigs.SSL_ENDPOINT_IDENTIFICATION_ALGORITHM_CONFIG, "https"); | |
restService.configure(configs); | |
HostnameVerifier hostnameVerifier = getHostnameVerifier(restService); | |
assertNull(hostnameVerifier); | |
} | |
@Test | |
public void testNoConfiguredSslEndpointIdentificationAlgorithm() throws Exception { | |
RestService restService = new RestService("https://localhost:8081"); | |
HostnameVerifier hostnameVerifier = getHostnameVerifier(restService); | |
assertNull(hostnameVerifier); | |
} | |
@Test(expected = ConfigException.class) | |
public void testSetInvalidSslEndpointIdentificationAlgorithm() throws Exception { | |
RestService restService = new RestService("https://localhost:8081"); | |
Map<String, Object> configs = new HashMap<>(); | |
configs.put(SslConfigs.SSL_ENDPOINT_IDENTIFICATION_ALGORITHM_CONFIG, "invalid"); | |
restService.configure(configs); | |
} | |
private HostnameVerifier getHostnameVerifier(RestService restService) throws Exception { | |
Field hostnameVerifierField = RestService.class.getDeclaredField("hostnameVerifier"); | |
boolean accessible = hostnameVerifierField.isAccessible(); | |
hostnameVerifierField.setAccessible(true); | |
try { | |
return (HostnameVerifier) hostnameVerifierField.get(restService); | |
} finally { | |
hostnameVerifierField.setAccessible(accessible); | |
} | |
} | |
... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment