From a26d00585d578eef5128d6c37e718f7d6f66a416 Mon Sep 17 00:00:00 2001 From: Steve Hamblett Date: Tue, 9 Jul 2024 08:28:44 +0100 Subject: [PATCH] Issue 524 fix up --- .../mqtt_client_mqtt_connect_ack_variable_header.dart | 4 +++- test/mqtt_client_connection_unsecure_test.dart | 6 ++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/src/messages/connectack/mqtt_client_mqtt_connect_ack_variable_header.dart b/lib/src/messages/connectack/mqtt_client_mqtt_connect_ack_variable_header.dart index 21a7b49..d404a97 100644 --- a/lib/src/messages/connectack/mqtt_client_mqtt_connect_ack_variable_header.dart +++ b/lib/src/messages/connectack/mqtt_client_mqtt_connect_ack_variable_header.dart @@ -40,7 +40,9 @@ class MqttConnectAckVariableHeader extends MqttVariableHeader { @override void readFrom(MqttByteBuffer variableHeaderStream) { final ackConnectFlags = variableHeaderStream.readByte(); - sessionPresent = ackConnectFlags == 1; + if (Protocol.version == MqttClientConstants.mqttV311ProtocolVersion) { + sessionPresent = ackConnectFlags == 1; + } readReturnCode(variableHeaderStream); } diff --git a/test/mqtt_client_connection_unsecure_test.dart b/test/mqtt_client_connection_unsecure_test.dart index a8c6ee1..fa6b7c8 100644 --- a/test/mqtt_client_connection_unsecure_test.dart +++ b/test/mqtt_client_connection_unsecure_test.dart @@ -249,12 +249,14 @@ void main() { final ch = SynchronousMqttServerConnectionHandler(clientEventBus, maxConnectionAttempts: 3, socketOptions: socketOptions); ch.onConnected = connectCb; - await ch.connect(mockBrokerAddress, mockBrokerPort, + final status = await ch.connect(mockBrokerAddress, mockBrokerPort, MqttConnectMessage().withClientIdentifier(testClientId)); expect(ch.connectionStatus.state, MqttConnectionState.connected); expect(ch.connectionStatus.returnCode, MqttConnectReturnCode.connectionAccepted); expect(ch.connectionStatus.connectAckMessage, isNotNull); + expect( + status.connectAckMessage?.variableHeader.sessionPresent, isFalse); expect(connectCbCalled, isTrue); final state = ch.disconnect(); expect(state, MqttConnectionState.disconnected); @@ -269,7 +271,7 @@ void main() { timeout: timeout)); }); - test('Successful response and disconnect with returned status', () async { + test('Successful response and disconnect with session present', () async { await IOOverrides.runZoned(() async { Protocol.version = MqttClientConstants.mqttV311ProtocolVersion; final clientEventBus = events.EventBus();