-
Notifications
You must be signed in to change notification settings - Fork 823
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Validate shared subscription and closed connection if not valid (#795)
During the processing of an MQTT5 SUBSCRIBE message search all topicFilters for shared subscriptions and check for validity respect to specs [MQTT-4.8.2-1] [MQTT-4.8.2-1]
- Loading branch information
Showing
7 changed files
with
162 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
broker/src/test/java/io/moquette/integration/mqtt5/SharedSubscriptionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package io.moquette.integration.mqtt5; | ||
|
||
import com.hivemq.client.mqtt.MqttClient; | ||
import com.hivemq.client.mqtt.mqtt5.Mqtt5BlockingClient; | ||
import com.hivemq.client.mqtt.mqtt5.message.connect.connack.Mqtt5ConnAckReasonCode; | ||
import io.netty.handler.codec.mqtt.MqttConnAckMessage; | ||
import io.netty.handler.codec.mqtt.MqttMessage; | ||
import io.netty.handler.codec.mqtt.MqttQoS; | ||
import io.netty.handler.codec.mqtt.MqttReasonCodeAndPropertiesVariableHeader; | ||
import io.netty.handler.codec.mqtt.MqttReasonCodes; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static io.moquette.integration.mqtt5.ConnectTest.assertConnectionAccepted; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
public class SharedSubscriptionTest extends AbstractServerIntegrationTest { | ||
|
||
@Override | ||
public String clientName() { | ||
return "subscriber"; | ||
} | ||
|
||
@Test | ||
public void givenAClientSendingBadlyFormattedSharedSubscriptionNameThenItIsDisconnected() { | ||
MqttConnAckMessage connAck = lowLevelClient.connectV5(); | ||
assertConnectionAccepted(connAck, "Connection must be accepted"); | ||
|
||
MqttMessage received = lowLevelClient.subscribeWithError("$share/+/measures/temp", MqttQoS.AT_LEAST_ONCE); | ||
|
||
// verify received is a disconnect with an error | ||
MqttReasonCodeAndPropertiesVariableHeader disconnectHeader = (MqttReasonCodeAndPropertiesVariableHeader) received.variableHeader(); | ||
assertEquals(MqttReasonCodes.Disconnect.MALFORMED_PACKET.byteValue(), disconnectHeader.reasonCode()); | ||
} | ||
|
||
@NotNull | ||
private Mqtt5BlockingClient createSubscriberClient() { | ||
final Mqtt5BlockingClient client = MqttClient.builder() | ||
.useMqttVersion5() | ||
.identifier(clientName()) | ||
.serverHost("localhost") | ||
.serverPort(1883) | ||
.buildBlocking(); | ||
assertEquals(Mqtt5ConnAckReasonCode.SUCCESS, client.connect().getReasonCode(), "Subscriber connected"); | ||
return client; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters