Skip to content

Commit e434f97

Browse files
committed
Renamed Quote transformation and corresponding class to ShellQuote.
Added DoubleQuote transformation. Modified default remote path transformation for ScpClient to DoubleQuote.
1 parent 7dde512 commit e434f97

21 files changed

+689
-317
lines changed

src/Renci.SshNet.NET35/Renci.SshNet.NET35.csproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -581,14 +581,14 @@
581581
<Compile Include="..\Renci.SshNet\ProxyTypes.cs">
582582
<Link>ProxyTypes.cs</Link>
583583
</Compile>
584-
<Compile Include="..\Renci.SshNet\RemotePathEscapeTransformation.cs">
585-
<Link>RemotePathEscapeTransformation.cs</Link>
584+
<Compile Include="..\Renci.SshNet\RemotePathDoubleQuoteTransformation.cs">
585+
<Link>RemotePathDoubleQuoteTransformation.cs</Link>
586586
</Compile>
587587
<Compile Include="..\Renci.SshNet\RemotePathNoneTransformation.cs">
588588
<Link>RemotePathNoneTransformation.cs</Link>
589589
</Compile>
590-
<Compile Include="..\Renci.SshNet\RemotePathQuoteTransformation.cs">
591-
<Link>RemotePathQuoteTransformation.cs</Link>
590+
<Compile Include="..\Renci.SshNet\RemotePathShellQuoteTransformation.cs">
591+
<Link>RemotePathShellQuoteTransformation.cs</Link>
592592
</Compile>
593593
<Compile Include="..\Renci.SshNet\RemotePathTransformation.cs">
594594
<Link>RemotePathTransformation.cs</Link>

src/Renci.SshNet.Tests.NET35/Renci.SshNet.Tests.NET35.csproj

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -768,6 +768,9 @@
768768
<Compile Include="..\Renci.SshNet.Tests\Classes\ScpClientTest.cs">
769769
<Link>Classes\ScpClientTest.cs</Link>
770770
</Compile>
771+
<Compile Include="..\Renci.SshNet.Tests\Classes\ScpClientTestBase.cs">
772+
<Link>Classes\ScpClientTestBase.cs</Link>
773+
</Compile>
771774
<Compile Include="..\Renci.SshNet.Tests\Classes\ScpClientTest_Download_PathAndDirectoryInfo_SendExecRequestReturnsFalse.cs">
772775
<Link>Classes\ScpClientTest_Download_PathAndDirectoryInfo_SendExecRequestReturnsFalse.cs</Link>
773776
</Compile>
@@ -1584,7 +1587,7 @@
15841587
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
15851588
<ProjectExtensions>
15861589
<VisualStudio>
1587-
<UserProperties ProjectLinkReference="c45379b9-17b1-4e89-bc2e-6d41726413e8" ProjectLinkerExcludeFilter="\\?desktop(\\.*)?$;\\?silverlight(\\.*)?$;\.desktop;\.silverlight;\.xaml;^service references(\\.*)?$;\.clientconfig;^web references(\\.*)?$" />
1590+
<UserProperties ProjectLinkerExcludeFilter="\\?desktop(\\.*)?$;\\?silverlight(\\.*)?$;\.desktop;\.silverlight;\.xaml;^service references(\\.*)?$;\.clientconfig;^web references(\\.*)?$" ProjectLinkReference="c45379b9-17b1-4e89-bc2e-6d41726413e8" />
15881591
</VisualStudio>
15891592
</ProjectExtensions>
15901593
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.

src/Renci.SshNet.Tests/Classes/ScpClientTest.cs

Lines changed: 228 additions & 78 deletions
Large diffs are not rendered by default.
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
using Microsoft.VisualStudio.TestTools.UnitTesting;
2+
using Moq;
3+
using Renci.SshNet.Channels;
4+
using Renci.SshNet.Common;
5+
6+
namespace Renci.SshNet.Tests.Classes
7+
{
8+
public abstract class ScpClientTestBase
9+
{
10+
internal Mock<IServiceFactory> _serviceFactoryMock;
11+
internal Mock<IRemotePathTransformation> _remotePathTransformationMock;
12+
internal Mock<ISession> _sessionMock;
13+
internal Mock<IChannelSession> _channelSessionMock;
14+
internal Mock<PipeStream> _pipeStreamMock;
15+
16+
protected abstract void SetupData();
17+
18+
protected void CreateMocks()
19+
{
20+
_serviceFactoryMock = new Mock<IServiceFactory>(MockBehavior.Strict);
21+
_remotePathTransformationMock = new Mock<IRemotePathTransformation>(MockBehavior.Strict);
22+
_sessionMock = new Mock<ISession>(MockBehavior.Strict);
23+
_channelSessionMock = new Mock<IChannelSession>(MockBehavior.Strict);
24+
_pipeStreamMock = new Mock<PipeStream>(MockBehavior.Strict);
25+
}
26+
27+
protected abstract void SetupMocks();
28+
29+
protected virtual void Arrange()
30+
{
31+
SetupData();
32+
CreateMocks();
33+
SetupMocks();
34+
}
35+
36+
[TestInitialize]
37+
public void Initialize()
38+
{
39+
Arrange();
40+
Act();
41+
}
42+
43+
protected abstract void Act();
44+
}
45+
}

src/Renci.SshNet.Tests/Classes/ScpClientTest_Download_PathAndDirectoryInfo_SendExecRequestReturnsFalse.cs

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,66 +4,66 @@
44
using System.IO;
55
using Microsoft.VisualStudio.TestTools.UnitTesting;
66
using Moq;
7-
using Renci.SshNet.Channels;
87
using Renci.SshNet.Common;
98

109
namespace Renci.SshNet.Tests.Classes
1110
{
1211
[TestClass]
13-
public class ScpClientTest_Download_PathAndDirectoryInfo_SendExecRequestReturnsFalse
12+
public class ScpClientTest_Download_PathAndDirectoryInfo_SendExecRequestReturnsFalse : ScpClientTestBase
1413
{
15-
private Mock<IServiceFactory> _serviceFactoryMock;
16-
private Mock<ISession> _sessionMock;
17-
private Mock<IChannelSession> _channelSessionMock;
18-
private Mock<PipeStream> _pipeStreamMock;
1914
private ConnectionInfo _connectionInfo;
2015
private ScpClient _scpClient;
2116
private DirectoryInfo _directoryInfo;
2217
private string _path;
23-
private string _quotedPath;
18+
private string _transformedPath;
2419
private IList<ScpUploadEventArgs> _uploadingRegister;
2520
private SshException _actualException;
2621

27-
[TestInitialize]
28-
public void Setup()
29-
{
30-
Arrange();
31-
Act();
32-
}
33-
34-
protected void Arrange()
22+
protected override void SetupData()
3523
{
3624
var random = new Random();
25+
3726
_connectionInfo = new ConnectionInfo("host", 22, "user", new PasswordAuthenticationMethod("user", "pwd"));
3827
_directoryInfo = new DirectoryInfo("destination");
3928
_path = "/home/sshnet/" + random.Next().ToString(CultureInfo.InvariantCulture);
40-
_quotedPath = _path.ShellQuote();
29+
_transformedPath = random.Next().ToString();
4130
_uploadingRegister = new List<ScpUploadEventArgs>();
31+
}
4232

43-
_serviceFactoryMock = new Mock<IServiceFactory>(MockBehavior.Strict);
44-
_sessionMock = new Mock<ISession>(MockBehavior.Strict);
45-
_channelSessionMock = new Mock<IChannelSession>(MockBehavior.Strict);
46-
_pipeStreamMock = new Mock<PipeStream>(MockBehavior.Strict);
47-
33+
protected override void SetupMocks()
34+
{
4835
var sequence = new MockSequence();
36+
37+
_serviceFactoryMock.InSequence(sequence)
38+
.Setup(p => p.CreateRemotePathDoubleQuoteTransformation())
39+
.Returns(_remotePathTransformationMock.Object);
4940
_serviceFactoryMock.InSequence(sequence)
50-
.Setup(p => p.CreateSession(_connectionInfo))
51-
.Returns(_sessionMock.Object);
41+
.Setup(p => p.CreateSession(_connectionInfo))
42+
.Returns(_sessionMock.Object);
5243
_sessionMock.InSequence(sequence).Setup(p => p.Connect());
5344
_serviceFactoryMock.InSequence(sequence).Setup(p => p.CreatePipeStream()).Returns(_pipeStreamMock.Object);
5445
_sessionMock.InSequence(sequence).Setup(p => p.CreateChannelSession()).Returns(_channelSessionMock.Object);
5546
_channelSessionMock.InSequence(sequence).Setup(p => p.Open());
47+
_remotePathTransformationMock.InSequence(sequence)
48+
.Setup(p => p.Transform(_path))
49+
.Returns(_transformedPath);
5650
_channelSessionMock.InSequence(sequence)
57-
.Setup(p => p.SendExecRequest(string.Format("scp -prf {0}", _quotedPath))).Returns(false);
51+
.Setup(p => p.SendExecRequest(string.Format("scp -prf {0}", _transformedPath)))
52+
.Returns(false);
5853
_channelSessionMock.InSequence(sequence).Setup(p => p.Dispose());
5954
_pipeStreamMock.As<IDisposable>().InSequence(sequence).Setup(p => p.Dispose());
55+
}
56+
57+
protected override void Arrange()
58+
{
59+
base.Arrange();
6060

6161
_scpClient = new ScpClient(_connectionInfo, false, _serviceFactoryMock.Object);
6262
_scpClient.Uploading += (sender, args) => _uploadingRegister.Add(args);
6363
_scpClient.Connect();
6464
}
6565

66-
protected virtual void Act()
66+
protected override void Act()
6767
{
6868
try
6969
{
@@ -87,7 +87,7 @@ public void UploadShouldHaveThrownSshException()
8787
[TestMethod]
8888
public void SendExecRequestOnChannelSessionShouldBeInvokedOnce()
8989
{
90-
_channelSessionMock.Verify(p => p.SendExecRequest(string.Format("scp -prf {0}", _quotedPath)), Times.Once);
90+
_channelSessionMock.Verify(p => p.SendExecRequest(string.Format("scp -prf {0}", _transformedPath)), Times.Once);
9191
}
9292

9393
[TestMethod]

src/Renci.SshNet.Tests/Classes/ScpClientTest_Download_PathAndFileInfo_SendExecRequestReturnsFalse.cs

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,66 +4,65 @@
44
using System.IO;
55
using Microsoft.VisualStudio.TestTools.UnitTesting;
66
using Moq;
7-
using Renci.SshNet.Channels;
87
using Renci.SshNet.Common;
98

109
namespace Renci.SshNet.Tests.Classes
1110
{
1211
[TestClass]
13-
public class ScpClientTest_Download_PathAndFileInfo_SendExecRequestReturnsFalse
12+
public class ScpClientTest_Download_PathAndFileInfo_SendExecRequestReturnsFalse : ScpClientTestBase
1413
{
15-
private Mock<IServiceFactory> _serviceFactoryMock;
16-
private Mock<ISession> _sessionMock;
17-
private Mock<IChannelSession> _channelSessionMock;
18-
private Mock<PipeStream> _pipeStreamMock;
1914
private ConnectionInfo _connectionInfo;
2015
private ScpClient _scpClient;
2116
private FileInfo _fileInfo;
2217
private string _path;
23-
private string _quotedPath;
18+
private string _transformedPath;
2419
private IList<ScpUploadEventArgs> _uploadingRegister;
2520
private SshException _actualException;
2621

27-
[TestInitialize]
28-
public void Setup()
29-
{
30-
Arrange();
31-
Act();
32-
}
33-
34-
protected void Arrange()
22+
protected override void SetupData()
3523
{
3624
var random = new Random();
25+
3726
_connectionInfo = new ConnectionInfo("host", 22, "user", new PasswordAuthenticationMethod("user", "pwd"));
3827
_fileInfo = new FileInfo("destination");
3928
_path = "/home/sshnet/" + random.Next().ToString(CultureInfo.InvariantCulture);
40-
_quotedPath = _path.ShellQuote();
29+
_transformedPath = random.Next().ToString();
4130
_uploadingRegister = new List<ScpUploadEventArgs>();
31+
}
4232

43-
_serviceFactoryMock = new Mock<IServiceFactory>(MockBehavior.Strict);
44-
_sessionMock = new Mock<ISession>(MockBehavior.Strict);
45-
_channelSessionMock = new Mock<IChannelSession>(MockBehavior.Strict);
46-
_pipeStreamMock = new Mock<PipeStream>(MockBehavior.Strict);
47-
33+
protected override void SetupMocks()
34+
{
4835
var sequence = new MockSequence();
36+
37+
_serviceFactoryMock.InSequence(sequence)
38+
.Setup(p => p.CreateRemotePathDoubleQuoteTransformation())
39+
.Returns(_remotePathTransformationMock.Object);
4940
_serviceFactoryMock.InSequence(sequence)
50-
.Setup(p => p.CreateSession(_connectionInfo))
51-
.Returns(_sessionMock.Object);
41+
.Setup(p => p.CreateSession(_connectionInfo))
42+
.Returns(_sessionMock.Object);
5243
_sessionMock.InSequence(sequence).Setup(p => p.Connect());
5344
_serviceFactoryMock.InSequence(sequence).Setup(p => p.CreatePipeStream()).Returns(_pipeStreamMock.Object);
5445
_sessionMock.InSequence(sequence).Setup(p => p.CreateChannelSession()).Returns(_channelSessionMock.Object);
5546
_channelSessionMock.InSequence(sequence).Setup(p => p.Open());
47+
_remotePathTransformationMock.InSequence(sequence)
48+
.Setup(p => p.Transform(_path))
49+
.Returns(_transformedPath);
5650
_channelSessionMock.InSequence(sequence)
57-
.Setup(p => p.SendExecRequest(string.Format("scp -pf {0}", _quotedPath))).Returns(false);
51+
.Setup(p => p.SendExecRequest(string.Format("scp -pf {0}", _transformedPath))).Returns(false);
5852
_channelSessionMock.InSequence(sequence).Setup(p => p.Dispose());
5953
_pipeStreamMock.As<IDisposable>().InSequence(sequence).Setup(p => p.Dispose());
54+
}
55+
56+
protected override void Arrange()
57+
{
58+
base.Arrange();
6059

6160
_scpClient = new ScpClient(_connectionInfo, false, _serviceFactoryMock.Object);
6261
_scpClient.Uploading += (sender, args) => _uploadingRegister.Add(args);
6362
_scpClient.Connect();
6463
}
6564

66-
protected virtual void Act()
65+
protected override void Act()
6766
{
6867
try
6968
{
@@ -87,7 +86,7 @@ public void UploadShouldHaveThrownSshException()
8786
[TestMethod]
8887
public void SendExecRequestOnChannelSessionShouldBeInvokedOnce()
8988
{
90-
_channelSessionMock.Verify(p => p.SendExecRequest(string.Format("scp -pf {0}", _quotedPath)), Times.Once);
89+
_channelSessionMock.Verify(p => p.SendExecRequest(string.Format("scp -pf {0}", _transformedPath)), Times.Once);
9190
}
9291

9392
[TestMethod]

src/Renci.SshNet.Tests/Classes/ScpClientTest_Download_PathAndStream_SendExecRequestReturnsFalse.cs

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,21 @@
44
using System.IO;
55
using Microsoft.VisualStudio.TestTools.UnitTesting;
66
using Moq;
7-
using Renci.SshNet.Channels;
87
using Renci.SshNet.Common;
98

109
namespace Renci.SshNet.Tests.Classes
1110
{
1211
[TestClass]
13-
public class ScpClientTest_Download_PathAndStream_SendExecRequestReturnsFalse
12+
public class ScpClientTest_Download_PathAndStream_SendExecRequestReturnsFalse : ScpClientTestBase
1413
{
15-
private Mock<IServiceFactory> _serviceFactoryMock;
16-
private Mock<ISession> _sessionMock;
17-
private Mock<IChannelSession> _channelSessionMock;
18-
private Mock<PipeStream> _pipeStreamMock;
1914
private ConnectionInfo _connectionInfo;
2015
private ScpClient _scpClient;
2116
private Stream _destination;
2217
private string _path;
23-
private string _quotedPath;
18+
private string _transformedPath;
2419
private IList<ScpUploadEventArgs> _uploadingRegister;
2520
private SshException _actualException;
2621

27-
[TestInitialize]
28-
public void Setup()
29-
{
30-
Arrange();
31-
Act();
32-
}
33-
3422
[TestCleanup]
3523
public void Cleanup()
3624
{
@@ -40,39 +28,51 @@ public void Cleanup()
4028
}
4129
}
4230

43-
protected void Arrange()
31+
protected override void SetupData()
4432
{
4533
var random = new Random();
34+
4635
_connectionInfo = new ConnectionInfo("host", 22, "user", new PasswordAuthenticationMethod("user", "pwd"));
4736
_destination = new MemoryStream();
4837
_path = "/home/sshnet/" + random.Next().ToString(CultureInfo.InvariantCulture);
49-
_quotedPath = _path.ShellQuote();
38+
_transformedPath = random.Next().ToString();
5039
_uploadingRegister = new List<ScpUploadEventArgs>();
40+
}
5141

52-
_serviceFactoryMock = new Mock<IServiceFactory>(MockBehavior.Strict);
53-
_sessionMock = new Mock<ISession>(MockBehavior.Strict);
54-
_channelSessionMock = new Mock<IChannelSession>(MockBehavior.Strict);
55-
_pipeStreamMock = new Mock<PipeStream>(MockBehavior.Strict);
56-
42+
protected override void SetupMocks()
43+
{
5744
var sequence = new MockSequence();
45+
46+
_serviceFactoryMock.InSequence(sequence)
47+
.Setup(p => p.CreateRemotePathDoubleQuoteTransformation())
48+
.Returns(_remotePathTransformationMock.Object);
5849
_serviceFactoryMock.InSequence(sequence)
59-
.Setup(p => p.CreateSession(_connectionInfo))
60-
.Returns(_sessionMock.Object);
50+
.Setup(p => p.CreateSession(_connectionInfo))
51+
.Returns(_sessionMock.Object);
6152
_sessionMock.InSequence(sequence).Setup(p => p.Connect());
6253
_serviceFactoryMock.InSequence(sequence).Setup(p => p.CreatePipeStream()).Returns(_pipeStreamMock.Object);
6354
_sessionMock.InSequence(sequence).Setup(p => p.CreateChannelSession()).Returns(_channelSessionMock.Object);
6455
_channelSessionMock.InSequence(sequence).Setup(p => p.Open());
56+
_remotePathTransformationMock.InSequence(sequence)
57+
.Setup(p => p.Transform(_path))
58+
.Returns(_transformedPath);
6559
_channelSessionMock.InSequence(sequence)
66-
.Setup(p => p.SendExecRequest(string.Format("scp -f {0}", _quotedPath))).Returns(false);
60+
.Setup(p => p.SendExecRequest(string.Format("scp -f {0}", _transformedPath)))
61+
.Returns(false);
6762
_channelSessionMock.InSequence(sequence).Setup(p => p.Dispose());
6863
_pipeStreamMock.As<IDisposable>().InSequence(sequence).Setup(p => p.Dispose());
64+
}
65+
66+
protected override void Arrange()
67+
{
68+
base.Arrange();
6969

7070
_scpClient = new ScpClient(_connectionInfo, false, _serviceFactoryMock.Object);
7171
_scpClient.Uploading += (sender, args) => _uploadingRegister.Add(args);
7272
_scpClient.Connect();
7373
}
7474

75-
protected virtual void Act()
75+
protected override void Act()
7676
{
7777
try
7878
{
@@ -96,7 +96,7 @@ public void UploadShouldHaveThrownSshException()
9696
[TestMethod]
9797
public void SendExecRequestOnChannelSessionShouldBeInvokedOnce()
9898
{
99-
_channelSessionMock.Verify(p => p.SendExecRequest(string.Format("scp -f {0}", _quotedPath)), Times.Once);
99+
_channelSessionMock.Verify(p => p.SendExecRequest(string.Format("scp -f {0}", _transformedPath)), Times.Once);
100100
}
101101

102102
[TestMethod]

0 commit comments

Comments
 (0)