2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.controller.netconf;
10 import ch.ethz.ssh2.Connection;
11 import junit.framework.Assert;
12 import org.apache.commons.io.IOUtils;
13 import org.junit.Test;
14 import org.opendaylight.controller.netconf.ssh.NetconfSSHServer;
15 import org.opendaylight.controller.netconf.ssh.authentication.AuthProvider;
16 import org.slf4j.Logger;
17 import org.slf4j.LoggerFactory;
19 import java.io.InputStream;
20 import java.net.InetSocketAddress;
23 public class SSHServerTest {
25 private static final String USER = "netconf";
26 private static final String PASSWORD = "netconf";
27 private static final String HOST = "127.0.0.1";
28 private static final int PORT = 1830;
29 private static final InetSocketAddress tcpAddress = new InetSocketAddress("127.0.0.1", 8383);
30 private static final Logger logger = LoggerFactory.getLogger(SSHServerTest.class);
31 private Thread sshServerThread;
36 public void startSSHServer() throws Exception{
37 logger.info("Creating SSH server");
38 StubUserManager um = new StubUserManager(USER,PASSWORD);
40 try(InputStream is = getClass().getResourceAsStream("/RSA.pk")) {
41 pem = IOUtils.toString(is);
43 AuthProvider ap = new AuthProvider(um, pem);
44 NetconfSSHServer server = NetconfSSHServer.start(PORT,tcpAddress,ap);
45 sshServerThread = new Thread(server);
46 sshServerThread.setDaemon(true);
47 sshServerThread.start();
48 logger.info("SSH server on");
52 public void connect(){
54 this.startSSHServer();
55 Connection conn = new Connection(HOST,PORT);
56 Assert.assertNotNull(conn);
57 logger.info("connecting to SSH server");
59 logger.info("authenticating ...");
60 boolean isAuthenticated = conn.authenticateWithPassword(USER,PASSWORD);
61 Assert.assertTrue(isAuthenticated);
62 } catch (Exception e) {
63 logger.error("Error while starting SSH server.", e);