|
16 | 16 |
|
17 | 17 | package org.springframework.boot.autoconfigure.amqp;
|
18 | 18 |
|
| 19 | +import java.security.NoSuchAlgorithmException; |
| 20 | + |
19 | 21 | import javax.net.SocketFactory;
|
20 | 22 | import javax.net.ssl.SSLSocketFactory;
|
21 | 23 |
|
@@ -540,21 +542,80 @@ public void enableSsl() {
|
540 | 542 |
|
541 | 543 | @Test
|
542 | 544 | // Make sure that we at least attempt to load the store
|
543 |
| - public void enableSslWithExtraConfig() { |
544 |
| - this.contextRunner.withUserConfiguration(TestConfiguration.class) |
| 545 | + public void enableSslWithNonExistingKeystoreShouldFail() { |
| 546 | + this.contextRunner |
| 547 | + .withUserConfiguration(TestConfiguration.class) |
545 | 548 | .withPropertyValues("spring.rabbitmq.ssl.enabled:true",
|
546 | 549 | "spring.rabbitmq.ssl.keyStore=foo",
|
547 |
| - "spring.rabbitmq.ssl.keyStorePassword=secret", |
| 550 | + "spring.rabbitmq.ssl.keyStorePassword=secret") |
| 551 | + .run(context -> { |
| 552 | + assertThat(context).hasFailed(); |
| 553 | + assertThat(context).getFailure().hasMessageContaining("foo"); |
| 554 | + assertThat(context).getFailure().hasMessageContaining("does not exist"); |
| 555 | + }); |
| 556 | + } |
| 557 | + |
| 558 | + @Test |
| 559 | + // Make sure that we at least attempt to load the store |
| 560 | + public void enableSslWithNonExistingTrustStoreShouldFail() { |
| 561 | + this.contextRunner |
| 562 | + .withUserConfiguration(TestConfiguration.class) |
| 563 | + .withPropertyValues( |
| 564 | + "spring.rabbitmq.ssl.enabled:true", |
548 | 565 | "spring.rabbitmq.ssl.trustStore=bar",
|
549 | 566 | "spring.rabbitmq.ssl.trustStorePassword=secret")
|
550 | 567 | .run((context) -> {
|
551 | 568 | assertThat(context).hasFailed();
|
552 |
| - assertThat(context).getFailure().hasMessageContaining("foo"); |
553 |
| - assertThat(context).getFailure() |
554 |
| - .hasMessageContaining("does not exist"); |
| 569 | + assertThat(context).getFailure().hasMessageContaining("bar"); |
| 570 | + assertThat(context).getFailure().hasMessageContaining("does not exist"); |
555 | 571 | });
|
556 | 572 | }
|
557 | 573 |
|
| 574 | + @Test |
| 575 | + public void enableSslWithInvalidKeystoreTypeShouldFail() throws Exception { |
| 576 | + this.contextRunner |
| 577 | + .withUserConfiguration(TestConfiguration.class) |
| 578 | + .withPropertyValues( |
| 579 | + "spring.rabbitmq.ssl.enabled:true", |
| 580 | + "spring.rabbitmq.ssl.keyStore=foo", |
| 581 | + "spring.rabbitmq.ssl.keyStoreType=fooType") |
| 582 | + .run(context -> { |
| 583 | + assertThat(context).hasFailed(); |
| 584 | + assertThat(context).getFailure().hasMessageContaining("fooType"); |
| 585 | + assertThat(context).getFailure().hasRootCauseInstanceOf(NoSuchAlgorithmException.class); |
| 586 | + }); |
| 587 | + } |
| 588 | + |
| 589 | + @Test |
| 590 | + public void enableSslWithInvalidTrustStoreTypeShouldFail() throws Exception { |
| 591 | + this.contextRunner |
| 592 | + .withUserConfiguration(TestConfiguration.class) |
| 593 | + .withPropertyValues( |
| 594 | + "spring.rabbitmq.ssl.enabled:true", |
| 595 | + "spring.rabbitmq.ssl.trustStore=bar", |
| 596 | + "spring.rabbitmq.ssl.trustStoreType=barType") |
| 597 | + .run(context -> { |
| 598 | + assertThat(context).hasFailed(); |
| 599 | + assertThat(context).getFailure().hasMessageContaining("barType"); |
| 600 | + assertThat(context).getFailure().hasRootCauseInstanceOf(NoSuchAlgorithmException.class); |
| 601 | + }); |
| 602 | + } |
| 603 | + |
| 604 | + @Test |
| 605 | + public void enableSslWithKeystoreTypeAndTrustStoreTypeShouldWork() throws Exception { |
| 606 | + this.contextRunner |
| 607 | + .withUserConfiguration(TestConfiguration.class) |
| 608 | + .withPropertyValues( |
| 609 | + "spring.rabbitmq.ssl.enabled:true", |
| 610 | + "spring.rabbitmq.ssl.keyStore=/org/springframework/boot/autoconfigure/amqp/test.jks", |
| 611 | + "spring.rabbitmq.ssl.keyStoreType=jks", |
| 612 | + "spring.rabbitmq.ssl.keyStorePassword=secret", |
| 613 | + "spring.rabbitmq.ssl.trustStore=/org/springframework/boot/autoconfigure/amqp/test.jks", |
| 614 | + "spring.rabbitmq.ssl.trustStoreType=jks", |
| 615 | + "spring.rabbitmq.ssl.trustStorePassword=secret") |
| 616 | + .run(context -> assertThat(context).hasNotFailed()); |
| 617 | + } |
| 618 | + |
558 | 619 | private com.rabbitmq.client.ConnectionFactory getTargetConnectionFactory(
|
559 | 620 | AssertableApplicationContext context) {
|
560 | 621 | CachingConnectionFactory connectionFactory = context
|
|
0 commit comments