|
@@ -7,6 +7,7 @@ using System.Threading;
|
|
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
|
|
using Moq;
|
|
using Moq;
|
|
|
using Renci.SshNet.Common;
|
|
using Renci.SshNet.Common;
|
|
|
|
|
+using Renci.SshNet.Connection;
|
|
|
using Renci.SshNet.Messages.Transport;
|
|
using Renci.SshNet.Messages.Transport;
|
|
|
using Renci.SshNet.Tests.Common;
|
|
using Renci.SshNet.Tests.Common;
|
|
|
using Renci.SshNet.Tests.Properties;
|
|
using Renci.SshNet.Tests.Properties;
|
|
@@ -20,12 +21,14 @@ namespace Renci.SshNet.Tests.Classes
|
|
|
public partial class SessionTest : TestBase
|
|
public partial class SessionTest : TestBase
|
|
|
{
|
|
{
|
|
|
private Mock<IServiceFactory> _serviceFactoryMock;
|
|
private Mock<IServiceFactory> _serviceFactoryMock;
|
|
|
|
|
+ private Mock<IConnector> _connectorMock;
|
|
|
|
|
|
|
|
protected override void OnInit()
|
|
protected override void OnInit()
|
|
|
{
|
|
{
|
|
|
base.OnInit();
|
|
base.OnInit();
|
|
|
|
|
|
|
|
_serviceFactoryMock = new Mock<IServiceFactory>(MockBehavior.Strict);
|
|
_serviceFactoryMock = new Mock<IServiceFactory>(MockBehavior.Strict);
|
|
|
|
|
+ _connectorMock = new Mock<IConnector>(MockBehavior.Strict);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
[TestMethod]
|
|
[TestMethod]
|
|
@@ -84,6 +87,11 @@ namespace Renci.SshNet.Tests.Classes
|
|
|
|
|
|
|
|
using (var session = new Session(connectionInfo, _serviceFactoryMock.Object))
|
|
using (var session = new Session(connectionInfo, _serviceFactoryMock.Object))
|
|
|
{
|
|
{
|
|
|
|
|
+ _serviceFactoryMock.Setup(p => p.CreateConnector(connectionInfo))
|
|
|
|
|
+ .Returns(_connectorMock.Object);
|
|
|
|
|
+ _connectorMock.Setup(p => p.Connect(connectionInfo))
|
|
|
|
|
+ .Returns<IConnectionInfo>(c => new DirectConnector().Connect(c));
|
|
|
|
|
+
|
|
|
try
|
|
try
|
|
|
{
|
|
{
|
|
|
session.Connect();
|
|
session.Connect();
|
|
@@ -130,6 +138,11 @@ namespace Renci.SshNet.Tests.Classes
|
|
|
|
|
|
|
|
using (var session = new Session(connectionInfo, _serviceFactoryMock.Object))
|
|
using (var session = new Session(connectionInfo, _serviceFactoryMock.Object))
|
|
|
{
|
|
{
|
|
|
|
|
+ _serviceFactoryMock.Setup(p => p.CreateConnector(connectionInfo))
|
|
|
|
|
+ .Returns(_connectorMock.Object);
|
|
|
|
|
+ _connectorMock.Setup(p => p.Connect(connectionInfo))
|
|
|
|
|
+ .Returns<IConnectionInfo>(c => new DirectConnector().Connect(c));
|
|
|
|
|
+
|
|
|
try
|
|
try
|
|
|
{
|
|
{
|
|
|
session.Connect();
|
|
session.Connect();
|
|
@@ -146,7 +159,6 @@ namespace Renci.SshNet.Tests.Classes
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
[TestMethod]
|
|
[TestMethod]
|
|
|
public void ConnectShouldSupportProtocolIdentificationStringThatDoesNotEndWithCrlf()
|
|
public void ConnectShouldSupportProtocolIdentificationStringThatDoesNotEndWithCrlf()
|
|
|
{
|
|
{
|
|
@@ -166,6 +178,11 @@ namespace Renci.SshNet.Tests.Classes
|
|
|
|
|
|
|
|
using (var session = new Session(connectionInfo, _serviceFactoryMock.Object))
|
|
using (var session = new Session(connectionInfo, _serviceFactoryMock.Object))
|
|
|
{
|
|
{
|
|
|
|
|
+ _serviceFactoryMock.Setup(p => p.CreateConnector(connectionInfo))
|
|
|
|
|
+ .Returns(_connectorMock.Object);
|
|
|
|
|
+ _connectorMock.Setup(p => p.Connect(connectionInfo))
|
|
|
|
|
+ .Returns<IConnectionInfo>(c => new DirectConnector().Connect(c));
|
|
|
|
|
+
|
|
|
try
|
|
try
|
|
|
{
|
|
{
|
|
|
session.Connect();
|
|
session.Connect();
|
|
@@ -199,8 +216,15 @@ namespace Renci.SshNet.Tests.Classes
|
|
|
};
|
|
};
|
|
|
serverStub.Start();
|
|
serverStub.Start();
|
|
|
|
|
|
|
|
- using (var session = new Session(CreateConnectionInfo(serverEndPoint, TimeSpan.FromMilliseconds(500)), _serviceFactoryMock.Object))
|
|
|
|
|
|
|
+ var connectionInfo = CreateConnectionInfo(serverEndPoint, TimeSpan.FromMilliseconds(500));
|
|
|
|
|
+
|
|
|
|
|
+ using (var session = new Session(connectionInfo, _serviceFactoryMock.Object))
|
|
|
{
|
|
{
|
|
|
|
|
+ _serviceFactoryMock.Setup(p => p.CreateConnector(connectionInfo))
|
|
|
|
|
+ .Returns(_connectorMock.Object);
|
|
|
|
|
+ _connectorMock.Setup(p => p.Connect(connectionInfo))
|
|
|
|
|
+ .Returns<IConnectionInfo>(c => new DirectConnector().Connect(c));
|
|
|
|
|
+
|
|
|
try
|
|
try
|
|
|
{
|
|
{
|
|
|
session.Connect();
|
|
session.Connect();
|
|
@@ -237,8 +261,15 @@ namespace Renci.SshNet.Tests.Classes
|
|
|
};
|
|
};
|
|
|
serverStub.Start();
|
|
serverStub.Start();
|
|
|
|
|
|
|
|
- using (var session = new Session(CreateConnectionInfo(serverEndPoint, TimeSpan.FromSeconds(5)), _serviceFactoryMock.Object))
|
|
|
|
|
|
|
+ var connectionInfo = CreateConnectionInfo(serverEndPoint, TimeSpan.FromSeconds(5));
|
|
|
|
|
+
|
|
|
|
|
+ using (var session = new Session(connectionInfo, _serviceFactoryMock.Object))
|
|
|
{
|
|
{
|
|
|
|
|
+ _serviceFactoryMock.Setup(p => p.CreateConnector(connectionInfo))
|
|
|
|
|
+ .Returns(_connectorMock.Object);
|
|
|
|
|
+ _connectorMock.Setup(p => p.Connect(connectionInfo))
|
|
|
|
|
+ .Returns<IConnectionInfo>(c => new DirectConnector().Connect(c));
|
|
|
|
|
+
|
|
|
try
|
|
try
|
|
|
{
|
|
{
|
|
|
session.Connect();
|
|
session.Connect();
|
|
@@ -263,8 +294,15 @@ namespace Renci.SshNet.Tests.Classes
|
|
|
};
|
|
};
|
|
|
serverStub.Start();
|
|
serverStub.Start();
|
|
|
|
|
|
|
|
- using (var session = new Session(CreateConnectionInfo(serverEndPoint, TimeSpan.FromSeconds(5)), _serviceFactoryMock.Object))
|
|
|
|
|
|
|
+ var connectionInfo = CreateConnectionInfo(serverEndPoint, TimeSpan.FromSeconds(5));
|
|
|
|
|
+
|
|
|
|
|
+ using (var session = new Session(connectionInfo, _serviceFactoryMock.Object))
|
|
|
{
|
|
{
|
|
|
|
|
+ _serviceFactoryMock.Setup(p => p.CreateConnector(connectionInfo))
|
|
|
|
|
+ .Returns(_connectorMock.Object);
|
|
|
|
|
+ _connectorMock.Setup(p => p.Connect(connectionInfo))
|
|
|
|
|
+ .Returns<IConnectionInfo>(c => new DirectConnector().Connect(c));
|
|
|
|
|
+
|
|
|
try
|
|
try
|
|
|
{
|
|
{
|
|
|
session.Connect();
|
|
session.Connect();
|
|
@@ -290,8 +328,15 @@ namespace Renci.SshNet.Tests.Classes
|
|
|
};
|
|
};
|
|
|
serverStub.Start();
|
|
serverStub.Start();
|
|
|
|
|
|
|
|
- using (var session = new Session(CreateConnectionInfo(serverEndPoint, TimeSpan.FromSeconds(5)), _serviceFactoryMock.Object))
|
|
|
|
|
|
|
+ var connectionInfo = CreateConnectionInfo(serverEndPoint, TimeSpan.FromSeconds(5));
|
|
|
|
|
+
|
|
|
|
|
+ using (var session = new Session(connectionInfo, _serviceFactoryMock.Object))
|
|
|
{
|
|
{
|
|
|
|
|
+ _serviceFactoryMock.Setup(p => p.CreateConnector(connectionInfo))
|
|
|
|
|
+ .Returns(_connectorMock.Object);
|
|
|
|
|
+ _connectorMock.Setup(p => p.Connect(connectionInfo))
|
|
|
|
|
+ .Returns<IConnectionInfo>(c => new DirectConnector().Connect(c));
|
|
|
|
|
+
|
|
|
try
|
|
try
|
|
|
{
|
|
{
|
|
|
session.Connect();
|
|
session.Connect();
|
|
@@ -313,6 +358,11 @@ namespace Renci.SshNet.Tests.Classes
|
|
|
new KeyboardInteractiveAuthenticationMethod("user"));
|
|
new KeyboardInteractiveAuthenticationMethod("user"));
|
|
|
var session = new Session(connectionInfo, _serviceFactoryMock.Object);
|
|
var session = new Session(connectionInfo, _serviceFactoryMock.Object);
|
|
|
|
|
|
|
|
|
|
+ _serviceFactoryMock.Setup(p => p.CreateConnector(connectionInfo))
|
|
|
|
|
+ .Returns(_connectorMock.Object);
|
|
|
|
|
+ _connectorMock.Setup(p => p.Connect(connectionInfo))
|
|
|
|
|
+ .Returns<IConnectionInfo>(c => new DirectConnector().Connect(c));
|
|
|
|
|
+
|
|
|
try
|
|
try
|
|
|
{
|
|
{
|
|
|
session.Connect();
|
|
session.Connect();
|
|
@@ -331,6 +381,11 @@ namespace Renci.SshNet.Tests.Classes
|
|
|
"proxyUser", "proxyPwd", new KeyboardInteractiveAuthenticationMethod("user"));
|
|
"proxyUser", "proxyPwd", new KeyboardInteractiveAuthenticationMethod("user"));
|
|
|
var session = new Session(connectionInfo, _serviceFactoryMock.Object);
|
|
var session = new Session(connectionInfo, _serviceFactoryMock.Object);
|
|
|
|
|
|
|
|
|
|
+ _serviceFactoryMock.Setup(p => p.CreateConnector(connectionInfo))
|
|
|
|
|
+ .Returns(_connectorMock.Object);
|
|
|
|
|
+ _connectorMock.Setup(p => p.Connect(connectionInfo))
|
|
|
|
|
+ .Returns<IConnectionInfo>(c => new HttpConnector().Connect(c));
|
|
|
|
|
+
|
|
|
try
|
|
try
|
|
|
{
|
|
{
|
|
|
session.Connect();
|
|
session.Connect();
|
|
@@ -349,6 +404,11 @@ namespace Renci.SshNet.Tests.Classes
|
|
|
new KeyboardInteractiveAuthenticationMethod(Resources.USERNAME));
|
|
new KeyboardInteractiveAuthenticationMethod(Resources.USERNAME));
|
|
|
var session = new Session(connectionInfo, _serviceFactoryMock.Object);
|
|
var session = new Session(connectionInfo, _serviceFactoryMock.Object);
|
|
|
|
|
|
|
|
|
|
+ _serviceFactoryMock.Setup(p => p.CreateConnector(connectionInfo))
|
|
|
|
|
+ .Returns(_connectorMock.Object);
|
|
|
|
|
+ _connectorMock.Setup(p => p.Connect(connectionInfo))
|
|
|
|
|
+ .Returns<IConnectionInfo>(c => new DirectConnector().Connect(c));
|
|
|
|
|
+
|
|
|
try
|
|
try
|
|
|
{
|
|
{
|
|
|
session.Connect();
|
|
session.Connect();
|
|
@@ -377,6 +437,11 @@ namespace Renci.SshNet.Tests.Classes
|
|
|
new KeyboardInteractiveAuthenticationMethod(Resources.USERNAME));
|
|
new KeyboardInteractiveAuthenticationMethod(Resources.USERNAME));
|
|
|
var session = new Session(connectionInfo, _serviceFactoryMock.Object);
|
|
var session = new Session(connectionInfo, _serviceFactoryMock.Object);
|
|
|
|
|
|
|
|
|
|
+ _serviceFactoryMock.Setup(p => p.CreateConnector(connectionInfo))
|
|
|
|
|
+ .Returns(_connectorMock.Object);
|
|
|
|
|
+ _connectorMock.Setup(p => p.Connect(connectionInfo))
|
|
|
|
|
+ .Returns<IConnectionInfo>(c => new DirectConnector().Connect(c));
|
|
|
|
|
+
|
|
|
try
|
|
try
|
|
|
{
|
|
{
|
|
|
session.Connect();
|
|
session.Connect();
|