You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mina.apache.org by lg...@apache.org on 2015/09/02 07:40:01 UTC
[2/4] mina-sshd git commit: [SSHD-559] Add support for reading
specific host configuration from config file
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/950e896d/sshd-core/src/test/java/org/apache/sshd/PortForwardingLoadTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/PortForwardingLoadTest.java b/sshd-core/src/test/java/org/apache/sshd/PortForwardingLoadTest.java
index 589bf13..0d845fe 100644
--- a/sshd-core/src/test/java/org/apache/sshd/PortForwardingLoadTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/PortForwardingLoadTest.java
@@ -51,8 +51,6 @@ import org.apache.mina.transport.socket.nio.NioSocketAcceptor;
import org.apache.sshd.server.SshServer;
import org.apache.sshd.server.forward.AcceptAllForwardingFilter;
import org.apache.sshd.util.BaseTestSupport;
-import org.apache.sshd.util.BogusPasswordAuthenticator;
-import org.apache.sshd.util.EchoShellFactory;
import org.apache.sshd.util.JSchLogger;
import org.apache.sshd.util.SimpleUserInfo;
import org.apache.sshd.util.Utils;
@@ -83,10 +81,7 @@ public class PortForwardingLoadTest extends BaseTestSupport {
@Before
public void setUp() throws Exception {
- sshd = SshServer.setUpDefaultServer();
- sshd.setKeyPairProvider(Utils.createTestHostKeyProvider());
- sshd.setShellFactory(new EchoShellFactory());
- sshd.setPasswordAuthenticator(BogusPasswordAuthenticator.INSTANCE);
+ sshd = Utils.setupTestServer();
sshd.setTcpipForwardingFilter(AcceptAllForwardingFilter.INSTANCE);
sshd.start();
sshPort = sshd.getPort();
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/950e896d/sshd-core/src/test/java/org/apache/sshd/PortForwardingTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/PortForwardingTest.java b/sshd-core/src/test/java/org/apache/sshd/PortForwardingTest.java
index 5dfc8e2..e2b0029 100644
--- a/sshd-core/src/test/java/org/apache/sshd/PortForwardingTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/PortForwardingTest.java
@@ -60,8 +60,6 @@ import org.apache.sshd.server.forward.AcceptAllForwardingFilter;
import org.apache.sshd.server.global.CancelTcpipForwardHandler;
import org.apache.sshd.server.global.TcpipForwardHandler;
import org.apache.sshd.util.BaseTestSupport;
-import org.apache.sshd.util.BogusPasswordAuthenticator;
-import org.apache.sshd.util.EchoShellFactory;
import org.apache.sshd.util.JSchLogger;
import org.apache.sshd.util.SimpleUserInfo;
import org.apache.sshd.util.Utils;
@@ -92,12 +90,9 @@ public class PortForwardingTest extends BaseTestSupport {
@Before
public void setUp() throws Exception {
- sshd = SshServer.setUpDefaultServer();
+ sshd = Utils.setupTestServer();
FactoryManagerUtils.updateProperty(sshd, FactoryManager.WINDOW_SIZE, 2048);
FactoryManagerUtils.updateProperty(sshd, FactoryManager.MAX_PACKET_SIZE, 256);
- sshd.setKeyPairProvider(Utils.createTestHostKeyProvider());
- sshd.setShellFactory(new EchoShellFactory());
- sshd.setPasswordAuthenticator(BogusPasswordAuthenticator.INSTANCE);
sshd.setTcpipForwardingFilter(AcceptAllForwardingFilter.INSTANCE);
sshd.start();
@@ -598,7 +593,7 @@ public class PortForwardingTest extends BaseTestSupport {
}
protected ClientSession createNativeSession() throws Exception {
- client = SshClient.setUpDefaultClient();
+ client = Utils.setupTestClient();
FactoryManagerUtils.updateProperty(client, FactoryManager.WINDOW_SIZE, 2048);
FactoryManagerUtils.updateProperty(client, FactoryManager.MAX_PACKET_SIZE, 256);
client.setTcpipForwardingFilter(AcceptAllForwardingFilter.INSTANCE);
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/950e896d/sshd-core/src/test/java/org/apache/sshd/ProxyTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/ProxyTest.java b/sshd-core/src/test/java/org/apache/sshd/ProxyTest.java
index 8636bd2..1e84b29 100644
--- a/sshd-core/src/test/java/org/apache/sshd/ProxyTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/ProxyTest.java
@@ -40,8 +40,6 @@ import org.apache.sshd.common.SshdSocketAddress;
import org.apache.sshd.server.SshServer;
import org.apache.sshd.server.forward.AcceptAllForwardingFilter;
import org.apache.sshd.util.BaseTestSupport;
-import org.apache.sshd.util.BogusPasswordAuthenticator;
-import org.apache.sshd.util.EchoShellFactory;
import org.apache.sshd.util.Utils;
import org.junit.After;
import org.junit.Before;
@@ -62,12 +60,9 @@ public class ProxyTest extends BaseTestSupport {
@Before
public void setUp() throws Exception {
- sshd = SshServer.setUpDefaultServer();
+ sshd = Utils.setupTestServer();
FactoryManagerUtils.updateProperty(sshd, FactoryManager.WINDOW_SIZE, 2048);
FactoryManagerUtils.updateProperty(sshd, FactoryManager.MAX_PACKET_SIZE, "256");
- sshd.setKeyPairProvider(Utils.createTestHostKeyProvider());
- sshd.setShellFactory(new EchoShellFactory());
- sshd.setPasswordAuthenticator(BogusPasswordAuthenticator.INSTANCE);
sshd.setTcpipForwardingFilter(AcceptAllForwardingFilter.INSTANCE);
sshd.start();
sshPort = sshd.getPort();
@@ -145,7 +140,7 @@ public class ProxyTest extends BaseTestSupport {
}
protected ClientSession createNativeSession() throws Exception {
- client = SshClient.setUpDefaultClient();
+ client = Utils.setupTestClient();
FactoryManagerUtils.updateProperty(client, FactoryManager.WINDOW_SIZE, 2048);
FactoryManagerUtils.updateProperty(client, FactoryManager.MAX_PACKET_SIZE, 256);
client.setTcpipForwardingFilter(AcceptAllForwardingFilter.INSTANCE);
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/950e896d/sshd-core/src/test/java/org/apache/sshd/SinglePublicKeyAuthTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/SinglePublicKeyAuthTest.java b/sshd-core/src/test/java/org/apache/sshd/SinglePublicKeyAuthTest.java
index 99445fe..eacdc6c 100644
--- a/sshd-core/src/test/java/org/apache/sshd/SinglePublicKeyAuthTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/SinglePublicKeyAuthTest.java
@@ -30,14 +30,11 @@ import org.apache.sshd.client.session.ClientSession;
import org.apache.sshd.common.FactoryManagerUtils;
import org.apache.sshd.common.config.keys.KeyUtils;
import org.apache.sshd.common.keyprovider.KeyPairProvider;
-import org.apache.sshd.server.Command;
-import org.apache.sshd.server.CommandFactory;
import org.apache.sshd.server.ServerFactoryManager;
import org.apache.sshd.server.SshServer;
import org.apache.sshd.server.auth.CachingPublicKeyAuthenticator;
import org.apache.sshd.server.auth.UserAuthPublicKeyFactory;
import org.apache.sshd.server.auth.pubkey.PublickeyAuthenticator;
-import org.apache.sshd.server.command.UnknownCommand;
import org.apache.sshd.server.keyprovider.SimpleGeneratorHostKeyProvider;
import org.apache.sshd.server.session.ServerSession;
import org.apache.sshd.util.BaseTestSupport;
@@ -70,14 +67,7 @@ public class SinglePublicKeyAuthTest extends BaseTestSupport {
@Before
public void setUp() throws Exception {
- sshd = SshServer.setUpDefaultServer();
- sshd.setKeyPairProvider(Utils.createTestHostKeyProvider());
- sshd.setCommandFactory(new CommandFactory() {
- @Override
- public Command createCommand(String command) {
- return new UnknownCommand(command);
- }
- });
+ sshd = Utils.setupTestServer();
FactoryManagerUtils.updateProperty(sshd, ServerFactoryManager.AUTH_METHODS, UserAuthPublicKeyFactory.NAME);
sshd.setPublickeyAuthenticator(new PublickeyAuthenticator() {
@SuppressWarnings("synthetic-access")
@@ -111,7 +101,7 @@ public class SinglePublicKeyAuthTest extends BaseTestSupport {
});
delegate = auth;
- try (SshClient client = SshClient.setUpDefaultClient()) {
+ try (SshClient client = Utils.setupTestClient()) {
client.start();
try (ClientSession session = client.connect(getCurrentTestName(), "localhost", port).verify(7L, TimeUnit.SECONDS).getSession()) {
@@ -147,7 +137,7 @@ public class SinglePublicKeyAuthTest extends BaseTestSupport {
}
};
- try (SshClient client = SshClient.setUpDefaultClient()) {
+ try (SshClient client = Utils.setupTestClient()) {
client.start();
try (ClientSession session = client.connect(getCurrentTestName(), "localhost", port).verify(7L, TimeUnit.SECONDS).getSession()) {
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/950e896d/sshd-core/src/test/java/org/apache/sshd/WelcomeBannerTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/WelcomeBannerTest.java b/sshd-core/src/test/java/org/apache/sshd/WelcomeBannerTest.java
index a71cd1a..e3c1d13 100644
--- a/sshd-core/src/test/java/org/apache/sshd/WelcomeBannerTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/WelcomeBannerTest.java
@@ -27,9 +27,7 @@ import org.apache.sshd.client.session.ClientSession;
import org.apache.sshd.common.FactoryManagerUtils;
import org.apache.sshd.server.ServerFactoryManager;
import org.apache.sshd.server.SshServer;
-import org.apache.sshd.server.auth.pubkey.AcceptAllPublickeyAuthenticator;
import org.apache.sshd.util.BaseTestSupport;
-import org.apache.sshd.util.BogusPasswordAuthenticator;
import org.apache.sshd.util.Utils;
import org.junit.After;
import org.junit.Before;
@@ -47,10 +45,7 @@ public class WelcomeBannerTest extends BaseTestSupport {
@Before
public void setUp() throws Exception {
- sshd = SshServer.setUpDefaultServer();
- sshd.setKeyPairProvider(Utils.createTestHostKeyProvider());
- sshd.setPasswordAuthenticator(BogusPasswordAuthenticator.INSTANCE);
- sshd.setPublickeyAuthenticator(AcceptAllPublickeyAuthenticator.INSTANCE);
+ sshd = Utils.setupTestServer();
FactoryManagerUtils.updateProperty(sshd, ServerFactoryManager.WELCOME_BANNER, WELCOME);
sshd.start();
port = sshd.getPort();
@@ -67,7 +62,7 @@ public class WelcomeBannerTest extends BaseTestSupport {
public void testBanner() throws Exception {
final AtomicReference<String> welcome = new AtomicReference<String>();
- try (SshClient client = SshClient.setUpDefaultClient()) {
+ try (SshClient client = Utils.setupTestClient()) {
client.setUserInteraction(new UserInteraction() {
@Override
public void welcome(String banner) {
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/950e896d/sshd-core/src/test/java/org/apache/sshd/WindowAdjustTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/WindowAdjustTest.java b/sshd-core/src/test/java/org/apache/sshd/WindowAdjustTest.java
index 4e02001..1b66d6f 100644
--- a/sshd-core/src/test/java/org/apache/sshd/WindowAdjustTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/WindowAdjustTest.java
@@ -46,7 +46,7 @@ import org.apache.sshd.server.Environment;
import org.apache.sshd.server.ExitCallback;
import org.apache.sshd.server.SshServer;
import org.apache.sshd.server.keyprovider.SimpleGeneratorHostKeyProvider;
-import org.apache.sshd.util.BogusPasswordAuthenticator;
+import org.apache.sshd.util.Utils;
import org.junit.After;
import org.junit.Before;
import org.junit.FixMethodOrder;
@@ -71,7 +71,7 @@ public class WindowAdjustTest {
@Before
public void setUp() throws Exception {
- sshServer = SshServer.setUpDefaultServer();
+ sshServer = Utils.setupTestServer();
final byte[] msg = Files.readAllBytes(
Paths.get(getClass().getResource("/big-msg.txt").toURI()));
@@ -82,7 +82,6 @@ public class WindowAdjustTest {
}
});
- sshServer.setPasswordAuthenticator(BogusPasswordAuthenticator.INSTANCE);
sshServer.setKeyPairProvider(new SimpleGeneratorHostKeyProvider());
sshServer.start();
port = sshServer.getPort();
@@ -99,7 +98,7 @@ public class WindowAdjustTest {
@Test(timeout = 2L * 60L * 1000L)
public void testTrafficHeavyLoad() throws Exception {
- try (SshClient client = SshClient.setUpDefaultClient()) {
+ try (SshClient client = Utils.setupTestClient()) {
client.start();
try (final ClientSession session = client.connect("admin", "localhost", port).verify(7L, TimeUnit.SECONDS).getSession()) {
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/950e896d/sshd-core/src/test/java/org/apache/sshd/agent/AgentTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/agent/AgentTest.java b/sshd-core/src/test/java/org/apache/sshd/agent/AgentTest.java
index 397f162..2917837 100644
--- a/sshd-core/src/test/java/org/apache/sshd/agent/AgentTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/agent/AgentTest.java
@@ -40,10 +40,9 @@ import org.apache.sshd.common.util.SecurityUtils;
import org.apache.sshd.server.Command;
import org.apache.sshd.server.Environment;
import org.apache.sshd.server.SshServer;
-import org.apache.sshd.server.auth.pubkey.AcceptAllPublickeyAuthenticator;
import org.apache.sshd.server.forward.AcceptAllForwardingFilter;
import org.apache.sshd.util.BaseTestSupport;
-import org.apache.sshd.util.BogusPasswordAuthenticator;
+import org.apache.sshd.util.EchoShell;
import org.apache.sshd.util.EchoShellFactory;
import org.apache.sshd.util.Utils;
import org.junit.Assume;
@@ -107,27 +106,21 @@ public class AgentTest extends BaseTestSupport {
KeyPair pair = createTestKeyPairProvider("dsaprivkey.pem").loadKey(KeyPairProvider.SSH_DSS);
localAgentFactory.getAgent().addIdentity(pair, username);
- try (SshServer sshd1 = SshServer.setUpDefaultServer()) {
- sshd1.setKeyPairProvider(Utils.createTestHostKeyProvider());
+ try (SshServer sshd1 = Utils.setupTestServer()) {
sshd1.setShellFactory(shellFactory);
- sshd1.setPasswordAuthenticator(BogusPasswordAuthenticator.INSTANCE);
- sshd1.setPublickeyAuthenticator(AcceptAllPublickeyAuthenticator.INSTANCE);
sshd1.setAgentFactory(agentFactory);
sshd1.setTcpipForwardingFilter(AcceptAllForwardingFilter.INSTANCE);
sshd1.start();
final int port1 = sshd1.getPort();
- try (SshServer sshd2 = SshServer.setUpDefaultServer()) {
- sshd2.setKeyPairProvider(Utils.createTestHostKeyProvider());
+ try (SshServer sshd2 = Utils.setupTestServer()) {
sshd2.setShellFactory(new TestEchoShellFactory());
- sshd2.setPasswordAuthenticator(BogusPasswordAuthenticator.INSTANCE);
- sshd2.setPublickeyAuthenticator(AcceptAllPublickeyAuthenticator.INSTANCE);
sshd1.setTcpipForwardingFilter(AcceptAllForwardingFilter.INSTANCE);
sshd2.setAgentFactory(new ProxyAgentFactory());
sshd2.start();
final int port2 = sshd2.getPort();
- try (SshClient client1 = SshClient.setUpDefaultClient()) {
+ try (SshClient client1 = Utils.setupTestClient()) {
client1.setAgentFactory(localAgentFactory);
client1.start();
@@ -151,7 +144,7 @@ public class AgentTest extends BaseTestSupport {
}
}
- try (SshClient client2 = SshClient.setUpDefaultClient()) {
+ try (SshClient client2 = Utils.setupTestClient()) {
client2.setAgentFactory(agentFactory);
client2.getProperties().putAll(shellFactory.shell.getEnvironment().getEnv());
client2.start();
@@ -190,24 +183,22 @@ public class AgentTest extends BaseTestSupport {
}
public static class TestEchoShellFactory extends EchoShellFactory {
-
- TestEchoShell shell = new TestEchoShell();
+ public final TestEchoShell shell = new TestEchoShell();
@Override
public Command create() {
return shell;
}
+ }
- public class TestEchoShell extends EchoShell {
-
- boolean started;
+ public static class TestEchoShell extends EchoShell {
+ public boolean started;
- @Override
- public synchronized void start(Environment env) throws IOException {
- super.start(env);
- started = true;
- notifyAll();
- }
+ @Override
+ public synchronized void start(Environment env) throws IOException {
+ super.start(env);
+ started = true;
+ notifyAll();
}
}
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/950e896d/sshd-core/src/test/java/org/apache/sshd/client/ClientTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/client/ClientTest.java b/sshd-core/src/test/java/org/apache/sshd/client/ClientTest.java
index 7713b2d..604b39c 100644
--- a/sshd-core/src/test/java/org/apache/sshd/client/ClientTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/client/ClientTest.java
@@ -94,13 +94,10 @@ import org.apache.sshd.common.util.buffer.Buffer;
import org.apache.sshd.common.util.buffer.ByteArrayBuffer;
import org.apache.sshd.common.util.io.NoCloseOutputStream;
import org.apache.sshd.server.Command;
-import org.apache.sshd.server.CommandFactory;
import org.apache.sshd.server.SshServer;
-import org.apache.sshd.server.auth.pubkey.AcceptAllPublickeyAuthenticator;
import org.apache.sshd.server.auth.pubkey.PublickeyAuthenticator;
import org.apache.sshd.server.channel.ChannelSession;
import org.apache.sshd.server.channel.ChannelSessionFactory;
-import org.apache.sshd.server.command.UnknownCommand;
import org.apache.sshd.server.forward.DirectTcpipFactory;
import org.apache.sshd.server.keyprovider.SimpleGeneratorHostKeyProvider;
import org.apache.sshd.server.session.ServerConnectionServiceFactory;
@@ -110,7 +107,7 @@ import org.apache.sshd.server.session.ServerUserAuthServiceFactory;
import org.apache.sshd.server.subsystem.sftp.SftpSubsystemFactory;
import org.apache.sshd.util.AsyncEchoShellFactory;
import org.apache.sshd.util.BaseTestSupport;
-import org.apache.sshd.util.BogusPasswordAuthenticator;
+import org.apache.sshd.util.EchoShell;
import org.apache.sshd.util.EchoShellFactory;
import org.apache.sshd.util.TeeOutputStream;
import org.apache.sshd.util.Utils;
@@ -167,17 +164,8 @@ public class ClientTest extends BaseTestSupport {
authLatch = new CountDownLatch(0);
channelLatch = new CountDownLatch(0);
- sshd = SshServer.setUpDefaultServer();
- sshd.setKeyPairProvider(Utils.createTestHostKeyProvider());
+ sshd = Utils.setupTestServer();
sshd.setShellFactory(new TestEchoShellFactory());
- sshd.setCommandFactory(new CommandFactory() {
- @Override
- public Command createCommand(String command) {
- return new UnknownCommand(command);
- }
- });
- sshd.setPasswordAuthenticator(BogusPasswordAuthenticator.INSTANCE);
- sshd.setPublickeyAuthenticator(AcceptAllPublickeyAuthenticator.INSTANCE);
sshd.setServiceFactories(Arrays.asList(
new ServerUserAuthServiceFactory() {
@Override
@@ -221,7 +209,7 @@ public class ClientTest extends BaseTestSupport {
sshd.start();
port = sshd.getPort();
- client = SshClient.setUpDefaultClient();
+ client = Utils.setupTestClient();
clientSessionHolder.set(null); // just making sure
client.addSessionListener(clientSessionListener);
}
@@ -1164,7 +1152,7 @@ public class ClientTest extends BaseTestSupport {
@Test
public void testClientDisconnect() throws Exception {
- TestEchoShellFactory.TestEchoShell.latch = new CountDownLatch(1);
+ TestEchoShell.latch = new CountDownLatch(1);
try {
client.start();
@@ -1191,14 +1179,14 @@ public class ClientTest extends BaseTestSupport {
assertTrue("Packet writing not completed in time", f.await(11L, TimeUnit.SECONDS));
suspend(cs.getIoSession());
- TestEchoShellFactory.TestEchoShell.latch.await();
+ TestEchoShell.latch.await();
} finally {
client.stop();
}
assertNull("Session closure not signalled", clientSessionHolder.get());
} finally {
- TestEchoShellFactory.TestEchoShell.latch = null;
+ TestEchoShell.latch = null;
}
}
@@ -1352,18 +1340,17 @@ public class ClientTest extends BaseTestSupport {
public Command create() {
return new TestEchoShell();
}
+ }
- public static class TestEchoShell extends EchoShell {
-
- public static CountDownLatch latch = new CountDownLatch(1);
+ public static class TestEchoShell extends EchoShell {
+ public static CountDownLatch latch;
- @Override
- public void destroy() {
- if (latch != null) {
- latch.countDown();
- }
- super.destroy();
+ @Override
+ public void destroy() {
+ if (latch != null) {
+ latch.countDown();
}
+ super.destroy();
}
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/950e896d/sshd-core/src/test/java/org/apache/sshd/client/config/hosts/ConfigFileHostEntryResolverTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/client/config/hosts/ConfigFileHostEntryResolverTest.java b/sshd-core/src/test/java/org/apache/sshd/client/config/hosts/ConfigFileHostEntryResolverTest.java
new file mode 100644
index 0000000..2405cbd
--- /dev/null
+++ b/sshd-core/src/test/java/org/apache/sshd/client/config/hosts/ConfigFileHostEntryResolverTest.java
@@ -0,0 +1,113 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.sshd.client.config.hosts;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import org.apache.sshd.common.util.io.IoUtils;
+import org.apache.sshd.util.BaseTestSupport;
+import org.junit.FixMethodOrder;
+import org.junit.Test;
+import org.junit.runners.MethodSorters;
+
+/**
+ * @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
+ */
+@FixMethodOrder(MethodSorters.NAME_ASCENDING)
+public class ConfigFileHostEntryResolverTest extends BaseTestSupport {
+ public ConfigFileHostEntryResolverTest() {
+ super();
+ }
+
+ @Test
+ public void testConfigFileReload() throws IOException {
+ File dir = new File(new File(detectTargetFolder(), TEMP_SUBFOLDER_NAME), getClass().getSimpleName());
+ final AtomicInteger reloadCount = new AtomicInteger();
+ ConfigFileHostEntryResolver resolver = new ConfigFileHostEntryResolver(new File(assertHierarchyTargetFolderExists(dir), getCurrentTestName() + ".config.txt")) {
+ @Override
+ protected List<HostConfigEntry> reloadHostConfigEntries(Path path, String host, int port, String username)
+ throws IOException {
+ reloadCount.incrementAndGet();
+ return super.reloadHostConfigEntries(path, host, port, username);
+ }
+ };
+ Path path = resolver.getPath();
+
+ HostConfigEntry expected = new HostConfigEntry(getCurrentTestName(), getCurrentTestName(), 7365, getCurrentTestName());
+ testConfigFileReload("Non-existing", path, reloadCount, null, resolver, expected, null);
+ testConfigFileReload("Empty", path, reloadCount, Collections.<HostConfigEntry>emptyList(), resolver, expected, null);
+ testConfigFileReload("Global", path, reloadCount,
+ Collections.singletonList(new HostConfigEntry(HostConfigEntry.ALL_HOSTS_PATTERN, expected.getHost(), expected.getPort(), expected.getUsername())),
+ resolver, expected, expected);
+ testConfigFileReload("Wildcard", path, reloadCount,
+ Arrays.asList(
+ new HostConfigEntry(HostConfigEntry.ALL_HOSTS_PATTERN, getClass().getSimpleName(), 1234, getClass().getSimpleName()),
+ new HostConfigEntry(expected.getHost() + String.valueOf(HostConfigEntry.WILDCARD_PATTERN), expected.getHost(), expected.getPort(), expected.getUsername())),
+ resolver, expected, expected);
+ testConfigFileReload("Specific", path, reloadCount,
+ Arrays.asList(
+ new HostConfigEntry(HostConfigEntry.ALL_HOSTS_PATTERN, getClass().getSimpleName(), 1234, getClass().getSimpleName()),
+ new HostConfigEntry(getClass().getSimpleName() + String.valueOf(HostConfigEntry.WILDCARD_PATTERN), getClass().getSimpleName(), 1234, getClass().getSimpleName()),
+ expected),
+ resolver, expected, expected);
+ }
+
+ private static void testConfigFileReload(
+ String phase, Path path, AtomicInteger reloadCount, Collection<? extends HostConfigEntry> entries, HostConfigEntryResolver resolver, HostConfigEntry query, HostConfigEntry expected)
+ throws IOException {
+ if (entries == null) {
+ if (Files.exists(path)) {
+ Files.delete(path);
+ }
+ } else {
+ HostConfigEntry.writeHostConfigEntries(path, entries, IoUtils.EMPTY_OPEN_OPTIONS);
+ }
+
+ reloadCount.set(0);
+
+ for (int index = 1; index < Byte.SIZE; index++) {
+ HostConfigEntry actual = resolver.resolveEffectiveHost(query.getHostName(), query.getPort(), query.getUsername());
+
+ if (entries == null) {
+ assertEquals(phase + "[" + index + "]: mismatched reload count", 0, reloadCount.get());
+ } else {
+ assertEquals(phase + "[" + index + "]: mismatched reload count", 1, reloadCount.get());
+ }
+
+ if (expected == null) {
+ assertNull(phase + "[" + index + "]: Unexpected success for " + query, actual);
+ } else {
+ assertNotNull(phase + "[" + index + "]: No result for " + query, actual);
+ assertNotSame(phase + "[" + index + "]: No cloned result for " + query, expected, actual);
+ assertEquals(phase + "[" + index + "]: Mismatched host for " + query, expected.getHostName(), actual.getHostName());
+ assertEquals(phase + "[" + index + "]: Mismatched port for " + query, expected.getPort(), actual.getPort());
+ assertEquals(phase + "[" + index + "]: Mismatched user for " + query, expected.getUsername(), actual.getUsername());
+ }
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/950e896d/sshd-core/src/test/java/org/apache/sshd/client/config/hosts/HostConfigEntryResolverTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/client/config/hosts/HostConfigEntryResolverTest.java b/sshd-core/src/test/java/org/apache/sshd/client/config/hosts/HostConfigEntryResolverTest.java
new file mode 100644
index 0000000..a47d999
--- /dev/null
+++ b/sshd-core/src/test/java/org/apache/sshd/client/config/hosts/HostConfigEntryResolverTest.java
@@ -0,0 +1,188 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.sshd.client.config.hosts;
+
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.net.InetSocketAddress;
+import java.net.SocketAddress;
+import java.security.GeneralSecurityException;
+import java.security.KeyPair;
+import java.security.PublicKey;
+import java.util.Iterator;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.sshd.client.ClientFactoryManager;
+import org.apache.sshd.client.SshClient;
+import org.apache.sshd.client.config.keys.ClientIdentityLoader;
+import org.apache.sshd.client.session.ClientSession;
+import org.apache.sshd.common.FactoryManagerUtils;
+import org.apache.sshd.common.SshdSocketAddress;
+import org.apache.sshd.common.config.keys.FilePasswordProvider;
+import org.apache.sshd.common.config.keys.KeyUtils;
+import org.apache.sshd.common.io.IoSession;
+import org.apache.sshd.common.keyprovider.KeyPairProvider;
+import org.apache.sshd.common.session.Session;
+import org.apache.sshd.common.util.ValidateUtils;
+import org.apache.sshd.server.SshServer;
+import org.apache.sshd.server.auth.password.RejectAllPasswordAuthenticator;
+import org.apache.sshd.server.auth.pubkey.PublickeyAuthenticator;
+import org.apache.sshd.server.session.ServerSession;
+import org.apache.sshd.util.BaseTestSupport;
+import org.apache.sshd.util.Utils;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.FixMethodOrder;
+import org.junit.Test;
+import org.junit.runners.MethodSorters;
+
+/**
+ * @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
+ */
+@FixMethodOrder(MethodSorters.NAME_ASCENDING)
+public class HostConfigEntryResolverTest extends BaseTestSupport {
+ private SshServer sshd;
+ private SshClient client;
+ private int port;
+
+ public HostConfigEntryResolverTest() {
+ super();
+ }
+
+ @Before
+ public void setUp() throws Exception {
+ sshd = Utils.setupTestServer();
+ sshd.start();
+ port = sshd.getPort();
+
+ client = Utils.setupTestClient();
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ if (sshd != null) {
+ sshd.stop(true);
+ }
+ if (client != null) {
+ client.stop();
+ }
+ }
+
+ @Test
+ public void testEffectiveHostConfigResolution() throws Exception {
+ final HostConfigEntry entry = new HostConfigEntry(getCurrentTestName(), "localhost", port, getCurrentTestName());
+ client.setHostConfigEntryResolver(new HostConfigEntryResolver() {
+ @Override
+ public HostConfigEntry resolveEffectiveHost(String host, int portValue, String username) throws IOException {
+ return entry;
+ }
+ });
+ client.start();
+
+ try(ClientSession session = client.connect(getClass().getSimpleName(), getClass().getPackage().getName(), getMovedPortNumber(port)).verify(7L, TimeUnit.SECONDS).getSession()) {
+ session.addPasswordIdentity(getCurrentTestName());
+ session.auth().verify(5L, TimeUnit.SECONDS);
+ assertEffectiveRemoteAddress(session, entry);
+ } finally {
+ client.stop();
+ }
+ }
+
+ @Test
+ public void testPreloadedIdentities() throws Exception {
+ KeyPairProvider provider = ValidateUtils.checkNotNull(sshd.getKeyPairProvider(), "No key pair provider");
+ Iterable<? extends KeyPair> pairs = ValidateUtils.checkNotNull(provider.loadKeys(), "No loaded keys");
+ Iterator<? extends KeyPair> iter = ValidateUtils.checkNotNull(pairs.iterator(), "No keys iterator");
+ assertTrue("Empty loaded kyes iterator", iter.hasNext());
+
+ final KeyPair identity = iter.next();
+ final String USER = getCurrentTestName();
+ // make sure authentication is achieved only via the identity public key
+ sshd.setPublickeyAuthenticator(new PublickeyAuthenticator() {
+ @Override
+ public boolean authenticate(String username, PublicKey key, ServerSession session) {
+ if (USER.equals(username)) {
+ return KeyUtils.compareKeys(identity.getPublic(), key);
+ }
+
+ return false;
+ }
+ });
+ sshd.setPasswordAuthenticator(RejectAllPasswordAuthenticator.INSTANCE);
+
+ final String IDENTITY = getCurrentTestName();
+ client.setClientIdentityLoader(new ClientIdentityLoader() {
+ @Override
+ public boolean isValidLocation(String location) throws IOException {
+ return IDENTITY.equals(location);
+ }
+
+ @Override
+ public KeyPair loadClientIdentity(String location, FilePasswordProvider provider) throws IOException, GeneralSecurityException {
+ if (isValidLocation(location)) {
+ return identity;
+ }
+
+ throw new FileNotFoundException("Unknown location: " + location);
+ }
+ });
+ FactoryManagerUtils.updateProperty(client, ClientFactoryManager.IGNORE_INVALID_IDENTITIES, false);
+
+ final String HOST = getClass().getSimpleName();
+ final HostConfigEntry entry = new HostConfigEntry(HOST, "localhost", port, USER);
+ entry.addIdentity(IDENTITY);
+ client.setHostConfigEntryResolver(new HostConfigEntryResolver() {
+ @Override
+ public HostConfigEntry resolveEffectiveHost(String host, int portValue, String username) throws IOException {
+ return entry;
+ }
+ });
+
+ client.start();
+ try(ClientSession session = client.connect(USER, HOST, getMovedPortNumber(port)).verify(7L, TimeUnit.SECONDS).getSession()) {
+ session.auth().verify(5L, TimeUnit.SECONDS);
+ assertEffectiveRemoteAddress(session, entry);
+ } finally {
+ client.stop();
+ }
+
+ }
+
+ private static int getMovedPortNumber(int port) {
+ return (port > Short.MAX_VALUE) ? (port - Short.MAX_VALUE) : (1 + Short.MAX_VALUE - port);
+ }
+
+ private static <S extends Session> S assertEffectiveRemoteAddress(S session, HostConfigEntry entry) {
+ IoSession ioSession = session.getIoSession();
+ SocketAddress remoteAddress = ioSession.getRemoteAddress();
+ InetSocketAddress inetAddress;
+ if (remoteAddress instanceof InetSocketAddress) {
+ inetAddress = (InetSocketAddress) remoteAddress;
+ } else if (remoteAddress instanceof SshdSocketAddress) {
+ inetAddress = ((SshdSocketAddress) remoteAddress).toInetSocketAddress();
+ } else {
+ throw new ClassCastException("Unknown remote address type: " + remoteAddress);
+ }
+
+ assertEquals("Mismatched effective port", entry.getPort(), inetAddress.getPort());
+ assertEquals("Mismatched effective user", entry.getUsername(), session.getUsername());
+ return session;
+ }
+}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/950e896d/sshd-core/src/test/java/org/apache/sshd/client/config/hosts/HostConfigEntryTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/client/config/hosts/HostConfigEntryTest.java b/sshd-core/src/test/java/org/apache/sshd/client/config/hosts/HostConfigEntryTest.java
new file mode 100644
index 0000000..00e61dd
--- /dev/null
+++ b/sshd-core/src/test/java/org/apache/sshd/client/config/hosts/HostConfigEntryTest.java
@@ -0,0 +1,301 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.sshd.client.config.hosts;
+
+import java.io.IOException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.regex.Pattern;
+
+import org.apache.sshd.common.util.GenericUtils;
+import org.apache.sshd.util.BaseTestSupport;
+import org.junit.FixMethodOrder;
+import org.junit.Test;
+import org.junit.runners.MethodSorters;
+
+/**
+ * @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
+ */
+@FixMethodOrder(MethodSorters.NAME_ASCENDING)
+public class HostConfigEntryTest extends BaseTestSupport {
+ public HostConfigEntryTest() {
+ super();
+ }
+
+ @Test
+ public void testHostWildcardPatternMatching() {
+ String pkgName = getClass().getPackage().getName();
+ String[] elements = GenericUtils.split(pkgName, '.');
+ StringBuilder sb = new StringBuilder(pkgName.length() + Long.SIZE + 1).append(HostConfigEntry.WILDCARD_PATTERN);
+ for (int index = elements.length - 1; index >= 0; index--) {
+ sb.append('.').append(elements[index]);
+ }
+
+ String value = sb.toString();
+ Pattern pattern = HostConfigEntry.toPattern(value);
+ String domain = value.substring(1); // chomp the wildcard prefix
+ for (String host : new String[] {
+ getClass().getSimpleName(),
+ getCurrentTestName(),
+ getClass().getSimpleName() + "-" + getCurrentTestName(),
+ getClass().getSimpleName() + "." + getCurrentTestName(),
+ }) {
+ sb.setLength(0); // start from scratch
+ sb.append(host).append(domain);
+
+ testCaseInsensitivePatternMatching(sb.toString(), pattern, true);
+ }
+ }
+
+ @Test
+ public void testIPAddressWildcardPatternMatching() {
+ StringBuilder sb = new StringBuilder().append("10.0.0.");
+ int sbLen = sb.length();
+
+ Pattern pattern = HostConfigEntry.toPattern(sb.append(HostConfigEntry.WILDCARD_PATTERN));
+ for (int v = 0; v <= 255; v++) {
+ sb.setLength(sbLen); // start from scratch
+ sb.append(v);
+
+ String address = sb.toString();
+ assertTrue("No match for " + address, HostConfigEntry.isHostMatch(address, pattern));
+ }
+ }
+
+ @Test
+ public void testHostSingleCharPatternMatching() {
+ String value = getCurrentTestName();
+ StringBuilder sb = new StringBuilder(value);
+ for (boolean restoreOriginal : new boolean[] { true, false }) {
+ for (int index = 0; index < value.length(); index++) {
+ sb.setCharAt(index, HostConfigEntry.SINGLE_CHAR_PATTERN);
+ testCaseInsensitivePatternMatching(value, HostConfigEntry.toPattern(sb.toString()), true);
+ if (restoreOriginal) {
+ sb.setCharAt(index, value.charAt(index));
+ }
+ }
+ }
+ }
+
+ @Test
+ public void testIPAddressSingleCharPatternMatching() {
+ StringBuilder sb = new StringBuilder().append("10.0.0.");
+ int sbLen = sb.length();
+
+ for (int v = 0; v <= 255; v++) {
+ sb.setLength(sbLen); // start from scratch
+ sb.append(v);
+
+ String address = sb.toString();
+ // replace the added digits with single char pattern
+ for (int index = sbLen; index < sb.length(); index++) {
+ sb.setCharAt(index, HostConfigEntry.SINGLE_CHAR_PATTERN);
+ }
+ String pattern = sb.toString();
+
+ assertTrue("No match for " + address + " on pattern=" + pattern, HostConfigEntry.isHostMatch(address, pattern));
+ }
+ }
+
+ @Test
+ public void testIsValidPatternChar() {
+ for (char ch = '\0'; ch <= ' '; ch++) {
+ assertFalse("Unexpected valid character (0x" + Integer.toHexString(ch & 0xFF) + ")", HostConfigEntry.isValidPatternChar(ch));
+ }
+
+ for (char ch = 'a'; ch <= 'z'; ch++) {
+ assertTrue("Valid character not recognized: " + String.valueOf(ch), HostConfigEntry.isValidPatternChar(ch));
+ }
+
+ for (char ch = 'A'; ch <= 'Z'; ch++) {
+ assertTrue("Valid character not recognized: " + String.valueOf(ch), HostConfigEntry.isValidPatternChar(ch));
+ }
+
+ for (char ch = '0'; ch <= '9'; ch++) {
+ assertTrue("Valid character not recognized: " + String.valueOf(ch), HostConfigEntry.isValidPatternChar(ch));
+ }
+
+ for (char ch : new char[] { '-', '_', '.', HostConfigEntry.SINGLE_CHAR_PATTERN, HostConfigEntry.WILDCARD_PATTERN }) {
+ assertTrue("Valid character not recognized: " + String.valueOf(ch), HostConfigEntry.isValidPatternChar(ch));
+ }
+
+ for (char ch : new char[] {
+ '(', ')', '{', '}', '[', ']', '!', '@',
+ '#', '$', '^', '&', '%', '~', '<', '>',
+ ',', '/', '\\', '\'', '"', ':', ';' }) {
+ assertFalse("Unexpected valid character: " + String.valueOf(ch), HostConfigEntry.isValidPatternChar(ch));
+ }
+
+ for (char ch = 0x7E; ch <= 0xFF; ch++) {
+ assertFalse("Unexpected valid character (0x" + Integer.toHexString(ch & 0xFF) + ")", HostConfigEntry.isValidPatternChar(ch));
+ }
+ }
+
+ @Test
+ public void testResolvePort() {
+ final int ORIGINAL_PORT = Short.MAX_VALUE;
+ final int ENTRY_PORT = 7365;
+ assertEquals("Mismatched entry port preference", ENTRY_PORT, HostConfigEntry.resolvePort(ORIGINAL_PORT, ENTRY_PORT));
+
+ for (int entryPort : new int[] { -1, 0 }) {
+ assertEquals("Non-preferred original port for entry port=" + entryPort, ORIGINAL_PORT, HostConfigEntry.resolvePort(ORIGINAL_PORT, entryPort));
+ }
+ }
+
+ @Test
+ public void testResolveUsername() {
+ final String ORIGINAL_USER = getCurrentTestName();
+ final String ENTRY_USER = getClass().getSimpleName();
+ assertSame("Mismatched entry user preference", ENTRY_USER, HostConfigEntry.resolveUsername(ORIGINAL_USER, ENTRY_USER));
+
+ for (String entryUser : new String[] { null, "" }) {
+ assertSame("Non-preferred original user for entry user='" + entryUser + "'", ORIGINAL_USER, HostConfigEntry.resolveUsername(ORIGINAL_USER, entryUser));
+ }
+ }
+
+ @Test
+ public void testReadSimpleHostsConfigEntries() throws IOException {
+ validateHostConfigEntries(readHostConfigEntries());
+ }
+
+ @Test
+ public void testReadGlobalHostsConfigEntries() throws IOException {
+ List<HostConfigEntry> entries = validateHostConfigEntries(readHostConfigEntries());
+ assertTrue("Not enough entries read", GenericUtils.size(entries) > 1);
+
+ // global entry MUST be 1st one
+ HostConfigEntry globalEntry = entries.get(0);
+ assertEquals("Mismatched global entry pattern", HostConfigEntry.ALL_HOSTS_PATTERN, globalEntry.getHost());
+
+ for (int index = 1; index < entries.size(); index++) {
+ HostConfigEntry entry = entries.get(index);
+ assertFalse("No target host for " + entry, GenericUtils.isEmpty(entry.getHostName()));
+ assertTrue("No target port for " + entry, entry.getPort() > 0);
+ assertFalse("No username for " + entry, GenericUtils.isEmpty(entry.getUsername()));
+ assertFalse("No identities for " + entry, GenericUtils.isEmpty(entry.getIdentities()));
+ assertFalse("No properties for " + entry, GenericUtils.isEmpty(entry.getProperties()));
+ }
+ }
+
+ @Test
+ public void testReadMultipleHostPatterns() throws IOException {
+ List<HostConfigEntry> entries = validateHostConfigEntries(readHostConfigEntries());
+ assertEquals("Mismatched number of duplicates", 3, GenericUtils.size(entries));
+
+ HostConfigEntry prototype = entries.get(0);
+ String protoIds = GenericUtils.join(prototype.getIdentities(), ',');
+ Collection<Map.Entry<String,String>> protoProps = prototype.getProperties().entrySet();
+ for (int index = 1; index < entries.size(); index++) {
+ HostConfigEntry entry = entries.get(index);
+ assertEquals("Mismatched host name for " + entry, prototype.getHostName(), entry.getHostName());
+ assertEquals("Mismatched port for " + entry, prototype.getPort(), entry.getPort());
+ assertSame("Mismatched user for " + entry, prototype.getUsername(), entry.getUsername());
+ assertEquals("Mismatched identities for " + entry, protoIds, GenericUtils.join(entry.getIdentities(), ','));
+
+ Map<String,String> entryProps = entry.getProperties();
+ assertEquals("Mismatched properties count for " + entry, GenericUtils.size(protoProps), GenericUtils.size(entryProps));
+
+ for (Map.Entry<String,String> ppe : protoProps) {
+ String key = ppe.getKey();
+ String expected = ppe.getValue();
+ String actual = entryProps.get(key);
+ assertEquals("Mismatched value for " + key + " property of " + entry, expected, actual);
+ }
+ }
+ }
+
+ @Test
+ public void testResolveIdentityFilePath() throws Exception {
+ final String HOST = getClass().getSimpleName();
+ final int PORT = 7365;
+ final String USER = getCurrentTestName();
+
+ Exception err = null;
+ for (String pattern : new String[] {
+ "~/.ssh/%h.key",
+ "%d/.ssh/%h.key",
+ "/home/%u/.ssh/id_rsa_%p",
+ "/home/%u/.ssh/id_%r_rsa",
+ "/home/%u/.ssh/%h/%l.key"
+ }) {
+ try {
+ String result = HostConfigEntry.resolveIdentityFilePath(pattern, HOST, PORT, USER);
+ System.out.append('\t').append(pattern).append(" => ").println(result);
+ } catch(Exception e) {
+ System.err.append("Failed (").append(e.getClass().getSimpleName())
+ .append(") to process pattern=").append(pattern)
+ .append(": ").println(e.getMessage());
+ err = e;
+ }
+ }
+
+ if (err != null) {
+ throw err;
+ }
+ }
+
+ @Test
+ public void testFindBestMatch() {
+ final String HOST = getCurrentTestName();
+ HostConfigEntry expected = new HostConfigEntry(HOST, HOST, 7365, HOST);
+ List<HostConfigEntry> matches = new ArrayList<>();
+ matches.add(new HostConfigEntry(HostConfigEntry.ALL_HOSTS_PATTERN, getClass().getSimpleName(), Short.MAX_VALUE, getClass().getSimpleName()));
+ matches.add(new HostConfigEntry(HOST + String.valueOf(HostConfigEntry.WILDCARD_PATTERN), getClass().getSimpleName(), Byte.MAX_VALUE, getClass().getSimpleName()));
+ matches.add(expected);
+
+ for (int index = 0; index < matches.size(); index++) {
+ HostConfigEntry actual = HostConfigEntry.findBestMatch(matches);
+ assertSame("Mismatched best match for " + matches, expected, actual);
+ Collections.shuffle(matches);
+ }
+ }
+
+ private static <C extends Collection<HostConfigEntry>> C validateHostConfigEntries(C entries) {
+ assertFalse("No entries", GenericUtils.isEmpty(entries));
+
+ for (HostConfigEntry entry : entries) {
+ assertFalse("No pattern for " + entry, GenericUtils.isEmpty(entry.getHost()));
+ assertFalse("No extra properties for " + entry, GenericUtils.isEmpty(entry.getProperties()));
+ }
+
+ return entries;
+ }
+
+ private List<HostConfigEntry> readHostConfigEntries() throws IOException {
+ return readHostConfigEntries(getCurrentTestName() + ".config.txt");
+ }
+
+ private List<HostConfigEntry> readHostConfigEntries(String resourceName) throws IOException {
+ URL url = getClass().getResource(resourceName);
+ assertNotNull("Missing resource " + resourceName, url);
+ return HostConfigEntry.readHostConfigEntries(url);
+ }
+ private static void testCaseInsensitivePatternMatching(String value, Pattern pattern, boolean expected) {
+ for (int index = 0; index < value.length(); index++) {
+ boolean actual = HostConfigEntry.isHostMatch(value, pattern);
+ assertEquals("Mismatched match result for " + value + " on pattern=" + pattern.pattern(), expected, actual);
+ value = shuffleCase(value);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/950e896d/sshd-core/src/test/java/org/apache/sshd/client/kex/KexTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/client/kex/KexTest.java b/sshd-core/src/test/java/org/apache/sshd/client/kex/KexTest.java
index 5ff1111..3c96be4 100644
--- a/sshd-core/src/test/java/org/apache/sshd/client/kex/KexTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/client/kex/KexTest.java
@@ -37,8 +37,6 @@ import org.apache.sshd.common.kex.BuiltinDHFactories;
import org.apache.sshd.common.kex.KeyExchange;
import org.apache.sshd.server.SshServer;
import org.apache.sshd.util.BaseTestSupport;
-import org.apache.sshd.util.BogusPasswordAuthenticator;
-import org.apache.sshd.util.EchoShellFactory;
import org.apache.sshd.util.TeeOutputStream;
import org.apache.sshd.util.Utils;
import org.junit.After;
@@ -75,10 +73,7 @@ public class KexTest extends BaseTestSupport {
@Before
public void setUp() throws Exception {
- sshd = SshServer.setUpDefaultServer();
- sshd.setKeyPairProvider(Utils.createTestHostKeyProvider());
- sshd.setShellFactory(new EchoShellFactory());
- sshd.setPasswordAuthenticator(BogusPasswordAuthenticator.INSTANCE);
+ sshd = Utils.setupTestServer();
sshd.start();
port = sshd.getPort();
}
@@ -102,7 +97,7 @@ public class KexTest extends BaseTestSupport {
try (ByteArrayOutputStream sent = new ByteArrayOutputStream();
ByteArrayOutputStream out = new ByteArrayOutputStream()) {
- try (SshClient client = SshClient.setUpDefaultClient()) {
+ try (SshClient client = Utils.setupTestClient()) {
client.setKeyExchangeFactories(Collections.singletonList(kex));
client.start();
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/950e896d/sshd-core/src/test/java/org/apache/sshd/client/scp/ScpTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/client/scp/ScpTest.java b/sshd-core/src/test/java/org/apache/sshd/client/scp/ScpTest.java
index 9e7ab79..5cf9543 100644
--- a/sshd-core/src/test/java/org/apache/sshd/client/scp/ScpTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/client/scp/ScpTest.java
@@ -55,11 +55,10 @@ import org.apache.sshd.common.scp.ScpTransferEventListener;
import org.apache.sshd.common.session.Session;
import org.apache.sshd.common.util.GenericUtils;
import org.apache.sshd.common.util.OsUtils;
+import org.apache.sshd.common.util.io.IoUtils;
import org.apache.sshd.server.SshServer;
import org.apache.sshd.server.command.ScpCommandFactory;
import org.apache.sshd.util.BaseTestSupport;
-import org.apache.sshd.util.BogusPasswordAuthenticator;
-import org.apache.sshd.util.EchoShellFactory;
import org.apache.sshd.util.JSchLogger;
import org.apache.sshd.util.SimpleUserInfo;
import org.apache.sshd.util.Utils;
@@ -99,11 +98,8 @@ public class ScpTest extends BaseTestSupport {
@Before
public void setUp() throws Exception {
- sshd = SshServer.setUpDefaultServer();
- sshd.setKeyPairProvider(Utils.createTestHostKeyProvider());
+ sshd = Utils.setupTestServer();
sshd.setCommandFactory(new ScpCommandFactory());
- sshd.setShellFactory(new EchoShellFactory());
- sshd.setPasswordAuthenticator(BogusPasswordAuthenticator.INSTANCE);
sshd.setFileSystemFactory(fileSystemFactory);
sshd.start();
port = sshd.getPort();
@@ -145,7 +141,7 @@ public class ScpTest extends BaseTestSupport {
Path localDir = assertHierarchyTargetFolderExists(scpRoot.resolve("local"));
Path localFile = localDir.resolve("file.txt");
- byte[] data = writeFile(localFile, getClass().getName() + "#" + getCurrentTestName() + System.getProperty("line.separator"));
+ byte[] data = writeFile(localFile, getClass().getName() + "#" + getCurrentTestName() + IoUtils.EOL);
Path remoteDir = assertHierarchyTargetFolderExists(scpRoot.resolve("remote"));
Path remoteFile = remoteDir.resolve(localFile.getFileName().toString());
@@ -153,7 +149,7 @@ public class ScpTest extends BaseTestSupport {
String remotePath = Utils.resolveRelativeRemotePath(parentPath, remoteFile);
String[] remoteComps = GenericUtils.split(remotePath, '/');
- try (SshClient client = SshClient.setUpDefaultClient()) {
+ try (SshClient client = Utils.setupTestClient()) {
client.start();
Factory<? extends Random> factory = client.getRandomFactory();
@@ -208,14 +204,14 @@ public class ScpTest extends BaseTestSupport {
Path localDir = assertHierarchyTargetFolderExists(scpRoot.resolve("local"));
Path localFile = localDir.resolve("file-1.txt");
- byte[] data = writeFile(localFile, getClass().getName() + "#" + getCurrentTestName() + System.getProperty("line.separator"));
+ byte[] data = writeFile(localFile, getClass().getName() + "#" + getCurrentTestName() + IoUtils.EOL);
Path remoteDir = assertHierarchyTargetFolderExists(scpRoot.resolve("remote"));
Path remoteFile = remoteDir.resolve(localFile.getFileName().toString());
String localPath = localFile.toString();
String remotePath = Utils.resolveRelativeRemotePath(parentPath, remoteFile);
- try (SshClient client = SshClient.setUpDefaultClient()) {
+ try (SshClient client = Utils.setupTestClient()) {
client.start();
try (ClientSession session = client.connect(getCurrentTestName(), "localhost", port).verify(7L, TimeUnit.SECONDS).getSession()) {
@@ -243,7 +239,7 @@ public class ScpTest extends BaseTestSupport {
@Test
public void testScpUploadOverwrite() throws Exception {
- try (SshClient client = SshClient.setUpDefaultClient()) {
+ try (SshClient client = Utils.setupTestClient()) {
client.start();
try (ClientSession session = client.connect(getCurrentTestName(), "localhost", port).verify(7L, TimeUnit.SECONDS).getSession()) {
@@ -251,7 +247,7 @@ public class ScpTest extends BaseTestSupport {
session.auth().verify(5L, TimeUnit.SECONDS);
ScpClient scp = createScpClient(session);
- String data = getClass().getName() + "#" + getCurrentTestName() + System.getProperty("line.separator");
+ String data = getClass().getName() + "#" + getCurrentTestName() + IoUtils.EOL;
Path targetPath = detectTargetFolder().toPath();
Path parentPath = targetPath.getParent();
@@ -295,7 +291,7 @@ public class ScpTest extends BaseTestSupport {
Files.delete(zeroRemote);
}
- try (SshClient client = SshClient.setUpDefaultClient()) {
+ try (SshClient client = Utils.setupTestClient()) {
client.start();
try (ClientSession session = client.connect(getCurrentTestName(), "localhost", port).verify(7L, TimeUnit.SECONDS).getSession()) {
@@ -331,7 +327,7 @@ public class ScpTest extends BaseTestSupport {
}
assertEquals("Non-zero size for remote file=" + zeroRemote, 0L, Files.size(zeroRemote));
- try (SshClient client = SshClient.setUpDefaultClient()) {
+ try (SshClient client = Utils.setupTestClient()) {
client.start();
try (ClientSession session = client.connect(getCurrentTestName(), "localhost", port).verify(7L, TimeUnit.SECONDS).getSession()) {
@@ -350,7 +346,7 @@ public class ScpTest extends BaseTestSupport {
@Test
public void testScpNativeOnSingleFile() throws Exception {
- String data = getClass().getName() + "#" + getCurrentTestName() + System.getProperty("line.separator");
+ String data = getClass().getName() + "#" + getCurrentTestName() + IoUtils.EOL;
Path targetPath = detectTargetFolder().toPath();
Path parentPath = targetPath.getParent();
@@ -362,7 +358,7 @@ public class ScpTest extends BaseTestSupport {
Path remoteDir = scpRoot.resolve("remote");
Path remoteOutFile = remoteDir.resolve(localOutFile.getFileName());
- try (SshClient client = SshClient.setUpDefaultClient()) {
+ try (SshClient client = Utils.setupTestClient()) {
client.start();
try (ClientSession session = client.connect(getCurrentTestName(), "localhost", port).verify(7L, TimeUnit.SECONDS).getSession()) {
@@ -402,7 +398,7 @@ public class ScpTest extends BaseTestSupport {
@Test
public void testScpNativeOnMultipleFiles() throws Exception {
- try (SshClient client = SshClient.setUpDefaultClient()) {
+ try (SshClient client = Utils.setupTestClient()) {
client.start();
try (ClientSession session = client.connect(getCurrentTestName(), "localhost", port).verify(7L, TimeUnit.SECONDS).getSession()) {
@@ -417,7 +413,7 @@ public class ScpTest extends BaseTestSupport {
Path localDir = assertHierarchyTargetFolderExists(scpRoot.resolve("local"));
Path local1 = localDir.resolve("file-1.txt");
- byte[] data = writeFile(local1, getClass().getName() + "#" + getCurrentTestName() + System.getProperty("line.separator"));
+ byte[] data = writeFile(local1, getClass().getName() + "#" + getCurrentTestName() + IoUtils.EOL);
Path local2 = localDir.resolve("file-2.txt");
Files.write(local2, data);
@@ -483,7 +479,7 @@ public class ScpTest extends BaseTestSupport {
@Test
public void testScpNativeOnRecursiveDirs() throws Exception {
- try (SshClient client = SshClient.setUpDefaultClient()) {
+ try (SshClient client = Utils.setupTestClient()) {
client.start();
try (ClientSession session = client.connect(getCurrentTestName(), "localhost", port).verify(7L, TimeUnit.SECONDS).getSession()) {
@@ -499,7 +495,7 @@ public class ScpTest extends BaseTestSupport {
Path localDir = scpRoot.resolve("local");
Path localSubDir = assertHierarchyTargetFolderExists(localDir.resolve("dir"));
Path localSub1 = localSubDir.resolve("file-1.txt");
- byte[] data = writeFile(localSub1, getClass().getName() + "#" + getCurrentTestName() + System.getProperty("line.separator"));
+ byte[] data = writeFile(localSub1, getClass().getName() + "#" + getCurrentTestName() + IoUtils.EOL);
Path localSub2 = localSubDir.resolve("file-2.txt");
Files.write(localSub2, data);
@@ -523,7 +519,7 @@ public class ScpTest extends BaseTestSupport {
@Test
public void testScpNativeOnDirWithPattern() throws Exception {
- try (SshClient client = SshClient.setUpDefaultClient()) {
+ try (SshClient client = Utils.setupTestClient()) {
client.start();
try (ClientSession session = client.connect(getCurrentTestName(), "localhost", port).verify(7L, TimeUnit.SECONDS).getSession()) {
@@ -538,7 +534,7 @@ public class ScpTest extends BaseTestSupport {
Path localDir = assertHierarchyTargetFolderExists(scpRoot.resolve("local"));
Path local1 = localDir.resolve("file-1.txt");
- byte[] data = writeFile(local1, getClass().getName() + "#" + getCurrentTestName() + System.getProperty("line.separator"));
+ byte[] data = writeFile(local1, getClass().getName() + "#" + getCurrentTestName() + IoUtils.EOL);
Path local2 = localDir.resolve("file-2.txt");
Files.write(local2, data);
@@ -561,7 +557,7 @@ public class ScpTest extends BaseTestSupport {
@Test
public void testScpNativeOnMixedDirAndFiles() throws Exception {
- try (SshClient client = SshClient.setUpDefaultClient()) {
+ try (SshClient client = Utils.setupTestClient()) {
client.start();
try (ClientSession session = client.connect(getCurrentTestName(), "localhost", port).verify(7L, TimeUnit.SECONDS).getSession()) {
@@ -577,7 +573,7 @@ public class ScpTest extends BaseTestSupport {
Path localDir = scpRoot.resolve("local");
Path localSubDir = assertHierarchyTargetFolderExists(localDir.resolve("dir"));
Path local1 = localDir.resolve("file-1.txt");
- byte[] data = writeFile(local1, getClass().getName() + "#" + getCurrentTestName() + System.getProperty("line.separator"));
+ byte[] data = writeFile(local1, getClass().getName() + "#" + getCurrentTestName() + IoUtils.EOL);
Path localSub2 = localSubDir.resolve("file-2.txt");
Files.write(localSub2, data);
@@ -608,7 +604,7 @@ public class ScpTest extends BaseTestSupport {
@Test
public void testScpNativePreserveAttributes() throws Exception {
- try (SshClient client = SshClient.setUpDefaultClient()) {
+ try (SshClient client = Utils.setupTestClient()) {
client.start();
try (ClientSession session = client.connect(getCurrentTestName(), "localhost", port).verify(7L, TimeUnit.SECONDS).getSession()) {
@@ -627,7 +623,7 @@ public class ScpTest extends BaseTestSupport {
final long lastModMillis = System.currentTimeMillis() - TimeUnit.DAYS.toMillis(1);
final long lastModSecs = TimeUnit.MILLISECONDS.toSeconds(lastModMillis);
Path local1 = localDir.resolve("file-1.txt");
- byte[] data = writeFile(local1, getClass().getName() + "#" + getCurrentTestName() + System.getProperty("line.separator"));
+ byte[] data = writeFile(local1, getClass().getName() + "#" + getCurrentTestName() + IoUtils.EOL);
File lclFile1 = local1.toFile();
boolean lcl1ModSet = lclFile1.setLastModified(lastModMillis);
@@ -672,7 +668,7 @@ public class ScpTest extends BaseTestSupport {
@Test
public void testStreamsUploadAndDownload() throws Exception {
- try (SshClient client = SshClient.setUpDefaultClient()) {
+ try (SshClient client = Utils.setupTestClient()) {
client.start();
try (ClientSession session = client.connect(getCurrentTestName(), "localhost", port).verify(7L, TimeUnit.SECONDS).getSession()) {
@@ -821,7 +817,7 @@ public class ScpTest extends BaseTestSupport {
byte[] remoteData = Files.readAllBytes(remoteFile);
assertArrayEquals("Mismatched remote put data", expected, remoteData);
- Arrays.fill(remoteData, (byte) 0); // make sure we start with a clean slate
+ Arrays.fill(remoteData, (byte) 0); // make sure we start with a clean slate
try (InputStream input = scp_client.get(remotePath + "/" + fileName)) {
int readLen = input.read(remoteData);
assertEquals("Mismatched remote get data size", expected.length, readLen);
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/950e896d/sshd-core/src/test/java/org/apache/sshd/client/subsystem/sftp/AbstractSftpClientTestSupport.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/client/subsystem/sftp/AbstractSftpClientTestSupport.java b/sshd-core/src/test/java/org/apache/sshd/client/subsystem/sftp/AbstractSftpClientTestSupport.java
index 75ff85d..8033be7 100644
--- a/sshd-core/src/test/java/org/apache/sshd/client/subsystem/sftp/AbstractSftpClientTestSupport.java
+++ b/sshd-core/src/test/java/org/apache/sshd/client/subsystem/sftp/AbstractSftpClientTestSupport.java
@@ -35,8 +35,6 @@ import org.apache.sshd.server.SshServer;
import org.apache.sshd.server.command.ScpCommandFactory;
import org.apache.sshd.server.subsystem.sftp.SftpSubsystemFactory;
import org.apache.sshd.util.BaseTestSupport;
-import org.apache.sshd.util.BogusPasswordAuthenticator;
-import org.apache.sshd.util.EchoShellFactory;
import org.apache.sshd.util.Utils;
/**
@@ -61,12 +59,9 @@ public abstract class AbstractSftpClientTestSupport extends BaseTestSupport {
}
protected void setupServer() throws Exception {
- sshd = SshServer.setUpDefaultServer();
- sshd.setKeyPairProvider(Utils.createTestHostKeyProvider());
+ sshd = Utils.setupTestServer();
sshd.setSubsystemFactories(Arrays.<NamedFactory<Command>>asList(new SftpSubsystemFactory()));
sshd.setCommandFactory(new ScpCommandFactory());
- sshd.setShellFactory(new EchoShellFactory());
- sshd.setPasswordAuthenticator(BogusPasswordAuthenticator.INSTANCE);
sshd.setFileSystemFactory(fileSystemFactory);
sshd.start();
port = sshd.getPort();
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/950e896d/sshd-core/src/test/java/org/apache/sshd/client/subsystem/sftp/SftpFileSystemTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/client/subsystem/sftp/SftpFileSystemTest.java b/sshd-core/src/test/java/org/apache/sshd/client/subsystem/sftp/SftpFileSystemTest.java
index 6c70d54..9603a87 100644
--- a/sshd-core/src/test/java/org/apache/sshd/client/subsystem/sftp/SftpFileSystemTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/client/subsystem/sftp/SftpFileSystemTest.java
@@ -66,8 +66,6 @@ import org.apache.sshd.server.SshServer;
import org.apache.sshd.server.command.ScpCommandFactory;
import org.apache.sshd.server.subsystem.sftp.SftpSubsystemFactory;
import org.apache.sshd.util.BaseTestSupport;
-import org.apache.sshd.util.BogusPasswordAuthenticator;
-import org.apache.sshd.util.EchoShellFactory;
import org.apache.sshd.util.Utils;
import org.junit.After;
import org.junit.Before;
@@ -96,12 +94,9 @@ public class SftpFileSystemTest extends BaseTestSupport {
@Before
public void setUp() throws Exception {
- sshd = SshServer.setUpDefaultServer();
- sshd.setKeyPairProvider(Utils.createTestHostKeyProvider());
+ sshd = Utils.setupTestServer();
sshd.setSubsystemFactories(Arrays.<NamedFactory<Command>>asList(new SftpSubsystemFactory()));
sshd.setCommandFactory(new ScpCommandFactory());
- sshd.setShellFactory(new EchoShellFactory());
- sshd.setPasswordAuthenticator(BogusPasswordAuthenticator.INSTANCE);
sshd.setFileSystemFactory(fileSystemFactory);
sshd.start();
port = sshd.getPort();
@@ -216,7 +211,7 @@ public class SftpFileSystemTest extends BaseTestSupport {
@Test
public void testMultipleFileStoresOnSameProvider() throws IOException {
- try (SshClient client = SshClient.setUpDefaultClient()) {
+ try (SshClient client = Utils.setupTestClient()) {
client.start();
SftpFileSystemProvider provider = new SftpFileSystemProvider(client);
@@ -286,7 +281,7 @@ public class SftpFileSystemTest extends BaseTestSupport {
return selected.get();
}
};
- try (SshClient client = SshClient.setUpDefaultClient()) {
+ try (SshClient client = Utils.setupTestClient()) {
client.start();
try (ClientSession session = client.connect(getCurrentTestName(), "localhost", port).verify(7L, TimeUnit.SECONDS).getSession()) {
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/950e896d/sshd-core/src/test/java/org/apache/sshd/client/subsystem/sftp/SftpTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/client/subsystem/sftp/SftpTest.java b/sshd-core/src/test/java/org/apache/sshd/client/subsystem/sftp/SftpTest.java
index 3226877..1c039c2 100644
--- a/sshd-core/src/test/java/org/apache/sshd/client/subsystem/sftp/SftpTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/client/subsystem/sftp/SftpTest.java
@@ -131,7 +131,7 @@ public class SftpTest extends AbstractSftpClientTestSupport {
rnd.fill(expectedRandom);
byte[] expectedText = (getClass().getName() + "#" + getCurrentTestName()).getBytes(StandardCharsets.UTF_8);
- try (SshClient client = SshClient.setUpDefaultClient()) {
+ try (SshClient client = Utils.setupTestClient()) {
client.start();
try (ClientSession session = client.connect(getCurrentTestName(), "localhost", port).verify(7L, TimeUnit.SECONDS).getSession()) {
@@ -183,7 +183,7 @@ public class SftpTest extends AbstractSftpClientTestSupport {
rnd.fill(expected);
Files.write(testFile, expected);
- try (SshClient client = SshClient.setUpDefaultClient()) {
+ try (SshClient client = Utils.setupTestClient()) {
client.start();
try (ClientSession session = client.connect(getCurrentTestName(), "localhost", port).verify(7L, TimeUnit.SECONDS).getSession()) {
@@ -227,7 +227,7 @@ public class SftpTest extends AbstractSftpClientTestSupport {
}
});
- try (SshClient client = SshClient.setUpDefaultClient()) {
+ try (SshClient client = Utils.setupTestClient()) {
client.start();
try (ClientSession session = client.connect(getCurrentTestName(), "localhost", port).verify(7L, TimeUnit.SECONDS).getSession()) {
@@ -247,7 +247,7 @@ public class SftpTest extends AbstractSftpClientTestSupport {
@Test
public void testNormalizeRemoteRootValues() throws Exception {
- try (SshClient client = SshClient.setUpDefaultClient()) {
+ try (SshClient client = Utils.setupTestClient()) {
client.start();
try (ClientSession session = client.connect(getCurrentTestName(), "localhost", port).verify(7L, TimeUnit.SECONDS).getSession()) {
@@ -286,7 +286,7 @@ public class SftpTest extends AbstractSftpClientTestSupport {
String file = Utils.resolveRelativeRemotePath(parentPath, testFile);
String[] comps = GenericUtils.split(file, '/');
- try (SshClient client = SshClient.setUpDefaultClient()) {
+ try (SshClient client = Utils.setupTestClient()) {
client.start();
Factory<? extends Random> factory = client.getRandomFactory();
@@ -347,7 +347,7 @@ public class SftpTest extends AbstractSftpClientTestSupport {
File javaFile = testFile.toFile();
assertHierarchyTargetFolderExists(javaFile.getParentFile());
- try (SshClient client = SshClient.setUpDefaultClient()) {
+ try (SshClient client = Utils.setupTestClient()) {
client.start();
try (ClientSession session = client.connect(getCurrentTestName(), "localhost", port).verify(7L, TimeUnit.SECONDS).getSession()) {
@@ -439,7 +439,7 @@ public class SftpTest extends AbstractSftpClientTestSupport {
@Test
public void testClient() throws Exception {
- try (SshClient client = SshClient.setUpDefaultClient()) {
+ try (SshClient client = Utils.setupTestClient()) {
client.start();
try (ClientSession session = client.connect(getCurrentTestName(), "localhost", port).verify(7L, TimeUnit.SECONDS).getSession()) {
@@ -464,7 +464,7 @@ public class SftpTest extends AbstractSftpClientTestSupport {
*/
@Test
public void testWriteChunking() throws Exception {
- try (SshClient client = SshClient.setUpDefaultClient()) {
+ try (SshClient client = Utils.setupTestClient()) {
client.start();
try (ClientSession session = client.connect(getCurrentTestName(), "localhost", port).verify(7L, TimeUnit.SECONDS).getSession()) {
@@ -655,7 +655,7 @@ public class SftpTest extends AbstractSftpClientTestSupport {
Path parentPath = targetPath.getParent();
Path clientFolder = assertHierarchyTargetFolderExists(lclSftp.resolve("client"));
- try (SshClient client = SshClient.setUpDefaultClient()) {
+ try (SshClient client = Utils.setupTestClient()) {
client.start();
try (ClientSession session = client.connect(getCurrentTestName(), "localhost", port).verify(7L, TimeUnit.SECONDS).getSession()) {
@@ -701,7 +701,7 @@ public class SftpTest extends AbstractSftpClientTestSupport {
@Test
public void testServerExtensionsDeclarations() throws Exception {
- try (SshClient client = SshClient.setUpDefaultClient()) {
+ try (SshClient client = Utils.setupTestClient()) {
client.start();
try (ClientSession session = client.connect(getCurrentTestName(), "localhost", port).verify(7L, TimeUnit.SECONDS).getSession()) {
@@ -800,7 +800,7 @@ public class SftpTest extends AbstractSftpClientTestSupport {
}
};
- try (SshClient client = SshClient.setUpDefaultClient()) {
+ try (SshClient client = Utils.setupTestClient()) {
client.start();
try (ClientSession session = client.connect(getCurrentTestName(), "localhost", port).verify(7L, TimeUnit.SECONDS).getSession()) {
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/950e896d/sshd-core/src/test/java/org/apache/sshd/client/subsystem/sftp/extensions/impl/AbstractCheckFileExtensionTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/client/subsystem/sftp/extensions/impl/AbstractCheckFileExtensionTest.java b/sshd-core/src/test/java/org/apache/sshd/client/subsystem/sftp/extensions/impl/AbstractCheckFileExtensionTest.java
index c591c1c..89415d2 100644
--- a/sshd-core/src/test/java/org/apache/sshd/client/subsystem/sftp/extensions/impl/AbstractCheckFileExtensionTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/client/subsystem/sftp/extensions/impl/AbstractCheckFileExtensionTest.java
@@ -138,7 +138,7 @@ public class AbstractCheckFileExtensionTest extends AbstractSftpClientTestSuppor
byte[] seed = (getClass().getName() + "#" + getCurrentTestName()
+ "-" + expectedAlgorithm
+ "-" + inputDataSize + "/" + hashBlockSize
- + System.getProperty("line.separator"))
+ + IoUtils.EOL)
.getBytes(StandardCharsets.UTF_8);
try (ByteArrayOutputStream baos = new ByteArrayOutputStream(inputDataSize + seed.length)) {
@@ -175,7 +175,7 @@ public class AbstractCheckFileExtensionTest extends AbstractSftpClientTestSuppor
String srcPath = Utils.resolveRelativeRemotePath(parentPath, srcFile);
String srcFolder = Utils.resolveRelativeRemotePath(parentPath, srcFile.getParent());
- try (SshClient client = SshClient.setUpDefaultClient()) {
+ try (SshClient client = Utils.setupTestClient()) {
client.start();
try (ClientSession session = client.connect(getCurrentTestName(), "localhost", port).verify(7L, TimeUnit.SECONDS).getSession()) {
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/950e896d/sshd-core/src/test/java/org/apache/sshd/client/subsystem/sftp/extensions/impl/AbstractMD5HashExtensionTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/client/subsystem/sftp/extensions/impl/AbstractMD5HashExtensionTest.java b/sshd-core/src/test/java/org/apache/sshd/client/subsystem/sftp/extensions/impl/AbstractMD5HashExtensionTest.java
index e2013a8..6b39051 100644
--- a/sshd-core/src/test/java/org/apache/sshd/client/subsystem/sftp/extensions/impl/AbstractMD5HashExtensionTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/client/subsystem/sftp/extensions/impl/AbstractMD5HashExtensionTest.java
@@ -96,7 +96,7 @@ public class AbstractMD5HashExtensionTest extends AbstractSftpClientTestSupport
}
private void testMD5HashExtension(int dataSize) throws Exception {
- byte[] seed = (getClass().getName() + "#" + getCurrentTestName() + "-" + dataSize + System.getProperty("line.separator")).getBytes(StandardCharsets.UTF_8);
+ byte[] seed = (getClass().getName() + "#" + getCurrentTestName() + "-" + dataSize + IoUtils.EOL).getBytes(StandardCharsets.UTF_8);
try (ByteArrayOutputStream baos = new ByteArrayOutputStream(dataSize + seed.length)) {
while (baos.size() < dataSize) {
baos.write(seed);
@@ -131,7 +131,7 @@ public class AbstractMD5HashExtensionTest extends AbstractSftpClientTestSupport
String srcPath = Utils.resolveRelativeRemotePath(parentPath, srcFile);
String srcFolder = Utils.resolveRelativeRemotePath(parentPath, srcFile.getParent());
- try (SshClient client = SshClient.setUpDefaultClient()) {
+ try (SshClient client = Utils.setupTestClient()) {
client.start();
try (ClientSession session = client.connect(getCurrentTestName(), "localhost", port).verify(7L, TimeUnit.SECONDS).getSession()) {
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/950e896d/sshd-core/src/test/java/org/apache/sshd/client/subsystem/sftp/extensions/impl/CopyDataExtensionImplTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/client/subsystem/sftp/extensions/impl/CopyDataExtensionImplTest.java b/sshd-core/src/test/java/org/apache/sshd/client/subsystem/sftp/extensions/impl/CopyDataExtensionImplTest.java
index 7c0f989..dda241e 100644
--- a/sshd-core/src/test/java/org/apache/sshd/client/subsystem/sftp/extensions/impl/CopyDataExtensionImplTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/client/subsystem/sftp/extensions/impl/CopyDataExtensionImplTest.java
@@ -123,7 +123,7 @@ public class CopyDataExtensionImplTest extends AbstractSftpClientTestSupport {
byte[] seed = (getClass().getName() + "#" + getCurrentTestName()
+ "-" + dataSize
+ "-" + readOffset + "/" + readLength + "/" + writeOffset
- + System.getProperty("line.separator"))
+ + IoUtils.EOL)
.getBytes(StandardCharsets.UTF_8);
try (ByteArrayOutputStream baos = new ByteArrayOutputStream(dataSize + seed.length)) {
while (baos.size() < dataSize) {
@@ -150,7 +150,7 @@ public class CopyDataExtensionImplTest extends AbstractSftpClientTestSupport {
}
String dstPath = Utils.resolveRelativeRemotePath(parentPath, dstFile);
- try (SshClient client = SshClient.setUpDefaultClient()) {
+ try (SshClient client = Utils.setupTestClient()) {
client.start();
if (writeOffset > 0L) {
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/950e896d/sshd-core/src/test/java/org/apache/sshd/client/subsystem/sftp/extensions/impl/CopyFileExtensionImplTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/client/subsystem/sftp/extensions/impl/CopyFileExtensionImplTest.java b/sshd-core/src/test/java/org/apache/sshd/client/subsystem/sftp/extensions/impl/CopyFileExtensionImplTest.java
index 1f9ebb1..59c1ef5 100644
--- a/sshd-core/src/test/java/org/apache/sshd/client/subsystem/sftp/extensions/impl/CopyFileExtensionImplTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/client/subsystem/sftp/extensions/impl/CopyFileExtensionImplTest.java
@@ -78,7 +78,7 @@ public class CopyFileExtensionImplTest extends AbstractSftpClientTestSupport {
LinkOption[] options = IoUtils.getLinkOptions(false);
assertFalse("Destination file unexpectedly exists", Files.exists(dstFile, options));
- try (SshClient client = SshClient.setUpDefaultClient()) {
+ try (SshClient client = Utils.setupTestClient()) {
client.start();
try (ClientSession session = client.connect(getCurrentTestName(), "localhost", port).verify(7L, TimeUnit.SECONDS).getSession()) {
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/950e896d/sshd-core/src/test/java/org/apache/sshd/client/subsystem/sftp/extensions/impl/SpaceAvailableExtensionImplTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/client/subsystem/sftp/extensions/impl/SpaceAvailableExtensionImplTest.java b/sshd-core/src/test/java/org/apache/sshd/client/subsystem/sftp/extensions/impl/SpaceAvailableExtensionImplTest.java
index 1c9e0d9..d200267 100644
--- a/sshd-core/src/test/java/org/apache/sshd/client/subsystem/sftp/extensions/impl/SpaceAvailableExtensionImplTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/client/subsystem/sftp/extensions/impl/SpaceAvailableExtensionImplTest.java
@@ -88,7 +88,7 @@ public class SpaceAvailableExtensionImplTest extends AbstractSftpClientTestSuppo
}
}));
- try (SshClient client = SshClient.setUpDefaultClient()) {
+ try (SshClient client = Utils.setupTestClient()) {
client.start();
try (ClientSession session = client.connect(getCurrentTestName(), "localhost", port).verify(7L, TimeUnit.SECONDS).getSession()) {
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/950e896d/sshd-core/src/test/java/org/apache/sshd/client/subsystem/sftp/extensions/openssh/impl/OpenSSHExtensionsTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/client/subsystem/sftp/extensions/openssh/impl/OpenSSHExtensionsTest.java b/sshd-core/src/test/java/org/apache/sshd/client/subsystem/sftp/extensions/openssh/impl/OpenSSHExtensionsTest.java
index 20ab5fa..087ae37 100644
--- a/sshd-core/src/test/java/org/apache/sshd/client/subsystem/sftp/extensions/openssh/impl/OpenSSHExtensionsTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/client/subsystem/sftp/extensions/openssh/impl/OpenSSHExtensionsTest.java
@@ -89,7 +89,7 @@ public class OpenSSHExtensionsTest extends AbstractSftpClientTestSupport {
Path parentPath = targetPath.getParent();
String srcPath = Utils.resolveRelativeRemotePath(parentPath, srcFile);
- try (SshClient client = SshClient.setUpDefaultClient()) {
+ try (SshClient client = Utils.setupTestClient()) {
client.start();
try (ClientSession session = client.connect(getCurrentTestName(), "localhost", port).verify(7L, TimeUnit.SECONDS).getSession()) {
@@ -178,7 +178,7 @@ public class OpenSSHExtensionsTest extends AbstractSftpClientTestSupport {
}
}));
- try (SshClient client = SshClient.setUpDefaultClient()) {
+ try (SshClient client = Utils.setupTestClient()) {
client.start();
try (ClientSession session = client.connect(getCurrentTestName(), "localhost", port).verify(7L, TimeUnit.SECONDS).getSession()) {
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/950e896d/sshd-core/src/test/java/org/apache/sshd/common/channel/WindowTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/common/channel/WindowTest.java b/sshd-core/src/test/java/org/apache/sshd/common/channel/WindowTest.java
index f8b23fb..73b64df 100644
--- a/sshd-core/src/test/java/org/apache/sshd/common/channel/WindowTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/common/channel/WindowTest.java
@@ -47,12 +47,9 @@ import org.apache.sshd.common.session.Session;
import org.apache.sshd.common.util.buffer.Buffer;
import org.apache.sshd.common.util.buffer.ByteArrayBuffer;
import org.apache.sshd.server.Command;
-import org.apache.sshd.server.CommandFactory;
import org.apache.sshd.server.SshServer;
-import org.apache.sshd.server.auth.pubkey.AcceptAllPublickeyAuthenticator;
import org.apache.sshd.server.channel.ChannelSession;
import org.apache.sshd.server.channel.ChannelSessionFactory;
-import org.apache.sshd.server.command.UnknownCommand;
import org.apache.sshd.server.forward.DirectTcpipFactory;
import org.apache.sshd.server.session.ServerConnectionService;
import org.apache.sshd.server.session.ServerConnectionServiceFactory;
@@ -60,7 +57,7 @@ import org.apache.sshd.server.session.ServerUserAuthService;
import org.apache.sshd.server.session.ServerUserAuthServiceFactory;
import org.apache.sshd.util.AsyncEchoShellFactory;
import org.apache.sshd.util.BaseTestSupport;
-import org.apache.sshd.util.BogusPasswordAuthenticator;
+import org.apache.sshd.util.EchoShell;
import org.apache.sshd.util.EchoShellFactory;
import org.apache.sshd.util.Utils;
import org.junit.After;
@@ -92,17 +89,8 @@ public class WindowTest extends BaseTestSupport {
authLatch = new CountDownLatch(0);
channelLatch = new CountDownLatch(0);
- sshd = SshServer.setUpDefaultServer();
- sshd.setKeyPairProvider(Utils.createTestHostKeyProvider());
+ sshd = Utils.setupTestServer();
sshd.setShellFactory(new TestEchoShellFactory());
- sshd.setCommandFactory(new CommandFactory() {
- @Override
- public Command createCommand(String command) {
- return new UnknownCommand(command);
- }
- });
- sshd.setPasswordAuthenticator(BogusPasswordAuthenticator.INSTANCE);
- sshd.setPublickeyAuthenticator(AcceptAllPublickeyAuthenticator.INSTANCE);
sshd.setServiceFactories(Arrays.asList(
new ServerUserAuthServiceFactory() {
@Override
@@ -146,7 +134,7 @@ public class WindowTest extends BaseTestSupport {
sshd.start();
port = sshd.getPort();
- client = SshClient.setUpDefaultClient();
+ client = Utils.setupTestClient();
}
@After
@@ -348,18 +336,18 @@ public class WindowTest extends BaseTestSupport {
public Command create() {
return new TestEchoShell();
}
+ }
- public static class TestEchoShell extends EchoShell {
+ public static class TestEchoShell extends EchoShell {
- public static CountDownLatch latch = new CountDownLatch(1);
+ public static final CountDownLatch latch = new CountDownLatch(1);
- @Override
- public void destroy() {
- if (latch != null) {
- latch.countDown();
- }
- super.destroy();
+ @Override
+ public void destroy() {
+ if (latch != null) {
+ latch.countDown();
}
+ super.destroy();
}
}
}