Skip to content

Commit 3ffc078

Browse files
committed
update old test (getHosting()). rm assert as irrelevant to use case. add new tests for bogon
1 parent edb6e11 commit 3ffc078

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

src/main/java/io/ipinfo/api/request/IPRequest.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,9 +154,6 @@ public IpAddressMatcher(String ipAddress) {
154154
nMaskBits = -1;
155155
}
156156
requiredAddress = parseAddress(ipAddress);
157-
assert (requiredAddress.getAddress().length * 8 >= nMaskBits) :
158-
String.format("IP address %s is too short for bitmask of length %d",
159-
ipAddress, nMaskBits);
160157
}
161158

162159
public boolean matches(String address) {

src/test/java/io/ipinfo/IPinfoTest.java

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,16 @@ public void testGoogleDNS() {
3939
() -> assertFalse(response.getPrivacy().getVpn()),
4040
() -> assertFalse(response.getPrivacy().getTor()),
4141
() -> assertFalse(response.getPrivacy().getRelay()),
42-
() -> assertFalse(response.getPrivacy().getHosting()),
42+
() -> assertTrue(response.getPrivacy().getHosting()),
4343
() -> assertEquals(response.getPrivacy().getService(), ""),
4444
() -> assertEquals(response.getDomains().getDomains().size(), 5)
4545
);
46+
47+
IPResponse bogonResp = ii.lookupIP("2001:0:c000:200::0:255:1");
48+
assertAll("",
49+
() -> assertEquals(bogonResp.getIp(), "2001:0:c000:200::0:255:1"),
50+
() -> assertTrue(bogonResp.getBogon())
51+
);
4652
} catch (RateLimitedException e) {
4753
fail(e);
4854
}
@@ -72,6 +78,7 @@ public void testGetBatch() {
7278
urls.add("AS123");
7379
urls.add("8.8.8.8");
7480
urls.add("9.9.9.9/hostname");
81+
urls.add("239.0.0.0");
7582
ConcurrentHashMap<String, Object> result = ii.getBatch(urls);
7683

7784
assertAll("keys exist",
@@ -107,13 +114,19 @@ public void testGetBatch() {
107114
() -> assertFalse(ipResp.getPrivacy().getVpn()),
108115
() -> assertFalse(ipResp.getPrivacy().getTor()),
109116
() -> assertFalse(ipResp.getPrivacy().getRelay()),
110-
() -> assertFalse(ipResp.getPrivacy().getHosting()),
117+
() -> assertTrue(ipResp.getPrivacy().getHosting()),
111118
() -> assertEquals(ipResp.getPrivacy().getService(), ""),
112119
() -> assertEquals(ipResp.getDomains().getDomains().size(), 5)
113120
);
114121

115122
String hostname = (String)result.get("9.9.9.9/hostname");
116123
assertEquals(hostname, "dns9.quad9.net");
124+
125+
IPResponse bogonResp = (IPResponse)result.get("239.0.0.0");
126+
assertAll("239.0.0.0",
127+
() -> assertEquals(bogonResp.getIp(), "239.0.0.0"),
128+
() -> assertTrue(bogonResp.getBogon())
129+
);
117130
} catch (RateLimitedException e) {
118131
fail(e);
119132
}
@@ -171,7 +184,7 @@ public void testGetBatchIps() {
171184
() -> assertFalse(res2.getPrivacy().getVpn()),
172185
() -> assertFalse(res2.getPrivacy().getTor()),
173186
() -> assertFalse(res2.getPrivacy().getRelay()),
174-
() -> assertFalse(res2.getPrivacy().getHosting()),
187+
() -> assertTrue(res2.getPrivacy().getHosting()),
175188
() -> assertEquals(res2.getPrivacy().getService(), ""),
176189
() -> assertEquals(res2.getDomains().getDomains().size(), 5)
177190
);

0 commit comments

Comments
 (0)