Adds support for uri encoded username/password

Fixes gh-1621
This commit is contained in:
spencergibb
2021-03-29 18:05:06 -04:00
parent 962abe7462
commit f4aab7f15d
2 changed files with 18 additions and 1 deletions

View File

@@ -16,8 +16,11 @@
package org.springframework.cloud.config.client;
import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
@@ -333,9 +336,14 @@ public class ConfigClientProperties {
// But the username can be overridden
result.username = explicitCredentials.username;
}
result.password = URLDecoder.decode(result.password,
StandardCharsets.UTF_8.toString());
result.username = URLDecoder.decode(result.username,
StandardCharsets.UTF_8.toString());
return result;
}
catch (MalformedURLException e) {
catch (MalformedURLException | UnsupportedEncodingException e) {
throw new IllegalStateException("Invalid URL: " + uri, e);
}
}

View File

@@ -59,6 +59,15 @@ public class ConfigClientPropertiesTests {
assertThat(credentials.getPassword()).isEqualTo("bar");
}
@Test
public void uriCredsWithAtInPassword() {
this.locator.setUri(new String[] { "http://foo:bar%40@localhost:9999" });
Credentials credentials = this.locator.getCredentials(0);
assertThat(credentials.getUri()).isEqualTo("http://localhost:9999");
assertThat(credentials.getUsername()).isEqualTo("foo");
assertThat(credentials.getPassword()).isEqualTo("bar@");
}
@Test
public void explicitPassword() {
this.locator.setUri(new String[] { "http://foo:bar@localhost:9999" });