Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ public void setAddresses(String addresses) {
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()));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not super keen on passing this info down into Address#init but doing so make all downstream processing in Address hinge off of Address.secureConnection.

}
return parsedAddresses;
}
Expand Down Expand Up @@ -991,21 +991,24 @@ private static final class Address {

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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,22 @@ void determinePortUsingAmqpsReturnsPortOfFirstAddress() {
}

@Test
void virtualHostDefaultsToNull() {
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();
}

Expand Down Expand Up @@ -242,7 +257,21 @@ void determineSslUsingAmqpsReturnsStateOfFirstAddress() {
}

@Test
void determineSslUsingAmqpReturnsStateOfFirstAddress() {
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");
assertThat(this.properties.getSsl().determineEnabled()).isFalse();
}
Expand Down