Skip to content

Commit b79e1a5

Browse files
committed
[broker-26] fixes for code review
1 parent 910f8cf commit b79e1a5

File tree

2 files changed

+13
-16
lines changed

2 files changed

+13
-16
lines changed

src/main/java/com/ss/mqtt/broker/network/packet/in/ConnectInPacket.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -282,12 +282,9 @@ protected void readVariableHeader(@NotNull MqttConnection connection, @NotNull B
282282
hasUserName = NumberUtils.isSetBit(flags, 7);
283283
hasPassword = NumberUtils.isSetBit(flags, 6);
284284

285-
if (mqttVersion.ordinal() < MqttVersion.MQTT_5.ordinal()) {
286-
287-
// for mqtt < 5 we cannot have password without user
288-
if (!hasUserName && hasPassword) {
289-
throw new ConnectionRejectException(ConnectAckReasonCode.BAD_USER_NAME_OR_PASSWORD);
290-
}
285+
// for mqtt < 5 we cannot have password without user
286+
if (mqttVersion.ordinal() < MqttVersion.MQTT_5.ordinal() && !hasUserName && hasPassword) {
287+
throw new ConnectionRejectException(ConnectAckReasonCode.BAD_USER_NAME_OR_PASSWORD);
291288
}
292289

293290
willFlag = NumberUtils.isSetBit(flags, 2);

src/test/groovy/com/ss/mqtt/broker/test/integration/ConnectSubscribePublishTest.groovy

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ class ConnectSubscribePublishTest extends IntegrationSpecification {
4444
received.get().qos == MqttQos.AT_MOST_ONCE
4545
received.get().type == Mqtt3MessageType.PUBLISH
4646
cleanup:
47-
subscriber.disconnect()
48-
publisher.disconnect()
47+
subscriber.disconnect().join()
48+
publisher.disconnect().join()
4949
}
5050

5151
def "publisher should publish message QoS 0 using mqtt 5"() {
@@ -77,8 +77,8 @@ class ConnectSubscribePublishTest extends IntegrationSpecification {
7777
received.get().qos == MqttQos.AT_MOST_ONCE
7878
received.get().type == Mqtt5MessageType.PUBLISH
7979
cleanup:
80-
subscriber.disconnect()
81-
publisher.disconnect()
80+
subscriber.disconnect().join()
81+
publisher.disconnect().join()
8282
}
8383

8484
def "publisher should publish message QoS 1 using mqtt 3.1.1"() {
@@ -110,8 +110,8 @@ class ConnectSubscribePublishTest extends IntegrationSpecification {
110110
received.get().qos == MqttQos.AT_LEAST_ONCE
111111
received.get().type == Mqtt3MessageType.PUBLISH
112112
cleanup:
113-
subscriber.disconnect()
114-
publisher.disconnect()
113+
subscriber.disconnect().join()
114+
publisher.disconnect().join()
115115
}
116116

117117
def "publisher should publish message QoS 1 using mqtt 5"() {
@@ -177,8 +177,8 @@ class ConnectSubscribePublishTest extends IntegrationSpecification {
177177
received.get().qos == MqttQos.EXACTLY_ONCE
178178
received.get().type == Mqtt3MessageType.PUBLISH
179179
cleanup:
180-
subscriber.disconnect()
181-
publisher.disconnect()
180+
subscriber.disconnect().join()
181+
publisher.disconnect().join()
182182
}
183183

184184
def "publisher should publish message QoS 2 using mqtt 5"() {
@@ -211,8 +211,8 @@ class ConnectSubscribePublishTest extends IntegrationSpecification {
211211
received.get().qos == MqttQos.EXACTLY_ONCE
212212
received.get().type == Mqtt5MessageType.PUBLISH
213213
cleanup:
214-
subscriber.disconnect()
215-
publisher.disconnect()
214+
subscriber.disconnect().join()
215+
publisher.disconnect().join()
216216
}
217217

218218
def publish(Mqtt5AsyncClient publisher, String subscriberId, MqttQos qos) {

0 commit comments

Comments
 (0)