You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jclouds.apache.org by na...@apache.org on 2015/04/15 21:41:39 UTC

[34/39] jclouds git commit: * Refactor OAuth to be less complex. * Remove oauth as a standalone api. * Rename redundant OAuthAuthenticationFilter to OAuthFilter. * Make AuthorizationApi more simple by using form semantics. * Simplified OAuth by only

http://git-wip-us.apache.org/repos/asf/jclouds/blob/46a7351a/apis/oauth/src/test/java/org/jclouds/oauth/v2/AuthorizationApiLiveTest.java
----------------------------------------------------------------------
diff --git a/apis/oauth/src/test/java/org/jclouds/oauth/v2/AuthorizationApiLiveTest.java b/apis/oauth/src/test/java/org/jclouds/oauth/v2/AuthorizationApiLiveTest.java
new file mode 100644
index 0000000..5002307
--- /dev/null
+++ b/apis/oauth/src/test/java/org/jclouds/oauth/v2/AuthorizationApiLiveTest.java
@@ -0,0 +1,94 @@
+/*
+ * 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.oauth.v2;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+import static org.jclouds.oauth.v2.OAuthTestUtils.setCredential;
+import static org.jclouds.oauth.v2.config.OAuthProperties.AUDIENCE;
+import static org.jclouds.oauth.v2.config.OAuthProperties.JWS_ALG;
+import static org.jclouds.oauth.v2.config.OAuthScopes.SingleScope;
+import static org.jclouds.providers.AnonymousProviderMetadata.forApiOnEndpoint;
+import static org.testng.Assert.assertNotNull;
+
+import java.util.Properties;
+
+import org.jclouds.apis.BaseApiLiveTest;
+import org.jclouds.oauth.v2.config.OAuthModule;
+import org.jclouds.oauth.v2.config.OAuthScopes;
+import org.jclouds.oauth.v2.domain.Claims;
+import org.jclouds.oauth.v2.domain.Token;
+import org.jclouds.providers.ProviderMetadata;
+import org.testng.annotations.Test;
+
+import com.google.common.collect.ImmutableList;
+import com.google.inject.Binder;
+import com.google.inject.Module;
+import com.google.inject.name.Names;
+
+@Test(groups = "live", singleThreaded = true)
+public class AuthorizationApiLiveTest extends BaseApiLiveTest<AuthorizationApi> {
+
+   private final String jwsAlg = "RS256";
+   private String scope;
+   private String audience;
+
+   public AuthorizationApiLiveTest() {
+      provider = "oauth";
+   }
+
+   public void authenticateJWTToken() throws Exception {
+      long now = System.currentTimeMillis() / 1000;
+      Claims claims = Claims.create(
+            identity, // iss
+            scope, // scope
+            audience, // aud
+            now + 3600, // exp
+            now // iat
+      );
+
+      Token token = api.authorize(claims);
+
+      assertNotNull(token, "no token when authorizing " + claims);
+   }
+
+   /** OAuth isn't registered as a provider intentionally, so we fake one. */
+   @Override protected ProviderMetadata createProviderMetadata() {
+      return forApiOnEndpoint(AuthorizationApi.class, endpoint).toBuilder().id("oauth").build();
+   }
+
+   @Override protected Properties setupProperties() {
+      Properties props = super.setupProperties();
+      props.setProperty(JWS_ALG, jwsAlg);
+      credential = setCredential(props, "oauth.credential");
+      audience = checkNotNull(setIfTestSystemPropertyPresent(props, AUDIENCE), "test.jclouds.oauth.audience");
+      scope = checkNotNull(setIfTestSystemPropertyPresent(props, "jclouds.oauth.scope"), "test.jclouds.oauth.scope");
+      return props;
+   }
+
+   @Override protected Iterable<Module> setupModules() {
+      return ImmutableList.<Module>builder() //
+            .add(new OAuthModule()) //
+            .add(new Module() {
+               @Override public void configure(Binder binder) {
+                  // ContextBuilder erases oauth.endpoint, as that's the same name as the provider key.
+                  binder.bindConstant().annotatedWith(Names.named("oauth.endpoint")).to(endpoint);
+                  binder.bind(OAuthScopes.class).toInstance(SingleScope.create(scope));
+               }
+            }).addAll(super.setupModules()).build();
+   }
+}
+

http://git-wip-us.apache.org/repos/asf/jclouds/blob/46a7351a/apis/oauth/src/test/java/org/jclouds/oauth/v2/AuthorizationApiMockTest.java
----------------------------------------------------------------------
diff --git a/apis/oauth/src/test/java/org/jclouds/oauth/v2/AuthorizationApiMockTest.java b/apis/oauth/src/test/java/org/jclouds/oauth/v2/AuthorizationApiMockTest.java
new file mode 100644
index 0000000..0d09090
--- /dev/null
+++ b/apis/oauth/src/test/java/org/jclouds/oauth/v2/AuthorizationApiMockTest.java
@@ -0,0 +1,125 @@
+/*
+ * 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.oauth.v2;
+
+import static com.google.common.base.Charsets.UTF_8;
+import static com.google.common.io.BaseEncoding.base64Url;
+import static com.google.common.util.concurrent.MoreExecutors.sameThreadExecutor;
+import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
+import static org.jclouds.Constants.PROPERTY_MAX_RETRIES;
+import static org.jclouds.oauth.v2.config.CredentialType.P12_PRIVATE_KEY_CREDENTIALS;
+import static org.jclouds.oauth.v2.config.OAuthProperties.AUDIENCE;
+import static org.jclouds.oauth.v2.config.OAuthProperties.CREDENTIAL_TYPE;
+import static org.jclouds.oauth.v2.config.OAuthProperties.JWS_ALG;
+import static org.jclouds.util.Strings2.toStringAndClose;
+import static org.testng.Assert.assertEquals;
+
+import java.io.IOException;
+import java.net.URL;
+import java.util.Properties;
+
+import org.jclouds.ContextBuilder;
+import org.jclouds.concurrent.config.ExecutorServiceModule;
+import org.jclouds.oauth.v2.config.OAuthModule;
+import org.jclouds.oauth.v2.config.OAuthScopes;
+import org.jclouds.oauth.v2.config.OAuthScopes.SingleScope;
+import org.jclouds.oauth.v2.domain.Claims;
+import org.jclouds.oauth.v2.domain.Token;
+import org.jclouds.rest.AnonymousHttpApiMetadata;
+import org.testng.annotations.Test;
+
+import com.google.common.base.Joiner;
+import com.google.common.collect.ImmutableSet;
+import com.google.common.io.BaseEncoding;
+import com.google.inject.Binder;
+import com.google.inject.Module;
+import com.squareup.okhttp.mockwebserver.MockResponse;
+import com.squareup.okhttp.mockwebserver.MockWebServer;
+import com.squareup.okhttp.mockwebserver.RecordedRequest;
+
+@Test(groups = "unit", testName = "OAuthApiMockTest")
+public class AuthorizationApiMockTest {
+   private static final String SCOPE = "https://www.googleapis.com/auth/prediction";
+
+   private static final String header = "{\"alg\":\"RS256\",\"typ\":\"JWT\"}";
+
+   private static final String claims = "{\"iss\":\"761326798069-r5mljlln1rd4lrbhg75efgigp36m78j5@developer" +
+         ".gserviceaccount.com\",\"scope\":\"" + SCOPE + "\",\"aud\":\"https://accounts.google" +
+         ".com/o/oauth2/token\",\"exp\":1328573381,\"iat\":1328569781}";
+
+   private static final Token TOKEN = Token.create("1/8xbJqaOZXSUZbHLl5EOtu1pxz3fmmetKx9W8CV4t79M", "Bearer", 3600);
+
+   private static final Claims CLAIMS = Claims.create(
+         "761326798069-r5mljlln1rd4lrbhg75efgigp36m78j5@developer.gserviceaccount.com", // iss
+         SCOPE, // scope
+         "https://accounts.google.com/o/oauth2/token", // aud
+         1328573381, // exp
+         1328569781 // iat
+   );
+
+   public void testGenerateJWTRequest() throws Exception {
+      MockWebServer server = new MockWebServer();
+      server.enqueue(new MockResponse().setBody("{\n" +
+                  "  \"access_token\" : \"1/8xbJqaOZXSUZbHLl5EOtu1pxz3fmmetKx9W8CV4t79M\",\n" +
+                  "  \"token_type\" : \"Bearer\",\n" +
+                  "  \"expires_in\" : 3600\n" +
+                  "}"));
+      server.play();
+
+      AuthorizationApi api = api(server.getUrl("/"));
+
+      assertEquals(api.authorize(CLAIMS), TOKEN);
+
+      RecordedRequest request = server.takeRequest();
+      assertEquals(request.getMethod(), "POST");
+      assertEquals(request.getHeader("Accept"), APPLICATION_JSON);
+      assertEquals(request.getHeader("Content-Type"), "application/x-www-form-urlencoded");
+
+      assertEquals(new String(request.getBody(), UTF_8), //
+            "grant_type=urn%3Aietf%3Aparams%3Aoauth%3Agrant-type%3Ajwt-bearer&" +
+                  // Base64 Encoded Header
+                  "assertion=" +
+                  Joiner.on('.').join(encoding.encode(header.getBytes(UTF_8)), encoding.encode(claims.getBytes(UTF_8)),
+                  // Base64 encoded {header}.{claims} signature (using SHA256)
+                  "W2Lesr_98AzVYiMbzxFqmwcOjpIWlwqkC6pNn1fXND9oSDNNnFhy-AAR6DKH-x9ZmxbY80" +
+                  "R5fH-OCeWumXlVgceKN8Z2SmgQsu8ElTpypQA54j_5j8vUImJ5hsOUYPeyF1U2BUzZ3L5g" +
+                  "03PXBA0YWwRU9E1ChH28dQBYuGiUmYw"));
+
+   }
+
+   private final BaseEncoding encoding = base64Url().omitPadding();
+
+   private AuthorizationApi api(URL url) throws IOException {
+      Properties overrides = new Properties();
+      overrides.setProperty("oauth.endpoint", url.toString());
+      overrides.setProperty(JWS_ALG, "RS256");
+      overrides.setProperty(CREDENTIAL_TYPE, P12_PRIVATE_KEY_CREDENTIALS.toString());
+      overrides.setProperty(AUDIENCE, "https://accounts.google.com/o/oauth2/token");
+      overrides.setProperty(PROPERTY_MAX_RETRIES, "1");
+
+      return ContextBuilder.newBuilder(AnonymousHttpApiMetadata.forApi(AuthorizationApi.class))
+            .credentials("foo", toStringAndClose(OAuthTestUtils.class.getResourceAsStream("/testpk.pem")))
+            .endpoint(url.toString())
+            .overrides(overrides)
+            .modules(ImmutableSet.of(new ExecutorServiceModule(sameThreadExecutor()), new OAuthModule(), new Module() {
+               @Override public void configure(Binder binder) {
+                  binder.bind(OAuthScopes.class).toInstance(SingleScope.create(SCOPE));
+               }
+            }))
+            .buildApi(AuthorizationApi.class);
+   }
+}

http://git-wip-us.apache.org/repos/asf/jclouds/blob/46a7351a/apis/oauth/src/test/java/org/jclouds/oauth/v2/OAuthApiMetadataTest.java
----------------------------------------------------------------------
diff --git a/apis/oauth/src/test/java/org/jclouds/oauth/v2/OAuthApiMetadataTest.java b/apis/oauth/src/test/java/org/jclouds/oauth/v2/OAuthApiMetadataTest.java
deleted file mode 100644
index 3bd0456..0000000
--- a/apis/oauth/src/test/java/org/jclouds/oauth/v2/OAuthApiMetadataTest.java
+++ /dev/null
@@ -1,39 +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.oauth.v2;
-
-import org.jclouds.View;
-import org.jclouds.apis.internal.BaseApiMetadataTest;
-import org.testng.annotations.Test;
-
-import com.google.common.collect.ImmutableSet;
-import com.google.common.reflect.TypeToken;
-
-/**
- * Tests that OAuthApiMetadata is properly registered in ServiceLoader
- * <p/>
- * <pre>
- * META-INF/services/org.jclouds.apis.ApiMetadata
- * </pre>
- */
-@Test(groups = "unit")
-public class OAuthApiMetadataTest extends BaseApiMetadataTest {
-
-   public OAuthApiMetadataTest() {
-      super(new OAuthApiMetadata(), ImmutableSet.<TypeToken<? extends View>>of());
-   }
-}

http://git-wip-us.apache.org/repos/asf/jclouds/blob/46a7351a/apis/oauth/src/test/java/org/jclouds/oauth/v2/binders/TokenBinderTest.java
----------------------------------------------------------------------
diff --git a/apis/oauth/src/test/java/org/jclouds/oauth/v2/binders/TokenBinderTest.java b/apis/oauth/src/test/java/org/jclouds/oauth/v2/binders/TokenBinderTest.java
deleted file mode 100644
index 93042f4..0000000
--- a/apis/oauth/src/test/java/org/jclouds/oauth/v2/binders/TokenBinderTest.java
+++ /dev/null
@@ -1,85 +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.oauth.v2.binders;
-
-import static org.jclouds.oauth.v2.domain.Claims.EXPIRATION_TIME;
-import static org.jclouds.oauth.v2.domain.Claims.ISSUED_AT;
-import static org.testng.Assert.assertNotNull;
-import static org.testng.Assert.assertSame;
-import static org.testng.Assert.assertTrue;
-
-import java.io.IOException;
-import java.util.Map;
-
-import org.jclouds.http.HttpRequest;
-import org.jclouds.json.config.GsonModule;
-import org.jclouds.oauth.v2.domain.Header;
-import org.jclouds.oauth.v2.domain.TokenRequest;
-import org.jclouds.util.Strings2;
-import org.testng.annotations.Test;
-
-import com.google.common.base.Function;
-import com.google.common.base.Functions;
-import com.google.common.base.Splitter;
-import com.google.common.base.Supplier;
-import com.google.common.base.Suppliers;
-import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.Iterables;
-import com.google.inject.Binder;
-import com.google.inject.Guice;
-import com.google.inject.Module;
-import com.google.inject.Provides;
-
-@Test(groups = "unit", testName = "OAuthTokenBinderTest")
-public class TokenBinderTest {
-   public static final String STRING_THAT_GENERATES_URL_UNSAFE_BASE64_ENCODING = "§1234567890'+±!\"#$%&/()" +
-         "=?*qwertyuiopº´WERTYUIOPªàsdfghjklç~ASDFGHJKLÇ^<zxcvbnm,.->ZXCVBNM;:_@€";
-
-   public void testPayloadIsUrlSafe() throws IOException {
-      Header header = Header.create("a", "b");
-
-      Map<String, Object> claims = ImmutableMap.<String, Object>builder()
-            .put(ISSUED_AT, 0)
-            .put(EXPIRATION_TIME, 0)
-            .put("ist", STRING_THAT_GENERATES_URL_UNSAFE_BASE64_ENCODING).build();
-
-      TokenRequest tokenRequest = TokenRequest.create(header, claims);
-      HttpRequest request = tokenBinder.bindToRequest(
-            HttpRequest.builder().method("GET").endpoint("http://localhost").build(), tokenRequest);
-
-      assertNotNull(request.getPayload());
-
-      String payload = Strings2.toStringAndClose(request.getPayload().getInput());
-
-      // make sure the paylod is in the format {header}.{claims}.{signature}
-      Iterable<String> parts = Splitter.on(".").split(payload);
-
-      assertSame(Iterables.size(parts), 3);
-
-      assertTrue(!payload.contains("+"));
-      assertTrue(!payload.contains("/"));
-   }
-
-   private final TokenBinder tokenBinder = Guice.createInjector(new GsonModule(), new Module() {
-      @Override public void configure(Binder binder) {
-      }
-
-      @Provides Supplier<Function<byte[], byte[]>> signer() {
-         return (Supplier) Suppliers.ofInstance(Functions.constant(null));
-      }
-   }).getInstance(TokenBinder.class);
-}

http://git-wip-us.apache.org/repos/asf/jclouds/blob/46a7351a/apis/oauth/src/test/java/org/jclouds/oauth/v2/config/PrivateKeySupplierTest.java
----------------------------------------------------------------------
diff --git a/apis/oauth/src/test/java/org/jclouds/oauth/v2/config/PrivateKeySupplierTest.java b/apis/oauth/src/test/java/org/jclouds/oauth/v2/config/PrivateKeySupplierTest.java
new file mode 100644
index 0000000..088c902
--- /dev/null
+++ b/apis/oauth/src/test/java/org/jclouds/oauth/v2/config/PrivateKeySupplierTest.java
@@ -0,0 +1,67 @@
+/*
+ * 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.oauth.v2.config;
+
+import static com.google.common.base.Suppliers.ofInstance;
+import static org.testng.Assert.assertNotNull;
+
+import java.io.File;
+import java.security.PrivateKey;
+import java.util.Properties;
+
+import org.jclouds.domain.Credentials;
+import org.jclouds.oauth.v2.OAuthTestUtils;
+import org.jclouds.oauth.v2.config.PrivateKeySupplier.PrivateKeyForCredentials;
+import org.jclouds.rest.AuthorizationException;
+import org.testng.annotations.Test;
+
+import com.google.common.base.Charsets;
+import com.google.common.base.Suppliers;
+import com.google.common.io.Files;
+
+@Test(groups = "unit")
+public class PrivateKeySupplierTest {
+
+   /** Test loading the credentials by extracting a pk from a PKCS12 keystore. */
+   public void testLoadPKString() throws Exception {
+      assertNotNull(loadPrivateKey());
+   }
+
+   @Test(expectedExceptions = AuthorizationException.class)
+   public void testAuthorizationExceptionIsThrownOnBadKeys() {
+      PrivateKeySupplier supplier = new PrivateKeySupplier(
+            Suppliers.ofInstance(new Credentials("MOMMA", "FileNotFoundCredential")),
+            new PrivateKeyForCredentials());
+      supplier.get();
+   }
+
+   public void testCredentialsAreLoadedOnRightAlgoAndCredentials() {
+      Properties propertied = OAuthTestUtils.defaultProperties(new Properties());
+      Credentials validCredentials = new Credentials(propertied.getProperty("oauth.identity"),
+              propertied.getProperty("oauth.credential"));
+      PrivateKeySupplier supplier = new PrivateKeySupplier(Suppliers.ofInstance(validCredentials),
+            new PrivateKeyForCredentials());
+      assertNotNull(supplier.get());
+   }
+
+   public static PrivateKey loadPrivateKey() throws Exception {
+      PrivateKeySupplier supplier = new PrivateKeySupplier(ofInstance(new Credentials("foo",
+            Files.asCharSource(new File("src/test/resources/testpk.pem"), Charsets.UTF_8).read())),
+            new PrivateKeyForCredentials());
+      return supplier.get();
+   }
+}

http://git-wip-us.apache.org/repos/asf/jclouds/blob/46a7351a/apis/oauth/src/test/java/org/jclouds/oauth/v2/features/OAuthApiLiveTest.java
----------------------------------------------------------------------
diff --git a/apis/oauth/src/test/java/org/jclouds/oauth/v2/features/OAuthApiLiveTest.java b/apis/oauth/src/test/java/org/jclouds/oauth/v2/features/OAuthApiLiveTest.java
deleted file mode 100644
index cc83f8b..0000000
--- a/apis/oauth/src/test/java/org/jclouds/oauth/v2/features/OAuthApiLiveTest.java
+++ /dev/null
@@ -1,84 +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.oauth.v2.features;
-
-import static com.google.common.base.Preconditions.checkState;
-import static org.jclouds.oauth.v2.OAuthTestUtils.getMandatoryProperty;
-import static org.jclouds.oauth.v2.config.OAuthProperties.AUDIENCE;
-import static org.jclouds.oauth.v2.config.OAuthProperties.JWS_ALG;
-import static org.jclouds.oauth.v2.domain.Claims.EXPIRATION_TIME;
-import static org.jclouds.oauth.v2.domain.Claims.ISSUED_AT;
-import static org.testng.Assert.assertNotNull;
-import static org.testng.Assert.assertTrue;
-
-import java.util.Map;
-import java.util.Properties;
-
-import org.jclouds.oauth.v2.JWSAlgorithms;
-import org.jclouds.oauth.v2.domain.Header;
-import org.jclouds.oauth.v2.domain.Token;
-import org.jclouds.oauth.v2.domain.TokenRequest;
-import org.jclouds.oauth.v2.internal.BaseOAuthApiLiveTest;
-import org.testng.annotations.Test;
-
-import com.google.common.collect.ImmutableMap;
-
-/**
- * A live test for authentication. Requires the following properties to be set:
- * - test.oauth.endpoint
- * - test.oauth.identity
- * - test.oauth.credential
- * - test.jclouds.oauth.audience
- * - test.jclouds.oauth.scopes
- * - test.jclouds.oauth.jws-alg
- */
-@Test(groups = "live", singleThreaded = true)
-public class OAuthApiLiveTest extends BaseOAuthApiLiveTest {
-
-   private Properties properties;
-
-   @Override
-   protected Properties setupProperties() {
-      properties = super.setupProperties();
-      return properties;
-   }
-
-   @Test(groups = "live", singleThreaded = true)
-   public void testAuthenticateJWTToken() throws Exception {
-      assertTrue(properties != null, "properties were not set");
-      String jwsAlg = getMandatoryProperty(properties, JWS_ALG);
-      checkState(JWSAlgorithms.supportedAlgs().contains(jwsAlg), "Algorithm not supported: %s", jwsAlg);
-
-      Header header = Header.create(jwsAlg, "JWT");
-
-      String audience = getMandatoryProperty(properties, AUDIENCE);
-
-      long now = System.currentTimeMillis() / 1000;
-
-      Map<String, Object> claims = ImmutableMap.<String, Object>builder()
-         .put("iss", identity)
-         .put("scope", scope)
-         .put("aud", audience)
-         .put(EXPIRATION_TIME, now + 3600)
-         .put(ISSUED_AT, now).build();
-
-      TokenRequest tokenRequest = TokenRequest.create(header, claims);
-      Token token = api.authenticate(tokenRequest);
-
-      assertNotNull(token, "no token when authenticating " + tokenRequest);
-   }
-}

http://git-wip-us.apache.org/repos/asf/jclouds/blob/46a7351a/apis/oauth/src/test/java/org/jclouds/oauth/v2/features/OAuthApiMockTest.java
----------------------------------------------------------------------
diff --git a/apis/oauth/src/test/java/org/jclouds/oauth/v2/features/OAuthApiMockTest.java b/apis/oauth/src/test/java/org/jclouds/oauth/v2/features/OAuthApiMockTest.java
deleted file mode 100644
index febaee7..0000000
--- a/apis/oauth/src/test/java/org/jclouds/oauth/v2/features/OAuthApiMockTest.java
+++ /dev/null
@@ -1,126 +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.oauth.v2.features;
-
-import static com.google.common.base.Charsets.UTF_8;
-import static com.google.common.io.BaseEncoding.base64Url;
-import static com.google.common.util.concurrent.MoreExecutors.sameThreadExecutor;
-import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
-import static org.jclouds.Constants.PROPERTY_MAX_RETRIES;
-import static org.jclouds.oauth.v2.config.OAuthProperties.AUDIENCE;
-import static org.jclouds.oauth.v2.domain.Claims.EXPIRATION_TIME;
-import static org.jclouds.oauth.v2.domain.Claims.ISSUED_AT;
-import static org.jclouds.util.Strings2.toStringAndClose;
-import static org.testng.Assert.assertEquals;
-
-import java.io.IOException;
-import java.net.URL;
-import java.util.Map;
-import java.util.Properties;
-
-import org.jclouds.ContextBuilder;
-import org.jclouds.concurrent.config.ExecutorServiceModule;
-import org.jclouds.oauth.v2.OAuthApi;
-import org.jclouds.oauth.v2.OAuthApiMetadata;
-import org.jclouds.oauth.v2.OAuthTestUtils;
-import org.jclouds.oauth.v2.config.OAuthScopes;
-import org.jclouds.oauth.v2.config.OAuthScopes.SingleScope;
-import org.jclouds.oauth.v2.domain.Header;
-import org.jclouds.oauth.v2.domain.Token;
-import org.jclouds.oauth.v2.domain.TokenRequest;
-import org.testng.annotations.Test;
-
-import com.google.common.base.Joiner;
-import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.ImmutableSet;
-import com.google.common.io.BaseEncoding;
-import com.google.inject.Binder;
-import com.google.inject.Module;
-import com.squareup.okhttp.mockwebserver.MockResponse;
-import com.squareup.okhttp.mockwebserver.MockWebServer;
-import com.squareup.okhttp.mockwebserver.RecordedRequest;
-
-@Test(groups = "unit", testName = "OAuthApiMockTest")
-public class OAuthApiMockTest {
-   private static final String SCOPE = "https://www.googleapis.com/auth/prediction";
-
-   private static final String header = "{\"alg\":\"RS256\",\"typ\":\"JWT\"}";
-
-   private static final String claims = "{\"iss\":\"761326798069-r5mljlln1rd4lrbhg75efgigp36m78j5@developer" +
-         ".gserviceaccount.com\",\"scope\":\"" + SCOPE + "\",\"aud\":\"https://accounts.google" +
-         ".com/o/oauth2/token\",\"exp\":1328573381,\"iat\":1328569781}";
-
-   private static final Token TOKEN = Token.create("1/8xbJqaOZXSUZbHLl5EOtu1pxz3fmmetKx9W8CV4t79M", "Bearer", 3600);
-
-   private static final Map<String, Object> CLAIMS = ImmutableMap.<String, Object>builder()
-         .put("iss", "761326798069-r5mljlln1rd4lrbhg75efgigp36m78j5@developer.gserviceaccount.com")
-         .put("scope", SCOPE)
-         .put("aud", "https://accounts.google.com/o/oauth2/token")
-         .put(EXPIRATION_TIME, 1328573381)
-         .put(ISSUED_AT, 1328569781).build();
-
-   private static final Header HEADER = Header.create("RS256", "JWT");
-
-   public void testGenerateJWTRequest() throws Exception {
-      MockWebServer server = new MockWebServer();
-      server.enqueue(new MockResponse().setBody("{\n" +
-                  "  \"access_token\" : \"1/8xbJqaOZXSUZbHLl5EOtu1pxz3fmmetKx9W8CV4t79M\",\n" +
-                  "  \"token_type\" : \"Bearer\",\n" +
-                  "  \"expires_in\" : 3600\n" +
-                  "}"));
-      server.play();
-
-      OAuthApi api = api(server.getUrl("/"));
-
-      assertEquals(api.authenticate(TokenRequest.create(HEADER, CLAIMS)), TOKEN);
-
-      RecordedRequest request = server.takeRequest();
-      assertEquals(request.getMethod(), "POST");
-      assertEquals(request.getHeader("Accept"), APPLICATION_JSON);
-      assertEquals(request.getHeader("Content-Type"), "application/x-www-form-urlencoded");
-
-      assertEquals(new String(request.getBody(), UTF_8), //
-            "grant_type=urn%3Aietf%3Aparams%3Aoauth%3Agrant-type%3Ajwt-bearer&" +
-                  // Base64 Encoded Header
-                  "assertion=" +
-                  Joiner.on('.').join(encoding.encode(header.getBytes(UTF_8)), encoding.encode(claims.getBytes(UTF_8)),
-                  // Base64 encoded {header}.{claims} signature (using SHA256)
-                  "W2Lesr_98AzVYiMbzxFqmwcOjpIWlwqkC6pNn1fXND9oSDNNnFhy-AAR6DKH-x9ZmxbY80" +
-                  "R5fH-OCeWumXlVgceKN8Z2SmgQsu8ElTpypQA54j_5j8vUImJ5hsOUYPeyF1U2BUzZ3L5g" +
-                  "03PXBA0YWwRU9E1ChH28dQBYuGiUmYw"));
-
-   }
-
-   private final BaseEncoding encoding = base64Url().omitPadding();
-
-   private OAuthApi api(URL url) throws IOException {
-      Properties overrides = new Properties();
-      overrides.put(AUDIENCE, "https://accounts.google.com/o/oauth2/token");
-      overrides.put(PROPERTY_MAX_RETRIES, "1");
-
-      return ContextBuilder.newBuilder(new OAuthApiMetadata())
-            .credentials("foo", toStringAndClose(OAuthTestUtils.class.getResourceAsStream("/testpk.pem")))
-            .endpoint(url.toString())
-            .overrides(overrides)
-            .modules(ImmutableSet.of(new ExecutorServiceModule(sameThreadExecutor()), new Module() {
-               @Override public void configure(Binder binder) {
-                  binder.bind(OAuthScopes.class).toInstance(SingleScope.create(SCOPE));
-               }
-            }))
-            .buildApi(OAuthApi.class);
-   }
-}

http://git-wip-us.apache.org/repos/asf/jclouds/blob/46a7351a/apis/oauth/src/test/java/org/jclouds/oauth/v2/functions/ClaimsToAssertionTest.java
----------------------------------------------------------------------
diff --git a/apis/oauth/src/test/java/org/jclouds/oauth/v2/functions/ClaimsToAssertionTest.java b/apis/oauth/src/test/java/org/jclouds/oauth/v2/functions/ClaimsToAssertionTest.java
new file mode 100644
index 0000000..bff9ed0
--- /dev/null
+++ b/apis/oauth/src/test/java/org/jclouds/oauth/v2/functions/ClaimsToAssertionTest.java
@@ -0,0 +1,48 @@
+/*
+ * 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.oauth.v2.functions;
+
+import static com.google.common.base.Charsets.UTF_8;
+import static com.google.common.io.BaseEncoding.base64Url;
+import static org.jclouds.oauth.v2.config.PrivateKeySupplierTest.loadPrivateKey;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNotNull;
+
+import org.testng.annotations.Test;
+
+@Test(groups = "unit")
+public class ClaimsToAssertionTest {
+
+   private static final String PAYLOAD = "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.\n" +
+           "eyJpc3MiOiI3NjEzMjY3OTgwNjktcjVtbGpsbG4xcmQ0bHJiaGc3NWVmZ2lncDM2bTc4ajVAZ" +
+           "GV2ZWxvcGVyLmdzZXJ2aWNlYWNjb3VudC5jb20iLCJzY29wZSI6Imh0dHBzOi8vd3d3Lmdvb2ds" +
+           "ZWFwaXMuY29tL2F1dGgvcHJlZGljdGlvbiIsImF1ZCI6Imh0dHBzOi8vYWNjb3VudHMuZ29vZ2x" +
+           "lLmNvbS9vL29hdXRoMi90b2tlbiIsImV4cCI6MTMyODU1NDM4NSwiaWF0IjoxMzI4NTUwNzg1fQ";
+
+   private static final String SHA256withRSA_PAYLOAD_SIGNATURE_RESULT =
+           "bmQrCv4gjkLWDK1JNJni74_kPiSDUMF_FImgqKJMUIgkDX1m2Sg3bH1yjF-cjBN7CvfAscnageo" +
+                   "GtL2TGbwoTjJgUO5Yy0esavUUF-mBQHQtSw-2nL-9TNyM4SNi6fHPbgr83GGKOgA86r" +
+                   "I9-nj3oUGd1fQty2k4Lsd-Zdkz6es";
+
+
+   public void sha256() throws Exception {
+      byte[] payloadSignature = ClaimsToAssertion.sha256(loadPrivateKey(), PAYLOAD.getBytes(UTF_8));
+      assertNotNull(payloadSignature);
+
+      assertEquals(base64Url().omitPadding().encode(payloadSignature), SHA256withRSA_PAYLOAD_SIGNATURE_RESULT);
+   }
+}

http://git-wip-us.apache.org/repos/asf/jclouds/blob/46a7351a/apis/oauth/src/test/java/org/jclouds/oauth/v2/functions/PrivateKeySupplierTest.java
----------------------------------------------------------------------
diff --git a/apis/oauth/src/test/java/org/jclouds/oauth/v2/functions/PrivateKeySupplierTest.java b/apis/oauth/src/test/java/org/jclouds/oauth/v2/functions/PrivateKeySupplierTest.java
deleted file mode 100644
index 48d9209..0000000
--- a/apis/oauth/src/test/java/org/jclouds/oauth/v2/functions/PrivateKeySupplierTest.java
+++ /dev/null
@@ -1,83 +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.oauth.v2.functions;
-
-import static com.google.common.base.Suppliers.ofInstance;
-import static org.jclouds.oauth.v2.functions.PrivateKeySupplier.PrivateKeyForCredentials;
-import static org.testng.Assert.assertNotNull;
-
-import java.io.File;
-import java.io.IOException;
-import java.security.KeyStoreException;
-import java.security.NoSuchAlgorithmException;
-import java.security.PrivateKey;
-import java.security.UnrecoverableKeyException;
-import java.security.cert.CertificateException;
-import java.security.spec.InvalidKeySpecException;
-import java.util.Properties;
-
-import org.jclouds.domain.Credentials;
-import org.jclouds.oauth.v2.OAuthTestUtils;
-import org.jclouds.rest.AuthorizationException;
-import org.testng.annotations.Test;
-
-import com.google.common.base.Charsets;
-import com.google.common.base.Suppliers;
-import com.google.common.io.Files;
-
-@Test(groups = "unit")
-public class PrivateKeySupplierTest {
-
-   /** Test loading the credentials by extracting a pk from a PKCS12 keystore. */
-   public void testLoadPKString() throws IOException, NoSuchAlgorithmException, KeyStoreException, CertificateException,
-         UnrecoverableKeyException, InvalidKeySpecException {
-      assertNotNull(loadPrivateKey());
-   }
-
-   @Test(expectedExceptions = AuthorizationException.class)
-   public void testAuthorizationExceptionIsThrownOnBadKeys() {
-      PrivateKeySupplier supplier = new PrivateKeySupplier(
-            Suppliers.ofInstance(new Credentials("MOMMA", "FileNotFoundCredential")),
-            new PrivateKeyForCredentials("RS256"));
-      supplier.get();
-   }
-
-   @Test(expectedExceptions = AuthorizationException.class)
-   public void testGSEChildExceptionsPropagateAsAuthorizationException() {
-      PrivateKeySupplier supplier = new PrivateKeySupplier(Suppliers.ofInstance(new Credentials("MOMMA", "MIA")),
-            new PrivateKeyForCredentials("MOMMA"));
-      supplier.get();
-   }
-
-   public void testCredentialsAreLoadedOnRightAlgoAndCredentials() {
-      Properties propertied = OAuthTestUtils.defaultProperties(new Properties());
-      Credentials validCredentials = new Credentials(propertied.getProperty("oauth.identity"),
-              propertied.getProperty("oauth.credential"));
-      PrivateKeySupplier supplier = new PrivateKeySupplier(Suppliers.ofInstance(validCredentials),
-            new PrivateKeyForCredentials("RS256"));
-      assertNotNull(supplier.get());
-   }
-
-   public static PrivateKey loadPrivateKey()
-         throws IOException, NoSuchAlgorithmException, CertificateException, InvalidKeySpecException {
-      PrivateKeySupplier supplier = new PrivateKeySupplier(ofInstance(new Credentials("foo",
-            Files.asCharSource(new File("src/test/resources/testpk.pem"), Charsets.UTF_8).read())),
-            new PrivateKeyForCredentials("RS256"));
-      return supplier.get();
-   }
-
-}

http://git-wip-us.apache.org/repos/asf/jclouds/blob/46a7351a/apis/oauth/src/test/java/org/jclouds/oauth/v2/functions/SignerFunctionTest.java
----------------------------------------------------------------------
diff --git a/apis/oauth/src/test/java/org/jclouds/oauth/v2/functions/SignerFunctionTest.java b/apis/oauth/src/test/java/org/jclouds/oauth/v2/functions/SignerFunctionTest.java
deleted file mode 100644
index a1c8a85..0000000
--- a/apis/oauth/src/test/java/org/jclouds/oauth/v2/functions/SignerFunctionTest.java
+++ /dev/null
@@ -1,56 +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.oauth.v2.functions;
-import static com.google.common.base.Charsets.UTF_8;
-import static com.google.common.base.Suppliers.ofInstance;
-import static com.google.common.io.BaseEncoding.base64Url;
-import static org.testng.Assert.assertNotNull;
-import static org.testng.AssertJUnit.assertEquals;
-
-import java.io.IOException;
-import java.security.InvalidKeyException;
-import java.security.NoSuchAlgorithmException;
-import java.security.cert.CertificateException;
-import java.security.spec.InvalidKeySpecException;
-
-import org.testng.annotations.Test;
-
-@Test(groups = "unit")
-public class SignerFunctionTest {
-
-   private static final String PAYLOAD = "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.\n" +
-           "eyJpc3MiOiI3NjEzMjY3OTgwNjktcjVtbGpsbG4xcmQ0bHJiaGc3NWVmZ2lncDM2bTc4ajVAZ" +
-           "GV2ZWxvcGVyLmdzZXJ2aWNlYWNjb3VudC5jb20iLCJzY29wZSI6Imh0dHBzOi8vd3d3Lmdvb2ds" +
-           "ZWFwaXMuY29tL2F1dGgvcHJlZGljdGlvbiIsImF1ZCI6Imh0dHBzOi8vYWNjb3VudHMuZ29vZ2x" +
-           "lLmNvbS9vL29hdXRoMi90b2tlbiIsImV4cCI6MTMyODU1NDM4NSwiaWF0IjoxMzI4NTUwNzg1fQ";
-
-   private static final String SHA256withRSA_PAYLOAD_SIGNATURE_RESULT =
-           "bmQrCv4gjkLWDK1JNJni74_kPiSDUMF_FImgqKJMUIgkDX1m2Sg3bH1yjF-cjBN7CvfAscnageo" +
-                   "GtL2TGbwoTjJgUO5Yy0esavUUF-mBQHQtSw-2nL-9TNyM4SNi6fHPbgr83GGKOgA86r" +
-                   "I9-nj3oUGd1fQty2k4Lsd-Zdkz6es";
-
-
-   public void testSignPayload() throws InvalidKeyException, IOException, NoSuchAlgorithmException,
-           CertificateException, InvalidKeySpecException {
-      SignOrProduceMacForToken signer = new SignOrProduceMacForToken("RS256",
-            ofInstance(PrivateKeySupplierTest.loadPrivateKey()));
-      byte[] payloadSignature = signer.get().apply(PAYLOAD.getBytes(UTF_8));
-      assertNotNull(payloadSignature);
-
-      assertEquals(base64Url().omitPadding().encode(payloadSignature), SHA256withRSA_PAYLOAD_SIGNATURE_RESULT);
-   }
-}

http://git-wip-us.apache.org/repos/asf/jclouds/blob/46a7351a/apis/oauth/src/test/java/org/jclouds/oauth/v2/handlers/OAuthErrorHandlerTest.java
----------------------------------------------------------------------
diff --git a/apis/oauth/src/test/java/org/jclouds/oauth/v2/handlers/OAuthErrorHandlerTest.java b/apis/oauth/src/test/java/org/jclouds/oauth/v2/handlers/OAuthErrorHandlerTest.java
deleted file mode 100644
index c3a61fe..0000000
--- a/apis/oauth/src/test/java/org/jclouds/oauth/v2/handlers/OAuthErrorHandlerTest.java
+++ /dev/null
@@ -1,92 +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.oauth.v2.handlers;
-
-import static org.easymock.EasyMock.createMock;
-import static org.easymock.EasyMock.expect;
-import static org.easymock.EasyMock.replay;
-import static org.easymock.EasyMock.reportMatcher;
-import static org.easymock.EasyMock.verify;
-
-import java.net.URI;
-
-import org.easymock.IArgumentMatcher;
-import org.jclouds.http.HttpCommand;
-import org.jclouds.http.HttpRequest;
-import org.jclouds.http.HttpResponse;
-import org.testng.annotations.Test;
-
-@Test(groups = "unit")
-public class OAuthErrorHandlerTest {
-
-   @Test
-   public void test409MakesIllegalStateException() {
-      assertCodeMakes(
-              "POST",
-              URI.create("http://oauth.org"),
-              409,
-              "HTTP/1.1 409 Conflict",
-              "\"{\"code\":\"InvalidState\",\"message\":\"An incompatible transition has already been queued for this" +
-                      " resource\"}\"",
-              IllegalStateException.class);
-   }
-
-   private void assertCodeMakes(String method, URI uri, int statusCode, String message, String content,
-                                Class<? extends Exception> expected) {
-      assertCodeMakes(method, uri, statusCode, message, "application/json", content, expected);
-   }
-
-   private void assertCodeMakes(String method, URI uri, int statusCode, String message, String contentType,
-                                String content, Class<? extends Exception> expected) {
-
-      OAuthErrorHandler function = new OAuthErrorHandler();
-
-      HttpCommand command = createMock(HttpCommand.class);
-      HttpRequest request = HttpRequest.builder().method(method).endpoint(uri).build();
-      HttpResponse response = HttpResponse.builder().statusCode(statusCode).message(message).payload(content).build();
-      response.getPayload().getContentMetadata().setContentType(contentType);
-
-      expect(command.getCurrentRequest()).andReturn(request).atLeastOnce();
-      command.setException(classEq(expected));
-
-      replay(command);
-
-      function.handleError(command, response);
-
-      verify(command);
-   }
-
-   public static Exception classEq(final Class<? extends Exception> in) {
-      reportMatcher(new IArgumentMatcher() {
-
-         @Override
-         public void appendTo(StringBuffer buffer) {
-            buffer.append("classEq(");
-            buffer.append(in);
-            buffer.append(")");
-         }
-
-         @Override
-         public boolean matches(Object arg) {
-            return arg.getClass() == in;
-         }
-
-      });
-      return null;
-   }
-
-}

http://git-wip-us.apache.org/repos/asf/jclouds/blob/46a7351a/apis/oauth/src/test/java/org/jclouds/oauth/v2/internal/Base64UrlSafeTest.java
----------------------------------------------------------------------
diff --git a/apis/oauth/src/test/java/org/jclouds/oauth/v2/internal/Base64UrlSafeTest.java b/apis/oauth/src/test/java/org/jclouds/oauth/v2/internal/Base64UrlSafeTest.java
deleted file mode 100644
index f6d938a..0000000
--- a/apis/oauth/src/test/java/org/jclouds/oauth/v2/internal/Base64UrlSafeTest.java
+++ /dev/null
@@ -1,40 +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.oauth.v2.internal;
-
-import static com.google.common.base.Charsets.UTF_8;
-import static com.google.common.io.BaseEncoding.base64Url;
-import static org.testng.Assert.assertTrue;
-
-import org.testng.annotations.Test;
-
-/**
- * Tests that the Base64 implementations used to Base64 encode the tokens are Url safe.
- */
-@Test(groups = "unit")
-public class Base64UrlSafeTest {
-
-   public static final String STRING_THAT_GENERATES_URL_UNSAFE_BASE64_ENCODING = "§1234567890'+±!\"#$%&/()"
-         + "=?*qwertyuiopº´WERTYUIOPªàsdfghjklç~ASDFGHJKLÇ^<zxcvbnm,.->ZXCVBNM;:_@€";
-
-   public void testUsedBase64IsUrlSafe() {
-      String encoded = base64Url().omitPadding().encode(STRING_THAT_GENERATES_URL_UNSAFE_BASE64_ENCODING.getBytes(UTF_8));
-      assertTrue(!encoded.contains("+"));
-      assertTrue(!encoded.contains("/"));
-      assertTrue(!encoded.endsWith("="));
-   }
-}

http://git-wip-us.apache.org/repos/asf/jclouds/blob/46a7351a/apis/oauth/src/test/java/org/jclouds/oauth/v2/internal/BaseOAuthApiLiveTest.java
----------------------------------------------------------------------
diff --git a/apis/oauth/src/test/java/org/jclouds/oauth/v2/internal/BaseOAuthApiLiveTest.java b/apis/oauth/src/test/java/org/jclouds/oauth/v2/internal/BaseOAuthApiLiveTest.java
deleted file mode 100644
index 2421d16..0000000
--- a/apis/oauth/src/test/java/org/jclouds/oauth/v2/internal/BaseOAuthApiLiveTest.java
+++ /dev/null
@@ -1,63 +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.oauth.v2.internal;
-
-import static com.google.common.base.Preconditions.checkNotNull;
-import static org.jclouds.oauth.v2.OAuthTestUtils.setCredential;
-import static org.jclouds.oauth.v2.config.OAuthProperties.AUDIENCE;
-import static org.jclouds.oauth.v2.config.OAuthProperties.JWS_ALG;
-import static org.jclouds.oauth.v2.config.OAuthScopes.SingleScope;
-
-import java.util.Properties;
-
-import org.jclouds.apis.BaseApiLiveTest;
-import org.jclouds.oauth.v2.OAuthApi;
-import org.jclouds.oauth.v2.config.OAuthScopes;
-import org.testng.annotations.Test;
-
-import com.google.common.collect.ImmutableList;
-import com.google.inject.Binder;
-import com.google.inject.Module;
-
-@Test(groups = "live")
-public class BaseOAuthApiLiveTest extends BaseApiLiveTest<OAuthApi> {
-
-   protected String scope;
-
-   public BaseOAuthApiLiveTest() {
-      provider = "oauth";
-   }
-
-   @Override protected Properties setupProperties() {
-      Properties props = super.setupProperties();
-      setCredential(props, "oauth.credential");
-      checkNotNull(setIfTestSystemPropertyPresent(props, "oauth.endpoint"), "test.oauth.endpoint must be set");
-      checkNotNull(setIfTestSystemPropertyPresent(props, AUDIENCE), "test.jclouds.oauth.audience must be set");
-      scope = setIfTestSystemPropertyPresent(props, "jclouds.oauth.scope");
-      setIfTestSystemPropertyPresent(props, JWS_ALG);
-      return props;
-   }
-
-   @Override protected Iterable<Module> setupModules() {
-      return ImmutableList.<Module>builder().add(new Module() {
-         @Override public void configure(Binder binder) {
-            binder.bind(OAuthScopes.class).toInstance(SingleScope.create(scope));
-         }
-      }).addAll(super.setupModules()).build();
-   }
-}
-

http://git-wip-us.apache.org/repos/asf/jclouds/blob/46a7351a/apis/oauth/src/test/java/org/jclouds/oauth/v2/internal/BaseOAuthAuthenticatedApiLiveTest.java
----------------------------------------------------------------------
diff --git a/apis/oauth/src/test/java/org/jclouds/oauth/v2/internal/BaseOAuthAuthenticatedApiLiveTest.java b/apis/oauth/src/test/java/org/jclouds/oauth/v2/internal/BaseOAuthAuthenticatedApiLiveTest.java
deleted file mode 100644
index 558d313..0000000
--- a/apis/oauth/src/test/java/org/jclouds/oauth/v2/internal/BaseOAuthAuthenticatedApiLiveTest.java
+++ /dev/null
@@ -1,112 +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.oauth.v2.internal;
-
-import static com.google.common.base.Preconditions.checkNotNull;
-import static com.google.common.base.Preconditions.checkState;
-import static java.util.concurrent.TimeUnit.MILLISECONDS;
-import static java.util.concurrent.TimeUnit.SECONDS;
-import static org.jclouds.oauth.v2.config.OAuthProperties.AUDIENCE;
-import static org.jclouds.oauth.v2.config.OAuthProperties.JWS_ALG;
-import static org.jclouds.oauth.v2.domain.Claims.EXPIRATION_TIME;
-import static org.jclouds.oauth.v2.domain.Claims.ISSUED_AT;
-import static org.testng.Assert.assertNotNull;
-
-import java.io.Closeable;
-import java.util.Map;
-import java.util.Properties;
-
-import org.jclouds.apis.BaseApiLiveTest;
-import org.jclouds.config.ValueOfConfigurationKeyOrNull;
-import org.jclouds.oauth.v2.JWSAlgorithms;
-import org.jclouds.oauth.v2.OAuthApi;
-import org.jclouds.oauth.v2.domain.Header;
-import org.jclouds.oauth.v2.domain.Token;
-import org.jclouds.oauth.v2.domain.TokenRequest;
-import org.testng.annotations.Test;
-
-import com.google.common.base.Function;
-import com.google.common.collect.ImmutableMap;
-import com.google.common.reflect.TypeToken;
-import com.google.inject.Injector;
-import com.google.inject.Key;
-import com.google.inject.Module;
-
-/**
- * A base test of oauth authenticated rest providers. Providers must set the following properties:
- * <p/>
- * - oauth.endpoint
- * - oauth.audience
- * - oauth.jws-alg
- * <p/>
- * - oauth.scopes is provided by the subclass
- * <p/>
- * This test asserts that a provider can authenticate with oauth for a given scope, or more simply
- * that authentication/authorization is working.
- */
-
-@Test(groups = "live")
-public abstract class BaseOAuthAuthenticatedApiLiveTest<A extends Closeable> extends BaseApiLiveTest<A> {
-
-   protected abstract String getScopes();
-
-   private OAuthApi oauthApi;
-
-   public void testAuthenticate() {
-      // obtain the necessary properties from the context
-      String jwsAlg = checkNotNull(propFunction.apply(JWS_ALG), JWS_ALG);
-
-      checkState(JWSAlgorithms.supportedAlgs().contains(jwsAlg), "Algorithm not supported: %s", jwsAlg);
-
-      String audience = checkNotNull(propFunction.apply(AUDIENCE), AUDIENCE);
-
-      // obtain the scopes from the subclass
-      String scopes = getScopes();
-
-      Header header = Header.create(jwsAlg, "JWT");
-
-      long now = SECONDS.convert(System.currentTimeMillis(), MILLISECONDS);
-
-      Map<String, Object> claims = ImmutableMap.<String, Object>builder()
-            .put("iss", identity)
-            .put("scope", scopes)
-            .put("aud", audience)
-            .put(EXPIRATION_TIME, now + 3600)
-            .put(ISSUED_AT, now).build();
-
-      TokenRequest tokenRequest = TokenRequest.create(header, claims);
-
-      Token token = oauthApi.authenticate(tokenRequest);
-
-      assertNotNull(token, "no token when authenticating " + tokenRequest);
-   }
-
-   @SuppressWarnings({ "unchecked", "serial" })
-   protected A create(Properties props, Iterable<Module> modules) {
-      Injector injector = newBuilder().modules(modules).overrides(props).buildInjector();
-      propFunction = injector.getInstance(ValueOfConfigurationKeyOrNull.class);
-      try {
-         oauthApi = injector.getInstance(OAuthApi.class);
-      } catch (Exception e) {
-         throw new IllegalStateException("Provider has no OAuthApi bound. Was the OAuthAuthenticationModule added?");
-      }
-      return (A) injector.getInstance(Key.get(new TypeToken<A>(getClass()) {
-      }.getType()));
-   }
-
-   private Function<String, String> propFunction;
-}

http://git-wip-us.apache.org/repos/asf/jclouds/blob/46a7351a/apis/oauth/src/test/java/org/jclouds/oauth/v2/parse/ParseTokenTest.java
----------------------------------------------------------------------
diff --git a/apis/oauth/src/test/java/org/jclouds/oauth/v2/parse/ParseTokenTest.java b/apis/oauth/src/test/java/org/jclouds/oauth/v2/parse/ParseTokenTest.java
deleted file mode 100644
index 416ec5e..0000000
--- a/apis/oauth/src/test/java/org/jclouds/oauth/v2/parse/ParseTokenTest.java
+++ /dev/null
@@ -1,40 +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.oauth.v2.parse;
-
-import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
-
-import javax.ws.rs.Consumes;
-
-import org.jclouds.json.BaseItemParserTest;
-import org.jclouds.oauth.v2.domain.Token;
-import org.testng.annotations.Test;
-
-@Test(groups = "unit", testName = "ParseTokenTest")
-public class ParseTokenTest extends BaseItemParserTest<Token> {
-
-   @Override
-   public String resource() {
-      return "/tokenResponse.json";
-   }
-
-   @Override
-   @Consumes(APPLICATION_JSON)
-   public Token expected() {
-      return Token.create("1/8xbJqaOZXSUZbHLl5EOtu1pxz3fmmetKx9W8CV4t79M", "Bearer", 3600);
-   }
-}

http://git-wip-us.apache.org/repos/asf/jclouds/blob/46a7351a/apis/oauth/src/test/resources/tokenResponse.json
----------------------------------------------------------------------
diff --git a/apis/oauth/src/test/resources/tokenResponse.json b/apis/oauth/src/test/resources/tokenResponse.json
deleted file mode 100644
index 6717a55..0000000
--- a/apis/oauth/src/test/resources/tokenResponse.json
+++ /dev/null
@@ -1,5 +0,0 @@
-{
-  "access_token" : "1/8xbJqaOZXSUZbHLl5EOtu1pxz3fmmetKx9W8CV4t79M",
-  "token_type" : "Bearer",
-  "expires_in" : 3600
-}
\ No newline at end of file