Use NetUtil.LOCALHOST4 instead of InetAddress.getLocalHost()
Motivation: On ubuntu, InetAddress.getLocalHost() will return 127.0.1.1 this causes some tests to fail. NetUtil.LOCALHOST4 is more portable. Modifications: Made changes in EpollSocketTcpMd5Test to make test passing on ubuntu. Result: EpollSocketTcpMd5Test now also passes on ubuntu.
This commit is contained in:
parent
c372f69118
commit
4f40913b33
@ -25,6 +25,7 @@ import java.net.InetAddress;
|
|||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
|
||||||
|
import io.netty.util.NetUtil;
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.AfterClass;
|
import org.junit.AfterClass;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
@ -63,8 +64,8 @@ public class EpollSocketTcpMd5Test {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testServerSocketChannelOption() throws Exception {
|
public void testServerSocketChannelOption() throws Exception {
|
||||||
server.config().setOption(EpollChannelOption.TCP_MD5SIG, Collections.singletonMap(InetAddress.getLocalHost(),
|
server.config().setOption(EpollChannelOption.TCP_MD5SIG,
|
||||||
SERVER_KEY));
|
Collections.<InetAddress, byte[]>singletonMap(NetUtil.LOCALHOST4, SERVER_KEY));
|
||||||
server.config().setOption(EpollChannelOption.TCP_MD5SIG, Collections.<InetAddress, byte[]>emptyMap());
|
server.config().setOption(EpollChannelOption.TCP_MD5SIG, Collections.<InetAddress, byte[]>emptyMap());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -76,8 +77,8 @@ public class EpollSocketTcpMd5Test {
|
|||||||
.handler(new ChannelInboundHandlerAdapter())
|
.handler(new ChannelInboundHandlerAdapter())
|
||||||
.bind(new InetSocketAddress(0)).syncUninterruptibly().channel();
|
.bind(new InetSocketAddress(0)).syncUninterruptibly().channel();
|
||||||
|
|
||||||
ch.config().setOption(EpollChannelOption.TCP_MD5SIG, Collections.singletonMap(InetAddress.getLocalHost(),
|
ch.config().setOption(EpollChannelOption.TCP_MD5SIG,
|
||||||
SERVER_KEY));
|
Collections.<InetAddress, byte[]>singletonMap(NetUtil.LOCALHOST4, SERVER_KEY));
|
||||||
ch.config().setOption(EpollChannelOption.TCP_MD5SIG, Collections.<InetAddress, byte[]>emptyMap());
|
ch.config().setOption(EpollChannelOption.TCP_MD5SIG, Collections.<InetAddress, byte[]>emptyMap());
|
||||||
|
|
||||||
ch.close().syncUninterruptibly();
|
ch.close().syncUninterruptibly();
|
||||||
@ -85,28 +86,28 @@ public class EpollSocketTcpMd5Test {
|
|||||||
|
|
||||||
@Test(expected = ConnectTimeoutException.class)
|
@Test(expected = ConnectTimeoutException.class)
|
||||||
public void testKeyMismatch() throws Exception {
|
public void testKeyMismatch() throws Exception {
|
||||||
server.config().setOption(EpollChannelOption.TCP_MD5SIG, Collections.singletonMap(InetAddress.getLocalHost(),
|
server.config().setOption(EpollChannelOption.TCP_MD5SIG,
|
||||||
SERVER_KEY));
|
Collections.<InetAddress, byte[]>singletonMap(NetUtil.LOCALHOST4, SERVER_KEY));
|
||||||
|
|
||||||
EpollSocketChannel client = (EpollSocketChannel) new Bootstrap().group(GROUP)
|
EpollSocketChannel client = (EpollSocketChannel) new Bootstrap().group(GROUP)
|
||||||
.channel(EpollSocketChannel.class)
|
.channel(EpollSocketChannel.class)
|
||||||
.handler(new ChannelInboundHandlerAdapter())
|
.handler(new ChannelInboundHandlerAdapter())
|
||||||
.option(EpollChannelOption.TCP_MD5SIG,
|
.option(EpollChannelOption.TCP_MD5SIG,
|
||||||
Collections.singletonMap(InetAddress.getLocalHost(), BAD_KEY))
|
Collections.<InetAddress, byte[]>singletonMap(NetUtil.LOCALHOST4, BAD_KEY))
|
||||||
.connect(server.localAddress()).syncUninterruptibly().channel();
|
.connect(server.localAddress()).syncUninterruptibly().channel();
|
||||||
client.close().syncUninterruptibly();
|
client.close().syncUninterruptibly();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testKeyMatch() throws Exception {
|
public void testKeyMatch() throws Exception {
|
||||||
server.config().setOption(EpollChannelOption.TCP_MD5SIG, Collections.singletonMap(InetAddress.getLocalHost(),
|
server.config().setOption(EpollChannelOption.TCP_MD5SIG,
|
||||||
SERVER_KEY));
|
Collections.<InetAddress, byte[]>singletonMap(NetUtil.LOCALHOST4, SERVER_KEY));
|
||||||
|
|
||||||
EpollSocketChannel client = (EpollSocketChannel) new Bootstrap().group(GROUP)
|
EpollSocketChannel client = (EpollSocketChannel) new Bootstrap().group(GROUP)
|
||||||
.channel(EpollSocketChannel.class)
|
.channel(EpollSocketChannel.class)
|
||||||
.handler(new ChannelInboundHandlerAdapter())
|
.handler(new ChannelInboundHandlerAdapter())
|
||||||
.option(EpollChannelOption.TCP_MD5SIG,
|
.option(EpollChannelOption.TCP_MD5SIG,
|
||||||
Collections.singletonMap(InetAddress.getLocalHost(), SERVER_KEY))
|
Collections.<InetAddress, byte[]>singletonMap(NetUtil.LOCALHOST4, SERVER_KEY))
|
||||||
.connect(server.localAddress()).syncUninterruptibly().channel();
|
.connect(server.localAddress()).syncUninterruptibly().channel();
|
||||||
client.close().syncUninterruptibly();
|
client.close().syncUninterruptibly();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user