public void testCreatePortForwardingRule() throws Exception { if (networksDisabled) return; while (portForwardingRule == null) { ip = reuseOrAssociate.apply(network); try { AsyncCreateResponse job = client.getFirewallApi() .createPortForwardingRuleForVirtualMachine(ip.getId(), PortForwardingRule.Protocol.TCP, 22, vm.getId(), 22); assertTrue(jobComplete.apply(job.getJobId())); portForwardingRule = client.getFirewallApi().getPortForwardingRule(job.getId()); } catch (IllegalStateException e) { Logger.CONSOLE.error("Failed while trying to allocate ip: " + e); // very likely an ip conflict, so retry; } } assertEquals(portForwardingRule.getIPAddressId(), ip.getId()); assertEquals(portForwardingRule.getVirtualMachineId(), vm.getId()); assertEquals(portForwardingRule.getPublicPort(), 22); assertEquals(portForwardingRule.getProtocol(), PortForwardingRule.Protocol.TCP); checkPortForwardingRule(portForwardingRule); checkSSH(HostAndPort.fromParts(ip.getIPAddress(), 22)); }
public void testCreatePortForwardingRuleForVirtualMachine() { FirewallApi client = requestSendsResponse( HttpRequest.builder().method("GET") .endpoint("http://localhost:8080/client/api") .addQueryParam("response", "json") .addQueryParam("command", "createPortForwardingRule") .addQueryParam("ipaddressid", "2") .addQueryParam("protocol", "tcp") .addQueryParam("publicport", "22") .addQueryParam("virtualmachineid", "1234") .addQueryParam("privateport", "22") .addQueryParam("apiKey", "identity") .addQueryParam("signature", "84dtGzQp0G6k3z3Gkc3F/HBNS2Y=") .addHeader("Accept", "application/json") .build(), HttpResponse.builder() .statusCode(200) .payload(payloadFromResource("/createportforwardingrulesresponse.json")) .build()); AsyncCreateResponse response = client.createPortForwardingRuleForVirtualMachine( "2", PortForwardingRule.Protocol.TCP, 22, "1234", 22); assertEquals(response.getJobId(), "2035"); assertEquals(response.getId(), "2015"); }