Skip to content

Commit

Permalink
Merge remote-tracking branch 'refs/remotes/origin/develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
drieseng committed Oct 7, 2017
2 parents cdf50d2 + 7a19bcd commit 6445546
Show file tree
Hide file tree
Showing 38 changed files with 2,152 additions and 228 deletions.
4 changes: 2 additions & 2 deletions build/nuget/SSH.NET.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
<metadata>
<id>SSH.NET</id>
<version>2016.1.0-beta3</version>
<version>2016.1.0-beta4</version>
<title>SSH.NET</title>
<authors>Renci</authors>
<owners>olegkap,drieseng</owners>
<licenseUrl>https://github.com/sshnet/SSH.NET/blob/master/LICENSE</licenseUrl>
<projectUrl>https://github.com/sshnet/SSH.NET/</projectUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>SSH.NET is a Secure Shell (SSH) library for .NET, optimized for parallelism and with broad framework support.</description>
<releaseNotes>https://github.com/sshnet/SSH.NET/releases/tag/2016.1.0-beta3</releaseNotes>
<releaseNotes>https://github.com/sshnet/SSH.NET/releases/tag/2016.1.0-beta4</releaseNotes>
<summary>A Secure Shell (SSH) library for .NET, optimized for parallelism.</summary>
<copyright>2012-2017, RENCI</copyright>
<language>en-US</language>
Expand Down
26 changes: 25 additions & 1 deletion src/Renci.SshNet.Tests.NET35/Renci.SshNet.Tests.NET35.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -213,9 +213,15 @@
<Compile Include="..\Renci.SshNet.Tests\Classes\CipherInfoTest.cs">
<Link>Classes\CipherInfoTest.cs</Link>
</Compile>
<Compile Include="..\Renci.SshNet.Tests\Classes\ClientAuthenticationTest.cs">
<Link>Classes\ClientAuthenticationTest.cs</Link>
</Compile>
<Compile Include="..\Renci.SshNet.Tests\Classes\ClientAuthenticationTestBase.cs">
<Link>Classes\ClientAuthenticationTestBase.cs</Link>
</Compile>
<Compile Include="..\Renci.SshNet.Tests\Classes\ClientAuthenticationTest_Failure_MultiList_AllAllowedAuthenticationsHaveReachedPartialSuccessLimit.cs">
<Link>Classes\ClientAuthenticationTest_Failure_MultiList_AllAllowedAuthenticationsHaveReachedPartialSuccessLimit.cs</Link>
</Compile>
<Compile Include="..\Renci.SshNet.Tests\Classes\ClientAuthenticationTest_Failure_SingleList_AuthenticationMethodFailed.cs">
<Link>Classes\ClientAuthenticationTest_Failure_SingleList_AuthenticationMethodFailed.cs</Link>
</Compile>
Expand All @@ -225,6 +231,21 @@
<Compile Include="..\Renci.SshNet.Tests\Classes\ClientAuthenticationTest_Success_MultiList_DifferentAllowedAuthenticationsAfterPartialSuccess.cs">
<Link>Classes\ClientAuthenticationTest_Success_MultiList_DifferentAllowedAuthenticationsAfterPartialSuccess.cs</Link>
</Compile>
<Compile Include="..\Renci.SshNet.Tests\Classes\ClientAuthenticationTest_Success_MultiList_PartialSuccessLimitReachedFollowedByFailureInAlternateBranch.cs">
<Link>Classes\ClientAuthenticationTest_Success_MultiList_PartialSuccessLimitReachedFollowedByFailureInAlternateBranch.cs</Link>
</Compile>
<Compile Include="..\Renci.SshNet.Tests\Classes\ClientAuthenticationTest_Success_MultiList_PartialSuccessLimitReachedFollowedByFailureInAlternateBranch2.cs">
<Link>Classes\ClientAuthenticationTest_Success_MultiList_PartialSuccessLimitReachedFollowedByFailureInAlternateBranch2.cs</Link>
</Compile>
<Compile Include="..\Renci.SshNet.Tests\Classes\ClientAuthenticationTest_Success_MultiList_PartialSuccessLimitReachedFollowedByFailureInSameBranch.cs">
<Link>Classes\ClientAuthenticationTest_Success_MultiList_PartialSuccessLimitReachedFollowedByFailureInSameBranch.cs</Link>
</Compile>
<Compile Include="..\Renci.SshNet.Tests\Classes\ClientAuthenticationTest_Success_MultiList_PartialSuccessLimitReachedFollowedBySuccessInAlternateBranch.cs">
<Link>Classes\ClientAuthenticationTest_Success_MultiList_PartialSuccessLimitReachedFollowedBySuccessInAlternateBranch.cs</Link>
</Compile>
<Compile Include="..\Renci.SshNet.Tests\Classes\ClientAuthenticationTest_Success_MultiList_PartialSuccessLimitReachedFollowedBySuccessInSameBranch.cs">
<Link>Classes\ClientAuthenticationTest_Success_MultiList_PartialSuccessLimitReachedFollowedBySuccessInSameBranch.cs</Link>
</Compile>
<Compile Include="..\Renci.SshNet.Tests\Classes\ClientAuthenticationTest_Success_MultiList_SameAllowedAuthenticationsAfterPartialSuccess.cs">
<Link>Classes\ClientAuthenticationTest_Success_MultiList_SameAllowedAuthenticationsAfterPartialSuccess.cs</Link>
</Compile>
Expand All @@ -234,6 +255,9 @@
<Compile Include="..\Renci.SshNet.Tests\Classes\ClientAuthenticationTest_Success_SingleList_SameAllowedAuthenticationAfterPartialSuccess.cs">
<Link>Classes\ClientAuthenticationTest_Success_SingleList_SameAllowedAuthenticationAfterPartialSuccess.cs</Link>
</Compile>
<Compile Include="..\Renci.SshNet.Tests\Classes\ClientAuthenticationTest_Success_SingleList_SameAllowedAuthenticationAfterPartialSuccess_PartialSuccessLimitReached.cs">
<Link>Classes\ClientAuthenticationTest_Success_SingleList_SameAllowedAuthenticationAfterPartialSuccess_PartialSuccessLimitReached.cs</Link>
</Compile>
<Compile Include="..\Renci.SshNet.Tests\Classes\CommandAsyncResultTest.cs">
<Link>Classes\CommandAsyncResultTest.cs</Link>
</Compile>
Expand Down Expand Up @@ -1668,7 +1692,7 @@
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ProjectExtensions>
<VisualStudio>
<UserProperties ProjectLinkReference="c45379b9-17b1-4e89-bc2e-6d41726413e8" ProjectLinkerExcludeFilter="\\?desktop(\\.*)?$;\\?silverlight(\\.*)?$;\.desktop;\.silverlight;\.xaml;^service references(\\.*)?$;\.clientconfig;^web references(\\.*)?$" />
<UserProperties ProjectLinkerExcludeFilter="\\?desktop(\\.*)?$;\\?silverlight(\\.*)?$;\.desktop;\.silverlight;\.xaml;^service references(\\.*)?$;\.clientconfig;^web references(\\.*)?$" ProjectLinkReference="c45379b9-17b1-4e89-bc2e-6d41726413e8" />
</VisualStudio>
</ProjectExtensions>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
using System;
using System.Collections.Generic;
using System.Threading;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
using Renci.SshNet.Channels;
using Renci.SshNet.Common;
using Renci.SshNet.Messages.Connection;
using Renci.SshNet.Tests.Common;

namespace Renci.SshNet.Tests.Classes.Channels
{
[TestClass]
public class ChannelSessionTest_Dispose_SessionIsConnectedAndChannelIsOpen_ChannelCloseAndChannelEofReceived_DisposeInEventHandler
{
private Mock<ISession> _sessionMock;
private uint _localChannelNumber;
private uint _localWindowSize;
private uint _localPacketSize;
private uint _remoteChannelNumber;
private uint _remoteWindowSize;
private uint _remotePacketSize;
private IList<ChannelEventArgs> _channelClosedRegister;
private List<ExceptionEventArgs> _channelExceptionRegister;
private ChannelSession _channel;
private Mock<IConnectionInfo> _connectionInfoMock;
private MockSequence _sequence;
private SemaphoreLight _sessionSemaphore;
private int _initialSessionSemaphoreCount;

[TestInitialize]
public void Initialize()
{
Arrange();
Act();
}

private void Arrange()
{
var random = new Random();
_localChannelNumber = (uint)random.Next(0, int.MaxValue);
_localWindowSize = (uint)random.Next(0, int.MaxValue);
_localPacketSize = (uint)random.Next(0, int.MaxValue);
_remoteChannelNumber = (uint)random.Next(0, int.MaxValue);
_remoteWindowSize = (uint)random.Next(0, int.MaxValue);
_remotePacketSize = (uint)random.Next(0, int.MaxValue);
_channelClosedRegister = new List<ChannelEventArgs>();
_channelExceptionRegister = new List<ExceptionEventArgs>();
_initialSessionSemaphoreCount = random.Next(10, 20);
_sessionSemaphore = new SemaphoreLight(_initialSessionSemaphoreCount);

_sessionMock = new Mock<ISession>(MockBehavior.Strict);
_connectionInfoMock = new Mock<IConnectionInfo>(MockBehavior.Strict);

_sequence = new MockSequence();
_sessionMock.InSequence(_sequence).Setup(p => p.ConnectionInfo).Returns(_connectionInfoMock.Object);
_connectionInfoMock.InSequence(_sequence).Setup(p => p.RetryAttempts).Returns(1);
_sessionMock.Setup(p => p.SessionSemaphore).Returns(_sessionSemaphore);
_sessionMock.InSequence(_sequence)
.Setup(
p =>
p.SendMessage(
It.Is<ChannelOpenMessage>(
m =>
m.LocalChannelNumber == _localChannelNumber &&
m.InitialWindowSize == _localWindowSize && m.MaximumPacketSize == _localPacketSize &&
m.Info is SessionChannelOpenInfo)));
_sessionMock.InSequence(_sequence)
.Setup(p => p.WaitOnHandle(It.IsNotNull<WaitHandle>()))
.Callback<WaitHandle>(
w =>
{
_sessionMock.Raise(
s => s.ChannelOpenConfirmationReceived += null,
new MessageEventArgs<ChannelOpenConfirmationMessage>(
new ChannelOpenConfirmationMessage(
_localChannelNumber,
_remoteWindowSize,
_remotePacketSize,
_remoteChannelNumber)));
w.WaitOne();
});
_sessionMock.InSequence(_sequence).Setup(p => p.IsConnected).Returns(true);
_sessionMock.InSequence(_sequence)
.Setup(p => p.TrySendMessage(It.Is<ChannelCloseMessage>(c => c.LocalChannelNumber == _remoteChannelNumber)))
.Returns(true);
_sessionMock.InSequence(_sequence)
.Setup(s => s.WaitOnHandle(It.IsNotNull<EventWaitHandle>()))
.Callback<WaitHandle>(w => w.WaitOne());

_channel = new ChannelSession(_sessionMock.Object, _localChannelNumber, _localWindowSize, _localPacketSize);
_channel.Closed += (sender, args) =>
{
_channelClosedRegister.Add(args);
_channel.Dispose();
};
_channel.Exception += (sender, args) => _channelExceptionRegister.Add(args);
_channel.Open();

_sessionMock.Raise(p => p.ChannelEofReceived += null,
new MessageEventArgs<ChannelEofMessage>(new ChannelEofMessage(_localChannelNumber)));
_sessionMock.Raise(p => p.ChannelCloseReceived += null,
new MessageEventArgs<ChannelCloseMessage>(new ChannelCloseMessage(_localChannelNumber)));
}

private void Act()
{
_channel.Dispose();
}

[TestMethod]
public void CurrentCountOfSessionSemaphoreShouldBeEqualToInitialCount()
{
Assert.AreEqual(_initialSessionSemaphoreCount, _sessionSemaphore.CurrentCount);
}

[TestMethod]
public void ExceptionShouldNeverHaveFired()
{
Assert.AreEqual(0, _channelExceptionRegister.Count, _channelExceptionRegister.AsString());
}

[TestMethod]
public void ClosedEventShouldHaveFiredOnce()
{
Assert.AreEqual(1, _channelClosedRegister.Count);
Assert.AreEqual(_localChannelNumber, _channelClosedRegister[0].ChannelNumber);
}

[TestMethod]
public void IsOpenShouldReturnFalse()
{
Assert.IsFalse(_channel.IsOpen);
}
}
}
61 changes: 58 additions & 3 deletions src/Renci.SshNet.Tests/Classes/ClientAuthenticationTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,68 @@ public class ClientAuthenticationTest
[TestInitialize]
public void Init()
{
_clientAuthentication = new ClientAuthentication();
_clientAuthentication = new ClientAuthentication(1);
}

[TestMethod]
public void Ctor_PartialSuccessLimit_Zero()
{
const int partialSuccessLimit = 0;

try
{
new ClientAuthentication(partialSuccessLimit);
Assert.Fail();
}
catch (ArgumentOutOfRangeException ex)
{
Assert.IsNull(ex.InnerException);
Assert.AreEqual(string.Format("Cannot be less than one.{0}Parameter name: {1}", Environment.NewLine, ex.ParamName), ex.Message);
Assert.AreEqual("partialSuccessLimit", ex.ParamName);
}
}

[TestMethod]
public void Ctor_PartialSuccessLimit_Negative()
{
var partialSuccessLimit = new Random().Next(int.MinValue, -1);

try
{
new ClientAuthentication(partialSuccessLimit);
Assert.Fail();
}
catch (ArgumentOutOfRangeException ex)
{
Assert.IsNull(ex.InnerException);
Assert.AreEqual(string.Format("Cannot be less than one.{0}Parameter name: {1}", Environment.NewLine, ex.ParamName), ex.Message);
Assert.AreEqual("partialSuccessLimit", ex.ParamName);
}
}

[TestMethod]
public void Ctor_PartialSuccessLimit_One()
{
const int partialSuccessLimit = 1;

var clientAuthentication = new ClientAuthentication(partialSuccessLimit);
Assert.AreEqual(partialSuccessLimit, clientAuthentication.PartialSuccessLimit);
}

[TestMethod]
public void Ctor_PartialSuccessLimit_MaxValue()
{
const int partialSuccessLimit = int.MaxValue;

var clientAuthentication = new ClientAuthentication(partialSuccessLimit);
Assert.AreEqual(partialSuccessLimit, clientAuthentication.PartialSuccessLimit);
}


[TestMethod]
public void AuthenticateShouldThrowArgumentNullExceptionWhenConnectionInfoIsNull()
{
IConnectionInfoInternal connectionInfo = null;
const IConnectionInfoInternal connectionInfo = null;
var session = new Mock<ISession>(MockBehavior.Strict).Object;

try
Expand All @@ -37,7 +92,7 @@ public void AuthenticateShouldThrowArgumentNullExceptionWhenConnectionInfoIsNull
public void AuthenticateShouldThrowArgumentNullExceptionWhenSessionIsNull()
{
var connectionInfo = new Mock<IConnectionInfoInternal>(MockBehavior.Strict).Object;
ISession session = null;
const ISession session = null;

try
{
Expand Down
19 changes: 11 additions & 8 deletions src/Renci.SshNet.Tests/Classes/ClientAuthenticationTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ public abstract class ClientAuthenticationTestBase : TestBase
internal Mock<IAuthenticationMethod> PasswordAuthenticationMethodMock { get; private set; }
internal Mock<IAuthenticationMethod> PublicKeyAuthenticationMethodMock { get; private set; }
internal Mock<IAuthenticationMethod> KeyboardInteractiveAuthenticationMethodMock { get; private set; }
internal ClientAuthentication ClientAuthentication { get; private set; }

protected abstract void SetupData();

protected void CreateMocks()
{
Expand All @@ -27,18 +28,20 @@ protected void CreateMocks()

protected abstract void SetupMocks();

protected virtual void Arrange()
{
SetupData();
CreateMocks();
SetupMocks();
}

protected abstract void Act();

protected override void OnInit()
protected sealed override void OnInit()
{
base.OnInit();

// Arrange
CreateMocks();
SetupMocks();
ClientAuthentication = new ClientAuthentication();

// Act
Arrange();
Act();
}

Expand Down
Loading

0 comments on commit 6445546

Please sign in to comment.