Use ssl.enabled flag when RabbitMQ address has no protocol
See gh-19109
This commit is contained in:
@@ -188,7 +188,7 @@ public class RabbitProperties {
|
||||
private List<Address> parseAddresses(String addresses) {
|
||||
List<Address> parsedAddresses = new ArrayList<>();
|
||||
for (String address : StringUtils.commaDelimitedListToStringArray(addresses)) {
|
||||
parsedAddresses.add(new Address(address));
|
||||
parsedAddresses.add(new Address(address, getSsl().isEnabled()));
|
||||
}
|
||||
return parsedAddresses;
|
||||
}
|
||||
@@ -968,21 +968,24 @@ public class RabbitProperties {
|
||||
|
||||
private boolean secureConnection;
|
||||
|
||||
private Address(String input) {
|
||||
private Address(String input, boolean sslEnabled) {
|
||||
input = input.trim();
|
||||
input = trimPrefix(input);
|
||||
input = trimPrefix(input, sslEnabled);
|
||||
input = parseUsernameAndPassword(input);
|
||||
input = parseVirtualHost(input);
|
||||
parseHostAndPort(input);
|
||||
}
|
||||
|
||||
private String trimPrefix(String input) {
|
||||
private String trimPrefix(String input, boolean sslEnabled) {
|
||||
if (input.startsWith(PREFIX_AMQP_SECURE)) {
|
||||
this.secureConnection = true;
|
||||
return input.substring(PREFIX_AMQP_SECURE.length());
|
||||
}
|
||||
if (input.startsWith(PREFIX_AMQP)) {
|
||||
input = input.substring(PREFIX_AMQP.length());
|
||||
return input.substring(PREFIX_AMQP.length());
|
||||
}
|
||||
if (sslEnabled) {
|
||||
this.secureConnection = true;
|
||||
}
|
||||
return input;
|
||||
}
|
||||
|
||||
@@ -101,6 +101,21 @@ public class RabbitPropertiesTests {
|
||||
assertThat(this.properties.determinePort()).isEqualTo(5671);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void determinePortReturnsDefaultAmqpsPortWhenFirstAddressHasNoExplicitPort() {
|
||||
this.properties.setPort(1234);
|
||||
this.properties.setAddresses("rabbit1.example.com,rabbit2.example.com:2345");
|
||||
assertThat(this.properties.determinePort()).isEqualTo(5672);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void determinePortReturnsDefaultAmqpsPortWhenFirstAddressHasNoExplicitPortButSslEnabled() {
|
||||
this.properties.getSsl().setEnabled(true);
|
||||
this.properties.setPort(1234);
|
||||
this.properties.setAddresses("rabbit1.example.com,rabbit2.example.com:2345");
|
||||
assertThat(this.properties.determinePort()).isEqualTo(5671);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void virtualHostDefaultsToNull() {
|
||||
assertThat(this.properties.getVirtualHost()).isNull();
|
||||
@@ -240,6 +255,20 @@ public class RabbitPropertiesTests {
|
||||
assertThat(this.properties.getSsl().determineEnabled()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void determineSslUsingAddressWithoutAmpqsDefersToSslFlagProperty() {
|
||||
this.properties.getSsl().setEnabled(true);
|
||||
this.properties.setAddresses("root:password@otherhost");
|
||||
assertThat(this.properties.getSsl().determineEnabled()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void determineSslUsingAddressWithoutAmpqDefersToSslFlagProperty() {
|
||||
this.properties.getSsl().setEnabled(false);
|
||||
this.properties.setAddresses("root:password@otherhost");
|
||||
assertThat(this.properties.getSsl().determineEnabled()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void determineSslUsingAmqpReturnsStateOfFirstAddress() {
|
||||
this.properties.setAddresses("amqp://root:password@otherhost,amqps://root:password2@otherhost2");
|
||||
|
||||
Reference in New Issue
Block a user