-
-
Notifications
You must be signed in to change notification settings - Fork 970
Handle unknown channel messages correctly #1363
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
1ab1300
Handle unknown channel messages correctly
mus65 c2ea1d2
consider WantReply before sending failure reply
mus65 88583b4
Use RemoteChannelNumber for failure message
mus65 e9f7ed5
fix wrong ChannelNumber in SshCommand Channel Response
mus65 36ca148
Merge branch 'develop' into unknownrequestmessage
Rob-Hague File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
src/Renci.SshNet/Messages/Connection/ChannelRequest/UnknownRequestInfo.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| namespace Renci.SshNet.Messages.Connection | ||
| { | ||
| /// <summary> | ||
| /// Represents an unknown request information that we can't handle. | ||
| /// </summary> | ||
| internal sealed class UnknownRequestInfo : RequestInfo | ||
| { | ||
| /// <summary> | ||
| /// Gets the name of the request. | ||
| /// </summary> | ||
| public override string RequestName { get; } | ||
|
|
||
| /// <summary> | ||
| /// Initializes a new instance of the <see cref="UnknownRequestInfo"/> class. | ||
| /// <paramref name="requestName">The name of the unknown request.</paramref> | ||
| /// </summary> | ||
| internal UnknownRequestInfo(string requestName) | ||
| { | ||
| RequestName = requestName; | ||
| } | ||
| } | ||
| } |
85 changes: 85 additions & 0 deletions
85
...ests/Classes/Channels/ChannelTest_OnSessionChannelRequestReceived_HandleUnknownMessage.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
|
|
||
| using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
|
|
||
| using Moq; | ||
|
|
||
| using Renci.SshNet.Common; | ||
| using Renci.SshNet.Messages; | ||
| using Renci.SshNet.Messages.Connection; | ||
|
|
||
| namespace Renci.SshNet.Tests.Classes.Channels | ||
| { | ||
| [TestClass] | ||
| public class ChannelTest_OnSessionChannelRequestReceived_HandleUnknownMessage : ChannelTestBase | ||
| { | ||
| private uint _localWindowSize; | ||
| private uint _localPacketSize; | ||
| private uint _localChannelNumber; | ||
| private ChannelStub _channel; | ||
| private IList<ExceptionEventArgs> _channelExceptionRegister; | ||
| private UnknownRequestInfoWithWantReply _requestInfo; | ||
|
|
||
| protected override void SetupData() | ||
| { | ||
| var random = new Random(); | ||
|
|
||
| _localWindowSize = (uint) random.Next(1000, int.MaxValue); | ||
| _localPacketSize = _localWindowSize - 1; | ||
| _localChannelNumber = (uint) random.Next(0, int.MaxValue); | ||
| _channelExceptionRegister = new List<ExceptionEventArgs>(); | ||
| _requestInfo = new UnknownRequestInfoWithWantReply(); | ||
| } | ||
|
|
||
| protected override void SetupMocks() | ||
| { | ||
| _ = SessionMock.Setup(p => p.ConnectionInfo) | ||
| .Returns(new ConnectionInfo("host", "user", new PasswordAuthenticationMethod("user", "password"))); | ||
| _ = SessionMock.Setup(p => p.SendMessage(It.IsAny<Message>())); | ||
| } | ||
|
|
||
| protected override void Arrange() | ||
| { | ||
| base.Arrange(); | ||
|
|
||
| _channel = new ChannelStub(SessionMock.Object, _localChannelNumber, _localWindowSize, _localPacketSize); | ||
| _channel.SetIsOpen(true); | ||
| _channel.Exception += (sender, args) => _channelExceptionRegister.Add(args); | ||
| } | ||
|
|
||
| protected override void Act() | ||
| { | ||
| SessionMock.Raise(s => s.ChannelRequestReceived += null, | ||
| new MessageEventArgs<ChannelRequestMessage>(new ChannelRequestMessage(_localChannelNumber, _requestInfo))); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| public void FailureMessageWasSent() | ||
| { | ||
| SessionMock.Verify(p => p.SendMessage(It.Is<ChannelFailureMessage>(m => m.LocalChannelNumber == _localChannelNumber)), Times.Once); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| public void NoExceptionShouldHaveFired() | ||
| { | ||
| Assert.AreEqual(0, _channelExceptionRegister.Count); | ||
| } | ||
| } | ||
|
|
||
| internal class UnknownRequestInfoWithWantReply : RequestInfo | ||
| { | ||
| public override string RequestName | ||
| { | ||
| get | ||
| { | ||
| return nameof(UnknownRequestInfoWithWantReply); | ||
| } | ||
| } | ||
|
|
||
| internal UnknownRequestInfoWithWantReply() | ||
| { | ||
| WantReply = true; | ||
| } | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.