HDDS-573. Make VirtualHostStyleFilter port agnostic. Contributed by Danilo Perez.
This commit is contained in:
parent
78ea897b67
commit
bfb720ebc8
@ -74,6 +74,7 @@ public void filter(ContainerRequestContext requestContext) throws
|
||||
}
|
||||
//Get the value of the host
|
||||
String host = requestContext.getHeaderString(HttpHeaders.HOST);
|
||||
host = checkHostWithoutPort(host);
|
||||
String domain = getDomainName(host);
|
||||
|
||||
if (domain == null) {
|
||||
@ -148,6 +149,14 @@ private String getDomainName(String host) {
|
||||
return match;
|
||||
}
|
||||
|
||||
private String checkHostWithoutPort(String host) {
|
||||
if (host.contains(":")){
|
||||
return host.substring(0, host.lastIndexOf(":"));
|
||||
} else {
|
||||
return host;
|
||||
}
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
public void setAuthenticationHeaderParser(AuthenticationHeaderParser parser) {
|
||||
this.authenticationHeaderParser = parser;
|
||||
|
@ -49,6 +49,7 @@ public void setup() {
|
||||
conf = new OzoneConfiguration();
|
||||
s3HttpAddr = "localhost:9878";
|
||||
conf.set(S3GatewayConfigKeys.OZONE_S3G_HTTP_ADDRESS_KEY, s3HttpAddr);
|
||||
s3HttpAddr = s3HttpAddr.substring(0, s3HttpAddr.lastIndexOf(":"));
|
||||
conf.set(S3GatewayConfigKeys.OZONE_S3G_DOMAIN_NAME, s3HttpAddr);
|
||||
authenticationHeaderParser = new AuthenticationHeaderParser();
|
||||
authenticationHeaderParser.setAuthHeader("AWS ozone:scret");
|
||||
@ -185,9 +186,10 @@ public void testVirtualHostStyleWithNoMatchingDomain() throws Exception {
|
||||
authenticationHeaderParser);
|
||||
|
||||
ContainerRequest containerRequest = createContainerRequest("mybucket" +
|
||||
".localhost:9999", null, null, true);
|
||||
".myhost:9999", null, null, true);
|
||||
try {
|
||||
virtualHostStyleFilter.filter(containerRequest);
|
||||
fail("testVirtualHostStyleWithNoMatchingDomain");
|
||||
} catch (InvalidRequestException ex) {
|
||||
GenericTestUtils.assertExceptionContains("No matching domain", ex);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user