7 changed files with 267 additions and 6 deletions
@ -0,0 +1,93 @@
@@ -0,0 +1,93 @@
|
||||
/* |
||||
* Copyright 2013-2017 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 |
||||
* |
||||
* http://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 org.springframework.cloud.gateway.test.ssl; |
||||
|
||||
import static org.junit.Assert.assertTrue; |
||||
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; |
||||
|
||||
import javax.net.ssl.SSLException; |
||||
|
||||
import org.junit.Before; |
||||
import org.junit.Test; |
||||
import org.junit.runner.RunWith; |
||||
import org.springframework.boot.SpringBootConfiguration; |
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration; |
||||
import org.springframework.boot.test.context.SpringBootTest; |
||||
import org.springframework.cloud.gateway.test.BaseWebClientTests; |
||||
import org.springframework.context.annotation.Import; |
||||
import org.springframework.http.HttpStatus; |
||||
import org.springframework.http.ResponseEntity; |
||||
import org.springframework.http.client.reactive.ClientHttpConnector; |
||||
import org.springframework.http.client.reactive.ReactorClientHttpConnector; |
||||
import org.springframework.test.annotation.DirtiesContext; |
||||
import org.springframework.test.context.ActiveProfiles; |
||||
import org.springframework.test.context.junit4.SpringRunner; |
||||
import org.springframework.web.bind.annotation.RequestMapping; |
||||
import org.springframework.web.bind.annotation.RestController; |
||||
import org.springframework.web.reactive.function.client.ClientResponse; |
||||
import org.springframework.web.reactive.function.client.WebClient; |
||||
|
||||
import io.netty.handler.ssl.SslContext; |
||||
import io.netty.handler.ssl.SslContextBuilder; |
||||
import io.netty.handler.ssl.util.InsecureTrustManagerFactory; |
||||
|
||||
@RunWith(SpringRunner.class) |
||||
@SpringBootTest(webEnvironment = RANDOM_PORT) |
||||
@DirtiesContext |
||||
@ActiveProfiles("ssl") |
||||
public class SSLTests extends BaseWebClientTests { |
||||
|
||||
@Before |
||||
public void setup() { |
||||
try { |
||||
SslContext sslContext = SslContextBuilder.forClient() |
||||
.trustManager(InsecureTrustManagerFactory.INSTANCE).build(); |
||||
ClientHttpConnector httpConnector = new ReactorClientHttpConnector( |
||||
opt -> opt.sslContext(sslContext)); |
||||
baseUri = "https://localhost:" + port; |
||||
this.webClient = WebClient.builder().clientConnector(httpConnector) |
||||
.baseUrl(baseUri).build(); |
||||
} |
||||
catch (SSLException e) { |
||||
throw new RuntimeException(e); |
||||
} |
||||
} |
||||
|
||||
@Test |
||||
public void testSslTrust() { |
||||
ClientResponse clientResponse = webClient.get().uri("/ssltrust") |
||||
.exchange().block(); |
||||
HttpStatus statusCode = clientResponse.statusCode(); |
||||
assertTrue(statusCode.is2xxSuccessful()); |
||||
|
||||
} |
||||
|
||||
@EnableAutoConfiguration |
||||
@SpringBootConfiguration |
||||
@Import(DefaultTestConfig.class) |
||||
@RestController |
||||
public static class TestConfig { |
||||
|
||||
@RequestMapping("/httpbin/ssltrust") |
||||
public ResponseEntity<Void> nocontenttype() { |
||||
return ResponseEntity.status(204).build(); |
||||
} |
||||
|
||||
} |
||||
|
||||
} |
@ -0,0 +1,38 @@
@@ -0,0 +1,38 @@
|
||||
test: |
||||
hostport: httpbin.org:80 |
||||
uri: lb://testservice |
||||
|
||||
server: |
||||
ssl: |
||||
enabled: true |
||||
key-alias: scg |
||||
key-store-password: scg1234 |
||||
key-store: classpath:scg-keystore.p12 |
||||
key-store-type: PKCS12 |
||||
|
||||
spring: |
||||
cloud: |
||||
gateway: |
||||
httpclient: |
||||
ssl: |
||||
trustedX509Certificates: |
||||
- src/test/resources/scg-cert.pem |
||||
default-filters: |
||||
- PrefixPath=/httpbin |
||||
routes: |
||||
- id: default_path_to_httpbin |
||||
uri: ${test.uri} |
||||
order: 10000 |
||||
predicates: |
||||
- name: Path |
||||
args: |
||||
pattern: /** |
||||
|
||||
logging: |
||||
level: |
||||
org.springframework.cloud.gateway: TRACE |
||||
org.springframework.http.server.reactive: DEBUG |
||||
org.springframework.web.reactive: DEBUG |
||||
reactor.ipc.netty: DEBUG |
||||
redisratelimiter: DEBUG |
||||
|
@ -0,0 +1,27 @@
@@ -0,0 +1,27 @@
|
||||
-----BEGIN CERTIFICATE----- |
||||
MIIEjTCCAvWgAwIBAgIEIZEBKTANBgkqhkiG9w0BAQwFADBsMRAwDgYDVQQGEwdV |
||||
bmtub3duMRAwDgYDVQQIEwdVbmtub3duMRAwDgYDVQQHEwdVbmtub3duMRAwDgYD |
||||
VQQKEwdVbmtub3duMRAwDgYDVQQLEwdVbmtub3duMRAwDgYDVQQDEwdVbmtub3du |
||||
MB4XDTE4MDcxODEyNTY0OFoXDTQ1MTIwMzEyNTY0OFowbDEQMA4GA1UEBhMHVW5r |
||||
bm93bjEQMA4GA1UECBMHVW5rbm93bjEQMA4GA1UEBxMHVW5rbm93bjEQMA4GA1UE |
||||
ChMHVW5rbm93bjEQMA4GA1UECxMHVW5rbm93bjEQMA4GA1UEAxMHVW5rbm93bjCC |
||||
AaIwDQYJKoZIhvcNAQEBBQADggGPADCCAYoCggGBAJhdOwHjozNaUdocb+p/Dn6E |
||||
UUXzkNGwmUZwRSQKnEK9IV/PTwrzK+fPJS8vpUzEpj37QIGBTSNuebQ3w5G4cAu6 |
||||
xFEk4e56C823Vio5Hae/+fos7goaR+ihKMy2lGPwFGNECqGmUZItE1+4pdjYyia7 |
||||
FTWluAVuTgue3VODl9ziDw+2Zrt6Axtnb5heQXP8ElEZldoePpUmbLWa03Xvfatb |
||||
4ZKkoCLOKhcgM5F2tyR+VlZnqm2dhvO+J778MsU4ToVAUGrVIkeQi0BHTi5Rzy2c |
||||
2kDLHHuJTYqN65sl5LyKDu003KXioelZVUeH3Hgtrj0Tt96oYSixvHSGwDmcXpux |
||||
4sbzTS7x/KeQAjLIFj/3rxQP0TSuTCe/XrqiCpFflLntTI9En9CWto6SXFRigval |
||||
zCITgImQthSfFMxFDqNtNQo5hTAu8VY2/FurMbkukQ5l2+vU4dKBccNxChj5m7p3 |
||||
8C4G7Rh08AEYaNYcNZlaz++c37rW7P6vWX8m6C21CQIDAQABozcwNTAUBgNVHREE |
||||
DTALgglsb2NhbGhvc3QwHQYDVR0OBBYEFDOSE31Vw2QdyVviz+H5+tY5HRR4MA0G |
||||
CSqGSIb3DQEBDAUAA4IBgQAJljlIubbQvw/2UVymsyF939XKus/7muiJLtQt0J4J |
||||
sSuGiSQmkyJajBRj9+qsLLTtdL6F2+BFJtP8S/zZixrEzktuRZ3b40MLtyI4hVDt |
||||
fmgj3UMmphVgbmDv71WvRmUXFfBX5Zka7zRW+lFvO5dLytegKi3Vc8zOFRUcvY9w |
||||
uBEOipAkUqH6y+lI/lJ72MrXpkxbkAq2fYffZK4e6KNpKG7pP0txEkwNvosKSAjA |
||||
yL+Ye5bK6sYbscwsqvXw9nWwjuFpj/0zvD/tM1jMtUtV1+9HKC3vsfAaL9QnwnS6 |
||||
qhSaos8j7fw9SYdAoO+yth2w1ETxKXrzcF+LEkhzj2R0zygycLZvWj51lIWDDOvy |
||||
m3IUFTY8fX7CBgLIGnHAcdWK6a+FkWIb8WybWkv2n2SxM4AnzXb5epk/K2Uo30hY |
||||
mr9wrywvo92xUjXEOmQpAbFx0hcVjYOtvpHdUeZTGLLQ7sWJGQFalRT+GsTy+Lph |
||||
10719GizKXQW2Mx/8XOr1Ow= |
||||
-----END CERTIFICATE----- |
Binary file not shown.
Loading…
Reference in new issue