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 26fb168a24..98780d5037 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 @@ -20,7 +20,6 @@ import static com.google.common.base.Preconditions.checkNotNull; import static org.jclouds.http.HttpUtils.releasePayload; import static org.jclouds.http.Uris.uriBuilder; import static org.jclouds.openstack.reference.AuthHeaders.AUTH_TOKEN; -import static org.jclouds.openstack.reference.AuthHeaders.URL_SUFFIX; import java.net.URI; import java.util.Map.Entry; @@ -31,6 +30,7 @@ import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpResponse; import org.jclouds.logging.Logger; import org.jclouds.openstack.domain.AuthenticationResponse; +import org.jclouds.openstack.reference.AuthHeaders; import org.jclouds.rest.InvocationContext; import com.google.common.annotations.VisibleForTesting; @@ -58,8 +58,14 @@ public class ParseAuthenticationResponseFromHeaders implements Function builder = ImmutableMap.builder(); for (Entry entry : from.getHeaders().entries()) { - if (entry.getKey().toLowerCase().endsWith(URL_SUFFIX.toLowerCase())) - builder.put(entry.getKey(), getURI(entry.getValue())); + String header = entry.getKey(); + if (header.equalsIgnoreCase(AuthHeaders.STORAGE_URL)) { + builder.put(AuthHeaders.STORAGE_URL, getURI(entry.getValue())); + } else if (header.equalsIgnoreCase(AuthHeaders.SERVER_MANAGEMENT_URL)) { + builder.put(AuthHeaders.SERVER_MANAGEMENT_URL, getURI(entry.getValue())); + } else if (header.equalsIgnoreCase(AuthHeaders.CDN_MANAGEMENT_URL)) { + builder.put(AuthHeaders.CDN_MANAGEMENT_URL, getURI(entry.getValue())); + } } AuthenticationResponse response = new AuthenticationResponse(checkNotNull(from.getFirstHeaderOrNull(AUTH_TOKEN), AUTH_TOKEN), builder.build()); 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 index 407abd6959..e566ca015e 100644 --- a/common/openstack/src/test/java/org/jclouds/openstack/functions/ParseAuthenticationResponseFromHeadersTest.java +++ b/common/openstack/src/test/java/org/jclouds/openstack/functions/ParseAuthenticationResponseFromHeadersTest.java @@ -23,9 +23,9 @@ import java.net.URI; import org.jclouds.Constants; import org.jclouds.http.HttpResponse; import org.jclouds.openstack.domain.AuthenticationResponse; +import org.jclouds.openstack.reference.AuthHeaders; 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; @@ -53,11 +53,16 @@ public class ParseAuthenticationResponseFromHeadersTest { 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(); + .addHeader("X-Storage-Url", "http://127.0.0.1:8080/v1/token") + .addHeader("X-CDN-Management-Url", "http://127.0.0.1:8080/cdn-mgmt") + .addHeader("X-Server-Management-Url", "http://127.0.0.1:8080/srv-mgmt") + .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.getAuthToken(), "token"); + assertEquals(md.getServices().get(AuthHeaders.STORAGE_URL), URI.create("http://fooman:8080/v1/token")); + assertEquals(md.getServices().get(AuthHeaders.CDN_MANAGEMENT_URL), URI.create("http://fooman:8080/cdn-mgmt")); + assertEquals(md.getServices().get(AuthHeaders.SERVER_MANAGEMENT_URL), URI.create("http://fooman:8080/srv-mgmt")); } public void testHandleHeadersCaseInsensitively() { @@ -67,9 +72,14 @@ public class ParseAuthenticationResponseFromHeadersTest { 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(); + .addHeader("x-storage-url", "http://127.0.0.1:8080/v1/token") + .addHeader("x-cdn-management-url", "http://127.0.0.1:8080/cdn-mgmt") + .addHeader("x-server-management-url", "http://127.0.0.1:8080/srv-mgmt") + .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.getAuthToken(), "token"); + assertEquals(md.getServices().get(AuthHeaders.STORAGE_URL), URI.create("http://fooman:8080/v1/token")); + assertEquals(md.getServices().get(AuthHeaders.CDN_MANAGEMENT_URL), URI.create("http://fooman:8080/cdn-mgmt")); + assertEquals(md.getServices().get(AuthHeaders.SERVER_MANAGEMENT_URL), URI.create("http://fooman:8080/srv-mgmt")); } }