X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fnetconf%2Fnetconf-ssh%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fnetconf%2Fnetty%2FSSHTest.java;h=2802488170ef9cc9ef6d27b3846592b19219ca9b;hb=ee0877c07ff700157dd9fc2e445df095c88f79bc;hp=62ce58723765231d2c4edd8683cb5e18093c09fe;hpb=ff6341706412a7c4b9f2ce0817687342d479f9de;p=controller.git diff --git a/opendaylight/netconf/netconf-ssh/src/test/java/org/opendaylight/controller/netconf/netty/SSHTest.java b/opendaylight/netconf/netconf-ssh/src/test/java/org/opendaylight/controller/netconf/netty/SSHTest.java index 62ce587237..2802488170 100644 --- a/opendaylight/netconf/netconf-ssh/src/test/java/org/opendaylight/controller/netconf/netty/SSHTest.java +++ b/opendaylight/netconf/netconf-ssh/src/test/java/org/opendaylight/controller/netconf/netty/SSHTest.java @@ -19,6 +19,7 @@ import io.netty.channel.EventLoopGroup; import io.netty.channel.nio.NioEventLoopGroup; import io.netty.channel.socket.nio.NioSocketChannel; import io.netty.util.HashedWheelTimer; +import java.io.File; import java.net.InetSocketAddress; import java.nio.file.Files; import java.util.concurrent.ExecutorService; @@ -35,12 +36,13 @@ import org.opendaylight.controller.netconf.netty.EchoClientHandler.State; import org.opendaylight.controller.netconf.nettyutil.handler.ssh.authentication.LoginPassword; import org.opendaylight.controller.netconf.nettyutil.handler.ssh.client.AsyncSshHandler; import org.opendaylight.controller.netconf.ssh.SshProxyServer; +import org.opendaylight.controller.netconf.ssh.SshProxyServerConfigurationBuilder; import org.opendaylight.controller.netconf.util.osgi.NetconfConfigUtil; import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class SSHTest { - public static final Logger logger = LoggerFactory.getLogger(SSHTest.class); + private static final Logger LOG = LoggerFactory.getLogger(SSHTest.class); public static final String AHOJ = "ahoj\n"; private static EventLoopGroup nettyGroup; @@ -66,17 +68,19 @@ public class SSHTest { @Test public void test() throws Exception { + File sshKeyPair = Files.createTempFile("sshKeyPair", ".pem").toFile(); + sshKeyPair.deleteOnExit(); new Thread(new EchoServer(), "EchoServer").start(); final InetSocketAddress addr = new InetSocketAddress("127.0.0.1", 10831); final SshProxyServer sshProxyServer = new SshProxyServer(minaTimerEx, nettyGroup, nioExec); - sshProxyServer.bind(addr, NetconfConfigUtil.getNetconfLocalAddress(), - new PasswordAuthenticator() { + sshProxyServer.bind( + new SshProxyServerConfigurationBuilder().setBindingAddress(addr).setLocalAddress(NetconfConfigUtil.getNetconfLocalAddress()).setAuthenticator(new PasswordAuthenticator() { @Override public boolean authenticate(final String username, final String password, final ServerSession session) { return true; } - }, new PEMGeneratorHostKeyProvider(Files.createTempFile("prefix", "suffix").toAbsolutePath().toString())); + }).setKeyPairProvider(new PEMGeneratorHostKeyProvider(sshKeyPair.toPath().toAbsolutePath().toString())).setIdleTimeout(Integer.MAX_VALUE).createSshProxyServerConfiguration()); final EchoClientHandler echoClientHandler = connectClient(addr); @@ -85,7 +89,7 @@ public class SSHTest { Thread.sleep(500); } assertTrue(echoClientHandler.isConnected()); - logger.info("connected, writing to client"); + LOG.info("connected, writing to client"); echoClientHandler.write(AHOJ); // check that server sent back the same string @@ -98,7 +102,7 @@ public class SSHTest { final String read = echoClientHandler.read(); assertTrue(read + " should end with " + AHOJ, read.endsWith(AHOJ)); } finally { - logger.info("Closing socket"); + LOG.info("Closing socket"); sshProxyServer.close(); } }