File tree Expand file tree Collapse file tree 2 files changed +22
-0
lines changed
Sources/MQTTNIO/ChannelHandlers Expand file tree Collapse file tree 2 files changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -50,6 +50,8 @@ struct ByteToMQTTMessageDecoder: ByteToMessageDecoder {
5050 let disconnectMessage = try MQTTDisconnectPacket . read ( version: self . client. configuration. version, from: packet)
5151 let ack = MQTTAckV5 ( reason: disconnectMessage. reason, properties: disconnectMessage. properties)
5252 context. fireErrorCaught ( MQTTError . serverDisconnection ( ack) )
53+ context. close ( promise: nil )
54+ buffer = readBuffer
5355 return . continue
5456 case . AUTH:
5557 message = try MQTTAuthPacket . read ( version: self . client. configuration. version, from: packet)
Original file line number Diff line number Diff line change @@ -308,6 +308,26 @@ final class MQTTNIOv5Tests: XCTestCase {
308308 try client. disconnect ( ) . wait ( )
309309 }
310310
311+ /// Test Publish that will cause a server disconnection message
312+ func testBadPublish( ) throws {
313+ let client = self . createClient ( identifier: " testBadPublish " )
314+ defer { XCTAssertNoThrow ( try client. syncShutdownGracefully ( ) ) }
315+ _ = try client. connect ( ) . wait ( )
316+ do {
317+ _ = try client. v5. publish (
318+ to: " testBadPublish " ,
319+ payload: ByteBufferAllocator ( ) . buffer ( string: " Test payload " ) ,
320+ qos: . atLeastOnce,
321+ properties: [ . requestResponseInformation( 1 ) ]
322+ ) . wait ( )
323+ XCTFail ( " Should have errored " )
324+ } catch MQTTError . serverDisconnection( let ack) {
325+ XCTAssertEqual ( ack. reason, . malformedPacket)
326+ } catch {
327+ XCTFail ( " \( error) " )
328+ }
329+ }
330+
311331 func testOutOfRangeTopicAlias( ) throws {
312332 let client = self . createClient ( identifier: " testOutOfRangeTopicAlias " )
313333 defer { XCTAssertNoThrow ( try client. syncShutdownGracefully ( ) ) }
You can’t perform that action at this time.
0 commit comments