forked from moquette-io/moquette
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds CONNACK properties, in particular return which capabilities are …
…actually enabled (moquette-io#709) * Added CONNACK capabilities * Extracted common shared code in abstract superclass * Fixed empty clientId management for MQTT5 * Added checks for majority of CONNACK properties, in particular assignedClientId * Introduce isProtocolVersion, and redefine isNotProtocolVersion
- Loading branch information
Showing
6 changed files
with
201 additions
and
72 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
59 changes: 59 additions & 0 deletions
59
broker/src/test/java/io/moquette/integration/mqtt5/AbstractServerIntegrationTest.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,59 @@ | ||
package io.moquette.integration.mqtt5; | ||
|
||
import io.moquette.broker.Server; | ||
import io.moquette.broker.config.IConfig; | ||
import io.moquette.broker.config.MemoryConfig; | ||
import io.moquette.integration.IntegrationUtils; | ||
import io.moquette.testclient.Client; | ||
import org.awaitility.Awaitility; | ||
import org.awaitility.Durations; | ||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.io.TempDir; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.Path; | ||
import java.util.Properties; | ||
|
||
abstract class AbstractServerIntegrationTest { | ||
Server broker; | ||
IConfig config; | ||
|
||
@TempDir | ||
Path tempFolder; | ||
private String dbPath; | ||
|
||
Client lowLevelClient; | ||
|
||
abstract String clientName(); | ||
|
||
protected void startServer(String dbPath) throws IOException { | ||
broker = new Server(); | ||
final Properties configProps = IntegrationUtils.prepareTestProperties(dbPath); | ||
config = new MemoryConfig(configProps); | ||
broker.startServer(config); | ||
} | ||
|
||
@BeforeAll | ||
public static void beforeTests() { | ||
Awaitility.setDefaultTimeout(Durations.ONE_SECOND); | ||
} | ||
|
||
@BeforeEach | ||
public void setUp() throws Exception { | ||
dbPath = IntegrationUtils.tempH2Path(tempFolder); | ||
startServer(dbPath); | ||
|
||
lowLevelClient = new Client("localhost").clientId(clientName()); | ||
} | ||
|
||
@AfterEach | ||
public void tearDown() throws Exception { | ||
stopServer(); | ||
} | ||
|
||
private void stopServer() { | ||
broker.stopServer(); | ||
} | ||
} |
71 changes: 71 additions & 0 deletions
71
broker/src/test/java/io/moquette/integration/mqtt5/ConnectAckTest.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,71 @@ | ||
package io.moquette.integration.mqtt5; | ||
|
||
import io.moquette.BrokerConstants; | ||
import io.moquette.testclient.Client; | ||
import io.netty.handler.codec.mqtt.MqttConnAckMessage; | ||
import io.netty.handler.codec.mqtt.MqttConnectReturnCode; | ||
import io.netty.handler.codec.mqtt.MqttProperties; | ||
import io.netty.handler.codec.mqtt.MqttProperties.MqttPropertyType; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
|
||
import static io.moquette.BrokerConstants.INFLIGHT_WINDOW_SIZE; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNull; | ||
|
||
class ConnectAckTest extends AbstractServerIntegrationTest { | ||
private static final Logger LOG = LoggerFactory.getLogger(ConnectAckTest.class); | ||
private MqttConnAckMessage connAck; | ||
|
||
@Override | ||
String clientName() { | ||
return "client"; | ||
} | ||
|
||
@BeforeEach | ||
public void setUp() throws Exception { | ||
super.setUp(); | ||
|
||
connAck = lowLevelClient.connectV5(); | ||
assertEquals(MqttConnectReturnCode.CONNECTION_ACCEPTED, connAck.variableHeader().connectReturnCode(), "Client connected"); | ||
} | ||
|
||
private <T> void verifyProperty(MqttPropertyType propertyType, MqttProperties props, T expectedValue, String comment) { | ||
final MqttProperties.MqttProperty<Integer> property = props.getProperty(propertyType.value()); | ||
assertEquals(expectedValue, property.value(), comment); | ||
} | ||
private void verifyNotSet(MqttPropertyType propertyType, MqttProperties props, String message) { | ||
assertNull(props.getProperty(propertyType.value()), message); | ||
} | ||
|
||
@Test | ||
public void testAckResponseProperties() { | ||
final MqttProperties ackProps = connAck.variableHeader().properties(); | ||
verifyProperty(MqttPropertyType.SESSION_EXPIRY_INTERVAL, ackProps, BrokerConstants.INFINITE_SESSION_EXPIRY, "Session expiry is infinite"); | ||
verifyProperty(MqttPropertyType.RECEIVE_MAXIMUM, ackProps, INFLIGHT_WINDOW_SIZE, "Receive maximum property must equals flight window size"); | ||
verifyNotSet(MqttPropertyType.MAXIMUM_QOS, ackProps, "Maximum QoS is not set => QoS 2 ready"); | ||
verifyProperty(MqttPropertyType.RETAIN_AVAILABLE, ackProps, 1, "Retain feature is available"); | ||
verifyNotSet(MqttPropertyType.MAXIMUM_PACKET_SIZE, ackProps, "Maximum packet size is the one defined by specs"); | ||
verifyProperty(MqttPropertyType.TOPIC_ALIAS_MAXIMUM, ackProps, 0, "No topic alias available"); | ||
verifyProperty(MqttPropertyType.WILDCARD_SUBSCRIPTION_AVAILABLE, ackProps, 1, "Wildcard subscription feature is available"); | ||
verifyProperty(MqttPropertyType.SUBSCRIPTION_IDENTIFIER_AVAILABLE, ackProps, 0, "Subscription feature is NOT available"); | ||
verifyProperty(MqttPropertyType.SHARED_SUBSCRIPTION_AVAILABLE, ackProps, 0, "Shared subscription feature is NOT available"); | ||
verifyNotSet(MqttPropertyType.AUTHENTICATION_METHOD, ackProps, "No auth method available"); | ||
verifyNotSet(MqttPropertyType.AUTHENTICATION_DATA, ackProps, "No auth data available"); | ||
} | ||
|
||
@Test | ||
public void testAssignedClientIdentifier() { | ||
Client unnamedClient = new Client("localhost").clientId(""); | ||
connAck = unnamedClient.connectV5(); | ||
assertEquals(MqttConnectReturnCode.CONNECTION_ACCEPTED, connAck.variableHeader().connectReturnCode(), "Client connected"); | ||
final MqttProperties ackProps = connAck.variableHeader().properties(); | ||
final MqttProperties.MqttProperty<String> property = ackProps.getProperty(MqttPropertyType.ASSIGNED_CLIENT_IDENTIFIER.value()); | ||
final int clientServerGeneratedSize = 32; | ||
assertEquals(clientServerGeneratedSize, property.value().length(), "Server assigned client ID"); | ||
|
||
} | ||
} |
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