From 4b7733aaa7fa5ce03391c98fa2ac8555fb39f679 Mon Sep 17 00:00:00 2001 From: Marius Thesing Date: Wed, 12 Aug 2026 21:06:36 +0200 Subject: [PATCH] Drop some dead internal code --- .../Abstractions/SocketAbstraction.cs | 34 ---- .../Authentication/RequestMessageHost.cs | 104 ------------- src/Renci.SshNet/Session.cs | 14 -- .../ExtendedRequests/FStatVfsRequest.cs | 56 ------- .../ExtendedRequests/HardLinkRequest.cs | 57 ------- .../Sftp/Requests/SftpBlockRequest.cs | 71 --------- .../Sftp/Requests/SftpLinkRequest.cs | 86 ----------- .../Sftp/Requests/SftpReadLinkRequest.cs | 78 ---------- .../Sftp/Requests/SftpUnblockRequest.cs | 65 -------- src/Renci.SshNet/Sftp/SftpSession.cs | 146 ------------------ src/Renci.SshNet/SshMessageFactory.cs | 9 -- .../ExtendedRequests/FStatVfsRequestTest.cs | 124 --------------- .../ExtendedRequests/HardLinkRequestTest.cs | 117 -------------- .../Sftp/Requests/SftpBlockRequestTest.cs | 103 ------------ .../Sftp/Requests/SftpLinkRequestTest.cs | 111 ------------- .../Sftp/Requests/SftpReadLinkRequestTest.cs | 129 ---------------- .../Sftp/Requests/SftpUnblockRequestTest.cs | 96 ------------ 17 files changed, 1400 deletions(-) delete mode 100644 src/Renci.SshNet/Messages/Authentication/RequestMessageHost.cs delete mode 100644 src/Renci.SshNet/Sftp/Requests/ExtendedRequests/FStatVfsRequest.cs delete mode 100644 src/Renci.SshNet/Sftp/Requests/ExtendedRequests/HardLinkRequest.cs delete mode 100644 src/Renci.SshNet/Sftp/Requests/SftpBlockRequest.cs delete mode 100644 src/Renci.SshNet/Sftp/Requests/SftpLinkRequest.cs delete mode 100644 src/Renci.SshNet/Sftp/Requests/SftpReadLinkRequest.cs delete mode 100644 src/Renci.SshNet/Sftp/Requests/SftpUnblockRequest.cs delete mode 100644 test/Renci.SshNet.Tests/Classes/Sftp/Requests/ExtendedRequests/FStatVfsRequestTest.cs delete mode 100644 test/Renci.SshNet.Tests/Classes/Sftp/Requests/ExtendedRequests/HardLinkRequestTest.cs delete mode 100644 test/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpBlockRequestTest.cs delete mode 100644 test/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpLinkRequestTest.cs delete mode 100644 test/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpReadLinkRequestTest.cs delete mode 100644 test/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpUnblockRequestTest.cs diff --git a/src/Renci.SshNet/Abstractions/SocketAbstraction.cs b/src/Renci.SshNet/Abstractions/SocketAbstraction.cs index 1dc992da5..080d2231a 100644 --- a/src/Renci.SshNet/Abstractions/SocketAbstraction.cs +++ b/src/Renci.SshNet/Abstractions/SocketAbstraction.cs @@ -88,40 +88,6 @@ private static void ConnectCore(Socket socket, EndPoint remoteEndpoint, TimeSpan args.Dispose(); } - public static void ClearReadBuffer(Socket socket) - { - var timeout = TimeSpan.FromMilliseconds(500); - var buffer = new byte[256]; - int bytesReceived; - - do - { - bytesReceived = ReadPartial(socket, buffer, 0, buffer.Length, timeout); - } - while (bytesReceived > 0); - } - - public static int ReadPartial(Socket socket, byte[] buffer, int offset, int size, TimeSpan timeout) - { - socket.ReceiveTimeout = timeout.AsTimeout(); - - try - { - return socket.Receive(buffer, offset, size, SocketFlags.None); - } - catch (SocketException ex) - { - if (ex.SocketErrorCode == SocketError.TimedOut) - { - throw new SshOperationTimeoutException(string.Format(CultureInfo.InvariantCulture, - "Socket read operation has timed out after {0:F0} milliseconds.", - timeout.TotalMilliseconds)); - } - - throw; - } - } - public static void ReadContinuous(Socket socket, byte[] buffer, int offset, int size, Action processReceivedBytesAction) { // do not time-out receive diff --git a/src/Renci.SshNet/Messages/Authentication/RequestMessageHost.cs b/src/Renci.SshNet/Messages/Authentication/RequestMessageHost.cs deleted file mode 100644 index ec9fd2047..000000000 --- a/src/Renci.SshNet/Messages/Authentication/RequestMessageHost.cs +++ /dev/null @@ -1,104 +0,0 @@ -namespace Renci.SshNet.Messages.Authentication -{ - /// - /// Represents "hostbased" SSH_MSG_USERAUTH_REQUEST message. - /// - internal sealed class RequestMessageHost : RequestMessage - { - /// - /// Gets the public key algorithm for host key as ASCII encoded byte array. - /// - public byte[] PublicKeyAlgorithm { get; } - - /// - /// Gets the public host key and certificates for client host. - /// - /// - /// The public host key. - /// - public byte[] PublicHostKey { get; } - - /// - /// Gets the name of the client host as ASCII encoded byte array. - /// - /// - /// The name of the client host. - /// - public byte[] ClientHostName { get; } - - /// - /// Gets the client username on the client host as UTF-8 encoded byte array. - /// - /// - /// The client username. - /// - public byte[] ClientUsername { get; } - - /// - /// Gets the signature. - /// - /// - /// The signature. - /// - public byte[] Signature { get; } - - /// - /// Gets the size of the message in bytes. - /// - /// - /// The size of the messages in bytes. - /// - protected override int BufferCapacity - { - get - { - var capacity = base.BufferCapacity; - capacity += 4; // PublicKeyAlgorithm length - capacity += PublicKeyAlgorithm.Length; // PublicKeyAlgorithm - capacity += 4; // PublicHostKey length - capacity += PublicHostKey.Length; // PublicHostKey - capacity += 4; // ClientHostName length - capacity += ClientHostName.Length; // ClientHostName - capacity += 4; // ClientUsername length - capacity += ClientUsername.Length; // ClientUsername - capacity += 4; // Signature length - capacity += Signature.Length; // Signature - return capacity; - } - } - - /// - /// Initializes a new instance of the class. - /// - /// Name of the service. - /// Authentication username. - /// The public key algorithm. - /// The public host key. - /// Name of the client host. - /// The client username. - /// The signature. - public RequestMessageHost(ServiceName serviceName, string username, string publicKeyAlgorithm, byte[] publicHostKey, string clientHostName, string clientUsername, byte[] signature) - : base(serviceName, username, "hostbased") - { - PublicKeyAlgorithm = Ascii.GetBytes(publicKeyAlgorithm); - PublicHostKey = publicHostKey; - ClientHostName = Ascii.GetBytes(clientHostName); - ClientUsername = Utf8.GetBytes(clientUsername); - Signature = signature; - } - - /// - /// Called when type specific data need to be saved. - /// - protected override void SaveData() - { - base.SaveData(); - - WriteBinaryString(PublicKeyAlgorithm); - WriteBinaryString(PublicHostKey); - WriteBinaryString(ClientHostName); - WriteBinaryString(ClientUsername); - WriteBinaryString(Signature); - } - } -} diff --git a/src/Renci.SshNet/Session.cs b/src/Renci.SshNet/Session.cs index 5468b53c8..559294209 100644 --- a/src/Renci.SshNet/Session.cs +++ b/src/Renci.SshNet/Session.cs @@ -467,11 +467,6 @@ public string ClientVersion /// internal event EventHandler> NewKeysReceived; - /// - /// Occurs when message received - /// - internal event EventHandler> UserAuthenticationRequestReceived; - /// /// Occurs when message received /// @@ -1675,15 +1670,6 @@ void ISession.OnDisconnecting() _isDisconnecting = true; } - /// - /// Called when message received. - /// - /// message. - internal void OnUserAuthenticationRequestReceived(RequestMessage message) - { - UserAuthenticationRequestReceived?.Invoke(this, new MessageEventArgs(message)); - } - /// /// Called when message received. /// diff --git a/src/Renci.SshNet/Sftp/Requests/ExtendedRequests/FStatVfsRequest.cs b/src/Renci.SshNet/Sftp/Requests/ExtendedRequests/FStatVfsRequest.cs deleted file mode 100644 index 685c03692..000000000 --- a/src/Renci.SshNet/Sftp/Requests/ExtendedRequests/FStatVfsRequest.cs +++ /dev/null @@ -1,56 +0,0 @@ -using System; - -using Renci.SshNet.Sftp.Responses; - -namespace Renci.SshNet.Sftp.Requests -{ - internal sealed class FStatVfsRequest : SftpExtendedRequest - { - private readonly Action _extendedReplyAction; - - public byte[] Handle { get; private set; } - - /// - /// Gets the size of the message in bytes. - /// - /// - /// The size of the messages in bytes. - /// - protected override int BufferCapacity - { - get - { - var capacity = base.BufferCapacity; - capacity += 4; // Handle length - capacity += Handle.Length; // Handle - return capacity; - } - } - - public FStatVfsRequest(uint protocolVersion, uint requestId, byte[] handle, Action extendedAction, Action statusAction) - : base(protocolVersion, requestId, statusAction, "fstatvfs@openssh.com") - { - Handle = handle; - - _extendedReplyAction = extendedAction; - } - - protected override void SaveData() - { - base.SaveData(); - WriteBinaryString(Handle); - } - - public override void Complete(SftpResponse response) - { - if (response is SftpExtendedReplyResponse extendedReplyResponse) - { - _extendedReplyAction(extendedReplyResponse); - } - else - { - base.Complete(response); - } - } - } -} diff --git a/src/Renci.SshNet/Sftp/Requests/ExtendedRequests/HardLinkRequest.cs b/src/Renci.SshNet/Sftp/Requests/ExtendedRequests/HardLinkRequest.cs deleted file mode 100644 index cd744f0e2..000000000 --- a/src/Renci.SshNet/Sftp/Requests/ExtendedRequests/HardLinkRequest.cs +++ /dev/null @@ -1,57 +0,0 @@ -using System; - -using Renci.SshNet.Sftp.Responses; - -namespace Renci.SshNet.Sftp.Requests -{ - internal sealed class HardLinkRequest : SftpExtendedRequest - { - private byte[] _oldPath; - private byte[] _newPath; - - public string OldPath - { - get { return Utf8.GetString(_oldPath, 0, _oldPath.Length); } - private set { _oldPath = Utf8.GetBytes(value); } - } - - public string NewPath - { - get { return Utf8.GetString(_newPath, 0, _newPath.Length); } - private set { _newPath = Utf8.GetBytes(value); } - } - - /// - /// Gets the size of the message in bytes. - /// - /// - /// The size of the messages in bytes. - /// - protected override int BufferCapacity - { - get - { - var capacity = base.BufferCapacity; - capacity += 4; // OldPath length - capacity += _oldPath.Length; // OldPath - capacity += 4; // NewPath length - capacity += _newPath.Length; // NewPath - return capacity; - } - } - - public HardLinkRequest(uint protocolVersion, uint requestId, string oldPath, string newPath, Action statusAction) - : base(protocolVersion, requestId, statusAction, "hardlink@openssh.com") - { - OldPath = oldPath; - NewPath = newPath; - } - - protected override void SaveData() - { - base.SaveData(); - WriteBinaryString(_oldPath); - WriteBinaryString(_newPath); - } - } -} diff --git a/src/Renci.SshNet/Sftp/Requests/SftpBlockRequest.cs b/src/Renci.SshNet/Sftp/Requests/SftpBlockRequest.cs deleted file mode 100644 index 9c2ccd6ca..000000000 --- a/src/Renci.SshNet/Sftp/Requests/SftpBlockRequest.cs +++ /dev/null @@ -1,71 +0,0 @@ -using System; - -using Renci.SshNet.Sftp.Responses; - -namespace Renci.SshNet.Sftp.Requests -{ - internal sealed class SftpBlockRequest : SftpRequest - { - public override SftpMessageTypes SftpMessageType - { - get { return SftpMessageTypes.Block; } - } - - public byte[] Handle { get; private set; } - - public ulong Offset { get; private set; } - - public ulong Length { get; private set; } - - public uint LockMask { get; private set; } - - /// - /// Gets the size of the message in bytes. - /// - /// - /// The size of the messages in bytes. - /// - protected override int BufferCapacity - { - get - { - var capacity = base.BufferCapacity; - capacity += 4; // Handle length - capacity += Handle.Length; // Handle - capacity += 8; // Offset - capacity += 8; // Length - capacity += 4; // LockMask - return capacity; - } - } - - public SftpBlockRequest(uint protocolVersion, uint requestId, byte[] handle, ulong offset, ulong length, uint lockMask, Action statusAction) - : base(protocolVersion, requestId, statusAction) - { - Handle = handle; - Offset = offset; - Length = length; - LockMask = lockMask; - } - - protected override void LoadData() - { - base.LoadData(); - - Handle = ReadBinary(); - Offset = ReadUInt64(); - Length = ReadUInt64(); - LockMask = ReadUInt32(); - } - - protected override void SaveData() - { - base.SaveData(); - - WriteBinaryString(Handle); - Write(Offset); - Write(Length); - Write(LockMask); - } - } -} diff --git a/src/Renci.SshNet/Sftp/Requests/SftpLinkRequest.cs b/src/Renci.SshNet/Sftp/Requests/SftpLinkRequest.cs deleted file mode 100644 index b5b8a9efc..000000000 --- a/src/Renci.SshNet/Sftp/Requests/SftpLinkRequest.cs +++ /dev/null @@ -1,86 +0,0 @@ -using System; - -using Renci.SshNet.Sftp.Responses; - -namespace Renci.SshNet.Sftp.Requests -{ - internal sealed class SftpLinkRequest : SftpRequest - { - private byte[] _newLinkPath; - private byte[] _existingPath; - - public override SftpMessageTypes SftpMessageType - { - get { return SftpMessageTypes.Link; } - } - - public string NewLinkPath - { - get { return Utf8.GetString(_newLinkPath, 0, _newLinkPath.Length); } - private set { _newLinkPath = Utf8.GetBytes(value); } - } - - public string ExistingPath - { - get { return Utf8.GetString(_existingPath, 0, _existingPath.Length); } - private set { _existingPath = Utf8.GetBytes(value); } - } - - public bool IsSymLink { get; private set; } - - /// - /// Gets the size of the message in bytes. - /// - /// - /// The size of the messages in bytes. - /// - protected override int BufferCapacity - { - get - { - var capacity = base.BufferCapacity; - capacity += 4; // NewLinkPath length - capacity += NewLinkPath.Length; // NewLinkPath - capacity += 4; // ExistingPath length - capacity += ExistingPath.Length; // ExistingPath - capacity += 1; // IsSymLink - return capacity; - } - } - - /// - /// Initializes a new instance of the class. - /// - /// The protocol version. - /// The request id. - /// Specifies the path name of the new link to create. - /// Specifies the path of a target object to which the newly created link will refer. In the case of a symbolic link, this path may not exist. - /// if set to the link should be a hard link, or a second directory entry referring to the same file or directory object. - /// The status action. - public SftpLinkRequest(uint protocolVersion, uint requestId, string newLinkPath, string existingPath, bool isSymLink, Action statusAction) - : base(protocolVersion, requestId, statusAction) - { - NewLinkPath = newLinkPath; - ExistingPath = existingPath; - IsSymLink = isSymLink; - } - - protected override void LoadData() - { - base.LoadData(); - - _newLinkPath = ReadBinary(); - _existingPath = ReadBinary(); - IsSymLink = ReadBoolean(); - } - - protected override void SaveData() - { - base.SaveData(); - - WriteBinaryString(_newLinkPath); - WriteBinaryString(_existingPath); - Write(IsSymLink); - } - } -} diff --git a/src/Renci.SshNet/Sftp/Requests/SftpReadLinkRequest.cs b/src/Renci.SshNet/Sftp/Requests/SftpReadLinkRequest.cs deleted file mode 100644 index 969eca564..000000000 --- a/src/Renci.SshNet/Sftp/Requests/SftpReadLinkRequest.cs +++ /dev/null @@ -1,78 +0,0 @@ -using System; -using System.Text; - -using Renci.SshNet.Sftp.Responses; - -namespace Renci.SshNet.Sftp.Requests -{ - internal sealed class SftpReadLinkRequest : SftpRequest - { - private readonly Action _nameAction; - private byte[] _path; - - public override SftpMessageTypes SftpMessageType - { - get { return SftpMessageTypes.ReadLink; } - } - - public string Path - { - get { return Encoding.GetString(_path, 0, _path.Length); } - private set { _path = Encoding.GetBytes(value); } - } - - public Encoding Encoding { get; } - - /// - /// Gets the size of the message in bytes. - /// - /// - /// The size of the messages in bytes. - /// - protected override int BufferCapacity - { - get - { - var capacity = base.BufferCapacity; - capacity += 4; // Path length - capacity += _path.Length; // Handle - return capacity; - } - } - - public SftpReadLinkRequest(uint protocolVersion, uint requestId, string path, Encoding encoding, Action nameAction, Action statusAction) - : base(protocolVersion, requestId, statusAction) - { - Encoding = encoding; - Path = path; - - _nameAction = nameAction; - } - - protected override void LoadData() - { - base.LoadData(); - - _path = ReadBinary(); - } - - protected override void SaveData() - { - base.SaveData(); - - WriteBinaryString(_path); - } - - public override void Complete(SftpResponse response) - { - if (response is SftpNameResponse nameResponse) - { - _nameAction(nameResponse); - } - else - { - base.Complete(response); - } - } - } -} diff --git a/src/Renci.SshNet/Sftp/Requests/SftpUnblockRequest.cs b/src/Renci.SshNet/Sftp/Requests/SftpUnblockRequest.cs deleted file mode 100644 index e456f98cf..000000000 --- a/src/Renci.SshNet/Sftp/Requests/SftpUnblockRequest.cs +++ /dev/null @@ -1,65 +0,0 @@ -using System; - -using Renci.SshNet.Sftp.Responses; - -namespace Renci.SshNet.Sftp.Requests -{ - internal sealed class SftpUnblockRequest : SftpRequest - { - public override SftpMessageTypes SftpMessageType - { - get { return SftpMessageTypes.Unblock; } - } - - public byte[] Handle { get; private set; } - - public ulong Offset { get; private set; } - - public ulong Length { get; private set; } - - /// - /// Gets the size of the message in bytes. - /// - /// - /// The size of the messages in bytes. - /// - protected override int BufferCapacity - { - get - { - var capacity = base.BufferCapacity; - capacity += 4; // Handle length - capacity += Handle.Length; // Handle - capacity += 8; // Offset - capacity += 8; // Length - return capacity; - } - } - - public SftpUnblockRequest(uint protocolVersion, uint requestId, byte[] handle, ulong offset, ulong length, Action statusAction) - : base(protocolVersion, requestId, statusAction) - { - Handle = handle; - Offset = offset; - Length = length; - } - - protected override void LoadData() - { - base.LoadData(); - - Handle = ReadBinary(); - Offset = ReadUInt64(); - Length = ReadUInt64(); - } - - protected override void SaveData() - { - base.SaveData(); - - WriteBinaryString(Handle); - Write(Offset); - Write(Length); - } - } -} diff --git a/src/Renci.SshNet/Sftp/SftpSession.cs b/src/Renci.SshNet/Sftp/SftpSession.cs index 6b2198053..041554505 100644 --- a/src/Renci.SshNet/Sftp/SftpSession.cs +++ b/src/Renci.SshNet/Sftp/SftpSession.cs @@ -1310,56 +1310,6 @@ public Task RequestRenameAsync(string oldPath, string newPath, CancellationToken return WaitOnHandleAsync(tcs, OperationTimeout, cancellationToken); } - /// - /// Performs SSH_FXP_READLINK request. - /// - /// The path. - /// if set to returns instead of throwing an exception. - /// - /// An array of where the key is the name of - /// a file and the value is the of the file. - /// - internal KeyValuePair[] RequestReadLink(string path, bool nullOnError = false) - { - if (ProtocolVersion < 3) - { - throw new NotSupportedException(string.Format(CultureInfo.CurrentCulture, "SSH_FXP_READLINK operation is not supported in {0} version that server operates in.", ProtocolVersion)); - } - - SftpException exception = null; - - KeyValuePair[] result = null; - - using (var wait = new AutoResetEvent(initialState: false)) - { - var request = new SftpReadLinkRequest(ProtocolVersion, - NextRequestId, - path, - _encoding, - response => - { - result = response.Files; - wait.SetIgnoringObjectDisposed(); - }, - response => - { - exception = GetSftpException(response, path); - wait.SetIgnoringObjectDisposed(); - }); - - SendRequest(request); - - WaitOnHandle(wait, OperationTimeout); - } - - if (!nullOnError && exception is not null) - { - throw exception; - } - - return result; - } - /// public void RequestSymLink(string linkpath, string targetpath) { @@ -1507,102 +1457,6 @@ public Task RequestStatVfsAsync(string path, Cancella return WaitOnHandleAsync(tcs, OperationTimeout, cancellationToken); } - /// - /// Performs fstatvfs@openssh.com extended request. - /// - /// The file handle. - /// if set to [null on error]. - /// - /// A for the specified path. - /// - /// This operation is not supported for the current SFTP protocol version. - internal SftpFileSystemInformation RequestFStatVfs(byte[] handle, bool nullOnError = false) - { - if (ProtocolVersion < 3) - { - throw new NotSupportedException(string.Format(CultureInfo.CurrentCulture, "SSH_FXP_EXTENDED operation is not supported in {0} version that server operates in.", ProtocolVersion)); - } - - SftpException exception = null; - - SftpFileSystemInformation information = null; - - using (var wait = new AutoResetEvent(initialState: false)) - { - var request = new FStatVfsRequest(ProtocolVersion, - NextRequestId, - handle, - response => - { - information = response.GetReply().Information; - wait.SetIgnoringObjectDisposed(); - }, - response => - { - exception = GetSftpException(response); - wait.SetIgnoringObjectDisposed(); - }); - - if (!_supportedExtensions.ContainsKey(request.Name)) - { - throw new NotSupportedException(string.Format(CultureInfo.CurrentCulture, "Extension method {0} currently not supported by the server.", request.Name)); - } - - SendRequest(request); - - WaitOnHandle(wait, OperationTimeout); - } - - if (!nullOnError && exception is not null) - { - throw exception; - } - - return information; - } - - /// - /// Performs hardlink@openssh.com extended request. - /// - /// The old path. - /// The new path. - internal void HardLink(string oldPath, string newPath) - { - if (ProtocolVersion < 3) - { - throw new NotSupportedException(string.Format(CultureInfo.CurrentCulture, "SSH_FXP_EXTENDED operation is not supported in {0} version that server operates in.", ProtocolVersion)); - } - - SftpException exception = null; - - using (var wait = new AutoResetEvent(initialState: false)) - { - var request = new HardLinkRequest(ProtocolVersion, - NextRequestId, - oldPath, - newPath, - response => - { - exception = GetSftpException(response); - wait.SetIgnoringObjectDisposed(); - }); - - if (!_supportedExtensions.ContainsKey(request.Name)) - { - throw new NotSupportedException(string.Format(CultureInfo.CurrentCulture, "Extension method {0} currently not supported by the server.", request.Name)); - } - - SendRequest(request); - - WaitOnHandle(wait, OperationTimeout); - } - - if (exception is not null) - { - throw exception; - } - } - /// /// Calculates the optimal size of the buffer to read data from the channel. /// diff --git a/src/Renci.SshNet/SshMessageFactory.cs b/src/Renci.SshNet/SshMessageFactory.cs index d598ff867..9985e1611 100644 --- a/src/Renci.SshNet/SshMessageFactory.cs +++ b/src/Renci.SshNet/SshMessageFactory.cs @@ -77,15 +77,6 @@ public SshMessageFactory() _enabledMessagesByNumber = new MessageMetadata[HighestMessageNumber + 1]; } - /// - /// Disables and deactivate all messages. - /// - public void Reset() - { - Array.Clear(_activatedMessagesById, 0, _activatedMessagesById.Length); - Array.Clear(_enabledMessagesByNumber, 0, _enabledMessagesByNumber.Length); - } - public Message Create(byte messageNumber) { if (messageNumber > HighestMessageNumber) diff --git a/test/Renci.SshNet.Tests/Classes/Sftp/Requests/ExtendedRequests/FStatVfsRequestTest.cs b/test/Renci.SshNet.Tests/Classes/Sftp/Requests/ExtendedRequests/FStatVfsRequestTest.cs deleted file mode 100644 index 3b776e8f6..000000000 --- a/test/Renci.SshNet.Tests/Classes/Sftp/Requests/ExtendedRequests/FStatVfsRequestTest.cs +++ /dev/null @@ -1,124 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -using Microsoft.VisualStudio.TestTools.UnitTesting; - -using Renci.SshNet.Common; -using Renci.SshNet.Sftp; -using Renci.SshNet.Sftp.Requests; -using Renci.SshNet.Sftp.Responses; - -namespace Renci.SshNet.Tests.Classes.Sftp.Requests.ExtendedRequests -{ - [TestClass] - public class FStatVfsRequestTest - { - private uint _protocolVersion; - private uint _requestId; - private byte[] _handle; - private string _name; - private byte[] _nameBytes; - - [TestInitialize] - public void Init() - { - var random = new Random(); - _protocolVersion = (uint)random.Next(0, int.MaxValue); - _requestId = (uint)random.Next(0, int.MaxValue); - _handle = new byte[random.Next(1, 10)]; - random.NextBytes(_handle); - - _name = "fstatvfs@openssh.com"; - _nameBytes = Encoding.UTF8.GetBytes(_name); - } - - [TestMethod] - public void Constructor() - { - var request = new FStatVfsRequest(_protocolVersion, _requestId, _handle, null, null); - - Assert.AreSame(_handle, request.Handle); - Assert.AreEqual(_name, request.Name); - Assert.AreEqual(_protocolVersion, request.ProtocolVersion); - Assert.AreEqual(_requestId, request.RequestId); - Assert.AreEqual(SftpMessageTypes.Extended, request.SftpMessageType); - } - - [TestMethod] - public void Complete_SftpStatusResponse() - { - IList statusActionInvocations = new List(); - IList extendedReplyActionInvocations = new List(); - - Action extendedAction = extendedReplyActionInvocations.Add; - Action statusAction = statusActionInvocations.Add; - var statusResponse = new SftpStatusResponse(_protocolVersion); - - var request = new FStatVfsRequest(_protocolVersion, _requestId, _handle, extendedAction, statusAction); - - request.Complete(statusResponse); - - Assert.HasCount(1, statusActionInvocations); - Assert.AreSame(statusResponse, statusActionInvocations[0]); - Assert.IsEmpty(extendedReplyActionInvocations); - } - - [TestMethod] - public void Complete_SftpExtendedReplyResponse() - { - IList statusActionInvocations = new List(); - IList extendedReplyActionInvocations = new List(); - - Action extendedAction = extendedReplyActionInvocations.Add; - Action statusAction = statusActionInvocations.Add; - var extendedReplyResponse = new SftpExtendedReplyResponse(_protocolVersion); - - var request = new FStatVfsRequest(_protocolVersion, _requestId, _handle, extendedAction, statusAction); - - request.Complete(extendedReplyResponse); - - Assert.IsEmpty(statusActionInvocations); - Assert.HasCount(1, extendedReplyActionInvocations); - Assert.AreSame(extendedReplyResponse, extendedReplyActionInvocations[0]); - } - - [TestMethod] - public void GetBytes() - { - var request = new FStatVfsRequest(_protocolVersion, _requestId, _handle, null, null); - - var bytes = request.GetBytes(); - - var expectedBytesLength = 0; - expectedBytesLength += 4; // Length - expectedBytesLength += 1; // Type - expectedBytesLength += 4; // RequestId - expectedBytesLength += 4; // Name length - expectedBytesLength += _nameBytes.Length; // Name - expectedBytesLength += 4; // Handle length - expectedBytesLength += _handle.Length; // Handle - - Assert.HasCount(expectedBytesLength, bytes); - - var sshDataStream = new SshDataStream(bytes); - - Assert.AreEqual((uint)bytes.Length - 4, sshDataStream.ReadUInt32()); - Assert.AreEqual((byte)SftpMessageTypes.Extended, sshDataStream.ReadByte()); - Assert.AreEqual(_requestId, sshDataStream.ReadUInt32()); - Assert.AreEqual((uint)_nameBytes.Length, sshDataStream.ReadUInt32()); - - var actualNameBytes = new byte[_nameBytes.Length]; - _ = sshDataStream.Read(actualNameBytes, 0, actualNameBytes.Length); - CollectionAssert.AreEqual(_nameBytes, actualNameBytes); - - Assert.AreEqual((uint)_handle.Length, sshDataStream.ReadUInt32()); - - var actualHandle = new byte[_handle.Length]; - _ = sshDataStream.Read(actualHandle, 0, actualHandle.Length); - CollectionAssert.AreEqual(_handle, actualHandle); - - Assert.IsTrue(sshDataStream.IsEndOfData); - } - } -} diff --git a/test/Renci.SshNet.Tests/Classes/Sftp/Requests/ExtendedRequests/HardLinkRequestTest.cs b/test/Renci.SshNet.Tests/Classes/Sftp/Requests/ExtendedRequests/HardLinkRequestTest.cs deleted file mode 100644 index c363eae17..000000000 --- a/test/Renci.SshNet.Tests/Classes/Sftp/Requests/ExtendedRequests/HardLinkRequestTest.cs +++ /dev/null @@ -1,117 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Text; - -using Microsoft.VisualStudio.TestTools.UnitTesting; - -using Renci.SshNet.Common; -using Renci.SshNet.Sftp; -using Renci.SshNet.Sftp.Requests; -using Renci.SshNet.Sftp.Responses; - -namespace Renci.SshNet.Tests.Classes.Sftp.Requests.ExtendedRequests -{ - [TestClass] - public class HardLinkRequestTest - { - private uint _protocolVersion; - private uint _requestId; - private string _name; - private string _oldPath; - private byte[] _oldPathBytes; - private string _newPath; - private byte[] _newPathBytes; - private byte[] _nameBytes; - - [TestInitialize] - public void Init() - { - var random = new Random(); - _protocolVersion = (uint)random.Next(0, int.MaxValue); - _requestId = (uint)random.Next(0, int.MaxValue); - _oldPath = random.Next().ToString(CultureInfo.InvariantCulture); - _oldPathBytes = Encoding.UTF8.GetBytes(_oldPath); - _newPath = random.Next().ToString(CultureInfo.InvariantCulture); - _newPathBytes = Encoding.UTF8.GetBytes(_newPath); - - _name = "hardlink@openssh.com"; - _nameBytes = Encoding.UTF8.GetBytes(_name); - } - - [TestMethod] - public void Constructor() - { - var request = new HardLinkRequest(_protocolVersion, _requestId, _oldPath, _newPath, null); - - Assert.AreEqual(_name, request.Name); - Assert.AreEqual(_newPath, request.NewPath); - Assert.AreEqual(_oldPath, request.OldPath); - Assert.AreEqual(_protocolVersion, request.ProtocolVersion); - Assert.AreEqual(_requestId, request.RequestId); - Assert.AreEqual(SftpMessageTypes.Extended, request.SftpMessageType); - } - - [TestMethod] - public void Complete_SftpStatusResponse() - { - IList statusActionInvocations = new List(); - - Action statusAction = statusActionInvocations.Add; - var statusResponse = new SftpStatusResponse(_protocolVersion); - - var request = new HardLinkRequest(_protocolVersion, _requestId, _oldPath, _newPath, statusAction); - - request.Complete(statusResponse); - - Assert.HasCount(1, statusActionInvocations); - Assert.AreSame(statusResponse, statusActionInvocations[0]); - } - - [TestMethod] - public void GetBytes() - { - var request = new HardLinkRequest(_protocolVersion, _requestId, _oldPath, _newPath, null); - - var bytes = request.GetBytes(); - - var expectedBytesLength = 0; - expectedBytesLength += 4; // Length - expectedBytesLength += 1; // Type - expectedBytesLength += 4; // RequestId - expectedBytesLength += 4; // Name length - expectedBytesLength += _nameBytes.Length; // Name - expectedBytesLength += 4; // OldPath length - expectedBytesLength += _oldPathBytes.Length; // OldPath - expectedBytesLength += 4; // NewPath length - expectedBytesLength += _newPathBytes.Length; // NewPath - - Assert.HasCount(expectedBytesLength, bytes); - - var sshDataStream = new SshDataStream(bytes); - - Assert.AreEqual((uint)bytes.Length - 4, sshDataStream.ReadUInt32()); - Assert.AreEqual((byte)SftpMessageTypes.Extended, sshDataStream.ReadByte()); - Assert.AreEqual(_requestId, sshDataStream.ReadUInt32()); - Assert.AreEqual((uint)_nameBytes.Length, sshDataStream.ReadUInt32()); - - var actualNameBytes = new byte[_nameBytes.Length]; - _ = sshDataStream.Read(actualNameBytes, 0, actualNameBytes.Length); - CollectionAssert.AreEqual(_nameBytes, actualNameBytes); - - Assert.AreEqual((uint)_oldPathBytes.Length, sshDataStream.ReadUInt32()); - - var actualOldPath = new byte[_oldPathBytes.Length]; - _ = sshDataStream.Read(actualOldPath, 0, actualOldPath.Length); - CollectionAssert.AreEqual(_oldPathBytes, actualOldPath); - - Assert.AreEqual((uint)_newPathBytes.Length, sshDataStream.ReadUInt32()); - - var actualNewPath = new byte[_newPathBytes.Length]; - _ = sshDataStream.Read(actualNewPath, 0, actualNewPath.Length); - CollectionAssert.AreEqual(_newPathBytes, actualNewPath); - - Assert.IsTrue(sshDataStream.IsEndOfData); - } - } -} diff --git a/test/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpBlockRequestTest.cs b/test/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpBlockRequestTest.cs deleted file mode 100644 index f8182660d..000000000 --- a/test/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpBlockRequestTest.cs +++ /dev/null @@ -1,103 +0,0 @@ -using System; -using System.Collections.Generic; - -using Microsoft.VisualStudio.TestTools.UnitTesting; - -using Renci.SshNet.Common; -using Renci.SshNet.Sftp; -using Renci.SshNet.Sftp.Requests; -using Renci.SshNet.Sftp.Responses; - -namespace Renci.SshNet.Tests.Classes.Sftp.Requests -{ - [TestClass] - public class SftpBlockRequestTest - { - private uint _protocolVersion; - private uint _requestId; - private byte[] _handle; - private ulong _offset; - private ulong _length; - private uint _lockMask; - - [TestInitialize] - public void Init() - { - var random = new Random(); - - _protocolVersion = (uint)random.Next(0, int.MaxValue); - _requestId = (uint)random.Next(0, int.MaxValue); - _handle = new byte[random.Next(1, 10)]; - random.NextBytes(_handle); - _offset = (ulong)random.Next(0, int.MaxValue); - _length = (ulong)random.Next(0, int.MaxValue); - _lockMask = (uint)random.Next(0, int.MaxValue); - } - - [TestMethod] - public void Constructor() - { - var request = new SftpBlockRequest(_protocolVersion, _requestId, _handle, _offset, _length, _lockMask, null); - - Assert.AreSame(_handle, request.Handle); - Assert.AreEqual(_length, request.Length); - Assert.AreEqual(_lockMask, request.LockMask); - Assert.AreEqual(_offset, request.Offset); - Assert.AreEqual(_protocolVersion, request.ProtocolVersion); - Assert.AreEqual(_requestId, request.RequestId); - Assert.AreEqual(SftpMessageTypes.Block, request.SftpMessageType); - } - - [TestMethod] - public void Complete_SftpStatusResponse() - { - IList statusActionInvocations = new List(); - - Action statusAction = statusActionInvocations.Add; - var statusResponse = new SftpStatusResponse(_protocolVersion); - - var request = new SftpBlockRequest(_protocolVersion, _requestId, _handle, _offset, _length, _lockMask, statusAction); - - request.Complete(statusResponse); - - Assert.HasCount(1, statusActionInvocations); - Assert.AreSame(statusResponse, statusActionInvocations[0]); - } - - [TestMethod] - public void GetBytes() - { - var request = new SftpBlockRequest(_protocolVersion, _requestId, _handle, _offset, _length, _lockMask, null); - - var bytes = request.GetBytes(); - - var expectedBytesLength = 0; - expectedBytesLength += 4; // Length - expectedBytesLength += 1; // Type - expectedBytesLength += 4; // RequestId - expectedBytesLength += 4; // Handle length - expectedBytesLength += _handle.Length; // Handle - expectedBytesLength += 8; // Offset - expectedBytesLength += 8; // Length - expectedBytesLength += 4; // LockMask - - Assert.HasCount(expectedBytesLength, bytes); - - var sshDataStream = new SshDataStream(bytes); - - Assert.AreEqual((uint)bytes.Length - 4, sshDataStream.ReadUInt32()); - Assert.AreEqual((byte)SftpMessageTypes.Block, sshDataStream.ReadByte()); - Assert.AreEqual(_requestId, sshDataStream.ReadUInt32()); - - Assert.AreEqual((uint)_handle.Length, sshDataStream.ReadUInt32()); - var actualHandle = new byte[_handle.Length]; - _ = sshDataStream.Read(actualHandle, 0, actualHandle.Length); - CollectionAssert.AreEqual(_handle, actualHandle); - - Assert.AreEqual(_offset, sshDataStream.ReadUInt64()); - Assert.AreEqual(_length, sshDataStream.ReadUInt64()); - Assert.AreEqual(_lockMask, sshDataStream.ReadUInt32()); - Assert.IsTrue(sshDataStream.IsEndOfData); - } - } -} diff --git a/test/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpLinkRequestTest.cs b/test/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpLinkRequestTest.cs deleted file mode 100644 index 34defb799..000000000 --- a/test/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpLinkRequestTest.cs +++ /dev/null @@ -1,111 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Text; - -using Microsoft.VisualStudio.TestTools.UnitTesting; - -using Renci.SshNet.Common; -using Renci.SshNet.Sftp; -using Renci.SshNet.Sftp.Requests; -using Renci.SshNet.Sftp.Responses; - -namespace Renci.SshNet.Tests.Classes.Sftp.Requests -{ - [TestClass] - public class SftpLinkRequestTest - { - private uint _protocolVersion; - private uint _requestId; - private string _newLinkPath; - private byte[] _newLinkPathBytes; - private string _existingPath; - private byte[] _existingPathBytes; - - [TestInitialize] - public void Init() - { - var random = new Random(); - - _protocolVersion = (uint)random.Next(0, int.MaxValue); - _requestId = (uint)random.Next(0, int.MaxValue); - _newLinkPath = random.Next().ToString(CultureInfo.InvariantCulture); - _newLinkPathBytes = Encoding.UTF8.GetBytes(_newLinkPath); - _existingPath = random.Next().ToString(CultureInfo.InvariantCulture); - _existingPathBytes = Encoding.UTF8.GetBytes(_existingPath); - } - - [TestMethod] - public void Constructor() - { - var request = new SftpLinkRequest(_protocolVersion, _requestId, _newLinkPath, _existingPath, true, null); - - Assert.AreEqual(_existingPath, request.ExistingPath); - Assert.IsTrue(request.IsSymLink); - Assert.AreEqual(_newLinkPath, request.NewLinkPath); - Assert.AreEqual(_protocolVersion, request.ProtocolVersion); - Assert.AreEqual(_requestId, request.RequestId); - Assert.AreEqual(SftpMessageTypes.Link, request.SftpMessageType); - - request = new SftpLinkRequest(_protocolVersion, _requestId, _newLinkPath, _existingPath, false, null); - - Assert.IsFalse(request.IsSymLink); - } - - [TestMethod] - public void Complete_SftpStatusResponse() - { - var statusActionInvocations = new List(); - - Action statusAction = statusActionInvocations.Add; - var statusResponse = new SftpStatusResponse(_protocolVersion); - - var request = new SftpLinkRequest(_protocolVersion, _requestId, _newLinkPath, _existingPath, true, statusAction); - - request.Complete(statusResponse); - - Assert.HasCount(1, statusActionInvocations); - Assert.AreSame(statusResponse, statusActionInvocations[0]); - } - - [TestMethod] - public void GetBytes() - { - var request = new SftpLinkRequest(_protocolVersion, _requestId, _newLinkPath, _existingPath, true, null); - - var bytes = request.GetBytes(); - - var expectedBytesLength = 0; - expectedBytesLength += 4; // Length - expectedBytesLength += 1; // Type - expectedBytesLength += 4; // RequestId - expectedBytesLength += 4; // NewLinkPath length - expectedBytesLength += _newLinkPathBytes.Length; // NewLinkPath - expectedBytesLength += 4; // ExistingPath length - expectedBytesLength += _existingPathBytes.Length; // ExistingPath - expectedBytesLength += 1; // IsSymLink - - Assert.HasCount(expectedBytesLength, bytes); - - var sshDataStream = new SshDataStream(bytes); - - Assert.AreEqual((uint)bytes.Length - 4, sshDataStream.ReadUInt32()); - Assert.AreEqual((byte)SftpMessageTypes.Link, sshDataStream.ReadByte()); - Assert.AreEqual(_requestId, sshDataStream.ReadUInt32()); - - Assert.AreEqual((uint)_newLinkPathBytes.Length, sshDataStream.ReadUInt32()); - var actualNewLinkPath = new byte[_newLinkPathBytes.Length]; - _ = sshDataStream.Read(actualNewLinkPath, 0, actualNewLinkPath.Length); - CollectionAssert.AreEqual(_newLinkPathBytes, actualNewLinkPath); - - Assert.AreEqual((uint)_existingPathBytes.Length, sshDataStream.ReadUInt32()); - var actualExistingPath = new byte[_existingPathBytes.Length]; - _ = sshDataStream.Read(actualExistingPath, 0, actualExistingPath.Length); - CollectionAssert.AreEqual(_existingPathBytes, actualExistingPath); - - Assert.AreEqual(1, sshDataStream.ReadByte()); - - Assert.IsTrue(sshDataStream.IsEndOfData); - } - } -} diff --git a/test/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpReadLinkRequestTest.cs b/test/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpReadLinkRequestTest.cs deleted file mode 100644 index add2f58ea..000000000 --- a/test/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpReadLinkRequestTest.cs +++ /dev/null @@ -1,129 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Text; - -using Microsoft.VisualStudio.TestTools.UnitTesting; - -using Renci.SshNet.Common; -using Renci.SshNet.Sftp; -using Renci.SshNet.Sftp.Requests; -using Renci.SshNet.Sftp.Responses; - -namespace Renci.SshNet.Tests.Classes.Sftp.Requests -{ - [TestClass] - public class SftpReadLinkRequestTest - { - private uint _protocolVersion; - private uint _requestId; - private Encoding _encoding; - private string _path; - private byte[] _pathBytes; - - [TestInitialize] - public void Init() - { - var random = new Random(); - - _protocolVersion = (uint)random.Next(0, int.MaxValue); - _requestId = (uint)random.Next(0, int.MaxValue); - _encoding = Encoding.Unicode; - _path = random.Next().ToString(CultureInfo.InvariantCulture); - _pathBytes = _encoding.GetBytes(_path); - } - - [TestMethod] - public void Constructor() - { - var request = new SftpReadLinkRequest(_protocolVersion, _requestId, _path, _encoding, null, null); - - Assert.AreSame(_encoding, request.Encoding); - Assert.AreEqual(_path, request.Path); - Assert.AreEqual(_protocolVersion, request.ProtocolVersion); - Assert.AreEqual(_requestId, request.RequestId); - Assert.AreEqual(SftpMessageTypes.ReadLink, request.SftpMessageType); - } - - [TestMethod] - public void Complete_SftpNameResponse() - { - var statusActionInvocations = new List(); - var nameActionInvocations = new List(); - - Action statusAction = statusActionInvocations.Add; - Action nameAction = nameActionInvocations.Add; - var nameResponse = new SftpNameResponse(_protocolVersion, Encoding.Unicode); - - var request = new SftpReadLinkRequest( - _protocolVersion, - _requestId, - _path, - _encoding, - nameAction, - statusAction); - - request.Complete(nameResponse); - - Assert.IsEmpty(statusActionInvocations); - Assert.HasCount(1, nameActionInvocations); - Assert.AreSame(nameResponse, nameActionInvocations[0]); - } - - [TestMethod] - public void Complete_SftpStatusResponse() - { - var statusActionInvocations = new List(); - var nameActionInvocations = new List(); - - Action statusAction = statusActionInvocations.Add; - Action nameAction = nameActionInvocations.Add; - var statusResponse = new SftpStatusResponse(_protocolVersion); - - var request = new SftpReadLinkRequest( - _protocolVersion, - _requestId, - _path, - _encoding, - nameAction, - statusAction); - - request.Complete(statusResponse); - - Assert.HasCount(1, statusActionInvocations); - Assert.AreSame(statusResponse, statusActionInvocations[0]); - Assert.IsEmpty(nameActionInvocations); - } - - [TestMethod] - public void GetBytes() - { - var request = new SftpReadLinkRequest(_protocolVersion, _requestId, _path, _encoding, null, null); - - var bytes = request.GetBytes(); - - var expectedBytesLength = 0; - expectedBytesLength += 4; // Length - expectedBytesLength += 1; // Type - expectedBytesLength += 4; // RequestId - expectedBytesLength += 4; // Path length - expectedBytesLength += _pathBytes.Length; // Path - - Assert.HasCount(expectedBytesLength, bytes); - - var sshDataStream = new SshDataStream(bytes); - - Assert.AreEqual((uint)bytes.Length - 4, sshDataStream.ReadUInt32()); - Assert.AreEqual((byte)SftpMessageTypes.ReadLink, sshDataStream.ReadByte()); - Assert.AreEqual(_requestId, sshDataStream.ReadUInt32()); - - Assert.AreEqual((uint)_pathBytes.Length, sshDataStream.ReadUInt32()); - var actualPath = new byte[_pathBytes.Length]; - _ = sshDataStream.Read(actualPath, 0, actualPath.Length); - CollectionAssert.AreEqual(_pathBytes, actualPath); - - Assert.IsTrue(sshDataStream.IsEndOfData); - } - } - -} diff --git a/test/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpUnblockRequestTest.cs b/test/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpUnblockRequestTest.cs deleted file mode 100644 index 87b6ef0d6..000000000 --- a/test/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpUnblockRequestTest.cs +++ /dev/null @@ -1,96 +0,0 @@ -using System; -using System.Collections.Generic; - -using Microsoft.VisualStudio.TestTools.UnitTesting; - -using Renci.SshNet.Common; -using Renci.SshNet.Sftp; -using Renci.SshNet.Sftp.Requests; -using Renci.SshNet.Sftp.Responses; - -namespace Renci.SshNet.Tests.Classes.Sftp.Requests -{ - [TestClass] - public class SftpUnblockRequestTest - { - private uint _protocolVersion; - private uint _requestId; - private byte[] _handle; - private ulong _offset; - private ulong _length; - - [TestInitialize] - public void Init() - { - var random = new Random(); - - _protocolVersion = (uint)random.Next(0, int.MaxValue); - _requestId = (uint)random.Next(0, int.MaxValue); - _handle = new byte[random.Next(1, 10)]; - random.NextBytes(_handle); - _offset = (ulong)random.Next(0, int.MaxValue); - _length = (ulong)random.Next(0, int.MaxValue); - } - - [TestMethod] - public void Constructor() - { - var request = new SftpUnblockRequest(_protocolVersion, _requestId, _handle, _offset, _length, null); - - Assert.AreSame(_handle, request.Handle); - Assert.AreEqual(_protocolVersion, request.ProtocolVersion); - Assert.AreEqual(_requestId, request.RequestId); - Assert.AreEqual(SftpMessageTypes.Unblock, request.SftpMessageType); - } - - [TestMethod] - public void Complete_SftpStatusResponse() - { - var statusActionInvocations = new List(); - Action statusAction = statusActionInvocations.Add; - var statusResponse = new SftpStatusResponse(_protocolVersion); - - var request = new SftpUnblockRequest(_protocolVersion, _requestId, _handle, _offset, _length, statusAction); - - request.Complete(statusResponse); - - Assert.HasCount(1, statusActionInvocations); - Assert.AreSame(statusResponse, statusActionInvocations[0]); - } - - [TestMethod] - public void GetBytes() - { - var request = new SftpUnblockRequest(_protocolVersion, _requestId, _handle, _offset, _length, null); - - var bytes = request.GetBytes(); - - var expectedBytesLength = 0; - expectedBytesLength += 4; // Length - expectedBytesLength += 1; // Type - expectedBytesLength += 4; // RequestId - expectedBytesLength += 4; // Handle length - expectedBytesLength += _handle.Length; // Handle - expectedBytesLength += 8; // Offset - expectedBytesLength += 8; // Length - - Assert.HasCount(expectedBytesLength, bytes); - - var sshDataStream = new SshDataStream(bytes); - - Assert.AreEqual((uint)bytes.Length - 4, sshDataStream.ReadUInt32()); - Assert.AreEqual((byte)SftpMessageTypes.Unblock, sshDataStream.ReadByte()); - Assert.AreEqual(_requestId, sshDataStream.ReadUInt32()); - - Assert.AreEqual((uint)_handle.Length, sshDataStream.ReadUInt32()); - var actualHandle = new byte[_handle.Length]; - _ = sshDataStream.Read(actualHandle, 0, actualHandle.Length); - CollectionAssert.AreEqual(_handle, actualHandle); - - Assert.AreEqual(_offset, sshDataStream.ReadUInt64()); - Assert.AreEqual(_length, sshDataStream.ReadUInt64()); - - Assert.IsTrue(sshDataStream.IsEndOfData); - } - } -}