|
| 1 | +/* |
| 2 | + * Copyright 2012-2025 the original author or authors. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * https://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package smoketest.tomcat.ssl; |
| 18 | + |
| 19 | +import org.junit.jupiter.api.Test; |
| 20 | + |
| 21 | +import org.springframework.beans.factory.annotation.Autowired; |
| 22 | +import org.springframework.boot.test.context.SpringBootTest; |
| 23 | +import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; |
| 24 | +import org.springframework.boot.test.web.client.TestRestTemplate; |
| 25 | +import org.springframework.boot.web.server.AbstractConfigurableWebServerFactory; |
| 26 | +import org.springframework.http.HttpStatus; |
| 27 | +import org.springframework.http.ResponseEntity; |
| 28 | +import org.springframework.test.json.JsonContent; |
| 29 | + |
| 30 | +import static org.assertj.core.api.Assertions.assertThat; |
| 31 | + |
| 32 | +@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) |
| 33 | +class SampleTomcat11SslApplicationTests { |
| 34 | + |
| 35 | + @Autowired |
| 36 | + private TestRestTemplate restTemplate; |
| 37 | + |
| 38 | + @Autowired |
| 39 | + private AbstractConfigurableWebServerFactory webServerFactory; |
| 40 | + |
| 41 | + @Test |
| 42 | + void testSsl() { |
| 43 | + assertThat(this.webServerFactory.getSsl().isEnabled()).isTrue(); |
| 44 | + } |
| 45 | + |
| 46 | + @Test |
| 47 | + void testHome() { |
| 48 | + ResponseEntity<String> entity = this.restTemplate.getForEntity("/", String.class); |
| 49 | + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); |
| 50 | + assertThat(entity.getBody()).isEqualTo("Hello, world"); |
| 51 | + } |
| 52 | + |
| 53 | + @Test |
| 54 | + void testSslInfo() { |
| 55 | + ResponseEntity<String> entity = this.restTemplate.getForEntity("/actuator/info", String.class); |
| 56 | + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); |
| 57 | + JsonContent body = new JsonContent(entity.getBody()); |
| 58 | + assertThat(body).extractingPath("ssl.bundles[0].name").isEqualTo("ssldemo"); |
| 59 | + assertThat(body).extractingPath("ssl.bundles[0].certificateChains[0].alias") |
| 60 | + .isEqualTo("spring-boot-ssl-sample"); |
| 61 | + assertThat(body).extractingPath("ssl.bundles[0].certificateChains[0].certificates[0].issuer") |
| 62 | + .isEqualTo("CN=localhost,OU=Unknown,O=Unknown,L=Unknown,ST=Unknown,C=Unknown"); |
| 63 | + assertThat(body).extractingPath("ssl.bundles[0].certificateChains[0].certificates[0].subject") |
| 64 | + .isEqualTo("CN=localhost,OU=Unknown,O=Unknown,L=Unknown,ST=Unknown,C=Unknown"); |
| 65 | + assertThat(body).extractingPath("ssl.bundles[0].certificateChains[0].certificates[0].validity.status") |
| 66 | + .isEqualTo("EXPIRED"); |
| 67 | + assertThat(body).extractingPath("ssl.bundles[0].certificateChains[0].certificates[0].validity.message") |
| 68 | + .asString() |
| 69 | + .startsWith("Not valid after "); |
| 70 | + } |
| 71 | + |
| 72 | + @Test |
| 73 | + void testSslHealth() { |
| 74 | + ResponseEntity<String> entity = this.restTemplate.getForEntity("/actuator/health", String.class); |
| 75 | + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.SERVICE_UNAVAILABLE); |
| 76 | + JsonContent body = new JsonContent(entity.getBody()); |
| 77 | + assertThat(body).extractingPath("status").isEqualTo("OUT_OF_SERVICE"); |
| 78 | + assertThat(body).extractingPath("components.ssl.status").isEqualTo("OUT_OF_SERVICE"); |
| 79 | + assertThat(body).extractingPath("components.ssl.details.invalidChains[0].alias") |
| 80 | + .isEqualTo("spring-boot-ssl-sample"); |
| 81 | + assertThat(body).extractingPath("components.ssl.details.invalidChains[0].certificates[0].issuer") |
| 82 | + .isEqualTo("CN=localhost,OU=Unknown,O=Unknown,L=Unknown,ST=Unknown,C=Unknown"); |
| 83 | + assertThat(body).extractingPath("components.ssl.details.invalidChains[0].certificates[0].subject") |
| 84 | + .isEqualTo("CN=localhost,OU=Unknown,O=Unknown,L=Unknown,ST=Unknown,C=Unknown"); |
| 85 | + assertThat(body).extractingPath("components.ssl.details.invalidChains[0].certificates[0].validity.status") |
| 86 | + .isEqualTo("EXPIRED"); |
| 87 | + assertThat(body).extractingPath("components.ssl.details.invalidChains[0].certificates[0].validity.message") |
| 88 | + .asString() |
| 89 | + .startsWith("Not valid after "); |
| 90 | + } |
| 91 | + |
| 92 | +} |
0 commit comments