From 16ca9af4fd884030166dbbd6918dcf006cc02d17 Mon Sep 17 00:00:00 2001 From: adstep Date: Fri, 16 Dec 2022 16:16:52 -0800 Subject: [PATCH] Add support for record/playback on tests --- .editorconfig | 6 + scripts/Generate-Coverage.ps1 | 6 +- scripts/Run-Tests.ps1 | 1 + .../BaseProtocolTests.cs | 105 +++++ .../IntegrationProtocolTests.cs | 39 ++ .../ProtocolTests.cs | 18 +- .../Recording/PassThruHandler.cs | 10 + .../Recording/PlaybackHandler.cs | 64 +++ .../Recording/RecordedRequest.cs | 44 ++ .../Recording/RecordedResponse.cs | 20 + .../Recording/RecordedSession.cs | 8 + .../Recording/Recording.cs | 8 + .../Recording/RecordingHandler.cs | 50 +++ .../Recording/RecordingManager.cs | 132 ++++++ .../Recording/RecordingSessionHandler.cs | 6 + .../Recording/SessionManager.cs | 45 ++ .../Sessions/GetCommandState.yml | 267 ++++++++++++ .../Sessions/OpenCloseShell.yml | 109 +++++ .../RunCommandExceedingOperationTimeout.yml | 386 ++++++++++++++++++ .../Sessions/RunCommandWithArgsAndCleanup.yml | 210 ++++++++++ .../Sessions/RunCommandWithEnv.yml | 272 ++++++++++++ .../RunCommandWithoutArgsAndCleanup.yml | 209 ++++++++++ .../UnitProtocolTests.cs | 34 ++ .../WinRMSharp.IntegrationTests.csproj | 19 + .../test.runsettings | 8 +- src/WinRMSharp.Tests/BaseClientTests.cs | 64 +++ src/WinRMSharp.Tests/BaseProtocolTests.cs | 179 ++++++++ .../Data/Sessions/ClientRunCommand.yml | 261 ++++++++++++ .../Sessions/ClientRunCommandWithArgs.yml | 261 ++++++++++++ .../ClientRunCommandWithEnvironment.yml | 277 +++++++++++++ .../Data/Sessions/ProtocolGetCommandState.yml | 264 ++++++++++++ .../ProtocolGetCommandStateBeforeRun.yml | 128 ++++++ .../Data/Sessions/ProtocolOpenCloseShell.yml | 106 +++++ ...colRunCommandExceedingOperationTimeout.yml | 383 +++++++++++++++++ .../ProtocolRunCommandWithArgsAndCleanup.yml | 207 ++++++++++ .../ProtocolRunCommandWithCommandInput.yml | 308 ++++++++++++++ .../Sessions/ProtocolRunCommandWithEnv.yml | 269 ++++++++++++ .../ProtocolRunCommandWithNoProfile.yml | 264 ++++++++++++ .../ProtocolRunCommandWithUnicode.yml | 264 ++++++++++++ ...rotocolRunCommandWithoutArgsAndCleanup.yml | 206 ++++++++++ src/WinRMSharp.Tests/InMemoryClientTests.cs | 64 +++ src/WinRMSharp.Tests/InMemoryProtocolTests.cs | 36 ++ .../IntegrationClientTests.cs | 38 ++ .../IntegrationProtocolTests.cs | 36 ++ src/WinRMSharp.Tests/MockClient.cs | 103 ----- src/WinRMSharp.Tests/ProtocolTests.cs | 147 ------- .../Sessions/PassThruHandler.cs | 10 + .../Sessions/PlaybackHandler.cs | 64 +++ .../Sessions/RecordedRequest.cs | 44 ++ .../Sessions/RecordedResponse.cs | 29 ++ src/WinRMSharp.Tests/Sessions/Recording.cs | 8 + .../Sessions/RecordingHandler.cs | 50 +++ .../Sessions/SessionHandler.cs | 6 + .../Sessions/SessionManager.cs | 50 +++ src/WinRMSharp.Tests/WinRMClientTests.cs | 68 +-- src/WinRMSharp.Tests/WinRMSharp.Tests.csproj | 51 +++ src/WinRMSharp.Tests/test.runsettings | 36 +- src/WinRMSharp.sln | 6 - src/WinRMSharp/Contracts/Fault.cs | 10 + src/WinRMSharp/Contracts/Header.cs | 2 +- src/WinRMSharp/Contracts/WSManFault.cs | 9 - .../Exceptions/OperationTimeoutException.cs | 9 - .../Exceptions/TransportException.cs | 7 - .../Exceptions/WSManFaultException.cs | 17 +- src/WinRMSharp/Exceptions/WinRMException.cs | 4 - src/WinRMSharp/IProtocol.cs | 16 +- src/WinRMSharp/ITransport.cs | 5 + src/WinRMSharp/IncrementingGuidProvider.cs | 19 + src/WinRMSharp/Protocol.cs | 142 ++++--- src/WinRMSharp/Transport.cs | 20 +- src/WinRMSharp/Utils/Fault.cs | 8 - src/WinRMSharp/Utils/StringExtensions.cs | 8 +- src/WinRMSharp/Utils/Xml.cs | 13 + src/WinRMSharp/WinRMClient.cs | 25 +- 74 files changed, 6236 insertions(+), 441 deletions(-) create mode 100644 scripts/Run-Tests.ps1 create mode 100644 src/WinRMSharp.IntegrationTests/BaseProtocolTests.cs create mode 100644 src/WinRMSharp.IntegrationTests/IntegrationProtocolTests.cs create mode 100644 src/WinRMSharp.IntegrationTests/Recording/PassThruHandler.cs create mode 100644 src/WinRMSharp.IntegrationTests/Recording/PlaybackHandler.cs create mode 100644 src/WinRMSharp.IntegrationTests/Recording/RecordedRequest.cs create mode 100644 src/WinRMSharp.IntegrationTests/Recording/RecordedResponse.cs create mode 100644 src/WinRMSharp.IntegrationTests/Recording/RecordedSession.cs create mode 100644 src/WinRMSharp.IntegrationTests/Recording/Recording.cs create mode 100644 src/WinRMSharp.IntegrationTests/Recording/RecordingHandler.cs create mode 100644 src/WinRMSharp.IntegrationTests/Recording/RecordingManager.cs create mode 100644 src/WinRMSharp.IntegrationTests/Recording/RecordingSessionHandler.cs create mode 100644 src/WinRMSharp.IntegrationTests/Recording/SessionManager.cs create mode 100644 src/WinRMSharp.IntegrationTests/Sessions/GetCommandState.yml create mode 100644 src/WinRMSharp.IntegrationTests/Sessions/OpenCloseShell.yml create mode 100644 src/WinRMSharp.IntegrationTests/Sessions/RunCommandExceedingOperationTimeout.yml create mode 100644 src/WinRMSharp.IntegrationTests/Sessions/RunCommandWithArgsAndCleanup.yml create mode 100644 src/WinRMSharp.IntegrationTests/Sessions/RunCommandWithEnv.yml create mode 100644 src/WinRMSharp.IntegrationTests/Sessions/RunCommandWithoutArgsAndCleanup.yml create mode 100644 src/WinRMSharp.IntegrationTests/UnitProtocolTests.cs create mode 100644 src/WinRMSharp.Tests/BaseClientTests.cs create mode 100644 src/WinRMSharp.Tests/BaseProtocolTests.cs create mode 100644 src/WinRMSharp.Tests/Data/Sessions/ClientRunCommand.yml create mode 100644 src/WinRMSharp.Tests/Data/Sessions/ClientRunCommandWithArgs.yml create mode 100644 src/WinRMSharp.Tests/Data/Sessions/ClientRunCommandWithEnvironment.yml create mode 100644 src/WinRMSharp.Tests/Data/Sessions/ProtocolGetCommandState.yml create mode 100644 src/WinRMSharp.Tests/Data/Sessions/ProtocolGetCommandStateBeforeRun.yml create mode 100644 src/WinRMSharp.Tests/Data/Sessions/ProtocolOpenCloseShell.yml create mode 100644 src/WinRMSharp.Tests/Data/Sessions/ProtocolRunCommandExceedingOperationTimeout.yml create mode 100644 src/WinRMSharp.Tests/Data/Sessions/ProtocolRunCommandWithArgsAndCleanup.yml create mode 100644 src/WinRMSharp.Tests/Data/Sessions/ProtocolRunCommandWithCommandInput.yml create mode 100644 src/WinRMSharp.Tests/Data/Sessions/ProtocolRunCommandWithEnv.yml create mode 100644 src/WinRMSharp.Tests/Data/Sessions/ProtocolRunCommandWithNoProfile.yml create mode 100644 src/WinRMSharp.Tests/Data/Sessions/ProtocolRunCommandWithUnicode.yml create mode 100644 src/WinRMSharp.Tests/Data/Sessions/ProtocolRunCommandWithoutArgsAndCleanup.yml create mode 100644 src/WinRMSharp.Tests/InMemoryClientTests.cs create mode 100644 src/WinRMSharp.Tests/InMemoryProtocolTests.cs create mode 100644 src/WinRMSharp.Tests/IntegrationClientTests.cs create mode 100644 src/WinRMSharp.Tests/IntegrationProtocolTests.cs delete mode 100644 src/WinRMSharp.Tests/MockClient.cs delete mode 100644 src/WinRMSharp.Tests/ProtocolTests.cs create mode 100644 src/WinRMSharp.Tests/Sessions/PassThruHandler.cs create mode 100644 src/WinRMSharp.Tests/Sessions/PlaybackHandler.cs create mode 100644 src/WinRMSharp.Tests/Sessions/RecordedRequest.cs create mode 100644 src/WinRMSharp.Tests/Sessions/RecordedResponse.cs create mode 100644 src/WinRMSharp.Tests/Sessions/Recording.cs create mode 100644 src/WinRMSharp.Tests/Sessions/RecordingHandler.cs create mode 100644 src/WinRMSharp.Tests/Sessions/SessionHandler.cs create mode 100644 src/WinRMSharp.Tests/Sessions/SessionManager.cs create mode 100644 src/WinRMSharp/Contracts/Fault.cs delete mode 100644 src/WinRMSharp/Contracts/WSManFault.cs delete mode 100644 src/WinRMSharp/Exceptions/OperationTimeoutException.cs create mode 100644 src/WinRMSharp/IncrementingGuidProvider.cs delete mode 100644 src/WinRMSharp/Utils/Fault.cs diff --git a/.editorconfig b/.editorconfig index bed5778..0263bff 100644 --- a/.editorconfig +++ b/.editorconfig @@ -224,6 +224,9 @@ dotnet_analyzer_diagnostic.category-CodeQuality.severity = warning # IDE0011: Add braces to 'if' statement dotnet_diagnostic.IDE0011.severity = silent +# IDE0045: 'if' statement can be simplified +dotnet_diagnostic.IDE0045.severity = silent + # IDE0046: 'if' statement can be simplified dotnet_diagnostic.IDE0046.severity = silent @@ -233,6 +236,9 @@ dotnet_diagnostic.IDE0058.severity = silent # IDE0065: Using directives must be placed outside of a namespace declaration dotnet_diagnostic.IDE0065.severity = silent +# IDE0078: Use pattern matching +dotnet_diagnostic.IDE0078.severity = silent + # C++ Files [*.{cpp,h,in}] curly_bracket_next_line = true diff --git a/scripts/Generate-Coverage.ps1 b/scripts/Generate-Coverage.ps1 index 0a51139..60c6b50 100644 --- a/scripts/Generate-Coverage.ps1 +++ b/scripts/Generate-Coverage.ps1 @@ -1,10 +1,12 @@ Push-Location -dotnet test "$PSScriptRoot/../src/WinRMSharp.Tests/" --framework net7.0 --collect:"XPlat Code Coverage" +dotnet test "$PSScriptRoot/../src/WinRMSharp.Tests/" --framework net7.0 --filter "Category!=Integration" --collect:"XPlat Code Coverage" $coverageFiles = Get-ChildItem -Path "$PSScriptRoot/../**/coverage.cobertura.xml" -Recurse $coverageFiles = $coverageFiles | Sort-Object -Property LastWriteTime -Descending $latestCoverageFile = $coverageFiles[0] -reportgenerator.exe -reports:$latestCoverageFile -targetdir:"$PSScriptRoot/../coveragereport" -reporttypes:Html \ No newline at end of file +reportgenerator.exe -reports:$latestCoverageFile -targetdir:"$PSScriptRoot/../coveragereport" -reporttypes:Html + +Invoke-Expression "$PSScriptRoot/../coveragereport\index.html" diff --git a/scripts/Run-Tests.ps1 b/scripts/Run-Tests.ps1 new file mode 100644 index 0000000..646ea23 --- /dev/null +++ b/scripts/Run-Tests.ps1 @@ -0,0 +1 @@ +dotnet test "$PSScriptRoot/../src/WinRMSharp.Tests/" --framework net7.0 --filter "Category!=Integration" diff --git a/src/WinRMSharp.IntegrationTests/BaseProtocolTests.cs b/src/WinRMSharp.IntegrationTests/BaseProtocolTests.cs new file mode 100644 index 0000000..93dd1f7 --- /dev/null +++ b/src/WinRMSharp.IntegrationTests/BaseProtocolTests.cs @@ -0,0 +1,105 @@ +using Xunit; + +namespace WinRMSharp.IntegrationTests +{ + public abstract class BaseProtocolTests + { + [Fact] + public async Task OpenCloseShell() + { + Protocol protocol = GenerateProtocol(nameof(OpenCloseShell)); + + string shellId = await protocol.OpenShell(); + await protocol.CloseShell(shellId); + + Assert.Matches(@"^\w{8}-\w{4}-\w{4}-\w{4}-\w{12}$", shellId); + } + + [Fact] + public async Task RunCommandWithArgsAndCleanup() + { + Protocol protocol = GenerateProtocol(nameof(RunCommandWithArgsAndCleanup)); + + string shellId = await protocol.OpenShell(); + string commandId = await protocol.RunCommand(shellId, "ipconfig", new string[] { "/all" }); + + await protocol.CloseCommand(shellId, commandId); + await protocol.CloseShell(shellId); + + Assert.Matches(@"^\w{8}-\w{4}-\w{4}-\w{4}-\w{12}$", commandId); + } + + [Fact] + public async Task RunCommandWithoutArgsAndCleanup() + { + Protocol protocol = GenerateProtocol(nameof(RunCommandWithoutArgsAndCleanup)); + + string shellId = await protocol.OpenShell(); + string commandId = await protocol.RunCommand(shellId, "hostname"); + + await protocol.CloseCommand(shellId, commandId); + await protocol.CloseShell(shellId); + + Assert.Matches(@"^\w{8}-\w{4}-\w{4}-\w{4}-\w{12}$", commandId); + } + + [Fact] + public async Task RunCommandWithEnv() + { + Protocol protocol = GenerateProtocol(nameof(RunCommandWithEnv)); + + Dictionary envVars = new Dictionary() + { + { "TESTENV1", "hi mom" }, + { "TESTENV2", "another var" } + }; + + string shellId = await protocol.OpenShell(envVars: envVars); + string commandId = await protocol.RunCommand(shellId, "echo", new string[] { "%TESTENV1%", "%TESTENV2%" }); + + CommandState state = await protocol.PollCommandState(shellId, commandId); + + await protocol.CloseCommand(shellId, commandId); + await protocol.CloseShell(shellId); + + Assert.Matches(@"hi mom another var", state.Stdout); + } + + [Fact] + public async Task GetCommandState() + { + Protocol protocol = GenerateProtocol(nameof(GetCommandState)); + + string shellId = await protocol.OpenShell(); + string commandId = await protocol.RunCommand(shellId, "ipconfig", new string[] { "/all" }); + + CommandState state = await protocol.PollCommandState(shellId, commandId); + + await protocol.CloseCommand(shellId, commandId); + await protocol.CloseShell(shellId); + + Assert.Equal(0, state.StatusCode); + Assert.Contains(@"Windows IP Configuration", state.Stdout); + Assert.Equal(0, state.Stderr.Length); + } + + [Fact] + public async Task RunCommandExceedingOperationTimeout() + { + Protocol protocol = GenerateProtocol(nameof(RunCommandExceedingOperationTimeout)); + + string shellId = await protocol.OpenShell(); + string commandId = await protocol.RunCommand(shellId, $"powershell -Command Start-Sleep -s {protocol.OperationTimeout.TotalSeconds * 2}"); + + CommandState state = await protocol.PollCommandState(shellId, commandId); + + await protocol.CloseCommand(shellId, commandId); + await protocol.CloseShell(shellId); + + Assert.Equal(0, state.StatusCode); + Assert.Equal(0, state.Stderr.Length); + } + + public abstract Protocol GenerateProtocol(string sessionName); + } +} diff --git a/src/WinRMSharp.IntegrationTests/IntegrationProtocolTests.cs b/src/WinRMSharp.IntegrationTests/IntegrationProtocolTests.cs new file mode 100644 index 0000000..3894d1b --- /dev/null +++ b/src/WinRMSharp.IntegrationTests/IntegrationProtocolTests.cs @@ -0,0 +1,39 @@ +using System.Net; +using WinRMSharp.IntegrationTests.Recording; + +namespace WinRMSharp.IntegrationTests +{ + public class IntegrationProtocolTests : BaseProtocolTests, IDisposable + { + private SessionManager _sessionManager = new SessionManager(); + + public IntegrationProtocolTests() + { + + } + + public void Dispose() + { + _sessionManager.Dispose(); + } + + public override Protocol GenerateProtocol(string sessionName) + { + string baseUrl = Environment.GetEnvironmentVariable("WINRM_BASE_URL") ?? throw new ArgumentNullException("WINRM_BASE_URL"); + string username = Environment.GetEnvironmentVariable("WINRM_USERNAME") ?? throw new ArgumentNullException("WINRM_USERNAME"); + string password = Environment.GetEnvironmentVariable("WINRM_PASSWORD") ?? throw new ArgumentNullException("WINRM_PASSWORD"); + + SessionHandler handler = _sessionManager.GenerateSessionHandler(State.Recording, sessionName); + + ICredentials credentials = new NetworkCredential(username, password); + ITransport transport = new Transport(baseUrl, handler, credentials); + + ProtocolOptions protocolOptions = new ProtocolOptions() + { + OperationTimeout = TimeSpan.FromSeconds(5) + }; + + return new Protocol(transport, new IncrementingGuidProvider(), protocolOptions); + } + } +} diff --git a/src/WinRMSharp.IntegrationTests/ProtocolTests.cs b/src/WinRMSharp.IntegrationTests/ProtocolTests.cs index 6691b3e..a59f3dc 100644 --- a/src/WinRMSharp.IntegrationTests/ProtocolTests.cs +++ b/src/WinRMSharp.IntegrationTests/ProtocolTests.cs @@ -1,27 +1,37 @@ using System.Net; +using WinRMSharp.IntegrationTests.Recording; using Xunit; +using Xunit.Abstractions; namespace WinRMSharp.IntegrationTests { public class ProtocolTests { + private readonly RecordingManager _recordingManager; private readonly Protocol _protocol; - public ProtocolTests() + public ProtocolTests(ITestOutputHelper outputHelper) { string baseUrl = Environment.GetEnvironmentVariable("WINRM_BASE_URL") ?? throw new ArgumentNullException("WINRM_BASE_URL"); string username = Environment.GetEnvironmentVariable("WINRM_USERNAME") ?? throw new ArgumentNullException("WINRM_USERNAME"); string password = Environment.GetEnvironmentVariable("WINRM_PASSWORD") ?? throw new ArgumentNullException("WINRM_PASSWORD"); + _recordingManager = new RecordingManager(); + _recordingManager.Load("example"); + ICredentials credentials = new NetworkCredential(username, password); - ITransport transport = new Transport(baseUrl, credentials); + ITransport transport = new Transport(baseUrl, _recordingManager, credentials); ProtocolOptions protocolOptions = new ProtocolOptions() { OperationTimeout = TimeSpan.FromSeconds(5) }; - _protocol = new Protocol(transport, protocolOptions); + _protocol = new Protocol(transport, new IncrementingGuidProvider(), protocolOptions); + _protocol.Transport.OnMessage += (string message) => + { + outputHelper.WriteLine(message); + }; } @@ -31,6 +41,8 @@ public async Task OpenCloseShell() string shellId = await _protocol.OpenShell(); await _protocol.CloseShell(shellId); + _recordingManager.Save(); + Assert.Matches(@"^\w{8}-\w{4}-\w{4}-\w{4}-\w{12}$", shellId); } diff --git a/src/WinRMSharp.IntegrationTests/Recording/PassThruHandler.cs b/src/WinRMSharp.IntegrationTests/Recording/PassThruHandler.cs new file mode 100644 index 0000000..9973de1 --- /dev/null +++ b/src/WinRMSharp.IntegrationTests/Recording/PassThruHandler.cs @@ -0,0 +1,10 @@ +namespace WinRMSharp.IntegrationTests.Recording +{ + internal class PassThruHandler : SessionHandler + { + protected override async Task SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) + { + return await base.SendAsync(request, cancellationToken); + } + } +} diff --git a/src/WinRMSharp.IntegrationTests/Recording/PlaybackHandler.cs b/src/WinRMSharp.IntegrationTests/Recording/PlaybackHandler.cs new file mode 100644 index 0000000..54b5211 --- /dev/null +++ b/src/WinRMSharp.IntegrationTests/Recording/PlaybackHandler.cs @@ -0,0 +1,64 @@ +using System.Net; +using System.Xml.Linq; +using WinRMSharp.Utils; +using YamlDotNet.Serialization; + +namespace WinRMSharp.IntegrationTests.Recording +{ + internal class PlaybackHandler : SessionHandler + { + private int _playbackIndex = 0; + private readonly List _recordings = new List(); + + private PlaybackHandler(List recordings) + { + _recordings = recordings; + } + + public static PlaybackHandler Load(string sessionName) + { + string path = Path.Join("sessions", $"{sessionName}.yml"); + + if (!File.Exists(path)) + { + throw new FileNotFoundException($"Expected recording to exist at '{path}'"); + } + + using StreamReader fileStream = File.OpenText(path); + + IDeserializer deserializer = new DeserializerBuilder().Build(); + List recordings = deserializer.Deserialize>(fileStream); + + return new PlaybackHandler(recordings); + } + + protected override async Task SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) + { + Recording recording = _recordings[_playbackIndex++]; + + XDocument? requestDocument = Xml.Parse(await request.Content!.ReadAsStringAsync(cancellationToken)); + XDocument? recordingDocument = Xml.Parse(recording.Request.Body); + + if (!XNode.DeepEquals(requestDocument, recordingDocument)) + { + throw new InvalidOperationException($"Expected '{requestDocument}' Actual: '{recordingDocument}'"); + } + + HttpResponseMessage response = new HttpResponseMessage((HttpStatusCode)recording.Response.StatusCode) + { + Content = new StringContent(recording.Response.Body!) + }; + + foreach (KeyValuePair kv in recording.Response.Headers) + { + string key = kv.Key; + string[] values = kv.Value.Split(';'); + + response.Headers.Add(key, values); + } + + return response; + } + + } +} diff --git a/src/WinRMSharp.IntegrationTests/Recording/RecordedRequest.cs b/src/WinRMSharp.IntegrationTests/Recording/RecordedRequest.cs new file mode 100644 index 0000000..609de04 --- /dev/null +++ b/src/WinRMSharp.IntegrationTests/Recording/RecordedRequest.cs @@ -0,0 +1,44 @@ +namespace WinRMSharp.IntegrationTests.Recording +{ + public class RecordedRequest + { + public string Method { get; set; } + public string? Url { get; set; } + public Dictionary Headers { get; set; } + public string? Body { get; set; } + + public RecordedRequest() + { + Method = string.Empty; + Url = string.Empty; + Headers = new Dictionary(); + Body = string.Empty; + } + + public RecordedRequest(HttpRequestMessage requestMessage) + { + Method = requestMessage.Method.Method; + Url = requestMessage.RequestUri?.ToString(); + Headers = ApplyFilters(requestMessage.Headers.ToDictionary(h => h.Key, h => string.Join(";", h.Value))); + Body = requestMessage.Content?.ReadAsStringAsync().Result; + } + + private static Dictionary ApplyFilters(Dictionary headers) + { + HashSet headersToFilter = new HashSet() + { + "Authorization" + }; + + foreach (string headerToFilter in headersToFilter) + { + if (!headers.ContainsKey(headerToFilter)) + continue; + + headers.Remove(headerToFilter); + } + + return headers; + } + } +} diff --git a/src/WinRMSharp.IntegrationTests/Recording/RecordedResponse.cs b/src/WinRMSharp.IntegrationTests/Recording/RecordedResponse.cs new file mode 100644 index 0000000..931ddc5 --- /dev/null +++ b/src/WinRMSharp.IntegrationTests/Recording/RecordedResponse.cs @@ -0,0 +1,20 @@ +using WinRMSharp.Utils; + +namespace WinRMSharp.IntegrationTests.Recording +{ + internal class RecordedResponse + { + public int StatusCode { get; set; } + public Dictionary Headers { get; set; } + public string? Body { get; set; } + + public RecordedResponse() { } + + public RecordedResponse(HttpResponseMessage responseMessage) + { + StatusCode = (int)responseMessage.StatusCode; + Headers = responseMessage.Headers.ToDictionary(h => h.Key, h => string.Join(";", h.Value)); + Body = Xml.Format(responseMessage.Content?.ReadAsStringAsync().Result); + } + } +} diff --git a/src/WinRMSharp.IntegrationTests/Recording/RecordedSession.cs b/src/WinRMSharp.IntegrationTests/Recording/RecordedSession.cs new file mode 100644 index 0000000..4af22dc --- /dev/null +++ b/src/WinRMSharp.IntegrationTests/Recording/RecordedSession.cs @@ -0,0 +1,8 @@ +namespace WinRMSharp.IntegrationTests.Recording +{ + internal class RecordedSession + { + public string Name { get; set; } + public List Recordings { get; set; } + } +} diff --git a/src/WinRMSharp.IntegrationTests/Recording/Recording.cs b/src/WinRMSharp.IntegrationTests/Recording/Recording.cs new file mode 100644 index 0000000..aa2f80f --- /dev/null +++ b/src/WinRMSharp.IntegrationTests/Recording/Recording.cs @@ -0,0 +1,8 @@ +namespace WinRMSharp.IntegrationTests.Recording +{ + internal class Recording + { + public RecordedRequest Request { get; set; } + public RecordedResponse Response { get; set; } + } +} diff --git a/src/WinRMSharp.IntegrationTests/Recording/RecordingHandler.cs b/src/WinRMSharp.IntegrationTests/Recording/RecordingHandler.cs new file mode 100644 index 0000000..1a36a76 --- /dev/null +++ b/src/WinRMSharp.IntegrationTests/Recording/RecordingHandler.cs @@ -0,0 +1,50 @@ +using YamlDotNet.Serialization; + +namespace WinRMSharp.IntegrationTests.Recording +{ + internal class RecordingHandler : SessionHandler + { + private readonly string _sessionName; + private readonly List _recordings = new List(); + + private RecordingHandler(string sessionName) + { + _sessionName = sessionName; + } + + public static RecordingHandler Create(string sessionName) + { + return new RecordingHandler(sessionName); + } + + public void Save() + { + ISerializer serializer = new SerializerBuilder().Build(); + string yaml = serializer.Serialize(_recordings); + string path = Path.Join("sessions", $"{_sessionName}.yml"); + + if (!Directory.Exists("sessions")) + Directory.CreateDirectory("sessions"); + + File.WriteAllText(path, yaml); + } + + protected override async Task SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) + { + HttpResponseMessage response = await base.SendAsync(request, cancellationToken); + + AddRecording(new Recording() + { + Request = new RecordedRequest(request), + Response = new RecordedResponse(response) + }); + + return response; + } + + private void AddRecording(Recording recording) + { + _recordings.Add(recording); + } + } +} diff --git a/src/WinRMSharp.IntegrationTests/Recording/RecordingManager.cs b/src/WinRMSharp.IntegrationTests/Recording/RecordingManager.cs new file mode 100644 index 0000000..9fcc528 --- /dev/null +++ b/src/WinRMSharp.IntegrationTests/Recording/RecordingManager.cs @@ -0,0 +1,132 @@ +using System.Diagnostics; +using System.Net; +using System.Xml.Linq; +using WinRMSharp.Utils; +using YamlDotNet.Serialization; + +namespace WinRMSharp.IntegrationTests.Recording +{ + public enum State + { + Recording, + Playback, + PassThru + } + + internal class RecordingManager : DelegatingHandler + { + private int _playbackIndex = 0; + private readonly List _recordings = new List(); + + private readonly State _state = State.Playback; + + protected override async Task SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) + { + if (_state == State.Recording) + { + return await Record(request, cancellationToken); + } + else if (_state == State.Playback) + { + return await Playback(request); + } + else if (_state == State.PassThru) + { + return await PassThru(request, cancellationToken); + } + else + { + throw new UnreachableException(); + } + } + + private async Task Record(HttpRequestMessage request, CancellationToken cancellationToken) + { + HttpResponseMessage response = await base.SendAsync(request, cancellationToken); + + AddRecording(new Recording() + { + Request = new RecordedRequest(request), + Response = new RecordedResponse(response) + }); + + return response; + } + + private async Task Playback(HttpRequestMessage request) + { + Recording recording = _recordings[_playbackIndex++]; + + XDocument? requestDocument = (request.Content == null) ? null : Xml.Parse(await request.Content!.ReadAsStringAsync()); + XDocument? recordingDocument = Xml.Parse(recording.Request.Body); + + if (!XNode.DeepEquals(requestDocument, recordingDocument)) + { + throw new InvalidOperationException($"Expected '{requestDocument}' Actual: '{recordingDocument}'"); + } + + HttpResponseMessage response = new HttpResponseMessage((HttpStatusCode)recording.Response.StatusCode) + { + Content = new StringContent(recording.Response.Body!) + }; + + foreach (KeyValuePair kv in recording.Response.Headers) + { + string key = kv.Key; + string[] values = kv.Value.Split(';'); + + response.Headers.Add(key, values); + } + + return response; + } + + private async Task PassThru(HttpRequestMessage request, CancellationToken cancellationToken) + { + return await base.SendAsync(request, cancellationToken); + } + + public void Save() + { + string sessionName = "example"; + + RecordedSession session = new RecordedSession() + { + Name = sessionName, + Recordings = _recordings + }; + + ISerializer serializer = new SerializerBuilder().Build(); + string yaml = serializer.Serialize(session); + string path = Path.Join("sessions", $"{sessionName}.yml"); + + if (!Directory.Exists("sessions")) + Directory.CreateDirectory("sessions"); + + File.WriteAllText(path, yaml); + } + + public void Load(string sessionName) + { + string path = Path.Join("sessions", $"{sessionName}.yml"); + + if (!File.Exists(path)) + { + throw new FileNotFoundException($"Expected recording to exist at '{path}'"); + } + + using StreamReader fileStream = File.OpenText(path); + + IDeserializer deserializer = new DeserializerBuilder().Build(); + RecordedSession session = deserializer.Deserialize(fileStream); + + _recordings.Clear(); + _recordings.AddRange(session.Recordings); + } + + private void AddRecording(Recording recording) + { + _recordings.Add(recording); + } + } +} diff --git a/src/WinRMSharp.IntegrationTests/Recording/RecordingSessionHandler.cs b/src/WinRMSharp.IntegrationTests/Recording/RecordingSessionHandler.cs new file mode 100644 index 0000000..d8ea767 --- /dev/null +++ b/src/WinRMSharp.IntegrationTests/Recording/RecordingSessionHandler.cs @@ -0,0 +1,6 @@ +namespace WinRMSharp.IntegrationTests.Recording +{ + internal class SessionHandler : DelegatingHandler + { + } +} diff --git a/src/WinRMSharp.IntegrationTests/Recording/SessionManager.cs b/src/WinRMSharp.IntegrationTests/Recording/SessionManager.cs new file mode 100644 index 0000000..327d275 --- /dev/null +++ b/src/WinRMSharp.IntegrationTests/Recording/SessionManager.cs @@ -0,0 +1,45 @@ +using System.Diagnostics; + +namespace WinRMSharp.IntegrationTests.Recording +{ + internal class SessionManager : IDisposable + { + private readonly List _handlers = new List(); + + public void Dispose() + { + foreach (DelegatingHandler handler in _handlers) + { + if (handler is RecordingHandler recordingHandler) + { + recordingHandler.Save(); + } + } + } + + public SessionHandler GenerateSessionHandler(State state, string sessionName) + { + SessionHandler? handler; + + if (state == State.Recording) + { + handler = RecordingHandler.Create(sessionName); + } + else if (state == State.Playback) + { + handler = PlaybackHandler.Load(sessionName); + } + else if (state == State.PassThru) + { + handler = new PassThruHandler(); + } + else + { + throw new UnreachableException(); + } + + _handlers.Add(handler); + return handler; + } + } +} diff --git a/src/WinRMSharp.IntegrationTests/Sessions/GetCommandState.yml b/src/WinRMSharp.IntegrationTests/Sessions/GetCommandState.yml new file mode 100644 index 0000000..f6027d7 --- /dev/null +++ b/src/WinRMSharp.IntegrationTests/Sessions/GetCommandState.yml @@ -0,0 +1,267 @@ +- Request: + Method: POST + Url: https://4.154.47.156:5986/wsman + Headers: {} + Body: >- + + + + + http://windows-host:5985/wsman + + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + + 153600 + uuid:00000000-0000-0000-0000-000000000000 + + + PT5S + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/cmd + http://schemas.xmlsoap.org/ws/2004/09/transfer/Create + + False + 437 + + + + + stdin + stdout stderr + + + + Response: + StatusCode: 200 + Headers: + Server: Microsoft-HTTPAPI/2.0 + Date: Fri, 16 Dec 2022 05:33:46 GMT + Body: >- + + + http://schemas.xmlsoap.org/ws/2004/09/transfer/CreateResponse + uuid:2A75888B-D128-464B-B46F-850986BFFE24 + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + uuid:00000000-0000-0000-0000-000000000000 + + + + http://windows-host:5985/wsman + + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/cmd + + 111F6F52-7FB4-49AC-8508-5850DCDBE55D + + + + + 111F6F52-7FB4-49AC-8508-5850DCDBE55D + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/cmd + winrm-vm-002\asuvpUser + 73.53.37.241 + PT7200.000S + stdin + stdout stderr + P0DT0H0M0S + P0DT0H0M0S + + + +- Request: + Method: POST + Url: https://4.154.47.156:5986/wsman + Headers: {} + Body: >- + + + + + http://windows-host:5985/wsman + + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + + 153600 + uuid:00000000-0000-0000-0000-000000000001 + + + PT5S + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/cmd + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/Command + + TRUE + FALSE + + + 111F6F52-7FB4-49AC-8508-5850DCDBE55D + + + + + ipconfig + /all + + + + Response: + StatusCode: 200 + Headers: + Server: Microsoft-HTTPAPI/2.0 + Date: Fri, 16 Dec 2022 05:33:46 GMT + Body: >- + + + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/CommandResponse + uuid:70A3FB36-675A-4A63-9A2C-893AE85DC8DC + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + uuid:00000000-0000-0000-0000-000000000001 + + + + DBB6F7A0-0F99-416F-820D-1A7F3944E3C5 + + + +- Request: + Method: POST + Url: https://4.154.47.156:5986/wsman + Headers: {} + Body: >- + + + + + http://windows-host:5985/wsman + + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + + 153600 + uuid:00000000-0000-0000-0000-000000000002 + + + PT5S + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/cmd + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/Receive + + 111F6F52-7FB4-49AC-8508-5850DCDBE55D + + + + + stdout stderr + + + + Response: + StatusCode: 200 + Headers: + Server: Microsoft-HTTPAPI/2.0 + Date: Fri, 16 Dec 2022 05:33:46 GMT + Body: >- + + + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/ReceiveResponse + uuid:A91E07C6-FE7E-4282-854F-DC045E342B08 + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + uuid:00000000-0000-0000-0000-000000000002 + + + + DQpXaW5kb3dzIElQIENvbmZpZ3VyYXRpb24NCg0K + ICAgSG9zdCBOYW1lIC4gLiAuIC4gLiAuIC4gLiAuIC4gLiAuIDogd2lucm0tdm0tMDAyDQogICBQcmltYXJ5IERucyBTdWZmaXggIC4gLiAuIC4gLiAuIC4gOiANCg== + ICAgTm9kZSBUeXBlIC4gLiAuIC4gLiAuIC4gLiAuIC4gLiAuIDogSHlicmlkDQo= + ICAgSVAgUm91dGluZyBFbmFibGVkLiAuIC4gLiAuIC4gLiAuIDogTm8NCiAgIFdJTlMgUHJveHkgRW5hYmxlZC4gLiAuIC4gLiAuIC4gLiA6IE5vDQogICBETlMgU3VmZml4IFNlYXJjaCBMaXN0LiAuIC4gLiAuIC4gOiBsZG93M28xcnJmYnUxYW9wbDBsd2E0bmNiZy54eC5pbnRlcm5hbC5jbG91ZGFwcC5uZXQNCg0KRXRoZXJuZXQgYWRhcHRlciBFdGhlcm5ldDoNCg0KICAgQ29ubmVjdGlvbi1zcGVjaWZpYyBETlMgU3VmZml4ICAuIDogbGRvdzNvMXJyZmJ1MWFvcGwwbHdhNG5jYmcueHguaW50ZXJuYWwuY2xvdWRhcHAubmV0DQogICBEZXNjcmlwdGlvbiAuIC4gLiAuIC4gLiAuIC4gLiAuIC4gOiBNaWNyb3NvZnQgSHlwZXItViBOZXR3b3JrIEFkYXB0ZXINCiAgIFBoeXNpY2FsIEFkZHJlc3MuIC4gLiAuIC4gLiAuIC4gLiA6IDAwLTBELTNBLUZDLTEyLTU5DQogICBESENQIEVuYWJsZWQuIC4gLiAuIC4gLiAuIC4gLiAuIC4gOiBZZXMNCiAgIEF1dG9jb25maWd1cmF0aW9uIEVuYWJsZWQgLiAuIC4gLiA6IFllcw0KICAgTGluay1sb2NhbCBJUHY2IEFkZHJlc3MgLiAuIC4gLiAuIDogZmU4MDo6YWE5Zjo4MGU3OmY0NjA6Mjk5NCU0KFByZWZlcnJlZCkgDQogICBJUHY0IEFkZHJlc3MuIC4gLiAuIC4gLiAuIC4gLiAuIC4gOiAxMC4wLjAuNChQcmVmZXJyZWQpIA0KICAgU3VibmV0IE1hc2sgLiAuIC4gLiAuIC4gLiAuIC4gLiAuIDogMjU1LjI1NS4yNTUuMA0KICAgTGVhc2UgT2J0YWluZWQuIC4gLiAuIC4gLiAuIC4gLiAuIDogVGh1cnNkYXksIERlY2VtYmVyIDE1LCAyMDIyIDc6Mjc6MTAgUE0NCiAgIExlYXNlIEV4cGlyZXMgLiAuIC4gLiAuIC4gLiAuIC4gLiA6IE1vbmRheSwgSmFudWFyeSAyMiwgMjE1OSAxMjowMjowMSBQTQ0KICAgRGVmYXVsdCBHYXRld2F5IC4gLiAuIC4gLiAuIC4gLiAuIDogMTAuMC4wLjENCiAgIERIQ1AgU2VydmVyIC4gLiAuIC4gLiAuIC4gLiAuIC4gLiA6IDE2OC42My4xMjkuMTYNCiAgIERIQ1B2NiBJQUlEIC4gLiAuIC4gLiAuIC4gLiAuIC4gLiA6IDEwMDY2NjY4Mg0KICAgREhDUHY2IENsaWVudCBEVUlELiAuIC4gLiAuIC4gLiAuIDogMDAtMDEtMDAtMDEtMkItMjItRTAtODUtMDAtMEQtM0EtRkMtMTItNTkNCiAgIEROUyBTZXJ2ZXJzIC4gLiAuIC4gLiAuIC4gLiAuIC4gLiA6IDE2OC42My4xMjkuMTYNCiAgIE5ldEJJT1Mgb3ZlciBUY3BpcC4gLiAuIC4gLiAuIC4gLiA6IEVuYWJsZWQNCg== + + + + 0 + + + + +- Request: + Method: POST + Url: https://4.154.47.156:5986/wsman + Headers: {} + Body: >- + + + + + http://windows-host:5985/wsman + + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + + 153600 + uuid:00000000-0000-0000-0000-000000000003 + + + PT5S + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/cmd + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/Signal + + 111F6F52-7FB4-49AC-8508-5850DCDBE55D + + + + + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/signal/terminate + + + + Response: + StatusCode: 200 + Headers: + Server: Microsoft-HTTPAPI/2.0 + Date: Fri, 16 Dec 2022 05:33:46 GMT + Body: >- + + + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/SignalResponse + uuid:A74EF692-CD16-43ED-8912-33BC3E0AF480 + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + uuid:00000000-0000-0000-0000-000000000003 + + + + + +- Request: + Method: POST + Url: https://4.154.47.156:5986/wsman + Headers: {} + Body: >- + + + + + http://windows-host:5985/wsman + + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + + 153600 + uuid:00000000-0000-0000-0000-000000000004 + + + PT5S + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/cmd + http://schemas.xmlsoap.org/ws/2004/09/transfer/Delete + + 111F6F52-7FB4-49AC-8508-5850DCDBE55D + + + + + Response: + StatusCode: 200 + Headers: + Server: Microsoft-HTTPAPI/2.0 + Date: Fri, 16 Dec 2022 05:33:46 GMT + Body: >- + + + http://schemas.xmlsoap.org/ws/2004/09/transfer/DeleteResponse + uuid:0EC9D62A-361B-4514-9DE4-4FC068769CBD + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + uuid:00000000-0000-0000-0000-000000000004 + + + diff --git a/src/WinRMSharp.IntegrationTests/Sessions/OpenCloseShell.yml b/src/WinRMSharp.IntegrationTests/Sessions/OpenCloseShell.yml new file mode 100644 index 0000000..4691bb9 --- /dev/null +++ b/src/WinRMSharp.IntegrationTests/Sessions/OpenCloseShell.yml @@ -0,0 +1,109 @@ +- Request: + Method: POST + Url: https://4.154.47.156:5986/wsman + Headers: {} + Body: >- + + + + + http://windows-host:5985/wsman + + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + + 153600 + uuid:00000000-0000-0000-0000-000000000000 + + + PT5S + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/cmd + http://schemas.xmlsoap.org/ws/2004/09/transfer/Create + + False + 437 + + + + + stdin + stdout stderr + + + + Response: + StatusCode: 200 + Headers: + Server: Microsoft-HTTPAPI/2.0 + Date: Fri, 16 Dec 2022 05:33:45 GMT + Body: >- + + + http://schemas.xmlsoap.org/ws/2004/09/transfer/CreateResponse + uuid:D1F1CE55-79EB-4636-9072-B1EB004EF9B2 + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + uuid:00000000-0000-0000-0000-000000000000 + + + + http://windows-host:5985/wsman + + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/cmd + + F4914FBC-16D0-4C7E-B6B6-0519A89D8D97 + + + + + F4914FBC-16D0-4C7E-B6B6-0519A89D8D97 + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/cmd + winrm-vm-002\asuvpUser + 73.53.37.241 + PT7200.000S + stdin + stdout stderr + P0DT0H0M0S + P0DT0H0M0S + + + +- Request: + Method: POST + Url: https://4.154.47.156:5986/wsman + Headers: {} + Body: >- + + + + + http://windows-host:5985/wsman + + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + + 153600 + uuid:00000000-0000-0000-0000-000000000001 + + + PT5S + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/cmd + http://schemas.xmlsoap.org/ws/2004/09/transfer/Delete + + F4914FBC-16D0-4C7E-B6B6-0519A89D8D97 + + + + + Response: + StatusCode: 200 + Headers: + Server: Microsoft-HTTPAPI/2.0 + Date: Fri, 16 Dec 2022 05:33:45 GMT + Body: >- + + + http://schemas.xmlsoap.org/ws/2004/09/transfer/DeleteResponse + uuid:C7A5ED4D-3AE1-4B40-965C-4E401B27917C + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + uuid:00000000-0000-0000-0000-000000000001 + + + diff --git a/src/WinRMSharp.IntegrationTests/Sessions/RunCommandExceedingOperationTimeout.yml b/src/WinRMSharp.IntegrationTests/Sessions/RunCommandExceedingOperationTimeout.yml new file mode 100644 index 0000000..6f13197 --- /dev/null +++ b/src/WinRMSharp.IntegrationTests/Sessions/RunCommandExceedingOperationTimeout.yml @@ -0,0 +1,386 @@ +- Request: + Method: POST + Url: https://4.154.47.156:5986/wsman + Headers: {} + Body: >- + + + + + http://windows-host:5985/wsman + + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + + 153600 + uuid:00000000-0000-0000-0000-000000000000 + + + PT5S + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/cmd + http://schemas.xmlsoap.org/ws/2004/09/transfer/Create + + False + 437 + + + + + stdin + stdout stderr + + + + Response: + StatusCode: 200 + Headers: + Server: Microsoft-HTTPAPI/2.0 + Date: Fri, 16 Dec 2022 05:33:34 GMT + Body: >- + + + http://schemas.xmlsoap.org/ws/2004/09/transfer/CreateResponse + uuid:D05659AB-225E-4DA7-9F62-544AC4AF11F0 + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + uuid:00000000-0000-0000-0000-000000000000 + + + + http://windows-host:5985/wsman + + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/cmd + + 620FED91-1B8A-4B8C-86E8-139D52DB6F9D + + + + + 620FED91-1B8A-4B8C-86E8-139D52DB6F9D + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/cmd + winrm-vm-002\asuvpUser + 73.53.37.241 + PT7200.000S + stdin + stdout stderr + P0DT0H0M0S + P0DT0H0M0S + + + +- Request: + Method: POST + Url: https://4.154.47.156:5986/wsman + Headers: {} + Body: >- + + + + + http://windows-host:5985/wsman + + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + + 153600 + uuid:00000000-0000-0000-0000-000000000001 + + + PT5S + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/cmd + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/Command + + TRUE + FALSE + + + 620FED91-1B8A-4B8C-86E8-139D52DB6F9D + + + + + powershell -Command Start-Sleep -s 10 + + + + Response: + StatusCode: 200 + Headers: + Server: Microsoft-HTTPAPI/2.0 + Date: Fri, 16 Dec 2022 05:33:34 GMT + Body: >- + + + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/CommandResponse + uuid:5EBF3527-3318-434C-A544-DB57194F566F + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + uuid:00000000-0000-0000-0000-000000000001 + + + + 9CCA5331-C019-42BB-9746-19CC2B9BA695 + + + +- Request: + Method: POST + Url: https://4.154.47.156:5986/wsman + Headers: {} + Body: >- + + + + + http://windows-host:5985/wsman + + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + + 153600 + uuid:00000000-0000-0000-0000-000000000002 + + + PT5S + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/cmd + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/Receive + + 620FED91-1B8A-4B8C-86E8-139D52DB6F9D + + + + + stdout stderr + + + + Response: + StatusCode: 500 + Headers: + Server: Microsoft-HTTPAPI/2.0 + Date: Fri, 16 Dec 2022 05:33:39 GMT + Body: >- + + + http://schemas.dmtf.org/wbem/wsman/1/wsman/fault + uuid:3F69EB22-ECB1-4629-9A50-28764A6B0F66 + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + uuid:00000000-0000-0000-0000-000000000002 + + + + + s:Receiver + + w:TimedOut + + + + The WS-Management service cannot complete the operation within the time specified in OperationTimeout. + + + + The WS-Management service cannot complete the operation within the time specified in OperationTimeout. + + + + + +- Request: + Method: POST + Url: https://4.154.47.156:5986/wsman + Headers: {} + Body: >- + + + + + http://windows-host:5985/wsman + + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + + 153600 + uuid:00000000-0000-0000-0000-000000000003 + + + PT5S + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/cmd + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/Receive + + 620FED91-1B8A-4B8C-86E8-139D52DB6F9D + + + + + stdout stderr + + + + Response: + StatusCode: 500 + Headers: + Server: Microsoft-HTTPAPI/2.0 + Date: Fri, 16 Dec 2022 05:33:44 GMT + Body: >- + + + http://schemas.dmtf.org/wbem/wsman/1/wsman/fault + uuid:E1C9A090-A38B-4739-87A8-663CF2607F6A + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + uuid:00000000-0000-0000-0000-000000000003 + + + + + s:Receiver + + w:TimedOut + + + + The WS-Management service cannot complete the operation within the time specified in OperationTimeout. + + + + The WS-Management service cannot complete the operation within the time specified in OperationTimeout. + + + + + +- Request: + Method: POST + Url: https://4.154.47.156:5986/wsman + Headers: {} + Body: >- + + + + + http://windows-host:5985/wsman + + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + + 153600 + uuid:00000000-0000-0000-0000-000000000004 + + + PT5S + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/cmd + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/Receive + + 620FED91-1B8A-4B8C-86E8-139D52DB6F9D + + + + + stdout stderr + + + + Response: + StatusCode: 200 + Headers: + Server: Microsoft-HTTPAPI/2.0 + Date: Fri, 16 Dec 2022 05:33:44 GMT + Body: >- + + + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/ReceiveResponse + uuid:91ADCB58-CFF1-4792-9FDC-1423879195B0 + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + uuid:00000000-0000-0000-0000-000000000004 + + + + + + + 0 + + + + +- Request: + Method: POST + Url: https://4.154.47.156:5986/wsman + Headers: {} + Body: >- + + + + + http://windows-host:5985/wsman + + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + + 153600 + uuid:00000000-0000-0000-0000-000000000005 + + + PT5S + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/cmd + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/Signal + + 620FED91-1B8A-4B8C-86E8-139D52DB6F9D + + + + + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/signal/terminate + + + + Response: + StatusCode: 200 + Headers: + Server: Microsoft-HTTPAPI/2.0 + Date: Fri, 16 Dec 2022 05:33:44 GMT + Body: >- + + + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/SignalResponse + uuid:88866695-CBA1-464E-B4EE-511C79A46397 + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + uuid:00000000-0000-0000-0000-000000000005 + + + + + +- Request: + Method: POST + Url: https://4.154.47.156:5986/wsman + Headers: {} + Body: >- + + + + + http://windows-host:5985/wsman + + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + + 153600 + uuid:00000000-0000-0000-0000-000000000006 + + + PT5S + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/cmd + http://schemas.xmlsoap.org/ws/2004/09/transfer/Delete + + 620FED91-1B8A-4B8C-86E8-139D52DB6F9D + + + + + Response: + StatusCode: 200 + Headers: + Server: Microsoft-HTTPAPI/2.0 + Date: Fri, 16 Dec 2022 05:33:44 GMT + Body: >- + + + http://schemas.xmlsoap.org/ws/2004/09/transfer/DeleteResponse + uuid:4BD7E014-019B-4C54-98A1-8877F25CAA61 + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + uuid:00000000-0000-0000-0000-000000000006 + + + diff --git a/src/WinRMSharp.IntegrationTests/Sessions/RunCommandWithArgsAndCleanup.yml b/src/WinRMSharp.IntegrationTests/Sessions/RunCommandWithArgsAndCleanup.yml new file mode 100644 index 0000000..bc0827a --- /dev/null +++ b/src/WinRMSharp.IntegrationTests/Sessions/RunCommandWithArgsAndCleanup.yml @@ -0,0 +1,210 @@ +- Request: + Method: POST + Url: https://4.154.47.156:5986/wsman + Headers: {} + Body: >- + + + + + http://windows-host:5985/wsman + + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + + 153600 + uuid:00000000-0000-0000-0000-000000000000 + + + PT5S + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/cmd + http://schemas.xmlsoap.org/ws/2004/09/transfer/Create + + False + 437 + + + + + stdin + stdout stderr + + + + Response: + StatusCode: 200 + Headers: + Server: Microsoft-HTTPAPI/2.0 + Date: Fri, 16 Dec 2022 05:33:44 GMT + Body: >- + + + http://schemas.xmlsoap.org/ws/2004/09/transfer/CreateResponse + uuid:7808B8BE-99EF-4D7C-9B1D-DB1A20CD71A6 + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + uuid:00000000-0000-0000-0000-000000000000 + + + + http://windows-host:5985/wsman + + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/cmd + + 2A7E954A-DA86-4C5F-B365-B17E198E2065 + + + + + 2A7E954A-DA86-4C5F-B365-B17E198E2065 + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/cmd + winrm-vm-002\asuvpUser + 73.53.37.241 + PT7200.000S + stdin + stdout stderr + P0DT0H0M0S + P0DT0H0M0S + + + +- Request: + Method: POST + Url: https://4.154.47.156:5986/wsman + Headers: {} + Body: >- + + + + + http://windows-host:5985/wsman + + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + + 153600 + uuid:00000000-0000-0000-0000-000000000001 + + + PT5S + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/cmd + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/Command + + TRUE + FALSE + + + 2A7E954A-DA86-4C5F-B365-B17E198E2065 + + + + + ipconfig + /all + + + + Response: + StatusCode: 200 + Headers: + Server: Microsoft-HTTPAPI/2.0 + Date: Fri, 16 Dec 2022 05:33:44 GMT + Body: >- + + + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/CommandResponse + uuid:960197CF-699B-4819-A14D-CD0DF908C334 + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + uuid:00000000-0000-0000-0000-000000000001 + + + + 2E973D48-7599-40D0-83E5-6975E355E6FC + + + +- Request: + Method: POST + Url: https://4.154.47.156:5986/wsman + Headers: {} + Body: >- + + + + + http://windows-host:5985/wsman + + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + + 153600 + uuid:00000000-0000-0000-0000-000000000002 + + + PT5S + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/cmd + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/Signal + + 2A7E954A-DA86-4C5F-B365-B17E198E2065 + + + + + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/signal/terminate + + + + Response: + StatusCode: 200 + Headers: + Server: Microsoft-HTTPAPI/2.0 + Date: Fri, 16 Dec 2022 05:33:45 GMT + Body: >- + + + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/SignalResponse + uuid:0B291FE8-E6A4-4844-9C6A-F1583A29BD5F + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + uuid:00000000-0000-0000-0000-000000000002 + + + + + +- Request: + Method: POST + Url: https://4.154.47.156:5986/wsman + Headers: {} + Body: >- + + + + + http://windows-host:5985/wsman + + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + + 153600 + uuid:00000000-0000-0000-0000-000000000003 + + + PT5S + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/cmd + http://schemas.xmlsoap.org/ws/2004/09/transfer/Delete + + 2A7E954A-DA86-4C5F-B365-B17E198E2065 + + + + + Response: + StatusCode: 200 + Headers: + Server: Microsoft-HTTPAPI/2.0 + Date: Fri, 16 Dec 2022 05:33:45 GMT + Body: >- + + + http://schemas.xmlsoap.org/ws/2004/09/transfer/DeleteResponse + uuid:C32ADD76-AD56-4BB4-A689-EA8906CB48B4 + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + uuid:00000000-0000-0000-0000-000000000003 + + + diff --git a/src/WinRMSharp.IntegrationTests/Sessions/RunCommandWithEnv.yml b/src/WinRMSharp.IntegrationTests/Sessions/RunCommandWithEnv.yml new file mode 100644 index 0000000..ed6d956 --- /dev/null +++ b/src/WinRMSharp.IntegrationTests/Sessions/RunCommandWithEnv.yml @@ -0,0 +1,272 @@ +- Request: + Method: POST + Url: https://4.154.47.156:5986/wsman + Headers: {} + Body: >- + + + + + http://windows-host:5985/wsman + + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + + 153600 + uuid:00000000-0000-0000-0000-000000000000 + + + PT5S + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/cmd + http://schemas.xmlsoap.org/ws/2004/09/transfer/Create + + False + 437 + + + + + + hi mom + another var + + stdin + stdout stderr + + + + Response: + StatusCode: 200 + Headers: + Server: Microsoft-HTTPAPI/2.0 + Date: Fri, 16 Dec 2022 05:33:46 GMT + Body: >- + + + http://schemas.xmlsoap.org/ws/2004/09/transfer/CreateResponse + uuid:9F0C94D6-5ABA-4E1B-9D77-44D6F6244287 + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + uuid:00000000-0000-0000-0000-000000000000 + + + + http://windows-host:5985/wsman + + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/cmd + + D0DAEF17-5084-4B8A-9024-08114A98FDA6 + + + + + D0DAEF17-5084-4B8A-9024-08114A98FDA6 + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/cmd + winrm-vm-002\asuvpUser + 73.53.37.241 + + hi mom + another var + + PT7200.000S + stdin + stdout stderr + P0DT0H0M0S + P0DT0H0M0S + + + +- Request: + Method: POST + Url: https://4.154.47.156:5986/wsman + Headers: {} + Body: >- + + + + + http://windows-host:5985/wsman + + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + + 153600 + uuid:00000000-0000-0000-0000-000000000001 + + + PT5S + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/cmd + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/Command + + TRUE + FALSE + + + D0DAEF17-5084-4B8A-9024-08114A98FDA6 + + + + + echo + %TESTENV1% %TESTENV2% + + + + Response: + StatusCode: 200 + Headers: + Server: Microsoft-HTTPAPI/2.0 + Date: Fri, 16 Dec 2022 05:33:46 GMT + Body: >- + + + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/CommandResponse + uuid:6071CC0B-AF6A-4E98-945B-3A69D0438208 + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + uuid:00000000-0000-0000-0000-000000000001 + + + + 09667DEF-6F91-4786-9B60-8327BFA22D72 + + + +- Request: + Method: POST + Url: https://4.154.47.156:5986/wsman + Headers: {} + Body: >- + + + + + http://windows-host:5985/wsman + + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + + 153600 + uuid:00000000-0000-0000-0000-000000000002 + + + PT5S + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/cmd + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/Receive + + D0DAEF17-5084-4B8A-9024-08114A98FDA6 + + + + + stdout stderr + + + + Response: + StatusCode: 200 + Headers: + Server: Microsoft-HTTPAPI/2.0 + Date: Fri, 16 Dec 2022 05:33:46 GMT + Body: >- + + + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/ReceiveResponse + uuid:3F6730CD-438C-4211-8543-3C3E4DEBE775 + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + uuid:00000000-0000-0000-0000-000000000002 + + + + aGkgbW9tIGFub3RoZXIgdmFyDQo= + + + + 0 + + + + +- Request: + Method: POST + Url: https://4.154.47.156:5986/wsman + Headers: {} + Body: >- + + + + + http://windows-host:5985/wsman + + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + + 153600 + uuid:00000000-0000-0000-0000-000000000003 + + + PT5S + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/cmd + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/Signal + + D0DAEF17-5084-4B8A-9024-08114A98FDA6 + + + + + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/signal/terminate + + + + Response: + StatusCode: 200 + Headers: + Server: Microsoft-HTTPAPI/2.0 + Date: Fri, 16 Dec 2022 05:33:46 GMT + Body: >- + + + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/SignalResponse + uuid:E534754E-99C1-474E-B9B1-C0914A2BFB52 + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + uuid:00000000-0000-0000-0000-000000000003 + + + + + +- Request: + Method: POST + Url: https://4.154.47.156:5986/wsman + Headers: {} + Body: >- + + + + + http://windows-host:5985/wsman + + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + + 153600 + uuid:00000000-0000-0000-0000-000000000004 + + + PT5S + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/cmd + http://schemas.xmlsoap.org/ws/2004/09/transfer/Delete + + D0DAEF17-5084-4B8A-9024-08114A98FDA6 + + + + + Response: + StatusCode: 200 + Headers: + Server: Microsoft-HTTPAPI/2.0 + Date: Fri, 16 Dec 2022 05:33:46 GMT + Body: >- + + + http://schemas.xmlsoap.org/ws/2004/09/transfer/DeleteResponse + uuid:027C1593-A17D-447C-8BAB-EFAA977C416A + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + uuid:00000000-0000-0000-0000-000000000004 + + + diff --git a/src/WinRMSharp.IntegrationTests/Sessions/RunCommandWithoutArgsAndCleanup.yml b/src/WinRMSharp.IntegrationTests/Sessions/RunCommandWithoutArgsAndCleanup.yml new file mode 100644 index 0000000..885a625 --- /dev/null +++ b/src/WinRMSharp.IntegrationTests/Sessions/RunCommandWithoutArgsAndCleanup.yml @@ -0,0 +1,209 @@ +- Request: + Method: POST + Url: https://4.154.47.156:5986/wsman + Headers: {} + Body: >- + + + + + http://windows-host:5985/wsman + + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + + 153600 + uuid:00000000-0000-0000-0000-000000000000 + + + PT5S + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/cmd + http://schemas.xmlsoap.org/ws/2004/09/transfer/Create + + False + 437 + + + + + stdin + stdout stderr + + + + Response: + StatusCode: 200 + Headers: + Server: Microsoft-HTTPAPI/2.0 + Date: Fri, 16 Dec 2022 05:33:45 GMT + Body: >- + + + http://schemas.xmlsoap.org/ws/2004/09/transfer/CreateResponse + uuid:C01E0D13-8080-43D9-9466-ECDF0FF561CA + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + uuid:00000000-0000-0000-0000-000000000000 + + + + http://windows-host:5985/wsman + + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/cmd + + 3BF95A99-FD69-4164-8E36-BEA4B6031234 + + + + + 3BF95A99-FD69-4164-8E36-BEA4B6031234 + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/cmd + winrm-vm-002\asuvpUser + 73.53.37.241 + PT7200.000S + stdin + stdout stderr + P0DT0H0M0S + P0DT0H0M0S + + + +- Request: + Method: POST + Url: https://4.154.47.156:5986/wsman + Headers: {} + Body: >- + + + + + http://windows-host:5985/wsman + + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + + 153600 + uuid:00000000-0000-0000-0000-000000000001 + + + PT5S + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/cmd + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/Command + + TRUE + FALSE + + + 3BF95A99-FD69-4164-8E36-BEA4B6031234 + + + + + hostname + + + + Response: + StatusCode: 200 + Headers: + Server: Microsoft-HTTPAPI/2.0 + Date: Fri, 16 Dec 2022 05:33:45 GMT + Body: >- + + + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/CommandResponse + uuid:6749635D-A524-464C-8E76-3638C53B50AE + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + uuid:00000000-0000-0000-0000-000000000001 + + + + 137877FA-804C-4568-A931-BA15B216BDF3 + + + +- Request: + Method: POST + Url: https://4.154.47.156:5986/wsman + Headers: {} + Body: >- + + + + + http://windows-host:5985/wsman + + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + + 153600 + uuid:00000000-0000-0000-0000-000000000002 + + + PT5S + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/cmd + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/Signal + + 3BF95A99-FD69-4164-8E36-BEA4B6031234 + + + + + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/signal/terminate + + + + Response: + StatusCode: 200 + Headers: + Server: Microsoft-HTTPAPI/2.0 + Date: Fri, 16 Dec 2022 05:33:45 GMT + Body: >- + + + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/SignalResponse + uuid:73297E2C-9177-4BC0-B9F1-D6A901B43D60 + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + uuid:00000000-0000-0000-0000-000000000002 + + + + + +- Request: + Method: POST + Url: https://4.154.47.156:5986/wsman + Headers: {} + Body: >- + + + + + http://windows-host:5985/wsman + + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + + 153600 + uuid:00000000-0000-0000-0000-000000000003 + + + PT5S + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/cmd + http://schemas.xmlsoap.org/ws/2004/09/transfer/Delete + + 3BF95A99-FD69-4164-8E36-BEA4B6031234 + + + + + Response: + StatusCode: 200 + Headers: + Server: Microsoft-HTTPAPI/2.0 + Date: Fri, 16 Dec 2022 05:33:45 GMT + Body: >- + + + http://schemas.xmlsoap.org/ws/2004/09/transfer/DeleteResponse + uuid:D64B27EA-7D49-460A-8DCF-99C139F2F1D5 + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + uuid:00000000-0000-0000-0000-000000000003 + + + diff --git a/src/WinRMSharp.IntegrationTests/UnitProtocolTests.cs b/src/WinRMSharp.IntegrationTests/UnitProtocolTests.cs new file mode 100644 index 0000000..e97ee0e --- /dev/null +++ b/src/WinRMSharp.IntegrationTests/UnitProtocolTests.cs @@ -0,0 +1,34 @@ +using System.Net; +using WinRMSharp.IntegrationTests.Recording; + +namespace WinRMSharp.IntegrationTests +{ + public class UnitProtocolTests : BaseProtocolTests, IDisposable + { + private SessionManager _recordingManager = new SessionManager(); + + public void Dispose() + { + _recordingManager.Dispose(); + } + + public override Protocol GenerateProtocol(string sessionName) + { + string baseUrl = "https://127.0.0.1/wsman"; + string userName = "exampleUser"; + string password = "examplePassword"; + + DelegatingHandler handler = _recordingManager.GenerateSessionHandler(State.Playback, sessionName); + + ICredentials credentials = new NetworkCredential(userName, password); + ITransport transport = new Transport(baseUrl, handler, credentials); + + ProtocolOptions protocolOptions = new ProtocolOptions() + { + OperationTimeout = TimeSpan.FromSeconds(5) + }; + + return new Protocol(transport, new IncrementingGuidProvider(), protocolOptions); + } + } +} diff --git a/src/WinRMSharp.IntegrationTests/WinRMSharp.IntegrationTests.csproj b/src/WinRMSharp.IntegrationTests/WinRMSharp.IntegrationTests.csproj index 342d790..921ff5a 100644 --- a/src/WinRMSharp.IntegrationTests/WinRMSharp.IntegrationTests.csproj +++ b/src/WinRMSharp.IntegrationTests/WinRMSharp.IntegrationTests.csproj @@ -20,6 +20,7 @@ runtime; build; native; contentfiles; analyzers; buildtransitive all + @@ -27,6 +28,24 @@ + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + PreserveNewest diff --git a/src/WinRMSharp.IntegrationTests/test.runsettings b/src/WinRMSharp.IntegrationTests/test.runsettings index 718c267..7b1e4a0 100644 --- a/src/WinRMSharp.IntegrationTests/test.runsettings +++ b/src/WinRMSharp.IntegrationTests/test.runsettings @@ -2,9 +2,9 @@ - - - + https://4.154.47.156:5986 + asuvpUser + AdventureTime1 - \ No newline at end of file + diff --git a/src/WinRMSharp.Tests/BaseClientTests.cs b/src/WinRMSharp.Tests/BaseClientTests.cs new file mode 100644 index 0000000..1f7d31c --- /dev/null +++ b/src/WinRMSharp.Tests/BaseClientTests.cs @@ -0,0 +1,64 @@ +using Xunit; + +namespace WinRMSharp.Tests +{ + public abstract class BaseClientTests + { + [Fact] + public async Task ClientRunCommand() + { + WinRMClient client = GenerateClient(nameof(ClientRunCommand)); + + CommandState state = await client.RunCommand("dir"); + + Assert.NotNull(state); + Assert.Equal(0, state.StatusCode); + Assert.Contains("Volume in drive C", state.Stdout); + Assert.Empty(state.Stderr); + } + + [Fact] + public async Task ClientRunCommandWithArgs() + { + WinRMClient client = GenerateClient(nameof(ClientRunCommandWithArgs)); + + CommandState state = await client.RunCommand("echo", new string[] { "abc" }); + + Assert.NotNull(state); + Assert.Equal(0, state.StatusCode); + Assert.Equal("abc\r\n", state.Stdout); + Assert.Empty(state.Stderr); + } + + [Fact] + public async Task ClientRunCommandWithEnvironment() + { + WinRMClient client = GenerateClient(nameof(ClientRunCommandWithEnvironment)); + + Dictionary environment = new Dictionary() + { + { "string", "string value" }, + { "int", "1234" }, + { "bool", "true" }, + { "double_quote", "double \" quote" }, + { "single_quote", "string ' value" }, + { "hyphen - var", "abc @ 123" }, + }; + + CommandState state = await client.RunCommand("set", environment: environment); + + Assert.NotNull(state); + IDictionary actualEnvironment = state.Stdout.Split(Environment.NewLine, StringSplitOptions.RemoveEmptyEntries) + .Select(line => line.Split(new[] { '=' }, 2)) + .ToDictionary(parts => parts[0], parts => parts[1]); + + foreach (KeyValuePair kv in environment) + { + Assert.Contains(kv.Key, actualEnvironment); + Assert.Equal(kv.Value, actualEnvironment[kv.Key]); + } + } + + public abstract WinRMClient GenerateClient(string sessionName); + } +} diff --git a/src/WinRMSharp.Tests/BaseProtocolTests.cs b/src/WinRMSharp.Tests/BaseProtocolTests.cs new file mode 100644 index 0000000..57104b1 --- /dev/null +++ b/src/WinRMSharp.Tests/BaseProtocolTests.cs @@ -0,0 +1,179 @@ +using WinRMSharp.Contracts; +using WinRMSharp.Exceptions; +using Xunit; + +namespace WinRMSharp.Tests +{ + public abstract class BaseProtocolTests + { + [Fact] + public async Task ProtocolOpenCloseShell() + { + Protocol protocol = GenerateProtocol(nameof(ProtocolOpenCloseShell)); + + string shellId = await protocol.OpenShell(); + await protocol.CloseShell(shellId); + + Assert.Matches(@"^\w{8}-\w{4}-\w{4}-\w{4}-\w{12}$", shellId); + } + + [Fact] + public async Task ProtocolGetCommandStateBeforeRun() + { + Protocol protocol = GenerateProtocol(nameof(ProtocolGetCommandStateBeforeRun)); + + string shellId = await protocol.OpenShell(); + string commandId = "de969dd4-2798-4a3c-9d57-28c1da9b2aa3"; + + WSManFaultException wsManFault = await Assert.ThrowsAsync(async () => await protocol.GetCommandState(shellId, commandId)); + + Assert.Equal(Fault.INVALID_SELECTORS, wsManFault.Code); + Assert.Equal("windows-host", wsManFault.Machine); + Assert.Equal("The Windows Remote Shell received a request to perform an operation on a command identifier that does not exist. Either the command has completed execution or the client specified an invalid command identifier.", wsManFault.FaultMessage); + Assert.Equal("The WS-Management service cannot process the request because the request contained invalid selectors for the resource.", wsManFault.Reason); + } + + + [Fact] + public async Task ProtocolRunCommandWithArgsAndCleanup() + { + Protocol protocol = GenerateProtocol(nameof(ProtocolRunCommandWithArgsAndCleanup)); + + string shellId = await protocol.OpenShell(); + string commandId = await protocol.RunCommand(shellId, "ipconfig", new string[] { "/all" }); + + await protocol.CloseCommand(shellId, commandId); + await protocol.CloseShell(shellId); + + Assert.Matches(@"^\w{8}-\w{4}-\w{4}-\w{4}-\w{12}$", commandId); + } + + [Fact] + public async Task ProtocolRunCommandWithoutArgsAndCleanup() + { + Protocol protocol = GenerateProtocol(nameof(ProtocolRunCommandWithoutArgsAndCleanup)); + + string shellId = await protocol.OpenShell(); + string commandId = await protocol.RunCommand(shellId, "hostname"); + + await protocol.CloseCommand(shellId, commandId); + await protocol.CloseShell(shellId); + + Assert.Matches(@"^\w{8}-\w{4}-\w{4}-\w{4}-\w{12}$", commandId); + } + + [Fact] + public async Task ProtocolRunCommandWithEnv() + { + Protocol protocol = GenerateProtocol(nameof(ProtocolRunCommandWithEnv)); + + Dictionary envVars = new Dictionary() + { + { "TESTENV1", "hi mom" }, + { "TESTENV2", "another var" } + }; + + string shellId = await protocol.OpenShell(envVars: envVars); + string commandId = await protocol.RunCommand(shellId, "echo", new string[] { "%TESTENV1%", "%TESTENV2%" }); + + CommandState state = await protocol.PollCommandState(shellId, commandId); + + await protocol.CloseCommand(shellId, commandId); + await protocol.CloseShell(shellId); + + Assert.Matches(@"hi mom another var", state.Stdout); + } + + [Fact] + public async Task ProtocolRunCommandWithUnicode() + { + Protocol protocol = GenerateProtocol(nameof(ProtocolRunCommandWithUnicode)); + + string shellId = await protocol.OpenShell(codePage: 65001); + string commandId = await protocol.RunCommand(shellId, "powershell.exe", new string[] { "Write-Host こんにちは" }); + + CommandState state = await protocol.PollCommandState(shellId, commandId); + + await protocol.CloseCommand(shellId, commandId); + await protocol.CloseShell(shellId); + + Assert.Equal(0, state.StatusCode); + Assert.Equal("こんにちは\n", state.Stdout); + Assert.Equal(string.Empty, state.Stderr); + } + + [Fact] + public async Task ProtocolRunCommandWithNoProfile() + { + Protocol protocol = GenerateProtocol(nameof(ProtocolRunCommandWithNoProfile)); + + string shellId = await protocol.OpenShell(noProfile: true); + string commandId = await protocol.RunCommand(shellId, "cmd.exe", new string[] { "/c", "set" }); + + CommandState state = await protocol.PollCommandState(shellId, commandId); + + await protocol.CloseCommand(shellId, commandId); + await protocol.CloseShell(shellId); + + Assert.Equal(0, state.StatusCode); + Assert.Contains(state.Stdout.Split(Environment.NewLine), l => l.Contains("USERPROFILE=C:\\Users\\Default")); + Assert.Equal(string.Empty, state.Stderr); + } + + [Fact] + public async Task ProtocolGetCommandState() + { + Protocol protocol = GenerateProtocol(nameof(ProtocolGetCommandState)); + + string shellId = await protocol.OpenShell(); + string commandId = await protocol.RunCommand(shellId, "ipconfig", new string[] { "/all" }); + + CommandState state = await protocol.PollCommandState(shellId, commandId); + + await protocol.CloseCommand(shellId, commandId); + await protocol.CloseShell(shellId); + + Assert.Equal(0, state.StatusCode); + Assert.Contains(@"Windows IP Configuration", state.Stdout); + Assert.Equal(0, state.Stderr.Length); + } + + [Fact] + public async Task ProtocolRunCommandExceedingOperationTimeout() + { + Protocol protocol = GenerateProtocol(nameof(ProtocolRunCommandExceedingOperationTimeout)); + + string shellId = await protocol.OpenShell(); + string commandId = await protocol.RunCommand(shellId, $"powershell -Command Start-Sleep -s {protocol.OperationTimeout.TotalSeconds * 2}"); + + CommandState state = await protocol.PollCommandState(shellId, commandId); + + await protocol.CloseCommand(shellId, commandId); + await protocol.CloseShell(shellId); + + Assert.Equal(0, state.StatusCode); + Assert.Equal(0, state.Stderr.Length); + } + + [Fact] + public async Task ProtocolRunCommandWithCommandInput() + { + Protocol protocol = GenerateProtocol(nameof(ProtocolRunCommandWithCommandInput)); + + string shellId = await protocol.OpenShell(); + string commandId = await protocol.RunCommand(shellId, "cmd"); + await protocol.SendCommandInput(shellId, commandId, "echo \"hello world\" && exit\r\n"); + + CommandState state = await protocol.PollCommandState(shellId, commandId); + + await protocol.CloseCommand(shellId, commandId); + await protocol.CloseShell(shellId); + + Assert.Equal(0, state.StatusCode); + Assert.Contains("hello world", state.Stdout); + Assert.Empty(state.Stderr); + } + + public abstract Protocol GenerateProtocol(string sessionName); + } +} diff --git a/src/WinRMSharp.Tests/Data/Sessions/ClientRunCommand.yml b/src/WinRMSharp.Tests/Data/Sessions/ClientRunCommand.yml new file mode 100644 index 0000000..b13f606 --- /dev/null +++ b/src/WinRMSharp.Tests/Data/Sessions/ClientRunCommand.yml @@ -0,0 +1,261 @@ +- Request: + Method: POST + Url: https://127.0.0.1:5986/wsman + Headers: {} + Body: >- + + + + + http://windows-host:5985/wsman + + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + + 153600 + uuid:00000000-0000-0000-0000-000000000000 + + + PT5S + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/cmd + http://schemas.xmlsoap.org/ws/2004/09/transfer/Create + + + + + stdin + stdout stderr + + + + Response: + StatusCode: 200 + Headers: + Server: Microsoft-HTTPAPI/2.0 + Date: Fri, 16 Dec 2022 23:59:38 GMT + Body: >- + + + http://schemas.xmlsoap.org/ws/2004/09/transfer/CreateResponse + uuid:9FC98B52-52C4-4ED9-9012-85DB379BCFDE + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + uuid:00000000-0000-0000-0000-000000000000 + + + + http://windows-host:5985/wsman + + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/cmd + + ADA12553-794F-4424-A469-862987811A49 + + + + + ADA12553-794F-4424-A469-862987811A49 + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/cmd + winrm-vm-003\Default + 73.53.37.241 + PT7200.000S + stdin + stdout stderr + P0DT0H0M0S + P0DT0H0M0S + + + +- Request: + Method: POST + Url: https://127.0.0.1:5986/wsman + Headers: {} + Body: >- + + + + + http://windows-host:5985/wsman + + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + + 153600 + uuid:00000000-0000-0000-0000-000000000001 + + + PT5S + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/cmd + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/Command + + TRUE + FALSE + + + ADA12553-794F-4424-A469-862987811A49 + + + + + dir + + + + Response: + StatusCode: 200 + Headers: + Server: Microsoft-HTTPAPI/2.0 + Date: Fri, 16 Dec 2022 23:59:38 GMT + Body: >- + + + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/CommandResponse + uuid:77FC2295-5BB1-4580-9964-80FEA109DCBF + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + uuid:00000000-0000-0000-0000-000000000001 + + + + AF4A5D9F-66E7-443A-9D27-0B58632FBA3E + + + +- Request: + Method: POST + Url: https://127.0.0.1:5986/wsman + Headers: {} + Body: >- + + + + + http://windows-host:5985/wsman + + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + + 153600 + uuid:00000000-0000-0000-0000-000000000002 + + + PT5S + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/cmd + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/Receive + + ADA12553-794F-4424-A469-862987811A49 + + + + + stdout stderr + + + + Response: + StatusCode: 200 + Headers: + Server: Microsoft-HTTPAPI/2.0 + Date: Fri, 16 Dec 2022 23:59:38 GMT + Body: >- + + + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/ReceiveResponse + uuid:028A6385-434F-4B1A-848A-07A06CB78852 + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + uuid:00000000-0000-0000-0000-000000000002 + + + + IFZvbHVtZSBpbiBkcml2ZSBDIGlzIFdpbmRvd3MNCg== + IFZvbHVtZSBTZXJpYWwgTnVtYmVyIGlzIDA4MkYtNDg1Qw0KDQogRGlyZWN0b3J5IG9mIEM6XFVzZXJzXERlZmF1bHQud2lucm0tdm0tMDAzDQoNCjEyLzE2LzIwMjIgIDExOjU3IFBNICAgIDxESVI+ICAgICAgICAgIC4NCjEyLzE2LzIwMjIgIDExOjU3IFBNICAgIDxESVI+ICAgICAgICAgIC4uDQowNS8wNy8yMDIyICAwNToyNCBBTSAgICA8RElSPiAgICAgICAgICBEZXNrdG9wDQoxMi8xNi8yMDIyICAxMTo1NyBQTSAgICA8RElSPiAgICAgICAgICBEb2N1bWVudHMNCjA1LzA3LzIwMjIgIDA1OjI0IEFNICAgIDxESVI+ICAgICAgICAgIERvd25sb2Fkcw0KMDUvMDcvMjAyMiAgMDU6MjQgQU0gICAgPERJUj4gICAgICAgICAgRmF2b3JpdGVzDQowNS8wNy8yMDIyICAwNToyNCBBTSAgICA8RElSPiAgICAgICAgICBMaW5rcw0KMDUvMDcvMjAyMiAgMDU6MjQgQU0gICAgPERJUj4gICAgICAgICAgTXVzaWMNCjA1LzA3LzIwMjIgIDA1OjI0IEFNICAgIDxESVI+ICAgICAgICAgIFBpY3R1cmVzDQowNS8wNy8yMDIyICAwNToyNCBBTSAgICA8RElSPiAgICAgICAgICBTYXZlZCBHYW1lcw0KMDUvMDcvMjAyMiAgMDU6MjQgQU0gICAgPERJUj4gICAgICAgICAgVmlkZW9zDQogICAgICAgICAgICAgICAwIEZpbGUocykgICAgICAgICAgICAgIDAgYnl0ZXMNCiAgICAgICAgICAgICAgMTEgRGlyKHMpICAxMTYsNDI5LDIzNCwxNzYgYnl0ZXMgZnJlZQ0K + + + + 0 + + + + +- Request: + Method: POST + Url: https://127.0.0.1:5986/wsman + Headers: {} + Body: >- + + + + + http://windows-host:5985/wsman + + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + + 153600 + uuid:00000000-0000-0000-0000-000000000003 + + + PT5S + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/cmd + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/Signal + + ADA12553-794F-4424-A469-862987811A49 + + + + + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/signal/terminate + + + + Response: + StatusCode: 200 + Headers: + Server: Microsoft-HTTPAPI/2.0 + Date: Fri, 16 Dec 2022 23:59:38 GMT + Body: >- + + + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/SignalResponse + uuid:FAF71E83-B2A0-4AB4-BC3C-FDC4CAD6E4D4 + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + uuid:00000000-0000-0000-0000-000000000003 + + + + + +- Request: + Method: POST + Url: https://127.0.0.1:5986/wsman + Headers: {} + Body: >- + + + + + http://windows-host:5985/wsman + + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + + 153600 + uuid:00000000-0000-0000-0000-000000000004 + + + PT5S + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/cmd + http://schemas.xmlsoap.org/ws/2004/09/transfer/Delete + + ADA12553-794F-4424-A469-862987811A49 + + + + + Response: + StatusCode: 200 + Headers: + Server: Microsoft-HTTPAPI/2.0 + Date: Fri, 16 Dec 2022 23:59:38 GMT + Body: >- + + + http://schemas.xmlsoap.org/ws/2004/09/transfer/DeleteResponse + uuid:480B0078-7189-47C1-9AD8-D0D67C696F25 + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + uuid:00000000-0000-0000-0000-000000000004 + + + diff --git a/src/WinRMSharp.Tests/Data/Sessions/ClientRunCommandWithArgs.yml b/src/WinRMSharp.Tests/Data/Sessions/ClientRunCommandWithArgs.yml new file mode 100644 index 0000000..4d15fa1 --- /dev/null +++ b/src/WinRMSharp.Tests/Data/Sessions/ClientRunCommandWithArgs.yml @@ -0,0 +1,261 @@ +- Request: + Method: POST + Url: https://127.0.0.1:5986/wsman + Headers: {} + Body: >- + + + + + http://windows-host:5985/wsman + + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + + 153600 + uuid:00000000-0000-0000-0000-000000000000 + + + PT5S + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/cmd + http://schemas.xmlsoap.org/ws/2004/09/transfer/Create + + + + + stdin + stdout stderr + + + + Response: + StatusCode: 200 + Headers: + Server: Microsoft-HTTPAPI/2.0 + Date: Fri, 16 Dec 2022 23:59:38 GMT + Body: >- + + + http://schemas.xmlsoap.org/ws/2004/09/transfer/CreateResponse + uuid:A568D8E3-2202-405B-B95B-8667E66EA659 + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + uuid:00000000-0000-0000-0000-000000000000 + + + + http://windows-host:5985/wsman + + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/cmd + + 2D630342-CFB6-4460-A4A7-AC22EBC4865E + + + + + 2D630342-CFB6-4460-A4A7-AC22EBC4865E + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/cmd + winrm-vm-003\Default + 73.53.37.241 + PT7200.000S + stdin + stdout stderr + P0DT0H0M0S + P0DT0H0M0S + + + +- Request: + Method: POST + Url: https://127.0.0.1:5986/wsman + Headers: {} + Body: >- + + + + + http://windows-host:5985/wsman + + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + + 153600 + uuid:00000000-0000-0000-0000-000000000001 + + + PT5S + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/cmd + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/Command + + TRUE + FALSE + + + 2D630342-CFB6-4460-A4A7-AC22EBC4865E + + + + + echo + abc + + + + Response: + StatusCode: 200 + Headers: + Server: Microsoft-HTTPAPI/2.0 + Date: Fri, 16 Dec 2022 23:59:38 GMT + Body: >- + + + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/CommandResponse + uuid:025CB083-2C47-4749-A122-69A5621556CC + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + uuid:00000000-0000-0000-0000-000000000001 + + + + B780C900-E19A-4287-85C4-7FC5C30A522D + + + +- Request: + Method: POST + Url: https://127.0.0.1:5986/wsman + Headers: {} + Body: >- + + + + + http://windows-host:5985/wsman + + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + + 153600 + uuid:00000000-0000-0000-0000-000000000002 + + + PT5S + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/cmd + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/Receive + + 2D630342-CFB6-4460-A4A7-AC22EBC4865E + + + + + stdout stderr + + + + Response: + StatusCode: 200 + Headers: + Server: Microsoft-HTTPAPI/2.0 + Date: Fri, 16 Dec 2022 23:59:38 GMT + Body: >- + + + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/ReceiveResponse + uuid:B827A49A-DEAA-4109-A407-46AD802FD097 + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + uuid:00000000-0000-0000-0000-000000000002 + + + + YWJjDQo= + + + + 0 + + + + +- Request: + Method: POST + Url: https://127.0.0.1:5986/wsman + Headers: {} + Body: >- + + + + + http://windows-host:5985/wsman + + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + + 153600 + uuid:00000000-0000-0000-0000-000000000003 + + + PT5S + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/cmd + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/Signal + + 2D630342-CFB6-4460-A4A7-AC22EBC4865E + + + + + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/signal/terminate + + + + Response: + StatusCode: 200 + Headers: + Server: Microsoft-HTTPAPI/2.0 + Date: Fri, 16 Dec 2022 23:59:38 GMT + Body: >- + + + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/SignalResponse + uuid:3E58D368-CA53-498A-88B4-1CB39D7EF348 + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + uuid:00000000-0000-0000-0000-000000000003 + + + + + +- Request: + Method: POST + Url: https://127.0.0.1:5986/wsman + Headers: {} + Body: >- + + + + + http://windows-host:5985/wsman + + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + + 153600 + uuid:00000000-0000-0000-0000-000000000004 + + + PT5S + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/cmd + http://schemas.xmlsoap.org/ws/2004/09/transfer/Delete + + 2D630342-CFB6-4460-A4A7-AC22EBC4865E + + + + + Response: + StatusCode: 200 + Headers: + Server: Microsoft-HTTPAPI/2.0 + Date: Fri, 16 Dec 2022 23:59:38 GMT + Body: >- + + + http://schemas.xmlsoap.org/ws/2004/09/transfer/DeleteResponse + uuid:67A80C95-F4C9-4D0C-A537-B19F1358025E + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + uuid:00000000-0000-0000-0000-000000000004 + + + diff --git a/src/WinRMSharp.Tests/Data/Sessions/ClientRunCommandWithEnvironment.yml b/src/WinRMSharp.Tests/Data/Sessions/ClientRunCommandWithEnvironment.yml new file mode 100644 index 0000000..f4259f7 --- /dev/null +++ b/src/WinRMSharp.Tests/Data/Sessions/ClientRunCommandWithEnvironment.yml @@ -0,0 +1,277 @@ +- Request: + Method: POST + Url: https://127.0.0.1:5986/wsman + Headers: {} + Body: >- + + + + + http://windows-host:5985/wsman + + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + + 153600 + uuid:00000000-0000-0000-0000-000000000000 + + + PT5S + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/cmd + http://schemas.xmlsoap.org/ws/2004/09/transfer/Create + + + + + + string value + 1234 + true + double " quote + string ' value + abc @ 123 + + stdin + stdout stderr + + + + Response: + StatusCode: 200 + Headers: + Server: Microsoft-HTTPAPI/2.0 + Date: Fri, 16 Dec 2022 23:59:38 GMT + Body: >- + + + http://schemas.xmlsoap.org/ws/2004/09/transfer/CreateResponse + uuid:35B13C1F-F325-46A3-BD3E-186CEC0DF0CD + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + uuid:00000000-0000-0000-0000-000000000000 + + + + http://windows-host:5985/wsman + + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/cmd + + 96FCC80C-0E04-497F-B25B-A630558E1ADA + + + + + 96FCC80C-0E04-497F-B25B-A630558E1ADA + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/cmd + winrm-vm-003\Default + 73.53.37.241 + + string value + 1234 + true + double " quote + string ' value + abc @ 123 + + PT7200.000S + stdin + stdout stderr + P0DT0H0M0S + P0DT0H0M0S + + + +- Request: + Method: POST + Url: https://127.0.0.1:5986/wsman + Headers: {} + Body: >- + + + + + http://windows-host:5985/wsman + + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + + 153600 + uuid:00000000-0000-0000-0000-000000000001 + + + PT5S + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/cmd + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/Command + + TRUE + FALSE + + + 96FCC80C-0E04-497F-B25B-A630558E1ADA + + + + + set + + + + Response: + StatusCode: 200 + Headers: + Server: Microsoft-HTTPAPI/2.0 + Date: Fri, 16 Dec 2022 23:59:38 GMT + Body: >- + + + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/CommandResponse + uuid:D628EE66-CF3D-4387-8D99-21D84D9F2B1B + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + uuid:00000000-0000-0000-0000-000000000001 + + + + A9560A27-B60C-4DA6-9638-DD3A537339C4 + + + +- Request: + Method: POST + Url: https://127.0.0.1:5986/wsman + Headers: {} + Body: >- + + + + + http://windows-host:5985/wsman + + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + + 153600 + uuid:00000000-0000-0000-0000-000000000002 + + + PT5S + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/cmd + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/Receive + + 96FCC80C-0E04-497F-B25B-A630558E1ADA + + + + + stdout stderr + + + + Response: + StatusCode: 200 + Headers: + Server: Microsoft-HTTPAPI/2.0 + Date: Fri, 16 Dec 2022 23:59:38 GMT + Body: >- + + + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/ReceiveResponse + uuid:2563C946-DF21-4344-87D4-50836790B6A6 + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + uuid:00000000-0000-0000-0000-000000000002 + + + + QUxMVVNFUlNQUk9GSUxFPUM6XFByb2dyYW1EYXRhDQo= + QVBQREFUQT1DOlxVc2Vyc1xEZWZhdWx0LndpbnJtLXZtLTAwM1xBcHBEYXRhXFJvYW1pbmcNCmJvb2w9dHJ1ZQ0KQ29tbW9uUHJvZ3JhbUZpbGVzPUM6XFByb2dyYW0gRmlsZXNcQ29tbW9uIEZpbGVzDQpDb21tb25Qcm9ncmFtRmlsZXMoeDg2KT1DOlxQcm9ncmFtIEZpbGVzICh4ODYpXENvbW1vbiBGaWxlcw0KQ29tbW9uUHJvZ3JhbVc2NDMyPUM6XFByb2dyYW0gRmlsZXNcQ29tbW9uIEZpbGVzDQpDT01QVVRFUk5BTUU9d2lucm0tdm0tMDAzDQpDb21TcGVjPUM6XFdpbmRvd3Ncc3lzdGVtMzJcY21kLmV4ZQ0KZG91YmxlX3F1b3RlPWRvdWJsZSAiIHF1b3RlDQpEcml2ZXJEYXRhPUM6XFdpbmRvd3NcU3lzdGVtMzJcRHJpdmVyc1xEcml2ZXJEYXRhDQpoeXBoZW4gLSB2YXI9YWJjIEAgMTIzDQppbnQ9MTIzNA0KTE9DQUxBUFBEQVRBPUM6XFVzZXJzXERlZmF1bHQud2lucm0tdm0tMDAzXEFwcERhdGFcTG9jYWwNCk5VTUJFUl9PRl9QUk9DRVNTT1JTPTQNCk9TPVdpbmRvd3NfTlQNClBhdGg9QzpcV2luZG93c1xzeXN0ZW0zMjtDOlxXaW5kb3dzO0M6XFdpbmRvd3NcU3lzdGVtMzJcV2JlbTtDOlxXaW5kb3dzXFN5c3RlbTMyXFdpbmRvd3NQb3dlclNoZWxsXHYxLjBcO0M6XFdpbmRvd3NcU3lzdGVtMzJcT3BlblNTSFw7QzpcVXNlcnNcRGVmYXVsdC53aW5ybS12bS0wMDNcQXBwRGF0YVxMb2NhbFxNaWNyb3NvZnRcV2luZG93c0FwcHMNClBBVEhFWFQ9LkNPTTsuRVhFOy5CQVQ7LkNNRDsuVkJTOy5WQkU7LkpTOy5KU0U7LldTRjsuV1NIOy5NU0MNClBST0NFU1NPUl9BUkNISVRFQ1RVUkU9QU1ENjQNClBST0NFU1NPUl9JREVOVElGSUVSPUludGVsNjQgRmFtaWx5IDYgTW9kZWwgNjMgU3RlcHBpbmcgMiwgR2VudWluZUludGVsDQpQUk9DRVNTT1JfTEVWRUw9Ng0KUFJPQ0VTU09SX1JFVklTSU9OPTNmMDINClByb2dyYW1EYXRhPUM6XFByb2dyYW1EYXRhDQpQcm9ncmFtRmlsZXM9QzpcUHJvZ3JhbSBGaWxlcw0KUHJvZ3JhbUZpbGVzKHg4Nik9QzpcUHJvZ3JhbSBGaWxlcyAoeDg2KQ0KUHJvZ3JhbVc2NDMyPUM6XFByb2dyYW0gRmlsZXMNClBST01QVD0kUCRHDQpQU01vZHVsZVBhdGg9JVByb2dyYW1GaWxlcyVcV2luZG93c1Bvd2VyU2hlbGxcTW9kdWxlcztDOlxXaW5kb3dzXHN5c3RlbTMyXFdpbmRvd3NQb3dlclNoZWxsXHYxLjBcTW9kdWxlcw0KUFVCTElDPUM6XFVzZXJzXFB1YmxpYw0Kc2luZ2xlX3F1b3RlPXN0cmluZyAnIHZhbHVlDQpzdHJpbmc9c3RyaW5nIHZhbHVlDQpTeXN0ZW1Ecml2ZT1DOg0KU3lzdGVtUm9vdD1DOlxXaW5kb3dzDQpURU1QPUM6XFVzZXJzXERFRkFVTH4xLldJTlxBcHBEYXRhXExvY2FsXFRlbXANClRNUD1DOlxVc2Vyc1xERUZBVUx+MS5XSU5cQXBwRGF0YVxMb2NhbFxUZW1wDQpVU0VSRE9NQUlOPXdpbnJtLXZtLTAwMw0KVVNFUk5BTUU9RGVmYXVsdA0KVVNFUlBST0ZJTEU9QzpcVXNlcnNcRGVmYXVsdC53aW5ybS12bS0wMDMNCndpbmRpcj1DOlxXaW5kb3dzDQo= + + + + 0 + + + + +- Request: + Method: POST + Url: https://127.0.0.1:5986/wsman + Headers: {} + Body: >- + + + + + http://windows-host:5985/wsman + + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + + 153600 + uuid:00000000-0000-0000-0000-000000000003 + + + PT5S + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/cmd + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/Signal + + 96FCC80C-0E04-497F-B25B-A630558E1ADA + + + + + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/signal/terminate + + + + Response: + StatusCode: 200 + Headers: + Server: Microsoft-HTTPAPI/2.0 + Date: Fri, 16 Dec 2022 23:59:38 GMT + Body: >- + + + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/SignalResponse + uuid:9C467D40-E130-4F61-926C-82B27ECD2516 + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + uuid:00000000-0000-0000-0000-000000000003 + + + + + +- Request: + Method: POST + Url: https://127.0.0.1:5986/wsman + Headers: {} + Body: >- + + + + + http://windows-host:5985/wsman + + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + + 153600 + uuid:00000000-0000-0000-0000-000000000004 + + + PT5S + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/cmd + http://schemas.xmlsoap.org/ws/2004/09/transfer/Delete + + 96FCC80C-0E04-497F-B25B-A630558E1ADA + + + + + Response: + StatusCode: 200 + Headers: + Server: Microsoft-HTTPAPI/2.0 + Date: Fri, 16 Dec 2022 23:59:38 GMT + Body: >- + + + http://schemas.xmlsoap.org/ws/2004/09/transfer/DeleteResponse + uuid:75C7E57E-BFBA-4EF3-9570-97975D297855 + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + uuid:00000000-0000-0000-0000-000000000004 + + + diff --git a/src/WinRMSharp.Tests/Data/Sessions/ProtocolGetCommandState.yml b/src/WinRMSharp.Tests/Data/Sessions/ProtocolGetCommandState.yml new file mode 100644 index 0000000..6cb61be --- /dev/null +++ b/src/WinRMSharp.Tests/Data/Sessions/ProtocolGetCommandState.yml @@ -0,0 +1,264 @@ +- Request: + Method: POST + Url: https://127.0.0.1:5986/wsman + Headers: {} + Body: >- + + + + + http://windows-host:5985/wsman + + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + + 153600 + uuid:00000000-0000-0000-0000-000000000000 + + + PT5S + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/cmd + http://schemas.xmlsoap.org/ws/2004/09/transfer/Create + + + + + stdin + stdout stderr + + + + Response: + StatusCode: 200 + Headers: + Server: Microsoft-HTTPAPI/2.0 + Date: Fri, 16 Dec 2022 23:58:24 GMT + Body: >- + + + http://schemas.xmlsoap.org/ws/2004/09/transfer/CreateResponse + uuid:7D5D5112-EC2A-4ABE-BEC5-0180ED03A386 + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + uuid:00000000-0000-0000-0000-000000000000 + + + + http://windows-host:5985/wsman + + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/cmd + + 98C75EFA-2C96-4F0C-B6C4-2D761E4FFC0D + + + + + 98C75EFA-2C96-4F0C-B6C4-2D761E4FFC0D + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/cmd + winrm-vm-003\Default + 73.53.37.241 + PT7200.000S + stdin + stdout stderr + P0DT0H0M0S + P0DT0H0M0S + + + +- Request: + Method: POST + Url: https://127.0.0.1:5986/wsman + Headers: {} + Body: >- + + + + + http://windows-host:5985/wsman + + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + + 153600 + uuid:00000000-0000-0000-0000-000000000001 + + + PT5S + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/cmd + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/Command + + TRUE + FALSE + + + 98C75EFA-2C96-4F0C-B6C4-2D761E4FFC0D + + + + + ipconfig + /all + + + + Response: + StatusCode: 200 + Headers: + Server: Microsoft-HTTPAPI/2.0 + Date: Fri, 16 Dec 2022 23:58:24 GMT + Body: >- + + + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/CommandResponse + uuid:ACDD93E0-3D10-4F25-9F8A-AB5AC452EEDB + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + uuid:00000000-0000-0000-0000-000000000001 + + + + 6EC2051A-1EF6-47DA-BF4B-71D86A41B7F0 + + + +- Request: + Method: POST + Url: https://127.0.0.1:5986/wsman + Headers: {} + Body: >- + + + + + http://windows-host:5985/wsman + + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + + 153600 + uuid:00000000-0000-0000-0000-000000000002 + + + PT5S + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/cmd + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/Receive + + 98C75EFA-2C96-4F0C-B6C4-2D761E4FFC0D + + + + + stdout stderr + + + + Response: + StatusCode: 200 + Headers: + Server: Microsoft-HTTPAPI/2.0 + Date: Fri, 16 Dec 2022 23:58:24 GMT + Body: >- + + + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/ReceiveResponse + uuid:2EE32DC8-550F-4A8A-856F-EC1D166D4FC4 + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + uuid:00000000-0000-0000-0000-000000000002 + + + + DQpXaW5kb3dzIElQIENvbmZpZ3VyYXRpb24NCg0K + ICAgSG9zdCBOYW1lIC4gLiAuIC4gLiAuIC4gLiAuIC4gLiAuIDogd2lucm0tdm0tMDAzDQo= + ICAgUHJpbWFyeSBEbnMgU3VmZml4ICAuIC4gLiAuIC4gLiAuIDogDQogICBOb2RlIFR5cGUgLiAuIC4gLiAuIC4gLiAuIC4gLiAuIC4gOiBIeWJyaWQNCiAgIElQIFJvdXRpbmcgRW5hYmxlZC4gLiAuIC4gLiAuIC4gLiA6IE5vDQogICBXSU5TIFByb3h5IEVuYWJsZWQuIC4gLiAuIC4gLiAuIC4gOiBObw0KICAgRE5TIFN1ZmZpeCBTZWFyY2ggTGlzdC4gLiAuIC4gLiAuIDogMTEzem91dXNkMWR1dnBtbnNpcGFicG8ycGcueHguaW50ZXJuYWwuY2xvdWRhcHAubmV0DQo= + DQpFdGhlcm5ldCBhZGFwdGVyIEV0aGVybmV0Og0KDQogICBDb25uZWN0aW9uLXNwZWNpZmljIEROUyBTdWZmaXggIC4gOiAxMTN6b3V1c2QxZHV2cG1uc2lwYWJwbzJwZy54eC5pbnRlcm5hbC5jbG91ZGFwcC5uZXQNCiAgIERlc2NyaXB0aW9uIC4gLiAuIC4gLiAuIC4gLiAuIC4gLiA6IE1pY3Jvc29mdCBIeXBlci1WIE5ldHdvcmsgQWRhcHRlcg0KICAgUGh5c2ljYWwgQWRkcmVzcy4gLiAuIC4gLiAuIC4gLiAuIDogMDAtMEQtM0EtRkItRUYtMjINCiAgIERIQ1AgRW5hYmxlZC4gLiAuIC4gLiAuIC4gLiAuIC4gLiA6IFllcw0KICAgQXV0b2NvbmZpZ3VyYXRpb24gRW5hYmxlZCAuIC4gLiAuIDogWWVzDQogICBMaW5rLWxvY2FsIElQdjYgQWRkcmVzcyAuIC4gLiAuIC4gOiBmZTgwOjoxM2I3OjRjYWM6ZjQyOTo4ZDIwJTYoUHJlZmVycmVkKSANCiAgIElQdjQgQWRkcmVzcy4gLiAuIC4gLiAuIC4gLiAuIC4gLiA6IDEwLjAuMC40KFByZWZlcnJlZCkgDQogICBTdWJuZXQgTWFzayAuIC4gLiAuIC4gLiAuIC4gLiAuIC4gOiAyNTUuMjU1LjI1NS4wDQogICBMZWFzZSBPYnRhaW5lZC4gLiAuIC4gLiAuIC4gLiAuIC4gOiBGcmlkYXksIERlY2VtYmVyIDE2LCAyMDIyIDExOjU2OjI2IFBNDQogICBMZWFzZSBFeHBpcmVzIC4gLiAuIC4gLiAuIC4gLiAuIC4gOiBUdWVzZGF5LCBKYW51YXJ5IDIzLCAyMTU5IDY6MjY6NDAgQU0NCiAgIERlZmF1bHQgR2F0ZXdheSAuIC4gLiAuIC4gLiAuIC4gLiA6IDEwLjAuMC4xDQogICBESENQIFNlcnZlciAuIC4gLiAuIC4gLiAuIC4gLiAuIC4gOiAxNjguNjMuMTI5LjE2DQogICBESENQdjYgSUFJRCAuIC4gLiAuIC4gLiAuIC4gLiAuIC4gOiAxMDA2NjY2ODINCiAgIERIQ1B2NiBDbGllbnQgRFVJRC4gLiAuIC4gLiAuIC4gLiA6IDAwLTAxLTAwLTAxLTJCLTJFLUJFLTAyLTAwLTBELTNBLUZCLUVGLTIyDQogICBETlMgU2VydmVycyAuIC4gLiAuIC4gLiAuIC4gLiAuIC4gOiAxNjguNjMuMTI5LjE2DQogICBOZXRCSU9TIG92ZXIgVGNwaXAuIC4gLiAuIC4gLiAuIC4gOiBFbmFibGVkDQo= + + + + 0 + + + + +- Request: + Method: POST + Url: https://127.0.0.1:5986/wsman + Headers: {} + Body: >- + + + + + http://windows-host:5985/wsman + + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + + 153600 + uuid:00000000-0000-0000-0000-000000000003 + + + PT5S + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/cmd + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/Signal + + 98C75EFA-2C96-4F0C-B6C4-2D761E4FFC0D + + + + + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/signal/terminate + + + + Response: + StatusCode: 200 + Headers: + Server: Microsoft-HTTPAPI/2.0 + Date: Fri, 16 Dec 2022 23:58:24 GMT + Body: >- + + + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/SignalResponse + uuid:6AAEBCF8-74DD-4CE7-9644-612440B55604 + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + uuid:00000000-0000-0000-0000-000000000003 + + + + + +- Request: + Method: POST + Url: https://127.0.0.1:5986/wsman + Headers: {} + Body: >- + + + + + http://windows-host:5985/wsman + + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + + 153600 + uuid:00000000-0000-0000-0000-000000000004 + + + PT5S + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/cmd + http://schemas.xmlsoap.org/ws/2004/09/transfer/Delete + + 98C75EFA-2C96-4F0C-B6C4-2D761E4FFC0D + + + + + Response: + StatusCode: 200 + Headers: + Server: Microsoft-HTTPAPI/2.0 + Date: Fri, 16 Dec 2022 23:58:24 GMT + Body: >- + + + http://schemas.xmlsoap.org/ws/2004/09/transfer/DeleteResponse + uuid:6F2C55EE-3096-4467-8F9D-AE4D3A4E1BDB + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + uuid:00000000-0000-0000-0000-000000000004 + + + diff --git a/src/WinRMSharp.Tests/Data/Sessions/ProtocolGetCommandStateBeforeRun.yml b/src/WinRMSharp.Tests/Data/Sessions/ProtocolGetCommandStateBeforeRun.yml new file mode 100644 index 0000000..8c1e422 --- /dev/null +++ b/src/WinRMSharp.Tests/Data/Sessions/ProtocolGetCommandStateBeforeRun.yml @@ -0,0 +1,128 @@ +- Request: + Method: POST + Url: https://127.0.0.1:5986/wsman + Headers: {} + Body: >- + + + + + http://windows-host:5985/wsman + + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + + 153600 + uuid:00000000-0000-0000-0000-000000000000 + + + PT5S + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/cmd + http://schemas.xmlsoap.org/ws/2004/09/transfer/Create + + + + + stdin + stdout stderr + + + + Response: + StatusCode: 200 + Headers: + Server: Microsoft-HTTPAPI/2.0 + Date: Fri, 16 Dec 2022 23:58:26 GMT + Body: >- + + + http://schemas.xmlsoap.org/ws/2004/09/transfer/CreateResponse + uuid:A9544914-E5A9-4416-AED3-4F07A994335A + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + uuid:00000000-0000-0000-0000-000000000000 + + + + http://windows-host:5985/wsman + + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/cmd + + 14A5BF64-8F72-45BA-8DC3-28AF35241444 + + + + + 14A5BF64-8F72-45BA-8DC3-28AF35241444 + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/cmd + winrm-vm-003\Default + 73.53.37.241 + PT7200.000S + stdin + stdout stderr + P0DT0H0M0S + P0DT0H0M0S + + + +- Request: + Method: POST + Url: https://127.0.0.1:5986/wsman + Headers: {} + Body: >- + + + + + http://windows-host:5985/wsman + + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + + 153600 + uuid:00000000-0000-0000-0000-000000000001 + + + PT5S + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/cmd + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/Receive + + 14A5BF64-8F72-45BA-8DC3-28AF35241444 + + + + + stdout stderr + + + + Response: + StatusCode: 500 + Headers: + Server: Microsoft-HTTPAPI/2.0 + Date: Fri, 16 Dec 2022 23:58:26 GMT + Body: >- + + + http://schemas.dmtf.org/wbem/wsman/1/wsman/fault + uuid:672DBF8D-53A4-42F1-94A8-110E11BEDF04 + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + uuid:00000000-0000-0000-0000-000000000001 + + + + + s:Sender + + w:InvalidSelectors + + + + The WS-Management service cannot process the request because the request contained invalid selectors for the resource. + + + http://schemas.dmtf.org/wbem/wsman/1/wsman/faultDetail/UnexpectedSelectors + + The Windows Remote Shell received a request to perform an operation on a command identifier that does not exist. Either the command has completed execution or the client specified an invalid command identifier. + + + + + diff --git a/src/WinRMSharp.Tests/Data/Sessions/ProtocolOpenCloseShell.yml b/src/WinRMSharp.Tests/Data/Sessions/ProtocolOpenCloseShell.yml new file mode 100644 index 0000000..6a9d3fa --- /dev/null +++ b/src/WinRMSharp.Tests/Data/Sessions/ProtocolOpenCloseShell.yml @@ -0,0 +1,106 @@ +- Request: + Method: POST + Url: https://127.0.0.1:5986/wsman + Headers: {} + Body: >- + + + + + http://windows-host:5985/wsman + + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + + 153600 + uuid:00000000-0000-0000-0000-000000000000 + + + PT5S + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/cmd + http://schemas.xmlsoap.org/ws/2004/09/transfer/Create + + + + + stdin + stdout stderr + + + + Response: + StatusCode: 200 + Headers: + Server: Microsoft-HTTPAPI/2.0 + Date: Fri, 16 Dec 2022 23:58:24 GMT + Body: >- + + + http://schemas.xmlsoap.org/ws/2004/09/transfer/CreateResponse + uuid:3BF51F2E-EE37-4F0F-9DFF-29726C7E4BB0 + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + uuid:00000000-0000-0000-0000-000000000000 + + + + http://windows-host:5985/wsman + + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/cmd + + 8552200B-8CA3-4FF5-8236-3384D727C7F4 + + + + + 8552200B-8CA3-4FF5-8236-3384D727C7F4 + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/cmd + winrm-vm-003\Default + 73.53.37.241 + PT7200.000S + stdin + stdout stderr + P0DT0H0M0S + P0DT0H0M0S + + + +- Request: + Method: POST + Url: https://127.0.0.1:5986/wsman + Headers: {} + Body: >- + + + + + http://windows-host:5985/wsman + + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + + 153600 + uuid:00000000-0000-0000-0000-000000000001 + + + PT5S + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/cmd + http://schemas.xmlsoap.org/ws/2004/09/transfer/Delete + + 8552200B-8CA3-4FF5-8236-3384D727C7F4 + + + + + Response: + StatusCode: 200 + Headers: + Server: Microsoft-HTTPAPI/2.0 + Date: Fri, 16 Dec 2022 23:58:24 GMT + Body: >- + + + http://schemas.xmlsoap.org/ws/2004/09/transfer/DeleteResponse + uuid:D91F49A9-5112-4ECF-8BD8-59A9FBC490B4 + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + uuid:00000000-0000-0000-0000-000000000001 + + + diff --git a/src/WinRMSharp.Tests/Data/Sessions/ProtocolRunCommandExceedingOperationTimeout.yml b/src/WinRMSharp.Tests/Data/Sessions/ProtocolRunCommandExceedingOperationTimeout.yml new file mode 100644 index 0000000..4b3d130 --- /dev/null +++ b/src/WinRMSharp.Tests/Data/Sessions/ProtocolRunCommandExceedingOperationTimeout.yml @@ -0,0 +1,383 @@ +- Request: + Method: POST + Url: https://127.0.0.1:5986/wsman + Headers: {} + Body: >- + + + + + http://windows-host:5985/wsman + + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + + 153600 + uuid:00000000-0000-0000-0000-000000000000 + + + PT5S + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/cmd + http://schemas.xmlsoap.org/ws/2004/09/transfer/Create + + + + + stdin + stdout stderr + + + + Response: + StatusCode: 200 + Headers: + Server: Microsoft-HTTPAPI/2.0 + Date: Fri, 16 Dec 2022 23:58:13 GMT + Body: >- + + + http://schemas.xmlsoap.org/ws/2004/09/transfer/CreateResponse + uuid:CAE3FD0A-7164-4DED-9E68-326AA6DC2BC4 + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + uuid:00000000-0000-0000-0000-000000000000 + + + + http://windows-host:5985/wsman + + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/cmd + + D8086E35-5A08-4AE1-BD63-F8AECD5C617C + + + + + D8086E35-5A08-4AE1-BD63-F8AECD5C617C + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/cmd + winrm-vm-003\Default + 73.53.37.241 + PT7200.000S + stdin + stdout stderr + P0DT0H0M0S + P0DT0H0M0S + + + +- Request: + Method: POST + Url: https://127.0.0.1:5986/wsman + Headers: {} + Body: >- + + + + + http://windows-host:5985/wsman + + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + + 153600 + uuid:00000000-0000-0000-0000-000000000001 + + + PT5S + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/cmd + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/Command + + TRUE + FALSE + + + D8086E35-5A08-4AE1-BD63-F8AECD5C617C + + + + + powershell -Command Start-Sleep -s 10 + + + + Response: + StatusCode: 200 + Headers: + Server: Microsoft-HTTPAPI/2.0 + Date: Fri, 16 Dec 2022 23:58:13 GMT + Body: >- + + + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/CommandResponse + uuid:F91766B1-EF7E-44E0-84EE-E5733F53D658 + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + uuid:00000000-0000-0000-0000-000000000001 + + + + 2FD3100F-7643-42A3-B478-E16A1EFAEFDF + + + +- Request: + Method: POST + Url: https://127.0.0.1:5986/wsman + Headers: {} + Body: >- + + + + + http://windows-host:5985/wsman + + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + + 153600 + uuid:00000000-0000-0000-0000-000000000002 + + + PT5S + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/cmd + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/Receive + + D8086E35-5A08-4AE1-BD63-F8AECD5C617C + + + + + stdout stderr + + + + Response: + StatusCode: 500 + Headers: + Server: Microsoft-HTTPAPI/2.0 + Date: Fri, 16 Dec 2022 23:58:18 GMT + Body: >- + + + http://schemas.dmtf.org/wbem/wsman/1/wsman/fault + uuid:D712A3C6-22A6-44A8-BD3B-ADC9D2CDEA4C + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + uuid:00000000-0000-0000-0000-000000000002 + + + + + s:Receiver + + w:TimedOut + + + + The WS-Management service cannot complete the operation within the time specified in OperationTimeout. + + + + The WS-Management service cannot complete the operation within the time specified in OperationTimeout. + + + + + +- Request: + Method: POST + Url: https://127.0.0.1:5986/wsman + Headers: {} + Body: >- + + + + + http://windows-host:5985/wsman + + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + + 153600 + uuid:00000000-0000-0000-0000-000000000003 + + + PT5S + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/cmd + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/Receive + + D8086E35-5A08-4AE1-BD63-F8AECD5C617C + + + + + stdout stderr + + + + Response: + StatusCode: 500 + Headers: + Server: Microsoft-HTTPAPI/2.0 + Date: Fri, 16 Dec 2022 23:58:23 GMT + Body: >- + + + http://schemas.dmtf.org/wbem/wsman/1/wsman/fault + uuid:690E015D-629F-4EC5-910B-7E55F3A61FE8 + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + uuid:00000000-0000-0000-0000-000000000003 + + + + + s:Receiver + + w:TimedOut + + + + The WS-Management service cannot complete the operation within the time specified in OperationTimeout. + + + + The WS-Management service cannot complete the operation within the time specified in OperationTimeout. + + + + + +- Request: + Method: POST + Url: https://127.0.0.1:5986/wsman + Headers: {} + Body: >- + + + + + http://windows-host:5985/wsman + + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + + 153600 + uuid:00000000-0000-0000-0000-000000000004 + + + PT5S + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/cmd + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/Receive + + D8086E35-5A08-4AE1-BD63-F8AECD5C617C + + + + + stdout stderr + + + + Response: + StatusCode: 200 + Headers: + Server: Microsoft-HTTPAPI/2.0 + Date: Fri, 16 Dec 2022 23:58:23 GMT + Body: >- + + + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/ReceiveResponse + uuid:F51B5563-59F3-4A38-A298-7741253E37EE + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + uuid:00000000-0000-0000-0000-000000000004 + + + + + + + 0 + + + + +- Request: + Method: POST + Url: https://127.0.0.1:5986/wsman + Headers: {} + Body: >- + + + + + http://windows-host:5985/wsman + + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + + 153600 + uuid:00000000-0000-0000-0000-000000000005 + + + PT5S + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/cmd + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/Signal + + D8086E35-5A08-4AE1-BD63-F8AECD5C617C + + + + + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/signal/terminate + + + + Response: + StatusCode: 200 + Headers: + Server: Microsoft-HTTPAPI/2.0 + Date: Fri, 16 Dec 2022 23:58:23 GMT + Body: >- + + + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/SignalResponse + uuid:353BF7C2-8CD1-4C4B-9513-30A7EA6B1D73 + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + uuid:00000000-0000-0000-0000-000000000005 + + + + + +- Request: + Method: POST + Url: https://127.0.0.1:5986/wsman + Headers: {} + Body: >- + + + + + http://windows-host:5985/wsman + + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + + 153600 + uuid:00000000-0000-0000-0000-000000000006 + + + PT5S + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/cmd + http://schemas.xmlsoap.org/ws/2004/09/transfer/Delete + + D8086E35-5A08-4AE1-BD63-F8AECD5C617C + + + + + Response: + StatusCode: 200 + Headers: + Server: Microsoft-HTTPAPI/2.0 + Date: Fri, 16 Dec 2022 23:58:23 GMT + Body: >- + + + http://schemas.xmlsoap.org/ws/2004/09/transfer/DeleteResponse + uuid:66780406-8C6B-4F0A-AF43-97D14A36B3FF + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + uuid:00000000-0000-0000-0000-000000000006 + + + diff --git a/src/WinRMSharp.Tests/Data/Sessions/ProtocolRunCommandWithArgsAndCleanup.yml b/src/WinRMSharp.Tests/Data/Sessions/ProtocolRunCommandWithArgsAndCleanup.yml new file mode 100644 index 0000000..296fadc --- /dev/null +++ b/src/WinRMSharp.Tests/Data/Sessions/ProtocolRunCommandWithArgsAndCleanup.yml @@ -0,0 +1,207 @@ +- Request: + Method: POST + Url: https://127.0.0.1:5986/wsman + Headers: {} + Body: >- + + + + + http://windows-host:5985/wsman + + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + + 153600 + uuid:00000000-0000-0000-0000-000000000000 + + + PT5S + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/cmd + http://schemas.xmlsoap.org/ws/2004/09/transfer/Create + + + + + stdin + stdout stderr + + + + Response: + StatusCode: 200 + Headers: + Server: Microsoft-HTTPAPI/2.0 + Date: Fri, 16 Dec 2022 23:58:25 GMT + Body: >- + + + http://schemas.xmlsoap.org/ws/2004/09/transfer/CreateResponse + uuid:C8425FD9-0FC6-4010-A8C1-2E081AD1FE9A + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + uuid:00000000-0000-0000-0000-000000000000 + + + + http://windows-host:5985/wsman + + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/cmd + + 2EF84C5D-6F72-4973-AFEE-37DF1C0E5304 + + + + + 2EF84C5D-6F72-4973-AFEE-37DF1C0E5304 + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/cmd + winrm-vm-003\Default + 73.53.37.241 + PT7200.000S + stdin + stdout stderr + P0DT0H0M0S + P0DT0H0M0S + + + +- Request: + Method: POST + Url: https://127.0.0.1:5986/wsman + Headers: {} + Body: >- + + + + + http://windows-host:5985/wsman + + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + + 153600 + uuid:00000000-0000-0000-0000-000000000001 + + + PT5S + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/cmd + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/Command + + TRUE + FALSE + + + 2EF84C5D-6F72-4973-AFEE-37DF1C0E5304 + + + + + ipconfig + /all + + + + Response: + StatusCode: 200 + Headers: + Server: Microsoft-HTTPAPI/2.0 + Date: Fri, 16 Dec 2022 23:58:25 GMT + Body: >- + + + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/CommandResponse + uuid:FAFF66C1-479D-4DCC-905D-5607660FC66E + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + uuid:00000000-0000-0000-0000-000000000001 + + + + FFB11272-9339-44D4-BBBC-22B9C5CEEFF7 + + + +- Request: + Method: POST + Url: https://127.0.0.1:5986/wsman + Headers: {} + Body: >- + + + + + http://windows-host:5985/wsman + + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + + 153600 + uuid:00000000-0000-0000-0000-000000000002 + + + PT5S + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/cmd + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/Signal + + 2EF84C5D-6F72-4973-AFEE-37DF1C0E5304 + + + + + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/signal/terminate + + + + Response: + StatusCode: 200 + Headers: + Server: Microsoft-HTTPAPI/2.0 + Date: Fri, 16 Dec 2022 23:58:25 GMT + Body: >- + + + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/SignalResponse + uuid:3DE91DCF-362F-4C7B-8F6B-78D4A571EF73 + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + uuid:00000000-0000-0000-0000-000000000002 + + + + + +- Request: + Method: POST + Url: https://127.0.0.1:5986/wsman + Headers: {} + Body: >- + + + + + http://windows-host:5985/wsman + + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + + 153600 + uuid:00000000-0000-0000-0000-000000000003 + + + PT5S + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/cmd + http://schemas.xmlsoap.org/ws/2004/09/transfer/Delete + + 2EF84C5D-6F72-4973-AFEE-37DF1C0E5304 + + + + + Response: + StatusCode: 200 + Headers: + Server: Microsoft-HTTPAPI/2.0 + Date: Fri, 16 Dec 2022 23:58:25 GMT + Body: >- + + + http://schemas.xmlsoap.org/ws/2004/09/transfer/DeleteResponse + uuid:4C704745-62D8-44C2-BF89-C4FFA8037012 + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + uuid:00000000-0000-0000-0000-000000000003 + + + diff --git a/src/WinRMSharp.Tests/Data/Sessions/ProtocolRunCommandWithCommandInput.yml b/src/WinRMSharp.Tests/Data/Sessions/ProtocolRunCommandWithCommandInput.yml new file mode 100644 index 0000000..75be790 --- /dev/null +++ b/src/WinRMSharp.Tests/Data/Sessions/ProtocolRunCommandWithCommandInput.yml @@ -0,0 +1,308 @@ +- Request: + Method: POST + Url: https://127.0.0.1:5986/wsman + Headers: {} + Body: >- + + + + + http://windows-host:5985/wsman + + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + + 153600 + uuid:00000000-0000-0000-0000-000000000000 + + + PT5S + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/cmd + http://schemas.xmlsoap.org/ws/2004/09/transfer/Create + + + + + stdin + stdout stderr + + + + Response: + StatusCode: 200 + Headers: + Server: Microsoft-HTTPAPI/2.0 + Date: Fri, 16 Dec 2022 23:58:26 GMT + Body: >- + + + http://schemas.xmlsoap.org/ws/2004/09/transfer/CreateResponse + uuid:AFAE0A96-6EA3-47FB-8634-DC7E15D164DC + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + uuid:00000000-0000-0000-0000-000000000000 + + + + http://windows-host:5985/wsman + + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/cmd + + C36757C5-D911-4791-9C7B-D9D4FDD063F7 + + + + + C36757C5-D911-4791-9C7B-D9D4FDD063F7 + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/cmd + winrm-vm-003\Default + 73.53.37.241 + PT7200.000S + stdin + stdout stderr + P0DT0H0M0S + P0DT0H0M0S + + + +- Request: + Method: POST + Url: https://127.0.0.1:5986/wsman + Headers: {} + Body: >- + + + + + http://windows-host:5985/wsman + + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + + 153600 + uuid:00000000-0000-0000-0000-000000000001 + + + PT5S + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/cmd + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/Command + + TRUE + FALSE + + + C36757C5-D911-4791-9C7B-D9D4FDD063F7 + + + + + cmd + + + + Response: + StatusCode: 200 + Headers: + Server: Microsoft-HTTPAPI/2.0 + Date: Fri, 16 Dec 2022 23:58:26 GMT + Body: >- + + + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/CommandResponse + uuid:AA769425-D805-480C-8ACC-5357048BF379 + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + uuid:00000000-0000-0000-0000-000000000001 + + + + C535FE48-3E73-43C5-AF62-4DFE4A7851CD + + + +- Request: + Method: POST + Url: https://127.0.0.1:5986/wsman + Headers: {} + Body: >- + + + + + http://windows-host:5985/wsman + + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + + 153600 + uuid:00000000-0000-0000-0000-000000000002 + + + PT5S + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/cmd + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/Send + + C36757C5-D911-4791-9C7B-D9D4FDD063F7 + + + + + ZWNobyAiaGVsbG8gd29ybGQiICYmIGV4aXQNCg== + + + + Response: + StatusCode: 200 + Headers: + Server: Microsoft-HTTPAPI/2.0 + Date: Fri, 16 Dec 2022 23:58:26 GMT + Body: >- + + + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/SendResponse + uuid:4C424E3F-D6CC-4916-B4AB-CBAB6EDC03B8 + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + uuid:00000000-0000-0000-0000-000000000002 + + + + + +- Request: + Method: POST + Url: https://127.0.0.1:5986/wsman + Headers: {} + Body: >- + + + + + http://windows-host:5985/wsman + + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + + 153600 + uuid:00000000-0000-0000-0000-000000000003 + + + PT5S + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/cmd + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/Receive + + C36757C5-D911-4791-9C7B-D9D4FDD063F7 + + + + + stdout stderr + + + + Response: + StatusCode: 200 + Headers: + Server: Microsoft-HTTPAPI/2.0 + Date: Fri, 16 Dec 2022 23:58:26 GMT + Body: >- + + + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/ReceiveResponse + uuid:837C39DB-0427-473B-A8AC-379CC58B81EA + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + uuid:00000000-0000-0000-0000-000000000003 + + + + TWljcm9zb2Z0IFdpbmRvd3MgW1ZlcnNpb24gMTAuMC4yMjYyMS45NjNd + DQooYykgTWljcm9zb2Z0IENvcnBvcmF0aW9uLiBBbGwgcmlnaHRzIHJlc2VydmVkLg0KDQpDOlxVc2Vyc1xEZWZhdWx0LndpbnJtLXZtLTAwMz5lY2hvICJoZWxsbyB3b3JsZCIgJiYgZXhpdA0KImhlbGxvIHdvcmxkIiANCg== + + + + 0 + + + + +- Request: + Method: POST + Url: https://127.0.0.1:5986/wsman + Headers: {} + Body: >- + + + + + http://windows-host:5985/wsman + + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + + 153600 + uuid:00000000-0000-0000-0000-000000000004 + + + PT5S + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/cmd + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/Signal + + C36757C5-D911-4791-9C7B-D9D4FDD063F7 + + + + + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/signal/terminate + + + + Response: + StatusCode: 200 + Headers: + Server: Microsoft-HTTPAPI/2.0 + Date: Fri, 16 Dec 2022 23:58:26 GMT + Body: >- + + + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/SignalResponse + uuid:76106A4F-CD07-4886-A363-062CE624E831 + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + uuid:00000000-0000-0000-0000-000000000004 + + + + + +- Request: + Method: POST + Url: https://127.0.0.1:5986/wsman + Headers: {} + Body: >- + + + + + http://windows-host:5985/wsman + + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + + 153600 + uuid:00000000-0000-0000-0000-000000000005 + + + PT5S + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/cmd + http://schemas.xmlsoap.org/ws/2004/09/transfer/Delete + + C36757C5-D911-4791-9C7B-D9D4FDD063F7 + + + + + Response: + StatusCode: 200 + Headers: + Server: Microsoft-HTTPAPI/2.0 + Date: Fri, 16 Dec 2022 23:58:26 GMT + Body: >- + + + http://schemas.xmlsoap.org/ws/2004/09/transfer/DeleteResponse + uuid:7E0EF214-91F6-408C-898D-E438B3A97189 + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + uuid:00000000-0000-0000-0000-000000000005 + + + diff --git a/src/WinRMSharp.Tests/Data/Sessions/ProtocolRunCommandWithEnv.yml b/src/WinRMSharp.Tests/Data/Sessions/ProtocolRunCommandWithEnv.yml new file mode 100644 index 0000000..6e4454d --- /dev/null +++ b/src/WinRMSharp.Tests/Data/Sessions/ProtocolRunCommandWithEnv.yml @@ -0,0 +1,269 @@ +- Request: + Method: POST + Url: https://127.0.0.1:5986/wsman + Headers: {} + Body: >- + + + + + http://windows-host:5985/wsman + + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + + 153600 + uuid:00000000-0000-0000-0000-000000000000 + + + PT5S + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/cmd + http://schemas.xmlsoap.org/ws/2004/09/transfer/Create + + + + + + hi mom + another var + + stdin + stdout stderr + + + + Response: + StatusCode: 200 + Headers: + Server: Microsoft-HTTPAPI/2.0 + Date: Fri, 16 Dec 2022 23:58:24 GMT + Body: >- + + + http://schemas.xmlsoap.org/ws/2004/09/transfer/CreateResponse + uuid:F066E2D7-B420-4753-99A5-F8BD7B3B3B0C + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + uuid:00000000-0000-0000-0000-000000000000 + + + + http://windows-host:5985/wsman + + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/cmd + + 4F7B59AD-1C73-4F40-AC57-791FF1E51EE0 + + + + + 4F7B59AD-1C73-4F40-AC57-791FF1E51EE0 + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/cmd + winrm-vm-003\Default + 73.53.37.241 + + hi mom + another var + + PT7200.000S + stdin + stdout stderr + P0DT0H0M0S + P0DT0H0M0S + + + +- Request: + Method: POST + Url: https://127.0.0.1:5986/wsman + Headers: {} + Body: >- + + + + + http://windows-host:5985/wsman + + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + + 153600 + uuid:00000000-0000-0000-0000-000000000001 + + + PT5S + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/cmd + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/Command + + TRUE + FALSE + + + 4F7B59AD-1C73-4F40-AC57-791FF1E51EE0 + + + + + echo + %TESTENV1% %TESTENV2% + + + + Response: + StatusCode: 200 + Headers: + Server: Microsoft-HTTPAPI/2.0 + Date: Fri, 16 Dec 2022 23:58:24 GMT + Body: >- + + + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/CommandResponse + uuid:D5F393A6-BFE3-4680-9D29-3721910AA515 + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + uuid:00000000-0000-0000-0000-000000000001 + + + + BDC0663A-6B1B-46DA-81D1-66D96303BE38 + + + +- Request: + Method: POST + Url: https://127.0.0.1:5986/wsman + Headers: {} + Body: >- + + + + + http://windows-host:5985/wsman + + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + + 153600 + uuid:00000000-0000-0000-0000-000000000002 + + + PT5S + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/cmd + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/Receive + + 4F7B59AD-1C73-4F40-AC57-791FF1E51EE0 + + + + + stdout stderr + + + + Response: + StatusCode: 200 + Headers: + Server: Microsoft-HTTPAPI/2.0 + Date: Fri, 16 Dec 2022 23:58:24 GMT + Body: >- + + + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/ReceiveResponse + uuid:975808C6-59C1-4EFE-A053-517E3181809E + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + uuid:00000000-0000-0000-0000-000000000002 + + + + aGkgbW9tIGFub3RoZXIgdmFyDQo= + + + + 0 + + + + +- Request: + Method: POST + Url: https://127.0.0.1:5986/wsman + Headers: {} + Body: >- + + + + + http://windows-host:5985/wsman + + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + + 153600 + uuid:00000000-0000-0000-0000-000000000003 + + + PT5S + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/cmd + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/Signal + + 4F7B59AD-1C73-4F40-AC57-791FF1E51EE0 + + + + + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/signal/terminate + + + + Response: + StatusCode: 200 + Headers: + Server: Microsoft-HTTPAPI/2.0 + Date: Fri, 16 Dec 2022 23:58:24 GMT + Body: >- + + + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/SignalResponse + uuid:E9988142-158B-4EE2-874A-C119C36B4976 + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + uuid:00000000-0000-0000-0000-000000000003 + + + + + +- Request: + Method: POST + Url: https://127.0.0.1:5986/wsman + Headers: {} + Body: >- + + + + + http://windows-host:5985/wsman + + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + + 153600 + uuid:00000000-0000-0000-0000-000000000004 + + + PT5S + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/cmd + http://schemas.xmlsoap.org/ws/2004/09/transfer/Delete + + 4F7B59AD-1C73-4F40-AC57-791FF1E51EE0 + + + + + Response: + StatusCode: 200 + Headers: + Server: Microsoft-HTTPAPI/2.0 + Date: Fri, 16 Dec 2022 23:58:24 GMT + Body: >- + + + http://schemas.xmlsoap.org/ws/2004/09/transfer/DeleteResponse + uuid:993F0B4E-5856-4F29-ACA4-0FC3F6CF10BD + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + uuid:00000000-0000-0000-0000-000000000004 + + + diff --git a/src/WinRMSharp.Tests/Data/Sessions/ProtocolRunCommandWithNoProfile.yml b/src/WinRMSharp.Tests/Data/Sessions/ProtocolRunCommandWithNoProfile.yml new file mode 100644 index 0000000..b18fc35 --- /dev/null +++ b/src/WinRMSharp.Tests/Data/Sessions/ProtocolRunCommandWithNoProfile.yml @@ -0,0 +1,264 @@ +- Request: + Method: POST + Url: https://127.0.0.1:5986/wsman + Headers: {} + Body: >- + + + + + http://windows-host:5985/wsman + + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + + 153600 + uuid:00000000-0000-0000-0000-000000000000 + + + PT5S + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/cmd + http://schemas.xmlsoap.org/ws/2004/09/transfer/Create + + True + + + + + stdin + stdout stderr + + + + Response: + StatusCode: 200 + Headers: + Server: Microsoft-HTTPAPI/2.0 + Date: Fri, 16 Dec 2022 23:59:29 GMT + Body: >- + + + http://schemas.xmlsoap.org/ws/2004/09/transfer/CreateResponse + uuid:F26C0914-3CDC-4860-B5F7-CFC5C939194A + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + uuid:00000000-0000-0000-0000-000000000000 + + + + http://windows-host:5985/wsman + + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/cmd + + 0B65F88F-BED8-4196-90EE-0ED25B058848 + + + + + 0B65F88F-BED8-4196-90EE-0ED25B058848 + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/cmd + winrm-vm-003\Default + 73.53.37.241 + PT7200.000S + stdin + stdout stderr + P0DT0H0M0S + P0DT0H0M0S + + + +- Request: + Method: POST + Url: https://127.0.0.1:5986/wsman + Headers: {} + Body: >- + + + + + http://windows-host:5985/wsman + + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + + 153600 + uuid:00000000-0000-0000-0000-000000000001 + + + PT5S + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/cmd + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/Command + + TRUE + FALSE + + + 0B65F88F-BED8-4196-90EE-0ED25B058848 + + + + + cmd.exe + /c set + + + + Response: + StatusCode: 200 + Headers: + Server: Microsoft-HTTPAPI/2.0 + Date: Fri, 16 Dec 2022 23:59:29 GMT + Body: >- + + + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/CommandResponse + uuid:B1A77746-002D-4E2B-A6DA-3C9310F4A441 + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + uuid:00000000-0000-0000-0000-000000000001 + + + + 9B8FD513-5380-4349-96E8-E291E465830F + + + +- Request: + Method: POST + Url: https://127.0.0.1:5986/wsman + Headers: {} + Body: >- + + + + + http://windows-host:5985/wsman + + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + + 153600 + uuid:00000000-0000-0000-0000-000000000002 + + + PT5S + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/cmd + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/Receive + + 0B65F88F-BED8-4196-90EE-0ED25B058848 + + + + + stdout stderr + + + + Response: + StatusCode: 200 + Headers: + Server: Microsoft-HTTPAPI/2.0 + Date: Fri, 16 Dec 2022 23:59:29 GMT + Body: >- + + + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/ReceiveResponse + uuid:85E8B6F6-E001-4962-9FA2-9B7BB0745BEE + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + uuid:00000000-0000-0000-0000-000000000002 + + + + QUxMVVNFUlNQUk9GSUxFPUM6XFByb2dyYW1EYXRhDQo= + QVBQREFUQT1DOlxVc2Vyc1xEZWZhdWx0LndpbnJtLXZtLTAwM1xBcHBEYXRhXFJvYW1pbmcNCkNvbW1vblByb2dyYW1GaWxlcz1DOlxQcm9ncmFtIEZpbGVzXENvbW1vbiBGaWxlcw0KQ29tbW9uUHJvZ3JhbUZpbGVzKHg4Nik9QzpcUHJvZ3JhbSBGaWxlcyAoeDg2KVxDb21tb24gRmlsZXMNCkNvbW1vblByb2dyYW1XNjQzMj1DOlxQcm9ncmFtIEZpbGVzXENvbW1vbiBGaWxlcw0KQ09NUFVURVJOQU1FPXdpbnJtLXZtLTAwMw0KQ29tU3BlYz1DOlxXaW5kb3dzXHN5c3RlbTMyXGNtZC5leGUNCkRyaXZlckRhdGE9QzpcV2luZG93c1xTeXN0ZW0zMlxEcml2ZXJzXERyaXZlckRhdGENCkxPQ0FMQVBQREFUQT1DOlxVc2Vyc1xEZWZhdWx0LndpbnJtLXZtLTAwM1xBcHBEYXRhXExvY2FsDQpOVU1CRVJfT0ZfUFJPQ0VTU09SUz00DQpPUz1XaW5kb3dzX05UDQpQYXRoPUM6XFdpbmRvd3Ncc3lzdGVtMzI7QzpcV2luZG93cztDOlxXaW5kb3dzXFN5c3RlbTMyXFdiZW07QzpcV2luZG93c1xTeXN0ZW0zMlxXaW5kb3dzUG93ZXJTaGVsbFx2MS4wXDtDOlxXaW5kb3dzXFN5c3RlbTMyXE9wZW5TU0hcO0M6XFVzZXJzXERlZmF1bHQud2lucm0tdm0tMDAzXEFwcERhdGFcTG9jYWxcTWljcm9zb2Z0XFdpbmRvd3NBcHBzDQpQQVRIRVhUPS5DT007LkVYRTsuQkFUOy5DTUQ7LlZCUzsuVkJFOy5KUzsuSlNFOy5XU0Y7LldTSDsuTVNDDQpQUk9DRVNTT1JfQVJDSElURUNUVVJFPUFNRDY0DQpQUk9DRVNTT1JfSURFTlRJRklFUj1JbnRlbDY0IEZhbWlseSA2IE1vZGVsIDYzIFN0ZXBwaW5nIDIsIEdlbnVpbmVJbnRlbA0KUFJPQ0VTU09SX0xFVkVMPTYNClBST0NFU1NPUl9SRVZJU0lPTj0zZjAyDQpQcm9ncmFtRGF0YT1DOlxQcm9ncmFtRGF0YQ0KUHJvZ3JhbUZpbGVzPUM6XFByb2dyYW0gRmlsZXMNClByb2dyYW1GaWxlcyh4ODYpPUM6XFByb2dyYW0gRmlsZXMgKHg4NikNClByb2dyYW1XNjQzMj1DOlxQcm9ncmFtIEZpbGVzDQpQUk9NUFQ9JFAkRw0KUFNNb2R1bGVQYXRoPSVQcm9ncmFtRmlsZXMlXFdpbmRvd3NQb3dlclNoZWxsXE1vZHVsZXM7QzpcV2luZG93c1xzeXN0ZW0zMlxXaW5kb3dzUG93ZXJTaGVsbFx2MS4wXE1vZHVsZXMNClBVQkxJQz1DOlxVc2Vyc1xQdWJsaWMNClN5c3RlbURyaXZlPUM6DQpTeXN0ZW1Sb290PUM6XFdpbmRvd3MNClRFTVA9QzpcVXNlcnNcREVGQVVMfjEuV0lOXEFwcERhdGFcTG9jYWxcVGVtcA0KVE1QPUM6XFVzZXJzXERFRkFVTH4xLldJTlxBcHBEYXRhXExvY2FsXFRlbXANClVTRVJET01BSU49d2lucm0tdm0tMDAzDQpVU0VSTkFNRT1EZWZhdWx0DQpVU0VSUFJPRklMRT1DOlxVc2Vyc1xEZWZhdWx0LndpbnJtLXZtLTAwMw0Kd2luZGlyPUM6XFdpbmRvd3MNCg== + + + + 0 + + + + +- Request: + Method: POST + Url: https://127.0.0.1:5986/wsman + Headers: {} + Body: >- + + + + + http://windows-host:5985/wsman + + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + + 153600 + uuid:00000000-0000-0000-0000-000000000003 + + + PT5S + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/cmd + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/Signal + + 0B65F88F-BED8-4196-90EE-0ED25B058848 + + + + + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/signal/terminate + + + + Response: + StatusCode: 200 + Headers: + Server: Microsoft-HTTPAPI/2.0 + Date: Fri, 16 Dec 2022 23:59:29 GMT + Body: >- + + + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/SignalResponse + uuid:731768C7-87DF-4FD5-AEF0-803ACF80D180 + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + uuid:00000000-0000-0000-0000-000000000003 + + + + + +- Request: + Method: POST + Url: https://127.0.0.1:5986/wsman + Headers: {} + Body: >- + + + + + http://windows-host:5985/wsman + + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + + 153600 + uuid:00000000-0000-0000-0000-000000000004 + + + PT5S + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/cmd + http://schemas.xmlsoap.org/ws/2004/09/transfer/Delete + + 0B65F88F-BED8-4196-90EE-0ED25B058848 + + + + + Response: + StatusCode: 200 + Headers: + Server: Microsoft-HTTPAPI/2.0 + Date: Fri, 16 Dec 2022 23:59:29 GMT + Body: >- + + + http://schemas.xmlsoap.org/ws/2004/09/transfer/DeleteResponse + uuid:D65D5ABC-6C14-47A9-9EE8-D64BA0C0E323 + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + uuid:00000000-0000-0000-0000-000000000004 + + + diff --git a/src/WinRMSharp.Tests/Data/Sessions/ProtocolRunCommandWithUnicode.yml b/src/WinRMSharp.Tests/Data/Sessions/ProtocolRunCommandWithUnicode.yml new file mode 100644 index 0000000..b544cb0 --- /dev/null +++ b/src/WinRMSharp.Tests/Data/Sessions/ProtocolRunCommandWithUnicode.yml @@ -0,0 +1,264 @@ +- Request: + Method: POST + Url: https://127.0.0.1:5986/wsman + Headers: {} + Body: >- + + + + + http://windows-host:5985/wsman + + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + + 153600 + uuid:00000000-0000-0000-0000-000000000000 + + + PT5S + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/cmd + http://schemas.xmlsoap.org/ws/2004/09/transfer/Create + + 65001 + + + + + stdin + stdout stderr + + + + Response: + StatusCode: 200 + Headers: + Server: Microsoft-HTTPAPI/2.0 + Date: Fri, 16 Dec 2022 23:58:24 GMT + Body: >- + + + http://schemas.xmlsoap.org/ws/2004/09/transfer/CreateResponse + uuid:A1CAB495-29B9-423E-8AC1-AA74D4AF7B22 + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + uuid:00000000-0000-0000-0000-000000000000 + + + + http://windows-host:5985/wsman + + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/cmd + + C5D0E586-F22B-425C-AB7C-6355765E0CF8 + + + + + C5D0E586-F22B-425C-AB7C-6355765E0CF8 + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/cmd + winrm-vm-003\Default + 73.53.37.241 + PT7200.000S + stdin + stdout stderr + P0DT0H0M0S + P0DT0H0M0S + + + +- Request: + Method: POST + Url: https://127.0.0.1:5986/wsman + Headers: {} + Body: >- + + + + + http://windows-host:5985/wsman + + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + + 153600 + uuid:00000000-0000-0000-0000-000000000001 + + + PT5S + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/cmd + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/Command + + TRUE + FALSE + + + C5D0E586-F22B-425C-AB7C-6355765E0CF8 + + + + + powershell.exe + Write-Host こんにちは + + + + Response: + StatusCode: 200 + Headers: + Server: Microsoft-HTTPAPI/2.0 + Date: Fri, 16 Dec 2022 23:58:25 GMT + Body: >- + + + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/CommandResponse + uuid:505B63BC-CC1D-4EB0-AE1A-E24EEA437415 + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + uuid:00000000-0000-0000-0000-000000000001 + + + + 4A19F8A1-C71C-42F7-AE08-0BC1CA4FB785 + + + +- Request: + Method: POST + Url: https://127.0.0.1:5986/wsman + Headers: {} + Body: >- + + + + + http://windows-host:5985/wsman + + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + + 153600 + uuid:00000000-0000-0000-0000-000000000002 + + + PT5S + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/cmd + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/Receive + + C5D0E586-F22B-425C-AB7C-6355765E0CF8 + + + + + stdout stderr + + + + Response: + StatusCode: 200 + Headers: + Server: Microsoft-HTTPAPI/2.0 + Date: Fri, 16 Dec 2022 23:58:25 GMT + Body: >- + + + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/ReceiveResponse + uuid:F9D673D0-1E6E-4FDA-9CD5-E6EB99F62F2E + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + uuid:00000000-0000-0000-0000-000000000002 + + + + 44GT44KT44Gr44Gh44Gv + Cg== + + + + 0 + + + + +- Request: + Method: POST + Url: https://127.0.0.1:5986/wsman + Headers: {} + Body: >- + + + + + http://windows-host:5985/wsman + + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + + 153600 + uuid:00000000-0000-0000-0000-000000000003 + + + PT5S + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/cmd + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/Signal + + C5D0E586-F22B-425C-AB7C-6355765E0CF8 + + + + + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/signal/terminate + + + + Response: + StatusCode: 200 + Headers: + Server: Microsoft-HTTPAPI/2.0 + Date: Fri, 16 Dec 2022 23:58:25 GMT + Body: >- + + + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/SignalResponse + uuid:9AFBE220-925B-427C-ADF4-024809FFAD80 + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + uuid:00000000-0000-0000-0000-000000000003 + + + + + +- Request: + Method: POST + Url: https://127.0.0.1:5986/wsman + Headers: {} + Body: >- + + + + + http://windows-host:5985/wsman + + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + + 153600 + uuid:00000000-0000-0000-0000-000000000004 + + + PT5S + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/cmd + http://schemas.xmlsoap.org/ws/2004/09/transfer/Delete + + C5D0E586-F22B-425C-AB7C-6355765E0CF8 + + + + + Response: + StatusCode: 200 + Headers: + Server: Microsoft-HTTPAPI/2.0 + Date: Fri, 16 Dec 2022 23:58:25 GMT + Body: >- + + + http://schemas.xmlsoap.org/ws/2004/09/transfer/DeleteResponse + uuid:CCA6CA16-A85B-4F07-822E-F47F018EE0D1 + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + uuid:00000000-0000-0000-0000-000000000004 + + + diff --git a/src/WinRMSharp.Tests/Data/Sessions/ProtocolRunCommandWithoutArgsAndCleanup.yml b/src/WinRMSharp.Tests/Data/Sessions/ProtocolRunCommandWithoutArgsAndCleanup.yml new file mode 100644 index 0000000..9ec5bc3 --- /dev/null +++ b/src/WinRMSharp.Tests/Data/Sessions/ProtocolRunCommandWithoutArgsAndCleanup.yml @@ -0,0 +1,206 @@ +- Request: + Method: POST + Url: https://127.0.0.1:5986/wsman + Headers: {} + Body: >- + + + + + http://windows-host:5985/wsman + + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + + 153600 + uuid:00000000-0000-0000-0000-000000000000 + + + PT5S + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/cmd + http://schemas.xmlsoap.org/ws/2004/09/transfer/Create + + + + + stdin + stdout stderr + + + + Response: + StatusCode: 200 + Headers: + Server: Microsoft-HTTPAPI/2.0 + Date: Fri, 16 Dec 2022 23:58:26 GMT + Body: >- + + + http://schemas.xmlsoap.org/ws/2004/09/transfer/CreateResponse + uuid:52559753-C089-41D6-8568-218CD795F85C + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + uuid:00000000-0000-0000-0000-000000000000 + + + + http://windows-host:5985/wsman + + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/cmd + + E9FA48B0-8DC7-47EE-913A-43A314B0D235 + + + + + E9FA48B0-8DC7-47EE-913A-43A314B0D235 + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/cmd + winrm-vm-003\Default + 73.53.37.241 + PT7200.000S + stdin + stdout stderr + P0DT0H0M0S + P0DT0H0M0S + + + +- Request: + Method: POST + Url: https://127.0.0.1:5986/wsman + Headers: {} + Body: >- + + + + + http://windows-host:5985/wsman + + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + + 153600 + uuid:00000000-0000-0000-0000-000000000001 + + + PT5S + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/cmd + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/Command + + TRUE + FALSE + + + E9FA48B0-8DC7-47EE-913A-43A314B0D235 + + + + + hostname + + + + Response: + StatusCode: 200 + Headers: + Server: Microsoft-HTTPAPI/2.0 + Date: Fri, 16 Dec 2022 23:58:26 GMT + Body: >- + + + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/CommandResponse + uuid:7CF021C4-DDBF-409B-AA7B-BDC9B7C3F4A4 + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + uuid:00000000-0000-0000-0000-000000000001 + + + + 275343BA-5E19-4C48-ABA1-310DAF0DD106 + + + +- Request: + Method: POST + Url: https://127.0.0.1:5986/wsman + Headers: {} + Body: >- + + + + + http://windows-host:5985/wsman + + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + + 153600 + uuid:00000000-0000-0000-0000-000000000002 + + + PT5S + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/cmd + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/Signal + + E9FA48B0-8DC7-47EE-913A-43A314B0D235 + + + + + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/signal/terminate + + + + Response: + StatusCode: 200 + Headers: + Server: Microsoft-HTTPAPI/2.0 + Date: Fri, 16 Dec 2022 23:58:26 GMT + Body: >- + + + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/SignalResponse + uuid:563B83B2-F4E1-4E5A-A07F-1A95A8F87B9C + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + uuid:00000000-0000-0000-0000-000000000002 + + + + + +- Request: + Method: POST + Url: https://127.0.0.1:5986/wsman + Headers: {} + Body: >- + + + + + http://windows-host:5985/wsman + + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + + 153600 + uuid:00000000-0000-0000-0000-000000000003 + + + PT5S + http://schemas.microsoft.com/wbem/wsman/1/windows/shell/cmd + http://schemas.xmlsoap.org/ws/2004/09/transfer/Delete + + E9FA48B0-8DC7-47EE-913A-43A314B0D235 + + + + + Response: + StatusCode: 200 + Headers: + Server: Microsoft-HTTPAPI/2.0 + Date: Fri, 16 Dec 2022 23:58:26 GMT + Body: >- + + + http://schemas.xmlsoap.org/ws/2004/09/transfer/DeleteResponse + uuid:6570E8C3-D06C-451A-A5B3-FEC090F012C5 + http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous + uuid:00000000-0000-0000-0000-000000000003 + + + diff --git a/src/WinRMSharp.Tests/InMemoryClientTests.cs b/src/WinRMSharp.Tests/InMemoryClientTests.cs new file mode 100644 index 0000000..66dcd55 --- /dev/null +++ b/src/WinRMSharp.Tests/InMemoryClientTests.cs @@ -0,0 +1,64 @@ +using System.Net; +using WinRMSharp.Tests.Sessions; +using Xunit; + +namespace WinRMSharp.Tests +{ + [Trait("Category", "InMemory")] + public class InMemoryClientTests : BaseClientTests, IDisposable + { + private readonly SessionManager _sessionManager = new SessionManager(); + + [Fact] + public void ConstructClient() + { + string baseUrl = "https://127.0.0.1/wsman"; + string userName = "exampleUser"; + string password = "examplePassword"; + + ICredentials credentials = new NetworkCredential(userName, password); + + WinRMClientOptions clientOptions = new WinRMClientOptions() + { + OperationTimeout = TimeSpan.FromSeconds(5), + MaxEnvelopeSize = 100, + ReadTimeout = TimeSpan.FromSeconds(10) + }; + + WinRMClient client = new WinRMClient(baseUrl, credentials, clientOptions); + + Assert.NotNull(client.Transport); + Assert.NotNull(client.Protocol); + + Assert.Equal(clientOptions.OperationTimeout, client.Protocol.OperationTimeout); + Assert.Equal(clientOptions.MaxEnvelopeSize, client.Protocol.MaxEnvelopeSize); + Assert.Equal(clientOptions.ReadTimeout, client.Transport.ReadTimeout); + } + + public void Dispose() + { + _sessionManager.Dispose(); + } + + public override WinRMClient GenerateClient(string sessionName) + { + string baseUrl = "https://127.0.0.1/wsman"; + string userName = "exampleUser"; + string password = "examplePassword"; + + DelegatingHandler handler = _sessionManager.GenerateSessionHandler(SessionState.Playback, sessionName); + + ICredentials credentials = new NetworkCredential(userName, password); + ITransport transport = new Transport(baseUrl, handler, credentials); + + ProtocolOptions protocolOptions = new ProtocolOptions() + { + OperationTimeout = TimeSpan.FromSeconds(5) + }; + + Protocol protocol = new Protocol(transport, new IncrementingGuidProvider(), protocolOptions); + + return new WinRMClient(protocol); + } + } +} diff --git a/src/WinRMSharp.Tests/InMemoryProtocolTests.cs b/src/WinRMSharp.Tests/InMemoryProtocolTests.cs new file mode 100644 index 0000000..5c4fd41 --- /dev/null +++ b/src/WinRMSharp.Tests/InMemoryProtocolTests.cs @@ -0,0 +1,36 @@ +using System.Net; +using WinRMSharp.Tests.Sessions; +using Xunit; + +namespace WinRMSharp.Tests +{ + [Trait("Category", "InMemory")] + public class InMemoryProtocolTests : BaseProtocolTests, IDisposable + { + private readonly SessionManager _sessionManager = new SessionManager(); + + public void Dispose() + { + _sessionManager.Dispose(); + } + + public override Protocol GenerateProtocol(string sessionName) + { + string baseUrl = "https://127.0.0.1/wsman"; + string userName = "exampleUser"; + string password = "examplePassword"; + + DelegatingHandler handler = _sessionManager.GenerateSessionHandler(SessionState.Playback, sessionName); + + ICredentials credentials = new NetworkCredential(userName, password); + ITransport transport = new Transport(baseUrl, handler, credentials); + + ProtocolOptions protocolOptions = new ProtocolOptions() + { + OperationTimeout = TimeSpan.FromSeconds(5) + }; + + return new Protocol(transport, new IncrementingGuidProvider(), protocolOptions); + } + } +} diff --git a/src/WinRMSharp.Tests/IntegrationClientTests.cs b/src/WinRMSharp.Tests/IntegrationClientTests.cs new file mode 100644 index 0000000..74315dd --- /dev/null +++ b/src/WinRMSharp.Tests/IntegrationClientTests.cs @@ -0,0 +1,38 @@ +using System.Net; +using WinRMSharp.Tests.Sessions; +using Xunit; + +namespace WinRMSharp.Tests +{ + [Trait("Category", "Integration")] + public class IntegrationClientTests : BaseClientTests, IDisposable + { + private readonly SessionManager _sessionManager = new SessionManager(); + + public void Dispose() + { + _sessionManager.Dispose(); + } + + public override WinRMClient GenerateClient(string sessionName) + { + string baseUrl = Environment.GetEnvironmentVariable("WINRM_BASE_URL") ?? throw new ArgumentNullException("WINRM_BASE_URL"); + string username = Environment.GetEnvironmentVariable("WINRM_USERNAME") ?? throw new ArgumentNullException("WINRM_USERNAME"); + string password = Environment.GetEnvironmentVariable("WINRM_PASSWORD") ?? throw new ArgumentNullException("WINRM_PASSWORD"); + + SessionHandler handler = _sessionManager.GenerateSessionHandler(SessionState.Recording, sessionName); + + ICredentials credentials = new NetworkCredential(username, password); + ITransport transport = new Transport(baseUrl, handler, credentials); + + ProtocolOptions protocolOptions = new ProtocolOptions() + { + OperationTimeout = TimeSpan.FromSeconds(5) + }; + + Protocol protocol = new Protocol(transport, new IncrementingGuidProvider(), protocolOptions); + + return new WinRMClient(protocol); + } + } +} diff --git a/src/WinRMSharp.Tests/IntegrationProtocolTests.cs b/src/WinRMSharp.Tests/IntegrationProtocolTests.cs new file mode 100644 index 0000000..2a863a6 --- /dev/null +++ b/src/WinRMSharp.Tests/IntegrationProtocolTests.cs @@ -0,0 +1,36 @@ +using System.Net; +using WinRMSharp.Tests.Sessions; +using Xunit; + +namespace WinRMSharp.Tests +{ + [Trait("Category", "Integration")] + public class IntegrationProtocolTests : BaseProtocolTests, IDisposable + { + private readonly SessionManager _sessionManager = new SessionManager(); + + public void Dispose() + { + _sessionManager.Dispose(); + } + + public override Protocol GenerateProtocol(string sessionName) + { + string baseUrl = Environment.GetEnvironmentVariable("WINRM_BASE_URL") ?? throw new ArgumentNullException("WINRM_BASE_URL"); + string username = Environment.GetEnvironmentVariable("WINRM_USERNAME") ?? throw new ArgumentNullException("WINRM_USERNAME"); + string password = Environment.GetEnvironmentVariable("WINRM_PASSWORD") ?? throw new ArgumentNullException("WINRM_PASSWORD"); + + SessionHandler handler = _sessionManager.GenerateSessionHandler(SessionState.Recording, sessionName); + + ICredentials credentials = new NetworkCredential(username, password); + ITransport transport = new Transport(baseUrl, handler, credentials); + + ProtocolOptions protocolOptions = new ProtocolOptions() + { + OperationTimeout = TimeSpan.FromSeconds(5) + }; + + return new Protocol(transport, new IncrementingGuidProvider(), protocolOptions); + } + } +} diff --git a/src/WinRMSharp.Tests/MockClient.cs b/src/WinRMSharp.Tests/MockClient.cs deleted file mode 100644 index 0e2292c..0000000 --- a/src/WinRMSharp.Tests/MockClient.cs +++ /dev/null @@ -1,103 +0,0 @@ -using Moq; -using System.Xml.Linq; -using WinRMSharp.Exceptions; -using WinRMSharp.Utils; - -namespace WinRMSharp.Tests -{ - public class MockClient - { - public Mock GuidProvider { get; private set; } - public Mock Transport { get; private set; } - public Mock Protocol { get; private set; } - - public MockClient() - { - GuidProvider = new Mock(); - GuidProvider.Setup(p => p.NewGuid()).Returns(Guid.Parse("11111111-1111-1111-1111-111111111111")); - - Transport = new Mock(); - Protocol = new Mock(Transport.Object, GuidProvider.Object, null); - - Transport.Setup(m => m.Send(It.IsAny())).ReturnsAsync((string message) => ResolveResponse(message)); - } - - private string ResolveResponse(string message) - { - //message = Patch(message); - - XDocument env = message.Parse(); - - // WARNING: Despite being contrary to the XML standard, DeepEquals only - // evaluates two nodes as equal if all attributes are in matching order. - // See https://github.com/dotnet/dotnet-api-docs/issues/830 - if (XNode.DeepEquals(env, Config.OPEN_SHELL_REQUEST.Parse())) - { - return Config.OPEN_SHELL_RESPONSE; - } - else if (XNode.DeepEquals(env, Config.CLOSE_SHELL_REQUEST.Parse())) - { - return Config.CLOSE_SHELL_RESPONSE; - } - else if (XNode.DeepEquals(env, Config.RUN_CMD_WITH_ARGS_REQUEST.Parse()) || XNode.DeepEquals(env, Config.RUN_CMD_WO_ARGS_REQUEST.Parse())) - { - return string.Format(Config.RUN_CMD_PS_RESPONSE, "1"); - } - else if (XNode.DeepEquals(env, string.Format(Config.CLEANUP_CMD_REQUEST, "1").Parse()) || - XNode.DeepEquals(env, string.Format(Config.CLEANUP_CMD_REQUEST, "2").Parse()) || - XNode.DeepEquals(env, string.Format(Config.CLEANUP_CMD_REQUEST, "3").Parse())) - { - return Config.CLEANUP_CMD_RESPONSE; - } - else if (XNode.DeepEquals(env, string.Format(Config.GET_CMD_PS_OUTPUT_REQUEST, "1").Parse())) - { - return Config.GET_CMD_OUTPUT_RESPONSE; - } - else if (XNode.DeepEquals(env, string.Format(Config.GET_CMD_PS_OUTPUT_REQUEST, "2").Parse())) - { - return Config.GET_PS_OUTPUT_RESPONSE; - } - else if (XNode.DeepEquals(env, Config.RUN_CMD_REQ_INPUT.Parse())) - { - return Config.RUN_CMD_REQ_INPUT_RESPONSE; - } - else if (XNode.DeepEquals(env, Config.RUN_CMD_SEND_INPUT.Parse())) - { - return Config.RUN_CMD_SEND_INPUT_RESPONSE; - } - else if (XNode.DeepEquals(env, Config.RUN_CMD_SEND_INPUT_GET_OUTPUT.Parse())) - { - return Config.RUN_CMD_SEND_INPUT_GET_OUTPUT_RESPONSE; - } - else if (XNode.DeepEquals(env, Config.STDIN_CMD_CLEANUP.Parse())) - { - return Config.STDIN_CMD_CLEANUP_RESPONSE; - } - else if (XNode.DeepEquals(env, Config.OPERATION_TIMEOUT_REQUEST.Parse())) - { - return Config.OPERATION_TIMEOUT_RESPONSE; - } - else if (XNode.DeepEquals(env, Config.OPERATION_TIMEOUT_GET_0_REQUEST.Parse())) - { - throw new TransportException(500, Config.OPERATION_TIMEOUT_GET_0_RESPONSE); - } - else if (XNode.DeepEquals(env, Config.OPERATION_TIMEOUT_GET_1_REQUEST.Parse())) - { - return Config.OPERATION_TIMEOUT_GET_1_RESPONSE; - } - else if (XNode.DeepEquals(env, Config.CLOSE_COMMAND_FAULT_REQUEST.Parse())) - { - throw new TransportException(500, Config.CLOSE_COMMAND_FAULT_RESPONSE); - } - - - throw new Exception($"Unexpected request message: '{message}'"); - } - - //private static string Patch(string message) - //{ - // // Hardcode the guids to be consistent across all messages to simplify equality. - // return Regex.Replace(message, @"uuid:[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}", "uuid:11111111-1111-1111-1111-111111111111"); - //} - } -} diff --git a/src/WinRMSharp.Tests/ProtocolTests.cs b/src/WinRMSharp.Tests/ProtocolTests.cs deleted file mode 100644 index 4bd0e30..0000000 --- a/src/WinRMSharp.Tests/ProtocolTests.cs +++ /dev/null @@ -1,147 +0,0 @@ -using Moq; -using Xunit; - -namespace WinRMSharp.Tests -{ - public class ProtocolTests - { - [Fact] - public async Task OpenCloseShell() - { - MockClient mockClient = new MockClient(); - Protocol protocol = new Protocol(mockClient.Transport.Object, mockClient.GuidProvider.Object); - - string shellId = await protocol.OpenShell(); - await protocol.CloseShell(shellId); - - Assert.Equal("11111111-1111-1111-1111-111111111113", shellId); - } - - [Fact] - public async Task RunCommandWithArgsAndCleanup() - { - MockClient mockClient = new MockClient(); - Protocol protocol = new Protocol(mockClient.Transport.Object, mockClient.GuidProvider.Object); - - string shellId = await protocol.OpenShell(); - string commandId = await protocol.RunCommand(shellId, "ipconfig", new[] { "/all" }); - - await protocol.CloseCommand(shellId, commandId); - await protocol.CloseShell(shellId); - - Assert.Equal("11111111-1111-1111-1111-111111111114", commandId); - } - - [Fact] - public async Task RunCommandWithoutArgsAndCleanup() - { - MockClient mockClient = new MockClient(); - Protocol protocol = new Protocol(mockClient.Transport.Object, mockClient.GuidProvider.Object); - - string shellId = await protocol.OpenShell(); - string commandId = await protocol.RunCommand(shellId, "hostname"); - - await protocol.CloseCommand(shellId, commandId); - await protocol.CloseShell(shellId); - - Assert.Equal("11111111-1111-1111-1111-111111111114", commandId); - } - - [Fact] - public async Task GetCommandState() - { - MockClient mockClient = new MockClient(); - Protocol protocol = new Protocol(mockClient.Transport.Object, mockClient.GuidProvider.Object); - - string shellId = await protocol.OpenShell(); - string commandId = await protocol.RunCommand(shellId, "ipconfig", new[] { "/all" }); - CommandState commandState = await protocol.GetCommandState(shellId, commandId); - - await protocol.CloseCommand(shellId, commandId); - await protocol.CloseShell(shellId); - - Assert.NotNull(commandState); - Assert.Equal(0, commandState.StatusCode); - Assert.Contains("Windows IP Configuration", commandState.Stdout); - Assert.Equal(0, commandState.Stderr.Length); - } - - [Fact] - public async Task PollCommandState() - { - MockClient mockClient = new MockClient(); - Protocol protocol = new Protocol(mockClient.Transport.Object, mockClient.GuidProvider.Object); - - string shellId = await protocol.OpenShell(); - string commandId = await protocol.RunCommand(shellId, "ipconfig", new[] { "/all" }); - CommandState commandState = await protocol.PollCommandState(shellId, commandId); - - await protocol.CloseCommand(shellId, commandId); - await protocol.CloseShell(shellId); - - Assert.NotNull(commandState); - Assert.Equal(0, commandState.StatusCode); - Assert.Contains("Windows IP Configuration", commandState.Stdout); - Assert.Equal(0, commandState.Stderr.Length); - } - - [Fact] - public async Task SendCommandInput() - { - MockClient mockClient = new MockClient(); - Protocol protocol = new Protocol(mockClient.Transport.Object, mockClient.GuidProvider.Object); - - string shellId = await protocol.OpenShell(); - string commandId = await protocol.RunCommand(shellId, "cmd"); - await protocol.SendCommandInput(shellId, commandId, "echo \"hello world\" && exit\\r\\n"); - CommandState commandState = await protocol.GetCommandState(shellId, commandId); - - await protocol.CloseCommand(shellId, commandId); - await protocol.CloseShell(shellId); - - Assert.NotNull(commandState); - Assert.Equal(0, commandState.StatusCode); - Assert.Contains("hello world", commandState.Stdout); - Assert.Equal(0, commandState.Stderr.Length); - } - - [Fact] - public async Task RunCommandExceedingOperationTimeout() - { - MockClient mockClient = new MockClient(); - Mock guidProvider = new Mock(MockBehavior.Strict); - guidProvider.SetupSequence(s => s.NewGuid()) - .Returns(Guid.Parse("11111111-1111-1111-1111-111111111111")) // OpenShell - .Returns(Guid.Parse("11111111-1111-1111-1111-111111111111")) // RunCommand - .Returns(Guid.Parse("11111111-1111-1111-1111-111111111111")) // First Poll - .Returns(Guid.Parse("11111111-1111-1111-1111-111111111112")) // Second Poll - .Returns(Guid.Parse("11111111-1111-1111-1111-111111111111")) // CleanupCommand - .Returns(Guid.Parse("11111111-1111-1111-1111-111111111111")); // CloseShell - - Protocol protocol = new Protocol(mockClient.Transport.Object, guidProvider.Object); - - string shellId = await protocol.OpenShell(); - string commandId = await protocol.RunCommand(shellId, $"powershell -Command Start-Sleep -s {protocol.OperationTimeout.TotalSeconds * 2}"); - - CommandState state = await protocol.PollCommandState(shellId, commandId); - - await protocol.CloseCommand(shellId, commandId); - await protocol.CloseShell(shellId); - - Assert.Equal(0, state.StatusCode); - Assert.Equal(0, state.Stdout.Length); - Assert.Equal(0, state.Stderr.Length); - } - - [Fact] - public async Task HandleCleanupCommandFault() - { - MockClient mockClient = new MockClient(); - Protocol protocol = new Protocol(mockClient.Transport.Object, mockClient.GuidProvider.Object); - - await protocol.CloseCommand("11111111-1111-1111-1111-111111111113", "11111111-1111-1111-1111-111111111117"); - - // We've setup the transport to return a failure and we're just checcking an exception doesn't bubble up - } - } -} diff --git a/src/WinRMSharp.Tests/Sessions/PassThruHandler.cs b/src/WinRMSharp.Tests/Sessions/PassThruHandler.cs new file mode 100644 index 0000000..463c497 --- /dev/null +++ b/src/WinRMSharp.Tests/Sessions/PassThruHandler.cs @@ -0,0 +1,10 @@ +namespace WinRMSharp.Tests.Sessions +{ + internal class PassThruHandler : SessionHandler + { + protected override async Task SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) + { + return await base.SendAsync(request, cancellationToken); + } + } +} diff --git a/src/WinRMSharp.Tests/Sessions/PlaybackHandler.cs b/src/WinRMSharp.Tests/Sessions/PlaybackHandler.cs new file mode 100644 index 0000000..9b1fb0f --- /dev/null +++ b/src/WinRMSharp.Tests/Sessions/PlaybackHandler.cs @@ -0,0 +1,64 @@ +using System.Net; +using System.Xml.Linq; +using WinRMSharp.Utils; +using YamlDotNet.Serialization; + +namespace WinRMSharp.Tests.Sessions +{ + internal class PlaybackHandler : SessionHandler + { + private int _playbackIndex = 0; + private readonly List _recordings = new List(); + + private PlaybackHandler(List recordings) + { + _recordings = recordings; + } + + public static PlaybackHandler Load(string sessionName) + { + string path = Path.Join(Directory.GetCurrentDirectory(), "Data", "Sessions", $"{sessionName}.yml"); + + if (!File.Exists(path)) + { + throw new FileNotFoundException($"Expected recording to exist at '{path}'"); + } + + using StreamReader fileStream = File.OpenText(path); + + IDeserializer deserializer = new DeserializerBuilder().Build(); + List recordings = deserializer.Deserialize>(fileStream); + + return new PlaybackHandler(recordings); + } + + protected override async Task SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) + { + Recording recording = _recordings[_playbackIndex++]; + + XDocument? requestDocument = (request.Content == null) ? null : Xml.Parse(await request.Content!.ReadAsStringAsync()); + XDocument? recordingDocument = (recording.Request?.Body == null) ? null : Xml.Parse(recording.Request!.Body); + + if (!XNode.DeepEquals(requestDocument, recordingDocument)) + { + throw new InvalidOperationException($"Expected '{requestDocument}' Actual: '{recordingDocument}'"); + } + + HttpResponseMessage response = new HttpResponseMessage((HttpStatusCode)recording.Response.StatusCode) + { + Content = new StringContent(recording.Response.Body!) + }; + + foreach (KeyValuePair kv in recording.Response.Headers) + { + string key = kv.Key; + string[] values = kv.Value.Split(';'); + + response.Headers.Add(key, values); + } + + return response; + } + + } +} diff --git a/src/WinRMSharp.Tests/Sessions/RecordedRequest.cs b/src/WinRMSharp.Tests/Sessions/RecordedRequest.cs new file mode 100644 index 0000000..3f1090c --- /dev/null +++ b/src/WinRMSharp.Tests/Sessions/RecordedRequest.cs @@ -0,0 +1,44 @@ +namespace WinRMSharp.Tests.Sessions +{ + public class RecordedRequest + { + public string Method { get; set; } + public string? Url { get; set; } + public Dictionary Headers { get; set; } + public string? Body { get; set; } + + public RecordedRequest() + { + Method = string.Empty; + Url = string.Empty; + Headers = new Dictionary(); + Body = string.Empty; + } + + public RecordedRequest(HttpRequestMessage requestMessage) + { + Method = requestMessage.Method.Method; + Url = requestMessage.RequestUri?.ToString(); + Headers = ApplyFilters(requestMessage.Headers.ToDictionary(h => h.Key, h => string.Join(";", h.Value))); + Body = requestMessage.Content?.ReadAsStringAsync().Result; + } + + private static Dictionary ApplyFilters(Dictionary headers) + { + HashSet headersToFilter = new HashSet() + { + "Authorization" + }; + + foreach (string headerToFilter in headersToFilter) + { + if (!headers.ContainsKey(headerToFilter)) + continue; + + headers.Remove(headerToFilter); + } + + return headers; + } + } +} diff --git a/src/WinRMSharp.Tests/Sessions/RecordedResponse.cs b/src/WinRMSharp.Tests/Sessions/RecordedResponse.cs new file mode 100644 index 0000000..8444e41 --- /dev/null +++ b/src/WinRMSharp.Tests/Sessions/RecordedResponse.cs @@ -0,0 +1,29 @@ +using WinRMSharp.Utils; + +namespace WinRMSharp.Tests.Sessions +{ + internal class RecordedResponse + { + public int StatusCode { get; set; } + public Dictionary Headers { get; set; } + public string? Body { get; set; } + + public RecordedResponse() + { + StatusCode = 200; + Headers = new Dictionary(); + Body = null; + } + + public RecordedResponse(HttpResponseMessage responseMessage) + { + StatusCode = (int)responseMessage.StatusCode; + Headers = responseMessage.Headers.ToDictionary(h => h.Key, h => string.Join(";", h.Value)); + + if (responseMessage.Content != null) + { + Body = Xml.Format(responseMessage.Content!.ReadAsStringAsync().Result); + } + } + } +} diff --git a/src/WinRMSharp.Tests/Sessions/Recording.cs b/src/WinRMSharp.Tests/Sessions/Recording.cs new file mode 100644 index 0000000..2ea4732 --- /dev/null +++ b/src/WinRMSharp.Tests/Sessions/Recording.cs @@ -0,0 +1,8 @@ +namespace WinRMSharp.Tests.Sessions +{ + internal class Recording + { + public required RecordedRequest Request { get; set; } + public required RecordedResponse Response { get; set; } + } +} diff --git a/src/WinRMSharp.Tests/Sessions/RecordingHandler.cs b/src/WinRMSharp.Tests/Sessions/RecordingHandler.cs new file mode 100644 index 0000000..7253b6c --- /dev/null +++ b/src/WinRMSharp.Tests/Sessions/RecordingHandler.cs @@ -0,0 +1,50 @@ +using YamlDotNet.Serialization; + +namespace WinRMSharp.Tests.Sessions +{ + internal class RecordingHandler : SessionHandler + { + private readonly string _sessionName; + private readonly List _recordings = new List(); + + private RecordingHandler(string sessionName) + { + _sessionName = sessionName; + } + + public static RecordingHandler Create(string sessionName) + { + return new RecordingHandler(sessionName); + } + + public void Save() + { + ISerializer serializer = new SerializerBuilder().Build(); + string yaml = serializer.Serialize(_recordings); + string path = Path.Join("Data", "Sessions", $"{_sessionName}.yml"); + + if (!Directory.Exists("sessions")) + Directory.CreateDirectory("sessions"); + + File.WriteAllText(path, yaml); + } + + protected override async Task SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) + { + HttpResponseMessage response = await base.SendAsync(request, cancellationToken); + + AddRecording(new Recording() + { + Request = new RecordedRequest(request), + Response = new RecordedResponse(response) + }); + + return response; + } + + private void AddRecording(Recording recording) + { + _recordings.Add(recording); + } + } +} diff --git a/src/WinRMSharp.Tests/Sessions/SessionHandler.cs b/src/WinRMSharp.Tests/Sessions/SessionHandler.cs new file mode 100644 index 0000000..bc104b4 --- /dev/null +++ b/src/WinRMSharp.Tests/Sessions/SessionHandler.cs @@ -0,0 +1,6 @@ +namespace WinRMSharp.Tests.Sessions +{ + internal class SessionHandler : DelegatingHandler + { + } +} diff --git a/src/WinRMSharp.Tests/Sessions/SessionManager.cs b/src/WinRMSharp.Tests/Sessions/SessionManager.cs new file mode 100644 index 0000000..f6d62c0 --- /dev/null +++ b/src/WinRMSharp.Tests/Sessions/SessionManager.cs @@ -0,0 +1,50 @@ +namespace WinRMSharp.Tests.Sessions +{ + public enum SessionState + { + Recording, + Playback, + PassThru + } + + internal class SessionManager : IDisposable + { + private readonly List _handlers = new List(); + + public void Dispose() + { + foreach (DelegatingHandler handler in _handlers) + { + if (handler is RecordingHandler recordingHandler) + { + recordingHandler.Save(); + } + } + } + + public SessionHandler GenerateSessionHandler(SessionState state, string sessionName) + { + SessionHandler? handler; + + if (state == SessionState.Recording) + { + handler = RecordingHandler.Create(sessionName); + } + else if (state == SessionState.Playback) + { + handler = PlaybackHandler.Load(sessionName); + } + else if (state == SessionState.PassThru) + { + handler = new PassThruHandler(); + } + else + { + throw new InvalidOperationException($"Unsupported session state '{state}'"); + } + + _handlers.Add(handler); + return handler; + } + } +} diff --git a/src/WinRMSharp.Tests/WinRMClientTests.cs b/src/WinRMSharp.Tests/WinRMClientTests.cs index b1d5e0d..000aaf7 100644 --- a/src/WinRMSharp.Tests/WinRMClientTests.cs +++ b/src/WinRMSharp.Tests/WinRMClientTests.cs @@ -3,43 +3,43 @@ namespace WinRMSharp.Tests { - public class WinRMClientTests - { - [Fact] - public void VerifyConstruction() - { - string baseUrl = "https://localhost:5986"; - ICredentials credentials = new NetworkCredential() - { - Domain = "localhost", - UserName = "testUser", - Password = "testPassword" - }; - WinRMClientOptions clientOptions = new WinRMClientOptions() - { - MaxEnvelopeSize = 1, - OperationTimeout = TimeSpan.FromSeconds(20), - ReadTimeout = TimeSpan.FromSeconds(30) - }; + //public class WinRMClientTests + //{ + // [Fact] + // public void VerifyConstruction() + // { + // string baseUrl = "https://localhost:5986"; + // ICredentials credentials = new NetworkCredential() + // { + // Domain = "localhost", + // UserName = "testUser", + // Password = "testPassword" + // }; + // WinRMClientOptions clientOptions = new WinRMClientOptions() + // { + // MaxEnvelopeSize = 1, + // OperationTimeout = TimeSpan.FromSeconds(20), + // ReadTimeout = TimeSpan.FromSeconds(30) + // }; - WinRMClient winRMClient = new WinRMClient(baseUrl, credentials, clientOptions); + // WinRMClient winRMClient = new WinRMClient(baseUrl, credentials, clientOptions); - Assert.NotNull(winRMClient); - } + // Assert.NotNull(winRMClient); + // } - [Fact] - public async Task RunCommand() - { - MockClient mockClient = new MockClient(); - Protocol protocol = new Protocol(mockClient.Transport.Object, mockClient.GuidProvider.Object); - WinRMClient winRMClient = new WinRMClient(protocol); + // [Fact] + // public async Task RunCommand() + // { + // MockClient mockClient = new MockClient(); + // Protocol protocol = new Protocol(mockClient.Transport.Object, mockClient.GuidProvider.Object); + // WinRMClient winRMClient = new WinRMClient(protocol); - CommandState commandState = await winRMClient.RunCommand("ipconfig", new[] { "/all" }); + // CommandState commandState = await winRMClient.RunCommand("ipconfig", new[] { "/all" }); - Assert.NotNull(commandState); - Assert.Equal(0, commandState.StatusCode); - Assert.Contains("Windows IP Configuration", commandState.Stdout); - Assert.Equal(0, commandState.Stderr.Length); - } - } + // Assert.NotNull(commandState); + // Assert.Equal(0, commandState.StatusCode); + // Assert.Contains("Windows IP Configuration", commandState.Stdout); + // Assert.Equal(0, commandState.Stderr.Length); + // } + //} } diff --git a/src/WinRMSharp.Tests/WinRMSharp.Tests.csproj b/src/WinRMSharp.Tests/WinRMSharp.Tests.csproj index 4401715..215f064 100644 --- a/src/WinRMSharp.Tests/WinRMSharp.Tests.csproj +++ b/src/WinRMSharp.Tests/WinRMSharp.Tests.csproj @@ -4,6 +4,7 @@ netcoreapp3.1;net5.0;net6.0;net7.0 enable enable + $(MSBuildProjectDirectory)\test.runsettings 11.0 false false @@ -35,10 +36,60 @@ runtime; build; native; contentfiles; analyzers; buildtransitive all + + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + + + + + diff --git a/src/WinRMSharp.Tests/test.runsettings b/src/WinRMSharp.Tests/test.runsettings index bff1f3b..f95554f 100644 --- a/src/WinRMSharp.Tests/test.runsettings +++ b/src/WinRMSharp.Tests/test.runsettings @@ -1,30 +1,10 @@  - - - - - - - - ^System.Diagnostics.CodeAnalysis\..* - ^System.Runtime.CompilerServices\..* - - - - - - - - ^System\.Diagnostics\.DebuggerHiddenAttribute$ - ^System\.Diagnostics\.DebuggerNonUserCodeAttribute$ - ^System\.CodeDom\.Compiler\.GeneratedCodeAttribute$ - ^System\.Diagnostics\.CodeAnalysis\.ExcludeFromCodeCoverageAttribute$ - - - - - - - - \ No newline at end of file + + + + + + + + diff --git a/src/WinRMSharp.sln b/src/WinRMSharp.sln index 692c120..46e8b0d 100644 --- a/src/WinRMSharp.sln +++ b/src/WinRMSharp.sln @@ -7,8 +7,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WinRMSharp", "WinRMSharp\Wi EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WinRMSharp.Tests", "WinRMSharp.Tests\WinRMSharp.Tests.csproj", "{8E923474-D205-48BF-9C95-A42A74E2C974}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WinRMSharp.IntegrationTests", "WinRMSharp.IntegrationTests\WinRMSharp.IntegrationTests.csproj", "{E252FB4F-6B1C-4A57-B44E-34D83542ED2B}" -EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Example.Client", "WinRMSharp.Examples\Example.Client\Example.Client.csproj", "{4F8EC118-6148-4F9F-A56E-F5B5B2F31A45}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Example.Protocol", "WinRMSharp.Examples\Example.Protocol\Example.Protocol.csproj", "{6984791A-5357-434D-9E55-3CE5E68E5771}" @@ -27,10 +25,6 @@ Global {8E923474-D205-48BF-9C95-A42A74E2C974}.Debug|Any CPU.Build.0 = Debug|Any CPU {8E923474-D205-48BF-9C95-A42A74E2C974}.Release|Any CPU.ActiveCfg = Release|Any CPU {8E923474-D205-48BF-9C95-A42A74E2C974}.Release|Any CPU.Build.0 = Release|Any CPU - {E252FB4F-6B1C-4A57-B44E-34D83542ED2B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {E252FB4F-6B1C-4A57-B44E-34D83542ED2B}.Debug|Any CPU.Build.0 = Debug|Any CPU - {E252FB4F-6B1C-4A57-B44E-34D83542ED2B}.Release|Any CPU.ActiveCfg = Release|Any CPU - {E252FB4F-6B1C-4A57-B44E-34D83542ED2B}.Release|Any CPU.Build.0 = Release|Any CPU {4F8EC118-6148-4F9F-A56E-F5B5B2F31A45}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {4F8EC118-6148-4F9F-A56E-F5B5B2F31A45}.Debug|Any CPU.Build.0 = Debug|Any CPU {4F8EC118-6148-4F9F-A56E-F5B5B2F31A45}.Release|Any CPU.ActiveCfg = Release|Any CPU diff --git a/src/WinRMSharp/Contracts/Fault.cs b/src/WinRMSharp/Contracts/Fault.cs new file mode 100644 index 0000000..e320ab2 --- /dev/null +++ b/src/WinRMSharp/Contracts/Fault.cs @@ -0,0 +1,10 @@ +namespace WinRMSharp.Contracts +{ + internal class Fault + { + public const string ERROR_OPERATION_ABORTED = "995"; + public const string SHELL_NOT_FOUND = "2150858843"; + public const string OPERATION_TIMEOUT = "2150858793"; + public const string INVALID_SELECTORS = "2150858843"; + } +} diff --git a/src/WinRMSharp/Contracts/Header.cs b/src/WinRMSharp/Contracts/Header.cs index 62b81bf..840af9e 100644 --- a/src/WinRMSharp/Contracts/Header.cs +++ b/src/WinRMSharp/Contracts/Header.cs @@ -33,7 +33,7 @@ public class Header public required Action Action { get; set; } [XmlArray(Namespace = Namespace.WSMAN_0)] - public Option[]? OptionSet { get; set; } + public List