From 375cb2075d22a26ff11fc6491fda57e347f207b4 Mon Sep 17 00:00:00 2001 From: Andrew Phillips Date: Mon, 29 Jul 2013 20:24:15 -0400 Subject: [PATCH] JCLOUDS-155: Making header handling in OpenStack case-insensitive Submitted by Rodney Beede --- ...arseAuthenticationResponseFromHeaders.java | 4 ++- ...AuthenticationResponseFromHeadersTest.java | 25 +++++++++++++------ 2 files changed, 21 insertions(+), 8 deletions(-) rename {apis/swift => common/openstack}/src/test/java/org/jclouds/openstack/functions/ParseAuthenticationResponseFromHeadersTest.java (72%) diff --git a/common/openstack/src/main/java/org/jclouds/openstack/functions/ParseAuthenticationResponseFromHeaders.java b/common/openstack/src/main/java/org/jclouds/openstack/functions/ParseAuthenticationResponseFromHeaders.java index aa988fbbb1..c824d9c2d9 100644 --- a/common/openstack/src/main/java/org/jclouds/openstack/functions/ParseAuthenticationResponseFromHeaders.java +++ b/common/openstack/src/main/java/org/jclouds/openstack/functions/ParseAuthenticationResponseFromHeaders.java @@ -56,9 +56,11 @@ public class ParseAuthenticationResponseFromHeaders implements Function builder = ImmutableMap.builder(); for (Entry entry : from.getHeaders().entries()) { - if (entry.getKey().endsWith(URL_SUFFIX)) + if (entry.getKey().toLowerCase().endsWith(URL_SUFFIX.toLowerCase())) builder.put(entry.getKey(), getURI(entry.getValue())); } AuthenticationResponse response = new AuthenticationResponse(checkNotNull(from.getFirstHeaderOrNull(AUTH_TOKEN), diff --git a/apis/swift/src/test/java/org/jclouds/openstack/functions/ParseAuthenticationResponseFromHeadersTest.java b/common/openstack/src/test/java/org/jclouds/openstack/functions/ParseAuthenticationResponseFromHeadersTest.java similarity index 72% rename from apis/swift/src/test/java/org/jclouds/openstack/functions/ParseAuthenticationResponseFromHeadersTest.java rename to common/openstack/src/test/java/org/jclouds/openstack/functions/ParseAuthenticationResponseFromHeadersTest.java index 85ae2549fc..7578394192 100644 --- a/apis/swift/src/test/java/org/jclouds/openstack/functions/ParseAuthenticationResponseFromHeadersTest.java +++ b/common/openstack/src/test/java/org/jclouds/openstack/functions/ParseAuthenticationResponseFromHeadersTest.java @@ -21,7 +21,6 @@ import static org.testng.Assert.assertEquals; import java.net.URI; import org.jclouds.Constants; -import org.jclouds.blobstore.reference.BlobStoreConstants; import org.jclouds.http.HttpResponse; import org.jclouds.openstack.domain.AuthenticationResponse; import org.testng.annotations.Test; @@ -33,8 +32,8 @@ import com.google.inject.Injector; import com.google.inject.name.Names; /** - * Tests behavior of {@code ParseContainerListFromJsonResponse} - * + * Tests behavior of {@code ParseAuthenticationResponseFromHeaders} + * * @author Adrian Cole */ @Test(groups = "unit", testName = "ParseAuthenticationResponseFromHeadersTest") @@ -44,7 +43,6 @@ public class ParseAuthenticationResponseFromHeadersTest { @Override protected void configure() { - bindConstant().annotatedWith(Names.named(BlobStoreConstants.PROPERTY_USER_METADATA_PREFIX)).to("sdf"); bindConstant().annotatedWith(Names.named(Constants.PROPERTY_API_VERSION)).to("1"); } @@ -53,14 +51,27 @@ public class ParseAuthenticationResponseFromHeadersTest { public void testReplaceLocalhost() { ParseAuthenticationResponseFromHeaders parser = i.getInstance(ParseAuthenticationResponseFromHeaders.class); parser = parser.setHostToReplace("fooman"); - + HttpResponse response = HttpResponse.builder().statusCode(204).message("No Content") .addHeader("X-Auth-Token", "token") .addHeader("X-Storage-Token", "token") .addHeader("X-Storage-Url", "http://127.0.0.1:8080/v1/token").build(); AuthenticationResponse md = parser.apply(response); - assertEquals(md, new AuthenticationResponse("token", ImmutableMap. of("X-Storage-Url", URI - .create("http://fooman:8080/v1/token")))); + assertEquals(md, new AuthenticationResponse("token", ImmutableMap. of("X-Storage-Url", + URI.create("http://fooman:8080/v1/token")))); + } + + public void testHandleHeadersCaseInsensitively() { + ParseAuthenticationResponseFromHeaders parser = i.getInstance(ParseAuthenticationResponseFromHeaders.class); + parser = parser.setHostToReplace("fooman"); + + HttpResponse response = HttpResponse.builder().statusCode(204).message("No Content") + .addHeader("x-auth-token", "token") + .addHeader("x-storage-token", "token") + .addHeader("x-storage-url", "http://127.0.0.1:8080/v1/token").build(); + AuthenticationResponse md = parser.apply(response); + assertEquals(md, new AuthenticationResponse("token", ImmutableMap. of("x-storage-url", + URI.create("http://fooman:8080/v1/token")))); } }