http://git-wip-us.apache.org/repos/asf/stratos/blob/3ddce9df/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/parse/ParseZoneTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/parse/ParseZoneTest.java b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/parse/ParseZoneTest.java new file mode 100644 index 0000000..48cdbfc --- /dev/null +++ b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/parse/ParseZoneTest.java @@ -0,0 +1,55 @@ +/* + * 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.googlecomputeengine.parse; + +import java.net.URI; + +import javax.ws.rs.Consumes; +import javax.ws.rs.core.MediaType; + +import org.jclouds.date.internal.SimpleDateFormatDateService; +import org.jclouds.googlecomputeengine.domain.Zone; +import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineParseTest; +import org.testng.annotations.Test; + +@Test(groups = "unit") +public class ParseZoneTest extends BaseGoogleComputeEngineParseTest<Zone> { + + @Override + public String resource() { + return "/zone_get.json"; + } + + @Override + @Consumes(MediaType.APPLICATION_JSON) + public Zone expected() { + return Zone.builder() + .id("13020128040171887099") + .creationTimestamp(new SimpleDateFormatDateService().iso8601DateParse("2012-10-19T16:42:54.131")) + .selfLink(URI.create("https://www.googleapis.com/compute/v1/projects/myproject/zones/us-central1-a")) + .name("us-central1-a") + .description("us-central1-a") + .status(Zone.Status.DOWN) + .addMaintenanceWindow(Zone.MaintenanceWindow.builder() + .name("2012-11-10-planned-outage") + .description("maintenance zone") + .beginTime(new SimpleDateFormatDateService().iso8601DateParse("2012-11-10T20:00:00.000")) + .endTime(new SimpleDateFormatDateService().iso8601DateParse("2012-12-02T20:00:00.000")) + .build()) + .build(); + } +}
http://git-wip-us.apache.org/repos/asf/stratos/blob/3ddce9df/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/predicates/NetworkFirewallPredicatesTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/predicates/NetworkFirewallPredicatesTest.java b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/predicates/NetworkFirewallPredicatesTest.java new file mode 100644 index 0000000..58ed81c --- /dev/null +++ b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/predicates/NetworkFirewallPredicatesTest.java @@ -0,0 +1,162 @@ +/* + * 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.googlecomputeengine.predicates; + +import static org.jclouds.googlecomputeengine.compute.functions.FirewallToIpPermissionTest.fwForTest; +import static org.jclouds.googlecomputeengine.predicates.NetworkFirewallPredicates.equalsIpPermission; +import static org.jclouds.googlecomputeengine.predicates.NetworkFirewallPredicates.hasPortRange; +import static org.jclouds.googlecomputeengine.predicates.NetworkFirewallPredicates.hasProtocol; +import static org.jclouds.googlecomputeengine.predicates.NetworkFirewallPredicates.hasSourceRange; +import static org.jclouds.googlecomputeengine.predicates.NetworkFirewallPredicates.hasSourceTag; +import static org.jclouds.googlecomputeengine.predicates.NetworkFirewallPredicates.providesIpPermission; +import static org.testng.Assert.assertFalse; +import static org.testng.Assert.assertTrue; + +import java.net.URI; +import java.util.Date; + +import org.jclouds.googlecomputeengine.domain.Firewall; +import org.jclouds.net.domain.IpPermission; +import org.jclouds.net.domain.IpProtocol; +import org.testng.annotations.Test; + +import com.google.common.collect.Range; + +@Test(groups = "unit") +public class NetworkFirewallPredicatesTest { + + public static Firewall getFwForTestSourceTags() { + Firewall.Builder builder = Firewall.builder(); + + builder.network(URI.create("https://www.googleapis.com/compute/v1/projects/myproject/global/networks/jclouds-test")); + builder.selfLink(URI.create("https://www.googleapis.com/compute/v1/projects/myproject/global/firewalls/jclouds-test")); + builder.addSourceTag("tag-1"); + builder.addAllowed(Firewall.Rule.builder().IpProtocol(IpProtocol.TCP) + .addPortRange(1, 10).build()); + builder.addAllowed(Firewall.Rule.builder().IpProtocol(IpProtocol.TCP) + .addPort(33).build()); + builder.addAllowed(Firewall.Rule.builder().IpProtocol(IpProtocol.ICMP).build()); + builder.id("abcd"); + builder.creationTimestamp(new Date()); + builder.name("jclouds-test"); + + return builder.build(); + } + + public static Firewall getFwForTestSourceTagsExact() { + Firewall.Builder builder = Firewall.builder(); + + builder.network(URI.create("https://www.googleapis.com/compute/v1/projects/myproject/global/networks/jclouds-test")); + builder.selfLink(URI.create("https://www.googleapis.com/compute/v1/projects/myproject/global/firewalls/jclouds-test")); + builder.addSourceTag("tag-1"); + builder.addAllowed(Firewall.Rule.builder().IpProtocol(IpProtocol.TCP) + .addPortRange(1, 10).build()); + builder.id("abcd"); + builder.creationTimestamp(new Date()); + builder.name("jclouds-test"); + + return builder.build(); + } + + @Test + public void testHasProtocol() { + assertTrue(hasProtocol(IpProtocol.TCP).apply(fwForTest()), + "Firewall " + fwForTest() + " should contain a TCP rule."); + } + + @Test + public void testHasProtocolFails() { + assertFalse(hasProtocol(IpProtocol.UDP).apply(fwForTest()), + "Firewall " + fwForTest() + " should NOT contain a UDP rule."); + } + + @Test + public void testHasPortRange() { + assertTrue(hasPortRange(Range.closed(2, 9)).apply(fwForTest()), + "Firewall " + fwForTest() + " should contain the port range 2-9."); + } + + @Test + public void testHasPortRangeFails() { + assertFalse(hasPortRange(Range.closed(11, 15)).apply(fwForTest()), + "Firewall " + fwForTest() + " should NOT contain the port range 11-15."); + } + + @Test + public void testHasSourceTag() { + assertTrue(hasSourceTag("tag-1").apply(getFwForTestSourceTags()), + "Firewall " + getFwForTestSourceTags() + " should contain the source tag 'tag-1'."); + } + + @Test + public void testHasSourceTagFails() { + assertFalse(hasSourceTag("tag-1").apply(fwForTest()), + "Firewall " + fwForTest() + " should NOT contain the source tag 'tag-1'."); + } + + @Test + public void testHasSourceRange() { + assertTrue(hasSourceRange("0.0.0.0/0").apply(fwForTest()), + "Firewall " + fwForTest() + " should contain the source range '0.0.0.0/0'."); + } + + @Test + public void testHasSourceRangeFails() { + assertFalse(hasSourceRange("0.0.0.0/0").apply(getFwForTestSourceTags()), + "Firewall " + getFwForTestSourceTags() + " should NOT contain the source range '0.0.0.0/0'."); + } + + @Test + public void testEqualsIpPermission() { + IpPermission perm = IpPermission.builder().groupId("tag-1") + .fromPort(1).toPort(10).ipProtocol(IpProtocol.TCP).build(); + + assertTrue(equalsIpPermission(perm).apply(getFwForTestSourceTagsExact()), + "Firewall " + getFwForTestSourceTagsExact() + " should match IpPermission " + perm + " but does not."); + } + + @Test + public void testEqualsIpPermissionFails() { + IpPermission perm = IpPermission.builder().groupId("tag-1") + .fromPort(1).toPort(10).ipProtocol(IpProtocol.TCP).build(); + + assertFalse(equalsIpPermission(perm).apply(getFwForTestSourceTags()), + "Firewall " + getFwForTestSourceTags() + " should not match IpPermission " + perm + " but does."); + } + + @Test + public void testProvidesIpPermission() { + IpPermission perm = IpPermission.builder().groupId("tag-1") + .fromPort(1).toPort(10).ipProtocol(IpProtocol.TCP).build(); + + assertTrue(providesIpPermission(perm).apply(getFwForTestSourceTagsExact()), + "Firewall " + getFwForTestSourceTagsExact() + " should provide IpPermission " + perm + " but does not."); + + assertTrue(providesIpPermission(perm).apply(getFwForTestSourceTags()), + "Firewall " + getFwForTestSourceTags() + " should inexactly provide IpPermission " + perm + " but does not."); + } + + @Test + public void testProvidesIpPermissionFails() { + IpPermission perm = IpPermission.builder().groupId("tag-1") + .fromPort(1).toPort(10).ipProtocol(IpProtocol.TCP).build(); + + assertFalse(providesIpPermission(perm).apply(fwForTest()), + "Firewall " + fwForTest() + " should not provide IpPermission " + perm + " but does."); + } +} + http://git-wip-us.apache.org/repos/asf/stratos/blob/3ddce9df/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/oauth/v2/OAuthApiMetadataTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/oauth/v2/OAuthApiMetadataTest.java b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/oauth/v2/OAuthApiMetadataTest.java new file mode 100644 index 0000000..d6ea17f --- /dev/null +++ b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/oauth/v2/OAuthApiMetadataTest.java @@ -0,0 +1,38 @@ +/* + * 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 com.google.common.collect.ImmutableSet; +import com.google.common.reflect.TypeToken; +import org.jclouds.View; +import org.jclouds.apis.internal.BaseApiMetadataTest; +import org.testng.annotations.Test; + +/** + * 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/stratos/blob/3ddce9df/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/oauth/v2/OAuthTestUtils.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/oauth/v2/OAuthTestUtils.java b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/oauth/v2/OAuthTestUtils.java new file mode 100644 index 0000000..901cdfe --- /dev/null +++ b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/oauth/v2/OAuthTestUtils.java @@ -0,0 +1,91 @@ +/* + * 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 com.google.common.base.Charsets; +import com.google.common.base.Throwables; +import com.google.common.io.Files; +import org.jclouds.oauth.v2.config.CredentialType; +import org.jclouds.oauth.v2.config.OAuthProperties; + +import java.io.File; +import java.io.IOException; +import java.util.Properties; + +import static com.google.common.base.Preconditions.checkNotNull; +import static org.jclouds.oauth.v2.config.OAuthProperties.AUDIENCE; + +/** + * Utils for OAuth tests. + */ +public class OAuthTestUtils { + + public static Properties defaultProperties(Properties properties) { + try { + properties = properties == null ? new Properties() : properties; + properties.put("oauth.identity", "foo"); + properties.put("oauth.credential", + Files.asCharSource(new File("src/test/resources/testpk.pem"), Charsets.UTF_8).read()); + properties.put("oauth.endpoint", "http://localhost:5000/o/oauth2/token"); + properties.put(AUDIENCE, "https://accounts.google.com/o/oauth2/token"); + return properties; + } catch (IOException e) { + throw Throwables.propagate(e); + } + } + + public static Properties bearerTokenAuthProperties(Properties properties) { + properties = properties == null ? new Properties() : properties; + properties.put("oauth.identity", "761326798069-r5mljlln1rd4lrbhg75efgigp36m7...@developer.gserviceaccount.com"); + properties.put("oauth.credential", "1/8xbJqaOZXSUZbHLl5EOtu1pxz3fmmetKx9W8CV4t79M"); + properties.put("oauth.endpoint", "http://localhost:5000/o/oauth2/token"); + properties.put(AUDIENCE, "https://accounts.google.com/o/oauth2/token"); + properties.put(OAuthProperties.CREDENTIAL_TYPE, CredentialType.BEARER_TOKEN_CREDENTIALS.toString()); + return properties; + } + + public static String setCredential(Properties overrides, String key) { + String val = null; + String credentialFromFile = null; + String testKey = "test." + key; + + if (System.getProperties().containsKey(testKey)) { + val = System.getProperty(testKey); + } + checkNotNull(val, String.format("the property %s must be set (pem private key file path or private key as a string)", testKey)); + + if (val.startsWith("-----BEGIN")) { + return val; + } + + try { + credentialFromFile = Files.toString(new File(val), Charsets.UTF_8); + } catch (IOException e) { + throw Throwables.propagate(e); + } + overrides.setProperty(key, credentialFromFile); + return credentialFromFile; + } + + public static String getMandatoryProperty(Properties properties, String key) { + checkNotNull(properties); + checkNotNull(key); + String value = properties.getProperty(key); + return checkNotNull(value, String.format("mandatory property %s or test.%s was not present", key, key)); + } + +} http://git-wip-us.apache.org/repos/asf/stratos/blob/3ddce9df/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/oauth/v2/features/OAuthApiExpectTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/oauth/v2/features/OAuthApiExpectTest.java b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/oauth/v2/features/OAuthApiExpectTest.java new file mode 100644 index 0000000..2008e5d --- /dev/null +++ b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/oauth/v2/features/OAuthApiExpectTest.java @@ -0,0 +1,99 @@ +/* + * 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 org.testng.Assert.assertEquals; + +import java.net.URI; +import java.util.Properties; + +import javax.ws.rs.core.MediaType; + +import org.jclouds.http.HttpRequest; +import org.jclouds.http.HttpResponse; +import org.jclouds.oauth.v2.OAuthApi; +import org.jclouds.oauth.v2.OAuthTestUtils; +import org.jclouds.oauth.v2.domain.ClaimSet; +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.BaseOAuthApiExpectTest; +import org.testng.annotations.Test; + +/** + * Tests that a token requess is well formed. + */ +@Test(groups = "unit") +public class OAuthApiExpectTest extends BaseOAuthApiExpectTest { + + private static final String header = "{\"alg\":\"RS256\",\"typ\":\"JWT\"}"; + + private static final String claims = "{\"iss\":\"761326798069-r5mljlln1rd4lrbhg75efgigp36m78j5@developer" + + ".gserviceaccount.com\"," + + "\"scope\":\"https://www.googleapis.com/auth/prediction\",\"aud\":\"https://accounts.google" + + ".com/o/oauth2/token\",\"exp\":1328573381,\"iat\":1328569781}"; + + private static final Token TOKEN = new Token.Builder().accessToken + ("1/8xbJqaOZXSUZbHLl5EOtu1pxz3fmmetKx9W8CV4t79M").tokenType("Bearer").expiresIn(3600).build(); + + private static final ClaimSet CLAIM_SET = new ClaimSet.Builder().addClaim("iss", + "761326798069-r5mljlln1rd4lrbhg75efgigp36m78j5@developer" + + ".gserviceaccount.com") + .addClaim("scope", "https://www.googleapis.com/auth/prediction") + .addClaim("aud", "https://accounts.google.com/o/oauth2/token") + .expirationTime(1328573381) + .emissionTime(1328569781).build(); + + private static final Header HEADER = new Header.Builder().signerAlgorithm("RS256").type("JWT").build(); + + private static final String URL_ENCODED_TOKEN_REQUEST = + "grant_type=urn%3Aietf%3Aparams%3Aoauth%3Agrant-type%3Ajwt-bearer&" + + // Base64 Encoded Header + "assertion=" + base64Url().omitPadding().encode(header.getBytes(UTF_8)) + "." + + // Base64 Encoded Claims + base64Url().omitPadding().encode(claims.getBytes(UTF_8)) + "." + + // Base64 encoded {header}.{claims} signature (using SHA256) + "W2Lesr_98AzVYiMbzxFqmwcOjpIWlwqkC6pNn1fXND9oSDNNnFhy-AAR6DKH-x9ZmxbY80" + + "R5fH-OCeWumXlVgceKN8Z2SmgQsu8ElTpypQA54j_5j8vUImJ5hsOUYPeyF1U2BUzZ3L5g" + + "03PXBA0YWwRU9E1ChH28dQBYuGiUmYw"; + + private static final HttpRequest TOKEN_REQUEST = HttpRequest.builder() + .method("POST") + .endpoint(URI.create("http://localhost:5000/o/oauth2/token")) + .addHeader("Accept", MediaType.APPLICATION_JSON) + .payload(payloadFromStringWithContentType(URL_ENCODED_TOKEN_REQUEST, "application/x-www-form-urlencoded")) + .build(); + + private static final HttpResponse TOKEN_RESPONSE = HttpResponse.builder().statusCode(200).payload( + payloadFromString("{\n" + + " \"access_token\" : \"1/8xbJqaOZXSUZbHLl5EOtu1pxz3fmmetKx9W8CV4t79M\",\n" + + " \"token_type\" : \"Bearer\",\n" + + " \"expires_in\" : 3600\n" + + "}")).build(); + + @Override + protected Properties setupProperties() { + return OAuthTestUtils.defaultProperties(super.setupProperties()); + } + + public void testGenerateJWTRequest() { + OAuthApi api = requestSendsResponse(TOKEN_REQUEST, TOKEN_RESPONSE); + assertEquals(api.authenticate(new TokenRequest(HEADER, CLAIM_SET)), TOKEN); + } +} http://git-wip-us.apache.org/repos/asf/stratos/blob/3ddce9df/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/oauth/v2/features/OAuthApiLiveTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/oauth/v2/features/OAuthApiLiveTest.java b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/oauth/v2/features/OAuthApiLiveTest.java new file mode 100644 index 0000000..4ac5950 --- /dev/null +++ b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/oauth/v2/features/OAuthApiLiveTest.java @@ -0,0 +1,80 @@ +/* + * 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.SCOPES; +import static org.jclouds.oauth.v2.config.OAuthProperties.SIGNATURE_OR_MAC_ALGORITHM; +import static org.testng.Assert.assertNotNull; +import static org.testng.Assert.assertTrue; + +import java.util.Properties; + +import org.jclouds.oauth.v2.OAuthConstants; +import org.jclouds.oauth.v2.domain.ClaimSet; +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; + +/** + * 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.signature-or-mac-algorithm + */ +@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 signatureAlgorithm = getMandatoryProperty(properties, SIGNATURE_OR_MAC_ALGORITHM); + checkState(OAuthConstants.OAUTH_ALGORITHM_NAMES_TO_SIGNATURE_ALGORITHM_NAMES.containsKey(signatureAlgorithm) + , String.format("Algorithm not supported: " + signatureAlgorithm)); + + Header header = Header.builder().signerAlgorithm(signatureAlgorithm).type("JWT").build(); + + String scopes = getMandatoryProperty(properties, SCOPES); + String audience = getMandatoryProperty(properties, AUDIENCE); + + long now = nowInSeconds(); + + ClaimSet claimSet = ClaimSet.builder().addClaim("aud", audience).addClaim("scope", scopes).addClaim("iss", + identity).emissionTime(now).expirationTime(now + 3600).build(); + + TokenRequest tokenRequest = TokenRequest.builder().header(header).claimSet(claimSet).build(); + Token token = api.authenticate(tokenRequest); + + assertNotNull(token, "no token when authenticating " + tokenRequest); + } +} http://git-wip-us.apache.org/repos/asf/stratos/blob/3ddce9df/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/oauth/v2/functions/OAuthCredentialsFromPKTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/oauth/v2/functions/OAuthCredentialsFromPKTest.java b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/oauth/v2/functions/OAuthCredentialsFromPKTest.java new file mode 100644 index 0000000..e3794d6 --- /dev/null +++ b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/oauth/v2/functions/OAuthCredentialsFromPKTest.java @@ -0,0 +1,61 @@ +/* + * 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.testng.Assert.assertEquals; +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.UnrecoverableKeyException; +import java.security.cert.CertificateException; +import java.security.spec.InvalidKeySpecException; + +import com.google.common.base.Charsets; +import com.google.common.io.Files; + +import org.jclouds.domain.Credentials; +import org.jclouds.oauth.v2.domain.OAuthCredentials; +import org.jclouds.oauth.v2.functions.OAuthCredentialsSupplier.OAuthCredentialsForCredentials; +import org.testng.annotations.Test; + +/** + * Test loading the credentials by extracting a pk from a PKCS12 keystore. + */ +@Test(groups = "unit") +public class OAuthCredentialsFromPKTest { + + public static OAuthCredentials loadOAuthCredentials() throws IOException, NoSuchAlgorithmException, + CertificateException, InvalidKeySpecException { + OAuthCredentialsSupplier loader = new OAuthCredentialsSupplier(ofInstance(new Credentials("foo", + Files.asCharSource(new File("src/test/resources/testpk.pem"), Charsets.UTF_8).read())), + new OAuthCredentialsForCredentials("RS256"), "RS256"); + return loader.get(); + } + + + public void testLoadPKString() throws IOException, NoSuchAlgorithmException, KeyStoreException, + CertificateException, UnrecoverableKeyException, InvalidKeySpecException { + OAuthCredentials creds = loadOAuthCredentials(); + assertNotNull(creds); + assertEquals(creds.identity, "foo"); + assertNotNull(creds.privateKey); + } +} http://git-wip-us.apache.org/repos/asf/stratos/blob/3ddce9df/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/oauth/v2/functions/OAuthCredentialsSupplierTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/oauth/v2/functions/OAuthCredentialsSupplierTest.java b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/oauth/v2/functions/OAuthCredentialsSupplierTest.java new file mode 100644 index 0000000..2b3d094 --- /dev/null +++ b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/oauth/v2/functions/OAuthCredentialsSupplierTest.java @@ -0,0 +1,55 @@ +/* + * 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 com.google.common.base.Suppliers; +import org.jclouds.domain.Credentials; +import org.jclouds.oauth.v2.OAuthTestUtils; +import org.jclouds.rest.AuthorizationException; +import org.testng.annotations.Test; + +import java.util.Properties; + +import static org.jclouds.oauth.v2.functions.OAuthCredentialsSupplier.OAuthCredentialsForCredentials; +import static org.testng.Assert.assertNotNull; + +@Test(groups = "unit") +public class OAuthCredentialsSupplierTest { + + @Test(expectedExceptions = AuthorizationException.class) + public void testAuthorizationExceptionIsThrownOnBadKeys() { + OAuthCredentialsSupplier supplier = new OAuthCredentialsSupplier(Suppliers.ofInstance(new Credentials("MOMMA", + "MIA")), new OAuthCredentialsForCredentials("RS256"), "RS256"); + supplier.get(); + } + + @Test(expectedExceptions = IllegalArgumentException.class) + public void testGSEChildExceptionsPropagateAsAuthorizationException() { + OAuthCredentialsSupplier supplier = new OAuthCredentialsSupplier(Suppliers.ofInstance(new Credentials("MOMMA", + "MIA")), new OAuthCredentialsForCredentials("MOMMA"), "MOMMA"); + supplier.get(); + } + + public void testCredentialsAreLoadedOnRightAlgoAndCredentials() { + Properties propertied = OAuthTestUtils.defaultProperties(new Properties()); + Credentials validCredentials = new Credentials(propertied.getProperty("oauth.identity"), + propertied.getProperty("oauth.credential")); + OAuthCredentialsSupplier supplier = new OAuthCredentialsSupplier(Suppliers.ofInstance(validCredentials), + new OAuthCredentialsForCredentials("RS256"), "RS256"); + assertNotNull(supplier.get()); + } +} http://git-wip-us.apache.org/repos/asf/stratos/blob/3ddce9df/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/oauth/v2/functions/SignerFunctionTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/oauth/v2/functions/SignerFunctionTest.java b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/oauth/v2/functions/SignerFunctionTest.java new file mode 100644 index 0000000..2a64822 --- /dev/null +++ b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/oauth/v2/functions/SignerFunctionTest.java @@ -0,0 +1,61 @@ +/* + * 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; + +/** + * Tests the SignOrProduceMacForToken + */ +@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(OAuthCredentialsFromPKTest + .loadOAuthCredentials())); + signer.loadSignatureOrMacOrNone(); + byte[] payloadSignature = signer.apply(PAYLOAD.getBytes(UTF_8)); + assertNotNull(payloadSignature); + + assertEquals(base64Url().omitPadding().encode(payloadSignature), SHA256withRSA_PAYLOAD_SIGNATURE_RESULT); + } +} http://git-wip-us.apache.org/repos/asf/stratos/blob/3ddce9df/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/oauth/v2/handlers/OAuthErrorHandlerTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/oauth/v2/handlers/OAuthErrorHandlerTest.java b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/oauth/v2/handlers/OAuthErrorHandlerTest.java new file mode 100644 index 0000000..255c5c7 --- /dev/null +++ b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/oauth/v2/handlers/OAuthErrorHandlerTest.java @@ -0,0 +1,92 @@ +/* + * 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 org.easymock.IArgumentMatcher; +import org.jclouds.http.HttpCommand; +import org.jclouds.http.HttpRequest; +import org.jclouds.http.HttpResponse; +import org.testng.annotations.Test; + +import java.net.URI; + +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; + +@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/stratos/blob/3ddce9df/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/oauth/v2/internal/Base64UrlSafeTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/oauth/v2/internal/Base64UrlSafeTest.java b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/oauth/v2/internal/Base64UrlSafeTest.java new file mode 100644 index 0000000..f6d938a --- /dev/null +++ b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/oauth/v2/internal/Base64UrlSafeTest.java @@ -0,0 +1,40 @@ +/* + * 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/stratos/blob/3ddce9df/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/oauth/v2/internal/BaseOAuthApiExpectTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/oauth/v2/internal/BaseOAuthApiExpectTest.java b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/oauth/v2/internal/BaseOAuthApiExpectTest.java new file mode 100644 index 0000000..a44bad1 --- /dev/null +++ b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/oauth/v2/internal/BaseOAuthApiExpectTest.java @@ -0,0 +1,23 @@ +/* + * 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 org.jclouds.oauth.v2.OAuthApi; + +public class BaseOAuthApiExpectTest extends BaseOAuthExpectTest<OAuthApi> { + +} http://git-wip-us.apache.org/repos/asf/stratos/blob/3ddce9df/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/oauth/v2/internal/BaseOAuthApiLiveTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/oauth/v2/internal/BaseOAuthApiLiveTest.java b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/oauth/v2/internal/BaseOAuthApiLiveTest.java new file mode 100644 index 0000000..ba1c616 --- /dev/null +++ b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/oauth/v2/internal/BaseOAuthApiLiveTest.java @@ -0,0 +1,56 @@ +/* + * 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.SCOPES; +import static org.jclouds.oauth.v2.config.OAuthProperties.SIGNATURE_OR_MAC_ALGORITHM; + +import java.util.Properties; +import java.util.concurrent.TimeUnit; + +import org.jclouds.apis.BaseApiLiveTest; +import org.jclouds.oauth.v2.OAuthApi; +import org.testng.annotations.Test; + + +@Test(groups = "live") +public class BaseOAuthApiLiveTest extends BaseApiLiveTest<OAuthApi> { + + 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"); + setIfTestSystemPropertyPresent(props, SCOPES); + setIfTestSystemPropertyPresent(props, SIGNATURE_OR_MAC_ALGORITHM); + return props; + } + + protected long nowInSeconds() { + return TimeUnit.SECONDS.convert(System.currentTimeMillis(), TimeUnit.MILLISECONDS); + } + +} + http://git-wip-us.apache.org/repos/asf/stratos/blob/3ddce9df/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/oauth/v2/internal/BaseOAuthAuthenticatedApiLiveTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/oauth/v2/internal/BaseOAuthAuthenticatedApiLiveTest.java b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/oauth/v2/internal/BaseOAuthAuthenticatedApiLiveTest.java new file mode 100644 index 0000000..aefdcdd --- /dev/null +++ b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/oauth/v2/internal/BaseOAuthAuthenticatedApiLiveTest.java @@ -0,0 +1,110 @@ +/* + * 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.SIGNATURE_OR_MAC_ALGORITHM; +import static org.testng.Assert.assertNotNull; + +import java.io.Closeable; +import java.util.Properties; + +import org.jclouds.apis.BaseApiLiveTest; +import org.jclouds.config.ValueOfConfigurationKeyOrNull; +import org.jclouds.oauth.v2.OAuthApi; +import org.jclouds.oauth.v2.OAuthConstants; +import org.jclouds.oauth.v2.domain.ClaimSet; +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.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.signature-or-mac-algorithm + * <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 signatureAlgorithm = checkNotNull(propFunction.apply(SIGNATURE_OR_MAC_ALGORITHM), + SIGNATURE_OR_MAC_ALGORITHM); + + checkState(OAuthConstants.OAUTH_ALGORITHM_NAMES_TO_SIGNATURE_ALGORITHM_NAMES.containsKey(signatureAlgorithm) + , String.format("Algorithm not supported: " + signatureAlgorithm)); + + String audience = checkNotNull(propFunction.apply(AUDIENCE), AUDIENCE); + + // obtain the scopes from the subclass + String scopes = getScopes(); + + Header header = Header.builder().signerAlgorithm(signatureAlgorithm).type("JWT").build(); + + long now = SECONDS.convert(System.currentTimeMillis(), MILLISECONDS); + + ClaimSet claimSet = ClaimSet.builder() + .addClaim("aud", audience) + .addClaim("scope", scopes) + .addClaim("iss", identity) + .emissionTime(now) + .expirationTime(now + 3600).build(); + + TokenRequest tokenRequest = TokenRequest.builder().header(header).claimSet(claimSet).build(); + + 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/stratos/blob/3ddce9df/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/oauth/v2/internal/BaseOAuthExpectTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/oauth/v2/internal/BaseOAuthExpectTest.java b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/oauth/v2/internal/BaseOAuthExpectTest.java new file mode 100644 index 0000000..18fe151 --- /dev/null +++ b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/oauth/v2/internal/BaseOAuthExpectTest.java @@ -0,0 +1,26 @@ +/* + * 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 org.jclouds.rest.internal.BaseRestApiExpectTest; + +public class BaseOAuthExpectTest<T> extends BaseRestApiExpectTest<T> { + + public BaseOAuthExpectTest() { + provider = "oauth"; + } +} http://git-wip-us.apache.org/repos/asf/stratos/blob/3ddce9df/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/oauth/v2/json/JWTTokenRequestFormatTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/oauth/v2/json/JWTTokenRequestFormatTest.java b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/oauth/v2/json/JWTTokenRequestFormatTest.java new file mode 100644 index 0000000..fa3307f --- /dev/null +++ b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/oauth/v2/json/JWTTokenRequestFormatTest.java @@ -0,0 +1,69 @@ +/* + * 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.json; + +import static org.testng.Assert.assertNotNull; +import static org.testng.Assert.assertSame; +import static org.testng.Assert.assertTrue; + +import java.io.IOException; + +import org.jclouds.ContextBuilder; +import org.jclouds.http.HttpRequest; +import org.jclouds.oauth.v2.OAuthApiMetadata; +import org.jclouds.oauth.v2.OAuthTestUtils; +import org.jclouds.oauth.v2.domain.ClaimSet; +import org.jclouds.oauth.v2.domain.Header; +import org.jclouds.oauth.v2.domain.TokenRequest; +import org.jclouds.oauth.v2.domain.TokenRequestFormat; +import org.jclouds.util.Strings2; +import org.testng.annotations.Test; + +import com.google.common.base.Splitter; +import com.google.common.collect.Iterables; + +@Test(groups = "unit") +public class JWTTokenRequestFormatTest { + public static final String STRING_THAT_GENERATES_URL_UNSAFE_BASE64_ENCODING = "§1234567890'+±!\"#$%&/()" + + "=?*qwertyuiopº´WERTYUIOPªà sdfghjklç~ASDFGHJKLÃ^<zxcvbnm," + + ".->ZXCVBNM;:_@â¬"; + + public void testPayloadIsUrlSafe() throws IOException { + + TokenRequestFormat tokenRequestFormat = ContextBuilder.newBuilder(new OAuthApiMetadata()).overrides + (OAuthTestUtils.defaultProperties(null)).build().utils() + .injector().getInstance(TokenRequestFormat.class); + Header header = new Header.Builder().signerAlgorithm("a").type("b").build(); + ClaimSet claimSet = new ClaimSet.Builder().addClaim("ist", STRING_THAT_GENERATES_URL_UNSAFE_BASE64_ENCODING) + .build(); + TokenRequest tokenRequest = new TokenRequest.Builder().claimSet(claimSet).header(header).build(); + HttpRequest request = tokenRequestFormat.formatRequest(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("/")); + } +} http://git-wip-us.apache.org/repos/asf/stratos/blob/3ddce9df/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/oauth/v2/parse/ParseTokenTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/oauth/v2/parse/ParseTokenTest.java b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/oauth/v2/parse/ParseTokenTest.java new file mode 100644 index 0000000..bcaa9e4 --- /dev/null +++ b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/oauth/v2/parse/ParseTokenTest.java @@ -0,0 +1,40 @@ +/* + * 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 org.jclouds.json.BaseItemParserTest; +import org.jclouds.oauth.v2.domain.Token; +import org.testng.annotations.Test; + +import javax.ws.rs.Consumes; +import javax.ws.rs.core.MediaType; + +@Test(groups = "unit") +public class ParseTokenTest extends BaseItemParserTest<Token> { + + @Override + public String resource() { + return "/tokenResponse.json"; + } + + @Override + @Consumes(MediaType.APPLICATION_JSON) + public Token expected() { + return Token.builder().expiresIn(3600).tokenType("Bearer").accessToken + ("1/8xbJqaOZXSUZbHLl5EOtu1pxz3fmmetKx9W8CV4t79M").build(); + } +} http://git-wip-us.apache.org/repos/asf/stratos/blob/3ddce9df/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/resources/GoogleComputeEngineServiceExpectTest/firewall_list.json ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/resources/GoogleComputeEngineServiceExpectTest/firewall_list.json b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/resources/GoogleComputeEngineServiceExpectTest/firewall_list.json new file mode 100644 index 0000000..c965349 --- /dev/null +++ b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/resources/GoogleComputeEngineServiceExpectTest/firewall_list.json @@ -0,0 +1,37 @@ +{ + "kind": "compute#firewallList", + "id": "projects/google/firewalls", + "selfLink": "https://www.googleapis.com/compute/v1/projects/google/global/firewalls", + "items": [ + { + + "kind": "compute#firewall", + "id": "12862241031274216284", + "creationTimestamp": "2012-04-13T03:05:02.855", + "selfLink": "https://www.googleapis.com/compute/v1/projects/myproject/global/firewalls/jclouds-test-delete", + "name": "jclouds-test-delete", + "description": "Internal traffic from default allowed", + "network": "https://www.googleapis.com/compute/v1/projects/myproject/global/networks/jclouds-test-delete", + "sourceRanges": [ + "10.0.0.0/8" + ], + "allowed": [ + { + "IPProtocol": "tcp", + "ports": [ + "1-65535" + ] + }, + { + "IPProtocol": "udp", + "ports": [ + "1-65535" + ] + }, + { + "IPProtocol": "icmp" + } + ] + } + ] +} http://git-wip-us.apache.org/repos/asf/stratos/blob/3ddce9df/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/resources/GoogleComputeEngineServiceExpectTest/network_get.json ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/resources/GoogleComputeEngineServiceExpectTest/network_get.json b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/resources/GoogleComputeEngineServiceExpectTest/network_get.json new file mode 100644 index 0000000..e9308f0 --- /dev/null +++ b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/resources/GoogleComputeEngineServiceExpectTest/network_get.json @@ -0,0 +1,10 @@ +{ + "kind": "compute#network", + "id": "13024414170909937976", + "creationTimestamp": "2012-10-24T20:13:19.967", + "selfLink": "https://www.googleapis.com/compute/v1/projects/myproject/global/networks/jclouds-test-delete", + "name": "jclouds-test-delete", + "description": "Default network for the project", + "IPv4Range": "10.0.0.0/8", + "gatewayIPv4": "10.0.0.1" +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/stratos/blob/3ddce9df/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/resources/address_get.json ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/resources/address_get.json b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/resources/address_get.json new file mode 100644 index 0000000..f93e497 --- /dev/null +++ b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/resources/address_get.json @@ -0,0 +1,12 @@ +{ + + "kind": "compute#address", + "id": "4439373783165447583", + "creationTimestamp": "2013-07-26T13:57:20.204-07:00", + "status": "RESERVED", + "region": "https://www.googleapis.com/compute/v1/projects/myproject/regions/us-central1", + "name": "test-ip1", + "description": "", + "address": "173.255.115.190", + "selfLink": "https://www.googleapis.com/compute/v1/projects/myproject/regions/us-central1/addresses/test-ip1" +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/stratos/blob/3ddce9df/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/resources/address_insert.json ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/resources/address_insert.json b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/resources/address_insert.json new file mode 100644 index 0000000..4bccf63 --- /dev/null +++ b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/resources/address_insert.json @@ -0,0 +1 @@ +{"name":"test-ip1"} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/stratos/blob/3ddce9df/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/resources/address_list.json ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/resources/address_list.json b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/resources/address_list.json new file mode 100644 index 0000000..cbfa9d5 --- /dev/null +++ b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/resources/address_list.json @@ -0,0 +1,31 @@ +{ + "kind": "compute#addressList", + "selfLink": "https://www.googleapis.com/compute/v1/projects/myproject/regions/us-central1/addresses", + "id": "projects/myproject/regions/us-central1/addresses", + "items": [ + { + + "kind": "compute#address", + "id": "4439373783165447583", + "creationTimestamp": "2013-07-26T13:57:20.204-07:00", + "status": "RESERVED", + "region": "https://www.googleapis.com/compute/v1/projects/myproject/regions/us-central1", + "name": "test-ip1", + "description": "", + "address": "173.255.115.190", + "selfLink": "https://www.googleapis.com/compute/v1/projects/myproject/regions/us-central1/addresses/test-ip1" + }, + { + + "kind": "compute#address", + "id": "4881363978908129158", + "creationTimestamp": "2013-07-26T14:08:21.552-07:00", + "status": "RESERVED", + "region": "https://www.googleapis.com/compute/v1/projects/myproject/regions/us-central1", + "name": "test-ip2", + "description": "", + "address": "173.255.118.115", + "selfLink": "https://www.googleapis.com/compute/v1/projects/myproject/regions/us-central1/addresses/test-ip2" + } + ] +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/stratos/blob/3ddce9df/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/resources/disk_create_snapshot.json ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/resources/disk_create_snapshot.json b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/resources/disk_create_snapshot.json new file mode 100644 index 0000000..6499744 --- /dev/null +++ b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/resources/disk_create_snapshot.json @@ -0,0 +1 @@ +{"name":"test-snap"} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/stratos/blob/3ddce9df/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/resources/disk_get.json ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/resources/disk_get.json b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/resources/disk_get.json new file mode 100644 index 0000000..88ddd54 --- /dev/null +++ b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/resources/disk_get.json @@ -0,0 +1,10 @@ +{ + "kind": "compute#disk", + "id": "13050421646334304115", + "creationTimestamp": "2012-11-25T01:38:48.306", + "selfLink": "https://www.googleapis.com/compute/v1/projects/myproject/zones/us-central1-a/disks/testimage1", + "name": "testimage1", + "sizeGb": "1", + "zone": "https://www.googleapis.com/compute/v1/projects/myproject/zones/us-central1-a", + "status": "READY" +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/stratos/blob/3ddce9df/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/resources/disk_insert.json ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/resources/disk_insert.json b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/resources/disk_insert.json new file mode 100644 index 0000000..8699cdd --- /dev/null +++ b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/resources/disk_insert.json @@ -0,0 +1 @@ +{"name":"testimage1","sizeGb":1} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/stratos/blob/3ddce9df/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/resources/disk_list.json ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/resources/disk_list.json b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/resources/disk_list.json new file mode 100644 index 0000000..bdca33d --- /dev/null +++ b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/resources/disk_list.json @@ -0,0 +1,17 @@ +{ + "kind": "compute#diskList", + "id": "projects/myproject/zones/us-central1-a/disks", + "selfLink": "https://www.googleapis.com/compute/v1/projects/myproject/zones/us-central1-a/disks", + "items": [ + { + "kind": "compute#disk", + "id": "13050421646334304115", + "creationTimestamp": "2012-11-25T01:38:48.306", + "selfLink": "https://www.googleapis.com/compute/v1/projects/myproject/zones/us-central1-a/disks/testimage1", + "name": "testimage1", + "sizeGb": "1", + "zone": "https://www.googleapis.com/compute/v1/projects/myproject/zones/us-central1-a", + "status": "READY" + } + ] +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/stratos/blob/3ddce9df/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/resources/firewall_get.json ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/resources/firewall_get.json b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/resources/firewall_get.json new file mode 100644 index 0000000..74ced74 --- /dev/null +++ b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/resources/firewall_get.json @@ -0,0 +1,30 @@ +{ + + "kind": "compute#firewall", + "id": "12862241031274216284", + "creationTimestamp": "2012-04-13T03:05:02.855", + "selfLink": "https://www.googleapis.com/compute/v1/projects/myproject/global/firewalls/jclouds-test", + "name": "jclouds-test", + "description": "Internal traffic from default allowed", + "network": "https://www.googleapis.com/compute/v1/projects/myproject/global/networks/jclouds-test", + "sourceRanges": [ + "10.0.0.0/8" + ], + "allowed": [ + { + "IPProtocol": "tcp", + "ports": [ + "1-65535" + ] + }, + { + "IPProtocol": "udp", + "ports": [ + "1-65535" + ] + }, + { + "IPProtocol": "icmp" + } + ] +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/stratos/blob/3ddce9df/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/resources/firewall_insert.json ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/resources/firewall_insert.json b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/resources/firewall_insert.json new file mode 100644 index 0000000..fabe1bd --- /dev/null +++ b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/resources/firewall_insert.json @@ -0,0 +1 @@ +{"name":"%s","network":"https://www.googleapis.com/compute/v1/projects/myproject/global/networks/%s","sourceRanges":[%s],"sourceTags":[%s],"targetTags":[%s],"allowed":[{"IPProtocol":"tcp","ports":[%s]}]} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/stratos/blob/3ddce9df/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/resources/firewall_list.json ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/resources/firewall_list.json b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/resources/firewall_list.json new file mode 100644 index 0000000..ab7d0b7 --- /dev/null +++ b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/resources/firewall_list.json @@ -0,0 +1,58 @@ +{ + "kind": "compute#firewallList", + "id": "projects/google/firewalls", + "selfLink": "https://www.googleapis.com/compute/v1/projects/google/global/firewalls", + "items": [ + { + + "kind": "compute#firewall", + "id": "12862241031274216284", + "creationTimestamp": "2012-04-13T03:05:02.855", + "selfLink": "https://www.googleapis.com/compute/v1/projects/myproject/global/firewalls/jclouds-test", + "name": "jclouds-test", + "description": "Internal traffic from default allowed", + "network": "https://www.googleapis.com/compute/v1/projects/myproject/global/networks/jclouds-test", + "sourceRanges": [ + "10.0.0.0/8" + ], + "allowed": [ + { + "IPProtocol": "tcp", + "ports": [ + "1-65535" + ] + }, + { + "IPProtocol": "udp", + "ports": [ + "1-65535" + ] + }, + { + "IPProtocol": "icmp" + } + ] + }, + { + + "kind": "compute#firewall", + "id": "12862241067393040785", + "creationTimestamp": "2012-04-13T03:05:04.365", + "selfLink": "https://www.googleapis.com/compute/v1/projects/google/global/firewalls/default-ssh", + "name": "default-ssh", + "description": "SSH allowed from anywhere", + "network": "https://www.googleapis.com/compute/v1/projects/google/global/networks/default", + "sourceRanges": [ + "0.0.0.0/0" + ], + "allowed": [ + { + "IPProtocol": "tcp", + "ports": [ + "22" + ] + } + ] + } + ] +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/stratos/blob/3ddce9df/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/resources/global_operation.json ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/resources/global_operation.json b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/resources/global_operation.json new file mode 100644 index 0000000..17d77483 --- /dev/null +++ b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/resources/global_operation.json @@ -0,0 +1,15 @@ +{ + "kind": "compute#operation", + "id": "13053095055850848306", + "selfLink": "https://www.googleapis.com/compute/v1/projects/myproject/global/operations/operation-1354084865060-4cf88735faeb8-bbbb12cb", + "name": "operation-1354084865060-4cf88735faeb8-bbbb12cb", + "targetLink": "https://www.googleapis.com/compute/v1/projects/myproject/global/firewalls/jclouds-test-delete", + "targetId": "13053094017547040099", + "status": "DONE", + "user": "[email protected]", + "progress": 100, + "insertTime": "2012-11-28T06:41:05.060", + "startTime": "2012-11-28T06:41:05.142", + "endTime": "2012-11-28T06:41:06.142", + "operationType": "insert" +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/stratos/blob/3ddce9df/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/resources/global_operation_list.json ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/resources/global_operation_list.json b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/resources/global_operation_list.json new file mode 100644 index 0000000..32b881a --- /dev/null +++ b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/resources/global_operation_list.json @@ -0,0 +1,22 @@ +{ + "kind": "compute#operationList", + "id": "projects/myproject/global/operations", + "selfLink": "https://www.googleapis.com/compute/v1/projects/myproject/global/operations", + "items": [ + { + "kind": "compute#operation", + "id": "13053095055850848306", + "selfLink": "https://www.googleapis.com/compute/v1/projects/myproject/global/operations/operation-1354084865060-4cf88735faeb8-bbbb12cb", + "name": "operation-1354084865060-4cf88735faeb8-bbbb12cb", + "targetLink": "https://www.googleapis.com/compute/v1/projects/myproject/global/firewalls/jclouds-test-delete", + "targetId": "13053094017547040099", + "status": "DONE", + "user": "[email protected]", + "progress": 100, + "insertTime": "2012-11-28T06:41:05.060", + "startTime": "2012-11-28T06:41:05.142", + "endTime": "2012-11-28T06:41:06.142", + "operationType": "insert" + } + ] +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/stratos/blob/3ddce9df/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/resources/image_get.json ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/resources/image_get.json b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/resources/image_get.json new file mode 100644 index 0000000..23cb0d2 --- /dev/null +++ b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/resources/image_get.json @@ -0,0 +1,13 @@ +{ + "kind": "compute#image", + "id": "12941197498378735318", + "creationTimestamp": "2012-07-16T22:16:13.468", + "selfLink": "https://www.googleapis.com/compute/v1/projects/centos-cloud/global/images/centos-6-2-v20120326", + "name": "centos-6-2-v20120326", + "description": "DEPRECATED. CentOS 6.2 image; Created Mon, 26 Mar 2012 21:19:09 +0000", + "sourceType": "RAW", + "rawDisk": { + "source": "", + "containerType": "TAR" + } +} http://git-wip-us.apache.org/repos/asf/stratos/blob/3ddce9df/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/resources/image_insert.json ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/resources/image_insert.json b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/resources/image_insert.json new file mode 100644 index 0000000..fd030a7 --- /dev/null +++ b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/resources/image_insert.json @@ -0,0 +1,4 @@ +{"sourceType": "RAW", "rawDisk": { + "source": "https://storage.googleapis.com/mybuket/myimage.image.tar.gz", + "containerType": "TAR" +}, "kind": "compute#image", "name": "myimage"} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/stratos/blob/3ddce9df/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/resources/image_list.json ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/resources/image_list.json b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/resources/image_list.json new file mode 100644 index 0000000..6010f5a --- /dev/null +++ b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/resources/image_list.json @@ -0,0 +1,24 @@ +{ + "kind": "compute#imageList", + "id": "projects/centos-cloud/global/images", + "selfLink": "https://www.googleapis.com/compute/v1/projects/centos-cloud/global/images", + "items": [ + { + "kind": "compute#image", + "id": "12941197498378735318", + "creationTimestamp": "2012-07-16T22:16:13.468", + "selfLink": "https://www.googleapis.com/compute/v1/projects/centos-cloud/global/images/centos-6-2-v20120326", + "name": "centos-6-2-v20120326", + "description": "DEPRECATED. CentOS 6.2 image; Created Mon, 26 Mar 2012 21:19:09 +0000", + "sourceType": "RAW", + "deprecated": { + "state": "DEPRECATED", + "replacement": "https://www.googleapis.com/compute/v1/projects/centos-cloud/global/images/centos-6-v20130104" + }, + "rawDisk": { + "source": "", + "containerType": "TAR" + } + } + ] +}
