diff --git a/apis/swift/src/main/java/org/jclouds/openstack/swift/SwiftApiMetadata.java b/apis/swift/src/main/java/org/jclouds/openstack/swift/SwiftApiMetadata.java index 1b1e25bf9b..34fa5479de 100644 --- a/apis/swift/src/main/java/org/jclouds/openstack/swift/SwiftApiMetadata.java +++ b/apis/swift/src/main/java/org/jclouds/openstack/swift/SwiftApiMetadata.java @@ -20,17 +20,12 @@ package org.jclouds.openstack.swift; import static org.jclouds.blobstore.reference.BlobStoreConstants.PROPERTY_USER_METADATA_PREFIX; import static org.jclouds.location.reference.LocationConstants.PROPERTY_REGIONS; -import static org.jclouds.openstack.keystone.v2_0.config.KeystoneProperties.CREDENTIAL_TYPE; -import static org.jclouds.openstack.keystone.v2_0.config.KeystoneProperties.SERVICE_TYPE; import java.net.URI; import java.util.Properties; import org.jclouds.apis.ApiMetadata; import org.jclouds.blobstore.BlobStoreContext; -import org.jclouds.openstack.keystone.v2_0.config.CredentialTypes; -import org.jclouds.openstack.keystone.v2_0.config.KeystoneProperties; -import org.jclouds.openstack.services.ServiceType; import org.jclouds.openstack.swift.blobstore.config.SwiftBlobStoreContextModule; import org.jclouds.openstack.swift.config.SwiftRestClientModule; import org.jclouds.openstack.swift.config.SwiftRestClientModule.StorageEndpointModule; @@ -69,12 +64,8 @@ public class SwiftApiMetadata extends BaseRestApiMetadata { public static Properties defaultProperties() { Properties properties = BaseRestApiMetadata.defaultProperties(); - properties.setProperty(SERVICE_TYPE, ServiceType.OBJECT_STORE); - // TODO: this doesn't actually do anything yet. - properties.setProperty(KeystoneProperties.VERSION, "2.0"); - properties.setProperty(CREDENTIAL_TYPE, CredentialTypes.API_ACCESS_KEY_CREDENTIALS); - properties.setProperty(PROPERTY_REGIONS, "DEFAULT"); properties.setProperty(PROPERTY_USER_METADATA_PREFIX, "X-Object-Meta-"); + properties.setProperty(PROPERTY_REGIONS, "DEFAULT"); return properties; } @@ -82,8 +73,8 @@ public class SwiftApiMetadata extends BaseRestApiMetadata { protected Builder(Class syncClient, Class asyncClient){ super(syncClient, asyncClient); id("swift") - .name("OpenStack Swift Pre-Diablo API") - .identityName("tenantName:user or user") + .name("OpenStack Swift with SwiftAuth") + .identityName("tenantId:user") .credentialName("password") .documentation(URI.create("http://api.openstack.org/")) .version("1.0") diff --git a/apis/swift/src/main/java/org/jclouds/openstack/swift/SwiftKeystoneApiMetadata.java b/apis/swift/src/main/java/org/jclouds/openstack/swift/SwiftKeystoneApiMetadata.java index 520ae80918..803054168e 100644 --- a/apis/swift/src/main/java/org/jclouds/openstack/swift/SwiftKeystoneApiMetadata.java +++ b/apis/swift/src/main/java/org/jclouds/openstack/swift/SwiftKeystoneApiMetadata.java @@ -19,10 +19,15 @@ package org.jclouds.openstack.swift; import static org.jclouds.location.reference.LocationConstants.PROPERTY_REGIONS; +import static org.jclouds.openstack.keystone.v2_0.config.KeystoneProperties.CREDENTIAL_TYPE; +import static org.jclouds.openstack.keystone.v2_0.config.KeystoneProperties.SERVICE_TYPE; import java.util.Properties; import org.jclouds.apis.ApiMetadata; +import org.jclouds.openstack.keystone.v2_0.config.CredentialTypes; +import org.jclouds.openstack.keystone.v2_0.config.KeystoneProperties; +import org.jclouds.openstack.services.ServiceType; import org.jclouds.openstack.swift.blobstore.config.SwiftBlobStoreContextModule; import org.jclouds.openstack.swift.config.SwiftKeystoneRestClientModule; import org.jclouds.openstack.swift.config.SwiftRestClientModule.KeystoneStorageEndpointModule; @@ -64,6 +69,10 @@ public class SwiftKeystoneApiMetadata extends SwiftApiMetadata { public static Properties defaultProperties() { Properties properties = SwiftApiMetadata.defaultProperties(); + properties.setProperty(SERVICE_TYPE, ServiceType.OBJECT_STORE); + // TODO: this doesn't actually do anything yet. + properties.setProperty(KeystoneProperties.VERSION, "2.0"); + properties.setProperty(CREDENTIAL_TYPE, CredentialTypes.API_ACCESS_KEY_CREDENTIALS); properties.remove(PROPERTY_REGIONS); return properties; } @@ -72,6 +81,9 @@ public class SwiftKeystoneApiMetadata extends SwiftApiMetadata { protected Builder(){ super(SwiftKeystoneClient.class, SwiftKeystoneAsyncClient.class); id("swift-keystone") + .name("OpenStack Swift with Keystone authentication") + .identityName("tenantName:user or user") + .credentialName("password") .context(CONTEXT_TOKEN) .defaultModules(ImmutableSet.>of(KeystoneStorageEndpointModule.class, SwiftKeystoneRestClientModule.class, SwiftBlobStoreContextModule.class)); } diff --git a/apis/swift/src/test/java/org/jclouds/openstack/swift/SwiftClientExpectTest.java b/apis/swift/src/test/java/org/jclouds/openstack/swift/SwiftClientExpectTest.java new file mode 100644 index 0000000000..7070455160 --- /dev/null +++ b/apis/swift/src/test/java/org/jclouds/openstack/swift/SwiftClientExpectTest.java @@ -0,0 +1,73 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds 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.swift; + +import static org.testng.Assert.assertFalse; +import static org.testng.Assert.assertTrue; + +import java.net.URI; + +import org.jclouds.http.HttpRequest; +import org.jclouds.http.HttpResponse; +import org.jclouds.openstack.swift.internal.BaseSwiftExpectTest; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableMultimap; + +/** + * + * @author Adrian Cole + */ +@Test(testName = "SwiftClientExpectTest") +public class SwiftClientExpectTest extends BaseSwiftExpectTest { + + public void testContainerExistsWhenResponseIs2xxReturnsTrue() throws Exception { + HttpRequest headContainer = HttpRequest.builder() + .method("HEAD") + .endpoint(URI.create(swiftEndpointWithHostReplaced + "/foo")) + .headers( + ImmutableMultimap. builder() + .put("X-Auth-Token", authToken).build()).build(); + + HttpResponse headContainerResponse = HttpResponse.builder().statusCode(200).build(); + + SwiftClient clientWhenContainerExists = requestsSendResponses(authRequest, + authResponse, headContainer, headContainerResponse); + + assertTrue(clientWhenContainerExists.containerExists("foo")); + } + + public void testContainerExistsWhenResponseIs404ReturnsFalse() throws Exception { + HttpRequest headContainer = HttpRequest.builder() + .method("HEAD") + .endpoint(URI.create(swiftEndpointWithHostReplaced + "/foo")) + .headers( + ImmutableMultimap. builder() + .put("X-Auth-Token", authToken).build()).build(); + + HttpResponse headContainerResponse = HttpResponse.builder().statusCode(404).build(); + + SwiftClient clientWhenContainerDoesntExist = requestsSendResponses(authRequest, + authResponse, headContainer, headContainerResponse); + + assertFalse(clientWhenContainerDoesntExist.containerExists("foo")); + + } + +} diff --git a/apis/swift/src/test/java/org/jclouds/openstack/swift/internal/BaseSwiftExpectTest.java b/apis/swift/src/test/java/org/jclouds/openstack/swift/internal/BaseSwiftExpectTest.java new file mode 100644 index 0000000000..ff15a6c741 --- /dev/null +++ b/apis/swift/src/test/java/org/jclouds/openstack/swift/internal/BaseSwiftExpectTest.java @@ -0,0 +1,75 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds 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.swift.internal; + +import java.net.URI; +import java.util.Properties; + +import org.jclouds.http.HttpRequest; +import org.jclouds.http.HttpResponse; +import org.jclouds.rest.internal.BaseRestClientExpectTest; + +import com.google.common.collect.ImmutableMultimap; + +/** + * Base class for writing Swift Expect tests + * + * @author Adrian Cole + */ +public class BaseSwiftExpectTest extends BaseRestClientExpectTest { + + protected String endpoint = "http://myhost:8080/auth"; + protected HttpRequest authRequest; + public BaseSwiftExpectTest() { + provider = "swift"; + identity = "test:tester"; + credential = "testing"; + authRequest = HttpRequest.builder() + .method("GET") + .endpoint(URI.create(endpoint+ "/v1.0")) + .headers(ImmutableMultimap.builder() + .put("X-Auth-User", identity) + .put("X-Auth-Key", credential) + .put("Accept", "*/*") + .put("Host", "myhost:8080").build()).build(); + } + + protected String authToken = "AUTH_tk36dabe83ca744cc296a98ec46089ec35"; + + protected String swiftEndpoint = "http://127.0.0.1:8080/v1/AUTH_test"; + + /** + * often swift returns the localhost url when requested via a dns name. this + * test ensures that replacement works. + */ + protected String swiftEndpointWithHostReplaced = swiftEndpoint.replace("127.0.0.1", "myhost"); + + protected HttpResponse authResponse = HttpResponse.builder() + .statusCode(200) + .message("HTTP/1.1 200 OK") + .headers(ImmutableMultimap.builder() + .put("X-Storage-Url", swiftEndpoint) + .put("X-Auth-Token", authToken).build()).build(); + + protected Properties setupProperties() { + Properties props = super.setupProperties(); + props.put(provider+".endpoint", endpoint); + return props; + } +} \ No newline at end of file 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 8061c41553..9b68139a8d 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 @@ -90,9 +90,6 @@ public class ParseAuthenticationResponseFromHeaders implements Function