@Consumes(APPLICATION_JSON) public Firewall expected(String base_url) { return Firewall.create( // "12862241031274216284", // id URI.create(base_url + "/party/global/firewalls/jclouds-test"), // selfLink parse("2012-04-13T03:05:02.855"), // creationTimestamp "jclouds-test", // name "Internal traffic from default allowed", // description URI.create(base_url + "/party/global/networks/jclouds-test"), // network ImmutableList.of("10.0.0.0/8"), // sourceRanges null, // sourceTags null, // targetTags ImmutableList.of( // allowed Rule.create("tcp", ImmutableList.of("1-65535")), // Rule.create("udp", ImmutableList.of("1-65535")), // Rule.create("icmp", null) // )); } }
if (firewall == null) { List<String> ports = ImmutableList.of(String.valueOf(port)); List<Rule> rules = ImmutableList.of(Rule.create("tcp", ports), Rule.create("udp", ports)); FirewallOptions firewallOptions = new FirewallOptions().name(name).network(network.selfLink()) .allowedRules(rules).sourceTags(templateOptions.getTags())
@Consumes(APPLICATION_JSON) public ListPage<Firewall> expected(String baseUrl) { Firewall firewall1 = new ParseFirewallTest().expected(baseUrl); Firewall firewall2 = Firewall.create( // "12862241067393040785", // id URI.create(baseUrl + "/google/global/firewalls/default-ssh"), // selfLink parse("2012-04-13T03:05:04.365"), // creationTimestamp "default-ssh", // name "SSH allowed from anywhere", // description URI.create(baseUrl + "/google/global/networks/default"), // network ImmutableList.of("0.0.0.0/0"), // sourceRanges null, // sourceTags null, // targetTags ImmutableList.of(Firewall.Rule.create("tcp", ImmutableList.of("22"))) // allowed ); return ForwardingListPage.create( // ImmutableList.of(firewall1, firewall2), // items null // nextPageToken ); } }
AtomicReference<Operation> operation = null; if (firewall == null) { List<Rule> rules = ImmutableList.of(Rule.create("tcp", ports), Rule.create("udp", ports)); FirewallOptions firewallOptions = new FirewallOptions().name(name).network(network.selfLink()) .allowedRules(rules).sourceTags(templateOptions.getTags())
public void patch() throws Exception { server.enqueue(jsonResponse("/operation.json")); FirewallOptions options = new FirewallOptions() .name("myfw") .network(URI.create(url("/projects/party/global/networks/default"))) .addAllowedRule(Firewall.Rule.create("tcp", ImmutableList.of("22", "23-24"))) .addSourceTag("tag1") .addSourceRange("10.0.1.0/32") .addTargetTag("tag2"); assertEquals(firewallApi().patch("myfw", options), new ParseOperationTest().expected(url("/projects"))); assertSent(server, "PATCH", "/projects/party/global/firewalls/myfw", stringFromResource("/firewall_insert.json")); }
@Test(groups = "live", dependsOnMethods = "testPatchFirewall") public void testGetFirewall() { FirewallOptions patchedFirewall = new FirewallOptions() .name(FIREWALL_NAME) .network(getNetworkUrl(FIREWALL_NETWORK_NAME)) .allowedRules(ImmutableList.of(Firewall.Rule.create("tcp", ImmutableList.of("22")), Firewall.Rule.create("tcp", ImmutableList.of("23")))) .addSourceRange("10.0.0.0/8") .addSourceTag("tag1") .addTargetTag("tag2"); Firewall firewall = api().get(FIREWALL_NAME); assertNotNull(firewall); assertFirewallEquals(firewall, patchedFirewall); }
public void update() throws Exception { server.enqueue(jsonResponse("/operation.json")); FirewallOptions options = new FirewallOptions() .name("myfw") .network(URI.create(url("/projects/party/global/networks/default"))) .addAllowedRule(Firewall.Rule.create("tcp", ImmutableList.of("22", "23-24"))) .addSourceTag("tag1") .addSourceRange("10.0.1.0/32") .addTargetTag("tag2"); assertEquals(firewallApi().update("myfw", options), new ParseOperationTest().expected(url("/projects"))); assertSent(server, "PUT", "/projects/party/global/firewalls/myfw", stringFromResource("/firewall_insert.json")); }
public void insert() throws Exception { server.enqueue(jsonResponse("/operation.json")); FirewallOptions options = new FirewallOptions() .addAllowedRule(Firewall.Rule.create("tcp", ImmutableList.of("22", "23-24"))) .addSourceTag("tag1") .addSourceRange("10.0.1.0/32") .addTargetTag("tag2"); assertEquals(firewallApi().createInNetwork("myfw", URI.create(url("/projects/party/global/networks/default")), options), new ParseOperationTest().expected(url("/projects"))); assertSent(server, "POST", "/projects/party/global/firewalls", stringFromResource("/firewall_insert.json")); }
@Test(groups = "live") public void testInsertFirewall() { // need to insert the network first assertOperationDoneSuccessfully(api.networks().createLegacy(FIREWALL_NETWORK_NAME, IPV4_RANGE)); FirewallOptions firewall = new FirewallOptions() .addAllowedRule(Firewall.Rule.create("tcp", ImmutableList.of("22"))) .addSourceRange("10.0.0.0/8") .addSourceTag("tag1") .addTargetTag("tag2"); assertOperationDoneSuccessfully( api().createInNetwork(FIREWALL_NAME, getNetworkUrl(FIREWALL_NETWORK_NAME), firewall)); }
@Test(groups = "live", dependsOnMethods = "testUpdateFirewall") public void testPatchFirewall() { FirewallOptions firewall = new FirewallOptions() .name(FIREWALL_NAME) .network(getNetworkUrl(FIREWALL_NETWORK_NAME)) .allowedRules(ImmutableList.of(Firewall.Rule.create("tcp", ImmutableList.of("22")), Firewall.Rule.create("tcp", ImmutableList.of("23")))) .addSourceRange("10.0.0.0/8") .addSourceTag("tag1") .addTargetTag("tag2"); assertOperationDoneSuccessfully(api().update(FIREWALL_NAME, firewall)); }
@Test(groups = "live", dependsOnMethods = "testInsertFirewall") public void testUpdateFirewall() { FirewallOptions firewall = new FirewallOptions() .name(FIREWALL_NAME) .network(getNetworkUrl(FIREWALL_NETWORK_NAME)) .addSourceRange("10.0.0.0/8") .addSourceTag("tag1") .addTargetTag("tag2") .allowedRules(ImmutableList.of(Firewall.Rule.create("tcp", ImmutableList.of("23")))); assertOperationDoneSuccessfully(api().update(FIREWALL_NAME, firewall)); }