|
38 | 38 | import co.ipregistry.api.client.exceptions.IpregistryException; |
39 | 39 | import co.ipregistry.api.client.model.IpInfo; |
40 | 40 | import co.ipregistry.api.client.model.IpInfoList; |
| 41 | +import co.ipregistry.api.client.model.RequesterIpInfo; |
41 | 42 | import co.ipregistry.api.client.request.DefaultRequestHandler; |
42 | 43 | import org.junit.jupiter.api.Assertions; |
43 | 44 | import org.junit.jupiter.api.Test; |
@@ -164,6 +165,27 @@ void testBatchRequestAllCachedSkipsApiCall() throws IpregistryException { |
164 | 165 | Assertions.assertSame(ipdata1111, response.get(1)); |
165 | 166 | } |
166 | 167 |
|
| 168 | + @Test |
| 169 | + void testOriginIpLookupBypassesCache() throws IpregistryException { |
| 170 | + final IpregistryConfig config = |
| 171 | + IpregistryConfig.builder().apiKey("test").build(); |
| 172 | + |
| 173 | + final IpregistryCache cache = Mockito.spy(new InMemoryCache()); |
| 174 | + final DefaultRequestHandler requestHandler = Mockito.spy(new DefaultRequestHandler(config)); |
| 175 | + |
| 176 | + final RequesterIpInfo originInfo = new RequesterIpInfo(); |
| 177 | + Mockito.doReturn(originInfo).when(requestHandler).lookup(""); |
| 178 | + |
| 179 | + final IpregistryClient client = new IpregistryClient(config, cache, requestHandler); |
| 180 | + |
| 181 | + final RequesterIpInfo response = client.lookup(); |
| 182 | + |
| 183 | + // Origin lookups must never touch the cache, as they cannot be keyed by the actual IP. |
| 184 | + Mockito.verify(cache, Mockito.never()).get(Mockito.anyString()); |
| 185 | + Mockito.verify(cache, Mockito.never()).put(Mockito.anyString(), Mockito.any(IpInfo.class)); |
| 186 | + Assertions.assertSame(originInfo, response); |
| 187 | + } |
| 188 | + |
167 | 189 | @Test |
168 | 190 | void testCloseClosesRequestHandler() throws Exception { |
169 | 191 | final IpregistryConfig config = |
|
0 commit comments