You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jclouds.apache.org by an...@apache.org on 2013/08/01 22:45:47 UTC

[5/5] git commit: JCLOUDS-155: Making header handling in OpenStack case-insensitive

JCLOUDS-155: Making header handling in OpenStack case-insensitive

Submitted by Rodney Beede


Project: http://git-wip-us.apache.org/repos/asf/incubator-jclouds/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-jclouds/commit/ac17241c
Tree: http://git-wip-us.apache.org/repos/asf/incubator-jclouds/tree/ac17241c
Diff: http://git-wip-us.apache.org/repos/asf/incubator-jclouds/diff/ac17241c

Branch: refs/heads/fix-jclouds-155
Commit: ac17241c089a78372afe136513cc5d76f8ea228c
Parents: f167319
Author: Andrew Phillips <an...@apache.org>
Authored: Mon Jul 29 20:24:15 2013 -0400
Committer: Andrew Phillips <an...@apache.org>
Committed: Thu Aug 1 16:44:53 2013 -0400

----------------------------------------------------------------------
 ...seAuthenticationResponseFromHeadersTest.java | 66 -----------------
 .../ParseAuthenticationResponseFromHeaders.java |  4 +-
 ...seAuthenticationResponseFromHeadersTest.java | 77 ++++++++++++++++++++
 3 files changed, 80 insertions(+), 67 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-jclouds/blob/ac17241c/apis/swift/src/test/java/org/jclouds/openstack/functions/ParseAuthenticationResponseFromHeadersTest.java
----------------------------------------------------------------------
diff --git a/apis/swift/src/test/java/org/jclouds/openstack/functions/ParseAuthenticationResponseFromHeadersTest.java b/apis/swift/src/test/java/org/jclouds/openstack/functions/ParseAuthenticationResponseFromHeadersTest.java
deleted file mode 100644
index 85ae254..0000000
--- a/apis/swift/src/test/java/org/jclouds/openstack/functions/ParseAuthenticationResponseFromHeadersTest.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.jclouds.openstack.functions;
-
-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;
-
-import com.google.common.collect.ImmutableMap;
-import com.google.inject.AbstractModule;
-import com.google.inject.Guice;
-import com.google.inject.Injector;
-import com.google.inject.name.Names;
-
-/**
- * Tests behavior of {@code ParseContainerListFromJsonResponse}
- * 
- * @author Adrian Cole
- */
-@Test(groups = "unit", testName = "ParseAuthenticationResponseFromHeadersTest")
-public class ParseAuthenticationResponseFromHeadersTest {
-
-   Injector i = Guice.createInjector(new AbstractModule() {
-
-      @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");
-      }
-
-   });
-
-   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.<String, URI> of("X-Storage-Url", URI
-               .create("http://fooman:8080/v1/token"))));
-   }
-}

http://git-wip-us.apache.org/repos/asf/incubator-jclouds/blob/ac17241c/common/openstack/src/main/java/org/jclouds/openstack/functions/ParseAuthenticationResponseFromHeaders.java
----------------------------------------------------------------------
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 aa988fb..c824d9c 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<HttpResp
     */
    public AuthenticationResponse apply(HttpResponse from) {
       releasePayload(from);
+
+      // HTTP headers are case insensitive (RFC 2616) so we must allow for that when looking an header names for the URL keyword
       Builder<String, URI> builder = ImmutableMap.builder();
       for (Entry<String, String> 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),

http://git-wip-us.apache.org/repos/asf/incubator-jclouds/blob/ac17241c/common/openstack/src/test/java/org/jclouds/openstack/functions/ParseAuthenticationResponseFromHeadersTest.java
----------------------------------------------------------------------
diff --git a/common/openstack/src/test/java/org/jclouds/openstack/functions/ParseAuthenticationResponseFromHeadersTest.java b/common/openstack/src/test/java/org/jclouds/openstack/functions/ParseAuthenticationResponseFromHeadersTest.java
new file mode 100644
index 0000000..7578394
--- /dev/null
+++ b/common/openstack/src/test/java/org/jclouds/openstack/functions/ParseAuthenticationResponseFromHeadersTest.java
@@ -0,0 +1,77 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jclouds.openstack.functions;
+
+import static org.testng.Assert.assertEquals;
+
+import java.net.URI;
+
+import org.jclouds.Constants;
+import org.jclouds.http.HttpResponse;
+import org.jclouds.openstack.domain.AuthenticationResponse;
+import org.testng.annotations.Test;
+
+import com.google.common.collect.ImmutableMap;
+import com.google.inject.AbstractModule;
+import com.google.inject.Guice;
+import com.google.inject.Injector;
+import com.google.inject.name.Names;
+
+/**
+ * Tests behavior of {@code ParseAuthenticationResponseFromHeaders}
+ *
+ * @author Adrian Cole
+ */
+@Test(groups = "unit", testName = "ParseAuthenticationResponseFromHeadersTest")
+public class ParseAuthenticationResponseFromHeadersTest {
+
+   Injector i = Guice.createInjector(new AbstractModule() {
+
+      @Override
+      protected void configure() {
+         bindConstant().annotatedWith(Names.named(Constants.PROPERTY_API_VERSION)).to("1");
+      }
+
+   });
+
+   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.<String, URI> 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.<String, URI> of("x-storage-url", 
+              URI.create("http://fooman:8080/v1/token"))));
+   }
+}