Enfore upper limit for minTtl when using DefaultCacheEntry. (#7920)

Motivation:

a598c3b69b added a upper limit for ttl but missed to also do the same for minTtl.

Modifications:

- Add upper limit for minTtl
- Add testcase.

Result:

No more IllegalArgumentException possible.
This commit is contained in:
Norman Maurer 2018-05-09 08:57:20 +02:00 committed by GitHub
parent a0ed6ec06c
commit f01a590154
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 2 deletions

View File

@ -65,8 +65,8 @@ public class DefaultDnsCache implements DnsCache {
* @param negativeTtl the TTL for failed queries
*/
public DefaultDnsCache(int minTtl, int maxTtl, int negativeTtl) {
this.minTtl = checkPositiveOrZero(minTtl, "minTtl");
this.maxTtl = checkPositiveOrZero(maxTtl, "maxTtl");
this.minTtl = Math.min(MAX_SUPPORTED_TTL_SECS, checkPositiveOrZero(minTtl, "minTtl"));
this.maxTtl = Math.min(MAX_SUPPORTED_TTL_SECS, checkPositiveOrZero(maxTtl, "maxTtl"));
if (minTtl > maxTtl) {
throw new IllegalArgumentException(
"minTtl: " + minTtl + ", maxTtl: " + maxTtl + " (expected: 0 <= minTtl <= maxTtl)");

View File

@ -86,6 +86,19 @@ public class DefaultDnsCacheTest {
}
}
@Test
public void testExpireWithToBigMinTTL() {
EventLoopGroup group = new NioEventLoopGroup(1);
try {
EventLoop loop = group.next();
final DefaultDnsCache cache = new DefaultDnsCache(Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE);
assertNotNull(cache.cache("netty.io", null, NetUtil.LOCALHOST, 100, loop));
} finally {
group.shutdownGracefully();
}
}
@Test
public void testAddMultipleAddressesForSameHostname() throws Exception {
InetAddress addr1 = InetAddress.getByAddress(new byte[] { 10, 0, 0, 1 });