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/07/09 14:05:40 UTC
mina-sshd git commit: [SSHD-534] SSHClient Channel id (
channel.getId() ) always returned as 0 ,
no matter how many channels are created.
Repository: mina-sshd
Updated Branches:
refs/heads/master 515427faa -> e08cbe1aa
[SSHD-534] SSHClient Channel id ( channel.getId() ) always returned as 0 , no matter how many channels are created.
Project: http://git-wip-us.apache.org/repos/asf/mina-sshd/repo
Commit: http://git-wip-us.apache.org/repos/asf/mina-sshd/commit/e08cbe1a
Tree: http://git-wip-us.apache.org/repos/asf/mina-sshd/tree/e08cbe1a
Diff: http://git-wip-us.apache.org/repos/asf/mina-sshd/diff/e08cbe1a
Branch: refs/heads/master
Commit: e08cbe1aab51f7f63a772c77adf6928f4dd2ca7a
Parents: 515427f
Author: Lyor Goldstein <lg...@vmware.com>
Authored: Thu Jul 9 15:05:30 2015 +0300
Committer: Lyor Goldstein <lg...@vmware.com>
Committed: Thu Jul 9 15:05:30 2015 +0300
----------------------------------------------------------------------
.../sshd/agent/unix/AgentServerProxy.java | 3 +-
.../sshd/client/channel/ClientChannel.java | 2 +-
.../sshd/client/session/ClientSessionImpl.java | 26 +++++--
.../org/apache/sshd/common/scp/ScpHelper.java | 15 ++--
.../session/AbstractConnectionService.java | 25 ++++--
.../sshd/common/session/AbstractSession.java | 5 +-
.../sshd/common/session/ConnectionService.java | 8 +-
.../org/apache/sshd/common/util/Base64.java | 2 +-
.../apache/sshd/server/command/ScpCommand.java | 8 +-
.../sshd/server/command/UnknownCommand.java | 3 +-
.../sshd/server/session/ServerSessionImpl.java | 3 +-
.../java/org/apache/sshd/KeyReExchangeTest.java | 15 ++--
.../src/test/java/org/apache/sshd/LoadTest.java | 5 +-
.../org/apache/sshd/PortForwardingLoadTest.java | 7 +-
.../org/apache/sshd/PortForwardingTest.java | 12 +--
.../test/java/org/apache/sshd/ProxyTest.java | 3 +-
.../java/org/apache/sshd/WindowAdjustTest.java | 3 +-
.../test/java/org/apache/sshd/WindowTest.java | 4 +-
.../java/org/apache/sshd/agent/AgentTest.java | 3 +-
.../java/org/apache/sshd/client/ClientTest.java | 80 ++++++++++++++------
.../org/apache/sshd/client/kex/KexTest.java | 7 +-
.../org/apache/sshd/client/scp/ScpTest.java | 14 ++--
.../subsystem/sftp/SftpFileSystemTest.java | 9 ++-
.../sshd/client/subsystem/sftp/SftpTest.java | 18 ++---
.../channel/ChannelPipedInputStreamTest.java | 5 +-
.../channel/ChannelPipedOutputStreamTest.java | 3 +-
.../sshd/common/cipher/BaseCipherTest.java | 3 +-
.../org/apache/sshd/common/mac/MacTest.java | 3 +-
.../common/session/AbstractSessionTest.java | 17 +++--
.../common/util/io/LimitInputStreamTest.java | 3 +-
.../java/org/apache/sshd/server/ServerTest.java | 3 +-
.../server/shell/InvertedShellWrapperTest.java | 7 +-
.../apache/sshd/util/AsyncEchoShellFactory.java | 3 +-
.../org/apache/sshd/util/EchoShellFactory.java | 3 +-
.../org/apache/sshd/git/pgm/GitPgmCommand.java | 3 +-
.../apache/sshd/git/util/EchoShellFactory.java | 3 +-
36 files changed, 212 insertions(+), 124 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/e08cbe1a/sshd-core/src/main/java/org/apache/sshd/agent/unix/AgentServerProxy.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/agent/unix/AgentServerProxy.java b/sshd-core/src/main/java/org/apache/sshd/agent/unix/AgentServerProxy.java
index 235263f..a7a8fe6 100644
--- a/sshd-core/src/main/java/org/apache/sshd/agent/unix/AgentServerProxy.java
+++ b/sshd-core/src/main/java/org/apache/sshd/agent/unix/AgentServerProxy.java
@@ -20,6 +20,7 @@ package org.apache.sshd.agent.unix;
import java.io.File;
import java.io.IOException;
+import java.nio.charset.StandardCharsets;
import java.util.Collection;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
@@ -63,7 +64,7 @@ public class AgentServerProxy extends AbstractLoggingBean implements SshAgentSer
private final AtomicBoolean innerFinished = new AtomicBoolean(false);
//used to wake the Local.listen() JNI call
- private static final byte[] END_OF_STREAM_MESSAGE = new byte[] { "END_OF_STREAM".getBytes()[0] };
+ private static final byte[] END_OF_STREAM_MESSAGE = new byte[] { "END_OF_STREAM".getBytes(StandardCharsets.UTF_8)[0] };
public AgentServerProxy(ConnectionService service) throws IOException {
this(service, null, false);
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/e08cbe1a/sshd-core/src/main/java/org/apache/sshd/client/channel/ClientChannel.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/channel/ClientChannel.java b/sshd-core/src/main/java/org/apache/sshd/client/channel/ClientChannel.java
index d897fe1..7931989 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/channel/ClientChannel.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/channel/ClientChannel.java
@@ -97,7 +97,7 @@ public interface ClientChannel extends Channel {
int waitFor(int mask, long timeout);
- CloseFuture close(boolean immediately);
+ CloseFuture close(boolean immediate);
Integer getExitStatus();
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/e08cbe1a/sshd-core/src/main/java/org/apache/sshd/client/session/ClientSessionImpl.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/session/ClientSessionImpl.java b/sshd-core/src/main/java/org/apache/sshd/client/session/ClientSessionImpl.java
index f2ee39b..dcb8a71 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/session/ClientSessionImpl.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/session/ClientSessionImpl.java
@@ -339,32 +339,48 @@ public class ClientSessionImpl extends AbstractSession implements ClientSession
@Override
public ChannelShell createShellChannel() throws IOException {
- if (inCipher instanceof CipherNone || outCipher instanceof CipherNone) {
+ if ((inCipher instanceof CipherNone) || (outCipher instanceof CipherNone)) {
throw new IllegalStateException("Interactive channels are not supported with none cipher");
}
ChannelShell channel = new ChannelShell();
- getConnectionService().registerChannel(channel);
+ ConnectionService service = getConnectionService();
+ int id = service.registerChannel(channel);
+ if (log.isDebugEnabled()) {
+ log.debug("createShellChannel(id={}) created", Integer.valueOf(id));
+ }
return channel;
}
@Override
public ChannelExec createExecChannel(String command) throws IOException {
ChannelExec channel = new ChannelExec(command);
- getConnectionService().registerChannel(channel);
+ ConnectionService service = getConnectionService();
+ int id = service.registerChannel(channel);
+ if (log.isDebugEnabled()) {
+ log.debug("createExecChannel(id={})[{}] created", Integer.valueOf(id), command);
+ }
return channel;
}
@Override
public ChannelSubsystem createSubsystemChannel(String subsystem) throws IOException {
ChannelSubsystem channel = new ChannelSubsystem(subsystem);
- getConnectionService().registerChannel(channel);
+ ConnectionService service = getConnectionService();
+ int id = service.registerChannel(channel);
+ if (log.isDebugEnabled()) {
+ log.debug("createSubsystemChannel(id={})[{}] created", Integer.valueOf(id), subsystem);
+ }
return channel;
}
@Override
public ChannelDirectTcpip createDirectTcpipChannel(SshdSocketAddress local, SshdSocketAddress remote) throws IOException {
ChannelDirectTcpip channel = new ChannelDirectTcpip(local, remote);
- getConnectionService().registerChannel(channel);
+ ConnectionService service = getConnectionService();
+ int id = service.registerChannel(channel);
+ if (log.isDebugEnabled()) {
+ log.debug("createDirectTcpipChannel(id={})[{} => {}] created", Integer.valueOf(id), local, remote);
+ }
return channel;
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/e08cbe1a/sshd-core/src/main/java/org/apache/sshd/common/scp/ScpHelper.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/scp/ScpHelper.java b/sshd-core/src/main/java/org/apache/sshd/common/scp/ScpHelper.java
index 16b9733..96efe39 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/scp/ScpHelper.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/scp/ScpHelper.java
@@ -25,6 +25,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.StreamCorruptedException;
+import java.nio.charset.StandardCharsets;
import java.nio.file.AccessDeniedException;
import java.nio.file.DirectoryStream;
import java.nio.file.FileSystem;
@@ -419,13 +420,13 @@ public class ScpHelper extends AbstractLoggingBean {
} else if (Files.isDirectory(file, options)) {
if (!recursive) {
out.write(ScpHelper.WARNING);
- out.write((path.toString().replace(File.separatorChar, '/') + " not a regular file\n").getBytes());
+ out.write((path.toString().replace(File.separatorChar, '/') + " not a regular file\n").getBytes(StandardCharsets.UTF_8));
} else {
sendDir(file, preserve, bufferSize);
}
} else {
out.write(ScpHelper.WARNING);
- out.write((path.toString().replace(File.separatorChar, '/') + " unknown file type\n").getBytes());
+ out.write((path.toString().replace(File.separatorChar, '/') + " unknown file type\n").getBytes(StandardCharsets.UTF_8));
}
}
} else {
@@ -522,7 +523,7 @@ public class ScpHelper extends AbstractLoggingBean {
.append(' ').append(TimeUnit.MILLISECONDS.toSeconds(time.lastAccessTime)).append(' ').append('0')
.append('\n')
.toString();
- out.write(cmd.getBytes());
+ out.write(cmd.getBytes(StandardCharsets.UTF_8));
out.flush();
readAck(false);
}
@@ -536,7 +537,7 @@ public class ScpHelper extends AbstractLoggingBean {
.append(' ').append(fileName)
.append('\n')
.toString();
- out.write(cmd.getBytes());
+ out.write(cmd.getBytes(StandardCharsets.UTF_8));
out.flush();
readAck(false);
@@ -572,7 +573,7 @@ public class ScpHelper extends AbstractLoggingBean {
buf.append(" ");
buf.append("0");
buf.append("\n");
- out.write(buf.toString().getBytes());
+ out.write(buf.toString().getBytes(StandardCharsets.UTF_8));
out.flush();
readAck(false);
}
@@ -587,7 +588,7 @@ public class ScpHelper extends AbstractLoggingBean {
buf.append(" ");
buf.append(path.getFileName().toString());
buf.append("\n");
- out.write(buf.toString().getBytes());
+ out.write(buf.toString().getBytes(StandardCharsets.UTF_8));
out.flush();
readAck(false);
@@ -610,7 +611,7 @@ public class ScpHelper extends AbstractLoggingBean {
}
}
- out.write("E\n".getBytes());
+ out.write("E\n".getBytes(StandardCharsets.UTF_8));
out.flush();
readAck(false);
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/e08cbe1a/sshd-core/src/main/java/org/apache/sshd/common/session/AbstractConnectionService.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/session/AbstractConnectionService.java b/sshd-core/src/main/java/org/apache/sshd/common/session/AbstractConnectionService.java
index 109ffb1..92ff394 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/session/AbstractConnectionService.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/session/AbstractConnectionService.java
@@ -44,6 +44,7 @@ import org.apache.sshd.client.channel.AbstractClientChannel;
import org.apache.sshd.client.future.OpenFuture;
import org.apache.sshd.common.Closeable;
import org.apache.sshd.common.FactoryManager;
+import org.apache.sshd.common.FactoryManagerUtils;
import org.apache.sshd.common.NamedFactory;
import org.apache.sshd.common.SshConstants;
import org.apache.sshd.common.SshException;
@@ -65,6 +66,12 @@ import org.apache.sshd.server.x11.X11ForwardSupport;
* @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
*/
public abstract class AbstractConnectionService extends CloseableUtils.AbstractInnerCloseable implements ConnectionService {
+ /**
+ * Property that can be used to configure max. allowed concurrent active channels
+ * @see #registerChannel(Channel)
+ */
+ public static final String MAX_CONCURRENT_CHANNELS_PROP = "max-sshd-channels";
+ public static final int DEFAULT_MAX_CHANNELS = Integer.MAX_VALUE;
/** Map of channels keyed by the identifier */
protected final Map<Integer, Channel> channels = new ConcurrentHashMap<Integer, Channel>();
@@ -124,23 +131,27 @@ public abstract class AbstractConnectionService extends CloseableUtils.AbstractI
return nextChannelId.getAndIncrement();
}
- /**
- * Register a newly created channel with a new unique identifier
- *
- * @param channel the channel to register
- * @return the id of this channel
- * @throws IOException
- */
@Override
public int registerChannel(Channel channel) throws IOException {
+ int maxChannels = FactoryManagerUtils.getIntProperty(session, MAX_CONCURRENT_CHANNELS_PROP, DEFAULT_MAX_CHANNELS);
+ int curSize = channels.size();
+ if (curSize > maxChannels) {
+ throw new IllegalStateException("Currently active channels (" + curSize + ") at max.: " + maxChannels);
+ }
+
int channelId = getNextChannelId();
channel.init(this, session, channelId);
synchronized (lock) {
if (isClosing()) {
throw new IllegalStateException("Session is being closed: " + toString());
}
+
channels.put(Integer.valueOf(channelId), channel);
}
+
+ if (log.isDebugEnabled()) {
+ log.debug("registerChannel(id={}) {}", Integer.valueOf(channelId), channel);
+ }
return channelId;
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/e08cbe1a/sshd-core/src/main/java/org/apache/sshd/common/session/AbstractSession.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/session/AbstractSession.java b/sshd-core/src/main/java/org/apache/sshd/common/session/AbstractSession.java
index ed8aced..0371d0c 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/session/AbstractSession.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/session/AbstractSession.java
@@ -29,6 +29,7 @@ import static org.apache.sshd.common.SshConstants.SSH_MSG_UNIMPLEMENTED;
import java.io.IOException;
import java.io.InterruptedIOException;
+import java.nio.charset.StandardCharsets;
import java.util.EnumMap;
import java.util.LinkedList;
import java.util.List;
@@ -394,7 +395,7 @@ public abstract class AbstractSession extends CloseableUtils.AbstractInnerClosea
kex = ValidateUtils.checkNotNull(NamedFactory.Utils.create(factoryManager.getKeyExchangeFactories(), kexAlgorithm),
"Unknown negotiated KEX algorithm: %s",
kexAlgorithm);
- kex.init(this, serverVersion.getBytes(), clientVersion.getBytes(), I_S, I_C);
+ kex.init(this, serverVersion.getBytes(StandardCharsets.UTF_8), clientVersion.getBytes(StandardCharsets.UTF_8), I_S, I_C);
}
sendEvent(SessionListener.Event.KexCompleted);
@@ -823,7 +824,7 @@ public abstract class AbstractSession extends CloseableUtils.AbstractInnerClosea
*/
protected void sendIdentification(String ident) {
log.debug("Send identification: {}", ident);
- byte[] data = (ident + "\r\n").getBytes();
+ byte[] data = (ident + "\r\n").getBytes(StandardCharsets.UTF_8);
ioSession.write(new ByteArrayBuffer(data));
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/e08cbe1a/sshd-core/src/main/java/org/apache/sshd/common/session/ConnectionService.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/session/ConnectionService.java b/sshd-core/src/main/java/org/apache/sshd/common/session/ConnectionService.java
index 51d7886..fcc242b 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/session/ConnectionService.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/session/ConnectionService.java
@@ -30,13 +30,11 @@ import org.apache.sshd.common.forward.TcpipForwarder;
* @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
*/
public interface ConnectionService extends Service {
-
/**
* Register a newly created channel with a new unique identifier
- *
- * @param channel the channel to register
- * @return the id of this channel
- * @throws IOException
+ * @param channel The {@link Channel} to register
+ * @return The assigned id of this channel
+ * @throws IOException If failed to initialize and register the channel
*/
int registerChannel(Channel channel) throws IOException;
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/e08cbe1a/sshd-core/src/main/java/org/apache/sshd/common/util/Base64.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/util/Base64.java b/sshd-core/src/main/java/org/apache/sshd/common/util/Base64.java
index a7cc8ca..d8ce356 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/util/Base64.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/util/Base64.java
@@ -53,7 +53,7 @@ public class Base64 {
*
* @see <a href="http://www.ietf.org/rfc/rfc2045.txt">RFC 2045 section 2.1</a>
*/
- static final byte[] CHUNK_SEPARATOR = "\r\n".getBytes();
+ static final byte[] CHUNK_SEPARATOR = "\r\n".getBytes(StandardCharsets.UTF_8);
/**
* The base length.
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/e08cbe1a/sshd-core/src/main/java/org/apache/sshd/server/command/ScpCommand.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/server/command/ScpCommand.java b/sshd-core/src/main/java/org/apache/sshd/server/command/ScpCommand.java
index acf9c7f..f9c3fe7 100644
--- a/sshd-core/src/main/java/org/apache/sshd/server/command/ScpCommand.java
+++ b/sshd-core/src/main/java/org/apache/sshd/server/command/ScpCommand.java
@@ -21,6 +21,7 @@ package org.apache.sshd.server.command;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
+import java.nio.charset.StandardCharsets;
import java.nio.file.FileSystem;
import java.util.Collection;
import java.util.Collections;
@@ -30,6 +31,7 @@ import java.util.concurrent.Future;
import org.apache.sshd.common.file.FileSystemAware;
import org.apache.sshd.common.scp.ScpHelper;
import org.apache.sshd.common.scp.ScpTransferEventListener;
+import org.apache.sshd.common.util.GenericUtils;
import org.apache.sshd.common.util.logging.AbstractLoggingBean;
import org.apache.sshd.common.util.threads.ThreadUtils;
import org.apache.sshd.server.Command;
@@ -228,9 +230,9 @@ public class ScpCommand extends AbstractLoggingBean implements Command, Runnable
} catch (IOException e) {
try {
exitValue = ScpHelper.ERROR;
- exitMessage = e.getMessage() == null ? "" : e.getMessage();
+ exitMessage = GenericUtils.trimToEmpty(e.getMessage());
out.write(exitValue);
- out.write(exitMessage.getBytes());
+ out.write(exitMessage.getBytes(StandardCharsets.UTF_8));
out.write('\n');
out.flush();
} catch (IOException e2) {
@@ -239,7 +241,7 @@ public class ScpCommand extends AbstractLoggingBean implements Command, Runnable
log.info("Error in scp command=" + name, e);
} finally {
if (callback != null) {
- callback.onExit(exitValue, exitMessage);
+ callback.onExit(exitValue, GenericUtils.trimToEmpty(exitMessage));
}
}
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/e08cbe1a/sshd-core/src/main/java/org/apache/sshd/server/command/UnknownCommand.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/server/command/UnknownCommand.java b/sshd-core/src/main/java/org/apache/sshd/server/command/UnknownCommand.java
index f4f0387..9ff43a6 100644
--- a/sshd-core/src/main/java/org/apache/sshd/server/command/UnknownCommand.java
+++ b/sshd-core/src/main/java/org/apache/sshd/server/command/UnknownCommand.java
@@ -21,6 +21,7 @@ package org.apache.sshd.server.command;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
+import java.nio.charset.StandardCharsets;
import org.apache.sshd.server.Command;
import org.apache.sshd.server.Environment;
@@ -67,7 +68,7 @@ public class UnknownCommand implements Command {
@Override
public void start(Environment env) throws IOException {
- err.write(("Unknown command: " + command + "\n").getBytes());
+ err.write(("Unknown command: " + command + "\n").getBytes(StandardCharsets.UTF_8));
err.flush();
if (callback != null) {
callback.onExit(1, "Unknown command: " + command);
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/e08cbe1a/sshd-core/src/main/java/org/apache/sshd/server/session/ServerSessionImpl.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/server/session/ServerSessionImpl.java b/sshd-core/src/main/java/org/apache/sshd/server/session/ServerSessionImpl.java
index e3e5eb0..35a1e39 100644
--- a/sshd-core/src/main/java/org/apache/sshd/server/session/ServerSessionImpl.java
+++ b/sshd-core/src/main/java/org/apache/sshd/server/session/ServerSessionImpl.java
@@ -19,6 +19,7 @@
package org.apache.sshd.server.session;
import java.io.IOException;
+import java.nio.charset.StandardCharsets;
import java.security.KeyPair;
import java.util.Collection;
import java.util.Map;
@@ -182,7 +183,7 @@ public class ServerSessionImpl extends AbstractSession implements ServerSession
log.debug("Client version string: {}", clientVersion);
if (!clientVersion.startsWith(DEFAULT_SSH_VERSION_PREFIX)) {
String msg = "Unsupported protocol version: " + clientVersion;
- ioSession.write(new ByteArrayBuffer((msg + "\n").getBytes())).addListener(new SshFutureListener<IoWriteFuture>() {
+ ioSession.write(new ByteArrayBuffer((msg + "\n").getBytes(StandardCharsets.UTF_8))).addListener(new SshFutureListener<IoWriteFuture>() {
@Override
public void operationComplete(IoWriteFuture future) {
close(true);
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/e08cbe1a/sshd-core/src/test/java/org/apache/sshd/KeyReExchangeTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/KeyReExchangeTest.java b/sshd-core/src/test/java/org/apache/sshd/KeyReExchangeTest.java
index de75221..ef853f2 100644
--- a/sshd-core/src/test/java/org/apache/sshd/KeyReExchangeTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/KeyReExchangeTest.java
@@ -23,6 +23,7 @@ import java.io.InputStream;
import java.io.OutputStream;
import java.io.PipedInputStream;
import java.io.PipedOutputStream;
+import java.nio.charset.StandardCharsets;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
@@ -99,7 +100,7 @@ public class KeyReExchangeTest extends BaseTestSupport {
InputStream is = c.getInputStream()) {
String expected = "this is my command\n";
- byte[] bytes = expected.getBytes();
+ byte[] bytes = expected.getBytes(StandardCharsets.UTF_8);
byte[] data = new byte[bytes.length + Long.SIZE];
for (int i = 0; i < 10; i++) {
os.write(bytes);
@@ -142,7 +143,7 @@ public class KeyReExchangeTest extends BaseTestSupport {
channel.setErr(err);
channel.open();
- teeOut.write("this is my command\n".getBytes());
+ teeOut.write("this is my command\n".getBytes(StandardCharsets.UTF_8));
teeOut.flush();
StringBuilder sb = new StringBuilder();
@@ -151,13 +152,13 @@ public class KeyReExchangeTest extends BaseTestSupport {
}
sb.append("\n");
- byte[] data=sb.toString().getBytes();
+ byte[] data=sb.toString().getBytes(StandardCharsets.UTF_8);
for (int i = 0; i < 10; i++) {
teeOut.write(data);
teeOut.flush();
session.reExchangeKeys();
}
- teeOut.write("exit\n".getBytes());
+ teeOut.write("exit\n".getBytes(StandardCharsets.UTF_8));
teeOut.flush();
channel.waitFor(ClientChannel.CLOSED, 0);
@@ -196,7 +197,7 @@ public class KeyReExchangeTest extends BaseTestSupport {
channel.setErr(err);
channel.open();
- teeOut.write("this is my command\n".getBytes());
+ teeOut.write("this is my command\n".getBytes(StandardCharsets.UTF_8));
teeOut.flush();
StringBuilder sb = new StringBuilder();
@@ -223,10 +224,10 @@ public class KeyReExchangeTest extends BaseTestSupport {
}
});
for (int i = 0; i < 100; i++) {
- teeOut.write(sb.toString().getBytes());
+ teeOut.write(sb.toString().getBytes(StandardCharsets.UTF_8));
teeOut.flush();
}
- teeOut.write("exit\n".getBytes());
+ teeOut.write("exit\n".getBytes(StandardCharsets.UTF_8));
teeOut.flush();
channel.waitFor(ClientChannel.CLOSED, 0);
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/e08cbe1a/sshd-core/src/test/java/org/apache/sshd/LoadTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/LoadTest.java b/sshd-core/src/test/java/org/apache/sshd/LoadTest.java
index c8ab9c3..d595892 100644
--- a/sshd-core/src/test/java/org/apache/sshd/LoadTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/LoadTest.java
@@ -20,6 +20,7 @@ package org.apache.sshd;
import java.io.ByteArrayOutputStream;
import java.io.OutputStream;
+import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@@ -141,7 +142,7 @@ public class LoadTest extends BaseTestSupport {
channel.open().verify(9L, TimeUnit.SECONDS);
try(OutputStream pipedIn = channel.getInvertedIn()) {
msg += "\nexit\n";
- pipedIn.write(msg.getBytes());
+ pipedIn.write(msg.getBytes(StandardCharsets.UTF_8));
pipedIn.flush();
}
@@ -150,7 +151,7 @@ public class LoadTest extends BaseTestSupport {
channel.close(false);
}
- assertArrayEquals("Mismatched message data", msg.getBytes(), out.toByteArray());
+ assertArrayEquals("Mismatched message data", msg.getBytes(StandardCharsets.UTF_8), out.toByteArray());
}
} finally {
client.stop();
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/e08cbe1a/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 fd13b65..bb5acdf 100644
--- a/sshd-core/src/test/java/org/apache/sshd/PortForwardingLoadTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/PortForwardingLoadTest.java
@@ -30,6 +30,7 @@ import java.net.InetSocketAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.URL;
+import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.CountDownLatch;
@@ -183,7 +184,7 @@ public class PortForwardingLoadTest extends BaseTestSupport {
Thread.sleep(50);
byte[] buf = new byte[8192];
- byte[] bytes = PAYLOAD.getBytes();
+ byte[] bytes = PAYLOAD.getBytes(StandardCharsets.UTF_8);
for (int i = 0; i < NUM_ITERATIONS; i++) {
log.info("Iteration {}", Integer.valueOf(i));
try(Socket s = new Socket("localhost", sinkPort);
@@ -241,7 +242,7 @@ public class PortForwardingLoadTest extends BaseTestSupport {
public void run() {
started[0] = true;
try {
- byte[] bytes=PAYLOAD.getBytes();
+ byte[] bytes=PAYLOAD.getBytes(StandardCharsets.UTF_8);
for (int i = 0; i < NUM_ITERATIONS; ++i) {
try(Socket s = ss.accept()) {
conCount.incrementAndGet();
@@ -340,7 +341,7 @@ public class PortForwardingLoadTest extends BaseTestSupport {
acceptor.setHandler(new IoHandlerAdapter() {
@Override
public void messageReceived(IoSession session, Object message) throws Exception {
- session.write(IoBuffer.wrap(sb.toString().getBytes()));
+ session.write(IoBuffer.wrap(sb.toString().getBytes(StandardCharsets.UTF_8)));
}
});
acceptor.setReuseAddress(true);
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/e08cbe1a/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 f054647..24cd809 100644
--- a/sshd-core/src/test/java/org/apache/sshd/PortForwardingTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/PortForwardingTest.java
@@ -276,7 +276,7 @@ public class PortForwardingTest extends BaseTestSupport {
s.setSoTimeout((int) TimeUnit.SECONDS.toMillis(10L));
String expected = getCurrentTestName();
- byte[] bytes = expected.getBytes();
+ byte[] bytes = expected.getBytes(StandardCharsets.UTF_8);
output.write(bytes);
output.flush();
@@ -305,7 +305,7 @@ public class PortForwardingTest extends BaseTestSupport {
s.setSoTimeout((int) TimeUnit.SECONDS.toMillis(10L));
String expected = getCurrentTestName();
- byte[] bytes = expected.getBytes();
+ byte[] bytes = expected.getBytes(StandardCharsets.UTF_8);
byte[] buf = new byte[bytes.length + Long.SIZE];
for (int i = 0; i < 1000; i++) {
@@ -337,7 +337,7 @@ public class PortForwardingTest extends BaseTestSupport {
s.setSoTimeout((int) TimeUnit.SECONDS.toMillis(10L));
String expected = getCurrentTestName();
- byte[] bytes = expected.getBytes();
+ byte[] bytes = expected.getBytes(StandardCharsets.UTF_8);
output.write(bytes);
output.flush();
@@ -368,7 +368,7 @@ public class PortForwardingTest extends BaseTestSupport {
s.setSoTimeout((int) TimeUnit.SECONDS.toMillis(10L));
String expected = getCurrentTestName();
- byte[] bytes = expected.getBytes();
+ byte[] bytes = expected.getBytes(StandardCharsets.UTF_8);
output.write(bytes);
output.flush();
@@ -408,7 +408,7 @@ public class PortForwardingTest extends BaseTestSupport {
SshdSocketAddress bound = session.startLocalPortForwarding(local, remote);
String expected = getCurrentTestName();
- byte[] bytes = expected.getBytes();
+ byte[] bytes = expected.getBytes(StandardCharsets.UTF_8);
byte[] buf = new byte[bytes.length + Long.SIZE];
try(Socket s = new Socket(bound.getHostName(), bound.getPort());
OutputStream output = s.getOutputStream();
@@ -441,7 +441,7 @@ public class PortForwardingTest extends BaseTestSupport {
channel.open().verify(9L, TimeUnit.SECONDS);
String expected = getCurrentTestName();
- byte[] bytes = expected.getBytes();
+ byte[] bytes = expected.getBytes(StandardCharsets.UTF_8);
try(OutputStream output = channel.getInvertedIn();
InputStream input = channel.getInvertedOut()) {
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/e08cbe1a/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 4fd4b13..5dc78ce 100644
--- a/sshd-core/src/test/java/org/apache/sshd/ProxyTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/ProxyTest.java
@@ -24,6 +24,7 @@ import java.io.OutputStream;
import java.net.InetSocketAddress;
import java.net.Proxy;
import java.net.Socket;
+import java.nio.charset.StandardCharsets;
import java.util.concurrent.TimeUnit;
import org.apache.mina.core.buffer.IoBuffer;
@@ -107,7 +108,7 @@ public class ProxyTest extends BaseTestSupport {
SshdSocketAddress dynamic = session.startDynamicPortForwarding(new SshdSocketAddress("localhost", 0));
String expected = getCurrentTestName();
- byte[] bytes = expected.getBytes();
+ byte[] bytes = expected.getBytes(StandardCharsets.UTF_8);
byte[] buf = new byte[bytes.length + Long.SIZE];
for (int i = 0; i < 10; i++) {
try(Socket s = new Socket(new Proxy(Proxy.Type.SOCKS, new InetSocketAddress("localhost", dynamic.getPort())))) {
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/e08cbe1a/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 3da6f0a..1bf282f 100644
--- a/sshd-core/src/test/java/org/apache/sshd/WindowAdjustTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/WindowAdjustTest.java
@@ -21,6 +21,7 @@ package org.apache.sshd;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
+import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Deque;
@@ -166,7 +167,7 @@ public class WindowAdjustTest {
for (int i = 0; i < sendCount; i++) {
a.write(new ByteArrayBuffer(msg));
}
- a.write(new ByteArrayBuffer((lastMsg.getBytes())));
+ a.write(new ByteArrayBuffer((lastMsg.getBytes(StandardCharsets.UTF_8))));
}
}).start();
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/e08cbe1a/sshd-core/src/test/java/org/apache/sshd/WindowTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/WindowTest.java b/sshd-core/src/test/java/org/apache/sshd/WindowTest.java
index 251ea64..045fad3 100644
--- a/sshd-core/src/test/java/org/apache/sshd/WindowTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/WindowTest.java
@@ -25,6 +25,7 @@ import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PipedInputStream;
import java.io.PipedOutputStream;
+import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
@@ -278,10 +279,9 @@ public class WindowTest extends BaseTestSupport {
Window serverRemote = serverChannel.getRemoteWindow();
final String message = "0123456789\n";
- final byte[] bytes=message.getBytes();
+ final byte[] bytes=message.getBytes(StandardCharsets.UTF_8);
final int nbMessages = 500;
for (int i = 0; i < nbMessages; i++) {
-
Buffer buffer = new ByteArrayBuffer(bytes);
channel.getAsyncIn().write(buffer).verify();
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/e08cbe1a/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 5bd086b..6aaeb22 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
@@ -23,6 +23,7 @@ import static org.apache.sshd.util.Utils.createTestKeyPairProvider;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
+import java.nio.charset.StandardCharsets;
import java.security.KeyPair;
import java.security.PublicKey;
import java.util.List;
@@ -165,7 +166,7 @@ public class AgentTest extends BaseTestSupport {
channel2.setAgentForwarding(true);
channel2.open().verify(9L, TimeUnit.SECONDS);
- pipedIn.write("foo\n".getBytes());
+ pipedIn.write("foo\n".getBytes(StandardCharsets.UTF_8));
pipedIn.flush();
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/e08cbe1a/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 4aebff8..7937c51 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
@@ -20,19 +20,23 @@ package org.apache.sshd.client;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
+import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PipedInputStream;
import java.io.PipedOutputStream;
import java.net.SocketAddress;
+import java.nio.charset.StandardCharsets;
import java.security.KeyPair;
import java.security.PublicKey;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
+import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
+import java.util.Set;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
@@ -57,6 +61,7 @@ import org.apache.sshd.common.RuntimeSshException;
import org.apache.sshd.common.Service;
import org.apache.sshd.common.SshConstants;
import org.apache.sshd.common.SshException;
+import org.apache.sshd.common.channel.AbstractChannel;
import org.apache.sshd.common.channel.Channel;
import org.apache.sshd.common.cipher.BuiltinCiphers;
import org.apache.sshd.common.future.CloseFuture;
@@ -208,7 +213,7 @@ public class ClientTest extends BaseTestSupport {
channel.setStreaming(ClientChannel.Streaming.Async);
channel.open().verify(5L, TimeUnit.SECONDS);
- final byte[] message = "0123456789\n".getBytes();
+ final byte[] message = "0123456789\n".getBytes(StandardCharsets.UTF_8);
final int nbMessages = 1000;
try(final ByteArrayOutputStream baosOut = new ByteArrayOutputStream();
@@ -296,17 +301,18 @@ public class ClientTest extends BaseTestSupport {
session.addPasswordIdentity(getCurrentTestName());
session.auth().verify(5L, TimeUnit.SECONDS);
- try(ChannelExec channel = session.createExecChannel("test");
+ try(ChannelExec channel = session.createExecChannel(getCurrentTestName());
OutputStream stdout = new NoCloseOutputStream(System.out);
OutputStream stderr = new NoCloseOutputStream(System.err)) {
channel.setOut(stdout);
channel.setErr(stderr);
channel.open().verify(9L, TimeUnit.SECONDS);
- Thread.sleep(100L);
+ Thread.sleep(125L);
try {
+ byte[] data = "a".getBytes(StandardCharsets.UTF_8);
for (int i = 0; i < 100; i++) {
- channel.getInvertedIn().write("a".getBytes());
+ channel.getInvertedIn().write(data);
channel.getInvertedIn().flush();
}
} catch (SshException e) {
@@ -328,7 +334,7 @@ public class ClientTest extends BaseTestSupport {
session.addPasswordIdentity(getCurrentTestName());
session.auth().verify(5L, TimeUnit.SECONDS);
- try(ClientChannel channel = session.createChannel(ClientChannel.CHANNEL_SHELL);
+ try(ClientChannel channel = session.createShellChannel();
ByteArrayOutputStream sent = new ByteArrayOutputStream();
PipedOutputStream pipedIn = new PipedOutputStream();
PipedInputStream pipedOut = new PipedInputStream(pipedIn)) {
@@ -343,7 +349,7 @@ public class ClientTest extends BaseTestSupport {
channel.setErr(err);
channel.open();
- teeOut.write("this is my command\n".getBytes());
+ teeOut.write("this is my command\n".getBytes(StandardCharsets.UTF_8));
teeOut.flush();
StringBuilder sb = new StringBuilder();
@@ -351,9 +357,9 @@ public class ClientTest extends BaseTestSupport {
sb.append("0123456789");
}
sb.append("\n");
- teeOut.write(sb.toString().getBytes());
+ teeOut.write(sb.toString().getBytes(StandardCharsets.UTF_8));
- teeOut.write("exit\n".getBytes());
+ teeOut.write("exit\n".getBytes(StandardCharsets.UTF_8));
teeOut.flush();
channel.waitFor(ClientChannel.CLOSED, 0);
@@ -377,7 +383,7 @@ public class ClientTest extends BaseTestSupport {
session.addPasswordIdentity(getCurrentTestName());
session.auth().verify(5L, TimeUnit.SECONDS);
- try(ClientChannel channel = session.createChannel(ClientChannel.CHANNEL_SHELL);
+ try(ClientChannel channel = session.createShellChannel();
ByteArrayOutputStream sent = new ByteArrayOutputStream();
ByteArrayOutputStream out = new ByteArrayOutputStream();
ByteArrayOutputStream err = new ByteArrayOutputStream()) {
@@ -387,7 +393,7 @@ public class ClientTest extends BaseTestSupport {
channel.open().verify(9L, TimeUnit.SECONDS);
try(OutputStream pipedIn = new TeeOutputStream(sent, channel.getInvertedIn())) {
- pipedIn.write("this is my command\n".getBytes());
+ pipedIn.write("this is my command\n".getBytes(StandardCharsets.UTF_8));
pipedIn.flush();
StringBuilder sb = new StringBuilder();
@@ -395,9 +401,9 @@ public class ClientTest extends BaseTestSupport {
sb.append("0123456789");
}
sb.append("\n");
- pipedIn.write(sb.toString().getBytes());
+ pipedIn.write(sb.toString().getBytes(StandardCharsets.UTF_8));
- pipedIn.write("exit\n".getBytes());
+ pipedIn.write("exit\n".getBytes(StandardCharsets.UTF_8));
pipedIn.flush();
}
@@ -445,7 +451,7 @@ public class ClientTest extends BaseTestSupport {
session.addPasswordIdentity(getCurrentTestName());
session.auth().verify(5L, TimeUnit.SECONDS);
- try(ClientChannel channel = session.createChannel(ClientChannel.CHANNEL_SHELL);
+ try(ClientChannel channel = session.createShellChannel();
ByteArrayOutputStream sent = new ByteArrayOutputStream();
PipedOutputStream pipedIn = new PipedOutputStream();
InputStream inPipe = new PipedInputStream(pipedIn);
@@ -458,7 +464,7 @@ public class ClientTest extends BaseTestSupport {
channel.open();
try(OutputStream teeOut = new TeeOutputStream(sent, pipedIn)) {
- teeOut.write("this is my command\n".getBytes());
+ teeOut.write("this is my command\n".getBytes(StandardCharsets.UTF_8));
teeOut.flush();
StringBuilder sb = new StringBuilder();
@@ -466,7 +472,7 @@ public class ClientTest extends BaseTestSupport {
sb.append("0123456789");
}
sb.append("\n");
- teeOut.write(sb.toString().getBytes());
+ teeOut.write(sb.toString().getBytes(StandardCharsets.UTF_8));
}
channel.waitFor(ClientChannel.CLOSED, 0);
@@ -494,7 +500,7 @@ public class ClientTest extends BaseTestSupport {
session.addPasswordIdentity(getCurrentTestName());
session.auth().verify(5L, TimeUnit.SECONDS);
- try(ClientChannel channel = session.createChannel(ClientChannel.CHANNEL_SHELL);
+ try(ClientChannel channel = session.createShellChannel();
ByteArrayOutputStream sent = new ByteArrayOutputStream();
PipedOutputStream pipedIn = new PipedOutputStream();
InputStream inPipe = new PipedInputStream(pipedIn);
@@ -508,7 +514,7 @@ public class ClientTest extends BaseTestSupport {
int bytes = 0;
- byte[] data = "01234567890123456789012345678901234567890123456789\n".getBytes();
+ byte[] data = "01234567890123456789012345678901234567890123456789\n".getBytes(StandardCharsets.UTF_8);
long t0 = System.currentTimeMillis();
try(OutputStream teeOut = new TeeOutputStream(sent, pipedIn)) {
for (int i = 0; i < 10000; i++) {
@@ -519,7 +525,7 @@ public class ClientTest extends BaseTestSupport {
System.out.println("Bytes written: " + bytes);
}
}
- teeOut.write("exit\n".getBytes());
+ teeOut.write("exit\n".getBytes(StandardCharsets.UTF_8));
teeOut.flush();
}
long t1 = System.currentTimeMillis();
@@ -549,7 +555,7 @@ public class ClientTest extends BaseTestSupport {
session.addPasswordIdentity(getCurrentTestName());
session.auth().verify(5L, TimeUnit.SECONDS);
- try(ClientChannel channel = session.createChannel(ClientChannel.CHANNEL_SHELL)) {
+ try(ClientChannel channel = session.createShellChannel()) {
session.close(false);
try(PipedOutputStream pipedIn = new PipedOutputStream();
@@ -594,7 +600,7 @@ public class ClientTest extends BaseTestSupport {
session.addPasswordIdentity(getCurrentTestName());
session.auth().verify(5L, TimeUnit.SECONDS);
- try(ClientChannel channel = session.createChannel(ClientChannel.CHANNEL_SHELL);
+ try(ClientChannel channel = session.createShellChannel();
InputStream inp = new ByteArrayInputStream(GenericUtils.EMPTY_BYTE_ARRAY);
OutputStream out = new ByteArrayOutputStream();
OutputStream err = new ByteArrayOutputStream()) {
@@ -624,7 +630,7 @@ public class ClientTest extends BaseTestSupport {
session.addPasswordIdentity(getCurrentTestName());
session.auth().verify(5L, TimeUnit.SECONDS);
- try(ClientChannel channel = session.createChannel(ClientChannel.CHANNEL_SHELL);
+ try(ClientChannel channel = session.createShellChannel();
InputStream inp = new ByteArrayInputStream(GenericUtils.EMPTY_BYTE_ARRAY);
OutputStream out = new ByteArrayOutputStream();
OutputStream err = new ByteArrayOutputStream()) {
@@ -957,7 +963,7 @@ public class ClientTest extends BaseTestSupport {
session.addPasswordIdentity(getCurrentTestName());
session.auth().verify(5L, TimeUnit.SECONDS);
- try(ClientChannel channel = session.createChannel(ClientChannel.CHANNEL_SHELL);
+ try(ClientChannel channel = session.createShellChannel();
PipedOutputStream pipedIn = new PipedOutputStream();
InputStream inPipe = new PipedInputStream(pipedIn);
ByteArrayOutputStream out = new ByteArrayOutputStream();
@@ -1034,6 +1040,36 @@ public class ClientTest extends BaseTestSupport {
}
}
+ @Test
+ public void testCreateChannelByType() throws Exception {
+ client.start();
+
+ Collection<ClientChannel> channels = new LinkedList<>();
+ try(ClientSession session = client.connect(getCurrentTestName(), "localhost", port).verify(7L, TimeUnit.SECONDS).getSession()) {
+ session.addPasswordIdentity(getCurrentTestName());
+ session.auth().verify(5L, TimeUnit.SECONDS);
+
+ channels.add(session.createChannel(ClientChannel.CHANNEL_SUBSYSTEM, SftpConstants.SFTP_SUBSYSTEM_NAME));
+ channels.add(session.createChannel(ClientChannel.CHANNEL_EXEC, getCurrentTestName()));
+ channels.add(session.createChannel(ClientChannel.CHANNEL_SHELL, getClass().getSimpleName()));
+
+ Set<Integer> ids = new HashSet<Integer>(channels.size());
+ for (ClientChannel c : channels) {
+ int id = ((AbstractChannel) c).getId();
+ assertTrue("Channel ID repeated: " + id, ids.add(Integer.valueOf(id)));
+ }
+ } finally {
+ for (Closeable c : channels) {
+ try {
+ c.close();
+ } catch(IOException e) {
+ // ignored
+ }
+ }
+ client.stop();
+ }
+ }
+
private void suspend(IoSession ioSession) {
if (ioSession instanceof MinaSession) {
((MinaSession) ioSession).suspend();
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/e08cbe1a/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 8f2f9d8..d5733eb 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
@@ -23,6 +23,7 @@ import java.io.InputStream;
import java.io.OutputStream;
import java.io.PipedInputStream;
import java.io.PipedOutputStream;
+import java.nio.charset.StandardCharsets;
import java.util.Collections;
import java.util.concurrent.TimeUnit;
@@ -129,7 +130,7 @@ public class KexTest extends BaseTestSupport {
channel.setErr(err);
channel.open().verify(9L, TimeUnit.SECONDS);
- teeOut.write("this is my command\n".getBytes());
+ teeOut.write("this is my command\n".getBytes(StandardCharsets.UTF_8));
teeOut.flush();
StringBuilder sb = new StringBuilder();
@@ -137,9 +138,9 @@ public class KexTest extends BaseTestSupport {
sb.append("0123456789");
}
sb.append("\n");
- teeOut.write(sb.toString().getBytes());
+ teeOut.write(sb.toString().getBytes(StandardCharsets.UTF_8));
- teeOut.write("exit\n".getBytes());
+ teeOut.write("exit\n".getBytes(StandardCharsets.UTF_8));
teeOut.flush();
channel.waitFor(ClientChannel.CLOSED, 0);
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/e08cbe1a/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 895852c..945f4ef 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
@@ -631,7 +631,7 @@ public class ScpTest extends BaseTestSupport {
Path remoteDir = assertHierarchyTargetFolderExists(scpRoot.resolve("remote"));
Path remoteFile = remoteDir.resolve(getCurrentTestName() + ".txt");
String remotePath = Utils.resolveRelativeRemotePath(parentPath, remoteFile);
- byte[] data = (getClass().getName() + "#" + getCurrentTestName()).getBytes();
+ byte[] data = (getClass().getName() + "#" + getCurrentTestName()).getBytes(StandardCharsets.UTF_8);
scp.upload(data, remotePath, EnumSet.allOf(PosixFilePermission.class), null);
byte[] uploaded = Files.readAllBytes(remoteFile);
@@ -663,7 +663,7 @@ public class ScpTest extends BaseTestSupport {
private static byte[] writeFile(Path path, String data) throws IOException {
try(OutputStream fos = Files.newOutputStream(path)) {
- byte[] bytes = data.getBytes();
+ byte[] bytes = data.getBytes(StandardCharsets.UTF_8);
fos.write(bytes);
return bytes;
}
@@ -863,7 +863,7 @@ public class ScpTest extends BaseTestSupport {
assertAckReceived(is, command);
assertAckReceived(os, is, "C7777 " + data.length() + " " + name);
- os.write(data.getBytes());
+ os.write(data.getBytes(StandardCharsets.UTF_8));
os.flush();
assertAckReceived(is, "Sent data (length=" + data.length() + ") for " + path + "[" + name + "]");
@@ -877,7 +877,7 @@ public class ScpTest extends BaseTestSupport {
}
protected void assertAckReceived(OutputStream os, InputStream is, String command) throws IOException {
- os.write((command + "\n").getBytes());
+ os.write((command + "\n").getBytes(StandardCharsets.UTF_8));
os.flush();
assertAckReceived(is, command);
}
@@ -898,7 +898,7 @@ public class ScpTest extends BaseTestSupport {
assertAckReceived(is, command);
command = "C7777 " + data.length() + " " + name;
- os.write((command + "\n").getBytes());
+ os.write((command + "\n").getBytes(StandardCharsets.UTF_8));
os.flush();
assertEquals("Mismatched response for command=" + command, 2, is.read());
} finally {
@@ -919,14 +919,14 @@ public class ScpTest extends BaseTestSupport {
assertAckReceived(os, is, "D0755 0 " + dirName);
assertAckReceived(os, is, "C7777 " + data.length() + " " + fileName);
- os.write(data.getBytes());
+ os.write(data.getBytes(StandardCharsets.UTF_8));
os.flush();
assertAckReceived(is, "Send data of " + path);
os.write(0);
os.flush();
- os.write("E\n".getBytes());
+ os.write("E\n".getBytes(StandardCharsets.UTF_8));
os.flush();
assertAckReceived(is, "Signal end of " + path);
} finally {
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/e08cbe1a/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 bfefc71..02f2068 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
@@ -23,6 +23,7 @@ import java.net.URI;
import java.nio.channels.FileChannel;
import java.nio.channels.FileLock;
import java.nio.channels.OverlappingFileLockException;
+import java.nio.charset.StandardCharsets;
import java.nio.file.DirectoryStream;
import java.nio.file.FileAlreadyExistsException;
import java.nio.file.FileStore;
@@ -149,7 +150,7 @@ public class SftpFileSystemTest extends BaseTestSupport {
String remFilePath = Utils.resolveRelativeRemotePath(parentPath, clientFolder.resolve(getCurrentTestName() + ".txt"));
Path file = fs.getPath(remFilePath);
Files.createDirectories(file.getParent());
- Files.write(file, (getCurrentTestName() + "\n").getBytes());
+ Files.write(file, (getCurrentTestName() + "\n").getBytes(StandardCharsets.UTF_8));
Map<String, Object> attrs = Files.readAttributes(file, "posix:*");
assertNotNull("NO attributes read for " + file, attrs);
@@ -346,8 +347,8 @@ public class SftpFileSystemTest extends BaseTestSupport {
String expected="Hello world: " + getCurrentTestName();
{
- Files.write(file1, expected.getBytes());
- String buf = new String(Files.readAllBytes(file1));
+ Files.write(file1, expected.getBytes(StandardCharsets.UTF_8));
+ String buf = new String(Files.readAllBytes(file1), StandardCharsets.UTF_8);
assertEquals("Mismatched read test data", expected, buf);
}
@@ -362,7 +363,7 @@ public class SftpFileSystemTest extends BaseTestSupport {
// expected
}
- Files.write(file2, "h".getBytes());
+ Files.write(file2, "h".getBytes(StandardCharsets.UTF_8));
try {
Files.move(file1, file2);
fail("Unexpected success in moving " + file1 + " => " + file2);
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/e08cbe1a/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 8f37d39..f975d25 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
@@ -285,7 +285,7 @@ public class SftpTest extends AbstractSftpClientTestSupport {
private void testInvalidParams(SftpClient sftp, Path file, String filePath) throws Exception {
// generate random file and upload it
String randomData = randomString(5);
- byte[] randomBytes = randomData.getBytes();
+ byte[] randomBytes = randomData.getBytes(StandardCharsets.UTF_8);
try(SftpClient.CloseableHandle handle = sftp.open(filePath, EnumSet.of(SftpClient.OpenMode.Write, SftpClient.OpenMode.Create))) {
try {
sftp.write(handle, -1, randomBytes, 0, 0);
@@ -328,7 +328,7 @@ public class SftpTest extends AbstractSftpClientTestSupport {
String remotePath = remoteDir + "/" + filename;
String randomData = randomString(size);
try(SftpClient.CloseableHandle handle = sftp.open(remotePath, EnumSet.of(SftpClient.OpenMode.Write, SftpClient.OpenMode.Create))) {
- sftp.write(handle, 0, randomData.getBytes(), 0, randomData.length());
+ sftp.write(handle, 0, randomData.getBytes(StandardCharsets.UTF_8), 0, randomData.length());
}
// verify results
@@ -386,13 +386,13 @@ public class SftpTest extends AbstractSftpClientTestSupport {
ChannelSftp c = (ChannelSftp) session.openChannel(SftpConstants.SFTP_SUBSYSTEM_NAME);
c.connect();
try {
- c.put(new ByteArrayInputStream(data.getBytes()), remotePath);
+ c.put(new ByteArrayInputStream(data.getBytes(StandardCharsets.UTF_8)), remotePath);
assertTrue("Remote file not created after initial write: " + localPath, Files.exists(localPath));
assertEquals("Mismatched data read from " + remotePath, data, readFile(remotePath));
try(OutputStream os = c.put(remotePath, null, ChannelSftp.APPEND, appendOffset)) {
- os.write(extraData.getBytes());
+ os.write(extraData.getBytes(StandardCharsets.UTF_8));
}
} finally {
c.disconnect();
@@ -468,7 +468,7 @@ public class SftpTest extends AbstractSftpClientTestSupport {
Path file1 = clientFolder.resolve(getCurrentTestName() + "-1.txt");
String file1Path = Utils.resolveRelativeRemotePath(parentPath, file1);
try (OutputStream os = sftp.write(file1Path, SftpClient.MIN_WRITE_BUFFER_SIZE)) {
- os.write((getCurrentTestName() + "\n").getBytes());
+ os.write((getCurrentTestName() + "\n").getBytes(StandardCharsets.UTF_8));
}
Path file2 = clientFolder.resolve(getCurrentTestName() + "-2.txt");
@@ -483,7 +483,7 @@ public class SftpTest extends AbstractSftpClientTestSupport {
}
try (OutputStream os = sftp.write(file2Path, SftpClient.MIN_WRITE_BUFFER_SIZE)) {
- os.write("H".getBytes());
+ os.write("H".getBytes(StandardCharsets.UTF_8));
}
try {
@@ -661,7 +661,7 @@ public class SftpTest extends AbstractSftpClientTestSupport {
sftp.mkdir(dir);
try(SftpClient.CloseableHandle h = sftp.open(file, EnumSet.of(SftpClient.OpenMode.Write, SftpClient.OpenMode.Create))) {
- byte[] d = "0123456789\n".getBytes();
+ byte[] d = "0123456789\n".getBytes(StandardCharsets.UTF_8);
sftp.write(h, 0, d, 0, d.length);
sftp.write(h, d.length, d, 0, d.length);
@@ -761,7 +761,7 @@ public class SftpTest extends AbstractSftpClientTestSupport {
ChannelSftp c = (ChannelSftp) session.openChannel(SftpConstants.SFTP_SUBSYSTEM_NAME);
c.connect();
try {
- c.put(new ByteArrayInputStream(data.getBytes()), remSrcPath);
+ c.put(new ByteArrayInputStream(data.getBytes(StandardCharsets.UTF_8)), remSrcPath);
assertTrue("Source file not created: " + sourcePath, Files.exists(sourcePath));
assertEquals("Mismatched stored data in " + remSrcPath, data, readFile(remSrcPath));
@@ -802,7 +802,7 @@ public class SftpTest extends AbstractSftpClientTestSupport {
ChannelSftp c = (ChannelSftp) session.openChannel(SftpConstants.SFTP_SUBSYSTEM_NAME);
c.connect();
try {
- c.put(new ByteArrayInputStream(data.getBytes()), path);
+ c.put(new ByteArrayInputStream(data.getBytes(StandardCharsets.UTF_8)), path);
} finally {
c.disconnect();
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/e08cbe1a/sshd-core/src/test/java/org/apache/sshd/common/channel/ChannelPipedInputStreamTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/common/channel/ChannelPipedInputStreamTest.java b/sshd-core/src/test/java/org/apache/sshd/common/channel/ChannelPipedInputStreamTest.java
index 3f20256..b7f1d9e 100644
--- a/sshd-core/src/test/java/org/apache/sshd/common/channel/ChannelPipedInputStreamTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/common/channel/ChannelPipedInputStreamTest.java
@@ -19,6 +19,7 @@
package org.apache.sshd.common.channel;
import java.io.IOException;
+import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import org.apache.sshd.util.BaseTestSupport;
@@ -37,7 +38,7 @@ public class ChannelPipedInputStreamTest extends BaseTestSupport {
public void testAvailable() throws IOException {
Window window = new Window(new BogusChannel(), null, true, true);
try(ChannelPipedInputStream stream = new ChannelPipedInputStream(window)) {
- byte[] b = getCurrentTestName().getBytes();
+ byte[] b = getCurrentTestName().getBytes(StandardCharsets.UTF_8);
stream.receive(b, 0, b.length);
assertEquals("Mismatched reported available size after receive", b.length, stream.available());
@@ -55,7 +56,7 @@ public class ChannelPipedInputStreamTest extends BaseTestSupport {
public void testIdempotentClose() throws IOException {
Window window = new Window(new BogusChannel(), null, true, true);
try(ChannelPipedInputStream stream = new ChannelPipedInputStream(window)) {
- byte[] b = getCurrentTestName().getBytes();
+ byte[] b = getCurrentTestName().getBytes(StandardCharsets.UTF_8);
stream.receive(b, 0, b.length);
stream.eof();
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/e08cbe1a/sshd-core/src/test/java/org/apache/sshd/common/channel/ChannelPipedOutputStreamTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/common/channel/ChannelPipedOutputStreamTest.java b/sshd-core/src/test/java/org/apache/sshd/common/channel/ChannelPipedOutputStreamTest.java
index 1c7fced..249887c 100644
--- a/sshd-core/src/test/java/org/apache/sshd/common/channel/ChannelPipedOutputStreamTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/common/channel/ChannelPipedOutputStreamTest.java
@@ -20,6 +20,7 @@
package org.apache.sshd.common.channel;
import java.io.IOException;
+import java.nio.charset.StandardCharsets;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
@@ -67,7 +68,7 @@ public class ChannelPipedOutputStreamTest extends BaseTestSupport {
assertTrue("Stream not marked as initially open", stream.isOpen());
assertEquals("Unexpected initial receive count", 0, receiveCount.intValue());
- byte[] b = getCurrentTestName().getBytes();
+ byte[] b = getCurrentTestName().getBytes(StandardCharsets.UTF_8);
stream.write(b);
assertTrue("Stream not marked as still open after write data", stream.isOpen());
assertEquals("Mismatched write data count", b.length, receiveCount.intValue());
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/e08cbe1a/sshd-core/src/test/java/org/apache/sshd/common/cipher/BaseCipherTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/common/cipher/BaseCipherTest.java b/sshd-core/src/test/java/org/apache/sshd/common/cipher/BaseCipherTest.java
index e6537ae..67fe05d 100644
--- a/sshd-core/src/test/java/org/apache/sshd/common/cipher/BaseCipherTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/common/cipher/BaseCipherTest.java
@@ -19,6 +19,7 @@
package org.apache.sshd.common.cipher;
+import java.nio.charset.StandardCharsets;
import java.security.GeneralSecurityException;
import java.security.InvalidKeyException;
@@ -75,7 +76,7 @@ public abstract class BaseCipherTest extends BaseTestSupport {
byte[] key=new byte[keySize], iv=new byte[ivSize];
enc.init(Mode.Encrypt, key, iv);
- byte[] expected=facName.getBytes();
+ byte[] expected=facName.getBytes(StandardCharsets.UTF_8);
byte[] workBuf=expected.clone(); // need to clone since the cipher works in-line
enc.update(workBuf, 0, workBuf.length);
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/e08cbe1a/sshd-core/src/test/java/org/apache/sshd/common/mac/MacTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/common/mac/MacTest.java b/sshd-core/src/test/java/org/apache/sshd/common/mac/MacTest.java
index 3b61822..d7364f1 100644
--- a/sshd-core/src/test/java/org/apache/sshd/common/mac/MacTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/common/mac/MacTest.java
@@ -20,6 +20,7 @@ package org.apache.sshd.common.mac;
import java.io.InputStream;
import java.io.OutputStream;
+import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import org.apache.sshd.common.NamedFactory;
@@ -152,7 +153,7 @@ public class MacTest extends BaseTestSupport {
InputStream is = c.getInputStream()) {
String expected = "this is my command\n";
- byte[] bytes = expected.getBytes();
+ byte[] bytes = expected.getBytes(StandardCharsets.UTF_8);
byte[] data = new byte[bytes.length + Long.SIZE];
for (int i = 0; i < 10; i++) {
os.write(bytes);
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/e08cbe1a/sshd-core/src/test/java/org/apache/sshd/common/session/AbstractSessionTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/common/session/AbstractSessionTest.java b/sshd-core/src/test/java/org/apache/sshd/common/session/AbstractSessionTest.java
index 539653f..ae5c805 100644
--- a/sshd-core/src/test/java/org/apache/sshd/common/session/AbstractSessionTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/common/session/AbstractSessionTest.java
@@ -19,6 +19,7 @@
package org.apache.sshd.common.session;
import java.io.IOException;
+import java.nio.charset.StandardCharsets;
import java.util.Map;
import org.apache.sshd.common.FactoryManager;
@@ -50,38 +51,38 @@ public class AbstractSessionTest extends BaseTestSupport {
@Test
public void testReadIdentSimple() {
- Buffer buf = new ByteArrayBuffer("SSH-2.0-software\r\n".getBytes());
+ Buffer buf = new ByteArrayBuffer("SSH-2.0-software\r\n".getBytes(StandardCharsets.UTF_8));
String ident = session.doReadIdentification(buf);
assertEquals("SSH-2.0-software", ident);
}
@Test
public void testReadIdentWithoutCR() {
- Buffer buf = new ByteArrayBuffer("SSH-2.0-software\n".getBytes());
+ Buffer buf = new ByteArrayBuffer("SSH-2.0-software\n".getBytes(StandardCharsets.UTF_8));
String ident = session.doReadIdentification(buf);
assertEquals("SSH-2.0-software", ident);
}
@Test
public void testReadIdentWithHeaders() {
- Buffer buf = new ByteArrayBuffer(("a header line\r\nSSH-2.0-software\r\n").getBytes());
+ Buffer buf = new ByteArrayBuffer(("a header line\r\nSSH-2.0-software\r\n").getBytes(StandardCharsets.UTF_8));
String ident = session.doReadIdentification(buf);
assertEquals("SSH-2.0-software", ident);
}
@Test
public void testReadIdentWithSplitPackets() {
- Buffer buf = new ByteArrayBuffer("header line\r\nSSH".getBytes());
+ Buffer buf = new ByteArrayBuffer("header line\r\nSSH".getBytes(StandardCharsets.UTF_8));
String ident = session.doReadIdentification(buf);
assertNull(ident);
- buf.putRawBytes("-2.0-software\r\n".getBytes());
+ buf.putRawBytes("-2.0-software\r\n".getBytes(StandardCharsets.UTF_8));
ident = session.doReadIdentification(buf);
assertEquals("SSH-2.0-software", ident);
}
@Test(expected = IllegalStateException.class)
public void testReadIdentBadLineEnding() {
- Buffer buf = new ByteArrayBuffer(("SSH-2.0-software\ra").getBytes());
+ Buffer buf = new ByteArrayBuffer(("SSH-2.0-software\ra").getBytes(StandardCharsets.UTF_8));
String ident = session.doReadIdentification(buf);
fail("Unexpected success: " + ident);
}
@@ -94,7 +95,7 @@ public class AbstractSessionTest extends BaseTestSupport {
"01234567890123456789012345678901234567890123456789" +
"01234567890123456789012345678901234567890123456789" +
"01234567890123456789012345678901234567890123456789" +
- "01234567890123456789012345678901234567890123456789").getBytes());
+ "01234567890123456789012345678901234567890123456789").getBytes(StandardCharsets.UTF_8));
String ident = session.doReadIdentification(buf);
fail("Unexpected success: " + ident);
}
@@ -106,7 +107,7 @@ public class AbstractSessionTest extends BaseTestSupport {
sb.append("01234567890123456789012345678901234567890123456789\r\n");
}
sb.append("SSH-2.0-software\r\n");
- Buffer buf = new ByteArrayBuffer(sb.toString().getBytes());
+ Buffer buf = new ByteArrayBuffer(sb.toString().getBytes(StandardCharsets.UTF_8));
String ident = session.doReadIdentification(buf);
fail("Unexpected success: " + ident);
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/e08cbe1a/sshd-core/src/test/java/org/apache/sshd/common/util/io/LimitInputStreamTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/common/util/io/LimitInputStreamTest.java b/sshd-core/src/test/java/org/apache/sshd/common/util/io/LimitInputStreamTest.java
index 23690f5..ee9e06e 100644
--- a/sshd-core/src/test/java/org/apache/sshd/common/util/io/LimitInputStreamTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/common/util/io/LimitInputStreamTest.java
@@ -21,6 +21,7 @@ package org.apache.sshd.common.util.io;
import java.io.IOException;
import java.io.InputStream;
+import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
@@ -43,7 +44,7 @@ public class LimitInputStreamTest extends BaseTestSupport {
Path targetPath = detectTargetFolder().toPath();
Path rootFolder = assertHierarchyTargetFolderExists(targetPath.resolve(getClass().getSimpleName()));
Path inputFile = rootFolder.resolve(getCurrentTestName() + ".bin");
- byte[] data = (getClass().getName() + "#" + getCurrentTestName()).getBytes();
+ byte[] data = (getClass().getName() + "#" + getCurrentTestName()).getBytes(StandardCharsets.UTF_8);
Files.write(inputFile, data);
try(InputStream in = Files.newInputStream(inputFile)) {
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/e08cbe1a/sshd-core/src/test/java/org/apache/sshd/server/ServerTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/server/ServerTest.java b/sshd-core/src/test/java/org/apache/sshd/server/ServerTest.java
index c77645a..db3e706 100644
--- a/sshd-core/src/test/java/org/apache/sshd/server/ServerTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/server/ServerTest.java
@@ -26,6 +26,7 @@ import java.io.PipedInputStream;
import java.io.PipedOutputStream;
import java.io.StreamCorruptedException;
import java.net.SocketAddress;
+import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.Map;
import java.util.TreeMap;
@@ -636,7 +637,7 @@ public class ServerTest extends BaseTestSupport {
Thread.sleep(5000);
while (true) {
for (int i = 0; i < 100; i++) {
- out.write("0123456789\n".getBytes());
+ out.write("0123456789\n".getBytes(StandardCharsets.UTF_8));
}
out.flush();
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/e08cbe1a/sshd-core/src/test/java/org/apache/sshd/server/shell/InvertedShellWrapperTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/server/shell/InvertedShellWrapperTest.java b/sshd-core/src/test/java/org/apache/sshd/server/shell/InvertedShellWrapperTest.java
index e66a238..ac1333a 100644
--- a/sshd-core/src/test/java/org/apache/sshd/server/shell/InvertedShellWrapperTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/server/shell/InvertedShellWrapperTest.java
@@ -20,6 +20,7 @@ package org.apache.sshd.server.shell;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
+import java.nio.charset.StandardCharsets;
import org.apache.sshd.util.BaseTestSupport;
import org.apache.sshd.util.BogusEnvironment;
@@ -36,7 +37,7 @@ public class InvertedShellWrapperTest extends BaseTestSupport {
public void testStreamsAreFlushedBeforeClosing() throws Exception {
BogusInvertedShell shell = newShell("out", "err");
shell.setAlive(false);
- try(ByteArrayInputStream in = new ByteArrayInputStream("in".getBytes());
+ try(ByteArrayInputStream in = new ByteArrayInputStream("in".getBytes(StandardCharsets.UTF_8));
ByteArrayOutputStream out = new ByteArrayOutputStream(50);
ByteArrayOutputStream err = new ByteArrayOutputStream()) {
@@ -58,8 +59,8 @@ public class InvertedShellWrapperTest extends BaseTestSupport {
private BogusInvertedShell newShell(String contentOut, String contentErr) {
ByteArrayOutputStream in = new ByteArrayOutputStream(20);
- ByteArrayInputStream out = new ByteArrayInputStream(contentOut.getBytes());
- ByteArrayInputStream err = new ByteArrayInputStream(contentErr.getBytes());
+ ByteArrayInputStream out = new ByteArrayInputStream(contentOut.getBytes(StandardCharsets.UTF_8));
+ ByteArrayInputStream err = new ByteArrayInputStream(contentErr.getBytes(StandardCharsets.UTF_8));
return new BogusInvertedShell(in, out, err);
}
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/e08cbe1a/sshd-core/src/test/java/org/apache/sshd/util/AsyncEchoShellFactory.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/util/AsyncEchoShellFactory.java b/sshd-core/src/test/java/org/apache/sshd/util/AsyncEchoShellFactory.java
index f1bbe1d..3aa4c3d 100644
--- a/sshd-core/src/test/java/org/apache/sshd/util/AsyncEchoShellFactory.java
+++ b/sshd-core/src/test/java/org/apache/sshd/util/AsyncEchoShellFactory.java
@@ -21,6 +21,7 @@ package org.apache.sshd.util;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
+import java.nio.charset.StandardCharsets;
import org.apache.sshd.common.Factory;
import org.apache.sshd.common.channel.BufferedIoOutputStream;
@@ -139,7 +140,7 @@ public class AsyncEchoShellFactory implements Factory<Command> {
for (int i = 0; i < buffer.length(); i++) {
if (buffer.charAt(i) == '\n') {
final String s = buffer.substring(0, i + 1);
- final byte[] bytes = s.getBytes();
+ final byte[] bytes = s.getBytes(StandardCharsets.UTF_8);
out.write(new ByteArrayBuffer(bytes)).addListener(new SshFutureListener<IoWriteFuture>() {
@Override
public void operationComplete(IoWriteFuture future) {
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/e08cbe1a/sshd-core/src/test/java/org/apache/sshd/util/EchoShellFactory.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/util/EchoShellFactory.java b/sshd-core/src/test/java/org/apache/sshd/util/EchoShellFactory.java
index da466da..aece47f 100644
--- a/sshd-core/src/test/java/org/apache/sshd/util/EchoShellFactory.java
+++ b/sshd-core/src/test/java/org/apache/sshd/util/EchoShellFactory.java
@@ -24,6 +24,7 @@ import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.InterruptedIOException;
import java.io.OutputStream;
+import java.nio.charset.StandardCharsets;
import org.apache.sshd.common.Factory;
import org.apache.sshd.server.Command;
@@ -113,7 +114,7 @@ public class EchoShellFactory implements Factory<Command> {
if (s == null) {
return;
}
- out.write((s + "\n").getBytes());
+ out.write((s + "\n").getBytes(StandardCharsets.UTF_8));
out.flush();
if ("exit".equals(s)) {
return;
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/e08cbe1a/sshd-git/src/main/java/org/apache/sshd/git/pgm/GitPgmCommand.java
----------------------------------------------------------------------
diff --git a/sshd-git/src/main/java/org/apache/sshd/git/pgm/GitPgmCommand.java b/sshd-git/src/main/java/org/apache/sshd/git/pgm/GitPgmCommand.java
index 210a7cf..5b296b0 100644
--- a/sshd-git/src/main/java/org/apache/sshd/git/pgm/GitPgmCommand.java
+++ b/sshd-git/src/main/java/org/apache/sshd/git/pgm/GitPgmCommand.java
@@ -21,6 +21,7 @@ package org.apache.sshd.git.pgm;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
+import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
@@ -101,7 +102,7 @@ public class GitPgmCommand implements Command, Runnable {
}
} catch (Throwable t) {
try {
- err.write((t.getMessage() + "\n").getBytes());
+ err.write((t.getMessage() + "\n").getBytes(StandardCharsets.UTF_8));
err.flush();
} catch (IOException e) {
e.printStackTrace();
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/e08cbe1a/sshd-git/src/test/java/org/apache/sshd/git/util/EchoShellFactory.java
----------------------------------------------------------------------
diff --git a/sshd-git/src/test/java/org/apache/sshd/git/util/EchoShellFactory.java b/sshd-git/src/test/java/org/apache/sshd/git/util/EchoShellFactory.java
index 9e9b2c2..1ba6add 100644
--- a/sshd-git/src/test/java/org/apache/sshd/git/util/EchoShellFactory.java
+++ b/sshd-git/src/test/java/org/apache/sshd/git/util/EchoShellFactory.java
@@ -23,6 +23,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
+import java.nio.charset.StandardCharsets;
import org.apache.sshd.common.Factory;
import org.apache.sshd.server.Command;
@@ -107,7 +108,7 @@ public class EchoShellFactory implements Factory<Command> {
if (s == null) {
return;
}
- out.write((s + "\n").getBytes());
+ out.write((s + "\n").getBytes(StandardCharsets.UTF_8));
out.flush();
if ("exit".equals(s)) {
return;