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 {
50
50
let disconnectMessage = try MQTTDisconnectPacket . read ( version: self . client. configuration. version, from: packet)
51
51
let ack = MQTTAckV5 ( reason: disconnectMessage. reason, properties: disconnectMessage. properties)
52
52
context. fireErrorCaught ( MQTTError . serverDisconnection ( ack) )
53
+ context. close ( promise: nil )
54
+ buffer = readBuffer
53
55
return . continue
54
56
case . AUTH:
55
57
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 {
308
308
try client. disconnect ( ) . wait ( )
309
309
}
310
310
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
+
311
331
func testOutOfRangeTopicAlias( ) throws {
312
332
let client = self . createClient ( identifier: " testOutOfRangeTopicAlias " )
313
333
defer { XCTAssertNoThrow ( try client. syncShutdownGracefully ( ) ) }
You can’t perform that action at this time.
0 commit comments