Skip to content

Commit 362c3fb

Browse files
tooryxcopybara-github
authored andcommitted
Provide getters for the callback address and port in the Tsunami callback client.
PiperOrigin-RevId: 702120836 Change-Id: I7efa6684b5cca5f734ee2aac8cb99717a6a82161
1 parent 02eb2ad commit 362c3fb

File tree

2 files changed

+56
-1
lines changed

2 files changed

+56
-1
lines changed

plugin/src/main/java/com/google/tsunami/plugin/TcsClient.java

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,26 @@ public String getCallbackUri(String secretString) {
8989
return CbidProcessor.addCbidToSubdomain(cbid, hostAndPort);
9090
}
9191
// Should never reach here
92-
throw new AssertionError("Unrecognized address format, should be Ip address or valid domain");
92+
throw new AssertionError("Unrecognized address format, should be IP address or valid domain");
93+
}
94+
95+
public String getCallbackAddress() {
96+
if (InetAddresses.isInetAddress(callbackAddress)) {
97+
return callbackAddress;
98+
} else if (InternetDomainName.isValid(callbackAddress)) {
99+
return callbackAddress;
100+
}
101+
102+
// Should never reach here
103+
throw new AssertionError("Unrecognized address format, should be IP address or valid domain");
104+
}
105+
106+
public int getCallbackPort() {
107+
if (!isValidPortNumber(callbackPort)) {
108+
throw new AssertionError("Invalid callbackPort number specified");
109+
}
110+
111+
return callbackPort;
93112
}
94113

95114
public boolean hasOobLog(String secretString) {

plugin/src/test/java/com/google/tsunami/plugin/TcsClientTest.java

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,42 @@ public void getCallbackUri_invalidCallbackPort_throwsError() {
110110
assertThrows(AssertionError.class, () -> client.getCallbackUri(SECRET));
111111
}
112112

113+
@Test
114+
public void getCallbackAddress_validIpv4Address_returnsAddress() {
115+
client = new TcsClient(VALID_IPV4_ADDRESS, VALID_PORT, VALID_URL, httpClient);
116+
assertThat(client.getCallbackAddress()).isEqualTo(VALID_IPV4_ADDRESS);
117+
}
118+
119+
@Test
120+
public void getCallbackAddress_validIpv6Address_returnsAddress() {
121+
client = new TcsClient(VALID_IPV6_ADDRESS, VALID_PORT, VALID_URL, httpClient);
122+
assertThat(client.getCallbackAddress()).isEqualTo(VALID_IPV6_ADDRESS);
123+
}
124+
125+
@Test
126+
public void getCallbackAddress_validDomainAddress_returnsAddress() {
127+
client = new TcsClient(VALID_DOMAIN, VALID_PORT, VALID_URL, httpClient);
128+
assertThat(client.getCallbackAddress()).isEqualTo(VALID_DOMAIN);
129+
}
130+
131+
@Test
132+
public void getCallbackAddress_invalidAddress_throwsError() {
133+
client = new TcsClient(INVALID_ADDRESS, 100000, VALID_URL, httpClient);
134+
assertThrows(AssertionError.class, () -> client.getCallbackAddress());
135+
}
136+
137+
@Test
138+
public void getCallbackPort_validPort_returnsPort() {
139+
client = new TcsClient(VALID_DOMAIN, VALID_PORT, VALID_URL, httpClient);
140+
assertThat(client.getCallbackPort()).isEqualTo(VALID_PORT);
141+
}
142+
143+
@Test
144+
public void getCallbackPort_invalidPort_throwsError() {
145+
client = new TcsClient(VALID_DOMAIN, 100000, VALID_URL, httpClient);
146+
assertThrows(AssertionError.class, () -> client.getCallbackPort());
147+
}
148+
113149
@Test
114150
public void isVulnerable_sendsValidPollingRequest() throws IOException, InterruptedException {
115151
MockWebServer mockWebServer = new MockWebServer();

0 commit comments

Comments
 (0)