Skip to content

Commit

Permalink
Enfore upper limit for minTtl when using DefaultCacheEntry. (netty#7920)
Browse files Browse the repository at this point in the history
Motivation:

a598c3b 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.
  • Loading branch information
normanmaurer authored May 9, 2018
1 parent a0ed6ec commit f01a590
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ public DefaultDnsCache() {
* @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)");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,19 @@ private static void testExpireWithTTL0(int days) {
}
}

@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 });
Expand Down

0 comments on commit f01a590

Please sign in to comment.