Skip to content

Commit

Permalink
Provide getters for the callback address and port in the Tsunami call…
Browse files Browse the repository at this point in the history
…back client.

PiperOrigin-RevId: 702120836
Change-Id: I7efa6684b5cca5f734ee2aac8cb99717a6a82161
  • Loading branch information
tooryx authored and copybara-github committed Dec 3, 2024
1 parent 02eb2ad commit 362c3fb
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 1 deletion.
21 changes: 20 additions & 1 deletion plugin/src/main/java/com/google/tsunami/plugin/TcsClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,26 @@ public String getCallbackUri(String secretString) {
return CbidProcessor.addCbidToSubdomain(cbid, hostAndPort);
}
// Should never reach here
throw new AssertionError("Unrecognized address format, should be Ip address or valid domain");
throw new AssertionError("Unrecognized address format, should be IP address or valid domain");
}

public String getCallbackAddress() {
if (InetAddresses.isInetAddress(callbackAddress)) {
return callbackAddress;
} else if (InternetDomainName.isValid(callbackAddress)) {
return callbackAddress;
}

// Should never reach here
throw new AssertionError("Unrecognized address format, should be IP address or valid domain");
}

public int getCallbackPort() {
if (!isValidPortNumber(callbackPort)) {
throw new AssertionError("Invalid callbackPort number specified");
}

return callbackPort;
}

public boolean hasOobLog(String secretString) {
Expand Down
36 changes: 36 additions & 0 deletions plugin/src/test/java/com/google/tsunami/plugin/TcsClientTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,42 @@ public void getCallbackUri_invalidCallbackPort_throwsError() {
assertThrows(AssertionError.class, () -> client.getCallbackUri(SECRET));
}

@Test
public void getCallbackAddress_validIpv4Address_returnsAddress() {
client = new TcsClient(VALID_IPV4_ADDRESS, VALID_PORT, VALID_URL, httpClient);
assertThat(client.getCallbackAddress()).isEqualTo(VALID_IPV4_ADDRESS);
}

@Test
public void getCallbackAddress_validIpv6Address_returnsAddress() {
client = new TcsClient(VALID_IPV6_ADDRESS, VALID_PORT, VALID_URL, httpClient);
assertThat(client.getCallbackAddress()).isEqualTo(VALID_IPV6_ADDRESS);
}

@Test
public void getCallbackAddress_validDomainAddress_returnsAddress() {
client = new TcsClient(VALID_DOMAIN, VALID_PORT, VALID_URL, httpClient);
assertThat(client.getCallbackAddress()).isEqualTo(VALID_DOMAIN);
}

@Test
public void getCallbackAddress_invalidAddress_throwsError() {
client = new TcsClient(INVALID_ADDRESS, 100000, VALID_URL, httpClient);
assertThrows(AssertionError.class, () -> client.getCallbackAddress());
}

@Test
public void getCallbackPort_validPort_returnsPort() {
client = new TcsClient(VALID_DOMAIN, VALID_PORT, VALID_URL, httpClient);
assertThat(client.getCallbackPort()).isEqualTo(VALID_PORT);
}

@Test
public void getCallbackPort_invalidPort_throwsError() {
client = new TcsClient(VALID_DOMAIN, 100000, VALID_URL, httpClient);
assertThrows(AssertionError.class, () -> client.getCallbackPort());
}

@Test
public void isVulnerable_sendsValidPollingRequest() throws IOException, InterruptedException {
MockWebServer mockWebServer = new MockWebServer();
Expand Down

0 comments on commit 362c3fb

Please sign in to comment.