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 java.io.InputStream;
12 import java.net.InetSocketAddress;
13 import junit.framework.Assert;
14 import org.junit.Test;
15 import org.opendaylight.controller.netconf.ssh.NetconfSSHServer;
16 import org.opendaylight.controller.netconf.ssh.authentication.AuthProvider;
17 import org.slf4j.Logger;
18 import org.slf4j.LoggerFactory;
21 public class SSHServerTest {
23 private static final String USER = "netconf";
24 private static final String PASSWORD = "netconf";
25 private static final String HOST = "127.0.0.1";
26 private static final int PORT = 1830;
27 private static final InetSocketAddress tcpAddress = new InetSocketAddress("127.0.0.1", 8383);
28 private static final Logger logger = LoggerFactory.getLogger(SSHServerTest.class);
29 private Thread sshServerThread;
34 public void startSSHServer() throws Exception{
35 logger.info("Creating SSH server");
36 StubUserManager um = new StubUserManager(USER,PASSWORD);
37 InputStream is = getClass().getResourceAsStream("/RSA.pk");
38 AuthProvider ap = new AuthProvider(um, is);
39 NetconfSSHServer server = NetconfSSHServer.start(PORT,tcpAddress,ap);
40 sshServerThread = new Thread(server);
41 sshServerThread.setDaemon(true);
42 sshServerThread.start();
43 logger.info("SSH server on");
47 public void connect(){
49 this.startSSHServer();
50 Connection conn = new Connection(HOST,PORT);
51 Assert.assertNotNull(conn);
52 logger.info("connecting to SSH server");
54 logger.info("authenticating ...");
55 boolean isAuthenticated = conn.authenticateWithPassword(USER,PASSWORD);
56 Assert.assertTrue(isAuthenticated);
57 } catch (Exception e) {
58 logger.error("Error while starting SSH server.", e);