HADOOP-13287. TestS3ACredentials#testInstantiateFromURL fails if AWS secret key contains +. Contributed by Chris Nauroth.
This commit is contained in:
parent
605b4b6136
commit
b2c596cdda
@ -33,7 +33,6 @@
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.net.URISyntaxException;
|
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
import java.nio.file.AccessDeniedException;
|
import java.nio.file.AccessDeniedException;
|
||||||
|
|
||||||
@ -73,7 +72,11 @@ public void testInstantiateFromURL() throws Throwable {
|
|||||||
accessKey, secretKey);
|
accessKey, secretKey);
|
||||||
if (secretKey.contains("/")) {
|
if (secretKey.contains("/")) {
|
||||||
assertTrue("test URI encodes the / symbol", secretsURI.toString().
|
assertTrue("test URI encodes the / symbol", secretsURI.toString().
|
||||||
contains("%2F"));
|
contains("%252F"));
|
||||||
|
}
|
||||||
|
if (secretKey.contains("+")) {
|
||||||
|
assertTrue("test URI encodes the + symbol", secretsURI.toString().
|
||||||
|
contains("%252B"));
|
||||||
}
|
}
|
||||||
assertFalse("Does not contain secrets", original.equals(secretsURI));
|
assertFalse("Does not contain secrets", original.equals(secretsURI));
|
||||||
|
|
||||||
@ -132,8 +135,7 @@ public void testInvalidCredentialsFail() throws Throwable {
|
|||||||
|
|
||||||
private URI createUriWithEmbeddedSecrets(URI original,
|
private URI createUriWithEmbeddedSecrets(URI original,
|
||||||
String accessKey,
|
String accessKey,
|
||||||
String secretKey) throws URISyntaxException,
|
String secretKey) throws UnsupportedEncodingException {
|
||||||
UnsupportedEncodingException {
|
|
||||||
String encodedSecretKey = URLEncoder.encode(secretKey, "UTF-8");
|
String encodedSecretKey = URLEncoder.encode(secretKey, "UTF-8");
|
||||||
String formattedString = String.format("%s://%s:%s@%s/%s/",
|
String formattedString = String.format("%s://%s:%s@%s/%s/",
|
||||||
original.getScheme(),
|
original.getScheme(),
|
||||||
@ -143,10 +145,10 @@ private URI createUriWithEmbeddedSecrets(URI original,
|
|||||||
original.getPath());
|
original.getPath());
|
||||||
URI testURI;
|
URI testURI;
|
||||||
try {
|
try {
|
||||||
testURI = new URI(formattedString);
|
testURI = new Path(formattedString).toUri();
|
||||||
} catch (URISyntaxException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
// inner cause is stripped to keep any secrets out of stack traces
|
// inner cause is stripped to keep any secrets out of stack traces
|
||||||
throw new URISyntaxException("", "Could not encode URI");
|
throw new IllegalArgumentException("Could not encode Path");
|
||||||
}
|
}
|
||||||
return testURI;
|
return testURI;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user