http://git-wip-us.apache.org/repos/asf/stratos/blob/897edde8/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/parse/ParseRouteListTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/parse/ParseRouteListTest.java b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/parse/ParseRouteListTest.java deleted file mode 100644 index 3a378aa..0000000 --- a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/parse/ParseRouteListTest.java +++ /dev/null @@ -1,62 +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.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.ListPage; -import org.jclouds.googlecomputeengine.domain.Resource.Kind; -import org.jclouds.googlecomputeengine.domain.Route; -import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineParseTest; -import org.testng.annotations.Test; - -import com.google.common.collect.ImmutableSet; - -@Test(groups = "unit") -public class ParseRouteListTest extends BaseGoogleComputeEngineParseTest<ListPage<Route>> { - - @Override - public String resource() { - return "/route_list.json"; - } - - @Override - @Consumes(MediaType.APPLICATION_JSON) - public ListPage<Route> expected() { - return ListPage.<Route>builder() - .kind(Kind.ROUTE_LIST) - .id("projects/myproject/global/routes") - .selfLink(URI.create("https://www.googleapis.com/compute/v1/projects/myproject/global/routes")) - .items(ImmutableSet.of(new ParseRouteTest().expected(), - Route.builder() - .selfLink(URI.create("https://www.googleapis.com/compute/v1/projects/myproject/global/routes/default-route-fc92a41ecb5a8d17")) - .id("507025480040058551") - .creationTimestamp(new SimpleDateFormatDateService().iso8601DateParse("2013-07-08T14:40:38.502-07:00")) - .name("default-route-fc92a41ecb5a8d17") - .description("Default route to the Internet.") - .network(URI.create("https://www.googleapis.com/compute/v1/projects/myproject/global/networks/default")) - .destRange("0.0.0.0/0") - .priority(1000) - .nextHopGateway(URI.create("https://www.googleapis.com/compute/v1/projects/myproject/global/gateways/default-internet-gateway")) - .build()) - ).build(); - } -}
http://git-wip-us.apache.org/repos/asf/stratos/blob/897edde8/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/parse/ParseRouteTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/parse/ParseRouteTest.java b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/parse/ParseRouteTest.java deleted file mode 100644 index 5ffd845..0000000 --- a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/parse/ParseRouteTest.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.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.Route; -import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineParseTest; -import org.testng.annotations.Test; - -import com.google.common.collect.ImmutableSet; - -@Test(groups = "unit") -public class ParseRouteTest extends BaseGoogleComputeEngineParseTest<Route> { - - @Override - public String resource() { - return "/route_get.json"; - } - - @Override - @Consumes(MediaType.APPLICATION_JSON) - public Route expected() { - return Route.builder() - .selfLink(URI.create("https://www.googleapis.com/compute/v1/projects/myproject/global/routes/default-route-c99ebfbed0e1f375")) - .id("7241926205630356071") - .name("default-route-c99ebfbed0e1f375") - .creationTimestamp(new SimpleDateFormatDateService().iso8601DateParse("2013-07-08T14:40:38.502-07:00")) - .description("Default route to the virtual network.") - .network(URI.create("https://www.googleapis.com/compute/v1/projects/myproject/global/networks/default")) - .destRange("10.240.0.0/16") - .priority(1000) - .nextHopNetwork(URI.create("https://www.googleapis.com/compute/v1/projects/myproject/global/networks/default")) - .tags(ImmutableSet.of("fooTag", "barTag")) - .build(); - - } -} http://git-wip-us.apache.org/repos/asf/stratos/blob/897edde8/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/parse/ParseSnapshotListTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/parse/ParseSnapshotListTest.java b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/parse/ParseSnapshotListTest.java deleted file mode 100644 index f52aa3f..0000000 --- a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/parse/ParseSnapshotListTest.java +++ /dev/null @@ -1,64 +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.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.ListPage; -import org.jclouds.googlecomputeengine.domain.Resource.Kind; -import org.jclouds.googlecomputeengine.domain.Snapshot; -import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineParseTest; -import org.testng.annotations.Test; - -import com.google.common.collect.ImmutableSet; - -@Test(groups = "unit") -public class ParseSnapshotListTest extends BaseGoogleComputeEngineParseTest<ListPage<Snapshot>> { - - @Override - public String resource() { - return "/snapshot_list.json"; - } - - @Override - @Consumes(MediaType.APPLICATION_JSON) - public ListPage<Snapshot> expected() { - return ListPage.<Snapshot>builder() - .kind(Kind.SNAPSHOT_LIST) - .id("projects/myproject/global/snapshots") - .selfLink(URI.create("https://www.googleapis.com/compute/v1/projects/myproject/global/snapshots")) - .items(ImmutableSet.of( - new ParseSnapshotTest().expected(), Snapshot.builder() - .selfLink(URI.create("https://www.googleapis" + - ".com/compute/v1/projects/myproject/global/snapshots/test-snap2")) - .id("13895715048576107883") - .creationTimestamp(new SimpleDateFormatDateService().iso8601DateParse - ("2013-07-26T12:57:01.927-07:00")) - .status("READY") - .sizeGb(10) - .sourceDisk(URI.create("https://www.googleapis.com/compute/v1/projects/myproject/zones/us-central1-a/disks/testimage1")) - .name("test-snap2") - .description("") - .sourceDiskId("8243603669926824540") - .build())) - .build(); - } -} http://git-wip-us.apache.org/repos/asf/stratos/blob/897edde8/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/parse/ParseSnapshotTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/parse/ParseSnapshotTest.java b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/parse/ParseSnapshotTest.java deleted file mode 100644 index f3e7a01..0000000 --- a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/parse/ParseSnapshotTest.java +++ /dev/null @@ -1,52 +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.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.Snapshot; -import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineParseTest; -import org.testng.annotations.Test; - -@Test(groups = "unit") -public class ParseSnapshotTest extends BaseGoogleComputeEngineParseTest<Snapshot> { - - @Override - public String resource() { - return "/snapshot_get.json"; - } - - @Override - @Consumes(MediaType.APPLICATION_JSON) - public Snapshot expected() { - return Snapshot.builder() - .selfLink(URI.create("https://www.googleapis.com/compute/v1/projects/myproject/global/snapshots/test-snap")) - .id("9734455566806191190") - .creationTimestamp(new SimpleDateFormatDateService().iso8601DateParse("2013-07-26T12:54:23.173-07:00")) - .status("READY") - .sizeGb(10) - .sourceDisk(URI.create("https://www.googleapis.com/compute/v1/projects/myproject/zones/us-central1-a/disks/testimage1")) - .name("test-snap") - .description("") - .sourceDiskId("8243603669926824540") - .build(); - } -} http://git-wip-us.apache.org/repos/asf/stratos/blob/897edde8/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/parse/ParseZoneListTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/parse/ParseZoneListTest.java b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/parse/ParseZoneListTest.java deleted file mode 100644 index 54fe1a2..0000000 --- a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/parse/ParseZoneListTest.java +++ /dev/null @@ -1,70 +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.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.ListPage; -import org.jclouds.googlecomputeengine.domain.Resource; -import org.jclouds.googlecomputeengine.domain.Zone; -import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineParseTest; -import org.testng.annotations.Test; - -import com.google.common.collect.ImmutableSet; - -@Test(groups = "unit") -public class ParseZoneListTest extends BaseGoogleComputeEngineParseTest<ListPage<Zone>> { - - @Override - public String resource() { - return "/zone_list.json"; - } - - @Override - @Consumes(MediaType.APPLICATION_JSON) - public ListPage<Zone> expected() { - return ListPage.<Zone>builder() - .kind(Resource.Kind.ZONE_LIST) - .id("projects/myproject/zones") - .selfLink(URI.create("https://www.googleapis.com/compute/v1/projects/myproject/zones")) - .items(ImmutableSet.of( - new ParseZoneTest().expected() - , Zone.builder() - .id("13024414164050619686") - .creationTimestamp(new SimpleDateFormatDateService().iso8601DateParse - ("2012-10-24T20:13:19.271")) - .selfLink(URI.create("https://www.googleapis" + - ".com/compute/v1/projects/myproject/zones/us-central1-b")) - .name("us-central1-b") - .description("us-central1-b") - .status(Zone.Status.UP) - .addMaintenanceWindow(Zone.MaintenanceWindow.builder() - .name("2013-02-17-planned-outage") - .description("maintenance zone") - .beginTime(new SimpleDateFormatDateService().iso8601DateParse - ("2013-02-17T08:00:00.000")) - .endTime(new SimpleDateFormatDateService().iso8601DateParse - ("2013-03-03T08:00:00.000")) - .build()) - .build())) - .build(); - } -} http://git-wip-us.apache.org/repos/asf/stratos/blob/897edde8/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 deleted file mode 100644 index 48cdbfc..0000000 --- a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/parse/ParseZoneTest.java +++ /dev/null @@ -1,55 +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.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/897edde8/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 deleted file mode 100644 index 58ed81c..0000000 --- a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/predicates/NetworkFirewallPredicatesTest.java +++ /dev/null @@ -1,162 +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.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/897edde8/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 deleted file mode 100644 index d6ea17f..0000000 --- a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/oauth/v2/OAuthApiMetadataTest.java +++ /dev/null @@ -1,38 +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 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/897edde8/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 deleted file mode 100644 index 901cdfe..0000000 --- a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/oauth/v2/OAuthTestUtils.java +++ /dev/null @@ -1,91 +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 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/897edde8/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 deleted file mode 100644 index 2008e5d..0000000 --- a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/oauth/v2/features/OAuthApiExpectTest.java +++ /dev/null @@ -1,99 +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 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/897edde8/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 deleted file mode 100644 index 4ac5950..0000000 --- a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/oauth/v2/features/OAuthApiLiveTest.java +++ /dev/null @@ -1,80 +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.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/897edde8/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 deleted file mode 100644 index e3794d6..0000000 --- a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/oauth/v2/functions/OAuthCredentialsFromPKTest.java +++ /dev/null @@ -1,61 +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.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/897edde8/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 deleted file mode 100644 index 2b3d094..0000000 --- a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/oauth/v2/functions/OAuthCredentialsSupplierTest.java +++ /dev/null @@ -1,55 +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 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/897edde8/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 deleted file mode 100644 index 2a64822..0000000 --- a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/oauth/v2/functions/SignerFunctionTest.java +++ /dev/null @@ -1,61 +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; - -/** - * 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/897edde8/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 deleted file mode 100644 index 255c5c7..0000000 --- a/dependencies/jclouds/apis/gce/1.8.1-stratos/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 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/897edde8/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 deleted file mode 100644 index f6d938a..0000000 --- a/dependencies/jclouds/apis/gce/1.8.1-stratos/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/stratos/blob/897edde8/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 deleted file mode 100644 index a44bad1..0000000 --- a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/oauth/v2/internal/BaseOAuthApiExpectTest.java +++ /dev/null @@ -1,23 +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 org.jclouds.oauth.v2.OAuthApi; - -public class BaseOAuthApiExpectTest extends BaseOAuthExpectTest<OAuthApi> { - -} http://git-wip-us.apache.org/repos/asf/stratos/blob/897edde8/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 deleted file mode 100644 index ba1c616..0000000 --- a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/oauth/v2/internal/BaseOAuthApiLiveTest.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.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/897edde8/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 deleted file mode 100644 index aefdcdd..0000000 --- a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/oauth/v2/internal/BaseOAuthAuthenticatedApiLiveTest.java +++ /dev/null @@ -1,110 +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.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/897edde8/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 deleted file mode 100644 index 18fe151..0000000 --- a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/oauth/v2/internal/BaseOAuthExpectTest.java +++ /dev/null @@ -1,26 +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 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/897edde8/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 deleted file mode 100644 index fa3307f..0000000 --- a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/oauth/v2/json/JWTTokenRequestFormatTest.java +++ /dev/null @@ -1,69 +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.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/897edde8/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 deleted file mode 100644 index bcaa9e4..0000000 --- a/dependencies/jclouds/apis/gce/1.8.1-stratos/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 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/897edde8/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 deleted file mode 100644 index c965349..0000000 --- a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/resources/GoogleComputeEngineServiceExpectTest/firewall_list.json +++ /dev/null @@ -1,37 +0,0 @@ -{ - "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/897edde8/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 deleted file mode 100644 index e9308f0..0000000 --- a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/resources/GoogleComputeEngineServiceExpectTest/network_get.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "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/897edde8/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 deleted file mode 100644 index f93e497..0000000 --- a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/resources/address_get.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - - "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/897edde8/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 deleted file mode 100644 index 4bccf63..0000000 --- a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/resources/address_insert.json +++ /dev/null @@ -1 +0,0 @@ -{"name":"test-ip1"} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/stratos/blob/897edde8/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 deleted file mode 100644 index cbfa9d5..0000000 --- a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/resources/address_list.json +++ /dev/null @@ -1,31 +0,0 @@ -{ - "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/897edde8/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 deleted file mode 100644 index 6499744..0000000 --- a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/resources/disk_create_snapshot.json +++ /dev/null @@ -1 +0,0 @@ -{"name":"test-snap"} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/stratos/blob/897edde8/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 deleted file mode 100644 index 88ddd54..0000000 --- a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/resources/disk_get.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "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/897edde8/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 deleted file mode 100644 index 8699cdd..0000000 --- a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/resources/disk_insert.json +++ /dev/null @@ -1 +0,0 @@ -{"name":"testimage1","sizeGb":1} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/stratos/blob/897edde8/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 deleted file mode 100644 index bdca33d..0000000 --- a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/resources/disk_list.json +++ /dev/null @@ -1,17 +0,0 @@ -{ - "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/897edde8/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 deleted file mode 100644 index 74ced74..0000000 --- a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/resources/firewall_get.json +++ /dev/null @@ -1,30 +0,0 @@ -{ - - "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
