Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ struct SSHConnectionStateMachine {

case .receivedDisconnect, .sentDisconnect:
// We do no further I/O in these states.
return .noMessage
return nil
}
}

Expand Down
17 changes: 17 additions & 0 deletions Tests/NIOSSHTests/SSHConnectionStateMachineTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -224,4 +224,21 @@ final class SSHConnectionStateMachineTests: XCTestCase {
XCTAssertNoThrow(try self.assertSendingIsProtocolError(message, sender: &client, allocator: allocator, loop: loop))
}
}

func testDisconnectedReturnsNil() throws {
let allocator = ByteBufferAllocator()
let loop = EmbeddedEventLoop()
var client = SSHConnectionStateMachine(role: .client(.init(userAuthDelegate: InfinitePasswordDelegate())))
var server = SSHConnectionStateMachine(role: .server(.init(hostKeys: [NIOSSHPrivateKey(ed25519Key: .init())], userAuthDelegate: DenyThenAcceptDelegate(messagesToDeny: 1))))

try assertSuccessfulConnection(client: &client, server: &server, allocator: allocator, loop: loop)
try self.assertDisconnects(.disconnect(.init(reason: 0, description: "", tag: "")), sender: &client, receiver: &server, allocator: allocator, loop: loop)

// Ok, in disconnected state. At this time, any attempt to process the connection should return nil.
var junkBuffer = allocator.buffer(capacity: 1024)
junkBuffer.writeBytes(0 ... 255)
server.bufferInboundData(&junkBuffer)

XCTAssertNoThrow(try XCTAssertNil(server.processInboundMessage(allocator: allocator, loop: loop)))
}
}