Files
mus65 933613e31c Update to MSTest 4 (#1721)
* Update to MSTest 4

* fix TestMethodForPlatformAttribute

replace Execute with ExecuteAsync and fix MSTEST0057

https://learn.microsoft.com/en-us/dotnet/core/testing/mstest-analyzers/mstest0057 (link currently dead)

* fix compilation error

* fix MSTEST0037

https://learn.microsoft.com/en-us/dotnet/core/testing/mstest-analyzers/mstest0037

* fix MSTEST0052

https://learn.microsoft.com/en-us/dotnet/core/testing/mstest-analyzers/mstest0052

* fix MSTEST0045

Fixing this properly would require the tests to respect
testContext.CancellationToken. I'm not sure this is worth fixing
or how to even do it for the sync methods.

https://learn.microsoft.com/en-us/dotnet/core/testing/mstest-analyzers/mstest0045

* fix MSTEST0001

I assume that parallelization would break a lot of stuff.

https://learn.microsoft.com/en-us/dotnet/core/testing/mstest-analyzers/mstest0001

* Workaround for new Sonar warnings because of MSTest4

* revert analyzer fixes in OrderedDictionaryTest

* use custom sync console logger for MSTest

to work around https://github.com/microsoft/testfx/issues/6457

* remove redundant args

---------

Co-authored-by: Wojciech Nagórski <wojtpl2@gmail.com>
Co-authored-by: Rob Hague <rob.hague00@gmail.com>
2025-11-14 22:09:13 +01:00

133 lines
4.7 KiB
C#

using Renci.SshNet.Common;
using Renci.SshNet.IntegrationTests.Common;
namespace Renci.SshNet.IntegrationTests
{
[TestClass]
public class SshTests_TTYDisabled : TestBase
{
private IConnectionInfoFactory _connectionInfoFactory;
private IConnectionInfoFactory _adminConnectionInfoFactory;
private RemoteSshdConfig _remoteSshdConfig;
[TestInitialize]
public void SetUp()
{
_connectionInfoFactory = new LinuxVMConnectionFactory(SshServerHostName, SshServerPort);
_adminConnectionInfoFactory = new LinuxAdminConnectionFactory(SshServerHostName, SshServerPort);
_remoteSshdConfig = new RemoteSshd(_adminConnectionInfoFactory).OpenConfig();
_remoteSshdConfig.AllowTcpForwarding()
.PermitTTY(false)
.PrintMotd(false)
.Update()
.Restart();
}
[TestCleanup]
public void TearDown()
{
_remoteSshdConfig?.Reset();
}
[TestMethod]
public void Ssh_CreateShellStream()
{
using (var client = new SshClient(_connectionInfoFactory.Create()))
{
client.Connect();
try
{
client.CreateShellStream("xterm", 80, 24, 800, 600, 1024, null);
Assert.Fail("Should not be able to create ShellStream with pseudo-terminal settings when PermitTTY is no at server side.");
}
catch (SshException ex)
{
Assert.AreEqual("The pseudo-terminal request was not accepted by the server. Consult the server log for more information.", ex.Message);
}
}
}
[TestMethod]
public void Ssh_CreateShellStreamNoTerminal()
{
using (var client = new SshClient(_connectionInfoFactory.Create()))
{
client.Connect();
using (var shellStream = client.CreateShellStreamNoTerminal(bufferSize: 1024))
{
var foo = new string('a', 90);
shellStream.WriteLine($"echo {foo}");
var line = shellStream.ReadLine(TimeSpan.FromSeconds(1));
Assert.IsNotNull(line);
Assert.EndsWith(foo, line);
}
}
}
[TestMethod]
public void Ssh_CreateShell()
{
using (var client = new SshClient(_connectionInfoFactory.Create()))
{
client.Connect();
using (var input = new MemoryStream())
using (var output = new MemoryStream())
using (var extOutput = new MemoryStream())
{
var shell = client.CreateShell(input, output, extOutput, "xterm", 80, 24, 800, 600, null, 1024);
try
{
shell.Start();
Assert.Fail("Should not be able to create ShellStream with terminal settings when PermitTTY is no at server side.");
}
catch (SshException ex)
{
Assert.AreEqual("The pseudo-terminal request was not accepted by the server. Consult the server log for more information.", ex.Message);
}
}
}
}
[TestMethod]
public void Ssh_CreateShellNoTerminal()
{
using (var client = new SshClient(_connectionInfoFactory.Create()))
{
client.Connect();
using (var input = new MemoryStream())
using (var output = new MemoryStream())
using (var extOutput = new MemoryStream())
{
var shell = client.CreateShellNoTerminal(input, output, extOutput, 1024);
shell.Start();
var inputWriter = new StreamWriter(input, Encoding.ASCII, 1024);
var foo = new string('a', 90);
inputWriter.WriteLine($"echo {foo}");
inputWriter.Flush();
input.Position = 0;
Thread.Sleep(1000);
output.Position = 0;
var outputReader = new StreamReader(output, Encoding.ASCII, false, 1024);
var outputString = outputReader.ReadLine();
Assert.IsNotNull(outputString);
Assert.EndsWith(foo, outputString);
shell.Stop();
}
}
}
}
}