mirror of https://github.com/apache/jclouds.git
JCLOUDS-656: Parse Swift authentication headers case-insensitively
Also ensure they are added to the result object with the normalized
capitalization expected by downstream code.
Follow-up to 375cb207
.
This commit is contained in:
parent
5d3b293b69
commit
aa174a5d73
|
@ -20,7 +20,6 @@ import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
import static org.jclouds.http.HttpUtils.releasePayload;
|
import static org.jclouds.http.HttpUtils.releasePayload;
|
||||||
import static org.jclouds.http.Uris.uriBuilder;
|
import static org.jclouds.http.Uris.uriBuilder;
|
||||||
import static org.jclouds.openstack.reference.AuthHeaders.AUTH_TOKEN;
|
import static org.jclouds.openstack.reference.AuthHeaders.AUTH_TOKEN;
|
||||||
import static org.jclouds.openstack.reference.AuthHeaders.URL_SUFFIX;
|
|
||||||
|
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
@ -31,6 +30,7 @@ import org.jclouds.http.HttpRequest;
|
||||||
import org.jclouds.http.HttpResponse;
|
import org.jclouds.http.HttpResponse;
|
||||||
import org.jclouds.logging.Logger;
|
import org.jclouds.logging.Logger;
|
||||||
import org.jclouds.openstack.domain.AuthenticationResponse;
|
import org.jclouds.openstack.domain.AuthenticationResponse;
|
||||||
|
import org.jclouds.openstack.reference.AuthHeaders;
|
||||||
import org.jclouds.rest.InvocationContext;
|
import org.jclouds.rest.InvocationContext;
|
||||||
|
|
||||||
import com.google.common.annotations.VisibleForTesting;
|
import com.google.common.annotations.VisibleForTesting;
|
||||||
|
@ -58,8 +58,14 @@ public class ParseAuthenticationResponseFromHeaders implements Function<HttpResp
|
||||||
// HTTP headers are case insensitive (RFC 2616) so we must allow for that when looking an header names for the URL keyword
|
// 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();
|
Builder<String, URI> builder = ImmutableMap.builder();
|
||||||
for (Entry<String, String> entry : from.getHeaders().entries()) {
|
for (Entry<String, String> entry : from.getHeaders().entries()) {
|
||||||
if (entry.getKey().toLowerCase().endsWith(URL_SUFFIX.toLowerCase()))
|
String header = entry.getKey();
|
||||||
builder.put(entry.getKey(), getURI(entry.getValue()));
|
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),
|
AuthenticationResponse response = new AuthenticationResponse(checkNotNull(from.getFirstHeaderOrNull(AUTH_TOKEN),
|
||||||
AUTH_TOKEN), builder.build());
|
AUTH_TOKEN), builder.build());
|
||||||
|
|
|
@ -23,9 +23,9 @@ import java.net.URI;
|
||||||
import org.jclouds.Constants;
|
import org.jclouds.Constants;
|
||||||
import org.jclouds.http.HttpResponse;
|
import org.jclouds.http.HttpResponse;
|
||||||
import org.jclouds.openstack.domain.AuthenticationResponse;
|
import org.jclouds.openstack.domain.AuthenticationResponse;
|
||||||
|
import org.jclouds.openstack.reference.AuthHeaders;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableMap;
|
|
||||||
import com.google.inject.AbstractModule;
|
import com.google.inject.AbstractModule;
|
||||||
import com.google.inject.Guice;
|
import com.google.inject.Guice;
|
||||||
import com.google.inject.Injector;
|
import com.google.inject.Injector;
|
||||||
|
@ -53,11 +53,16 @@ public class ParseAuthenticationResponseFromHeadersTest {
|
||||||
HttpResponse response = HttpResponse.builder().statusCode(204).message("No Content")
|
HttpResponse response = HttpResponse.builder().statusCode(204).message("No Content")
|
||||||
.addHeader("X-Auth-Token", "token")
|
.addHeader("X-Auth-Token", "token")
|
||||||
.addHeader("X-Storage-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);
|
AuthenticationResponse md = parser.apply(response);
|
||||||
assertEquals(md, new AuthenticationResponse("token", ImmutableMap.<String, URI> of("X-Storage-Url",
|
assertEquals(md.getAuthToken(), "token");
|
||||||
URI.create("http://fooman:8080/v1/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() {
|
public void testHandleHeadersCaseInsensitively() {
|
||||||
|
@ -67,9 +72,14 @@ public class ParseAuthenticationResponseFromHeadersTest {
|
||||||
HttpResponse response = HttpResponse.builder().statusCode(204).message("No Content")
|
HttpResponse response = HttpResponse.builder().statusCode(204).message("No Content")
|
||||||
.addHeader("x-auth-token", "token")
|
.addHeader("x-auth-token", "token")
|
||||||
.addHeader("x-storage-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);
|
AuthenticationResponse md = parser.apply(response);
|
||||||
assertEquals(md, new AuthenticationResponse("token", ImmutableMap.<String, URI> of("x-storage-url",
|
assertEquals(md.getAuthToken(), "token");
|
||||||
URI.create("http://fooman:8080/v1/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"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue