forked from netty/netty
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DnsNameResolver.resolve*(...) never notifies the Future when empty ho…
…stname is used. Motivation: When an empty hostname is used in DnsNameResolver.resolve*(...) it will never notify the future / promise. The root cause is that we not correctly guard against errors of IDN.toASCII(...) which will throw an IllegalArgumentException when it can not parse its input. That said we should also handle an empty hostname the same way as the JDK does and just use "localhost" when this happens. Modifications: - If the try to resolve an empty hostname we use localhost - Correctly guard against errors raised by IDN.toASCII(...) so we will always noify the future / promise - Add unit test. Result: DnsNameResolver.resolve*(...) will always notify the future.
- Loading branch information
1 parent
640ef61
commit a416b79
Showing
7 changed files
with
239 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
resolver/src/test/java/io/netty/resolver/InetNameResolverTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/*@ | ||
* Copyright 2017 The Netty Project | ||
* | ||
* The Netty Project licenses this file to you under the Apache License, | ||
* version 2.0 (the "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at: | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package io.netty.resolver; | ||
|
||
import io.netty.util.concurrent.ImmediateEventExecutor; | ||
import io.netty.util.concurrent.Promise; | ||
import io.netty.util.internal.SocketUtils; | ||
import io.netty.util.internal.StringUtil; | ||
import org.junit.Test; | ||
|
||
import java.net.InetAddress; | ||
import java.net.UnknownHostException; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
public class InetNameResolverTest { | ||
|
||
@Test | ||
public void testResolveEmpty() throws UnknownHostException { | ||
testResolve0(SocketUtils.addressByName(StringUtil.EMPTY_STRING), StringUtil.EMPTY_STRING); | ||
} | ||
|
||
@Test | ||
public void testResolveNull() throws UnknownHostException { | ||
testResolve0(SocketUtils.addressByName(null), null); | ||
} | ||
|
||
@Test | ||
public void testResolveAllEmpty() throws UnknownHostException { | ||
testResolveAll0(Arrays.asList( | ||
SocketUtils.allAddressesByName(StringUtil.EMPTY_STRING)), StringUtil.EMPTY_STRING); | ||
} | ||
|
||
@Test | ||
public void testResolveAllNull() throws UnknownHostException { | ||
testResolveAll0(Arrays.asList( | ||
SocketUtils.allAddressesByName(null)), null); | ||
} | ||
|
||
private static void testResolve0(InetAddress expectedAddr, String name) { | ||
InetNameResolver resolver = new TestInetNameResolver(); | ||
try { | ||
InetAddress address = resolver.resolve(name).syncUninterruptibly().getNow(); | ||
assertEquals(expectedAddr, address); | ||
} finally { | ||
resolver.close(); | ||
} | ||
} | ||
|
||
private static void testResolveAll0(List<InetAddress> expectedAddrs, String name) { | ||
InetNameResolver resolver = new TestInetNameResolver(); | ||
try { | ||
List<InetAddress> addresses = resolver.resolveAll(name).syncUninterruptibly().getNow(); | ||
assertEquals(expectedAddrs, addresses); | ||
} finally { | ||
resolver.close(); | ||
} | ||
} | ||
|
||
private static final class TestInetNameResolver extends InetNameResolver { | ||
public TestInetNameResolver() { | ||
super(ImmediateEventExecutor.INSTANCE); | ||
} | ||
|
||
@Override | ||
protected void doResolve(String inetHost, Promise<InetAddress> promise) throws Exception { | ||
promise.setFailure(new UnsupportedOperationException()); | ||
} | ||
|
||
@Override | ||
protected void doResolveAll(String inetHost, Promise<List<InetAddress>> promise) throws Exception { | ||
promise.setFailure(new UnsupportedOperationException()); | ||
} | ||
} | ||
} |