Merge branch '2.7.x'

Closes gh-33753
This commit is contained in:
Moritz Halbritter 2023-01-11 11:30:37 +01:00
commit 46f09be1c0
2 changed files with 20 additions and 10 deletions

View File

@ -1127,17 +1127,20 @@ public class RabbitProperties {
} }
private String parseUsernameAndPassword(String input) { private String parseUsernameAndPassword(String input) {
if (input.contains("@")) { String[] splitInput = StringUtils.split(input, "@");
String[] split = StringUtils.split(input, "@"); if (splitInput == null) {
String creds = split[0]; return input;
input = split[1];
split = StringUtils.split(creds, ":");
this.username = split[0];
if (split.length > 0) {
this.password = split[1];
}
} }
return input; String credentials = splitInput[0];
String[] splitCredentials = StringUtils.split(credentials, ":");
if (splitCredentials == null) {
this.username = credentials;
}
else {
this.username = splitCredentials[0];
this.password = splitCredentials[1];
}
return splitInput[1];
} }
private String parseVirtualHost(String input) { private String parseVirtualHost(String input) {

View File

@ -331,4 +331,11 @@ class RabbitPropertiesTests {
assertThat(container).hasFieldOrPropertyWithValue("deBatchingEnabled", direct.isDeBatchingEnabled()); assertThat(container).hasFieldOrPropertyWithValue("deBatchingEnabled", direct.isDeBatchingEnabled());
} }
@Test
void determineUsernameWithoutPassword() {
this.properties.setAddresses("user@rabbit1.example.com:1234/alpha");
assertThat(this.properties.determineUsername()).isEqualTo("user");
assertThat(this.properties.determinePassword()).isEqualTo("guest");
}
} }