[ONOS-6376] Netconf ssh connection through Apache Mina library
Change-Id: If69fd89afe3082debc3c28a06debfed53426635c
diff --git a/protocols/netconf/ctl/src/test/java/org/onosproject/netconf/ctl/impl/NetconfSessionImplTest.java b/protocols/netconf/ctl/src/test/java/org/onosproject/netconf/ctl/impl/NetconfSessionImplTest.java
index 27223b8..846642c 100644
--- a/protocols/netconf/ctl/src/test/java/org/onosproject/netconf/ctl/impl/NetconfSessionImplTest.java
+++ b/protocols/netconf/ctl/src/test/java/org/onosproject/netconf/ctl/impl/NetconfSessionImplTest.java
@@ -24,7 +24,7 @@
import static org.onosproject.netconf.TargetConfig.RUNNING;
import static org.onosproject.netconf.TargetConfig.CANDIDATE;
-import java.util.ArrayList;
+import java.io.File;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
@@ -35,12 +35,10 @@
import java.util.concurrent.FutureTask;
import java.util.regex.Pattern;
-import org.apache.sshd.SshServer;
import org.apache.sshd.common.NamedFactory;
import org.apache.sshd.server.Command;
-import org.apache.sshd.server.PasswordAuthenticator;
-import org.apache.sshd.server.UserAuth;
-import org.apache.sshd.server.auth.UserAuthPassword;
+import org.apache.sshd.server.SshServer;
+import org.apache.sshd.server.auth.password.PasswordAuthenticator;
import org.apache.sshd.server.keyprovider.SimpleGeneratorHostKeyProvider;
import org.apache.sshd.server.session.ServerSession;
import org.junit.AfterClass;
@@ -59,7 +57,7 @@
/**
* Unit tests for NetconfSession.
- *
+ * <p>
* Sets up an SSH Server with Apache SSHD and connects to it using 2 clients
* Truly verifies that the NETCONF flows are compliant with a NETCONF server.
*/
@@ -77,8 +75,8 @@
private static final String SAMPLE_REQUEST =
"<some-yang-element xmlns=\"some-namespace\">"
- + "<some-child-element/>"
- + "</some-yang-element>";
+ + "<some-child-element/>"
+ + "</some-yang-element>";
private static final String EDIT_CONFIG_REQUEST =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?><rpc message-id=\"6\" "
@@ -112,9 +110,6 @@
@BeforeClass
public static void setUp() throws Exception {
sshServerNetconf = SshServer.setUpDefaultServer();
- List<NamedFactory<UserAuth>> userAuthFactories = new ArrayList<>();
- userAuthFactories.add(new UserAuthPassword.Factory());
- sshServerNetconf.setUserAuthFactories(userAuthFactories);
sshServerNetconf.setPasswordAuthenticator(
new PasswordAuthenticator() {
@Override
@@ -126,7 +121,9 @@
}
});
sshServerNetconf.setPort(PORT_NUMBER);
- sshServerNetconf.setKeyPairProvider(new SimpleGeneratorHostKeyProvider(TEST_SERFILE));
+ SimpleGeneratorHostKeyProvider provider = new SimpleGeneratorHostKeyProvider();
+ provider.setFile(new File(TEST_SERFILE));
+ sshServerNetconf.setKeyPairProvider(provider);
sshServerNetconf.setSubsystemFactories(
Arrays.<NamedFactory<Command>>asList(new NetconfSshdTestSubsystem.Factory()));
sshServerNetconf.open();
@@ -224,10 +221,10 @@
assertNotNull("Incorrect sessionId", session1.getSessionId());
try {
assertTrue("NETCONF get-config running command failed. ",
- GET_REPLY_PATTERN.matcher(session1.getConfig(RUNNING, SAMPLE_REQUEST)).matches());
+ GET_REPLY_PATTERN.matcher(session1.getConfig(RUNNING, SAMPLE_REQUEST)).matches());
assertTrue("NETCONF get-config candidate command failed. ",
- GET_REPLY_PATTERN.matcher(session1.getConfig(CANDIDATE, SAMPLE_REQUEST)).matches());
+ GET_REPLY_PATTERN.matcher(session1.getConfig(CANDIDATE, SAMPLE_REQUEST)).matches());
} catch (NetconfException e) {
e.printStackTrace();
@@ -242,7 +239,7 @@
assertNotNull("Incorrect sessionId", session1.getSessionId());
try {
assertTrue("NETCONF get running command failed. ",
- GET_REPLY_PATTERN.matcher(session1.get(SAMPLE_REQUEST, null)).matches());
+ GET_REPLY_PATTERN.matcher(session1.get(SAMPLE_REQUEST, null)).matches());
} catch (NetconfException e) {
e.printStackTrace();