diff --git a/src/Renci.SshNet/Channels/Channel.cs b/src/Renci.SshNet/Channels/Channel.cs
index e1e154ffd..2bf8e2031 100644
--- a/src/Renci.SshNet/Channels/Channel.cs
+++ b/src/Renci.SshNet/Channels/Channel.cs
@@ -275,7 +275,7 @@ protected bool IsConnected
/// Gets the connection info.
///
/// The connection info.
- protected IConnectionInfo ConnectionInfo
+ protected ISshConnectionInfo ConnectionInfo
{
get { return _session.ConnectionInfo; }
}
diff --git a/src/Renci.SshNet/Channels/ChannelDirectTcpip.cs b/src/Renci.SshNet/Channels/ChannelDirectTcpip.cs
index 6a07d59b0..3720f26bf 100644
--- a/src/Renci.SshNet/Channels/ChannelDirectTcpip.cs
+++ b/src/Renci.SshNet/Channels/ChannelDirectTcpip.cs
@@ -58,7 +58,10 @@ public void Open(string remoteHost, uint port, IForwardedPort forwardedPort, Soc
_socket = socket;
_forwardedPort = forwardedPort;
- _forwardedPort.Closing += ForwardedPort_Closing;
+ if (_forwardedPort != null)
+ {
+ _forwardedPort.Closing += ForwardedPort_Closing;
+ }
var ep = (IPEndPoint)socket.RemoteEndPoint;
diff --git a/src/Renci.SshNet/Channels/JumpChannel.cs b/src/Renci.SshNet/Channels/JumpChannel.cs
new file mode 100644
index 000000000..01d725cfd
--- /dev/null
+++ b/src/Renci.SshNet/Channels/JumpChannel.cs
@@ -0,0 +1,215 @@
+using System;
+using System.Net;
+using System.Net.Sockets;
+using System.Threading;
+
+using Renci.SshNet.Common;
+
+namespace Renci.SshNet.Channels
+{
+ ///
+ /// Implements "direct-tcpip" SSH channel.
+ ///
+ internal sealed class JumpChannel : IDisposable
+ {
+ private readonly ISession _session;
+ private readonly EventWaitHandle _channelOpen = new AutoResetEvent(initialState: false);
+
+ private Socket _listener;
+
+ ///
+ /// Gets the bound host.
+ ///
+ public string BoundHost { get; private set; }
+
+ ///
+ /// Gets the bound port.
+ ///
+ public uint BoundPort { get; private set; }
+
+ ///
+ /// Gets the forwarded host.
+ ///
+ public string Host { get; private set; }
+
+ ///
+ /// Gets the forwarded port.
+ ///
+ public uint Port { get; private set; }
+
+ ///
+ /// Gets a value indicating whether port forwarding is started.
+ ///
+ ///
+ /// true if port forwarding is started; otherwise, false.
+ ///
+ public bool IsStarted
+ { get; private set; }
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The session used to create the channel.
+ /// The host.
+ /// The port.
+ /// is null.
+ /// is greater than .
+ public JumpChannel(ISession session, string host, uint port)
+ {
+ if (host == null)
+ {
+ throw new ArgumentNullException(nameof(host));
+ }
+
+ port.ValidatePort("port");
+
+ Host = host;
+ Port = port;
+
+ _session = session;
+ }
+
+ public Socket Connect()
+ {
+ var ep = new IPEndPoint(IPAddress.Loopback, 0);
+ _listener = new Socket(ep.AddressFamily, SocketType.Stream, ProtocolType.Tcp) { NoDelay = true };
+ _listener.Bind(ep);
+ _listener.Listen(1);
+
+ IsStarted = true;
+
+ // update bound port (in case original was passed as zero)
+ ep.Port = ((IPEndPoint)_listener.LocalEndPoint).Port;
+
+ using (var e = new SocketAsyncEventArgs())
+ {
+ e.Completed += AcceptCompleted;
+
+ // only accept new connections while we are started
+ if (!_listener.AcceptAsync(e))
+ {
+ AcceptCompleted(sender: null, e);
+ }
+ }
+
+ var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
+ socket.Connect(ep);
+
+ // Wait for channel to open
+ _session.WaitOnHandle(_channelOpen);
+ _listener.Dispose();
+ _listener = null;
+
+ return socket;
+ }
+
+ #region IDisposable Members
+
+ private bool _isDisposed;
+
+ ///
+ /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
+ ///
+ public void Dispose()
+ {
+ Dispose(disposing: true);
+ GC.SuppressFinalize(this);
+ }
+
+ ///
+ /// Releases unmanaged and - optionally - managed resources.
+ ///
+ /// true to release both managed and unmanaged resources; false to release only unmanaged resources.
+ private void Dispose(bool disposing)
+ {
+ if (_isDisposed)
+ {
+ return;
+ }
+
+ if (disposing)
+ {
+ // Don't dispose the _session here, as it's considered 'owned' by the object that instantiated this JumpChannel (usually SSHConnector)
+ }
+
+ _isDisposed = true;
+ }
+
+ ///
+ /// Releases unmanaged resources and performs other cleanup operations before the
+ /// is reclaimed by garbage collection.
+ ///
+ ~JumpChannel()
+ {
+ Dispose(disposing: false);
+ }
+
+ #endregion
+
+ private void AcceptCompleted(object sender, SocketAsyncEventArgs e)
+ {
+ if (e.SocketError is SocketError.OperationAborted or SocketError.NotSocket)
+ {
+ // server was stopped
+ return;
+ }
+
+ // capture client socket
+ var clientSocket = e.AcceptSocket;
+
+ if (e.SocketError != SocketError.Success)
+ {
+ // dispose broken client socket
+ CloseClientSocket(clientSocket);
+ return;
+ }
+
+ _ = _channelOpen.Set();
+
+ // process connection
+ ProcessAccept(clientSocket);
+ }
+
+ private void ProcessAccept(Socket clientSocket)
+ {
+ // close the client socket if we're no longer accepting new connections
+ if (!IsStarted)
+ {
+ CloseClientSocket(clientSocket);
+ return;
+ }
+
+ try
+ {
+ var originatorEndPoint = (IPEndPoint)clientSocket.RemoteEndPoint;
+
+ using (var channel = _session.CreateChannelDirectTcpip())
+ {
+ channel.Open(Host, Port, forwardedPort: null, clientSocket);
+ channel.Bind();
+ }
+ }
+ catch
+ {
+ CloseClientSocket(clientSocket);
+ }
+ }
+
+ private static void CloseClientSocket(Socket clientSocket)
+ {
+ if (clientSocket.Connected)
+ {
+ try
+ {
+ clientSocket.Shutdown(SocketShutdown.Send);
+ }
+ catch (Exception)
+ {
+ // ignore exception when client socket was already closed
+ }
+ }
+
+ clientSocket.Dispose();
+ }
+ }
+}
diff --git a/src/Renci.SshNet/Connection/ConnectorBase.cs b/src/Renci.SshNet/Connection/ConnectorBase.cs
index 735e88c53..5a817c075 100644
--- a/src/Renci.SshNet/Connection/ConnectorBase.cs
+++ b/src/Renci.SshNet/Connection/ConnectorBase.cs
@@ -12,17 +12,27 @@ namespace Renci.SshNet.Connection
{
internal abstract class ConnectorBase : IConnector
{
- protected ConnectorBase(ISocketFactory socketFactory)
+ private bool _disposedValue;
+
+ protected ConnectorBase(IServiceFactory serviceFactory, ISocketFactory socketFactory)
{
+ if (serviceFactory is null)
+ {
+ throw new ArgumentNullException(nameof(serviceFactory));
+ }
+
if (socketFactory is null)
{
throw new ArgumentNullException(nameof(socketFactory));
}
+ ServiceFactory = serviceFactory;
SocketFactory = socketFactory;
}
+ internal IServiceFactory ServiceFactory { get; private set; }
internal ISocketFactory SocketFactory { get; private set; }
+ internal IConnector ProxyConnection { get; set; }
public abstract Socket Connect(IConnectionInfo connectionInfo);
@@ -143,5 +153,34 @@ protected static int SocketRead(Socket socket, byte[] buffer, int offset, int le
return bytesRead;
}
+
+ protected virtual void Dispose(bool disposing)
+ {
+ if (!_disposedValue)
+ {
+ if (disposing)
+ {
+ var proxyConnection = ProxyConnection;
+ if (proxyConnection != null)
+ {
+ proxyConnection.Dispose();
+ ProxyConnection = null;
+ }
+
+ // TODO: dispose managed state (managed objects)
+ }
+
+ // TODO: free unmanaged resources (unmanaged objects) and override finalizer
+ // TODO: set large fields to null
+ _disposedValue = true;
+ }
+ }
+
+ public void Dispose()
+ {
+ // Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
+ Dispose(disposing: true);
+ GC.SuppressFinalize(this);
+ }
}
}
diff --git a/src/Renci.SshNet/Connection/DirectConnector.cs b/src/Renci.SshNet/Connection/DirectConnector.cs
index bf6db0d73..e90bd0ca4 100644
--- a/src/Renci.SshNet/Connection/DirectConnector.cs
+++ b/src/Renci.SshNet/Connection/DirectConnector.cs
@@ -6,8 +6,8 @@ namespace Renci.SshNet.Connection
{
internal sealed class DirectConnector : ConnectorBase
{
- public DirectConnector(ISocketFactory socketFactory)
- : base(socketFactory)
+ public DirectConnector(IServiceFactory serviceFactory, ISocketFactory socketFactory)
+ : base(serviceFactory, socketFactory)
{
}
diff --git a/src/Renci.SshNet/Connection/HttpConnector.cs b/src/Renci.SshNet/Connection/HttpConnector.cs
index a05222fe3..af9dbb772 100644
--- a/src/Renci.SshNet/Connection/HttpConnector.cs
+++ b/src/Renci.SshNet/Connection/HttpConnector.cs
@@ -48,24 +48,25 @@ internal sealed partial class HttpConnector : ProxyConnector
private static readonly Regex HttpHeaderRegex = new Regex(HttpHeaderPattern, RegexOptions.Compiled);
#endif
- public HttpConnector(ISocketFactory socketFactory)
- : base(socketFactory)
+ public HttpConnector(IServiceFactory serviceFactory, ISocketFactory socketFactory)
+ : base(serviceFactory, socketFactory)
{
}
protected override void HandleProxyConnect(IConnectionInfo connectionInfo, Socket socket)
{
+ var proxyConnection = (IProxyConnectionInfo)connectionInfo.ProxyConnection;
SocketAbstraction.Send(socket, SshData.Ascii.GetBytes(string.Format(CultureInfo.InvariantCulture,
"CONNECT {0}:{1} HTTP/1.0\r\n",
connectionInfo.Host,
connectionInfo.Port)));
// Send proxy authorization if specified
- if (!string.IsNullOrEmpty(connectionInfo.ProxyUsername))
+ if (!string.IsNullOrEmpty(proxyConnection.Username))
{
var authorization = string.Format(CultureInfo.InvariantCulture,
"Proxy-Authorization: Basic {0}\r\n",
- Convert.ToBase64String(SshData.Ascii.GetBytes($"{connectionInfo.ProxyUsername}:{connectionInfo.ProxyPassword}")));
+ Convert.ToBase64String(SshData.Ascii.GetBytes($"{proxyConnection.Username}:{proxyConnection.Password}")));
SocketAbstraction.Send(socket, SshData.Ascii.GetBytes(authorization));
}
diff --git a/src/Renci.SshNet/Connection/IConnector.cs b/src/Renci.SshNet/Connection/IConnector.cs
index 6ce454eb2..5842a0396 100644
--- a/src/Renci.SshNet/Connection/IConnector.cs
+++ b/src/Renci.SshNet/Connection/IConnector.cs
@@ -1,4 +1,5 @@
-using System.Net.Sockets;
+using System;
+using System.Net.Sockets;
using System.Threading;
namespace Renci.SshNet.Connection
@@ -6,7 +7,7 @@ namespace Renci.SshNet.Connection
///
/// Represents a means to connect to a SSH endpoint.
///
- internal interface IConnector
+ internal interface IConnector : IDisposable
{
///
/// Connects to a SSH endpoint using the specified .
diff --git a/src/Renci.SshNet/Connection/ProxyConnector.cs b/src/Renci.SshNet/Connection/ProxyConnector.cs
index 2e5b715b5..11412a333 100644
--- a/src/Renci.SshNet/Connection/ProxyConnector.cs
+++ b/src/Renci.SshNet/Connection/ProxyConnector.cs
@@ -1,5 +1,4 @@
using System;
-using System.Net;
using System.Net.Sockets;
using System.Threading;
using System.Threading.Tasks;
@@ -12,11 +11,26 @@ namespace Renci.SshNet.Connection
///
internal abstract class ProxyConnector : ConnectorBase
{
- protected ProxyConnector(ISocketFactory socketFactory)
- : base(socketFactory)
+ protected ProxyConnector(IServiceFactory serviceFactory, ISocketFactory socketFactory)
+ : base(serviceFactory, socketFactory)
{
}
+ protected internal IConnector GetProxyConnector(IConnectionInfo proxyConnectionInfo)
+ {
+ if (proxyConnectionInfo == null)
+ {
+ throw new ArgumentNullException("connectionInfo.ProxyConnection");
+ }
+
+ if (proxyConnectionInfo is not IProxyConnectionInfo)
+ {
+ throw new ArgumentException("Expecting ProxyConnection to be of type IProxyConnectionInfo");
+ }
+
+ return ServiceFactory.CreateConnector(proxyConnectionInfo, SocketFactory);
+ }
+
protected abstract void HandleProxyConnect(IConnectionInfo connectionInfo, Socket socket);
// ToDo: Performs async/sync fallback, true async version should be implemented in derived classes
@@ -53,7 +67,8 @@ Task HandleProxyConnectAsync(IConnectionInfo connectionInfo, Socket socket, Canc
///
public override Socket Connect(IConnectionInfo connectionInfo)
{
- var socket = SocketConnect(new DnsEndPoint(connectionInfo.ProxyHost, connectionInfo.ProxyPort), connectionInfo.Timeout);
+ ProxyConnection = GetProxyConnector(connectionInfo.ProxyConnection);
+ var socket = ProxyConnection.Connect(connectionInfo.ProxyConnection);
try
{
@@ -79,7 +94,8 @@ public override Socket Connect(IConnectionInfo connectionInfo)
///
public override async Task ConnectAsync(IConnectionInfo connectionInfo, CancellationToken cancellationToken)
{
- var socket = await SocketConnectAsync(new DnsEndPoint(connectionInfo.ProxyHost, connectionInfo.ProxyPort), cancellationToken).ConfigureAwait(false);
+ ProxyConnection = GetProxyConnector(connectionInfo.ProxyConnection);
+ var socket = await ProxyConnection.ConnectAsync(connectionInfo.ProxyConnection, cancellationToken).ConfigureAwait(false);
try
{
diff --git a/src/Renci.SshNet/Connection/Socks4Connector.cs b/src/Renci.SshNet/Connection/Socks4Connector.cs
index ecc3d3dea..420541f99 100644
--- a/src/Renci.SshNet/Connection/Socks4Connector.cs
+++ b/src/Renci.SshNet/Connection/Socks4Connector.cs
@@ -17,8 +17,8 @@ namespace Renci.SshNet.Connection
///
internal sealed class Socks4Connector : ProxyConnector
{
- public Socks4Connector(ISocketFactory socketFactory)
- : base(socketFactory)
+ public Socks4Connector(IServiceFactory serviceFactory, ISocketFactory socketFactory)
+ : base(serviceFactory, socketFactory)
{
}
@@ -29,7 +29,10 @@ public Socks4Connector(ISocketFactory socketFactory)
/// The .
protected override void HandleProxyConnect(IConnectionInfo connectionInfo, Socket socket)
{
- var connectionRequest = CreateSocks4ConnectionRequest(connectionInfo.Host, (ushort)connectionInfo.Port, connectionInfo.ProxyUsername);
+ // socket is connected to the proxyhost. When we send a Socks4 connection request we need the username,
+ // which is stored in the ProxyConnection of the current connectionInfo
+ var proxyConnection = (IProxyConnectionInfo)connectionInfo.ProxyConnection;
+ var connectionRequest = CreateSocks4ConnectionRequest(connectionInfo.Host, (ushort)connectionInfo.Port, proxyConnection.Username);
SocketAbstraction.Send(socket, connectionRequest);
// Read reply version
diff --git a/src/Renci.SshNet/Connection/Socks5Connector.cs b/src/Renci.SshNet/Connection/Socks5Connector.cs
index a548eaea4..f99bea3ff 100644
--- a/src/Renci.SshNet/Connection/Socks5Connector.cs
+++ b/src/Renci.SshNet/Connection/Socks5Connector.cs
@@ -18,8 +18,8 @@ namespace Renci.SshNet.Connection
///
internal sealed class Socks5Connector : ProxyConnector
{
- public Socks5Connector(ISocketFactory socketFactory)
- : base(socketFactory)
+ public Socks5Connector(IServiceFactory serviceFactory, ISocketFactory socketFactory)
+ : base(serviceFactory, socketFactory)
{
}
@@ -30,6 +30,7 @@ public Socks5Connector(ISocketFactory socketFactory)
/// The .
protected override void HandleProxyConnect(IConnectionInfo connectionInfo, Socket socket)
{
+ var proxyConnection = (IProxyConnectionInfo)connectionInfo.ProxyConnection;
var greeting = new byte[]
{
// SOCKS version number
@@ -60,7 +61,7 @@ protected override void HandleProxyConnect(IConnectionInfo connectionInfo, Socke
break;
case 0x02:
// Create username/password authentication request
- var authenticationRequest = CreateSocks5UserNameAndPasswordAuthenticationRequest(connectionInfo.ProxyUsername, connectionInfo.ProxyPassword);
+ var authenticationRequest = CreateSocks5UserNameAndPasswordAuthenticationRequest(proxyConnection.Username, proxyConnection.Password);
// Send authentication request
SocketAbstraction.Send(socket, authenticationRequest);
diff --git a/src/Renci.SshNet/Connection/SshConnector.cs b/src/Renci.SshNet/Connection/SshConnector.cs
new file mode 100644
index 000000000..75c2c9e41
--- /dev/null
+++ b/src/Renci.SshNet/Connection/SshConnector.cs
@@ -0,0 +1,80 @@
+using System;
+using System.Net.Sockets;
+using System.Threading;
+using System.Threading.Tasks;
+
+using Renci.SshNet.Channels;
+
+namespace Renci.SshNet.Connection
+{
+ internal sealed class SshConnector : ConnectorBase
+ {
+ private Session _jumpSession;
+ private JumpChannel _jumpChannel;
+
+ public SshConnector(IServiceFactory serviceFactory, ISocketFactory socketFactory)
+ : base(serviceFactory, socketFactory)
+ {
+ }
+
+ public override Socket Connect(IConnectionInfo connectionInfo)
+ {
+ var proxyConnection = connectionInfo.ProxyConnection;
+ if (proxyConnection == null)
+ {
+ throw new ArgumentNullException("connectionInfo.ProxyConnection");
+ }
+
+ if (proxyConnection.GetType() != typeof(ConnectionInfo))
+ {
+ throw new ArgumentException("Expecting connectionInfo to be of type ConnectionInfo");
+ }
+
+ _jumpSession = new Session((ConnectionInfo)proxyConnection, ServiceFactory, SocketFactory);
+ _jumpSession.Connect();
+ _jumpChannel = new JumpChannel(_jumpSession, connectionInfo.Host, (uint)connectionInfo.Port);
+ return _jumpChannel.Connect();
+ }
+
+ public override async Task ConnectAsync(IConnectionInfo connectionInfo, CancellationToken cancellationToken)
+ {
+ var proxyConnection = connectionInfo.ProxyConnection;
+ if (proxyConnection == null)
+ {
+ throw new ArgumentNullException("connectionInfo.ProxyConnection");
+ }
+
+ if (proxyConnection.GetType() != typeof(ConnectionInfo))
+ {
+ throw new ArgumentException("Expecting connectionInfo to be of type ConnectionInfo");
+ }
+
+ _jumpSession = new Session((ConnectionInfo)proxyConnection, ServiceFactory, SocketFactory);
+ await _jumpSession.ConnectAsync(cancellationToken).ConfigureAwait(false);
+ _jumpChannel = new JumpChannel(_jumpSession, connectionInfo.Host, (uint)connectionInfo.Port);
+ return _jumpChannel.Connect();
+ }
+
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing)
+ {
+ var jumpChannel = _jumpChannel;
+ if (jumpChannel != null)
+ {
+ jumpChannel.Dispose();
+ _jumpChannel = null;
+ }
+
+ var jumpSession = _jumpSession;
+ if (jumpSession != null)
+ {
+ jumpSession.Dispose();
+ _jumpSession = null;
+ }
+ }
+
+ base.Dispose(disposing);
+ }
+ }
+}
diff --git a/src/Renci.SshNet/ConnectionInfo.cs b/src/Renci.SshNet/ConnectionInfo.cs
index 1c923286c..5ca67e61b 100644
--- a/src/Renci.SshNet/ConnectionInfo.cs
+++ b/src/Renci.SshNet/ConnectionInfo.cs
@@ -124,24 +124,9 @@ public class ConnectionInfo : IConnectionInfoInternal
public ProxyTypes ProxyType { get; private set; }
///
- /// Gets proxy connection host.
+ /// Gets connection info used for connecting through a proxy.
///
- public string ProxyHost { get; private set; }
-
- ///
- /// Gets proxy connection port.
- ///
- public int ProxyPort { get; private set; }
-
- ///
- /// Gets proxy connection username.
- ///
- public string ProxyUsername { get; private set; }
-
- ///
- /// Gets proxy connection password.
- ///
- public string ProxyPassword { get; private set; }
+ public IConnectionInfo ProxyConnection { get; private set; }
///
/// Gets or sets connection timeout.
@@ -280,7 +265,7 @@ public TimeSpan ChannelCloseTimeout
/// is .
/// No specified.
public ConnectionInfo(string host, string username, params AuthenticationMethod[] authenticationMethods)
- : this(host, DefaultPort, username, ProxyTypes.None, proxyHost: null, 0, proxyUsername: null, proxyPassword: null, authenticationMethods)
+ : this(host, DefaultPort, username, ProxyTypes.None, proxyConnection: null, authenticationMethods)
{
}
@@ -297,7 +282,7 @@ public ConnectionInfo(string host, string username, params AuthenticationMethod[
/// is .
/// No specified.
public ConnectionInfo(string host, int port, string username, params AuthenticationMethod[] authenticationMethods)
- : this(host, port, username, ProxyTypes.None, proxyHost: null, 0, proxyUsername: null, proxyPassword: null, authenticationMethods)
+ : this(host, port, username, ProxyTypes.None, proxyConnection: null, authenticationMethods)
{
}
@@ -316,11 +301,28 @@ public ConnectionInfo(string host, int port, string username, params Authenticat
/// is .
/// is , a zero-length string or contains only whitespace characters.
/// is not within and .
- /// is not and is .
- /// is not and is not within and .
/// is .
/// No specified.
public ConnectionInfo(string host, int port, string username, ProxyTypes proxyType, string proxyHost, int proxyPort, string proxyUsername, string proxyPassword, params AuthenticationMethod[] authenticationMethods)
+ : this(host, port, username, proxyType, proxyType == ProxyTypes.None ? null : new ProxyConnectionInfo(proxyHost, proxyPort, proxyUsername, proxyPassword), authenticationMethods)
+ {
+ }
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// Connection host.
+ /// Connection port.
+ /// Connection username.
+ /// Type of the proxy.
+ /// The proxy host.
+ /// The authentication methods.
+ /// is null.
+ /// is null, a zero-length string or contains only whitespace characters.
+ /// is not within and .
+ /// is null.
+ /// No specified.
+ public ConnectionInfo(string host, int port, string username, ProxyTypes proxyType, IConnectionInfo proxyConnection, params AuthenticationMethod[] authenticationMethods)
{
if (host is null)
{
@@ -341,12 +343,10 @@ public ConnectionInfo(string host, int port, string username, ProxyTypes proxyTy
if (proxyType != ProxyTypes.None)
{
- if (proxyHost is null)
+ if (proxyConnection is null)
{
- throw new ArgumentNullException(nameof(proxyHost));
+ throw new ArgumentNullException(nameof(proxyConnection));
}
-
- proxyPort.ValidatePort("proxyPort");
}
if (authenticationMethods is null)
@@ -452,10 +452,7 @@ public ConnectionInfo(string host, int port, string username, ProxyTypes proxyTy
Username = username;
ProxyType = proxyType;
- ProxyHost = proxyHost;
- ProxyPort = proxyPort;
- ProxyUsername = proxyUsername;
- ProxyPassword = proxyPassword;
+ ProxyConnection = proxyConnection;
AuthenticationMethods = authenticationMethods;
}
diff --git a/src/Renci.SshNet/ForwardedPortDynamic.cs b/src/Renci.SshNet/ForwardedPortDynamic.cs
index f09d73369..b93ee7cc5 100644
--- a/src/Renci.SshNet/ForwardedPortDynamic.cs
+++ b/src/Renci.SshNet/ForwardedPortDynamic.cs
@@ -35,9 +35,9 @@ public class ForwardedPortDynamic : ForwardedPort
public string BoundHost { get; }
///
- /// Gets the bound port.
+ /// Gets or sets the bound port.
///
- public uint BoundPort { get; }
+ public uint BoundPort { get; protected set; }
private Socket _listener;
private CountdownEvent _pendingChannelCountdown;
@@ -171,6 +171,9 @@ private void InternalStart()
_listener.Bind(ep);
_listener.Listen(5);
+ // update bound port (in case original was passed as zero)
+ BoundPort = (uint)((IPEndPoint)_listener.LocalEndPoint).Port;
+
Session.ErrorOccured += Session_ErrorOccured;
Session.Disconnected += Session_Disconnected;
diff --git a/src/Renci.SshNet/IConnectionInfo.cs b/src/Renci.SshNet/IConnectionInfo.cs
index 35dabcc2f..b36f3714c 100644
--- a/src/Renci.SshNet/IConnectionInfo.cs
+++ b/src/Renci.SshNet/IConnectionInfo.cs
@@ -10,28 +10,8 @@ namespace Renci.SshNet
///
/// Represents remote connection information.
///
- internal interface IConnectionInfo
+ public interface IConnectionInfo
{
- ///
- /// Gets the timeout to used when waiting for a server to acknowledge closing a channel.
- ///
- ///
- /// The channel close timeout. The default value is 1 second.
- ///
- ///
- /// If a server does not send a SSH2_MSG_CHANNEL_CLOSE message before the specified timeout
- /// elapses, the channel will be closed immediately.
- ///
- TimeSpan ChannelCloseTimeout { get; }
-
- ///
- /// Gets the supported channel requests for this connection.
- ///
- ///
- /// The supported channel requests for this connection.
- ///
- IDictionary ChannelRequests { get; }
-
///
/// Gets the character encoding.
///
@@ -65,24 +45,43 @@ internal interface IConnectionInfo
ProxyTypes ProxyType { get; }
///
- /// Gets proxy connection host.
+ /// Gets the connection info to connect to the proxy.
///
- string ProxyHost { get; }
+ IConnectionInfo ProxyConnection { get; }
///
- /// Gets proxy connection port.
+ /// Gets the connection timeout.
///
- int ProxyPort { get; }
+ ///
+ /// The connection timeout. The default value is 30 seconds.
+ ///
+ TimeSpan Timeout { get; }
+ }
+ ///
+ /// Represents remote SSH connection information.
+ ///
+ internal interface ISshConnectionInfo : IConnectionInfo
+ {
///
- /// Gets proxy connection username.
+ /// Gets the timeout to used when waiting for a server to acknowledge closing a channel.
///
- string ProxyUsername { get; }
+ ///
+ /// The channel close timeout. The default value is 1 second.
+ ///
+ ///
+ /// If a server does not send a SSH2_MSG_CHANNEL_CLOSE message before the specified timeout
+ /// elapses, the channel will be closed immediately.
+ ///
+ TimeSpan ChannelCloseTimeout { get; }
///
- /// Gets proxy connection password.
+ /// Gets the supported channel requests for this connection.
///
- string ProxyPassword { get; }
+ ///
+ /// The supported channel requests for this connection.
+ ///
+ IDictionary ChannelRequests { get; }
///
/// Gets the number of retry attempts when session channel creation failed.
@@ -93,16 +92,24 @@ internal interface IConnectionInfo
int RetryAttempts { get; }
///
- /// Gets the connection timeout.
+ /// Occurs when authentication banner is sent by the server.
///
- ///
- /// The connection timeout. The default value is 30 seconds.
- ///
- TimeSpan Timeout { get; }
+ event EventHandler AuthenticationBanner;
+ }
+
+ ///
+ /// Represents proxy connection information (HTTP, SOCKS4, SOCKS5).
+ ///
+ internal interface IProxyConnectionInfo : IConnectionInfo
+ {
+ ///
+ /// Gets the username to authenticate this proxy host.
+ ///
+ string Username { get; }
///
- /// Occurs when authentication banner is sent by the server.
+ /// Gets the password to authenticat this proxy host.
///
- event EventHandler AuthenticationBanner;
+ string Password { get; }
}
}
diff --git a/src/Renci.SshNet/IConnectionInfoInternal.cs b/src/Renci.SshNet/IConnectionInfoInternal.cs
index 053e36dda..86f878b6b 100644
--- a/src/Renci.SshNet/IConnectionInfoInternal.cs
+++ b/src/Renci.SshNet/IConnectionInfoInternal.cs
@@ -7,7 +7,7 @@ namespace Renci.SshNet
///
/// Represents remote connection information.
///
- internal interface IConnectionInfoInternal : IConnectionInfo
+ internal interface IConnectionInfoInternal : ISshConnectionInfo
{
///
/// Signals that an authentication banner message was received from the server.
diff --git a/src/Renci.SshNet/ISession.cs b/src/Renci.SshNet/ISession.cs
index 707d36805..c0dce693f 100644
--- a/src/Renci.SshNet/ISession.cs
+++ b/src/Renci.SshNet/ISession.cs
@@ -20,7 +20,7 @@ internal interface ISession : IDisposable
/// Gets the connection info.
///
/// The connection info.
- IConnectionInfo ConnectionInfo { get; }
+ ISshConnectionInfo ConnectionInfo { get; }
///
/// Gets a value indicating whether the session is connected.
diff --git a/src/Renci.SshNet/ProxyConnectionInfo.cs b/src/Renci.SshNet/ProxyConnectionInfo.cs
new file mode 100644
index 000000000..7b7711e05
--- /dev/null
+++ b/src/Renci.SshNet/ProxyConnectionInfo.cs
@@ -0,0 +1,107 @@
+using System;
+using System.Net;
+using System.Text;
+
+using Renci.SshNet.Common;
+
+namespace Renci.SshNet
+{
+ ///
+ /// Connection info for connecting to a proxy host.
+ ///
+ public class ProxyConnectionInfo : IProxyConnectionInfo
+ {
+ ///
+ /// Gets or sets the character encoding.
+ ///
+ ///
+ /// The character encoding.
+ ///
+ public Encoding Encoding { get; set; }
+
+ ///
+ /// Gets the proxy host to connect through.
+ ///
+ public string Host { get; private set; }
+
+ ///
+ /// Gets the proxy port to connect through.
+ ///
+ public int Port { get; private set; }
+
+ ///
+ /// Gets the username to authenticate this proxy host.
+ ///
+ public string Username { get; private set; }
+
+ ///
+ /// Gets the password to authenticat this proxy host.
+ ///
+ public string Password { get; private set; }
+
+ ///
+ /// Gets or sets connection timeout.
+ ///
+ ///
+ /// The connection timeout. The default value is 30 seconds.
+ ///
+ ///
+ ///
+ ///
+ public TimeSpan Timeout { get; set; }
+
+ ///
+ /// Gets the proxy connection Type when this connection should connect through another proxy host.
+ ///
+ public ProxyTypes ProxyType { get; private set; }
+
+ ///
+ /// Gets the proxy connection to connect through.
+ ///
+ public IConnectionInfo ProxyConnection { get; private set; }
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// Poxy host to connect through.
+ /// Proxy port to connect through.
+ /// Username to use when authenticating the proxy host connection.
+ /// Password to use when authenticating the proxy host connection.
+ public ProxyConnectionInfo(string host, int port, string username, string password)
+ : this(host, port, username, password, ProxyTypes.None, proxyConnection: null)
+ {
+ }
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// Poxy host to connect through.
+ /// Proxy port to connect through.
+ /// Username to use when authenticating the proxy host connection.
+ /// Password to use when authenticating the proxy host connection.
+ /// Proxy type of proxy connection used to connect to this proxy host.
+ /// Connection info to connect to proxy host, through which this proxy host is connected.
+ /// is not and is null.
+ /// is not and is not within and .
+ public ProxyConnectionInfo(string host, int port, string username, string password, ProxyTypes proxyType, IConnectionInfo proxyConnection)
+ {
+ if (host == null)
+ {
+ throw new ArgumentNullException("proxyHost");
+ }
+
+ port.ValidatePort("proxyPort");
+
+ Host = host;
+ Port = port;
+ Username = username;
+ Password = password;
+
+ ProxyType = proxyType;
+ ProxyConnection = proxyConnection;
+
+ Encoding = Encoding.UTF8;
+ Timeout = TimeSpan.FromSeconds(30);
+ }
+ }
+}
diff --git a/src/Renci.SshNet/ProxyTypes.cs b/src/Renci.SshNet/ProxyTypes.cs
index cff5eb247..7cbf3d67c 100644
--- a/src/Renci.SshNet/ProxyTypes.cs
+++ b/src/Renci.SshNet/ProxyTypes.cs
@@ -24,5 +24,8 @@ public enum ProxyTypes
/// An HTTP proxy server.
///
Http,
+
+ /// A Ssh jump server.
+ Ssh,
}
}
diff --git a/src/Renci.SshNet/ServiceFactory.cs b/src/Renci.SshNet/ServiceFactory.cs
index 7c67fbf16..5f998f716 100644
--- a/src/Renci.SshNet/ServiceFactory.cs
+++ b/src/Renci.SshNet/ServiceFactory.cs
@@ -254,13 +254,15 @@ public IConnector CreateConnector(IConnectionInfo connectionInfo, ISocketFactory
switch (connectionInfo.ProxyType)
{
case ProxyTypes.None:
- return new DirectConnector(socketFactory);
+ return new DirectConnector(this, socketFactory);
case ProxyTypes.Socks4:
- return new Socks4Connector(socketFactory);
+ return new Socks4Connector(this, socketFactory);
case ProxyTypes.Socks5:
- return new Socks5Connector(socketFactory);
+ return new Socks5Connector(this, socketFactory);
case ProxyTypes.Http:
- return new HttpConnector(socketFactory);
+ return new HttpConnector(this, socketFactory);
+ case ProxyTypes.Ssh:
+ return new SshConnector(this, socketFactory);
default:
throw new NotSupportedException(string.Format("ProxyTypes '{0}' is not supported.", connectionInfo.ProxyType));
}
diff --git a/src/Renci.SshNet/Session.cs b/src/Renci.SshNet/Session.cs
index 7ff95e27b..839ca33bc 100644
--- a/src/Renci.SshNet/Session.cs
+++ b/src/Renci.SshNet/Session.cs
@@ -195,6 +195,11 @@ public class Session : ISession
private bool _isDisconnectMessageSent;
+ ///
+ /// Holds the proxyConnector object, through which the SSH server is connected.
+ ///
+ private IConnector _proxyConnector;
+
private int _nextChannelNumber;
///
@@ -578,8 +583,8 @@ public void Connect()
// Build list of available messages while connecting
_sshMessageFactory = new SshMessageFactory();
- _socket = _serviceFactory.CreateConnector(ConnectionInfo, _socketFactory)
- .Connect(ConnectionInfo);
+ _proxyConnector = _serviceFactory.CreateConnector(ConnectionInfo, _socketFactory);
+ _socket = _proxyConnector.Connect(ConnectionInfo);
var serverIdentification = _serviceFactory.CreateProtocolVersionExchange()
.Start(ClientVersion, _socket, ConnectionInfo.Timeout);
@@ -1993,6 +1998,13 @@ private void SocketDisconnectAndDispose()
_socket.Dispose();
DiagnosticAbstraction.Log(string.Format("[{0}] Disposed socket.", ToHex(SessionId)));
_socket = null;
+
+ var proxyConnector = _proxyConnector;
+ if (proxyConnector != null)
+ {
+ proxyConnector.Dispose();
+ _proxyConnector = null;
+ }
}
}
finally
@@ -2269,7 +2281,7 @@ protected virtual void Dispose(bool disposing)
/// Gets the connection info.
///
/// The connection info.
- IConnectionInfo ISession.ConnectionInfo
+ ISshConnectionInfo ISession.ConnectionInfo
{
get { return ConnectionInfo; }
}
diff --git a/test/Renci.SshNet.Tests/Classes/Channels/ChannelDirectTcpipTest.cs b/test/Renci.SshNet.Tests/Classes/Channels/ChannelDirectTcpipTest.cs
index 0b67b9174..110b0af4b 100644
--- a/test/Renci.SshNet.Tests/Classes/Channels/ChannelDirectTcpipTest.cs
+++ b/test/Renci.SshNet.Tests/Classes/Channels/ChannelDirectTcpipTest.cs
@@ -21,7 +21,7 @@ public class ChannelDirectTcpipTestTest : TestBase
{
private Mock _sessionMock;
private Mock _forwardedPortMock;
- private Mock _connectionInfoMock;
+ private Mock _connectionInfoMock;
private uint _localChannelNumber;
private uint _localWindowSize;
private uint _localPacketSize;
@@ -50,7 +50,7 @@ protected override void OnInit()
_sessionMock = new Mock(MockBehavior.Strict);
_forwardedPortMock = new Mock(MockBehavior.Strict);
- _connectionInfoMock = new Mock(MockBehavior.Strict);
+ _connectionInfoMock = new Mock(MockBehavior.Strict);
}
[TestMethod]
@@ -68,7 +68,7 @@ public void SocketShouldBeClosedAndBindShouldEndWhenForwardedPortSignalsClosingE
_ = _sessionMock.Setup(p => p.WaitOnHandle(It.IsAny()))
.Callback(p => p.WaitOne());
- var localPortEndPoint = new IPEndPoint(IPAddress.Loopback, 8122);
+ var localPortEndPoint = new IPEndPoint(IPAddress.Loopback, 0);
using (var localPortListener = new AsyncSocketListener(localPortEndPoint))
{
localPortListener.Start();
@@ -95,6 +95,7 @@ public void SocketShouldBeClosedAndBindShouldEndWhenForwardedPortSignalsClosingE
closeForwardedPortThread.Join();
};
+ localPortEndPoint.Port = ((IPEndPoint)localPortListener.ListenerEndPoint).Port;
var client = new Socket(localPortEndPoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
client.Connect(localPortEndPoint);
@@ -124,7 +125,7 @@ public void SocketShouldBeClosedAndBindShouldEndWhenOnErrorOccurredIsInvoked()
_ = _sessionMock.Setup(p => p.WaitOnHandle(It.IsAny()))
.Callback(p => p.WaitOne());
- var localPortEndPoint = new IPEndPoint(IPAddress.Loopback, 8122);
+ var localPortEndPoint = new IPEndPoint(IPAddress.Loopback, 0);
using (var localPortListener = new AsyncSocketListener(localPortEndPoint))
{
localPortListener.Start();
@@ -152,6 +153,7 @@ public void SocketShouldBeClosedAndBindShouldEndWhenOnErrorOccurredIsInvoked()
signalSessionErrorOccurredThread.Join();
};
+ localPortEndPoint.Port = ((IPEndPoint)localPortListener.ListenerEndPoint).Port;
var client = new Socket(localPortEndPoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
client.Connect(localPortEndPoint);
@@ -223,25 +225,26 @@ public void SocketShouldBeClosedAndEofShouldBeSentToServerWhenClientShutsDownSoc
Socket handler = null;
ChannelDirectTcpip channel = null;
- var localPortEndPoint = new IPEndPoint(IPAddress.Loopback, 8122);
+ var localPortEndPoint = new IPEndPoint(IPAddress.Loopback, 0);
using (var localPortListener = new AsyncSocketListener(localPortEndPoint))
{
localPortListener.Start();
localPortListener.Connected += socket =>
- {
- channel = new ChannelDirectTcpip(_sessionMock.Object,
- _localChannelNumber,
- _localWindowSize,
- _localPacketSize);
- channel.Open(_remoteHost, _port, _forwardedPortMock.Object, socket);
- channel.Bind();
- channel.Dispose();
+ {
+ channel = new ChannelDirectTcpip(_sessionMock.Object,
+ _localChannelNumber,
+ _localWindowSize,
+ _localPacketSize);
+ channel.Open(_remoteHost, _port, _forwardedPortMock.Object, socket);
+ channel.Bind();
+ channel.Dispose();
- handler = socket;
+ handler = socket;
- _ = channelBindFinishedWaitHandle.Set();
- };
+ _ = channelBindFinishedWaitHandle.Set();
+ };
+ localPortEndPoint.Port = ((IPEndPoint)localPortListener.ListenerEndPoint).Port;
var client = new Socket(localPortEndPoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
client.Connect(localPortEndPoint);
diff --git a/test/Renci.SshNet.Tests/Classes/Channels/ChannelDirectTcpipTest_Dispose_SessionIsConnectedAndChannelIsOpen.cs b/test/Renci.SshNet.Tests/Classes/Channels/ChannelDirectTcpipTest_Dispose_SessionIsConnectedAndChannelIsOpen.cs
index ae7abed92..3de4b9566 100644
--- a/test/Renci.SshNet.Tests/Classes/Channels/ChannelDirectTcpipTest_Dispose_SessionIsConnectedAndChannelIsOpen.cs
+++ b/test/Renci.SshNet.Tests/Classes/Channels/ChannelDirectTcpipTest_Dispose_SessionIsConnectedAndChannelIsOpen.cs
@@ -18,7 +18,7 @@ namespace Renci.SshNet.Tests.Classes.Channels
public class ChannelDirectTcpipTest_Dispose_SessionIsConnectedAndChannelIsOpen
{
private Mock _sessionMock;
- private Mock _connectionInfoMock;
+ private Mock _connectionInfoMock;
private Mock _forwardedPortMock;
private ChannelDirectTcpip _channel;
private uint _localChannelNumber;
@@ -78,7 +78,7 @@ private void Arrange()
_remotePacketSize = (uint)random.Next(100, 200);
_sessionMock = new Mock(MockBehavior.Strict);
- _connectionInfoMock = new Mock(MockBehavior.Strict);
+ _connectionInfoMock = new Mock(MockBehavior.Strict);
_forwardedPortMock = new Mock(MockBehavior.Strict);
var sequence = new MockSequence();
@@ -132,7 +132,7 @@ private void Arrange()
using var barrier = new Barrier(2);
- var localEndpoint = new IPEndPoint(IPAddress.Loopback, 8122);
+ var localEndpoint = new IPEndPoint(IPAddress.Loopback, 0);
_listener = new AsyncSocketListener(localEndpoint);
_listener.Connected += socket =>
{
@@ -162,6 +162,7 @@ private void Arrange()
}
};
_listener.Start();
+ localEndpoint.Port = ((IPEndPoint)_listener.ListenerEndPoint).Port;
_client = new Socket(localEndpoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
_client.Connect(localEndpoint);
diff --git a/test/Renci.SshNet.Tests/Classes/Channels/ChannelForwardedTcpipTest_Dispose_SessionIsConnectedAndChannelIsOpen.cs b/test/Renci.SshNet.Tests/Classes/Channels/ChannelForwardedTcpipTest_Dispose_SessionIsConnectedAndChannelIsOpen.cs
index 8eab76554..c64bb8eb5 100644
--- a/test/Renci.SshNet.Tests/Classes/Channels/ChannelForwardedTcpipTest_Dispose_SessionIsConnectedAndChannelIsOpen.cs
+++ b/test/Renci.SshNet.Tests/Classes/Channels/ChannelForwardedTcpipTest_Dispose_SessionIsConnectedAndChannelIsOpen.cs
@@ -19,7 +19,7 @@ public class ChannelForwardedTcpipTest_Dispose_SessionIsConnectedAndChannelIsOpe
{
private Mock _sessionMock;
private Mock _forwardedPortMock;
- private Mock _connectionInfoMock;
+ private Mock _connectionInfoMock;
private ChannelForwardedTcpip _channel;
private uint _localChannelNumber;
private uint _localWindowSize;
@@ -80,10 +80,17 @@ private void Arrange()
_disconnectedRegister = new List();
_connectionInfoTimeout = TimeSpan.FromSeconds(5);
- _remoteEndpoint = new IPEndPoint(IPAddress.Loopback, 8122);
+ _remoteEndpoint = new IPEndPoint(IPAddress.Loopback, 0);
+
+ _remoteListener = new AsyncSocketListener(_remoteEndpoint);
+ _remoteListener.Connected += _connectedRegister.Add;
+ _remoteListener.Disconnected += _disconnectedRegister.Add;
+ _remoteListener.Start();
+
+ _remoteEndpoint.Port = ((IPEndPoint)_remoteListener.ListenerEndPoint).Port;
_sessionMock = new Mock(MockBehavior.Strict);
- _connectionInfoMock = new Mock(MockBehavior.Strict);
+ _connectionInfoMock = new Mock(MockBehavior.Strict);
_forwardedPortMock = new Mock(MockBehavior.Strict);
var sequence = new MockSequence();
@@ -132,11 +139,6 @@ private void Arrange()
})
.Returns(WaitResult.Success);
- _remoteListener = new AsyncSocketListener(_remoteEndpoint);
- _remoteListener.Connected += _connectedRegister.Add;
- _remoteListener.Disconnected += _disconnectedRegister.Add;
- _remoteListener.Start();
-
_channel = new ChannelForwardedTcpip(_sessionMock.Object,
_localChannelNumber,
_localWindowSize,
diff --git a/test/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTestBase.cs b/test/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTestBase.cs
index 302f5d39f..f9a4b1632 100644
--- a/test/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTestBase.cs
+++ b/test/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTestBase.cs
@@ -7,7 +7,7 @@ namespace Renci.SshNet.Tests.Classes.Channels
public abstract class ChannelSessionTestBase
{
internal Mock SessionMock { get; private set; }
- internal Mock ConnectionInfoMock { get; private set; }
+ internal Mock ConnectionInfoMock { get; private set; }
[TestInitialize]
public void Initialize()
@@ -21,7 +21,7 @@ public void Initialize()
protected void CreateMocks()
{
SessionMock = new Mock(MockBehavior.Strict);
- ConnectionInfoMock = new Mock(MockBehavior.Strict);
+ ConnectionInfoMock = new Mock(MockBehavior.Strict);
}
protected abstract void SetupMocks();
diff --git a/test/Renci.SshNet.Tests/Classes/Channels/ChannelTestBase.cs b/test/Renci.SshNet.Tests/Classes/Channels/ChannelTestBase.cs
index e8f1aba2b..bca3043a5 100644
--- a/test/Renci.SshNet.Tests/Classes/Channels/ChannelTestBase.cs
+++ b/test/Renci.SshNet.Tests/Classes/Channels/ChannelTestBase.cs
@@ -7,7 +7,7 @@ namespace Renci.SshNet.Tests.Classes.Channels
public abstract class ChannelTestBase
{
internal Mock SessionMock { get; private set; }
- internal Mock ConnectionInfoMock { get; private set; }
+ internal Mock ConnectionInfoMock { get; private set; }
[TestInitialize]
public void Initialize()
@@ -21,7 +21,7 @@ public void Initialize()
protected void CreateMocks()
{
SessionMock = new Mock(MockBehavior.Strict);
- ConnectionInfoMock = new Mock(MockBehavior.Strict);
+ ConnectionInfoMock = new Mock(MockBehavior.Strict);
}
protected abstract void SetupMocks();
diff --git a/test/Renci.SshNet.Tests/Classes/Connection/DirectConnectorTestBase.cs b/test/Renci.SshNet.Tests/Classes/Connection/DirectConnectorTestBase.cs
index 7eb9040e9..de209299c 100644
--- a/test/Renci.SshNet.Tests/Classes/Connection/DirectConnectorTestBase.cs
+++ b/test/Renci.SshNet.Tests/Classes/Connection/DirectConnectorTestBase.cs
@@ -7,18 +7,20 @@ namespace Renci.SshNet.Tests.Classes.Connection
{
public abstract class DirectConnectorTestBase : TripleATestBase
{
+ internal Mock ServiceFactoryMock { get; private set; }
internal Mock SocketFactoryMock { get; private set; }
internal DirectConnector Connector { get; private set; }
internal SocketFactory SocketFactory { get; private set; }
protected virtual void CreateMocks()
{
+ ServiceFactoryMock = new Mock(MockBehavior.Strict);
SocketFactoryMock = new Mock(MockBehavior.Strict);
}
protected virtual void SetupData()
{
- Connector = new DirectConnector(SocketFactoryMock.Object);
+ Connector = new DirectConnector(ServiceFactoryMock.Object, SocketFactoryMock.Object);
SocketFactory = new SocketFactory();
}
@@ -33,10 +35,10 @@ protected sealed override void Arrange()
SetupMocks();
}
- protected ConnectionInfo CreateConnectionInfo(string hostName)
+ protected ConnectionInfo CreateConnectionInfo(string hostName, int port)
{
return new ConnectionInfo(hostName,
- 1027,
+ port,
"user",
new KeyboardInteractiveAuthenticationMethod("user"));
}
diff --git a/test/Renci.SshNet.Tests/Classes/Connection/DirectConnectorTest_Connect_ConnectionRefusedByServer.cs b/test/Renci.SshNet.Tests/Classes/Connection/DirectConnectorTest_Connect_ConnectionRefusedByServer.cs
index 3037134c3..d883d1382 100644
--- a/test/Renci.SshNet.Tests/Classes/Connection/DirectConnectorTest_Connect_ConnectionRefusedByServer.cs
+++ b/test/Renci.SshNet.Tests/Classes/Connection/DirectConnectorTest_Connect_ConnectionRefusedByServer.cs
@@ -21,7 +21,7 @@ protected override void SetupData()
{
base.SetupData();
- _connectionInfo = CreateConnectionInfo(IPAddress.Loopback.ToString());
+ _connectionInfo = CreateConnectionInfo(IPAddress.Loopback.ToString(), 777);
_connectionInfo.Timeout = TimeSpan.FromMilliseconds(5000);
_stopWatch = new Stopwatch();
_actualException = null;
diff --git a/test/Renci.SshNet.Tests/Classes/Connection/DirectConnectorTest_Connect_ConnectionSucceeded.cs b/test/Renci.SshNet.Tests/Classes/Connection/DirectConnectorTest_Connect_ConnectionSucceeded.cs
index 17d984262..32fdb6f30 100644
--- a/test/Renci.SshNet.Tests/Classes/Connection/DirectConnectorTest_Connect_ConnectionSucceeded.cs
+++ b/test/Renci.SshNet.Tests/Classes/Connection/DirectConnectorTest_Connect_ConnectionSucceeded.cs
@@ -27,17 +27,17 @@ protected override void SetupData()
var random = new Random();
- _connectionInfo = CreateConnectionInfo(IPAddress.Loopback.ToString());
+ _server = new AsyncSocketListener(new IPEndPoint(IPAddress.Loopback, 0));
+ _server.Disconnected += (socket) => _disconnected = true;
+ _server.Connected += (socket) => socket.Send(new byte[1] { 0x44 });
+ _server.Start();
+
+ _connectionInfo = CreateConnectionInfo(IPAddress.Loopback.ToString(), ((IPEndPoint)_server.ListenerEndPoint).Port);
_connectionInfo.Timeout = TimeSpan.FromMilliseconds(random.Next(50, 200));
_stopWatch = new Stopwatch();
_disconnected = false;
_clientSocket = SocketFactory.Create(SocketType.Stream, ProtocolType.Tcp);
-
- _server = new AsyncSocketListener(new IPEndPoint(IPAddress.Loopback, _connectionInfo.Port));
- _server.Disconnected += (socket) => _disconnected = true;
- _server.Connected += (socket) => socket.Send(new byte[1] { 0x44 });
- _server.Start();
}
protected override void SetupMocks()
diff --git a/test/Renci.SshNet.Tests/Classes/Connection/DirectConnectorTest_Connect_HostNameInvalid.cs b/test/Renci.SshNet.Tests/Classes/Connection/DirectConnectorTest_Connect_HostNameInvalid.cs
index 0a29d70d7..3c2158f4c 100644
--- a/test/Renci.SshNet.Tests/Classes/Connection/DirectConnectorTest_Connect_HostNameInvalid.cs
+++ b/test/Renci.SshNet.Tests/Classes/Connection/DirectConnectorTest_Connect_HostNameInvalid.cs
@@ -15,7 +15,7 @@ protected override void SetupData()
{
base.SetupData();
- _connectionInfo = CreateConnectionInfo("invalid.");
+ _connectionInfo = CreateConnectionInfo("invalid.", 777);
_actualException = null;
_clientSocket = SocketFactory.Create(SocketType.Stream, ProtocolType.Tcp);
}
diff --git a/test/Renci.SshNet.Tests/Classes/Connection/DirectConnectorTest_Connect_TimeoutConnectingToServer.cs b/test/Renci.SshNet.Tests/Classes/Connection/DirectConnectorTest_Connect_TimeoutConnectingToServer.cs
index 82623bc3e..9f24926e6 100644
--- a/test/Renci.SshNet.Tests/Classes/Connection/DirectConnectorTest_Connect_TimeoutConnectingToServer.cs
+++ b/test/Renci.SshNet.Tests/Classes/Connection/DirectConnectorTest_Connect_TimeoutConnectingToServer.cs
@@ -28,7 +28,7 @@ protected override void SetupData()
var random = new Random();
- _connectionInfo = CreateConnectionInfo(IPAddress.Loopback.ToString());
+ _connectionInfo = CreateConnectionInfo(IPAddress.Loopback.ToString(), 777);
_connectionInfo.Timeout = TimeSpan.FromMilliseconds(random.Next(50, 200));
_stopWatch = new Stopwatch();
_actualException = null;
diff --git a/test/Renci.SshNet.Tests/Classes/Connection/HttpConnectorTestBase.cs b/test/Renci.SshNet.Tests/Classes/Connection/HttpConnectorTestBase.cs
index 7023901fa..ecc17f255 100644
--- a/test/Renci.SshNet.Tests/Classes/Connection/HttpConnectorTestBase.cs
+++ b/test/Renci.SshNet.Tests/Classes/Connection/HttpConnectorTestBase.cs
@@ -7,18 +7,22 @@ namespace Renci.SshNet.Tests.Classes.Connection
{
public abstract class HttpConnectorTestBase : TripleATestBase
{
+ internal Mock ServiceFactoryMock { get; private set; }
internal Mock SocketFactoryMock { get; private set; }
internal HttpConnector Connector { get; private set; }
internal SocketFactory SocketFactory { get; private set; }
+ internal ServiceFactory ServiceFactory { get; private set; }
protected virtual void CreateMocks()
{
+ ServiceFactoryMock = new Mock(MockBehavior.Strict);
SocketFactoryMock = new Mock(MockBehavior.Strict);
}
protected virtual void SetupData()
{
- Connector = new HttpConnector(SocketFactoryMock.Object);
+ Connector = new HttpConnector(ServiceFactoryMock.Object, SocketFactoryMock.Object);
+ ServiceFactory = new ServiceFactory();
SocketFactory = new SocketFactory();
}
diff --git a/test/Renci.SshNet.Tests/Classes/Connection/HttpConnectorTest_Connect_ConnectionToProxyRefused.cs b/test/Renci.SshNet.Tests/Classes/Connection/HttpConnectorTest_Connect_ConnectionToProxyRefused.cs
index fd7d9c72a..b5cea521b 100644
--- a/test/Renci.SshNet.Tests/Classes/Connection/HttpConnectorTest_Connect_ConnectionToProxyRefused.cs
+++ b/test/Renci.SshNet.Tests/Classes/Connection/HttpConnectorTest_Connect_ConnectionToProxyRefused.cs
@@ -7,14 +7,18 @@
using Moq;
+using Renci.SshNet.Connection;
+
namespace Renci.SshNet.Tests.Classes.Connection
{
[TestClass]
public class HttpConnectorTest_Connect_ConnectionToProxyRefused : HttpConnectorTestBase
{
private ConnectionInfo _connectionInfo;
+ private ProxyConnectionInfo _proxyConnectionInfo;
private SocketException _actualException;
private Socket _clientSocket;
+ private IConnector _proxyConnector;
private Stopwatch _stopWatch;
protected override void SetupData()
@@ -26,23 +30,27 @@ protected override void SetupData()
"user",
ProxyTypes.Http,
IPAddress.Loopback.ToString(),
- 8122,
+ 8121,
"proxyUser",
"proxyPwd",
new KeyboardInteractiveAuthenticationMethod("user"))
{
Timeout = TimeSpan.FromMilliseconds(5000)
};
+ _proxyConnectionInfo = (ProxyConnectionInfo)_connectionInfo.ProxyConnection;
_stopWatch = new Stopwatch();
_actualException = null;
_clientSocket = SocketFactory.Create(SocketType.Stream, ProtocolType.Tcp);
+ _proxyConnector = ServiceFactory.CreateConnector(_proxyConnectionInfo, SocketFactoryMock.Object);
}
protected override void SetupMocks()
{
_ = SocketFactoryMock.Setup(p => p.Create(SocketType.Stream, ProtocolType.Tcp))
- .Returns(_clientSocket);
+ .Returns(_clientSocket);
+ _ = ServiceFactoryMock.Setup(p => p.CreateConnector(_proxyConnectionInfo, SocketFactoryMock.Object))
+ .Returns(_proxyConnector);
}
protected override void TearDown()
@@ -50,6 +58,7 @@ protected override void TearDown()
base.TearDown();
_clientSocket?.Dispose();
+ _proxyConnector?.Dispose();
}
protected override void Act()
diff --git a/test/Renci.SshNet.Tests/Classes/Connection/HttpConnectorTest_Connect_ProxyClosesConnectionBeforeStatusLineIsSent.cs b/test/Renci.SshNet.Tests/Classes/Connection/HttpConnectorTest_Connect_ProxyClosesConnectionBeforeStatusLineIsSent.cs
index 583afa14d..1af13e38a 100644
--- a/test/Renci.SshNet.Tests/Classes/Connection/HttpConnectorTest_Connect_ProxyClosesConnectionBeforeStatusLineIsSent.cs
+++ b/test/Renci.SshNet.Tests/Classes/Connection/HttpConnectorTest_Connect_ProxyClosesConnectionBeforeStatusLineIsSent.cs
@@ -7,6 +7,7 @@
using Moq;
+using Renci.SshNet.Connection;
using Renci.SshNet.Common;
using Renci.SshNet.Tests.Common;
@@ -16,44 +17,50 @@ namespace Renci.SshNet.Tests.Classes.Connection
public class HttpConnectorTest_Connect_ProxyClosesConnectionBeforeStatusLineIsSent : HttpConnectorTestBase
{
private ConnectionInfo _connectionInfo;
+ private ProxyConnectionInfo _proxyConnectionInfo;
private AsyncSocketListener _proxyServer;
private Socket _clientSocket;
+ private IConnector _proxyConnector;
private bool _disconnected;
private ProxyException _actualException;
protected override void SetupData()
{
base.SetupData();
+ _proxyServer = new AsyncSocketListener(new IPEndPoint(IPAddress.Loopback, 0));
+ _proxyServer.Disconnected += socket => _disconnected = true;
+ _proxyServer.BytesReceived += (bytesReceived, socket) =>
+ {
+ socket.Shutdown(SocketShutdown.Send);
+ };
+ _proxyServer.Start();
_connectionInfo = new ConnectionInfo(IPAddress.Loopback.ToString(),
777,
"user",
ProxyTypes.Http,
IPAddress.Loopback.ToString(),
- 8122,
+ ((IPEndPoint)_proxyServer.ListenerEndPoint).Port,
"proxyUser",
"proxyPwd",
new KeyboardInteractiveAuthenticationMethod("user"))
{
Timeout = TimeSpan.FromMilliseconds(100)
};
+
+ _proxyConnectionInfo = (ProxyConnectionInfo)_connectionInfo.ProxyConnection;
_actualException = null;
_clientSocket = SocketFactory.Create(SocketType.Stream, ProtocolType.Tcp);
-
- _proxyServer = new AsyncSocketListener(new IPEndPoint(IPAddress.Loopback, _connectionInfo.ProxyPort));
- _proxyServer.Disconnected += socket => _disconnected = true;
- _proxyServer.BytesReceived += (bytesReceived, socket) =>
- {
- socket.Shutdown(SocketShutdown.Send);
- };
- _proxyServer.Start();
+ _proxyConnector = ServiceFactory.CreateConnector(_proxyConnectionInfo, SocketFactoryMock.Object);
}
protected override void SetupMocks()
{
_ = SocketFactoryMock.Setup(p => p.Create(SocketType.Stream, ProtocolType.Tcp))
- .Returns(_clientSocket);
+ .Returns(_clientSocket);
+ _ = ServiceFactoryMock.Setup(p => p.CreateConnector(_proxyConnectionInfo, SocketFactoryMock.Object))
+ .Returns(_proxyConnector);
}
protected override void TearDown()
@@ -62,6 +69,7 @@ protected override void TearDown()
_proxyServer?.Dispose();
_clientSocket?.Dispose();
+ _proxyConnector?.Dispose();
}
protected override void Act()
diff --git a/test/Renci.SshNet.Tests/Classes/Connection/HttpConnectorTest_Connect_ProxyHostInvalid.cs b/test/Renci.SshNet.Tests/Classes/Connection/HttpConnectorTest_Connect_ProxyHostInvalid.cs
index bf9d37d41..19501cb41 100644
--- a/test/Renci.SshNet.Tests/Classes/Connection/HttpConnectorTest_Connect_ProxyHostInvalid.cs
+++ b/test/Renci.SshNet.Tests/Classes/Connection/HttpConnectorTest_Connect_ProxyHostInvalid.cs
@@ -2,12 +2,16 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
+using Renci.SshNet.Connection;
+
namespace Renci.SshNet.Tests.Classes.Connection
{
[TestClass]
public class HttpConnectorTest_Connect_ProxyHostInvalid : HttpConnectorTestBase
{
private ConnectionInfo _connectionInfo;
+ private ProxyConnectionInfo _proxyConnectionInfo;
+ private IConnector _proxyConnector;
private SocketException _actualException;
private Socket _clientSocket;
@@ -24,6 +28,8 @@ protected override void SetupData()
"proxyUser",
"proxyPwd",
new KeyboardInteractiveAuthenticationMethod("user"));
+ _proxyConnectionInfo = (ProxyConnectionInfo)_connectionInfo.ProxyConnection;
+ _proxyConnector = ServiceFactory.CreateConnector(_proxyConnectionInfo, SocketFactoryMock.Object);
_actualException = null;
_clientSocket = SocketFactory.Create(SocketType.Stream, ProtocolType.Tcp);
}
@@ -32,6 +38,15 @@ protected override void SetupMocks()
{
_ = SocketFactoryMock.Setup(p => p.Create(SocketType.Stream, ProtocolType.Tcp))
.Returns(_clientSocket);
+ _ = ServiceFactoryMock.Setup(p => p.CreateConnector(_proxyConnectionInfo, SocketFactoryMock.Object))
+ .Returns(_proxyConnector);
+ }
+
+ protected override void TearDown()
+ {
+ base.TearDown();
+
+ _proxyConnector?.Dispose();
}
protected override void Act()
diff --git a/test/Renci.SshNet.Tests/Classes/Connection/HttpConnectorTest_Connect_ProxyPasswordIsEmpty.cs b/test/Renci.SshNet.Tests/Classes/Connection/HttpConnectorTest_Connect_ProxyPasswordIsEmpty.cs
index 57ed498b9..76d5e46ed 100644
--- a/test/Renci.SshNet.Tests/Classes/Connection/HttpConnectorTest_Connect_ProxyPasswordIsEmpty.cs
+++ b/test/Renci.SshNet.Tests/Classes/Connection/HttpConnectorTest_Connect_ProxyPasswordIsEmpty.cs
@@ -10,6 +10,7 @@
using Moq;
+using Renci.SshNet.Connection;
using Renci.SshNet.Tests.Common;
namespace Renci.SshNet.Tests.Classes.Connection
@@ -18,9 +19,11 @@ namespace Renci.SshNet.Tests.Classes.Connection
public class HttpConnectorTest_Connect_ProxyPasswordIsEmpty : HttpConnectorTestBase
{
private ConnectionInfo _connectionInfo;
+ private ProxyConnectionInfo _proxyConnectionInfo;
private AsyncSocketListener _proxyServer;
private bool _disconnected;
private Socket _clientSocket;
+ private IConnector _proxyConnector;
private List _bytesReceivedByProxy;
private string _expectedHttpRequest;
private Socket _actual;
@@ -29,18 +32,38 @@ protected override void SetupData()
{
base.SetupData();
+ _proxyServer = new AsyncSocketListener(new IPEndPoint(IPAddress.Loopback, 0));
+ _proxyServer.Disconnected += (socket) => _disconnected = true;
+ _proxyServer.Connected += socket =>
+ {
+ _ = socket.Send(Encoding.ASCII.GetBytes("\r\n"));
+ _ = socket.Send(Encoding.ASCII.GetBytes("SSH.NET\r\n"));
+ _ = socket.Send(Encoding.ASCII.GetBytes("HTTP/1.0 200 OK\r\n"));
+ _ = socket.Send(Encoding.ASCII.GetBytes("Content-Type: application/octet-stream\r\n"));
+ _ = socket.Send(Encoding.ASCII.GetBytes("\r\n"));
+ _ = socket.Send(Encoding.ASCII.GetBytes("SSH4EVER"));
+
+ socket.Shutdown(SocketShutdown.Send);
+ };
+ _proxyServer.BytesReceived += (bytesReceived, socket) =>
+ {
+ _bytesReceivedByProxy.AddRange(bytesReceived);
+ };
+ _proxyServer.Start();
+
_connectionInfo = new ConnectionInfo(IPAddress.Loopback.ToString(),
777,
"user",
ProxyTypes.Http,
IPAddress.Loopback.ToString(),
- 8122,
+ ((IPEndPoint)_proxyServer.ListenerEndPoint).Port,
"proxyUser",
string.Empty,
new KeyboardInteractiveAuthenticationMethod("user"))
{
Timeout = TimeSpan.FromMilliseconds(20)
};
+ _proxyConnectionInfo = (ProxyConnectionInfo)_connectionInfo.ProxyConnection;
_expectedHttpRequest = string.Format("CONNECT {0}:{1} HTTP/1.0{2}" +
"Proxy-Authorization: Basic cHJveHlVc2VyOg=={2}{2}",
_connectionInfo.Host,
@@ -49,31 +72,15 @@ protected override void SetupData()
_bytesReceivedByProxy = new List();
_disconnected = false;
_clientSocket = SocketFactory.Create(SocketType.Stream, ProtocolType.Tcp);
-
- _proxyServer = new AsyncSocketListener(new IPEndPoint(IPAddress.Loopback, _connectionInfo.ProxyPort));
- _proxyServer.Disconnected += (socket) => _disconnected = true;
- _proxyServer.Connected += socket =>
- {
- _ = socket.Send(Encoding.ASCII.GetBytes("\r\n"));
- _ = socket.Send(Encoding.ASCII.GetBytes("SSH.NET\r\n"));
- _ = socket.Send(Encoding.ASCII.GetBytes("HTTP/1.0 200 OK\r\n"));
- _ = socket.Send(Encoding.ASCII.GetBytes("Content-Type: application/octet-stream\r\n"));
- _ = socket.Send(Encoding.ASCII.GetBytes("\r\n"));
- _ = socket.Send(Encoding.ASCII.GetBytes("SSH4EVER"));
-
- socket.Shutdown(SocketShutdown.Send);
- };
- _proxyServer.BytesReceived += (bytesReceived, socket) =>
- {
- _bytesReceivedByProxy.AddRange(bytesReceived);
- };
- _proxyServer.Start();
+ _proxyConnector = ServiceFactory.CreateConnector(_proxyConnectionInfo, SocketFactoryMock.Object);
}
protected override void SetupMocks()
{
_ = SocketFactoryMock.Setup(p => p.Create(SocketType.Stream, ProtocolType.Tcp))
- .Returns(_clientSocket);
+ .Returns(_clientSocket);
+ _ = ServiceFactoryMock.Setup(p => p.CreateConnector(_proxyConnectionInfo, SocketFactoryMock.Object))
+ .Returns(_proxyConnector);
}
protected override void TearDown()
@@ -87,6 +94,8 @@ protected override void TearDown()
_clientSocket.Shutdown(SocketShutdown.Both);
_clientSocket.Close();
}
+
+ _proxyConnector?.Dispose();
}
protected override void Act()
diff --git a/test/Renci.SshNet.Tests/Classes/Connection/HttpConnectorTest_Connect_ProxyPasswordIsNull.cs b/test/Renci.SshNet.Tests/Classes/Connection/HttpConnectorTest_Connect_ProxyPasswordIsNull.cs
index 7fcd9da85..5e02dc6c0 100644
--- a/test/Renci.SshNet.Tests/Classes/Connection/HttpConnectorTest_Connect_ProxyPasswordIsNull.cs
+++ b/test/Renci.SshNet.Tests/Classes/Connection/HttpConnectorTest_Connect_ProxyPasswordIsNull.cs
@@ -10,6 +10,7 @@
using Moq;
+using Renci.SshNet.Connection;
using Renci.SshNet.Tests.Common;
namespace Renci.SshNet.Tests.Classes.Connection
@@ -18,9 +19,11 @@ namespace Renci.SshNet.Tests.Classes.Connection
public class HttpConnectorTest_Connect_ProxyPasswordIsNull : HttpConnectorTestBase
{
private ConnectionInfo _connectionInfo;
+ private ProxyConnectionInfo _proxyConnectionInfo;
private AsyncSocketListener _proxyServer;
private bool _disconnected;
private Socket _clientSocket;
+ private IConnector _proxyConnector;
private List _bytesReceivedByProxy;
private string _expectedHttpRequest;
private Socket _actual;
@@ -29,18 +32,38 @@ protected override void SetupData()
{
base.SetupData();
+ _proxyServer = new AsyncSocketListener(new IPEndPoint(IPAddress.Loopback, 0));
+ _proxyServer.Disconnected += (socket) => _disconnected = true;
+ _proxyServer.Connected += socket =>
+ {
+ _ = socket.Send(Encoding.ASCII.GetBytes("\r\n"));
+ _ = socket.Send(Encoding.ASCII.GetBytes("SSH.NET\r\n"));
+ _ = socket.Send(Encoding.ASCII.GetBytes("HTTP/1.0 200 OK\r\n"));
+ _ = socket.Send(Encoding.ASCII.GetBytes("Content-Type: application/octet-stream\r\n"));
+ _ = socket.Send(Encoding.ASCII.GetBytes("\r\n"));
+ _ = socket.Send(Encoding.ASCII.GetBytes("SSH4EVER"));
+
+ socket.Shutdown(SocketShutdown.Send);
+ };
+ _proxyServer.BytesReceived += (bytesReceived, socket) =>
+ {
+ _bytesReceivedByProxy.AddRange(bytesReceived);
+ };
+ _proxyServer.Start();
+
_connectionInfo = new ConnectionInfo(IPAddress.Loopback.ToString(),
777,
"user",
ProxyTypes.Http,
IPAddress.Loopback.ToString(),
- 8122,
+ ((IPEndPoint)_proxyServer.ListenerEndPoint).Port,
"proxyUser",
null,
new KeyboardInteractiveAuthenticationMethod("user"))
{
Timeout = TimeSpan.FromMilliseconds(20)
};
+ _proxyConnectionInfo = (ProxyConnectionInfo)_connectionInfo.ProxyConnection;
_expectedHttpRequest = string.Format("CONNECT {0}:{1} HTTP/1.0{2}" +
"Proxy-Authorization: Basic cHJveHlVc2VyOg=={2}{2}",
_connectionInfo.Host,
@@ -49,31 +72,15 @@ protected override void SetupData()
_bytesReceivedByProxy = new List();
_disconnected = false;
_clientSocket = SocketFactory.Create(SocketType.Stream, ProtocolType.Tcp);
-
- _proxyServer = new AsyncSocketListener(new IPEndPoint(IPAddress.Loopback, _connectionInfo.ProxyPort));
- _proxyServer.Disconnected += (socket) => _disconnected = true;
- _proxyServer.Connected += socket =>
- {
- _ = socket.Send(Encoding.ASCII.GetBytes("\r\n"));
- _ = socket.Send(Encoding.ASCII.GetBytes("SSH.NET\r\n"));
- _ = socket.Send(Encoding.ASCII.GetBytes("HTTP/1.0 200 OK\r\n"));
- _ = socket.Send(Encoding.ASCII.GetBytes("Content-Type: application/octet-stream\r\n"));
- _ = socket.Send(Encoding.ASCII.GetBytes("\r\n"));
- _ = socket.Send(Encoding.ASCII.GetBytes("SSH4EVER"));
-
- socket.Shutdown(SocketShutdown.Send);
- };
- _proxyServer.BytesReceived += (bytesReceived, socket) =>
- {
- _bytesReceivedByProxy.AddRange(bytesReceived);
- };
- _proxyServer.Start();
+ _proxyConnector = ServiceFactory.CreateConnector(_proxyConnectionInfo, SocketFactoryMock.Object);
}
protected override void SetupMocks()
{
_ = SocketFactoryMock.Setup(p => p.Create(SocketType.Stream, ProtocolType.Tcp))
- .Returns(_clientSocket);
+ .Returns(_clientSocket);
+ _ = ServiceFactoryMock.Setup(p => p.CreateConnector(_proxyConnectionInfo, SocketFactoryMock.Object))
+ .Returns(_proxyConnector);
}
protected override void TearDown()
@@ -87,6 +94,8 @@ protected override void TearDown()
_clientSocket.Shutdown(SocketShutdown.Both);
_clientSocket.Close();
}
+
+ _proxyConnector?.Dispose();
}
protected override void Act()
diff --git a/test/Renci.SshNet.Tests/Classes/Connection/HttpConnectorTest_Connect_ProxyResponseDoesNotContainHttpStatusLine.cs b/test/Renci.SshNet.Tests/Classes/Connection/HttpConnectorTest_Connect_ProxyResponseDoesNotContainHttpStatusLine.cs
index e5e9107fe..5dce19841 100644
--- a/test/Renci.SshNet.Tests/Classes/Connection/HttpConnectorTest_Connect_ProxyResponseDoesNotContainHttpStatusLine.cs
+++ b/test/Renci.SshNet.Tests/Classes/Connection/HttpConnectorTest_Connect_ProxyResponseDoesNotContainHttpStatusLine.cs
@@ -9,6 +9,7 @@
using Moq;
+using Renci.SshNet.Connection;
using Renci.SshNet.Common;
using Renci.SshNet.Tests.Common;
@@ -18,8 +19,10 @@ namespace Renci.SshNet.Tests.Classes.Connection
public class HttpConnectorTest_Connect_ProxyResponseDoesNotContainHttpStatusLine : HttpConnectorTestBase
{
private ConnectionInfo _connectionInfo;
+ private ProxyConnectionInfo _proxyConnectionInfo;
private AsyncSocketListener _proxyServer;
private Socket _clientSocket;
+ private IConnector _proxyConnector;
private List _bytesReceivedByProxy;
private bool _disconnected;
private ProxyException _actualException;
@@ -28,43 +31,47 @@ protected override void SetupData()
{
base.SetupData();
+ _proxyServer = new AsyncSocketListener(new IPEndPoint(IPAddress.Loopback, 0));
+ _proxyServer.Disconnected += socket => _disconnected = true;
+ _proxyServer.BytesReceived += (bytesReceived, socket) =>
+ {
+ if (_bytesReceivedByProxy.Count == 0)
+ {
+ _ = socket.Send(Encoding.ASCII.GetBytes("Whatever\r\n"));
+
+ socket.Shutdown(SocketShutdown.Send);
+ }
+
+ _bytesReceivedByProxy.AddRange(bytesReceived);
+ };
+ _proxyServer.Start();
+
_connectionInfo = new ConnectionInfo(IPAddress.Loopback.ToString(),
777,
"user",
ProxyTypes.Http,
IPAddress.Loopback.ToString(),
- 8122,
+ ((IPEndPoint)_proxyServer.ListenerEndPoint).Port,
"proxyUser",
"proxyPwd",
new KeyboardInteractiveAuthenticationMethod("user"))
{
Timeout = TimeSpan.FromMilliseconds(100)
};
+ _proxyConnectionInfo = (ProxyConnectionInfo)_connectionInfo.ProxyConnection;
_bytesReceivedByProxy = new List();
_actualException = null;
_clientSocket = SocketFactory.Create(SocketType.Stream, ProtocolType.Tcp);
-
- _proxyServer = new AsyncSocketListener(new IPEndPoint(IPAddress.Loopback, _connectionInfo.ProxyPort));
- _proxyServer.Disconnected += socket => _disconnected = true;
- _proxyServer.BytesReceived += (bytesReceived, socket) =>
- {
- if (_bytesReceivedByProxy.Count == 0)
- {
- _ = socket.Send(Encoding.ASCII.GetBytes("Whatever\r\n"));
-
- socket.Shutdown(SocketShutdown.Send);
- }
-
- _bytesReceivedByProxy.AddRange(bytesReceived);
- };
- _proxyServer.Start();
+ _proxyConnector = ServiceFactory.CreateConnector(_proxyConnectionInfo, SocketFactoryMock.Object);
}
protected override void SetupMocks()
{
_ = SocketFactoryMock.Setup(p => p.Create(SocketType.Stream, ProtocolType.Tcp))
- .Returns(_clientSocket);
+ .Returns(_clientSocket);
+ _ = ServiceFactoryMock.Setup(p => p.CreateConnector(_proxyConnectionInfo, SocketFactoryMock.Object))
+ .Returns(_proxyConnector);
}
protected override void TearDown()
@@ -72,6 +79,7 @@ protected override void TearDown()
base.TearDown();
_proxyServer?.Dispose();
+ _proxyConnector?.Dispose();
}
protected override void Act()
diff --git a/test/Renci.SshNet.Tests/Classes/Connection/HttpConnectorTest_Connect_ProxyResponseStatusIs200_ExtraTextBeforeStatusLine.cs b/test/Renci.SshNet.Tests/Classes/Connection/HttpConnectorTest_Connect_ProxyResponseStatusIs200_ExtraTextBeforeStatusLine.cs
index 829263340..ad231bcc2 100644
--- a/test/Renci.SshNet.Tests/Classes/Connection/HttpConnectorTest_Connect_ProxyResponseStatusIs200_ExtraTextBeforeStatusLine.cs
+++ b/test/Renci.SshNet.Tests/Classes/Connection/HttpConnectorTest_Connect_ProxyResponseStatusIs200_ExtraTextBeforeStatusLine.cs
@@ -10,6 +10,7 @@
using Moq;
+using Renci.SshNet.Connection;
using Renci.SshNet.Tests.Common;
namespace Renci.SshNet.Tests.Classes.Connection
@@ -18,9 +19,11 @@ namespace Renci.SshNet.Tests.Classes.Connection
public class HttpConnectorTest_Connect_ProxyResponseStatusIs200_ExtraTextBeforeStatusLine : HttpConnectorTestBase
{
private ConnectionInfo _connectionInfo;
+ private ProxyConnectionInfo _proxyConnectionInfo;
private AsyncSocketListener _proxyServer;
private bool _disconnected;
private Socket _clientSocket;
+ private IConnector _proxyConnector;
private List _bytesReceivedByProxy;
private string _expectedHttpRequest;
private Socket _actual;
@@ -29,28 +32,7 @@ protected override void SetupData()
{
base.SetupData();
- _connectionInfo = new ConnectionInfo(IPAddress.Loopback.ToString(),
- 777,
- "user",
- ProxyTypes.Http,
- IPAddress.Loopback.ToString(),
- 8122,
- "proxyUser",
- "proxyPwd",
- new KeyboardInteractiveAuthenticationMethod("user"))
- {
- Timeout = TimeSpan.FromMilliseconds(20)
- };
- _expectedHttpRequest = string.Format("CONNECT {0}:{1} HTTP/1.0{2}" +
- "Proxy-Authorization: Basic cHJveHlVc2VyOnByb3h5UHdk{2}{2}",
- _connectionInfo.Host,
- _connectionInfo.Port.ToString(CultureInfo.InvariantCulture),
- "\r\n");
- _bytesReceivedByProxy = new List();
- _disconnected = false;
- _clientSocket = SocketFactory.Create(SocketType.Stream, ProtocolType.Tcp);
-
- _proxyServer = new AsyncSocketListener(new IPEndPoint(IPAddress.Loopback, _connectionInfo.ProxyPort));
+ _proxyServer = new AsyncSocketListener(new IPEndPoint(IPAddress.Loopback, 0));
_proxyServer.Disconnected += (socket) => _disconnected = true;
_proxyServer.BytesReceived += (bytesReceived, socket) =>
{
@@ -72,12 +54,37 @@ protected override void SetupData()
}
};
_proxyServer.Start();
+
+ _connectionInfo = new ConnectionInfo(IPAddress.Loopback.ToString(),
+ 777,
+ "user",
+ ProxyTypes.Http,
+ IPAddress.Loopback.ToString(),
+ ((IPEndPoint)_proxyServer.ListenerEndPoint).Port,
+ "proxyUser",
+ "proxyPwd",
+ new KeyboardInteractiveAuthenticationMethod("user"))
+ {
+ Timeout = TimeSpan.FromMilliseconds(20)
+ };
+ _proxyConnectionInfo = (ProxyConnectionInfo)_connectionInfo.ProxyConnection;
+ _expectedHttpRequest = string.Format("CONNECT {0}:{1} HTTP/1.0{2}" +
+ "Proxy-Authorization: Basic cHJveHlVc2VyOnByb3h5UHdk{2}{2}",
+ _connectionInfo.Host,
+ _connectionInfo.Port.ToString(CultureInfo.InvariantCulture),
+ "\r\n");
+ _bytesReceivedByProxy = new List();
+ _disconnected = false;
+ _clientSocket = SocketFactory.Create(SocketType.Stream, ProtocolType.Tcp);
+ _proxyConnector = ServiceFactory.CreateConnector(_proxyConnectionInfo, SocketFactoryMock.Object);
}
protected override void SetupMocks()
{
_ = SocketFactoryMock.Setup(p => p.Create(SocketType.Stream, ProtocolType.Tcp))
- .Returns(_clientSocket);
+ .Returns(_clientSocket);
+ _ = ServiceFactoryMock.Setup(p => p.CreateConnector(_proxyConnectionInfo, SocketFactoryMock.Object))
+ .Returns(_proxyConnector);
}
protected override void TearDown()
@@ -91,6 +98,8 @@ protected override void TearDown()
_clientSocket.Shutdown(SocketShutdown.Both);
_clientSocket.Close();
}
+
+ _proxyConnector?.Dispose();
}
protected override void Act()
diff --git a/test/Renci.SshNet.Tests/Classes/Connection/HttpConnectorTest_Connect_ProxyResponseStatusIs200_HeadersAndContent.cs b/test/Renci.SshNet.Tests/Classes/Connection/HttpConnectorTest_Connect_ProxyResponseStatusIs200_HeadersAndContent.cs
index 48c86128e..6796c3cba 100644
--- a/test/Renci.SshNet.Tests/Classes/Connection/HttpConnectorTest_Connect_ProxyResponseStatusIs200_HeadersAndContent.cs
+++ b/test/Renci.SshNet.Tests/Classes/Connection/HttpConnectorTest_Connect_ProxyResponseStatusIs200_HeadersAndContent.cs
@@ -10,6 +10,7 @@
using Moq;
+using Renci.SshNet.Connection;
using Renci.SshNet.Tests.Common;
namespace Renci.SshNet.Tests.Classes.Connection
@@ -18,9 +19,11 @@ namespace Renci.SshNet.Tests.Classes.Connection
public class HttpConnectorTest_Connect_ProxyResponseStatusIs200_HeadersAndContent : HttpConnectorTestBase
{
private ConnectionInfo _connectionInfo;
+ private ProxyConnectionInfo _proxyConnectionInfo;
private AsyncSocketListener _proxyServer;
private bool _disconnected;
private Socket _clientSocket;
+ private IConnector _proxyConnector;
private List _bytesReceivedByProxy;
private string _expectedHttpRequest;
private Socket _actual;
@@ -29,18 +32,42 @@ protected override void SetupData()
{
base.SetupData();
+ _proxyServer = new AsyncSocketListener(new IPEndPoint(IPAddress.Loopback, 0));
+ _proxyServer.Disconnected += (socket) => _disconnected = true;
+ _proxyServer.BytesReceived += (bytesReceived, socket) =>
+ {
+ _bytesReceivedByProxy.AddRange(bytesReceived);
+
+ // Only send response back after we've received the complete CONNECT request
+ // as we want to make sure HttpConnector is not waiting for any data before
+ // it sends the CONNECT request
+ if (_bytesReceivedByProxy.Count == _expectedHttpRequest.Length)
+ {
+ _ = socket.Send(Encoding.ASCII.GetBytes("HTTP/1.0 200 OK\r\n"));
+ _ = socket.Send(Encoding.ASCII.GetBytes("Content-Length: 10\r\n"));
+ _ = socket.Send(Encoding.ASCII.GetBytes("Content-Type: application/octet-stream\r\n"));
+ _ = socket.Send(Encoding.ASCII.GetBytes("\r\n"));
+ _ = socket.Send(Encoding.ASCII.GetBytes("TEEN_BYTES"));
+ _ = socket.Send(Encoding.ASCII.GetBytes("!666!"));
+
+ socket.Shutdown(SocketShutdown.Send);
+ }
+ };
+ _proxyServer.Start();
+
_connectionInfo = new ConnectionInfo(IPAddress.Loopback.ToString(),
777,
"user",
ProxyTypes.Http,
IPAddress.Loopback.ToString(),
- 8122,
+ ((IPEndPoint)_proxyServer.ListenerEndPoint).Port,
"proxyUser",
"proxyPwd",
new KeyboardInteractiveAuthenticationMethod("user"))
{
Timeout = TimeSpan.FromMilliseconds(20)
};
+ _proxyConnectionInfo = (ProxyConnectionInfo)_connectionInfo.ProxyConnection;
_expectedHttpRequest = string.Format("CONNECT {0}:{1} HTTP/1.0{2}" +
"Proxy-Authorization: Basic cHJveHlVc2VyOnByb3h5UHdk{2}{2}",
_connectionInfo.Host,
@@ -49,35 +76,15 @@ protected override void SetupData()
_bytesReceivedByProxy = new List();
_disconnected = false;
_clientSocket = SocketFactory.Create(SocketType.Stream, ProtocolType.Tcp);
-
- _proxyServer = new AsyncSocketListener(new IPEndPoint(IPAddress.Loopback, _connectionInfo.ProxyPort));
- _proxyServer.Disconnected += (socket) => _disconnected = true;
- _proxyServer.BytesReceived += (bytesReceived, socket) =>
- {
- _bytesReceivedByProxy.AddRange(bytesReceived);
-
- // Only send response back after we've received the complete CONNECT request
- // as we want to make sure HttpConnector is not waiting for any data before
- // it sends the CONNECT request
- if (_bytesReceivedByProxy.Count == _expectedHttpRequest.Length)
- {
- _ = socket.Send(Encoding.ASCII.GetBytes("HTTP/1.0 200 OK\r\n"));
- _ = socket.Send(Encoding.ASCII.GetBytes("Content-Length: 10\r\n"));
- _ = socket.Send(Encoding.ASCII.GetBytes("Content-Type: application/octet-stream\r\n"));
- _ = socket.Send(Encoding.ASCII.GetBytes("\r\n"));
- _ = socket.Send(Encoding.ASCII.GetBytes("TEEN_BYTES"));
- _ = socket.Send(Encoding.ASCII.GetBytes("!666!"));
-
- socket.Shutdown(SocketShutdown.Send);
- }
- };
- _proxyServer.Start();
+ _proxyConnector = ServiceFactory.CreateConnector(_proxyConnectionInfo, SocketFactoryMock.Object);
}
protected override void SetupMocks()
{
_ = SocketFactoryMock.Setup(p => p.Create(SocketType.Stream, ProtocolType.Tcp))
- .Returns(_clientSocket);
+ .Returns(_clientSocket);
+ _ = ServiceFactoryMock.Setup(p => p.CreateConnector(_proxyConnectionInfo, SocketFactoryMock.Object))
+ .Returns(_proxyConnector);
}
protected override void TearDown()
@@ -91,6 +98,8 @@ protected override void TearDown()
_clientSocket.Shutdown(SocketShutdown.Both);
_clientSocket.Close();
}
+
+ _proxyConnector?.Dispose();
}
protected override void Act()
diff --git a/test/Renci.SshNet.Tests/Classes/Connection/HttpConnectorTest_Connect_ProxyResponseStatusIs200_OnlyHeaders.cs b/test/Renci.SshNet.Tests/Classes/Connection/HttpConnectorTest_Connect_ProxyResponseStatusIs200_OnlyHeaders.cs
index 4ce401e0e..32625112a 100644
--- a/test/Renci.SshNet.Tests/Classes/Connection/HttpConnectorTest_Connect_ProxyResponseStatusIs200_OnlyHeaders.cs
+++ b/test/Renci.SshNet.Tests/Classes/Connection/HttpConnectorTest_Connect_ProxyResponseStatusIs200_OnlyHeaders.cs
@@ -10,6 +10,7 @@
using Moq;
+using Renci.SshNet.Connection;
using Renci.SshNet.Tests.Common;
namespace Renci.SshNet.Tests.Classes.Connection
@@ -18,9 +19,11 @@ namespace Renci.SshNet.Tests.Classes.Connection
public class HttpConnectorTest_Connect_ProxyResponseStatusIs200_OnlyHeaders : HttpConnectorTestBase
{
private ConnectionInfo _connectionInfo;
+ private ProxyConnectionInfo _proxyConnectionInfo;
private AsyncSocketListener _proxyServer;
private bool _disconnected;
private Socket _clientSocket;
+ private IConnector _proxyConnector;
private List _bytesReceivedByProxy;
private string _expectedHttpRequest;
private Socket _actual;
@@ -29,28 +32,7 @@ protected override void SetupData()
{
base.SetupData();
- _connectionInfo = new ConnectionInfo(IPAddress.Loopback.ToString(),
- 777,
- "user",
- ProxyTypes.Http,
- IPAddress.Loopback.ToString(),
- 8122,
- "proxyUser",
- "proxyPwd",
- new KeyboardInteractiveAuthenticationMethod("user"))
- {
- Timeout = TimeSpan.FromMilliseconds(20)
- };
- _expectedHttpRequest = string.Format("CONNECT {0}:{1} HTTP/1.0{2}" +
- "Proxy-Authorization: Basic cHJveHlVc2VyOnByb3h5UHdk{2}{2}",
- _connectionInfo.Host,
- _connectionInfo.Port.ToString(CultureInfo.InvariantCulture),
- "\r\n");
- _bytesReceivedByProxy = new List();
- _disconnected = false;
- _clientSocket = SocketFactory.Create(SocketType.Stream, ProtocolType.Tcp);
-
- _proxyServer = new AsyncSocketListener(new IPEndPoint(IPAddress.Loopback, _connectionInfo.ProxyPort));
+ _proxyServer = new AsyncSocketListener(new IPEndPoint(IPAddress.Loopback, 0));
_proxyServer.Disconnected += (socket) => _disconnected = true;
_proxyServer.BytesReceived += (bytesReceived, socket) =>
{
@@ -70,12 +52,37 @@ protected override void SetupData()
}
};
_proxyServer.Start();
+
+ _connectionInfo = new ConnectionInfo(IPAddress.Loopback.ToString(),
+ 777,
+ "user",
+ ProxyTypes.Http,
+ IPAddress.Loopback.ToString(),
+ ((IPEndPoint)_proxyServer.ListenerEndPoint).Port,
+ "proxyUser",
+ "proxyPwd",
+ new KeyboardInteractiveAuthenticationMethod("user"))
+ {
+ Timeout = TimeSpan.FromMilliseconds(20)
+ };
+ _proxyConnectionInfo = (ProxyConnectionInfo)_connectionInfo.ProxyConnection;
+ _expectedHttpRequest = string.Format("CONNECT {0}:{1} HTTP/1.0{2}" +
+ "Proxy-Authorization: Basic cHJveHlVc2VyOnByb3h5UHdk{2}{2}",
+ _connectionInfo.Host,
+ _connectionInfo.Port.ToString(CultureInfo.InvariantCulture),
+ "\r\n");
+ _bytesReceivedByProxy = new List();
+ _disconnected = false;
+ _clientSocket = SocketFactory.Create(SocketType.Stream, ProtocolType.Tcp);
+ _proxyConnector = ServiceFactory.CreateConnector(_proxyConnectionInfo, SocketFactoryMock.Object);
}
protected override void SetupMocks()
{
_ = SocketFactoryMock.Setup(p => p.Create(SocketType.Stream, ProtocolType.Tcp))
- .Returns(_clientSocket);
+ .Returns(_clientSocket);
+ _ = ServiceFactoryMock.Setup(p => p.CreateConnector(_proxyConnectionInfo, SocketFactoryMock.Object))
+ .Returns(_proxyConnector);
}
protected override void TearDown()
@@ -89,6 +96,8 @@ protected override void TearDown()
_clientSocket.Shutdown(SocketShutdown.Both);
_clientSocket.Close();
}
+
+ _proxyConnector?.Dispose();
}
protected override void Act()
diff --git a/test/Renci.SshNet.Tests/Classes/Connection/HttpConnectorTest_Connect_ProxyResponseStatusIsNot200.cs b/test/Renci.SshNet.Tests/Classes/Connection/HttpConnectorTest_Connect_ProxyResponseStatusIsNot200.cs
index 00465a932..f3d5d1697 100644
--- a/test/Renci.SshNet.Tests/Classes/Connection/HttpConnectorTest_Connect_ProxyResponseStatusIsNot200.cs
+++ b/test/Renci.SshNet.Tests/Classes/Connection/HttpConnectorTest_Connect_ProxyResponseStatusIsNot200.cs
@@ -9,6 +9,7 @@
using Moq;
+using Renci.SshNet.Connection;
using Renci.SshNet.Common;
using Renci.SshNet.Tests.Common;
@@ -18,8 +19,10 @@ namespace Renci.SshNet.Tests.Classes.Connection
public class HttpConnectorTest_Connect_ProxyResponseStatusIsNot200 : HttpConnectorTestBase
{
private ConnectionInfo _connectionInfo;
+ private ProxyConnectionInfo _proxyConnectionInfo;
private AsyncSocketListener _proxyServer;
private Socket _clientSocket;
+ private IConnector _proxyConnector;
private List _bytesReceivedByProxy;
private bool _disconnected;
private ProxyException _actualException;
@@ -28,43 +31,47 @@ protected override void SetupData()
{
base.SetupData();
+ _proxyServer = new AsyncSocketListener(new IPEndPoint(IPAddress.Loopback, 0));
+ _proxyServer.Disconnected += (socket) => _disconnected = true;
+ _proxyServer.BytesReceived += (bytesReceived, socket) =>
+ {
+ if (_bytesReceivedByProxy.Count == 0)
+ {
+ _ = socket.Send(Encoding.ASCII.GetBytes("HTTP/1.0 404 I searched everywhere, really...\r\n"));
+
+ socket.Shutdown(SocketShutdown.Send);
+ }
+
+ _bytesReceivedByProxy.AddRange(bytesReceived);
+ };
+ _proxyServer.Start();
+
_connectionInfo = new ConnectionInfo(IPAddress.Loopback.ToString(),
777,
"user",
ProxyTypes.Http,
IPAddress.Loopback.ToString(),
- 8122,
+ ((IPEndPoint)_proxyServer.ListenerEndPoint).Port,
"proxyUser",
"proxyPwd",
new KeyboardInteractiveAuthenticationMethod("user"))
{
Timeout = TimeSpan.FromMilliseconds(100)
};
+ _proxyConnectionInfo = (ProxyConnectionInfo)_connectionInfo.ProxyConnection;
_bytesReceivedByProxy = new List();
_actualException = null;
_clientSocket = SocketFactory.Create(SocketType.Stream, ProtocolType.Tcp);
-
- _proxyServer = new AsyncSocketListener(new IPEndPoint(IPAddress.Loopback, _connectionInfo.ProxyPort));
- _proxyServer.Disconnected += (socket) => _disconnected = true;
- _proxyServer.BytesReceived += (bytesReceived, socket) =>
- {
- if (_bytesReceivedByProxy.Count == 0)
- {
- _ = socket.Send(Encoding.ASCII.GetBytes("HTTP/1.0 404 I searched everywhere, really...\r\n"));
-
- socket.Shutdown(SocketShutdown.Send);
- }
-
- _bytesReceivedByProxy.AddRange(bytesReceived);
- };
- _proxyServer.Start();
+ _proxyConnector = ServiceFactory.CreateConnector(_proxyConnectionInfo, SocketFactoryMock.Object);
}
protected override void SetupMocks()
{
_ = SocketFactoryMock.Setup(p => p.Create(SocketType.Stream, ProtocolType.Tcp))
- .Returns(_clientSocket);
+ .Returns(_clientSocket);
+ _ = ServiceFactoryMock.Setup(p => p.CreateConnector(_proxyConnectionInfo, SocketFactoryMock.Object))
+ .Returns(_proxyConnector);
}
protected override void TearDown()
@@ -72,6 +79,7 @@ protected override void TearDown()
base.TearDown();
_proxyServer?.Dispose();
+ _proxyConnector?.Dispose();
}
protected override void Act()
diff --git a/test/Renci.SshNet.Tests/Classes/Connection/HttpConnectorTest_Connect_ProxyUserNameIsEmpty.cs b/test/Renci.SshNet.Tests/Classes/Connection/HttpConnectorTest_Connect_ProxyUserNameIsEmpty.cs
index b0efb36f3..efdb31f5b 100644
--- a/test/Renci.SshNet.Tests/Classes/Connection/HttpConnectorTest_Connect_ProxyUserNameIsEmpty.cs
+++ b/test/Renci.SshNet.Tests/Classes/Connection/HttpConnectorTest_Connect_ProxyUserNameIsEmpty.cs
@@ -10,6 +10,7 @@
using Moq;
+using Renci.SshNet.Connection;
using Renci.SshNet.Tests.Common;
namespace Renci.SshNet.Tests.Classes.Connection
@@ -18,9 +19,11 @@ namespace Renci.SshNet.Tests.Classes.Connection
public class HttpConnectorTest_Connect_ProxyUserNameIsEmpty : HttpConnectorTestBase
{
private ConnectionInfo _connectionInfo;
+ private ProxyConnectionInfo _proxyConnectionInfo;
private AsyncSocketListener _proxyServer;
private bool _disconnected;
private Socket _clientSocket;
+ private IConnector _proxyConnector;
private List _bytesReceivedByProxy;
private string _expectedHttpRequest;
private Socket _actual;
@@ -29,27 +32,7 @@ protected override void SetupData()
{
base.SetupData();
- _connectionInfo = new ConnectionInfo(IPAddress.Loopback.ToString(),
- 777,
- "user",
- ProxyTypes.Http,
- IPAddress.Loopback.ToString(),
- 8122,
- string.Empty,
- "proxyPwd",
- new KeyboardInteractiveAuthenticationMethod("user"))
- {
- Timeout = TimeSpan.FromMilliseconds(20)
- };
- _expectedHttpRequest = string.Format("CONNECT {0}:{1} HTTP/1.0{2}{2}",
- _connectionInfo.Host,
- _connectionInfo.Port.ToString(CultureInfo.InvariantCulture),
- "\r\n");
- _bytesReceivedByProxy = new List();
- _disconnected = false;
- _clientSocket = SocketFactory.Create(SocketType.Stream, ProtocolType.Tcp);
-
- _proxyServer = new AsyncSocketListener(new IPEndPoint(IPAddress.Loopback, _connectionInfo.ProxyPort));
+ _proxyServer = new AsyncSocketListener(new IPEndPoint(IPAddress.Loopback, 0));
_proxyServer.Disconnected += (socket) => _disconnected = true;
_proxyServer.BytesReceived += (bytesReceived, socket) =>
{
@@ -69,12 +52,36 @@ protected override void SetupData()
}
};
_proxyServer.Start();
+
+ _connectionInfo = new ConnectionInfo(IPAddress.Loopback.ToString(),
+ 777,
+ "user",
+ ProxyTypes.Http,
+ IPAddress.Loopback.ToString(),
+ ((IPEndPoint)_proxyServer.ListenerEndPoint).Port,
+ string.Empty,
+ "proxyPwd",
+ new KeyboardInteractiveAuthenticationMethod("user"))
+ {
+ Timeout = TimeSpan.FromMilliseconds(20)
+ };
+ _proxyConnectionInfo = (ProxyConnectionInfo)_connectionInfo.ProxyConnection;
+ _expectedHttpRequest = string.Format("CONNECT {0}:{1} HTTP/1.0{2}{2}",
+ _connectionInfo.Host,
+ _connectionInfo.Port.ToString(CultureInfo.InvariantCulture),
+ "\r\n");
+ _bytesReceivedByProxy = new List();
+ _disconnected = false;
+ _clientSocket = SocketFactory.Create(SocketType.Stream, ProtocolType.Tcp);
+ _proxyConnector = ServiceFactory.CreateConnector(_proxyConnectionInfo, SocketFactoryMock.Object);
}
protected override void SetupMocks()
{
_ = SocketFactoryMock.Setup(p => p.Create(SocketType.Stream, ProtocolType.Tcp))
- .Returns(_clientSocket);
+ .Returns(_clientSocket);
+ _ = ServiceFactoryMock.Setup(p => p.CreateConnector(_proxyConnectionInfo, SocketFactoryMock.Object))
+ .Returns(_proxyConnector);
}
protected override void TearDown()
@@ -83,6 +90,7 @@ protected override void TearDown()
_proxyServer?.Dispose();
_clientSocket?.Close();
+ _proxyConnector?.Dispose();
}
protected override void Act()
diff --git a/test/Renci.SshNet.Tests/Classes/Connection/HttpConnectorTest_Connect_ProxyUserNameIsNotNullAndNotEmpty.cs b/test/Renci.SshNet.Tests/Classes/Connection/HttpConnectorTest_Connect_ProxyUserNameIsNotNullAndNotEmpty.cs
index 0b7c81ccc..2ec53d43e 100644
--- a/test/Renci.SshNet.Tests/Classes/Connection/HttpConnectorTest_Connect_ProxyUserNameIsNotNullAndNotEmpty.cs
+++ b/test/Renci.SshNet.Tests/Classes/Connection/HttpConnectorTest_Connect_ProxyUserNameIsNotNullAndNotEmpty.cs
@@ -10,6 +10,7 @@
using Moq;
+using Renci.SshNet.Connection;
using Renci.SshNet.Tests.Common;
namespace Renci.SshNet.Tests.Classes.Connection
@@ -18,9 +19,11 @@ namespace Renci.SshNet.Tests.Classes.Connection
public class HttpConnectorTest_Connect_ProxyUserNameIsNotNullAndNotEmpty : HttpConnectorTestBase
{
private ConnectionInfo _connectionInfo;
+ private ProxyConnectionInfo _proxyConnectionInfo;
private AsyncSocketListener _proxyServer;
private bool _disconnected;
private Socket _clientSocket;
+ private IConnector _proxyConnector;
private List _bytesReceivedByProxy;
private string _expectedHttpRequest;
private Socket _actual;
@@ -29,18 +32,34 @@ protected override void SetupData()
{
base.SetupData();
+ _proxyServer = new AsyncSocketListener(new IPEndPoint(IPAddress.Loopback, 0));
+ _proxyServer.Connected += (socket) =>
+ {
+ _ = socket.Send(Encoding.ASCII.GetBytes("HTTP/1.0 200 OK\r\n"));
+ _ = socket.Send(Encoding.ASCII.GetBytes("Content-Type: application/octet-stream\r\n"));
+ _ = socket.Send(Encoding.ASCII.GetBytes("\r\n"));
+ _ = socket.Send(Encoding.ASCII.GetBytes("SSH4EVER"));
+ };
+ _proxyServer.Disconnected += (socket) => _disconnected = true;
+ _proxyServer.BytesReceived += (bytesReceived, socket) =>
+ {
+ _bytesReceivedByProxy.AddRange(bytesReceived);
+ };
+ _proxyServer.Start();
+
_connectionInfo = new ConnectionInfo(IPAddress.Loopback.ToString(),
777,
"user",
ProxyTypes.Http,
IPAddress.Loopback.ToString(),
- 8122,
+ ((IPEndPoint)_proxyServer.ListenerEndPoint).Port,
"user",
"pwd",
new KeyboardInteractiveAuthenticationMethod("user"))
{
Timeout = TimeSpan.FromMilliseconds(20)
};
+ _proxyConnectionInfo = (ProxyConnectionInfo)_connectionInfo.ProxyConnection;
_expectedHttpRequest = string.Format("CONNECT {0}:{1} HTTP/1.0{2}" +
"Proxy-Authorization: Basic dXNlcjpwd2Q={2}{2}",
_connectionInfo.Host,
@@ -49,27 +68,15 @@ protected override void SetupData()
_bytesReceivedByProxy = new List();
_disconnected = false;
_clientSocket = SocketFactory.Create(SocketType.Stream, ProtocolType.Tcp);
-
- _proxyServer = new AsyncSocketListener(new IPEndPoint(IPAddress.Loopback, _connectionInfo.ProxyPort));
- _proxyServer.Connected += (socket) =>
- {
- _ = socket.Send(Encoding.ASCII.GetBytes("HTTP/1.0 200 OK\r\n"));
- _ = socket.Send(Encoding.ASCII.GetBytes("Content-Type: application/octet-stream\r\n"));
- _ = socket.Send(Encoding.ASCII.GetBytes("\r\n"));
- _ = socket.Send(Encoding.ASCII.GetBytes("SSH4EVER"));
- };
- _proxyServer.Disconnected += (socket) => _disconnected = true;
- _proxyServer.BytesReceived += (bytesReceived, socket) =>
- {
- _bytesReceivedByProxy.AddRange(bytesReceived);
- };
- _proxyServer.Start();
+ _proxyConnector = ServiceFactory.CreateConnector(_proxyConnectionInfo, SocketFactoryMock.Object);
}
protected override void SetupMocks()
{
_ = SocketFactoryMock.Setup(p => p.Create(SocketType.Stream, ProtocolType.Tcp))
- .Returns(_clientSocket);
+ .Returns(_clientSocket);
+ _ = ServiceFactoryMock.Setup(p => p.CreateConnector(_proxyConnectionInfo, SocketFactoryMock.Object))
+ .Returns(_proxyConnector);
}
protected override void TearDown()
@@ -83,6 +90,8 @@ protected override void TearDown()
_clientSocket.Shutdown(SocketShutdown.Both);
_clientSocket.Close();
}
+
+ _proxyConnector?.Dispose();
}
protected override void Act()
diff --git a/test/Renci.SshNet.Tests/Classes/Connection/HttpConnectorTest_Connect_ProxyUserNameIsNull.cs b/test/Renci.SshNet.Tests/Classes/Connection/HttpConnectorTest_Connect_ProxyUserNameIsNull.cs
index ab4da5511..c6f9b5fd1 100644
--- a/test/Renci.SshNet.Tests/Classes/Connection/HttpConnectorTest_Connect_ProxyUserNameIsNull.cs
+++ b/test/Renci.SshNet.Tests/Classes/Connection/HttpConnectorTest_Connect_ProxyUserNameIsNull.cs
@@ -10,6 +10,7 @@
using Moq;
+using Renci.SshNet.Connection;
using Renci.SshNet.Tests.Common;
namespace Renci.SshNet.Tests.Classes.Connection
@@ -18,9 +19,11 @@ namespace Renci.SshNet.Tests.Classes.Connection
public class HttpConnectorTest_Connect_ProxyUserNameIsNull : HttpConnectorTestBase
{
private ConnectionInfo _connectionInfo;
+ private ProxyConnectionInfo _proxyConnectionInfo;
private AsyncSocketListener _proxyServer;
private bool _disconnected;
private Socket _clientSocket;
+ private IConnector _proxyConnector;
private List _bytesReceivedByProxy;
private string _expectedHttpRequest;
private Socket _actual;
@@ -29,27 +32,7 @@ protected override void SetupData()
{
base.SetupData();
- _connectionInfo = new ConnectionInfo(IPAddress.Loopback.ToString(),
- 777,
- "user",
- ProxyTypes.Http,
- IPAddress.Loopback.ToString(),
- 8122,
- null,
- "proxyPwd",
- new KeyboardInteractiveAuthenticationMethod("user"))
- {
- Timeout = TimeSpan.FromMilliseconds(20)
- };
- _expectedHttpRequest = string.Format("CONNECT {0}:{1} HTTP/1.0{2}{2}",
- _connectionInfo.Host,
- _connectionInfo.Port.ToString(CultureInfo.InvariantCulture),
- "\r\n");
- _bytesReceivedByProxy = new List();
- _disconnected = false;
- _clientSocket = SocketFactory.Create(SocketType.Stream, ProtocolType.Tcp);
-
- _proxyServer = new AsyncSocketListener(new IPEndPoint(IPAddress.Loopback, _connectionInfo.ProxyPort));
+ _proxyServer = new AsyncSocketListener(new IPEndPoint(IPAddress.Loopback, 0));
_proxyServer.Disconnected += (socket) => _disconnected = true;
_proxyServer.BytesReceived += (bytesReceived, socket) =>
{
@@ -69,12 +52,36 @@ protected override void SetupData()
}
};
_proxyServer.Start();
+
+ _connectionInfo = new ConnectionInfo(IPAddress.Loopback.ToString(),
+ 777,
+ "user",
+ ProxyTypes.Http,
+ IPAddress.Loopback.ToString(),
+ ((IPEndPoint)_proxyServer.ListenerEndPoint).Port,
+ null,
+ "proxyPwd",
+ new KeyboardInteractiveAuthenticationMethod("user"))
+ {
+ Timeout = TimeSpan.FromMilliseconds(20)
+ };
+ _proxyConnectionInfo = (ProxyConnectionInfo)_connectionInfo.ProxyConnection;
+ _expectedHttpRequest = string.Format("CONNECT {0}:{1} HTTP/1.0{2}{2}",
+ _connectionInfo.Host,
+ _connectionInfo.Port.ToString(CultureInfo.InvariantCulture),
+ "\r\n");
+ _bytesReceivedByProxy = new List();
+ _disconnected = false;
+ _clientSocket = SocketFactory.Create(SocketType.Stream, ProtocolType.Tcp);
+ _proxyConnector = ServiceFactory.CreateConnector(_proxyConnectionInfo, SocketFactoryMock.Object);
}
protected override void SetupMocks()
{
_ = SocketFactoryMock.Setup(p => p.Create(SocketType.Stream, ProtocolType.Tcp))
- .Returns(_clientSocket);
+ .Returns(_clientSocket);
+ _ = ServiceFactoryMock.Setup(p => p.CreateConnector(_proxyConnectionInfo, SocketFactoryMock.Object))
+ .Returns(_proxyConnector);
}
protected override void TearDown()
@@ -88,6 +95,7 @@ protected override void TearDown()
}
_proxyServer?.Dispose();
+ _proxyConnector?.Dispose();
}
protected override void Act()
diff --git a/test/Renci.SshNet.Tests/Classes/Connection/HttpConnectorTest_Connect_TimeoutConnectingToProxy.cs b/test/Renci.SshNet.Tests/Classes/Connection/HttpConnectorTest_Connect_TimeoutConnectingToProxy.cs
index 0e8b0935e..e2e1347a6 100644
--- a/test/Renci.SshNet.Tests/Classes/Connection/HttpConnectorTest_Connect_TimeoutConnectingToProxy.cs
+++ b/test/Renci.SshNet.Tests/Classes/Connection/HttpConnectorTest_Connect_TimeoutConnectingToProxy.cs
@@ -9,6 +9,7 @@
using Moq;
+using Renci.SshNet.Connection;
using Renci.SshNet.Common;
using Renci.SshNet.Tests.Common;
@@ -18,8 +19,10 @@ namespace Renci.SshNet.Tests.Classes.Connection
public class HttpConnectorTest_Connect_TimeoutConnectingToProxy : HttpConnectorTestBase
{
private ConnectionInfo _connectionInfo;
+ private ProxyConnectionInfo _proxyConnectionInfo;
private Exception _actualException;
private Socket _clientSocket;
+ private IConnector _proxyConnector;
private Stopwatch _stopWatch;
protected override void SetupData()
@@ -33,23 +36,28 @@ protected override void SetupData()
"user",
ProxyTypes.Http,
IPAddress.Loopback.ToString(),
- 8122,
+ 8121,
"proxyUser",
"proxyPwd",
new KeyboardInteractiveAuthenticationMethod("user"))
{
Timeout = TimeSpan.FromMilliseconds(random.Next(50, 200))
};
+ _proxyConnectionInfo = (ProxyConnectionInfo)_connectionInfo.ProxyConnection;
+ _proxyConnectionInfo.Timeout = _connectionInfo.Timeout;
_stopWatch = new Stopwatch();
_actualException = null;
_clientSocket = SocketFactory.Create(SocketType.Stream, ProtocolType.Tcp);
+ _proxyConnector = ServiceFactory.CreateConnector(_proxyConnectionInfo, SocketFactoryMock.Object);
}
protected override void SetupMocks()
{
_ = SocketFactoryMock.Setup(p => p.Create(SocketType.Stream, ProtocolType.Tcp))
- .Returns(_clientSocket);
+ .Returns(_clientSocket);
+ _ = ServiceFactoryMock.Setup(p => p.CreateConnector(_proxyConnectionInfo, SocketFactoryMock.Object))
+ .Returns(_proxyConnector);
}
protected override void TearDown()
@@ -57,6 +65,7 @@ protected override void TearDown()
base.TearDown();
_clientSocket?.Dispose();
+ _proxyConnector?.Dispose();
}
protected override void Act()
diff --git a/test/Renci.SshNet.Tests/Classes/Connection/HttpConnectorTest_Connect_TimeoutReadingHttpContent.cs b/test/Renci.SshNet.Tests/Classes/Connection/HttpConnectorTest_Connect_TimeoutReadingHttpContent.cs
index 45d9a59e6..aa22cad67 100644
--- a/test/Renci.SshNet.Tests/Classes/Connection/HttpConnectorTest_Connect_TimeoutReadingHttpContent.cs
+++ b/test/Renci.SshNet.Tests/Classes/Connection/HttpConnectorTest_Connect_TimeoutReadingHttpContent.cs
@@ -11,6 +11,7 @@
using Moq;
+using Renci.SshNet.Connection;
using Renci.SshNet.Common;
using Renci.SshNet.Tests.Common;
@@ -20,8 +21,10 @@ namespace Renci.SshNet.Tests.Classes.Connection
public class HttpConnectorTest_Connect_TimeoutReadingHttpContent : HttpConnectorTestBase
{
private ConnectionInfo _connectionInfo;
+ private ProxyConnectionInfo _proxyConnectionInfo;
private SshOperationTimeoutException _actualException;
private Socket _clientSocket;
+ private IConnector _proxyConnector;
private AsyncSocketListener _proxyServer;
private List _bytesReceivedByProxy;
private string _expectedHttpRequest;
@@ -35,18 +38,40 @@ protected override void SetupData()
var random = new Random();
+ _proxyServer = new AsyncSocketListener(new IPEndPoint(IPAddress.Loopback, 0));
+ _proxyServer.Disconnected += (socket) => _disconnected = true;
+ _proxyServer.BytesReceived += (bytesReceived, socket) =>
+ {
+ _bytesReceivedByProxy.AddRange(bytesReceived);
+
+ // Force a timeout by sending less content than indicated by Content-Length header
+ if (_bytesReceivedByProxy.Count == _expectedHttpRequest.Length)
+ {
+ _ = socket.Send(Encoding.ASCII.GetBytes("HTTP/1.0 200 OK\r\n"));
+ _ = socket.Send(Encoding.ASCII.GetBytes("Content-Length: 10\r\n"));
+ _ = socket.Send(Encoding.ASCII.GetBytes("Content-Type: application/octet-stream\r\n"));
+ _ = socket.Send(Encoding.ASCII.GetBytes("\r\n"));
+ _ = socket.Send(Encoding.ASCII.GetBytes("TOO_FEW"));
+ }
+ };
+ _proxyServer.Start();
+
+ _server = new AsyncSocketListener(new IPEndPoint(IPAddress.Loopback, 0));
+ _server.Start();
+
_connectionInfo = new ConnectionInfo(IPAddress.Loopback.ToString(),
- 1026,
+ ((IPEndPoint)_server.ListenerEndPoint).Port,
"user",
ProxyTypes.Http,
IPAddress.Loopback.ToString(),
- 8122,
+ ((IPEndPoint)_proxyServer.ListenerEndPoint).Port,
"proxyUser",
"proxyPwd",
new KeyboardInteractiveAuthenticationMethod("user"))
{
Timeout = TimeSpan.FromMilliseconds(random.Next(50, 200))
};
+ _proxyConnectionInfo = (ProxyConnectionInfo)_connectionInfo.ProxyConnection;
_expectedHttpRequest = string.Format("CONNECT {0}:{1} HTTP/1.0{2}" +
"Proxy-Authorization: Basic cHJveHlVc2VyOnByb3h5UHdk{2}{2}",
_connectionInfo.Host,
@@ -57,33 +82,15 @@ protected override void SetupData()
_actualException = null;
_clientSocket = SocketFactory.Create(SocketType.Stream, ProtocolType.Tcp);
-
- _proxyServer = new AsyncSocketListener(new IPEndPoint(IPAddress.Loopback, _connectionInfo.ProxyPort));
- _proxyServer.Disconnected += (socket) => _disconnected = true;
- _proxyServer.BytesReceived += (bytesReceived, socket) =>
- {
- _bytesReceivedByProxy.AddRange(bytesReceived);
-
- // Force a timeout by sending less content than indicated by Content-Length header
- if (_bytesReceivedByProxy.Count == _expectedHttpRequest.Length)
- {
- _ = socket.Send(Encoding.ASCII.GetBytes("HTTP/1.0 200 OK\r\n"));
- _ = socket.Send(Encoding.ASCII.GetBytes("Content-Length: 10\r\n"));
- _ = socket.Send(Encoding.ASCII.GetBytes("Content-Type: application/octet-stream\r\n"));
- _ = socket.Send(Encoding.ASCII.GetBytes("\r\n"));
- _ = socket.Send(Encoding.ASCII.GetBytes("TOO_FEW"));
- }
- };
- _proxyServer.Start();
-
- _server = new AsyncSocketListener(new IPEndPoint(IPAddress.Loopback, _connectionInfo.Port));
- _server.Start();
+ _proxyConnector = ServiceFactory.CreateConnector(_proxyConnectionInfo, SocketFactoryMock.Object);
}
protected override void SetupMocks()
{
_ = SocketFactoryMock.Setup(p => p.Create(SocketType.Stream, ProtocolType.Tcp))
- .Returns(_clientSocket);
+ .Returns(_clientSocket);
+ _ = ServiceFactoryMock.Setup(p => p.CreateConnector(_proxyConnectionInfo, SocketFactoryMock.Object))
+ .Returns(_proxyConnector);
}
protected override void TearDown()
@@ -92,6 +99,7 @@ protected override void TearDown()
_server?.Dispose();
_proxyServer?.Dispose();
+ _proxyConnector?.Dispose();
}
protected override void Act()
diff --git a/test/Renci.SshNet.Tests/Classes/Connection/HttpConnectorTest_Connect_TimeoutReadingStatusLine.cs b/test/Renci.SshNet.Tests/Classes/Connection/HttpConnectorTest_Connect_TimeoutReadingStatusLine.cs
index 4610c521c..69ef57aea 100644
--- a/test/Renci.SshNet.Tests/Classes/Connection/HttpConnectorTest_Connect_TimeoutReadingStatusLine.cs
+++ b/test/Renci.SshNet.Tests/Classes/Connection/HttpConnectorTest_Connect_TimeoutReadingStatusLine.cs
@@ -9,6 +9,7 @@
using Moq;
+using Renci.SshNet.Connection;
using Renci.SshNet.Common;
using Renci.SshNet.Tests.Common;
@@ -18,8 +19,10 @@ namespace Renci.SshNet.Tests.Classes.Connection
public class HttpConnectorTest_Connect_TimeoutReadingStatusLine : HttpConnectorTestBase
{
private ConnectionInfo _connectionInfo;
+ private ProxyConnectionInfo _proxyConnectionInfo;
private SshOperationTimeoutException _actualException;
private Socket _clientSocket;
+ private IConnector _proxyConnector;
private AsyncSocketListener _proxyServer;
private Stopwatch _stopWatch;
private AsyncSocketListener _server;
@@ -31,35 +34,39 @@ protected override void SetupData()
var random = new Random();
+ _proxyServer = new AsyncSocketListener(new IPEndPoint(IPAddress.Loopback, 0));
+ _proxyServer.Disconnected += (socket) => _disconnected = true;
+ _proxyServer.Start();
+
+ _server = new AsyncSocketListener(new IPEndPoint(IPAddress.Loopback, 0));
+ _server.Start();
+
_connectionInfo = new ConnectionInfo(IPAddress.Loopback.ToString(),
- 1028,
+ ((IPEndPoint)_server.ListenerEndPoint).Port,
"user",
ProxyTypes.Http,
IPAddress.Loopback.ToString(),
- 8122,
+ ((IPEndPoint)_proxyServer.ListenerEndPoint).Port,
"proxyUser",
"proxyPwd",
new KeyboardInteractiveAuthenticationMethod("user"))
{
Timeout = TimeSpan.FromMilliseconds(random.Next(50, 200))
};
+ _proxyConnectionInfo = (ProxyConnectionInfo)_connectionInfo.ProxyConnection;
_stopWatch = new Stopwatch();
_actualException = null;
_clientSocket = SocketFactory.Create(SocketType.Stream, ProtocolType.Tcp);
-
- _proxyServer = new AsyncSocketListener(new IPEndPoint(IPAddress.Loopback, _connectionInfo.ProxyPort));
- _proxyServer.Disconnected += (socket) => _disconnected = true;
- _proxyServer.Start();
-
- _server = new AsyncSocketListener(new IPEndPoint(IPAddress.Loopback, _connectionInfo.Port));
- _server.Start();
+ _proxyConnector = ServiceFactory.CreateConnector(_proxyConnectionInfo, SocketFactoryMock.Object);
}
protected override void SetupMocks()
{
_ = SocketFactoryMock.Setup(p => p.Create(SocketType.Stream, ProtocolType.Tcp))
- .Returns(_clientSocket);
+ .Returns(_clientSocket);
+ _ = ServiceFactoryMock.Setup(p => p.CreateConnector(_proxyConnectionInfo, SocketFactoryMock.Object))
+ .Returns(_proxyConnector);
}
protected override void TearDown()
@@ -68,6 +75,7 @@ protected override void TearDown()
_server?.Dispose();
_proxyServer?.Dispose();
+ _proxyConnector?.Dispose();
}
protected override void Act()
diff --git a/test/Renci.SshNet.Tests/Classes/Connection/ProtocolVersionExchangeTest_ConnectionClosedByServer_NoDataSentByServer.cs b/test/Renci.SshNet.Tests/Classes/Connection/ProtocolVersionExchangeTest_ConnectionClosedByServer_NoDataSentByServer.cs
index 43aa9a3b1..c4d0da2dc 100644
--- a/test/Renci.SshNet.Tests/Classes/Connection/ProtocolVersionExchangeTest_ConnectionClosedByServer_NoDataSentByServer.cs
+++ b/test/Renci.SshNet.Tests/Classes/Connection/ProtocolVersionExchangeTest_ConnectionClosedByServer_NoDataSentByServer.cs
@@ -53,7 +53,7 @@ protected void Arrange()
{
_clientVersion = "\uD55C";
_timeout = TimeSpan.FromSeconds(5);
- _serverEndPoint = new IPEndPoint(IPAddress.Loopback, 8122);
+ _serverEndPoint = new IPEndPoint(IPAddress.Loopback, 0);
_dataReceivedByServer = new List();
_server = new AsyncSocketListener(_serverEndPoint);
@@ -65,6 +65,8 @@ protected void Arrange()
};
_server.Disconnected += (socket) => _clientDisconnected = true;
+ _serverEndPoint.Port = ((IPEndPoint)_server.ListenerEndPoint).Port;
+
_client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
_client.Connect(_serverEndPoint);
diff --git a/test/Renci.SshNet.Tests/Classes/Connection/ProtocolVersionExchangeTest_ServerResponseContainsNullCharacter.cs b/test/Renci.SshNet.Tests/Classes/Connection/ProtocolVersionExchangeTest_ServerResponseContainsNullCharacter.cs
index 164cb6a70..cec21c1ff 100644
--- a/test/Renci.SshNet.Tests/Classes/Connection/ProtocolVersionExchangeTest_ServerResponseContainsNullCharacter.cs
+++ b/test/Renci.SshNet.Tests/Classes/Connection/ProtocolVersionExchangeTest_ServerResponseContainsNullCharacter.cs
@@ -56,7 +56,7 @@ protected void Arrange()
{
_clientVersion = "SSH-2.0-Renci.SshNet.SshClient.0.0.1";
_timeout = TimeSpan.FromSeconds(5);
- _serverEndPoint = new IPEndPoint(IPAddress.Loopback, 8122);
+ _serverEndPoint = new IPEndPoint(IPAddress.Loopback, 0);
_dataReceivedByServer = new List();
_serverIdentification = Encoding.UTF8.GetBytes("\uD55C!\0\uD55CSSH -2.0-Renci.SshNet.SshClient.0.0.1");
@@ -69,6 +69,8 @@ protected void Arrange()
};
_server.Disconnected += (socket) => _clientDisconnected = true;
+ _serverEndPoint.Port = ((IPEndPoint)_server.ListenerEndPoint).Port;
+
_client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
_client.Connect(_serverEndPoint);
diff --git a/test/Renci.SshNet.Tests/Classes/Connection/ProtocolVersionExchangeTest_ServerResponseInvalid_SshIdentificationOnlyContainsProtocolVersion.cs b/test/Renci.SshNet.Tests/Classes/Connection/ProtocolVersionExchangeTest_ServerResponseInvalid_SshIdentificationOnlyContainsProtocolVersion.cs
index 3b0649517..fa1760936 100644
--- a/test/Renci.SshNet.Tests/Classes/Connection/ProtocolVersionExchangeTest_ServerResponseInvalid_SshIdentificationOnlyContainsProtocolVersion.cs
+++ b/test/Renci.SshNet.Tests/Classes/Connection/ProtocolVersionExchangeTest_ServerResponseInvalid_SshIdentificationOnlyContainsProtocolVersion.cs
@@ -56,7 +56,7 @@ protected void Arrange()
{
_clientVersion = "SSH-2.0-Renci.SshNet.SshClient.0.0.1";
_timeout = TimeSpan.FromSeconds(5);
- _serverEndPoint = new IPEndPoint(IPAddress.Loopback, 8122);
+ _serverEndPoint = new IPEndPoint(IPAddress.Loopback, 0);
_dataReceivedByServer = new List();
_serverIdentification = Encoding.UTF8.GetBytes("SSH-2.0\r\n");
@@ -72,6 +72,8 @@ protected void Arrange()
};
_server.Disconnected += (socket) => _clientDisconnected = true;
+ _serverEndPoint.Port = ((IPEndPoint)_server.ListenerEndPoint).Port;
+
_client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
_client.Connect(_serverEndPoint);
diff --git a/test/Renci.SshNet.Tests/Classes/Connection/ProtocolVersionExchangeTest_ServerResponseValid_Comments.cs b/test/Renci.SshNet.Tests/Classes/Connection/ProtocolVersionExchangeTest_ServerResponseValid_Comments.cs
index 2af8062b6..08d878084 100644
--- a/test/Renci.SshNet.Tests/Classes/Connection/ProtocolVersionExchangeTest_ServerResponseValid_Comments.cs
+++ b/test/Renci.SshNet.Tests/Classes/Connection/ProtocolVersionExchangeTest_ServerResponseValid_Comments.cs
@@ -55,7 +55,7 @@ protected void Arrange()
{
_clientVersion = "SSH-2.0-Renci.SshNet.SshClient.0.0.1";
_timeout = TimeSpan.FromSeconds(5);
- _serverEndPoint = new IPEndPoint(IPAddress.Loopback, 8122);
+ _serverEndPoint = new IPEndPoint(IPAddress.Loopback, 0);
_dataReceivedByServer = new List();
_serverIdentification = Encoding.UTF8.GetBytes("\r\nWelcome stranger!\r\n\r\nSSH-ABC2.0-OurSSHAppliance-1.4.7 Use at own risk.\uD55C\r\n!");
@@ -69,6 +69,8 @@ protected void Arrange()
};
_server.Disconnected += (socket) => _clientDisconnected = true;
+ _serverEndPoint.Port = ((IPEndPoint)_server.ListenerEndPoint).Port;
+
_client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
_client.Connect(_serverEndPoint);
diff --git a/test/Renci.SshNet.Tests/Classes/Connection/ProtocolVersionExchangeTest_ServerResponseValid_NoComments.cs b/test/Renci.SshNet.Tests/Classes/Connection/ProtocolVersionExchangeTest_ServerResponseValid_NoComments.cs
index 365967209..621c5c667 100644
--- a/test/Renci.SshNet.Tests/Classes/Connection/ProtocolVersionExchangeTest_ServerResponseValid_NoComments.cs
+++ b/test/Renci.SshNet.Tests/Classes/Connection/ProtocolVersionExchangeTest_ServerResponseValid_NoComments.cs
@@ -55,7 +55,7 @@ protected void Arrange()
{
_clientVersion = "SSH-2.0-Renci.SshNet.SshClient.0.0.1";
_timeout = TimeSpan.FromSeconds(5);
- _serverEndPoint = new IPEndPoint(IPAddress.Loopback, 8122);
+ _serverEndPoint = new IPEndPoint(IPAddress.Loopback, 0);
_dataReceivedByServer = new List();
_serverIdentification = Encoding.UTF8.GetBytes("Welcome stranger!\r\n\r\nSSH-Zero-OurSSHAppliance\r\n!");
@@ -69,6 +69,8 @@ protected void Arrange()
};
_server.Disconnected += (socket) => _clientDisconnected = true;
+ _serverEndPoint.Port = ((IPEndPoint)_server.ListenerEndPoint).Port;
+
_client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
_client.Connect(_serverEndPoint);
diff --git a/test/Renci.SshNet.Tests/Classes/Connection/ProtocolVersionExchangeTest_ServerResponseValid_TerminatedByLineFeedWithoutCarriageReturn.cs b/test/Renci.SshNet.Tests/Classes/Connection/ProtocolVersionExchangeTest_ServerResponseValid_TerminatedByLineFeedWithoutCarriageReturn.cs
index 2c35bce53..007d1bea9 100644
--- a/test/Renci.SshNet.Tests/Classes/Connection/ProtocolVersionExchangeTest_ServerResponseValid_TerminatedByLineFeedWithoutCarriageReturn.cs
+++ b/test/Renci.SshNet.Tests/Classes/Connection/ProtocolVersionExchangeTest_ServerResponseValid_TerminatedByLineFeedWithoutCarriageReturn.cs
@@ -55,7 +55,7 @@ protected void Arrange()
{
_clientVersion = "SSH-2.0-Renci.SshNet.SshClient.0.0.1";
_timeout = TimeSpan.FromSeconds(5);
- _serverEndPoint = new IPEndPoint(IPAddress.Loopback, 8122);
+ _serverEndPoint = new IPEndPoint(IPAddress.Loopback, 0);
_dataReceivedByServer = new List();
_serverIdentification = Encoding.UTF8.GetBytes("Welcome stranger!\n\nSSH-Zero-OurSSHAppliance\n\0");
@@ -71,6 +71,8 @@ protected void Arrange()
};
_server.Disconnected += (socket) => _clientDisconnected = true;
+ _serverEndPoint.Port = ((IPEndPoint)_server.ListenerEndPoint).Port;
+
_client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
_client.Connect(_serverEndPoint);
diff --git a/test/Renci.SshNet.Tests/Classes/Connection/ProtocolVersionExchangeTest_TimeoutReadingIdentificationString.cs b/test/Renci.SshNet.Tests/Classes/Connection/ProtocolVersionExchangeTest_TimeoutReadingIdentificationString.cs
index 3710e2064..a0625584b 100644
--- a/test/Renci.SshNet.Tests/Classes/Connection/ProtocolVersionExchangeTest_TimeoutReadingIdentificationString.cs
+++ b/test/Renci.SshNet.Tests/Classes/Connection/ProtocolVersionExchangeTest_TimeoutReadingIdentificationString.cs
@@ -54,7 +54,7 @@ protected void Arrange()
{
_clientVersion = "SSH-2.0-Renci.SshNet.SshClient.0.0.1";
_timeout = TimeSpan.FromMilliseconds(200);
- _serverEndPoint = new IPEndPoint(IPAddress.Loopback, 8122);
+ _serverEndPoint = new IPEndPoint(IPAddress.Loopback, 0);
_dataReceivedByServer = new List();
_clientDisconnected = false;
@@ -68,6 +68,8 @@ protected void Arrange()
};
_server.Disconnected += (socket) => _clientDisconnected = true;
+ _serverEndPoint.Port = ((IPEndPoint)_server.ListenerEndPoint).Port;
+
_client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
_client.Connect(_serverEndPoint);
diff --git a/test/Renci.SshNet.Tests/Classes/Connection/Socks4ConnectorTestBase.cs b/test/Renci.SshNet.Tests/Classes/Connection/Socks4ConnectorTestBase.cs
index ced3e1551..87792d6a3 100644
--- a/test/Renci.SshNet.Tests/Classes/Connection/Socks4ConnectorTestBase.cs
+++ b/test/Renci.SshNet.Tests/Classes/Connection/Socks4ConnectorTestBase.cs
@@ -9,18 +9,22 @@ namespace Renci.SshNet.Tests.Classes.Connection
{
public abstract class Socks4ConnectorTestBase : TripleATestBase
{
+ internal Mock ServiceFactoryMock { get; private set; }
internal Mock SocketFactoryMock { get; private set; }
internal Socks4Connector Connector { get; private set; }
internal SocketFactory SocketFactory { get; private set; }
+ internal ServiceFactory ServiceFactory { get; private set; }
protected virtual void CreateMocks()
{
+ ServiceFactoryMock = new Mock(MockBehavior.Strict);
SocketFactoryMock = new Mock(MockBehavior.Strict);
}
protected virtual void SetupData()
{
- Connector = new Socks4Connector(SocketFactoryMock.Object);
+ Connector = new Socks4Connector(ServiceFactoryMock.Object, SocketFactoryMock.Object);
+ ServiceFactory = new ServiceFactory();
SocketFactory = new SocketFactory();
}
@@ -35,14 +39,14 @@ protected sealed override void Arrange()
SetupMocks();
}
- protected ConnectionInfo CreateConnectionInfo(string proxyUser, string proxyPassword)
+ protected ConnectionInfo CreateConnectionInfo(string proxyUser, string proxyPassword, int port, int proxyPort)
{
return new ConnectionInfo(IPAddress.Loopback.ToString(),
- 1030,
+ port,
"user",
ProxyTypes.Socks4,
IPAddress.Loopback.ToString(),
- 8122,
+ proxyPort,
proxyUser,
proxyPassword,
new KeyboardInteractiveAuthenticationMethod("user"));
diff --git a/test/Renci.SshNet.Tests/Classes/Connection/Socks4ConnectorTest_Connect_ConnectionRejectedByProxy.cs b/test/Renci.SshNet.Tests/Classes/Connection/Socks4ConnectorTest_Connect_ConnectionRejectedByProxy.cs
index 9a1696267..bda4f8982 100644
--- a/test/Renci.SshNet.Tests/Classes/Connection/Socks4ConnectorTest_Connect_ConnectionRejectedByProxy.cs
+++ b/test/Renci.SshNet.Tests/Classes/Connection/Socks4ConnectorTest_Connect_ConnectionRejectedByProxy.cs
@@ -8,6 +8,7 @@
using Moq;
+using Renci.SshNet.Connection;
using Renci.SshNet.Common;
using Renci.SshNet.Tests.Common;
@@ -17,8 +18,10 @@ namespace Renci.SshNet.Tests.Classes.Connection
public class Socks4ConnectorTest_Connect_ConnectionRejectedByProxy : Socks4ConnectorTestBase
{
private ConnectionInfo _connectionInfo;
+ private ProxyConnectionInfo _proxyConnectionInfo;
private AsyncSocketListener _proxyServer;
private Socket _clientSocket;
+ private IConnector _proxyConnector;
private List _bytesReceivedByProxy;
private bool _disconnected;
private ProxyException _actualException;
@@ -27,13 +30,7 @@ protected override void SetupData()
{
base.SetupData();
- _connectionInfo = CreateConnectionInfo("proxyUser", "proxyPwd");
- _connectionInfo.Timeout = TimeSpan.FromMilliseconds(100);
- _bytesReceivedByProxy = new List();
- _clientSocket = SocketFactory.Create(SocketType.Stream, ProtocolType.Tcp);
- _actualException = null;
-
- _proxyServer = new AsyncSocketListener(new IPEndPoint(IPAddress.Loopback, _connectionInfo.ProxyPort));
+ _proxyServer = new AsyncSocketListener(new IPEndPoint(IPAddress.Loopback, 0));
_proxyServer.Disconnected += socket => _disconnected = true;
_proxyServer.BytesReceived += (bytesReceived, socket) =>
{
@@ -51,12 +48,22 @@ protected override void SetupData()
_bytesReceivedByProxy.AddRange(bytesReceived);
};
_proxyServer.Start();
+
+ _connectionInfo = CreateConnectionInfo("proxyUser", "proxyPwd", 777, ((IPEndPoint)_proxyServer.ListenerEndPoint).Port);
+ _connectionInfo.Timeout = TimeSpan.FromMilliseconds(100);
+ _proxyConnectionInfo = (ProxyConnectionInfo)_connectionInfo.ProxyConnection;
+ _bytesReceivedByProxy = new List();
+ _clientSocket = SocketFactory.Create(SocketType.Stream, ProtocolType.Tcp);
+ _proxyConnector = ServiceFactory.CreateConnector(_proxyConnectionInfo, SocketFactoryMock.Object);
+ _actualException = null;
}
protected override void SetupMocks()
{
_ = SocketFactoryMock.Setup(p => p.Create(SocketType.Stream, ProtocolType.Tcp))
- .Returns(_clientSocket);
+ .Returns(_clientSocket);
+ _ = ServiceFactoryMock.Setup(p => p.CreateConnector(_proxyConnectionInfo, SocketFactoryMock.Object))
+ .Returns(_proxyConnector);
}
protected override void TearDown()
@@ -65,6 +72,7 @@ protected override void TearDown()
_proxyServer?.Dispose();
_clientSocket?.Dispose();
+ _proxyConnector?.Dispose();
}
protected override void Act()
diff --git a/test/Renci.SshNet.Tests/Classes/Connection/Socks4ConnectorTest_Connect_ConnectionSucceeded.cs b/test/Renci.SshNet.Tests/Classes/Connection/Socks4ConnectorTest_Connect_ConnectionSucceeded.cs
index 5b37bfa9e..3a6a60690 100644
--- a/test/Renci.SshNet.Tests/Classes/Connection/Socks4ConnectorTest_Connect_ConnectionSucceeded.cs
+++ b/test/Renci.SshNet.Tests/Classes/Connection/Socks4ConnectorTest_Connect_ConnectionSucceeded.cs
@@ -9,6 +9,7 @@
using Moq;
+using Renci.SshNet.Connection;
using Renci.SshNet.Common;
using Renci.SshNet.Tests.Common;
@@ -18,7 +19,9 @@ namespace Renci.SshNet.Tests.Classes.Connection
public class Socks4ConnectorTest_Connect_ConnectionSucceeded : Socks4ConnectorTestBase
{
private ConnectionInfo _connectionInfo;
+ private ProxyConnectionInfo _proxyConnectionInfo;
private Socket _clientSocket;
+ private IConnector _proxyConnector;
private AsyncSocketListener _proxyServer;
private List _bytesReceivedByProxy;
private bool _disconnected;
@@ -30,13 +33,7 @@ protected override void SetupData()
var random = new Random();
- _connectionInfo = CreateConnectionInfo("proxyUser", "proxyPwd");
- _connectionInfo.Timeout = TimeSpan.FromMilliseconds(random.Next(50, 200));
- _bytesReceivedByProxy = new List();
- _clientSocket = SocketFactory.Create(SocketType.Stream, ProtocolType.Tcp);
- _actual = null;
-
- _proxyServer = new AsyncSocketListener(new IPEndPoint(IPAddress.Loopback, _connectionInfo.ProxyPort));
+ _proxyServer = new AsyncSocketListener(new IPEndPoint(IPAddress.Loopback, 0));
_proxyServer.Disconnected += socket => _disconnected = true;
_proxyServer.BytesReceived += (bytesReceived, socket) =>
{
@@ -69,12 +66,22 @@ protected override void SetupData()
}
};
_proxyServer.Start();
+
+ _connectionInfo = CreateConnectionInfo("proxyUser", "proxyPwd", 1030, ((IPEndPoint)_proxyServer.ListenerEndPoint).Port);
+ _connectionInfo.Timeout = TimeSpan.FromMilliseconds(random.Next(50, 200));
+ _proxyConnectionInfo = (ProxyConnectionInfo)_connectionInfo.ProxyConnection;
+ _bytesReceivedByProxy = new List();
+ _clientSocket = SocketFactory.Create(SocketType.Stream, ProtocolType.Tcp);
+ _proxyConnector = ServiceFactory.CreateConnector(_proxyConnectionInfo, SocketFactoryMock.Object);
+ _actual = null;
}
protected override void SetupMocks()
{
_ = SocketFactoryMock.Setup(p => p.Create(SocketType.Stream, ProtocolType.Tcp))
- .Returns(_clientSocket);
+ .Returns(_clientSocket);
+ _ = ServiceFactoryMock.Setup(p => p.CreateConnector(_proxyConnectionInfo, SocketFactoryMock.Object))
+ .Returns(_proxyConnector);
}
protected override void TearDown()
@@ -83,6 +90,7 @@ protected override void TearDown()
_proxyServer?.Dispose();
_clientSocket?.Dispose();
+ _proxyConnector?.Dispose();
}
protected override void Act()
diff --git a/test/Renci.SshNet.Tests/Classes/Connection/Socks4ConnectorTest_Connect_ConnectionToProxyRefused.cs b/test/Renci.SshNet.Tests/Classes/Connection/Socks4ConnectorTest_Connect_ConnectionToProxyRefused.cs
index 96e094a1b..05ce6598c 100644
--- a/test/Renci.SshNet.Tests/Classes/Connection/Socks4ConnectorTest_Connect_ConnectionToProxyRefused.cs
+++ b/test/Renci.SshNet.Tests/Classes/Connection/Socks4ConnectorTest_Connect_ConnectionToProxyRefused.cs
@@ -6,32 +6,40 @@
using Moq;
+using Renci.SshNet.Connection;
+
namespace Renci.SshNet.Tests.Classes.Connection
{
[TestClass]
public class Socks4ConnectorTest_Connect_ConnectionToProxyRefused : Socks4ConnectorTestBase
{
private ConnectionInfo _connectionInfo;
+ private ProxyConnectionInfo _proxyConnectionInfo;
private SocketException _actualException;
private Socket _clientSocket;
+ private IConnector _proxyConnector;
private Stopwatch _stopWatch;
protected override void SetupData()
{
base.SetupData();
- _connectionInfo = CreateConnectionInfo("proxyUser", "proxyPwd");
+ _connectionInfo = CreateConnectionInfo("proxyUser", "proxyPwd", 777, 8121);
+ _proxyConnectionInfo = (ProxyConnectionInfo)_connectionInfo.ProxyConnection;
_connectionInfo.Timeout = TimeSpan.FromMilliseconds(5000);
_stopWatch = new Stopwatch();
_actualException = null;
_clientSocket = SocketFactory.Create(SocketType.Stream, ProtocolType.Tcp);
+ _proxyConnector = ServiceFactory.CreateConnector(_proxyConnectionInfo, SocketFactoryMock.Object);
}
protected override void SetupMocks()
{
_ = SocketFactoryMock.Setup(p => p.Create(SocketType.Stream, ProtocolType.Tcp))
- .Returns(_clientSocket);
+ .Returns(_clientSocket);
+ _ = ServiceFactoryMock.Setup(p => p.CreateConnector(_proxyConnectionInfo, SocketFactoryMock.Object))
+ .Returns(_proxyConnector);
}
protected override void TearDown()
@@ -39,6 +47,7 @@ protected override void TearDown()
base.TearDown();
_clientSocket?.Dispose();
+ _proxyConnector?.Dispose();
}
protected override void Act()
diff --git a/test/Renci.SshNet.Tests/Classes/Connection/Socks4ConnectorTest_Connect_TimeoutConnectingToProxy.cs b/test/Renci.SshNet.Tests/Classes/Connection/Socks4ConnectorTest_Connect_TimeoutConnectingToProxy.cs
index 639a603c1..3b17a6118 100644
--- a/test/Renci.SshNet.Tests/Classes/Connection/Socks4ConnectorTest_Connect_TimeoutConnectingToProxy.cs
+++ b/test/Renci.SshNet.Tests/Classes/Connection/Socks4ConnectorTest_Connect_TimeoutConnectingToProxy.cs
@@ -8,6 +8,7 @@
using Moq;
+using Renci.SshNet.Connection;
using Renci.SshNet.Common;
using Renci.SshNet.Tests.Common;
@@ -17,8 +18,10 @@ namespace Renci.SshNet.Tests.Classes.Connection
public class Socks4ConnectorTest_Connect_TimeoutConnectingToProxy : Socks4ConnectorTestBase
{
private ConnectionInfo _connectionInfo;
+ private ProxyConnectionInfo _proxyConnectionInfo;
private Exception _actualException;
private Socket _clientSocket;
+ private IConnector _proxyConnector;
private Stopwatch _stopWatch;
protected override void SetupData()
@@ -27,17 +30,22 @@ protected override void SetupData()
var random = new Random();
- _connectionInfo = CreateConnectionInfo("proxyUser", "proxyPwd");
+ _connectionInfo = CreateConnectionInfo("proxyUser", "proxyPwd", 777, 8121);
_connectionInfo.Timeout = TimeSpan.FromMilliseconds(random.Next(50, 200));
+ _proxyConnectionInfo = (ProxyConnectionInfo)_connectionInfo.ProxyConnection;
+ _proxyConnectionInfo.Timeout = _connectionInfo.Timeout;
_stopWatch = new Stopwatch();
_clientSocket = SocketFactory.Create(SocketType.Stream, ProtocolType.Tcp);
+ _proxyConnector = ServiceFactory.CreateConnector(_proxyConnectionInfo, SocketFactoryMock.Object);
_actualException = null;
}
protected override void SetupMocks()
{
_ = SocketFactoryMock.Setup(p => p.Create(SocketType.Stream, ProtocolType.Tcp))
- .Returns(_clientSocket);
+ .Returns(_clientSocket);
+ _ = ServiceFactoryMock.Setup(p => p.CreateConnector(_proxyConnectionInfo, SocketFactoryMock.Object))
+ .Returns(_proxyConnector);
}
protected override void TearDown()
@@ -45,6 +53,7 @@ protected override void TearDown()
base.TearDown();
_clientSocket?.Dispose();
+ _proxyConnector?.Dispose();
}
protected override void Act()
diff --git a/test/Renci.SshNet.Tests/Classes/Connection/Socks4ConnectorTest_Connect_TimeoutReadingDestinationAddress.cs b/test/Renci.SshNet.Tests/Classes/Connection/Socks4ConnectorTest_Connect_TimeoutReadingDestinationAddress.cs
index efcd02520..5480cbf37 100644
--- a/test/Renci.SshNet.Tests/Classes/Connection/Socks4ConnectorTest_Connect_TimeoutReadingDestinationAddress.cs
+++ b/test/Renci.SshNet.Tests/Classes/Connection/Socks4ConnectorTest_Connect_TimeoutReadingDestinationAddress.cs
@@ -9,6 +9,7 @@
using Moq;
+using Renci.SshNet.Connection;
using Renci.SshNet.Common;
using Renci.SshNet.Tests.Common;
@@ -18,8 +19,10 @@ namespace Renci.SshNet.Tests.Classes.Connection
public class Socks4ConnectorTest_Connect_TimeoutReadingDestinationAddress : Socks4ConnectorTestBase
{
private ConnectionInfo _connectionInfo;
+ private ProxyConnectionInfo _proxyConnectionInfo;
private SshOperationTimeoutException _actualException;
private Socket _clientSocket;
+ private IConnector _proxyConnector;
private AsyncSocketListener _proxyServer;
private Stopwatch _stopWatch;
private AsyncSocketListener _server;
@@ -31,14 +34,7 @@ protected override void SetupData()
var random = new Random();
- _connectionInfo = CreateConnectionInfo("proxyUser", "proxyPwd");
- _connectionInfo.Timeout = TimeSpan.FromMilliseconds(random.Next(50, 200));
- _stopWatch = new Stopwatch();
- _actualException = null;
-
- _clientSocket = SocketFactory.Create(SocketType.Stream, ProtocolType.Tcp);
-
- _proxyServer = new AsyncSocketListener(new IPEndPoint(IPAddress.Loopback, _connectionInfo.ProxyPort));
+ _proxyServer = new AsyncSocketListener(new IPEndPoint(IPAddress.Loopback, 0));
_proxyServer.Disconnected += socket => _disconnected = true;
_proxyServer.Connected += socket =>
{
@@ -54,14 +50,25 @@ protected override void SetupData()
};
_proxyServer.Start();
- _server = new AsyncSocketListener(new IPEndPoint(IPAddress.Loopback, _connectionInfo.Port));
+ _server = new AsyncSocketListener(new IPEndPoint(IPAddress.Loopback, 0));
_server.Start();
+
+ _connectionInfo = CreateConnectionInfo("proxyUser", "proxyPwd", ((IPEndPoint)_server.ListenerEndPoint).Port, ((IPEndPoint)_proxyServer.ListenerEndPoint).Port);
+ _connectionInfo.Timeout = TimeSpan.FromMilliseconds(random.Next(50, 200));
+ _proxyConnectionInfo = (ProxyConnectionInfo)_connectionInfo.ProxyConnection;
+ _stopWatch = new Stopwatch();
+ _actualException = null;
+
+ _clientSocket = SocketFactory.Create(SocketType.Stream, ProtocolType.Tcp);
+ _proxyConnector = ServiceFactory.CreateConnector(_proxyConnectionInfo, SocketFactoryMock.Object);
}
protected override void SetupMocks()
{
_ = SocketFactoryMock.Setup(p => p.Create(SocketType.Stream, ProtocolType.Tcp))
- .Returns(_clientSocket);
+ .Returns(_clientSocket);
+ _ = ServiceFactoryMock.Setup(p => p.CreateConnector(_proxyConnectionInfo, SocketFactoryMock.Object))
+ .Returns(_proxyConnector);
}
protected override void TearDown()
@@ -70,6 +77,7 @@ protected override void TearDown()
_server?.Dispose();
_proxyServer?.Dispose();
+ _proxyConnector?.Dispose();
}
protected override void Act()
diff --git a/test/Renci.SshNet.Tests/Classes/Connection/Socks4ConnectorTest_Connect_TimeoutReadingReplyCode.cs b/test/Renci.SshNet.Tests/Classes/Connection/Socks4ConnectorTest_Connect_TimeoutReadingReplyCode.cs
index 92b8843e4..fc773f38b 100644
--- a/test/Renci.SshNet.Tests/Classes/Connection/Socks4ConnectorTest_Connect_TimeoutReadingReplyCode.cs
+++ b/test/Renci.SshNet.Tests/Classes/Connection/Socks4ConnectorTest_Connect_TimeoutReadingReplyCode.cs
@@ -9,6 +9,7 @@
using Moq;
+using Renci.SshNet.Connection;
using Renci.SshNet.Common;
using Renci.SshNet.Tests.Common;
@@ -18,8 +19,10 @@ namespace Renci.SshNet.Tests.Classes.Connection
public class Socks4ConnectorTest_Connect_TimeoutReadingReplyCode : Socks4ConnectorTestBase
{
private ConnectionInfo _connectionInfo;
+ private ProxyConnectionInfo _proxyConnectionInfo;
private SshOperationTimeoutException _actualException;
private Socket _clientSocket;
+ private IConnector _proxyConnector;
private AsyncSocketListener _proxyServer;
private Stopwatch _stopWatch;
private AsyncSocketListener _server;
@@ -31,14 +34,7 @@ protected override void SetupData()
var random = new Random();
- _connectionInfo = CreateConnectionInfo("proxyUser", "proxyPwd");
- _connectionInfo.Timeout = TimeSpan.FromMilliseconds(random.Next(50, 200));
- _stopWatch = new Stopwatch();
- _actualException = null;
-
- _clientSocket = SocketFactory.Create(SocketType.Stream, ProtocolType.Tcp);
-
- _proxyServer = new AsyncSocketListener(new IPEndPoint(IPAddress.Loopback, _connectionInfo.ProxyPort));
+ _proxyServer = new AsyncSocketListener(new IPEndPoint(IPAddress.Loopback, 0));
_proxyServer.Disconnected += socket => _disconnected = true;
_proxyServer.Connected += socket =>
{
@@ -50,14 +46,25 @@ protected override void SetupData()
};
_proxyServer.Start();
- _server = new AsyncSocketListener(new IPEndPoint(IPAddress.Loopback, _connectionInfo.Port));
+ _server = new AsyncSocketListener(new IPEndPoint(IPAddress.Loopback, 0));
_server.Start();
+
+ _connectionInfo = CreateConnectionInfo("proxyUser", "proxyPwd", ((IPEndPoint)_server.ListenerEndPoint).Port, ((IPEndPoint)_proxyServer.ListenerEndPoint).Port);
+ _connectionInfo.Timeout = TimeSpan.FromMilliseconds(random.Next(50, 200));
+ _proxyConnectionInfo = (ProxyConnectionInfo)_connectionInfo.ProxyConnection;
+ _stopWatch = new Stopwatch();
+ _actualException = null;
+
+ _clientSocket = SocketFactory.Create(SocketType.Stream, ProtocolType.Tcp);
+ _proxyConnector = ServiceFactory.CreateConnector(_proxyConnectionInfo, SocketFactoryMock.Object);
}
protected override void SetupMocks()
{
_ = SocketFactoryMock.Setup(p => p.Create(SocketType.Stream, ProtocolType.Tcp))
- .Returns(_clientSocket);
+ .Returns(_clientSocket);
+ _ = ServiceFactoryMock.Setup(p => p.CreateConnector(_proxyConnectionInfo, SocketFactoryMock.Object))
+ .Returns(_proxyConnector);
}
protected override void TearDown()
@@ -66,6 +73,7 @@ protected override void TearDown()
_server?.Dispose();
_proxyServer?.Dispose();
+ _proxyConnector?.Dispose();
}
protected override void Act()
diff --git a/test/Renci.SshNet.Tests/Classes/Connection/Socks4ConnectorTest_Connect_TimeoutReadingReplyVersion.cs b/test/Renci.SshNet.Tests/Classes/Connection/Socks4ConnectorTest_Connect_TimeoutReadingReplyVersion.cs
index fcb5ffb0c..9c3b687ec 100644
--- a/test/Renci.SshNet.Tests/Classes/Connection/Socks4ConnectorTest_Connect_TimeoutReadingReplyVersion.cs
+++ b/test/Renci.SshNet.Tests/Classes/Connection/Socks4ConnectorTest_Connect_TimeoutReadingReplyVersion.cs
@@ -9,6 +9,7 @@
using Moq;
+using Renci.SshNet.Connection;
using Renci.SshNet.Common;
using Renci.SshNet.Tests.Common;
@@ -18,8 +19,10 @@ namespace Renci.SshNet.Tests.Classes.Connection
public class Socks4ConnectorTest_Connect_TimeoutReadingReplyVersion : Socks4ConnectorTestBase
{
private ConnectionInfo _connectionInfo;
+ private ProxyConnectionInfo _proxyConnectionInfo;
private SshOperationTimeoutException _actualException;
private Socket _clientSocket;
+ private IConnector _proxyConnector;
private AsyncSocketListener _proxyServer;
private Stopwatch _stopWatch;
private AsyncSocketListener _server;
@@ -31,25 +34,29 @@ protected override void SetupData()
var random = new Random();
- _connectionInfo = CreateConnectionInfo("proxyUser", "proxyPwd");
+ _proxyServer = new AsyncSocketListener(new IPEndPoint(IPAddress.Loopback, 0));
+ _proxyServer.Disconnected += socket => _disconnected = true;
+ _proxyServer.Start();
+
+ _server = new AsyncSocketListener(new IPEndPoint(IPAddress.Loopback, 0));
+ _server.Start();
+
+ _connectionInfo = CreateConnectionInfo("proxyUser", "proxyPwd", ((IPEndPoint)_server.ListenerEndPoint).Port, ((IPEndPoint)_proxyServer.ListenerEndPoint).Port);
_connectionInfo.Timeout = TimeSpan.FromMilliseconds(random.Next(50, 200));
+ _proxyConnectionInfo = (ProxyConnectionInfo)_connectionInfo.ProxyConnection;
_stopWatch = new Stopwatch();
_actualException = null;
_clientSocket = SocketFactory.Create(SocketType.Stream, ProtocolType.Tcp);
-
- _proxyServer = new AsyncSocketListener(new IPEndPoint(IPAddress.Loopback, _connectionInfo.ProxyPort));
- _proxyServer.Disconnected += socket => _disconnected = true;
- _proxyServer.Start();
-
- _server = new AsyncSocketListener(new IPEndPoint(IPAddress.Loopback, _connectionInfo.Port));
- _server.Start();
+ _proxyConnector = ServiceFactory.CreateConnector(_proxyConnectionInfo, SocketFactoryMock.Object);
}
protected override void SetupMocks()
{
_ = SocketFactoryMock.Setup(p => p.Create(SocketType.Stream, ProtocolType.Tcp))
- .Returns(_clientSocket);
+ .Returns(_clientSocket);
+ _ = ServiceFactoryMock.Setup(p => p.CreateConnector(_proxyConnectionInfo, SocketFactoryMock.Object))
+ .Returns(_proxyConnector);
}
protected override void TearDown()
@@ -58,6 +65,7 @@ protected override void TearDown()
_server?.Dispose();
_proxyServer?.Dispose();
+ _proxyConnector?.Dispose();
}
protected override void Act()
diff --git a/test/Renci.SshNet.Tests/Classes/Connection/Socks5ConnectorTestBase.cs b/test/Renci.SshNet.Tests/Classes/Connection/Socks5ConnectorTestBase.cs
index 24809f614..e54548e44 100644
--- a/test/Renci.SshNet.Tests/Classes/Connection/Socks5ConnectorTestBase.cs
+++ b/test/Renci.SshNet.Tests/Classes/Connection/Socks5ConnectorTestBase.cs
@@ -11,19 +11,23 @@ namespace Renci.SshNet.Tests.Classes.Connection
{
public abstract class Socks5ConnectorTestBase : TripleATestBase
{
+ internal Mock ServiceFactoryMock { get; private set; }
internal Mock SocketFactoryMock { get; private set; }
internal Socks5Connector Connector { get; private set; }
internal SocketFactory SocketFactory { get; private set; }
+ internal ServiceFactory ServiceFactory { get; private set; }
protected virtual void CreateMocks()
{
+ ServiceFactoryMock = new Mock(MockBehavior.Strict);
SocketFactoryMock = new Mock(MockBehavior.Strict);
}
protected virtual void SetupData()
{
- Connector = new Socks5Connector(SocketFactoryMock.Object);
+ Connector = new Socks5Connector(ServiceFactoryMock.Object, SocketFactoryMock.Object);
SocketFactory = new SocketFactory();
+ ServiceFactory = new ServiceFactory();
}
protected virtual void SetupMocks()
@@ -37,14 +41,14 @@ protected sealed override void Arrange()
SetupMocks();
}
- protected ConnectionInfo CreateConnectionInfo(string proxyUser, string proxyPassword)
+ protected ConnectionInfo CreateConnectionInfo(string proxyUser, string proxyPassword, int proxyPort)
{
return new ConnectionInfo(IPAddress.Loopback.ToString(),
1029,
"user",
ProxyTypes.Socks5,
IPAddress.Loopback.ToString(),
- 8122,
+ proxyPort,
proxyUser,
proxyPassword,
new KeyboardInteractiveAuthenticationMethod("user"));
diff --git a/test/Renci.SshNet.Tests/Classes/Connection/Socks5ConnectorTest_Connect_ConnectionToProxyRefused.cs b/test/Renci.SshNet.Tests/Classes/Connection/Socks5ConnectorTest_Connect_ConnectionToProxyRefused.cs
index 51d6edda2..82de7deba 100644
--- a/test/Renci.SshNet.Tests/Classes/Connection/Socks5ConnectorTest_Connect_ConnectionToProxyRefused.cs
+++ b/test/Renci.SshNet.Tests/Classes/Connection/Socks5ConnectorTest_Connect_ConnectionToProxyRefused.cs
@@ -6,32 +6,40 @@
using Moq;
+using Renci.SshNet.Connection;
+
namespace Renci.SshNet.Tests.Classes.Connection
{
[TestClass]
public class Socks5ConnectorTest_Connect_ConnectionToProxyRefused : Socks5ConnectorTestBase
{
private ConnectionInfo _connectionInfo;
+ private ProxyConnectionInfo _proxyConnectionInfo;
private SocketException _actualException;
private Socket _clientSocket;
+ private IConnector _proxyConnector;
private Stopwatch _stopWatch;
protected override void SetupData()
{
base.SetupData();
- _connectionInfo = CreateConnectionInfo("proxyUser", "proxyPwd");
+ _connectionInfo = CreateConnectionInfo("proxyUser", "proxyPwd", 8121);
_connectionInfo.Timeout = TimeSpan.FromMilliseconds(5000);
+ _proxyConnectionInfo = (ProxyConnectionInfo)_connectionInfo.ProxyConnection;
_stopWatch = new Stopwatch();
_actualException = null;
_clientSocket = SocketFactory.Create(SocketType.Stream, ProtocolType.Tcp);
+ _proxyConnector = ServiceFactory.CreateConnector(_proxyConnectionInfo, SocketFactoryMock.Object);
}
protected override void SetupMocks()
{
_ = SocketFactoryMock.Setup(p => p.Create(SocketType.Stream, ProtocolType.Tcp))
- .Returns(_clientSocket);
+ .Returns(_clientSocket);
+ _ = ServiceFactoryMock.Setup(p => p.CreateConnector(_proxyConnectionInfo, SocketFactoryMock.Object))
+ .Returns(_proxyConnector);
}
protected override void TearDown()
@@ -39,6 +47,7 @@ protected override void TearDown()
base.TearDown();
_clientSocket?.Dispose();
+ _proxyConnector?.Dispose();
}
protected override void Act()
diff --git a/test/Renci.SshNet.Tests/Classes/Connection/Socks5ConnectorTest_Connect_NoAuthentication_ConnectionSucceeded.cs b/test/Renci.SshNet.Tests/Classes/Connection/Socks5ConnectorTest_Connect_NoAuthentication_ConnectionSucceeded.cs
index 2b7931103..22c222aa9 100644
--- a/test/Renci.SshNet.Tests/Classes/Connection/Socks5ConnectorTest_Connect_NoAuthentication_ConnectionSucceeded.cs
+++ b/test/Renci.SshNet.Tests/Classes/Connection/Socks5ConnectorTest_Connect_NoAuthentication_ConnectionSucceeded.cs
@@ -9,6 +9,7 @@
using Moq;
+using Renci.SshNet.Connection;
using Renci.SshNet.Common;
using Renci.SshNet.Tests.Common;
@@ -18,8 +19,10 @@ namespace Renci.SshNet.Tests.Classes.Connection
public class Socks5Connector_Connect_NoAuthentication_Succeed : Socks5ConnectorTestBase
{
private ConnectionInfo _connectionInfo;
+ private ProxyConnectionInfo _proxyConnectionInfo;
private AsyncSocketListener _proxyServer;
private Socket _clientSocket;
+ private IConnector _proxyConnector;
private List _bytesReceivedByProxy;
private Socket _actual;
@@ -27,13 +30,7 @@ protected override void SetupData()
{
base.SetupData();
- _connectionInfo = CreateConnectionInfo(new string('a', 255), new string('b', 255));
- _connectionInfo.Timeout = TimeSpan.FromMilliseconds(100);
- _bytesReceivedByProxy = new List();
-
- _clientSocket = SocketFactory.Create(SocketType.Stream, ProtocolType.Tcp);
-
- _proxyServer = new AsyncSocketListener(new IPEndPoint(IPAddress.Loopback, _connectionInfo.ProxyPort));
+ _proxyServer = new AsyncSocketListener(new IPEndPoint(IPAddress.Loopback, 0));
_proxyServer.BytesReceived += (bytesReceived, socket) =>
{
_bytesReceivedByProxy.AddRange(bytesReceived);
@@ -99,12 +96,22 @@ protected override void SetupData()
}
};
_proxyServer.Start();
+
+ _connectionInfo = CreateConnectionInfo(new string('a', 255), new string('b', 255), ((IPEndPoint)_proxyServer.ListenerEndPoint).Port);
+ _proxyConnectionInfo = (ProxyConnectionInfo)_connectionInfo.ProxyConnection;
+ _connectionInfo.Timeout = TimeSpan.FromMilliseconds(100);
+ _bytesReceivedByProxy = new List();
+
+ _clientSocket = SocketFactory.Create(SocketType.Stream, ProtocolType.Tcp);
+ _proxyConnector = ServiceFactory.CreateConnector(_proxyConnectionInfo, SocketFactoryMock.Object);
}
protected override void SetupMocks()
{
_ = SocketFactoryMock.Setup(p => p.Create(SocketType.Stream, ProtocolType.Tcp))
- .Returns(_clientSocket);
+ .Returns(_clientSocket);
+ _ = ServiceFactoryMock.Setup(p => p.CreateConnector(_proxyConnectionInfo, SocketFactoryMock.Object))
+ .Returns(_proxyConnector);
}
protected override void TearDown()
@@ -118,6 +125,8 @@ protected override void TearDown()
_clientSocket.Shutdown(SocketShutdown.Both);
_clientSocket.Dispose();
}
+
+ _proxyConnector?.Dispose();
}
protected override void Act()
diff --git a/test/Renci.SshNet.Tests/Classes/Connection/Socks5ConnectorTest_Connect_ProxySocksVersionIsNotSupported.cs b/test/Renci.SshNet.Tests/Classes/Connection/Socks5ConnectorTest_Connect_ProxySocksVersionIsNotSupported.cs
index 6a304913a..d361b21f2 100644
--- a/test/Renci.SshNet.Tests/Classes/Connection/Socks5ConnectorTest_Connect_ProxySocksVersionIsNotSupported.cs
+++ b/test/Renci.SshNet.Tests/Classes/Connection/Socks5ConnectorTest_Connect_ProxySocksVersionIsNotSupported.cs
@@ -7,6 +7,7 @@
using Moq;
+using Renci.SshNet.Connection;
using Renci.SshNet.Common;
using Renci.SshNet.Tests.Common;
@@ -16,8 +17,10 @@ namespace Renci.SshNet.Tests.Classes.Connection
public class Socks5ConnectorTest_Connect_ProxySocksVersionIsNotSupported : Socks5ConnectorTestBase
{
private ConnectionInfo _connectionInfo;
+ private ProxyConnectionInfo _proxyConnectionInfo;
private AsyncSocketListener _proxyServer;
private Socket _clientSocket;
+ private IConnector _proxyConnector;
private byte _proxySocksVersion;
private bool _disconnected;
private ProxyException _actualException;
@@ -25,27 +28,31 @@ public class Socks5ConnectorTest_Connect_ProxySocksVersionIsNotSupported : Socks
protected override void SetupData()
{
base.SetupData();
-
- _connectionInfo = CreateConnectionInfo("proxyUser", "proxyPwd");
- _connectionInfo.Timeout = TimeSpan.FromMilliseconds(100);
_proxySocksVersion = GetNotSupportedSocksVersion();
- _actualException = null;
-
- _clientSocket = SocketFactory.Create(SocketType.Stream, ProtocolType.Tcp);
- _proxyServer = new AsyncSocketListener(new IPEndPoint(IPAddress.Loopback, _connectionInfo.ProxyPort));
+ _proxyServer = new AsyncSocketListener(new IPEndPoint(IPAddress.Loopback, 0));
_proxyServer.Disconnected += socket => _disconnected = true;
_proxyServer.BytesReceived += (bytesReceived, socket) =>
{
_ = socket.Send(new byte[] { _proxySocksVersion });
};
_proxyServer.Start();
+
+ _connectionInfo = CreateConnectionInfo("proxyUser", "proxyPwd", ((IPEndPoint)_proxyServer.ListenerEndPoint).Port);
+ _proxyConnectionInfo = (ProxyConnectionInfo)_connectionInfo.ProxyConnection;
+ _connectionInfo.Timeout = TimeSpan.FromMilliseconds(100);
+ _actualException = null;
+
+ _clientSocket = SocketFactory.Create(SocketType.Stream, ProtocolType.Tcp);
+ _proxyConnector = ServiceFactory.CreateConnector(_proxyConnectionInfo, SocketFactoryMock.Object);
}
protected override void SetupMocks()
{
_ = SocketFactoryMock.Setup(p => p.Create(SocketType.Stream, ProtocolType.Tcp))
- .Returns(_clientSocket);
+ .Returns(_clientSocket);
+ _ = ServiceFactoryMock.Setup(p => p.CreateConnector(_proxyConnectionInfo, SocketFactoryMock.Object))
+ .Returns(_proxyConnector);
}
protected override void TearDown()
@@ -54,6 +61,7 @@ protected override void TearDown()
_proxyServer?.Dispose();
_clientSocket?.Dispose();
+ _proxyConnector?.Dispose();
}
protected override void Act()
diff --git a/test/Renci.SshNet.Tests/Classes/Connection/Socks5ConnectorTest_Connect_TimeoutConnectingToProxy.cs b/test/Renci.SshNet.Tests/Classes/Connection/Socks5ConnectorTest_Connect_TimeoutConnectingToProxy.cs
index 1bf0f80d6..fde2418c4 100644
--- a/test/Renci.SshNet.Tests/Classes/Connection/Socks5ConnectorTest_Connect_TimeoutConnectingToProxy.cs
+++ b/test/Renci.SshNet.Tests/Classes/Connection/Socks5ConnectorTest_Connect_TimeoutConnectingToProxy.cs
@@ -8,6 +8,7 @@
using Moq;
+using Renci.SshNet.Connection;
using Renci.SshNet.Common;
using Renci.SshNet.Tests.Common;
@@ -17,8 +18,10 @@ namespace Renci.SshNet.Tests.Classes.Connection
public class Socks5ConnectorTest_Connect_TimeoutConnectingToProxy : Socks5ConnectorTestBase
{
private ConnectionInfo _connectionInfo;
+ private ProxyConnectionInfo _proxyConnectionInfo;
private Exception _actualException;
private Socket _clientSocket;
+ private IConnector _proxyConnector;
private Stopwatch _stopWatch;
protected override void SetupData()
@@ -27,18 +30,23 @@ protected override void SetupData()
var random = new Random();
- _connectionInfo = CreateConnectionInfo("proxyUser", "proxyPwd");
+ _connectionInfo = CreateConnectionInfo("proxyUser", "proxyPwd", 8121);
_connectionInfo.Timeout = TimeSpan.FromMilliseconds(random.Next(50, 200));
+ _proxyConnectionInfo = (ProxyConnectionInfo)_connectionInfo.ProxyConnection;
+ _proxyConnectionInfo.Timeout = _connectionInfo.Timeout;
_stopWatch = new Stopwatch();
_actualException = null;
_clientSocket = SocketFactory.Create(SocketType.Stream, ProtocolType.Tcp);
+ _proxyConnector = ServiceFactory.CreateConnector(_proxyConnectionInfo, SocketFactoryMock.Object);
}
protected override void SetupMocks()
{
_ = SocketFactoryMock.Setup(p => p.Create(SocketType.Stream, ProtocolType.Tcp))
.Returns(_clientSocket);
+ _ = ServiceFactoryMock.Setup(p => p.CreateConnector(_proxyConnectionInfo, SocketFactoryMock.Object))
+ .Returns(_proxyConnector);
}
protected override void TearDown()
@@ -46,6 +54,7 @@ protected override void TearDown()
base.TearDown();
_clientSocket?.Dispose();
+ _proxyConnector?.Dispose();
}
protected override void Act()
diff --git a/test/Renci.SshNet.Tests/Classes/Connection/Socks5ConnectorTest_Connect_TimeoutConnectionReply.cs b/test/Renci.SshNet.Tests/Classes/Connection/Socks5ConnectorTest_Connect_TimeoutConnectionReply.cs
index 40d078546..81262e260 100644
--- a/test/Renci.SshNet.Tests/Classes/Connection/Socks5ConnectorTest_Connect_TimeoutConnectionReply.cs
+++ b/test/Renci.SshNet.Tests/Classes/Connection/Socks5ConnectorTest_Connect_TimeoutConnectionReply.cs
@@ -8,6 +8,7 @@
using Moq;
+using Renci.SshNet.Connection;
using Renci.SshNet.Common;
using Renci.SshNet.Tests.Common;
@@ -17,9 +18,11 @@ namespace Renci.SshNet.Tests.Classes.Connection
public class Socks5ConnectorTest_Connect_TimeoutConnectionReply : Socks5ConnectorTestBase
{
private ConnectionInfo _connectionInfo;
+ private ProxyConnectionInfo _proxyConnectionInfo;
private Exception _actualException;
private AsyncSocketListener _proxyServer;
private Socket _clientSocket;
+ private IConnector _proxyConnector;
private List _bytesReceivedByProxy;
private Stopwatch _stopWatch;
@@ -29,14 +32,20 @@ protected override void SetupData()
var random = new Random();
- _connectionInfo = CreateConnectionInfo("proxyUser", "proxyPwd");
+ _connectionInfo = CreateConnectionInfo("proxyUser", "proxyPwd", 8121);
_connectionInfo.Timeout = TimeSpan.FromMilliseconds(random.Next(50, 200));
+ _proxyConnectionInfo = (ProxyConnectionInfo)_connectionInfo.ProxyConnection;
+ _proxyConnectionInfo.Timeout = _connectionInfo.Timeout;
_stopWatch = new Stopwatch();
_bytesReceivedByProxy = new List();
_clientSocket = SocketFactory.Create(SocketType.Stream, ProtocolType.Tcp);
+ _proxyConnector = ServiceFactory.CreateConnector(_proxyConnectionInfo, SocketFactoryMock.Object);
- _proxyServer = new AsyncSocketListener(new IPEndPoint(IPAddress.Loopback, _connectionInfo.ProxyPort));
+ _proxyConnectionInfo = (ProxyConnectionInfo)_connectionInfo.ProxyConnection;
+ _proxyConnectionInfo.Timeout = _connectionInfo.Timeout;
+
+ _proxyServer = new AsyncSocketListener(new IPEndPoint(IPAddress.Loopback, _proxyConnectionInfo.Port));
_proxyServer.BytesReceived += (bytesReceived, socket) =>
{
_bytesReceivedByProxy.AddRange(bytesReceived);
@@ -59,6 +68,8 @@ protected override void SetupMocks()
{
_ = SocketFactoryMock.Setup(p => p.Create(SocketType.Stream, ProtocolType.Tcp))
.Returns(_clientSocket);
+ _ = ServiceFactoryMock.Setup(p => p.CreateConnector(_proxyConnectionInfo, SocketFactoryMock.Object))
+ .Returns(_proxyConnector);
}
protected override void TearDown()
@@ -67,6 +78,7 @@ protected override void TearDown()
_proxyServer?.Dispose();
_clientSocket?.Dispose();
+ _proxyConnector?.Dispose();
}
protected override void Act()
diff --git a/test/Renci.SshNet.Tests/Classes/Connection/Socks5ConnectorTest_Connect_UserNamePasswordAuthentication_AuthenticationFailed.cs b/test/Renci.SshNet.Tests/Classes/Connection/Socks5ConnectorTest_Connect_UserNamePasswordAuthentication_AuthenticationFailed.cs
index 0d31e3ace..00acf4e56 100644
--- a/test/Renci.SshNet.Tests/Classes/Connection/Socks5ConnectorTest_Connect_UserNamePasswordAuthentication_AuthenticationFailed.cs
+++ b/test/Renci.SshNet.Tests/Classes/Connection/Socks5ConnectorTest_Connect_UserNamePasswordAuthentication_AuthenticationFailed.cs
@@ -10,6 +10,7 @@
using Moq;
+using Renci.SshNet.Connection;
using Renci.SshNet.Common;
using Renci.SshNet.Tests.Common;
@@ -19,8 +20,10 @@ namespace Renci.SshNet.Tests.Classes.Connection
public class Socks5ConnectorTest_Connect_UserNamePasswordAuthentication_AuthenticationFailed : Socks5ConnectorTestBase
{
private ConnectionInfo _connectionInfo;
+ private ProxyConnectionInfo _proxyConnectionInfo;
private AsyncSocketListener _proxyServer;
private Socket _clientSocket;
+ private IConnector _proxyConnector;
private List _bytesReceivedByProxy;
private bool _disconnected;
private ProxyException _actualException;
@@ -29,13 +32,7 @@ protected override void SetupData()
{
base.SetupData();
- _connectionInfo = CreateConnectionInfo("aa", "bbbb");
- _connectionInfo.Timeout = TimeSpan.FromMilliseconds(100);
- _bytesReceivedByProxy = new List();
-
- _clientSocket = SocketFactory.Create(SocketType.Stream, ProtocolType.Tcp);
-
- _proxyServer = new AsyncSocketListener(new IPEndPoint(IPAddress.Loopback, _connectionInfo.ProxyPort));
+ _proxyServer = new AsyncSocketListener(new IPEndPoint(IPAddress.Loopback, 0));
_proxyServer.Disconnected += socket => _disconnected = true;
_proxyServer.BytesReceived += (bytesReceived, socket) =>
{
@@ -67,12 +64,22 @@ protected override void SetupData()
}
};
_proxyServer.Start();
+
+ _connectionInfo = CreateConnectionInfo("aa", "bbbb", ((IPEndPoint)_proxyServer.ListenerEndPoint).Port);
+ _proxyConnectionInfo = (ProxyConnectionInfo)_connectionInfo.ProxyConnection;
+ _connectionInfo.Timeout = TimeSpan.FromMilliseconds(100);
+ _bytesReceivedByProxy = new List();
+
+ _clientSocket = SocketFactory.Create(SocketType.Stream, ProtocolType.Tcp);
+ _proxyConnector = ServiceFactory.CreateConnector(_proxyConnectionInfo, SocketFactoryMock.Object);
}
protected override void SetupMocks()
{
_ = SocketFactoryMock.Setup(p => p.Create(SocketType.Stream, ProtocolType.Tcp))
.Returns(_clientSocket);
+ _ = ServiceFactoryMock.Setup(p => p.CreateConnector(_proxyConnectionInfo, SocketFactoryMock.Object))
+ .Returns(_proxyConnector);
}
protected override void TearDown()
@@ -81,6 +88,7 @@ protected override void TearDown()
_proxyServer?.Dispose();
_clientSocket?.Dispose();
+ _proxyConnector?.Dispose();
}
protected override void Act()
@@ -132,13 +140,13 @@ public void ProxyShouldHaveReceivedExpectedSocksRequest()
// Version of the negotiation
expectedSocksRequest.Add(0x01);
// Length of the username
- expectedSocksRequest.Add((byte)_connectionInfo.ProxyUsername.Length);
+ expectedSocksRequest.Add((byte)_proxyConnectionInfo.Username.Length);
// Username
- expectedSocksRequest.AddRange(Encoding.ASCII.GetBytes(_connectionInfo.ProxyUsername));
+ expectedSocksRequest.AddRange(Encoding.ASCII.GetBytes(_proxyConnectionInfo.Username));
// Length of the password
- expectedSocksRequest.Add((byte)_connectionInfo.ProxyPassword.Length);
+ expectedSocksRequest.Add((byte)_proxyConnectionInfo.Password.Length);
// Password
- expectedSocksRequest.AddRange(Encoding.ASCII.GetBytes(_connectionInfo.ProxyPassword));
+ expectedSocksRequest.AddRange(Encoding.ASCII.GetBytes(_proxyConnectionInfo.Password));
var errorText = string.Format("Expected:{0}{1}{0}but was:{0}{2}",
Environment.NewLine,
diff --git a/test/Renci.SshNet.Tests/Classes/Connection/Socks5ConnectorTest_Connect_UserNamePasswordAuthentication_ConnectionSucceeded.cs b/test/Renci.SshNet.Tests/Classes/Connection/Socks5ConnectorTest_Connect_UserNamePasswordAuthentication_ConnectionSucceeded.cs
index 50c5aad0a..00b026ed5 100644
--- a/test/Renci.SshNet.Tests/Classes/Connection/Socks5ConnectorTest_Connect_UserNamePasswordAuthentication_ConnectionSucceeded.cs
+++ b/test/Renci.SshNet.Tests/Classes/Connection/Socks5ConnectorTest_Connect_UserNamePasswordAuthentication_ConnectionSucceeded.cs
@@ -10,6 +10,7 @@
using Moq;
+using Renci.SshNet.Connection;
using Renci.SshNet.Common;
using Renci.SshNet.Tests.Common;
@@ -19,8 +20,10 @@ namespace Renci.SshNet.Tests.Classes.Connection
public class Socks5ConnectorTest_Connect_UserNamePasswordAuthentication_ConnectionSucceeded : Socks5ConnectorTestBase
{
private ConnectionInfo _connectionInfo;
+ private ProxyConnectionInfo _proxyConnectionInfo;
private AsyncSocketListener _proxyServer;
private Socket _clientSocket;
+ private IConnector _proxyConnector;
private List _bytesReceivedByProxy;
private Socket _actual;
@@ -28,13 +31,7 @@ protected override void SetupData()
{
base.SetupData();
- _connectionInfo = CreateConnectionInfo(GenerateRandomString(0, 255), GenerateRandomString(0, 255));
- _connectionInfo.Timeout = TimeSpan.FromMilliseconds(100);
- _bytesReceivedByProxy = new List();
-
- _clientSocket = SocketFactory.Create(SocketType.Stream, ProtocolType.Tcp);
-
- _proxyServer = new AsyncSocketListener(new IPEndPoint(IPAddress.Loopback, _connectionInfo.ProxyPort));
+ _proxyServer = new AsyncSocketListener(new IPEndPoint(IPAddress.Loopback, 0));
_proxyServer.BytesReceived += (bytesReceived, socket) =>
{
_bytesReceivedByProxy.AddRange(bytesReceived);
@@ -51,7 +48,7 @@ protected override void SetupData()
0x02
});
}
- else if (_bytesReceivedByProxy.Count == 4 + (1 + 1 + _connectionInfo.ProxyUsername.Length + 1 + _connectionInfo.ProxyPassword.Length))
+ else if (_bytesReceivedByProxy.Count == 4 + (1 + 1 + _proxyConnectionInfo.Username.Length + 1 + _proxyConnectionInfo.Password.Length))
{
// We received the username/password authentication request
@@ -63,7 +60,7 @@ protected override void SetupData()
0x00
});
}
- else if (_bytesReceivedByProxy.Count == 4 + (1 + 1 + _connectionInfo.ProxyUsername.Length + 1 + _connectionInfo.ProxyPassword.Length) + (1 + 1 + 1 + 1 + 4 + 2))
+ else if (_bytesReceivedByProxy.Count == 4 + (1 + 1 + _proxyConnectionInfo.Username.Length + 1 + _proxyConnectionInfo.Password.Length) + (1 + 1 + 1 + 1 + 4 + 2))
{
// We received the connection request
@@ -100,12 +97,22 @@ protected override void SetupData()
}
};
_proxyServer.Start();
+
+ _connectionInfo = CreateConnectionInfo(GenerateRandomString(0, 255), GenerateRandomString(0, 255), ((IPEndPoint)_proxyServer.ListenerEndPoint).Port);
+ _proxyConnectionInfo = (ProxyConnectionInfo)_connectionInfo.ProxyConnection;
+ _connectionInfo.Timeout = TimeSpan.FromMilliseconds(100);
+ _bytesReceivedByProxy = new List();
+
+ _clientSocket = SocketFactory.Create(SocketType.Stream, ProtocolType.Tcp);
+ _proxyConnector = ServiceFactory.CreateConnector(_proxyConnectionInfo, SocketFactoryMock.Object);
}
protected override void SetupMocks()
{
_ = SocketFactoryMock.Setup(p => p.Create(SocketType.Stream, ProtocolType.Tcp))
.Returns(_clientSocket);
+ _ = ServiceFactoryMock.Setup(p => p.CreateConnector(_proxyConnectionInfo, SocketFactoryMock.Object))
+ .Returns(_proxyConnector);
}
protected override void TearDown()
@@ -119,6 +126,8 @@ protected override void TearDown()
_clientSocket.Shutdown(SocketShutdown.Both);
_clientSocket.Dispose();
}
+
+ _proxyConnector?.Dispose();
}
protected override void Act()
@@ -167,13 +176,13 @@ public void ProxyShouldHaveReceivedExpectedSocksRequest()
// Version of the negotiation
expectedSocksRequest.Add(0x01);
// Length of the username
- expectedSocksRequest.Add((byte)_connectionInfo.ProxyUsername.Length);
+ expectedSocksRequest.Add((byte)_proxyConnectionInfo.Username.Length);
// Username
- expectedSocksRequest.AddRange(Encoding.ASCII.GetBytes(_connectionInfo.ProxyUsername));
+ expectedSocksRequest.AddRange(Encoding.ASCII.GetBytes(_proxyConnectionInfo.Username));
// Length of the password
- expectedSocksRequest.Add((byte)_connectionInfo.ProxyPassword.Length);
+ expectedSocksRequest.Add((byte)_proxyConnectionInfo.Password.Length);
// Password
- expectedSocksRequest.AddRange(Encoding.ASCII.GetBytes(_connectionInfo.ProxyPassword));
+ expectedSocksRequest.AddRange(Encoding.ASCII.GetBytes(_proxyConnectionInfo.Password));
//
// Client connection request
diff --git a/test/Renci.SshNet.Tests/Classes/Connection/Socks5ConnectorTest_Connect_UserNamePasswordAuthentication_PasswordExceedsMaximumLength.cs b/test/Renci.SshNet.Tests/Classes/Connection/Socks5ConnectorTest_Connect_UserNamePasswordAuthentication_PasswordExceedsMaximumLength.cs
index 2ef33b2b4..fa76b16dc 100644
--- a/test/Renci.SshNet.Tests/Classes/Connection/Socks5ConnectorTest_Connect_UserNamePasswordAuthentication_PasswordExceedsMaximumLength.cs
+++ b/test/Renci.SshNet.Tests/Classes/Connection/Socks5ConnectorTest_Connect_UserNamePasswordAuthentication_PasswordExceedsMaximumLength.cs
@@ -9,6 +9,7 @@
using Moq;
+using Renci.SshNet.Connection;
using Renci.SshNet.Common;
using Renci.SshNet.Tests.Common;
@@ -18,8 +19,10 @@ namespace Renci.SshNet.Tests.Classes.Connection
public class Socks5ConnectorTest_Connect_UserNamePasswordAuthentication_PasswordExceedsMaximumLength : Socks5ConnectorTestBase
{
private ConnectionInfo _connectionInfo;
+ private ProxyConnectionInfo _proxyConnectionInfo;
private AsyncSocketListener _proxyServer;
private Socket _clientSocket;
+ private IConnector _proxyConnector;
private List _bytesReceivedByProxy;
private bool _disconnected;
private ProxyException _actualException;
@@ -27,15 +30,9 @@ public class Socks5ConnectorTest_Connect_UserNamePasswordAuthentication_Password
protected override void SetupData()
{
base.SetupData();
-
- _connectionInfo = CreateConnectionInfo(new string('a', 255), new string('b', 256));
- _connectionInfo.Timeout = TimeSpan.FromMilliseconds(100);
_bytesReceivedByProxy = new List();
- _actualException = null;
-
- _clientSocket = SocketFactory.Create(SocketType.Stream, ProtocolType.Tcp);
- _proxyServer = new AsyncSocketListener(new IPEndPoint(IPAddress.Loopback, _connectionInfo.ProxyPort));
+ _proxyServer = new AsyncSocketListener(new IPEndPoint(IPAddress.Loopback, 0));
_proxyServer.Disconnected += socket => _disconnected = true;
_proxyServer.BytesReceived += (bytesReceived, socket) =>
{
@@ -54,12 +51,22 @@ protected override void SetupData()
}
};
_proxyServer.Start();
+
+ _connectionInfo = CreateConnectionInfo(new string('a', 255), new string('b', 256), ((IPEndPoint)_proxyServer.ListenerEndPoint).Port);
+ _proxyConnectionInfo = (ProxyConnectionInfo)_connectionInfo.ProxyConnection;
+ _connectionInfo.Timeout = TimeSpan.FromMilliseconds(100);
+ _actualException = null;
+
+ _clientSocket = SocketFactory.Create(SocketType.Stream, ProtocolType.Tcp);
+ _proxyConnector = ServiceFactory.CreateConnector(_proxyConnectionInfo, SocketFactoryMock.Object);
}
protected override void SetupMocks()
{
_ = SocketFactoryMock.Setup(p => p.Create(SocketType.Stream, ProtocolType.Tcp))
.Returns(_clientSocket);
+ _ = ServiceFactoryMock.Setup(p => p.CreateConnector(_proxyConnectionInfo, SocketFactoryMock.Object))
+ .Returns(_proxyConnector);
}
protected override void TearDown()
@@ -68,6 +75,7 @@ protected override void TearDown()
_proxyServer?.Dispose();
_clientSocket?.Dispose();
+ _proxyConnector?.Dispose();
}
protected override void Act()
diff --git a/test/Renci.SshNet.Tests/Classes/Connection/Socks5ConnectorTest_Connect_UserNamePasswordAuthentication_UserNameExceedsMaximumLength.cs b/test/Renci.SshNet.Tests/Classes/Connection/Socks5ConnectorTest_Connect_UserNamePasswordAuthentication_UserNameExceedsMaximumLength.cs
index 0c847390c..1a0de85b4 100644
--- a/test/Renci.SshNet.Tests/Classes/Connection/Socks5ConnectorTest_Connect_UserNamePasswordAuthentication_UserNameExceedsMaximumLength.cs
+++ b/test/Renci.SshNet.Tests/Classes/Connection/Socks5ConnectorTest_Connect_UserNamePasswordAuthentication_UserNameExceedsMaximumLength.cs
@@ -9,6 +9,7 @@
using Moq;
+using Renci.SshNet.Connection;
using Renci.SshNet.Common;
using Renci.SshNet.Tests.Common;
@@ -18,8 +19,10 @@ namespace Renci.SshNet.Tests.Classes.Connection
public class Socks5ConnectorTest_Connect_UserNamePasswordAuthentication_UserNameExceedsMaximumLength : Socks5ConnectorTestBase
{
private ConnectionInfo _connectionInfo;
+ private ProxyConnectionInfo _proxyConnectionInfo;
private AsyncSocketListener _proxyServer;
private Socket _clientSocket;
+ private IConnector _proxyConnector;
private List _bytesReceivedByProxy;
private bool _disconnected;
private ProxyException _actualException;
@@ -28,14 +31,7 @@ protected override void SetupData()
{
base.SetupData();
- _connectionInfo = CreateConnectionInfo(new string('a', 256), new string('b', 255));
- _connectionInfo.Timeout = TimeSpan.FromMilliseconds(100);
- _bytesReceivedByProxy = new List();
- _actualException = null;
-
- _clientSocket = SocketFactory.Create(SocketType.Stream, ProtocolType.Tcp);
-
- _proxyServer = new AsyncSocketListener(new IPEndPoint(IPAddress.Loopback, _connectionInfo.ProxyPort));
+ _proxyServer = new AsyncSocketListener(new IPEndPoint(IPAddress.Loopback, 0));
_proxyServer.Disconnected += socket => _disconnected = true;
_proxyServer.BytesReceived += (bytesReceived, socket) =>
{
@@ -54,12 +50,23 @@ protected override void SetupData()
}
};
_proxyServer.Start();
+
+ _connectionInfo = CreateConnectionInfo(new string('a', 256), new string('b', 255), ((IPEndPoint)_proxyServer.ListenerEndPoint).Port);
+ _proxyConnectionInfo = (ProxyConnectionInfo)_connectionInfo.ProxyConnection;
+ _connectionInfo.Timeout = TimeSpan.FromMilliseconds(100);
+ _bytesReceivedByProxy = new List();
+ _actualException = null;
+
+ _clientSocket = SocketFactory.Create(SocketType.Stream, ProtocolType.Tcp);
+ _proxyConnector = ServiceFactory.CreateConnector(_proxyConnectionInfo, SocketFactoryMock.Object);
}
protected override void SetupMocks()
{
_ = SocketFactoryMock.Setup(p => p.Create(SocketType.Stream, ProtocolType.Tcp))
- .Returns(_clientSocket);
+ .Returns(_clientSocket);
+ _ = ServiceFactoryMock.Setup(p => p.CreateConnector(_proxyConnectionInfo, SocketFactoryMock.Object))
+ .Returns(_proxyConnector);
}
protected override void TearDown()
@@ -68,6 +75,7 @@ protected override void TearDown()
_proxyServer?.Dispose();
_clientSocket?.Dispose();
+ _proxyConnector?.Dispose();
}
protected override void Act()
diff --git a/test/Renci.SshNet.Tests/Classes/ConnectionInfoTest.cs b/test/Renci.SshNet.Tests/Classes/ConnectionInfoTest.cs
index 4e143bbc6..dac49c54d 100644
--- a/test/Renci.SshNet.Tests/Classes/ConnectionInfoTest.cs
+++ b/test/Renci.SshNet.Tests/Classes/ConnectionInfoTest.cs
@@ -27,7 +27,7 @@ public void ConstructorShouldNotThrowExceptionhenProxyTypesIsNoneAndProxyHostIsN
ProxyTypes.None, proxyHost, int.Parse(Resources.PORT), Resources.USERNAME, Resources.PASSWORD,
new KeyboardInteractiveAuthenticationMethod(Resources.USERNAME));
- Assert.IsNull(connectionInfo.ProxyHost);
+ Assert.IsNull(connectionInfo.ProxyConnection?.Host);
}
[TestMethod]
@@ -70,7 +70,7 @@ public void ConstructorShouldNotThrowExceptionWhenProxyTypesIsNotNoneAndProxyHos
Resources.PASSWORD,
new KeyboardInteractiveAuthenticationMethod(Resources.USERNAME));
- Assert.AreSame(proxyHost, connectionInfo.ProxyHost);
+ Assert.AreSame(proxyHost, connectionInfo.ProxyConnection.Host);
}
[TestMethod]
@@ -132,10 +132,10 @@ public void Test_ConnectionInfo_ProxyPort_Valid()
var proxyPort = new Random().Next(IPEndPoint.MinPort, IPEndPoint.MaxPort);
var connectionInfo = new ConnectionInfo(Resources.HOST, int.Parse(Resources.PORT), Resources.USERNAME,
- ProxyTypes.None, Resources.HOST, proxyPort, Resources.USERNAME, Resources.PASSWORD,
+ ProxyTypes.Http, Resources.HOST, proxyPort, Resources.USERNAME, Resources.PASSWORD,
new KeyboardInteractiveAuthenticationMethod(Resources.USERNAME));
- Assert.AreEqual(proxyPort, connectionInfo.ProxyPort);
+ Assert.AreEqual(proxyPort, connectionInfo.ProxyConnection.Port);
}
[TestMethod]
@@ -148,7 +148,7 @@ public void ConstructorShouldNotThrowExceptionWhenProxyTypesIsNotNoneAndProxyUse
Resources.PROXY_HOST, int.Parse(Resources.PORT), proxyUsername, Resources.PASSWORD,
new KeyboardInteractiveAuthenticationMethod(Resources.USERNAME));
- Assert.IsNull(connectionInfo.ProxyUsername);
+ Assert.IsNull(((ProxyConnectionInfo)connectionInfo.ProxyConnection).Username);
}
[TestMethod]
diff --git a/test/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Dispose_PortNeverStarted.cs b/test/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Dispose_PortNeverStarted.cs
index dfd07a273..9ba7f8055 100644
--- a/test/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Dispose_PortNeverStarted.cs
+++ b/test/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Dispose_PortNeverStarted.cs
@@ -15,7 +15,7 @@ namespace Renci.SshNet.Tests.Classes
public class ForwardedPortDynamicTest_Dispose_PortNeverStarted
{
private Mock _sessionMock;
- private Mock _connectionInfoMock;
+ private Mock _connectionInfoMock;
private ForwardedPortDynamic _forwardedPort;
private IList _closingRegister;
private IList _exceptionRegister;
@@ -42,9 +42,9 @@ protected void Arrange()
{
_closingRegister = new List();
_exceptionRegister = new List();
- _endpoint = new IPEndPoint(IPAddress.Loopback, 8122);
+ _endpoint = new IPEndPoint(IPAddress.Loopback, 8121);
- _connectionInfoMock = new Mock(MockBehavior.Strict);
+ _connectionInfoMock = new Mock(MockBehavior.Strict);
_sessionMock = new Mock(MockBehavior.Strict);
_connectionInfoMock.Setup(p => p.Timeout).Returns(TimeSpan.FromSeconds(15));
diff --git a/test/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Dispose_PortStarted_ChannelBound.cs b/test/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Dispose_PortStarted_ChannelBound.cs
index 64f2ab371..4517a8a23 100644
--- a/test/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Dispose_PortStarted_ChannelBound.cs
+++ b/test/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Dispose_PortStarted_ChannelBound.cs
@@ -22,7 +22,7 @@ namespace Renci.SshNet.Tests.Classes
public class ForwardedPortDynamicTest_Dispose_PortStarted_ChannelBound
{
private Mock _sessionMock;
- private Mock _connectionInfoMock;
+ private Mock _connectionInfoMock;
private Mock _channelMock;
private ForwardedPortDynamic _forwardedPort;
private IList _closingRegister;
@@ -69,7 +69,7 @@ public void Cleanup()
private void CreateMocks()
{
- _connectionInfoMock = new Mock(MockBehavior.Strict);
+ _connectionInfoMock = new Mock(MockBehavior.Strict);
_sessionMock = new Mock(MockBehavior.Strict);
_channelMock = new Mock(MockBehavior.Strict);
}
@@ -80,7 +80,7 @@ private void SetupData()
_closingRegister = new List();
_exceptionRegister = new List();
- _endpoint = new IPEndPoint(IPAddress.Loopback, 8122);
+ _endpoint = new IPEndPoint(IPAddress.Loopback, 8121);
_remoteEndpoint = new IPEndPoint(IPAddress.Parse("193.168.1.5"), random.Next(IPEndPoint.MinPort, IPEndPoint.MaxPort));
_bindSleepTime = TimeSpan.FromMilliseconds(random.Next(100, 500));
_userName = random.Next().ToString(CultureInfo.InvariantCulture);
diff --git a/test/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Dispose_PortStarted_ChannelNotBound.cs b/test/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Dispose_PortStarted_ChannelNotBound.cs
index fb148f66e..6d4a5df7f 100644
--- a/test/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Dispose_PortStarted_ChannelNotBound.cs
+++ b/test/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Dispose_PortStarted_ChannelNotBound.cs
@@ -2,9 +2,8 @@
using System.Collections.Generic;
using System.Net;
using System.Net.Sockets;
-using System.Runtime.InteropServices;
using System.Threading;
-
+using System.Runtime.InteropServices;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
@@ -19,7 +18,7 @@ namespace Renci.SshNet.Tests.Classes
public class ForwardedPortDynamicTest_Dispose_PortStarted_ChannelNotBound
{
private Mock _sessionMock;
- private Mock _connectionInfoMock;
+ private Mock _connectionInfoMock;
private Mock _channelMock;
private ForwardedPortDynamic _forwardedPort;
private IList _closingRegister;
@@ -53,9 +52,9 @@ protected void Arrange()
{
_closingRegister = new List();
_exceptionRegister = new List();
- _endpoint = new IPEndPoint(IPAddress.Loopback, 8122);
+ _endpoint = new IPEndPoint(IPAddress.Loopback, 0);
- _connectionInfoMock = new Mock(MockBehavior.Strict);
+ _connectionInfoMock = new Mock(MockBehavior.Strict);
_sessionMock = new Mock(MockBehavior.Strict);
_channelMock = new Mock(MockBehavior.Strict);
@@ -71,6 +70,8 @@ protected void Arrange()
_forwardedPort.Session = _sessionMock.Object;
_forwardedPort.Start();
+ _endpoint.Port = (int)_forwardedPort.BoundPort;
+
_client = new Socket(_endpoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp)
{
ReceiveTimeout = 500,
diff --git a/test/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Dispose_PortStopped.cs b/test/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Dispose_PortStopped.cs
index 5e8d9c3e2..c7b839341 100644
--- a/test/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Dispose_PortStopped.cs
+++ b/test/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Dispose_PortStopped.cs
@@ -15,7 +15,7 @@ namespace Renci.SshNet.Tests.Classes
public class ForwardedPortDynamicTest_Dispose_PortStopped
{
private Mock _sessionMock;
- private Mock _connectionInfoMock;
+ private Mock _connectionInfoMock;
private ForwardedPortDynamic _forwardedPort;
private IList _closingRegister;
private IList _exceptionRegister;
@@ -42,9 +42,9 @@ protected void Arrange()
{
_closingRegister = new List();
_exceptionRegister = new List();
- _endpoint = new IPEndPoint(IPAddress.Loopback, 8122);
+ _endpoint = new IPEndPoint(IPAddress.Loopback, 0);
- _connectionInfoMock = new Mock(MockBehavior.Strict);
+ _connectionInfoMock = new Mock(MockBehavior.Strict);
_sessionMock = new Mock(MockBehavior.Strict);
_connectionInfoMock.Setup(p => p.Timeout).Returns(TimeSpan.FromSeconds(15));
@@ -56,8 +56,11 @@ protected void Arrange()
_forwardedPort.Exception += (sender, args) => _exceptionRegister.Add(args);
_forwardedPort.Session = _sessionMock.Object;
_forwardedPort.Start();
+
_forwardedPort.Stop();
+ _endpoint.Port = (int)_forwardedPort.BoundPort;
+
_closingRegister.Clear();
}
diff --git a/test/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_SessionErrorOccurred_ChannelBound.cs b/test/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_SessionErrorOccurred_ChannelBound.cs
index af699acc9..33c08fc1a 100644
--- a/test/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_SessionErrorOccurred_ChannelBound.cs
+++ b/test/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_SessionErrorOccurred_ChannelBound.cs
@@ -22,7 +22,7 @@ namespace Renci.SshNet.Tests.Classes
public class ForwardedPortDynamicTest_SessionErrorOccurred_ChannelBound
{
private Mock _sessionMock;
- private Mock _connectionInfoMock;
+ private Mock _connectionInfoMock;
private Mock _channelMock;
private ForwardedPortDynamic _forwardedPort;
private IList _closingRegister;
@@ -70,7 +70,7 @@ public void Cleanup()
private void CreateMocks()
{
- _connectionInfoMock = new Mock(MockBehavior.Strict);
+ _connectionInfoMock = new Mock(MockBehavior.Strict);
_sessionMock = new Mock(MockBehavior.Strict);
_channelMock = new Mock(MockBehavior.Strict);
}
@@ -81,7 +81,7 @@ private void SetupData()
_closingRegister = new List();
_exceptionRegister = new List();
- _endpoint = new IPEndPoint(IPAddress.Loopback, 8122);
+ _endpoint = new IPEndPoint(IPAddress.Loopback, 8121);
_remoteEndpoint = new IPEndPoint(IPAddress.Parse("193.168.1.5"), random.Next(IPEndPoint.MinPort, IPEndPoint.MaxPort));
_bindSleepTime = TimeSpan.FromMilliseconds(random.Next(100, 500));
_userName = random.Next().ToString(CultureInfo.InvariantCulture);
diff --git a/test/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Start_PortNeverStarted.cs b/test/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Start_PortNeverStarted.cs
index 0bdb35cd9..51d5c9976 100644
--- a/test/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Start_PortNeverStarted.cs
+++ b/test/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Start_PortNeverStarted.cs
@@ -16,7 +16,7 @@ namespace Renci.SshNet.Tests.Classes
public class ForwardedPortDynamicTest_Start_PortNeverStarted
{
private Mock _sessionMock;
- private Mock _connectionInfoMock;
+ private Mock _connectionInfoMock;
private Mock _channelMock;
private ForwardedPortDynamic _forwardedPort;
private IList _closingRegister;
@@ -44,9 +44,9 @@ protected void Arrange()
{
_closingRegister = new List();
_exceptionRegister = new List();
- _endpoint = new IPEndPoint(IPAddress.Loopback, 8122);
+ _endpoint = new IPEndPoint(IPAddress.Loopback, 8121);
- _connectionInfoMock = new Mock(MockBehavior.Strict);
+ _connectionInfoMock = new Mock(MockBehavior.Strict);
_sessionMock = new Mock(MockBehavior.Strict);
_channelMock = new Mock(MockBehavior.Strict);
diff --git a/test/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Start_PortStarted.cs b/test/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Start_PortStarted.cs
index 0124a8db7..3fa401c2c 100644
--- a/test/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Start_PortStarted.cs
+++ b/test/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Start_PortStarted.cs
@@ -16,7 +16,7 @@ namespace Renci.SshNet.Tests.Classes
public class ForwardedPortDynamicTest_Start_PortStarted
{
private Mock _sessionMock;
- private Mock _connectionInfoMock;
+ private Mock _connectionInfoMock;
private Mock _channelMock;
private ForwardedPortDynamic _forwardedPort;
private IList _closingRegister;
@@ -45,9 +45,9 @@ protected void Arrange()
{
_closingRegister = new List();
_exceptionRegister = new List();
- _endpoint = new IPEndPoint(IPAddress.Loopback, 8122);
+ _endpoint = new IPEndPoint(IPAddress.Loopback, 0);
- _connectionInfoMock = new Mock(MockBehavior.Strict);
+ _connectionInfoMock = new Mock(MockBehavior.Strict);
_sessionMock = new Mock(MockBehavior.Strict);
_channelMock = new Mock(MockBehavior.Strict);
@@ -61,6 +61,8 @@ protected void Arrange()
_forwardedPort.Exception += (sender, args) => _exceptionRegister.Add(args);
_forwardedPort.Session = _sessionMock.Object;
_forwardedPort.Start();
+
+ _endpoint.Port = (int)_forwardedPort.BoundPort;
}
protected void Act()
diff --git a/test/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Start_PortStopped.cs b/test/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Start_PortStopped.cs
index ea869931f..15db66bbf 100644
--- a/test/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Start_PortStopped.cs
+++ b/test/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Start_PortStopped.cs
@@ -16,7 +16,7 @@ namespace Renci.SshNet.Tests.Classes
public class ForwardedPortDynamicTest_Start_PortStopped
{
private Mock _sessionMock;
- private Mock _connectionInfoMock;
+ private Mock _connectionInfoMock;
private Mock _channelMock;
private ForwardedPortDynamic _forwardedPort;
private IList _closingRegister;
@@ -44,9 +44,9 @@ protected void Arrange()
{
_closingRegister = new List();
_exceptionRegister = new List();
- _endpoint = new IPEndPoint(IPAddress.Loopback, 8122);
+ _endpoint = new IPEndPoint(IPAddress.Loopback, 0);
- _connectionInfoMock = new Mock(MockBehavior.Strict);
+ _connectionInfoMock = new Mock(MockBehavior.Strict);
_sessionMock = new Mock(MockBehavior.Strict);
_channelMock = new Mock(MockBehavior.Strict);
@@ -60,8 +60,11 @@ protected void Arrange()
_forwardedPort.Exception += (sender, args) => _exceptionRegister.Add(args);
_forwardedPort.Session = _sessionMock.Object;
_forwardedPort.Start();
+
_forwardedPort.Stop();
+ _endpoint.Port = (int)_forwardedPort.BoundPort;
+
_closingRegister.Clear();
}
diff --git a/test/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Start_SessionNotConnected.cs b/test/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Start_SessionNotConnected.cs
index b873df284..7d3440abe 100644
--- a/test/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Start_SessionNotConnected.cs
+++ b/test/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Start_SessionNotConnected.cs
@@ -15,7 +15,7 @@ namespace Renci.SshNet.Tests.Classes
public class ForwardedPortDynamicTest_Start_SessionNotConnected
{
private Mock _sessionMock;
- private Mock _connectionInfoMock;
+ private Mock _connectionInfoMock;
private ForwardedPortDynamic _forwardedPort;
private IList _closingRegister;
private IList _exceptionRegister;
@@ -44,10 +44,10 @@ protected void Arrange()
{
_closingRegister = new List();
_exceptionRegister = new List();
- _endpoint = new IPEndPoint(IPAddress.Loopback, 8122);
+ _endpoint = new IPEndPoint(IPAddress.Loopback, 8121);
_sessionMock = new Mock(MockBehavior.Strict);
- _connectionInfoMock = new Mock(MockBehavior.Strict);
+ _connectionInfoMock = new Mock(MockBehavior.Strict);
_sessionMock.Setup(p => p.IsConnected).Returns(false);
_sessionMock.Setup(p => p.ConnectionInfo).Returns(_connectionInfoMock.Object);
diff --git a/test/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Start_SessionNull.cs b/test/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Start_SessionNull.cs
index c326c00d1..5c257d6b4 100644
--- a/test/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Start_SessionNull.cs
+++ b/test/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Start_SessionNull.cs
@@ -39,7 +39,7 @@ protected void Arrange()
{
_closingRegister = new List();
_exceptionRegister = new List();
- _endpoint = new IPEndPoint(IPAddress.Loopback, 8122);
+ _endpoint = new IPEndPoint(IPAddress.Loopback, 8121);
_forwardedPort = new ForwardedPortDynamic(_endpoint.Address.ToString(), (uint)_endpoint.Port);
_forwardedPort.Closing += (sender, args) => _closingRegister.Add(args);
diff --git a/test/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Started_SocketSendShutdownImmediately.cs b/test/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Started_SocketSendShutdownImmediately.cs
index a5e1b796c..428478f3f 100644
--- a/test/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Started_SocketSendShutdownImmediately.cs
+++ b/test/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Started_SocketSendShutdownImmediately.cs
@@ -19,7 +19,7 @@ public class ForwardedPortDynamicTest_Started_SocketSendShutdownImmediately
{
private Mock _sessionMock;
private Mock _channelMock;
- private Mock _connectionInfoMock;
+ private Mock _connectionInfoMock;
private ForwardedPortDynamic _forwardedPort;
private Socket _client;
private IList _closingRegister;
@@ -71,7 +71,7 @@ private void SetupData()
_exceptionRegister = new List();
_connectionTimeout = TimeSpan.FromSeconds(5);
_channelDisposed = new ManualResetEvent(false);
- _forwardedPortEndPoint = new IPEndPoint(IPAddress.Loopback, 8122);
+ _forwardedPortEndPoint = new IPEndPoint(IPAddress.Loopback, 8121);
_forwardedPort = new ForwardedPortDynamic((uint)_forwardedPortEndPoint.Port);
_forwardedPort.Closing += (sender, args) => _closingRegister.Add(args);
@@ -85,7 +85,7 @@ private void CreateMocks()
{
_sessionMock = new Mock(MockBehavior.Strict);
_channelMock = new Mock(MockBehavior.Strict);
- _connectionInfoMock = new Mock(MockBehavior.Strict);
+ _connectionInfoMock = new Mock(MockBehavior.Strict);
}
private void SetupMocks()
diff --git a/test/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Started_SocketVersionNotSupported.cs b/test/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Started_SocketVersionNotSupported.cs
index 9c15f0798..c10da6acb 100644
--- a/test/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Started_SocketVersionNotSupported.cs
+++ b/test/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Started_SocketVersionNotSupported.cs
@@ -19,7 +19,7 @@ public class ForwardedPortDynamicTest_Started_SocketVersionNotSupported
{
private Mock _sessionMock;
private Mock _channelMock;
- private Mock _connectionInfoMock;
+ private Mock _connectionInfoMock;
private ForwardedPortDynamic _forwardedPort;
private Socket _client;
private IList _closingRegister;
@@ -69,7 +69,7 @@ private void CreateMocks()
{
_sessionMock = new Mock(MockBehavior.Strict);
_channelMock = new Mock(MockBehavior.Strict);
- _connectionInfoMock = new Mock(MockBehavior.Strict);
+ _connectionInfoMock = new Mock(MockBehavior.Strict);
}
private void SetupMocks()
@@ -89,7 +89,7 @@ private void Arrange()
CreateMocks();
SetupMocks();
- _forwardedPort = new ForwardedPortDynamic(8122);
+ _forwardedPort = new ForwardedPortDynamic(0);
_forwardedPort.Closing += (sender, args) => _closingRegister.Add(args);
_forwardedPort.Exception += (sender, args) =>
{
@@ -99,7 +99,7 @@ private void Arrange()
_forwardedPort.Session = _sessionMock.Object;
_forwardedPort.Start();
- var endPoint = new IPEndPoint(IPAddress.Loopback, 8122);
+ var endPoint = new IPEndPoint(IPAddress.Loopback, (int)_forwardedPort.BoundPort);
_client = new Socket(endPoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
_client.Connect(endPoint);
diff --git a/test/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Stop_PortDisposed.cs b/test/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Stop_PortDisposed.cs
index 58b020323..ea30cc083 100644
--- a/test/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Stop_PortDisposed.cs
+++ b/test/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Stop_PortDisposed.cs
@@ -38,7 +38,7 @@ protected void Arrange()
{
_closingRegister = new List();
_exceptionRegister = new List();
- _endpoint = new IPEndPoint(IPAddress.Loopback, 8122);
+ _endpoint = new IPEndPoint(IPAddress.Loopback, 8121);
_forwardedPort = new ForwardedPortDynamic(_endpoint.Address.ToString(), (uint)_endpoint.Port);
_forwardedPort.Closing += (sender, args) => _closingRegister.Add(args);
diff --git a/test/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Stop_PortNeverStarted.cs b/test/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Stop_PortNeverStarted.cs
index 118b075e4..4c536e398 100644
--- a/test/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Stop_PortNeverStarted.cs
+++ b/test/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Stop_PortNeverStarted.cs
@@ -38,7 +38,7 @@ protected void Arrange()
{
_closingRegister = new List();
_exceptionRegister = new List();
- _endpoint = new IPEndPoint(IPAddress.Loopback, 8122);
+ _endpoint = new IPEndPoint(IPAddress.Loopback, 8121);
_forwardedPort = new ForwardedPortDynamic(_endpoint.Address.ToString(), (uint)_endpoint.Port);
_forwardedPort.Closing += (sender, args) => _closingRegister.Add(args);
diff --git a/test/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Stop_PortStarted_ChannelBound.cs b/test/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Stop_PortStarted_ChannelBound.cs
index 2ade89d8f..26c866d95 100644
--- a/test/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Stop_PortStarted_ChannelBound.cs
+++ b/test/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Stop_PortStarted_ChannelBound.cs
@@ -21,7 +21,7 @@ namespace Renci.SshNet.Tests.Classes
public class ForwardedPortDynamicTest_Stop_PortStarted_ChannelBound
{
private Mock _sessionMock;
- private Mock _connectionInfoMock;
+ private Mock _connectionInfoMock;
private Mock _channelMock;
private ForwardedPortDynamic _forwardedPort;
private IList _closingRegister;
@@ -68,7 +68,7 @@ public void Cleanup()
private void CreateMocks()
{
- _connectionInfoMock = new Mock(MockBehavior.Strict);
+ _connectionInfoMock = new Mock(MockBehavior.Strict);
_sessionMock = new Mock(MockBehavior.Strict);
_channelMock = new Mock(MockBehavior.Strict);
}
@@ -79,7 +79,7 @@ private void SetupData()
_closingRegister = new List();
_exceptionRegister = new List();
- _endpoint = new IPEndPoint(IPAddress.Loopback, 8122);
+ _endpoint = new IPEndPoint(IPAddress.Loopback, 8121);
_remoteEndpoint = new IPEndPoint(IPAddress.Parse("193.168.1.5"), random.Next(IPEndPoint.MinPort, IPEndPoint.MaxPort));
_bindSleepTime = TimeSpan.FromMilliseconds(random.Next(100, 500));
_userName = random.Next().ToString(CultureInfo.InvariantCulture);
diff --git a/test/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Stop_PortStarted_ChannelNotBound.cs b/test/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Stop_PortStarted_ChannelNotBound.cs
index ed6301e72..26bf9a1a5 100644
--- a/test/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Stop_PortStarted_ChannelNotBound.cs
+++ b/test/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Stop_PortStarted_ChannelNotBound.cs
@@ -2,9 +2,8 @@
using System.Collections.Generic;
using System.Net;
using System.Net.Sockets;
-using System.Runtime.InteropServices;
using System.Threading;
-
+using System.Runtime.InteropServices;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
@@ -19,7 +18,7 @@ namespace Renci.SshNet.Tests.Classes
public class ForwardedPortDynamicTest_Stop_PortStarted_ChannelNotBound
{
private Mock _sessionMock;
- private Mock _connectionInfoMock;
+ private Mock _connectionInfoMock;
private Mock