mirror of
https://github.com/eclipse-mosquitto/mosquitto.git
synced 2026-09-25 19:34:16 +08:00
Strict protocol compliance fixes, and extensive test suite.
This commit is contained in:
committed by
Roger A. Light
parent
723b5d7081
commit
ba2ca33671
@@ -28,6 +28,7 @@ Broker:
|
||||
directory. Closes #2241.
|
||||
- Fix listener mount_point not being removed on outgoing messages.
|
||||
Closes #2244.
|
||||
- Strict protocol compliance fixes, plus test suite.
|
||||
|
||||
Client library:
|
||||
- If a client uses TLS-PSK then force the default cipher list to use "PSK"
|
||||
|
||||
@@ -41,6 +41,9 @@ int handle__auth(struct mosquitto *mosq)
|
||||
if(mosq->protocol != mosq_p_mqtt5){
|
||||
return MOSQ_ERR_PROTOCOL;
|
||||
}
|
||||
if(mosq->in_packet.command != CMD_AUTH){
|
||||
return MOSQ_ERR_MALFORMED_PACKET;
|
||||
}
|
||||
|
||||
if(packet__read_byte(&mosq->in_packet, &reason_code)) return 1;
|
||||
|
||||
|
||||
@@ -65,6 +65,10 @@ int handle__connack(struct mosquitto *mosq)
|
||||
char *clientid = NULL;
|
||||
|
||||
assert(mosq);
|
||||
if(mosq->in_packet.command != CMD_CONNACK){
|
||||
return MOSQ_ERR_MALFORMED_PACKET;
|
||||
}
|
||||
|
||||
rc = packet__read_byte(&mosq->in_packet, &connect_flags);
|
||||
if(rc) return rc;
|
||||
rc = packet__read_byte(&mosq->in_packet, &reason_code);
|
||||
|
||||
@@ -44,6 +44,9 @@ int handle__disconnect(struct mosquitto *mosq)
|
||||
if(mosq->protocol != mosq_p_mqtt5){
|
||||
return MOSQ_ERR_PROTOCOL;
|
||||
}
|
||||
if(mosq->in_packet.command != CMD_DISCONNECT){
|
||||
return MOSQ_ERR_MALFORMED_PACKET;
|
||||
}
|
||||
|
||||
rc = packet__read_byte(&mosq->in_packet, &reason_code);
|
||||
if(rc) return rc;
|
||||
|
||||
+7
-1
@@ -44,11 +44,14 @@ int handle__pingreq(struct mosquitto *mosq)
|
||||
if(mosquitto__get_state(mosq) != mosq_cs_active){
|
||||
return MOSQ_ERR_PROTOCOL;
|
||||
}
|
||||
if(mosq->in_packet.command != CMD_PINGREQ){
|
||||
return MOSQ_ERR_MALFORMED_PACKET;
|
||||
}
|
||||
|
||||
#ifdef WITH_BROKER
|
||||
log__printf(NULL, MOSQ_LOG_DEBUG, "Received PINGREQ from %s", mosq->id);
|
||||
#else
|
||||
log__printf(mosq, MOSQ_LOG_DEBUG, "Client %s received PINGREQ", mosq->id);
|
||||
return MOSQ_ERR_PROTOCOL;
|
||||
#endif
|
||||
return send__pingresp(mosq);
|
||||
}
|
||||
@@ -63,6 +66,9 @@ int handle__pingresp(struct mosquitto *mosq)
|
||||
|
||||
mosq->ping_t = 0; /* No longer waiting for a PINGRESP. */
|
||||
#ifdef WITH_BROKER
|
||||
if(mosq->bridge == NULL){
|
||||
return MOSQ_ERR_PROTOCOL;
|
||||
}
|
||||
log__printf(NULL, MOSQ_LOG_DEBUG, "Received PINGRESP from %s", mosq->id);
|
||||
#else
|
||||
log__printf(mosq, MOSQ_LOG_DEBUG, "Client %s received PINGRESP", mosq->id);
|
||||
|
||||
+50
-3
@@ -51,6 +51,11 @@ int handle__pubackcomp(struct mosquitto *mosq, const char *type)
|
||||
if(mosquitto__get_state(mosq) != mosq_cs_active){
|
||||
return MOSQ_ERR_PROTOCOL;
|
||||
}
|
||||
if(mosq->protocol != mosq_p_mqtt31){
|
||||
if((mosq->in_packet.command&0x0F) != 0x00){
|
||||
return MOSQ_ERR_MALFORMED_PACKET;
|
||||
}
|
||||
}
|
||||
|
||||
pthread_mutex_lock(&mosq->msgs_out.mutex);
|
||||
util__increment_send_quota(mosq);
|
||||
@@ -58,17 +63,59 @@ int handle__pubackcomp(struct mosquitto *mosq, const char *type)
|
||||
|
||||
rc = packet__read_uint16(&mosq->in_packet, &mid);
|
||||
if(rc) return rc;
|
||||
qos = type[3] == 'A'?1:2; /* pubAck or pubComp */
|
||||
if(mid == 0) return MOSQ_ERR_PROTOCOL;
|
||||
if(type[3] == 'A'){ /* pubAck or pubComp */
|
||||
if(mosq->in_packet.command != CMD_PUBACK){
|
||||
return MOSQ_ERR_MALFORMED_PACKET;
|
||||
}
|
||||
qos = 1;
|
||||
}else{
|
||||
if(mosq->in_packet.command != CMD_PUBCOMP){
|
||||
return MOSQ_ERR_MALFORMED_PACKET;
|
||||
}
|
||||
qos = 2;
|
||||
}
|
||||
if(mid == 0){
|
||||
return MOSQ_ERR_PROTOCOL;
|
||||
}
|
||||
|
||||
if(mosq->protocol == mosq_p_mqtt5 && mosq->in_packet.remaining_length > 2){
|
||||
rc = packet__read_byte(&mosq->in_packet, &reason_code);
|
||||
if(rc) return rc;
|
||||
if(rc){
|
||||
return rc;
|
||||
}
|
||||
|
||||
if(mosq->in_packet.remaining_length > 3){
|
||||
rc = property__read_all(CMD_PUBACK, &mosq->in_packet, &properties);
|
||||
if(rc) return rc;
|
||||
}
|
||||
if(type[3] == 'A'){ /* pubAck or pubComp */
|
||||
if(reason_code != MQTT_RC_SUCCESS
|
||||
&& reason_code != MQTT_RC_NO_MATCHING_SUBSCRIBERS
|
||||
&& reason_code != MQTT_RC_UNSPECIFIED
|
||||
&& reason_code != MQTT_RC_IMPLEMENTATION_SPECIFIC
|
||||
&& reason_code != MQTT_RC_NOT_AUTHORIZED
|
||||
&& reason_code != MQTT_RC_TOPIC_NAME_INVALID
|
||||
&& reason_code != MQTT_RC_PACKET_ID_IN_USE
|
||||
&& reason_code != MQTT_RC_QUOTA_EXCEEDED
|
||||
&& reason_code != MQTT_RC_PAYLOAD_FORMAT_INVALID
|
||||
){
|
||||
|
||||
return MOSQ_ERR_PROTOCOL;
|
||||
}
|
||||
}else{
|
||||
if(reason_code != MQTT_RC_SUCCESS
|
||||
&& reason_code != MQTT_RC_PACKET_ID_NOT_FOUND
|
||||
){
|
||||
|
||||
return MOSQ_ERR_PROTOCOL;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(mosq->in_packet.pos < mosq->in_packet.remaining_length){
|
||||
#ifdef WITH_BROKER
|
||||
mosquitto_property_free_all(&properties);
|
||||
#endif
|
||||
return MOSQ_ERR_MALFORMED_PACKET;
|
||||
}
|
||||
|
||||
#ifdef WITH_BROKER
|
||||
|
||||
@@ -49,6 +49,9 @@ int handle__pubrec(struct mosquitto *mosq)
|
||||
if(mosquitto__get_state(mosq) != mosq_cs_active){
|
||||
return MOSQ_ERR_PROTOCOL;
|
||||
}
|
||||
if(mosq->in_packet.command != CMD_PUBREC){
|
||||
return MOSQ_ERR_MALFORMED_PACKET;
|
||||
}
|
||||
|
||||
rc = packet__read_uint16(&mosq->in_packet, &mid);
|
||||
if(rc) return rc;
|
||||
@@ -58,14 +61,34 @@ int handle__pubrec(struct mosquitto *mosq)
|
||||
rc = packet__read_byte(&mosq->in_packet, &reason_code);
|
||||
if(rc) return rc;
|
||||
|
||||
if(reason_code != MQTT_RC_SUCCESS
|
||||
&& reason_code != MQTT_RC_NO_MATCHING_SUBSCRIBERS
|
||||
&& reason_code != MQTT_RC_UNSPECIFIED
|
||||
&& reason_code != MQTT_RC_IMPLEMENTATION_SPECIFIC
|
||||
&& reason_code != MQTT_RC_NOT_AUTHORIZED
|
||||
&& reason_code != MQTT_RC_TOPIC_NAME_INVALID
|
||||
&& reason_code != MQTT_RC_PACKET_ID_IN_USE
|
||||
&& reason_code != MQTT_RC_QUOTA_EXCEEDED){
|
||||
|
||||
return MOSQ_ERR_PROTOCOL;
|
||||
}
|
||||
|
||||
if(mosq->in_packet.remaining_length > 3){
|
||||
rc = property__read_all(CMD_PUBREC, &mosq->in_packet, &properties);
|
||||
if(rc) return rc;
|
||||
|
||||
/* Immediately free, we don't do anything with Reason String or User Property at the moment */
|
||||
mosquitto_property_free_all(&properties);
|
||||
}
|
||||
}
|
||||
|
||||
if(mosq->in_packet.pos < mosq->in_packet.remaining_length){
|
||||
#ifdef WITH_BROKER
|
||||
mosquitto_property_free_all(&properties);
|
||||
#endif
|
||||
return MOSQ_ERR_MALFORMED_PACKET;
|
||||
}
|
||||
|
||||
#ifdef WITH_BROKER
|
||||
log__printf(NULL, MOSQ_LOG_DEBUG, "Received PUBREC from %s (Mid: %d)", mosq->id, mid);
|
||||
|
||||
|
||||
@@ -53,6 +53,9 @@ int handle__pubrel(struct mosquitto *mosq)
|
||||
if(mosquitto__get_state(mosq) != mosq_cs_active){
|
||||
return MOSQ_ERR_PROTOCOL;
|
||||
}
|
||||
if(mosq->protocol != mosq_p_mqtt31 && mosq->in_packet.command != (CMD_PUBREL|2)){
|
||||
return MOSQ_ERR_MALFORMED_PACKET;
|
||||
}
|
||||
|
||||
if(mosq->protocol != mosq_p_mqtt31){
|
||||
if((mosq->in_packet.command&0x0F) != 0x02){
|
||||
@@ -67,12 +70,23 @@ int handle__pubrel(struct mosquitto *mosq)
|
||||
rc = packet__read_byte(&mosq->in_packet, &reason_code);
|
||||
if(rc) return rc;
|
||||
|
||||
if(reason_code != MQTT_RC_SUCCESS && reason_code != MQTT_RC_PACKET_ID_NOT_FOUND){
|
||||
return MOSQ_ERR_PROTOCOL;
|
||||
}
|
||||
|
||||
if(mosq->in_packet.remaining_length > 3){
|
||||
rc = property__read_all(CMD_PUBREL, &mosq->in_packet, &properties);
|
||||
if(rc) return rc;
|
||||
}
|
||||
}
|
||||
|
||||
if(mosq->in_packet.pos < mosq->in_packet.remaining_length){
|
||||
#ifdef WITH_BROKER
|
||||
mosquitto_property_free_all(&properties);
|
||||
#endif
|
||||
return MOSQ_ERR_MALFORMED_PACKET;
|
||||
}
|
||||
|
||||
#ifdef WITH_BROKER
|
||||
log__printf(NULL, MOSQ_LOG_DEBUG, "Received PUBREL from %s (Mid: %d)", mosq->id, mid);
|
||||
|
||||
|
||||
@@ -50,8 +50,15 @@ int handle__suback(struct mosquitto *mosq)
|
||||
if(mosquitto__get_state(mosq) != mosq_cs_active){
|
||||
return MOSQ_ERR_PROTOCOL;
|
||||
}
|
||||
if(mosq->in_packet.command != CMD_SUBACK){
|
||||
return MOSQ_ERR_MALFORMED_PACKET;
|
||||
}
|
||||
|
||||
#ifdef WITH_BROKER
|
||||
if(mosq->bridge == NULL){
|
||||
/* Client is not a bridge, so shouldn't be sending SUBACK */
|
||||
return MOSQ_ERR_PROTOCOL;
|
||||
}
|
||||
log__printf(NULL, MOSQ_LOG_DEBUG, "Received SUBACK from %s", mosq->id);
|
||||
#else
|
||||
log__printf(mosq, MOSQ_LOG_DEBUG, "Client %s received SUBACK", mosq->id);
|
||||
|
||||
@@ -50,8 +50,15 @@ int handle__unsuback(struct mosquitto *mosq)
|
||||
if(mosquitto__get_state(mosq) != mosq_cs_active){
|
||||
return MOSQ_ERR_PROTOCOL;
|
||||
}
|
||||
if(mosq->in_packet.command != CMD_UNSUBACK){
|
||||
return MOSQ_ERR_MALFORMED_PACKET;
|
||||
}
|
||||
|
||||
#ifdef WITH_BROKER
|
||||
if(mosq->bridge == NULL){
|
||||
/* Client is not a bridge, so shouldn't be sending SUBACK */
|
||||
return MOSQ_ERR_PROTOCOL;
|
||||
}
|
||||
log__printf(NULL, MOSQ_LOG_DEBUG, "Received UNSUBACK from %s", mosq->id);
|
||||
#else
|
||||
log__printf(mosq, MOSQ_LOG_DEBUG, "Client %s received UNSUBACK", mosq->id);
|
||||
|
||||
@@ -49,7 +49,7 @@ Contributors:
|
||||
int packet__read_byte(struct mosquitto__packet *packet, uint8_t *byte)
|
||||
{
|
||||
assert(packet);
|
||||
if(packet->pos+1 > packet->remaining_length) return MOSQ_ERR_PROTOCOL;
|
||||
if(packet->pos+1 > packet->remaining_length) return MOSQ_ERR_MALFORMED_PACKET;
|
||||
|
||||
*byte = packet->payload[packet->pos];
|
||||
packet->pos++;
|
||||
@@ -71,7 +71,7 @@ void packet__write_byte(struct mosquitto__packet *packet, uint8_t byte)
|
||||
int packet__read_bytes(struct mosquitto__packet *packet, void *bytes, uint32_t count)
|
||||
{
|
||||
assert(packet);
|
||||
if(packet->pos+count > packet->remaining_length) return MOSQ_ERR_PROTOCOL;
|
||||
if(packet->pos+count > packet->remaining_length) return MOSQ_ERR_MALFORMED_PACKET;
|
||||
|
||||
memcpy(bytes, &(packet->payload[packet->pos]), count);
|
||||
packet->pos += count;
|
||||
@@ -105,7 +105,7 @@ int packet__read_binary(struct mosquitto__packet *packet, uint8_t **data, uint16
|
||||
return MOSQ_ERR_SUCCESS;
|
||||
}
|
||||
|
||||
if(packet->pos+slen > packet->remaining_length) return MOSQ_ERR_PROTOCOL;
|
||||
if(packet->pos+slen > packet->remaining_length) return MOSQ_ERR_MALFORMED_PACKET;
|
||||
|
||||
*data = mosquitto__malloc(slen+1U);
|
||||
if(*data){
|
||||
@@ -153,7 +153,7 @@ int packet__read_uint16(struct mosquitto__packet *packet, uint16_t *word)
|
||||
uint8_t msb, lsb;
|
||||
|
||||
assert(packet);
|
||||
if(packet->pos+2 > packet->remaining_length) return MOSQ_ERR_PROTOCOL;
|
||||
if(packet->pos+2 > packet->remaining_length) return MOSQ_ERR_MALFORMED_PACKET;
|
||||
|
||||
msb = packet->payload[packet->pos];
|
||||
packet->pos++;
|
||||
@@ -179,7 +179,7 @@ int packet__read_uint32(struct mosquitto__packet *packet, uint32_t *word)
|
||||
int i;
|
||||
|
||||
assert(packet);
|
||||
if(packet->pos+4 > packet->remaining_length) return MOSQ_ERR_PROTOCOL;
|
||||
if(packet->pos+4 > packet->remaining_length) return MOSQ_ERR_MALFORMED_PACKET;
|
||||
|
||||
for(i=0; i<4; i++){
|
||||
val = (val << 8) + packet->payload[packet->pos];
|
||||
@@ -219,7 +219,7 @@ int packet__read_varint(struct mosquitto__packet *packet, uint32_t *word, uint8_
|
||||
if((byte & 128) == 0){
|
||||
if(lbytes > 1 && byte == 0){
|
||||
/* Catch overlong encodings */
|
||||
return MOSQ_ERR_PROTOCOL;
|
||||
return MOSQ_ERR_MALFORMED_PACKET;
|
||||
}else{
|
||||
*word = lword;
|
||||
if(bytes) (*bytes) = lbytes;
|
||||
@@ -227,10 +227,10 @@ int packet__read_varint(struct mosquitto__packet *packet, uint32_t *word, uint8_
|
||||
}
|
||||
}
|
||||
}else{
|
||||
return MOSQ_ERR_PROTOCOL;
|
||||
return MOSQ_ERR_MALFORMED_PACKET;
|
||||
}
|
||||
}
|
||||
return MOSQ_ERR_PROTOCOL;
|
||||
return MOSQ_ERR_MALFORMED_PACKET;
|
||||
}
|
||||
|
||||
|
||||
@@ -251,7 +251,7 @@ int packet__write_varint(struct mosquitto__packet *packet, uint32_t word)
|
||||
}while(word > 0 && count < 5);
|
||||
|
||||
if(count == 5){
|
||||
return MOSQ_ERR_PROTOCOL;
|
||||
return MOSQ_ERR_MALFORMED_PACKET;
|
||||
}
|
||||
return MOSQ_ERR_SUCCESS;
|
||||
}
|
||||
|
||||
+32
-1
@@ -423,7 +423,7 @@ int packet__read(struct mosquitto *mosq)
|
||||
* Anything more likely means a broken/malicious client.
|
||||
*/
|
||||
if(mosq->in_packet.remaining_count < -4){
|
||||
return MOSQ_ERR_PROTOCOL;
|
||||
return MOSQ_ERR_MALFORMED_PACKET;
|
||||
}
|
||||
|
||||
G_BYTES_RECEIVED_INC(1);
|
||||
@@ -455,6 +455,37 @@ int packet__read(struct mosquitto *mosq)
|
||||
mosq->in_packet.remaining_count = (int8_t)(mosq->in_packet.remaining_count * -1);
|
||||
|
||||
#ifdef WITH_BROKER
|
||||
switch(mosq->in_packet.command & 0xF0){
|
||||
case CMD_CONNECT:
|
||||
if(mosq->in_packet.remaining_length > 100000){ /* Arbitrary limit, make configurable */
|
||||
return MOSQ_ERR_MALFORMED_PACKET;
|
||||
}
|
||||
break;
|
||||
|
||||
case CMD_PUBACK:
|
||||
case CMD_PUBREC:
|
||||
case CMD_PUBREL:
|
||||
case CMD_PUBCOMP:
|
||||
case CMD_UNSUBACK:
|
||||
if(mosq->protocol != mosq_p_mqtt5 && mosq->in_packet.remaining_length != 2){
|
||||
return MOSQ_ERR_MALFORMED_PACKET;
|
||||
}
|
||||
break;
|
||||
|
||||
case CMD_PINGREQ:
|
||||
case CMD_PINGRESP:
|
||||
if(mosq->in_packet.remaining_length != 0){
|
||||
return MOSQ_ERR_MALFORMED_PACKET;
|
||||
}
|
||||
break;
|
||||
|
||||
case CMD_DISCONNECT:
|
||||
if(mosq->protocol != mosq_p_mqtt5 && mosq->in_packet.remaining_length != 0){
|
||||
return MOSQ_ERR_MALFORMED_PACKET;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if(db.config->max_packet_size > 0 && mosq->in_packet.remaining_length+1 > db.config->max_packet_size){
|
||||
if(mosq->protocol == mosq_p_mqtt5){
|
||||
send__disconnect(mosq, MQTT_RC_PACKET_TOO_LARGE, NULL);
|
||||
|
||||
+4
-1
@@ -48,7 +48,9 @@ static int property__read(struct mosquitto__packet *packet, uint32_t *len, mosqu
|
||||
if(!property) return MOSQ_ERR_INVAL;
|
||||
|
||||
rc = packet__read_varint(packet, &property_identifier, NULL);
|
||||
if(rc) return rc;
|
||||
if(rc){
|
||||
return rc;
|
||||
}
|
||||
*len -= 1;
|
||||
|
||||
memset(property, 0, sizeof(mosquitto_property));
|
||||
@@ -932,6 +934,7 @@ int mosquitto_property_check_all(int command, const mosquitto_property *properti
|
||||
while(p){
|
||||
/* Validity checks */
|
||||
if(p->identifier == MQTT_PROP_REQUEST_PROBLEM_INFORMATION
|
||||
|| p->identifier == MQTT_PROP_PAYLOAD_FORMAT_INDICATOR
|
||||
|| p->identifier == MQTT_PROP_REQUEST_RESPONSE_INFORMATION
|
||||
|| p->identifier == MQTT_PROP_MAXIMUM_QOS
|
||||
|| p->identifier == MQTT_PROP_RETAIN_AVAILABLE
|
||||
|
||||
@@ -47,6 +47,9 @@ int handle__auth(struct mosquitto *context)
|
||||
if(context->protocol != mosq_p_mqtt5 || context->auth_method == NULL){
|
||||
return MOSQ_ERR_PROTOCOL;
|
||||
}
|
||||
if(context->in_packet.command != CMD_AUTH){
|
||||
return MOSQ_ERR_MALFORMED_PACKET;
|
||||
}
|
||||
|
||||
if(context->in_packet.remaining_length > 0){
|
||||
if(packet__read_byte(&context->in_packet, &reason_code)) return MOSQ_ERR_MALFORMED_PACKET;
|
||||
|
||||
@@ -39,9 +39,15 @@ int handle__connack(struct mosquitto *context)
|
||||
uint16_t server_keepalive;
|
||||
uint8_t max_qos = 255;
|
||||
|
||||
if(context == NULL || context->bridge == NULL){
|
||||
if(context == NULL){
|
||||
return MOSQ_ERR_INVAL;
|
||||
}
|
||||
if(context->bridge == NULL){
|
||||
return MOSQ_ERR_PROTOCOL;
|
||||
}
|
||||
if(context->in_packet.command != CMD_CONNACK){
|
||||
return MOSQ_ERR_MALFORMED_PACKET;
|
||||
}
|
||||
log__printf(NULL, MOSQ_LOG_DEBUG, "Received CONNACK on connection %s.", context->id);
|
||||
if(packet__read_byte(&context->in_packet, &connect_acknowledge)) return MOSQ_ERR_MALFORMED_PACKET;
|
||||
if(packet__read_byte(&context->in_packet, &reason_code)) return MOSQ_ERR_MALFORMED_PACKET;
|
||||
|
||||
@@ -445,6 +445,9 @@ int handle__connect(struct mosquitto *context)
|
||||
rc = MOSQ_ERR_PROTOCOL;
|
||||
goto handle_connect_error;
|
||||
}
|
||||
if(context->in_packet.command != CMD_CONNECT){
|
||||
return MOSQ_ERR_MALFORMED_PACKET;
|
||||
}
|
||||
|
||||
/* Read protocol name as length then bytes rather than with read_string
|
||||
* because the length is fixed and we can check that. Removes the need
|
||||
@@ -673,7 +676,7 @@ int handle__connect(struct mosquitto *context)
|
||||
if(rc == MOSQ_ERR_NOMEM){
|
||||
rc = MOSQ_ERR_NOMEM;
|
||||
goto handle_connect_error;
|
||||
}else if(rc == MOSQ_ERR_PROTOCOL){
|
||||
}else if(rc == MOSQ_ERR_MALFORMED_PACKET){
|
||||
if(context->protocol == mosq_p_mqtt31){
|
||||
/* Password flag given, but no password. Ignore. */
|
||||
}else{
|
||||
|
||||
@@ -37,6 +37,10 @@ int handle__disconnect(struct mosquitto *context)
|
||||
return MOSQ_ERR_INVAL;
|
||||
}
|
||||
|
||||
if(context->in_packet.command != CMD_DISCONNECT){
|
||||
return MOSQ_ERR_MALFORMED_PACKET;
|
||||
}
|
||||
|
||||
if(context->protocol == mosq_p_mqtt5 && context->in_packet.remaining_length > 0){
|
||||
/* FIXME - must handle reason code */
|
||||
rc = packet__read_byte(&context->in_packet, &reason_code);
|
||||
@@ -49,9 +53,6 @@ int handle__disconnect(struct mosquitto *context)
|
||||
}
|
||||
rc = property__process_disconnect(context, &properties);
|
||||
if(rc){
|
||||
if(rc == MOSQ_ERR_PROTOCOL){
|
||||
send__disconnect(context, MQTT_RC_PROTOCOL_ERROR, NULL);
|
||||
}
|
||||
mosquitto_property_free_all(&properties);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -64,6 +64,12 @@ int handle__publish(struct mosquitto *context)
|
||||
|
||||
dup = (header & 0x08)>>3;
|
||||
msg->qos = (header & 0x06)>>1;
|
||||
if(dup == 1 && msg->qos == 0){
|
||||
log__printf(NULL, MOSQ_LOG_INFO,
|
||||
"Invalid PUBLISH (QoS=0 and DUP=1) from %s, disconnecting.", context->id);
|
||||
db__msg_store_free(msg);
|
||||
return MOSQ_ERR_MALFORMED_PACKET;
|
||||
}
|
||||
if(msg->qos == 3){
|
||||
log__printf(NULL, MOSQ_LOG_INFO,
|
||||
"Invalid QoS in PUBLISH from %s, disconnecting.", context->id);
|
||||
@@ -112,11 +118,7 @@ int handle__publish(struct mosquitto *context)
|
||||
rc = property__read_all(CMD_PUBLISH, &context->in_packet, &properties);
|
||||
if(rc){
|
||||
db__msg_store_free(msg);
|
||||
if(rc == MOSQ_ERR_PROTOCOL){
|
||||
return MOSQ_ERR_MALFORMED_PACKET;
|
||||
}else{
|
||||
return rc;
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
p = properties;
|
||||
@@ -202,7 +204,7 @@ int handle__publish(struct mosquitto *context)
|
||||
if(mosquitto_pub_topic_check(msg->topic) != MOSQ_ERR_SUCCESS){
|
||||
/* Invalid publish topic, just swallow it. */
|
||||
db__msg_store_free(msg);
|
||||
return MOSQ_ERR_PROTOCOL;
|
||||
return MOSQ_ERR_MALFORMED_PACKET;
|
||||
}
|
||||
|
||||
msg->payloadlen = context->in_packet.remaining_length - context->in_packet.pos;
|
||||
|
||||
@@ -52,6 +52,9 @@ int handle__subscribe(struct mosquitto *context)
|
||||
if(context->state != mosq_cs_active){
|
||||
return MOSQ_ERR_PROTOCOL;
|
||||
}
|
||||
if(context->in_packet.command != (CMD_SUBSCRIBE|2)){
|
||||
return MOSQ_ERR_MALFORMED_PACKET;
|
||||
}
|
||||
|
||||
log__printf(NULL, MOSQ_LOG_DEBUG, "Received SUBSCRIBE from %s", context->id);
|
||||
|
||||
|
||||
@@ -45,6 +45,9 @@ int handle__unsubscribe(struct mosquitto *context)
|
||||
if(context->state != mosq_cs_active){
|
||||
return MOSQ_ERR_PROTOCOL;
|
||||
}
|
||||
if(context->in_packet.command != (CMD_UNSUBSCRIBE|2)){
|
||||
return MOSQ_ERR_MALFORMED_PACKET;
|
||||
}
|
||||
log__printf(NULL, MOSQ_LOG_DEBUG, "Received UNSUBSCRIBE from %s", context->id);
|
||||
|
||||
if(context->protocol != mosq_p_mqtt31){
|
||||
|
||||
+1
-1
@@ -348,7 +348,7 @@ void do_disconnect(struct mosquitto *context, int reason)
|
||||
log__printf(NULL, MOSQ_LOG_NOTICE, "Client %s disconnected due to out of memory.", id);
|
||||
break;
|
||||
case MOSQ_ERR_NOT_SUPPORTED:
|
||||
log__printf(NULL, MOSQ_LOG_NOTICE, "Client %s disconnected due to QoS too high or retain not supported.", id);
|
||||
log__printf(NULL, MOSQ_LOG_NOTICE, "Client %s disconnected due to using not allowed feature (QoS too high, retain not supported, or bad AUTH method).", id);
|
||||
break;
|
||||
case MOSQ_ERR_ADMINISTRATIVE_ACTION:
|
||||
log__printf(NULL, MOSQ_LOG_NOTICE, "Client %s been disconnected by administrative action.", id);
|
||||
|
||||
+23
-13
@@ -40,24 +40,31 @@ int handle__packet(struct mosquitto *context)
|
||||
|
||||
switch((context->in_packet.command)&0xF0){
|
||||
case CMD_PINGREQ:
|
||||
return handle__pingreq(context);
|
||||
rc = handle__pingreq(context);
|
||||
break;
|
||||
case CMD_PINGRESP:
|
||||
return handle__pingresp(context);
|
||||
rc = handle__pingresp(context);
|
||||
break;
|
||||
case CMD_PUBACK:
|
||||
return handle__pubackcomp(context, "PUBACK");
|
||||
rc = handle__pubackcomp(context, "PUBACK");
|
||||
break;
|
||||
case CMD_PUBCOMP:
|
||||
return handle__pubackcomp(context, "PUBCOMP");
|
||||
rc = handle__pubackcomp(context, "PUBCOMP");
|
||||
break;
|
||||
case CMD_PUBLISH:
|
||||
rc = handle__publish(context);
|
||||
break;
|
||||
case CMD_PUBREC:
|
||||
return handle__pubrec(context);
|
||||
rc = handle__pubrec(context);
|
||||
break;
|
||||
case CMD_PUBREL:
|
||||
return handle__pubrel(context);
|
||||
rc = handle__pubrel(context);
|
||||
break;
|
||||
case CMD_CONNECT:
|
||||
return handle__connect(context);
|
||||
case CMD_DISCONNECT:
|
||||
return handle__disconnect(context);
|
||||
rc = handle__disconnect(context);
|
||||
break;
|
||||
case CMD_SUBSCRIBE:
|
||||
rc = handle__subscribe(context);
|
||||
break;
|
||||
@@ -66,20 +73,24 @@ int handle__packet(struct mosquitto *context)
|
||||
break;
|
||||
#ifdef WITH_BRIDGE
|
||||
case CMD_CONNACK:
|
||||
return handle__connack(context);
|
||||
rc = handle__connack(context);
|
||||
break;
|
||||
case CMD_SUBACK:
|
||||
return handle__suback(context);
|
||||
rc = handle__suback(context);
|
||||
break;
|
||||
case CMD_UNSUBACK:
|
||||
return handle__unsuback(context);
|
||||
rc = handle__unsuback(context);
|
||||
break;
|
||||
#endif
|
||||
case CMD_AUTH:
|
||||
return handle__auth(context);
|
||||
rc = handle__auth(context);
|
||||
break;
|
||||
default:
|
||||
rc = MOSQ_ERR_PROTOCOL;
|
||||
}
|
||||
|
||||
if(context->protocol == mosq_p_mqtt5){
|
||||
if(rc == MOSQ_ERR_PROTOCOL){
|
||||
if(rc == MOSQ_ERR_PROTOCOL || rc == MOSQ_ERR_DUPLICATE_PROPERTY){
|
||||
send__disconnect(context, MQTT_RC_PROTOCOL_ERROR, NULL);
|
||||
}else if(rc == MOSQ_ERR_MALFORMED_PACKET){
|
||||
send__disconnect(context, MQTT_RC_MALFORMED_PACKET, NULL);
|
||||
@@ -95,4 +106,3 @@ int handle__packet(struct mosquitto *context)
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,43 +0,0 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
# Test whether a first packet of non-CONNECT is rejected.
|
||||
|
||||
from mosq_test_helper import *
|
||||
|
||||
def do_test(proto_ver):
|
||||
rc = 1
|
||||
mid = 2
|
||||
publish_packet = mosq_test.gen_publish("pub/qos1/test", qos=1, mid=mid, payload="message", proto_ver=proto_ver)
|
||||
puback_packet = mosq_test.gen_puback(mid, proto_ver=proto_ver)
|
||||
|
||||
port = mosq_test.get_port()
|
||||
broker = mosq_test.start_broker(filename=os.path.basename(__file__), port=port)
|
||||
|
||||
try:
|
||||
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
sock.settimeout(5)
|
||||
sock.connect(("localhost", port))
|
||||
sock.send(publish_packet)
|
||||
data = sock.recv(1)
|
||||
sock.close()
|
||||
if len(data) == 0:
|
||||
rc = 0
|
||||
except socket.error as e:
|
||||
if e.errno == errno.ECONNRESET:
|
||||
# Connection has been closed by peer, this is the expected behaviour
|
||||
rc = 0
|
||||
except mosq_test.TestError:
|
||||
pass
|
||||
finally:
|
||||
broker.terminate()
|
||||
broker.wait()
|
||||
(stdo, stde) = broker.communicate()
|
||||
if rc:
|
||||
print(stde.decode('utf-8'))
|
||||
print("proto_ver=%d" % (proto_ver))
|
||||
exit(rc)
|
||||
|
||||
|
||||
do_test(proto_ver=4)
|
||||
do_test(proto_ver=5)
|
||||
exit(0)
|
||||
@@ -1,50 +0,0 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
# Test https://github.com/eclipse/mosquitto/issues/2163
|
||||
# Does the broker cope with a malformed CONNACK sent to it after a valid CONNECT?
|
||||
|
||||
from mosq_test_helper import *
|
||||
|
||||
def do_test(proto_ver):
|
||||
rc = 1
|
||||
keepalive = 10
|
||||
connect_packet = mosq_test.gen_connect("connect-connack-2163", keepalive=keepalive, proto_ver=proto_ver)
|
||||
connack_packet = mosq_test.gen_connack(rc=0, proto_ver=proto_ver)
|
||||
connack_malformed = struct.pack("BBBBB", 0x02, 0x00, 0x01, 0xE0, 0x00)
|
||||
connack_malformed = struct.pack("BBBB", 0x29, 0x02, 0x00, 0x01)
|
||||
pingreq_packet = mosq_test.gen_pingreq()
|
||||
|
||||
port = mosq_test.get_port()
|
||||
broker = mosq_test.start_broker(filename=os.path.basename(__file__), port=port)
|
||||
|
||||
try:
|
||||
sock = mosq_test.do_client_connect(connect_packet, connack_packet, port=port)
|
||||
sock.send(connack_malformed)
|
||||
try:
|
||||
mosq_test.do_send_receive(sock, pingreq_packet, b"", "pingreq")
|
||||
except ConnectionResetError:
|
||||
pass
|
||||
sock.close()
|
||||
|
||||
# Does the broker still exist?
|
||||
sock = mosq_test.do_client_connect(connect_packet, connack_packet, port=port)
|
||||
mosq_test.do_ping(sock)
|
||||
sock.close()
|
||||
|
||||
rc = 0
|
||||
except mosq_test.TestError:
|
||||
pass
|
||||
finally:
|
||||
broker.terminate()
|
||||
broker.wait()
|
||||
(stdo, stde) = broker.communicate()
|
||||
if rc:
|
||||
print(stde.decode('utf-8'))
|
||||
print("proto_ver=%d" % (proto_ver))
|
||||
exit(rc)
|
||||
|
||||
|
||||
do_test(proto_ver=3)
|
||||
do_test(proto_ver=4)
|
||||
do_test(proto_ver=5)
|
||||
exit(0)
|
||||
@@ -65,5 +65,4 @@ finally:
|
||||
print(stde.decode('utf-8'))
|
||||
|
||||
if rc != 0:
|
||||
print(test)
|
||||
exit(rc)
|
||||
|
||||
@@ -1,39 +0,0 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
# Test whether a duplicate CONNECT is rejected.
|
||||
|
||||
from mosq_test_helper import *
|
||||
|
||||
def do_test(proto_ver):
|
||||
rc = 1
|
||||
keepalive = 10
|
||||
connect_packet = mosq_test.gen_connect("connect-test", keepalive=keepalive, proto_ver=proto_ver)
|
||||
connack_packet = mosq_test.gen_connack(rc=0, proto_ver=proto_ver)
|
||||
|
||||
port = mosq_test.get_port()
|
||||
broker = mosq_test.start_broker(filename=os.path.basename(__file__), port=port)
|
||||
|
||||
try:
|
||||
sock = mosq_test.do_client_connect(connect_packet, connack_packet, port=port)
|
||||
sock.settimeout(3)
|
||||
sock.send(connect_packet)
|
||||
data = sock.recv(1)
|
||||
if len(data) == 0:
|
||||
rc = 0
|
||||
except socket.error:
|
||||
rc = 0
|
||||
except mosq_test.TestError:
|
||||
pass
|
||||
finally:
|
||||
broker.terminate()
|
||||
broker.wait()
|
||||
(stdo, stde) = broker.communicate()
|
||||
if rc:
|
||||
print(stde.decode('utf-8'))
|
||||
print("proto_ver=%d" % (proto_ver))
|
||||
exit(rc)
|
||||
|
||||
|
||||
do_test(proto_ver=4)
|
||||
do_test(proto_ver=5)
|
||||
exit(0)
|
||||
@@ -1,37 +0,0 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
# Test whether a CONNECT with a zero length client id results in the correct CONNACK packet.
|
||||
# MQTT V3.1 only - zero length is invalid.
|
||||
from mosq_test_helper import *
|
||||
|
||||
def do_test(proto_ver):
|
||||
rc = 1
|
||||
keepalive = 10
|
||||
connect_packet = mosq_test.gen_connect("", keepalive=keepalive, proto_ver=proto_ver)
|
||||
if proto_ver == 3:
|
||||
connack_packet = mosq_test.gen_connack(rc=2, proto_ver=proto_ver)
|
||||
elif proto_ver == 4:
|
||||
connack_packet = mosq_test.gen_connack(rc=0, proto_ver=proto_ver, properties=None)
|
||||
|
||||
port = mosq_test.get_port()
|
||||
broker = mosq_test.start_broker(filename=os.path.basename(__file__), port=port)
|
||||
|
||||
try:
|
||||
sock = mosq_test.do_client_connect(connect_packet, connack_packet, port=port)
|
||||
sock.close()
|
||||
rc = 0
|
||||
except mosq_test.TestError:
|
||||
pass
|
||||
finally:
|
||||
broker.terminate()
|
||||
broker.wait()
|
||||
(stdo, stde) = broker.communicate()
|
||||
if rc:
|
||||
print(stde.decode('utf-8'))
|
||||
print("proto_ver=%d" % (proto_ver))
|
||||
exit(rc)
|
||||
|
||||
|
||||
do_test(proto_ver=3)
|
||||
do_test(proto_ver=4)
|
||||
exit(0)
|
||||
@@ -1,28 +0,0 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
# Test whether a CONNECT with a zero length client id results in the correct CONNACK packet.
|
||||
|
||||
from mosq_test_helper import *
|
||||
|
||||
rc = 1
|
||||
keepalive = 10
|
||||
connect_packet = mosq_test.gen_connect(None, keepalive=keepalive, proto_ver=3)
|
||||
connack_packet = mosq_test.gen_connack(rc=2)
|
||||
|
||||
port = mosq_test.get_port()
|
||||
broker = mosq_test.start_broker(filename=os.path.basename(__file__), port=port)
|
||||
|
||||
try:
|
||||
sock = mosq_test.do_client_connect(connect_packet, connack_packet, port=port)
|
||||
sock.close()
|
||||
rc = 0
|
||||
except mosq_test.TestError:
|
||||
pass
|
||||
finally:
|
||||
broker.terminate()
|
||||
broker.wait()
|
||||
(stdo, stde) = broker.communicate()
|
||||
if rc:
|
||||
print(stde.decode('utf-8'))
|
||||
|
||||
exit(rc)
|
||||
@@ -1,39 +0,0 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
# Test whether a client id with invalid UTF-8 fails.
|
||||
|
||||
from mosq_test_helper import *
|
||||
|
||||
def do_test(proto_ver):
|
||||
rc = 1
|
||||
keepalive = 60
|
||||
connect_packet = mosq_test.gen_connect("connect-invalid-utf8", keepalive=keepalive, proto_ver=proto_ver)
|
||||
b = list(struct.unpack("B"*len(connect_packet), connect_packet))
|
||||
b[21] = 0 # Client id should never have a 0x0000
|
||||
connect_packet = struct.pack("B"*len(b), *b)
|
||||
|
||||
port = mosq_test.get_port()
|
||||
broker = mosq_test.start_broker(filename=os.path.basename(__file__), port=port)
|
||||
|
||||
try:
|
||||
time.sleep(0.5)
|
||||
|
||||
sock = mosq_test.do_client_connect(connect_packet, b"", port=port)
|
||||
# Exception occurs if connack packet returned
|
||||
rc = 0
|
||||
sock.close()
|
||||
except mosq_test.TestError:
|
||||
pass
|
||||
finally:
|
||||
broker.terminate()
|
||||
broker.wait()
|
||||
(stdo, stde) = broker.communicate()
|
||||
if rc:
|
||||
print(stde.decode('utf-8'))
|
||||
print("proto_ver=%d" % (proto_ver))
|
||||
exit(rc)
|
||||
|
||||
|
||||
do_test(proto_ver=4)
|
||||
do_test(proto_ver=5)
|
||||
exit(0)
|
||||
@@ -1,30 +0,0 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
# Test whether a CONNECT with an invalid protocol number results in the correct CONNACK packet.
|
||||
|
||||
from mosq_test_helper import *
|
||||
|
||||
rc = 1
|
||||
keepalive = 10
|
||||
connect_packet = mosq_test.gen_connect("connect-invalid-test", keepalive=keepalive, proto_ver=0)
|
||||
connack_packet = mosq_test.gen_connack(rc=1)
|
||||
|
||||
port = mosq_test.get_port()
|
||||
broker = mosq_test.start_broker(filename=os.path.basename(__file__), port=port)
|
||||
|
||||
try:
|
||||
sock = mosq_test.do_client_connect(connect_packet, connack_packet, port=port)
|
||||
sock.close()
|
||||
rc = 0
|
||||
|
||||
except mosq_test.TestError:
|
||||
pass
|
||||
finally:
|
||||
broker.terminate()
|
||||
broker.wait()
|
||||
(stdo, stde) = broker.communicate()
|
||||
if rc:
|
||||
print(stde.decode('utf-8'))
|
||||
|
||||
exit(rc)
|
||||
|
||||
@@ -1,32 +0,0 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
# Test whether a CONNECT with reserved set to 1 results in a disconnect. MQTT-3.1.2-3
|
||||
|
||||
from mosq_test_helper import *
|
||||
|
||||
rc = 1
|
||||
keepalive = 10
|
||||
connect_packet = mosq_test.gen_connect("connect-invalid-test", keepalive=keepalive, connect_reserved=True, proto_ver=4)
|
||||
|
||||
port = mosq_test.get_port()
|
||||
broker = mosq_test.start_broker(filename=os.path.basename(__file__), port=port)
|
||||
|
||||
try:
|
||||
sock = mosq_test.do_client_connect(connect_packet, b"", port=port)
|
||||
sock.close()
|
||||
rc = 0
|
||||
except socket.error as e:
|
||||
if e.errno == errno.ECONNRESET:
|
||||
# Connection has been closed by peer, this is the expected behaviour
|
||||
rc = 0
|
||||
except mosq_test.TestError:
|
||||
pass
|
||||
finally:
|
||||
broker.terminate()
|
||||
broker.wait()
|
||||
(stdo, stde) = broker.communicate()
|
||||
if rc:
|
||||
print(stde.decode('utf-8'))
|
||||
|
||||
exit(rc)
|
||||
|
||||
@@ -1,35 +0,0 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
# Test whether a valid CONNECT results in the correct CONNACK packet.
|
||||
|
||||
from mosq_test_helper import *
|
||||
|
||||
def do_test(proto_ver):
|
||||
rc = 1
|
||||
keepalive = 10
|
||||
connect_packet = mosq_test.gen_connect("connect-success-test", keepalive=keepalive, proto_ver=proto_ver)
|
||||
connack_packet = mosq_test.gen_connack(rc=0, proto_ver=proto_ver)
|
||||
|
||||
port = mosq_test.get_port()
|
||||
broker = mosq_test.start_broker(filename=os.path.basename(__file__), port=port)
|
||||
|
||||
try:
|
||||
sock = mosq_test.do_client_connect(connect_packet, connack_packet, port=port)
|
||||
sock.close()
|
||||
rc = 0
|
||||
except mosq_test.TestError:
|
||||
pass
|
||||
finally:
|
||||
broker.terminate()
|
||||
broker.wait()
|
||||
(stdo, stde) = broker.communicate()
|
||||
if rc:
|
||||
print(stde.decode('utf-8'))
|
||||
print("proto_ver=%d" % (proto_ver))
|
||||
exit(rc)
|
||||
|
||||
|
||||
do_test(proto_ver=3)
|
||||
do_test(proto_ver=4)
|
||||
do_test(proto_ver=5)
|
||||
exit(0)
|
||||
@@ -1,39 +0,0 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
# Test whether a username with invalid UTF-8 fails.
|
||||
|
||||
from mosq_test_helper import *
|
||||
|
||||
def do_test(proto_ver):
|
||||
rc = 1
|
||||
keepalive = 60
|
||||
connect_packet = mosq_test.gen_connect("connect-invalid-utf8", keepalive=keepalive, username="invalid/utf8", proto_ver=proto_ver)
|
||||
b = list(struct.unpack("B"*len(connect_packet), connect_packet))
|
||||
b[43] = 0 # Username should never have a 0x0000
|
||||
connect_packet = struct.pack("B"*len(b), *b)
|
||||
|
||||
port = mosq_test.get_port()
|
||||
broker = mosq_test.start_broker(filename=os.path.basename(__file__), port=port)
|
||||
|
||||
try:
|
||||
time.sleep(0.5)
|
||||
|
||||
sock = mosq_test.do_client_connect(connect_packet, b"", port=port)
|
||||
# Exception occurs if connack packet returned
|
||||
rc = 0
|
||||
sock.close()
|
||||
except mosq_test.TestError:
|
||||
pass
|
||||
finally:
|
||||
broker.terminate()
|
||||
broker.wait()
|
||||
(stdo, stde) = broker.communicate()
|
||||
if rc:
|
||||
print(stde.decode('utf-8'))
|
||||
print("proto_ver=%d" % (proto_ver))
|
||||
exit(rc)
|
||||
|
||||
|
||||
do_test(proto_ver=4)
|
||||
do_test(proto_ver=5)
|
||||
exit(0)
|
||||
@@ -1,39 +0,0 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
# Test whether a connection is disconnected if it provides a username but the
|
||||
# username flag is 0.
|
||||
|
||||
from mosq_test_helper import *
|
||||
|
||||
def do_test(proto_ver):
|
||||
rc = 1
|
||||
keepalive = 10
|
||||
connect_packet = mosq_test.gen_connect("connect-uname-test", keepalive=keepalive, username="user", proto_ver=proto_ver)
|
||||
b = list(struct.unpack("B"*len(connect_packet), connect_packet))
|
||||
b[9] = 2 # Remove username flag
|
||||
connect_packet = struct.pack("B"*len(b), *b)
|
||||
|
||||
connack_packet = mosq_test.gen_connack(rc=5)
|
||||
|
||||
port = mosq_test.get_port()
|
||||
broker = mosq_test.start_broker(filename=os.path.basename(__file__), port=port)
|
||||
|
||||
try:
|
||||
sock = mosq_test.do_client_connect(connect_packet, b"", port=port)
|
||||
sock.close()
|
||||
rc = 0
|
||||
except mosq_test.TestError:
|
||||
pass
|
||||
finally:
|
||||
broker.terminate()
|
||||
broker.wait()
|
||||
(stdo, stde) = broker.communicate()
|
||||
if rc:
|
||||
print(stde.decode('utf-8'))
|
||||
print("proto_ver=%d" % (proto_ver))
|
||||
exit(rc)
|
||||
|
||||
|
||||
do_test(proto_ver=4)
|
||||
do_test(proto_ver=5)
|
||||
exit(0)
|
||||
@@ -1,40 +0,0 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
# Test whether a connection is disconnected if it provides a password but the
|
||||
# password flag is 0.
|
||||
|
||||
from mosq_test_helper import *
|
||||
|
||||
|
||||
def do_test(proto_ver):
|
||||
rc = 1
|
||||
keepalive = 10
|
||||
connect_packet = mosq_test.gen_connect("connect-uname-test", keepalive=keepalive, username="user", password="pw", proto_ver=proto_ver)
|
||||
b = list(struct.unpack("B"*len(connect_packet), connect_packet))
|
||||
b[9] = 66 # Remove password flag
|
||||
connect_packet = struct.pack("B"*len(b), *b)
|
||||
|
||||
connack_packet = mosq_test.gen_connack(rc=5)
|
||||
|
||||
port = mosq_test.get_port()
|
||||
broker = mosq_test.start_broker(filename=os.path.basename(__file__), port=port)
|
||||
|
||||
try:
|
||||
sock = mosq_test.do_client_connect(connect_packet, b"", port=port)
|
||||
sock.close()
|
||||
rc = 0
|
||||
except mosq_test.TestError:
|
||||
pass
|
||||
finally:
|
||||
broker.terminate()
|
||||
broker.wait()
|
||||
(stdo, stde) = broker.communicate()
|
||||
if rc:
|
||||
print(stde.decode('utf-8'))
|
||||
print("proto_ver=%d" % (proto_ver))
|
||||
exit(rc)
|
||||
|
||||
|
||||
do_test(proto_ver=4)
|
||||
do_test(proto_ver=5)
|
||||
exit(0)
|
||||
@@ -1,45 +0,0 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
# Test whether a client subscribed to a topic receives its own message sent to that topic.
|
||||
|
||||
from mosq_test_helper import *
|
||||
|
||||
def do_test(proto_ver):
|
||||
rc = 1
|
||||
mid = 53
|
||||
keepalive = 60
|
||||
connect_packet = mosq_test.gen_connect("subpub-qos0-test", keepalive=keepalive, proto_ver=proto_ver)
|
||||
connack_packet = mosq_test.gen_connack(rc=0, proto_ver=proto_ver)
|
||||
|
||||
subscribe_packet = mosq_test.gen_subscribe(mid, "subpub/qos0", 0, proto_ver=proto_ver)
|
||||
suback_packet = mosq_test.gen_suback(mid, 0, proto_ver=proto_ver)
|
||||
|
||||
publish_packet = mosq_test.gen_publish("subpub/qos0", qos=0, payload="message", proto_ver=proto_ver)
|
||||
|
||||
port = mosq_test.get_port()
|
||||
broker = mosq_test.start_broker(filename=os.path.basename(__file__), port=port)
|
||||
|
||||
try:
|
||||
sock = mosq_test.do_client_connect(connect_packet, connack_packet, timeout=20, port=port)
|
||||
|
||||
mosq_test.do_send_receive(sock, subscribe_packet, suback_packet, "suback")
|
||||
mosq_test.do_send_receive(sock, publish_packet, publish_packet, "publish")
|
||||
|
||||
rc = 0
|
||||
|
||||
sock.close()
|
||||
except mosq_test.TestError:
|
||||
pass
|
||||
finally:
|
||||
broker.terminate()
|
||||
broker.wait()
|
||||
(stdo, stde) = broker.communicate()
|
||||
if rc:
|
||||
print(stde.decode('utf-8'))
|
||||
print("proto_ver=%d" % (proto_ver))
|
||||
exit(rc)
|
||||
|
||||
|
||||
do_test(proto_ver=4)
|
||||
do_test(proto_ver=5)
|
||||
exit(0)
|
||||
@@ -1,76 +0,0 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
# Test what the broker does if receiving a PUBCOMP in response to a QoS 1 PUBLISH.
|
||||
|
||||
from mosq_test_helper import *
|
||||
|
||||
def helper(port, proto_ver):
|
||||
connect_packet = mosq_test.gen_connect("helper", keepalive=60, proto_ver=proto_ver)
|
||||
connack_packet = mosq_test.gen_connack(rc=0, proto_ver=proto_ver)
|
||||
|
||||
mid = 1
|
||||
publish1s_packet = mosq_test.gen_publish("subpub/qos1", qos=1, mid=mid, payload="message", proto_ver=proto_ver)
|
||||
puback1s_packet = mosq_test.gen_puback(mid, proto_ver=proto_ver)
|
||||
|
||||
sock = mosq_test.do_client_connect(connect_packet, connack_packet, timeout=20, port=port)
|
||||
mosq_test.do_send_receive(sock, publish1s_packet, puback1s_packet, "puback 1s")
|
||||
sock.close()
|
||||
|
||||
|
||||
def do_test(proto_ver):
|
||||
rc = 1
|
||||
keepalive = 60
|
||||
|
||||
connect_packet = mosq_test.gen_connect("subpub-qos1-test", keepalive=keepalive, proto_ver=proto_ver)
|
||||
connack_packet = mosq_test.gen_connack(rc=0, proto_ver=proto_ver)
|
||||
|
||||
mid = 1
|
||||
subscribe_packet = mosq_test.gen_subscribe(mid, "subpub/qos1", 1, proto_ver=proto_ver)
|
||||
suback_packet = mosq_test.gen_suback(mid, 1, proto_ver=proto_ver)
|
||||
|
||||
mid = 1
|
||||
publish_packet2 = mosq_test.gen_publish("subpub/qos1", qos=1, mid=mid, payload="message", proto_ver=proto_ver)
|
||||
|
||||
mid = 1
|
||||
publish1r_packet = mosq_test.gen_publish("subpub/qos1", qos=1, mid=mid, payload="message", proto_ver=proto_ver)
|
||||
pubcomp1r_packet = mosq_test.gen_pubcomp(mid, proto_ver=proto_ver)
|
||||
|
||||
pingreq_packet = mosq_test.gen_pingreq()
|
||||
pingresp_packet = mosq_test.gen_pingresp()
|
||||
|
||||
port = mosq_test.get_port()
|
||||
broker = mosq_test.start_broker(filename=os.path.basename(__file__), port=port)
|
||||
|
||||
try:
|
||||
sock = mosq_test.do_client_connect(connect_packet, connack_packet, timeout=20, port=port)
|
||||
mosq_test.do_send_receive(sock, subscribe_packet, suback_packet, "suback")
|
||||
|
||||
helper(port, proto_ver)
|
||||
|
||||
mosq_test.expect_packet(sock, "publish 1r", publish1r_packet)
|
||||
sock.send(pubcomp1r_packet)
|
||||
sock.send(pingreq_packet)
|
||||
p = sock.recv(len(pingresp_packet))
|
||||
if len(p) == 0:
|
||||
rc = 0
|
||||
|
||||
sock.close()
|
||||
except socket.error as e:
|
||||
if e.errno == errno.ECONNRESET:
|
||||
# Connection has been closed by peer, this is the expected behaviour
|
||||
rc = 0
|
||||
except mosq_test.TestError:
|
||||
pass
|
||||
finally:
|
||||
broker.terminate()
|
||||
broker.wait()
|
||||
(stdo, stde) = broker.communicate()
|
||||
if rc:
|
||||
print(stde.decode('utf-8'))
|
||||
print("proto_ver=%d" % (proto_ver))
|
||||
exit(rc)
|
||||
|
||||
|
||||
do_test(proto_ver=4)
|
||||
do_test(proto_ver=5)
|
||||
exit(0)
|
||||
@@ -1,73 +0,0 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
# Test what the broker does if receiving a PUBREC in response to a QoS 1 PUBLISH.
|
||||
|
||||
from mosq_test_helper import *
|
||||
|
||||
def helper(port, proto_ver):
|
||||
connect_packet = mosq_test.gen_connect("helper", keepalive=60, proto_ver=proto_ver)
|
||||
connack_packet = mosq_test.gen_connack(rc=0, proto_ver=proto_ver)
|
||||
|
||||
mid = 1
|
||||
publish1s_packet = mosq_test.gen_publish("subpub/qos1", qos=1, mid=mid, payload="message", proto_ver=proto_ver)
|
||||
puback1s_packet = mosq_test.gen_puback(mid, proto_ver=proto_ver)
|
||||
|
||||
sock = mosq_test.do_client_connect(connect_packet, connack_packet, timeout=20, port=port)
|
||||
mosq_test.do_send_receive(sock, publish1s_packet, puback1s_packet, "puback 1s")
|
||||
sock.close()
|
||||
|
||||
|
||||
def do_test(proto_ver):
|
||||
rc = 1
|
||||
keepalive = 60
|
||||
|
||||
connect_packet = mosq_test.gen_connect("subpub-qos1-test", keepalive=keepalive, proto_ver=proto_ver)
|
||||
connack_packet = mosq_test.gen_connack(rc=0, proto_ver=proto_ver)
|
||||
|
||||
mid = 1
|
||||
subscribe_packet = mosq_test.gen_subscribe(mid, "subpub/qos1", 1, proto_ver=proto_ver)
|
||||
suback_packet = mosq_test.gen_suback(mid, 1, proto_ver=proto_ver)
|
||||
|
||||
mid = 1
|
||||
publish1r_packet = mosq_test.gen_publish("subpub/qos1", qos=1, mid=mid, payload="message", proto_ver=proto_ver)
|
||||
pubrec1r_packet = mosq_test.gen_pubrec(mid, proto_ver=proto_ver)
|
||||
|
||||
pingreq_packet = mosq_test.gen_pingreq()
|
||||
pingresp_packet = mosq_test.gen_pingresp()
|
||||
|
||||
port = mosq_test.get_port()
|
||||
broker = mosq_test.start_broker(filename=os.path.basename(__file__), port=port)
|
||||
|
||||
try:
|
||||
sock = mosq_test.do_client_connect(connect_packet, connack_packet, timeout=20, port=port)
|
||||
mosq_test.do_send_receive(sock, subscribe_packet, suback_packet, "suback")
|
||||
|
||||
helper(port, proto_ver)
|
||||
|
||||
mosq_test.expect_packet(sock, "publish 1r", publish1r_packet)
|
||||
sock.send(pubrec1r_packet)
|
||||
sock.send(pingreq_packet)
|
||||
p = sock.recv(len(pingresp_packet))
|
||||
if len(p) == 0:
|
||||
rc = 0
|
||||
|
||||
sock.close()
|
||||
except socket.error as e:
|
||||
if e.errno == errno.ECONNRESET:
|
||||
# Connection has been closed by peer, this is the expected behaviour
|
||||
rc = 0
|
||||
except mosq_test.TestError:
|
||||
pass
|
||||
finally:
|
||||
broker.terminate()
|
||||
broker.wait()
|
||||
(stdo, stde) = broker.communicate()
|
||||
if rc:
|
||||
print(stde.decode('utf-8'))
|
||||
print("proto_ver=%d" % (proto_ver))
|
||||
exit(rc)
|
||||
|
||||
|
||||
do_test(proto_ver=4)
|
||||
do_test(proto_ver=5)
|
||||
exit(0)
|
||||
@@ -1,76 +0,0 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
# Test what the broker does if receiving a PUBACK in response to a QoS 2 PUBLISH.
|
||||
|
||||
from mosq_test_helper import *
|
||||
|
||||
def helper(port, proto_ver):
|
||||
connect_packet = mosq_test.gen_connect("helper", keepalive=60, proto_ver=proto_ver)
|
||||
connack_packet = mosq_test.gen_connack(rc=0, proto_ver=proto_ver)
|
||||
|
||||
mid = 1
|
||||
publish1s_packet = mosq_test.gen_publish("subpub/qos2", qos=2, mid=mid, payload="message", proto_ver=proto_ver)
|
||||
pubrec1s_packet = mosq_test.gen_pubrec(mid, proto_ver=proto_ver)
|
||||
pubrel1s_packet = mosq_test.gen_pubrel(mid, proto_ver=proto_ver)
|
||||
pubcomp1s_packet = mosq_test.gen_pubcomp(mid, proto_ver=proto_ver)
|
||||
|
||||
sock = mosq_test.do_client_connect(connect_packet, connack_packet, timeout=20, port=port)
|
||||
mosq_test.do_send_receive(sock, publish1s_packet, pubrec1s_packet, "pubrec 1s")
|
||||
mosq_test.do_send_receive(sock, pubrel1s_packet, pubcomp1s_packet, "pubcomp 1s")
|
||||
sock.close()
|
||||
|
||||
|
||||
def do_test(proto_ver):
|
||||
rc = 1
|
||||
keepalive = 60
|
||||
|
||||
connect_packet = mosq_test.gen_connect("subpub-qos2-test", keepalive=keepalive, proto_ver=proto_ver)
|
||||
connack_packet = mosq_test.gen_connack(rc=0, proto_ver=proto_ver)
|
||||
|
||||
mid = 1
|
||||
subscribe_packet = mosq_test.gen_subscribe(mid, "subpub/qos2", 2, proto_ver=proto_ver)
|
||||
suback_packet = mosq_test.gen_suback(mid, 2, proto_ver=proto_ver)
|
||||
|
||||
mid = 1
|
||||
publish1r_packet = mosq_test.gen_publish("subpub/qos2", qos=2, mid=mid, payload="message", proto_ver=proto_ver)
|
||||
puback1r_packet = mosq_test.gen_puback(mid, proto_ver=proto_ver)
|
||||
|
||||
pingreq_packet = mosq_test.gen_pingreq()
|
||||
pingresp_packet = mosq_test.gen_pingresp()
|
||||
|
||||
port = mosq_test.get_port()
|
||||
broker = mosq_test.start_broker(filename=os.path.basename(__file__), port=port)
|
||||
|
||||
try:
|
||||
sock = mosq_test.do_client_connect(connect_packet, connack_packet, timeout=20, port=port)
|
||||
mosq_test.do_send_receive(sock, subscribe_packet, suback_packet, "suback")
|
||||
|
||||
helper(port, proto_ver)
|
||||
|
||||
mosq_test.expect_packet(sock, "publish 1r", publish1r_packet)
|
||||
sock.send(puback1r_packet)
|
||||
sock.send(pingreq_packet)
|
||||
p = sock.recv(len(pingresp_packet))
|
||||
if len(p) == 0:
|
||||
rc = 0
|
||||
|
||||
sock.close()
|
||||
except socket.error as e:
|
||||
if e.errno == errno.ECONNRESET:
|
||||
# Connection has been closed by peer, this is the expected behaviour
|
||||
rc = 0
|
||||
except mosq_test.TestError:
|
||||
pass
|
||||
finally:
|
||||
broker.terminate()
|
||||
broker.wait()
|
||||
(stdo, stde) = broker.communicate()
|
||||
if rc:
|
||||
print(stde.decode('utf-8'))
|
||||
print("proto_ver=%d" % (proto_ver))
|
||||
exit(rc)
|
||||
|
||||
|
||||
do_test(proto_ver=4)
|
||||
do_test(proto_ver=5)
|
||||
exit(0)
|
||||
@@ -1,75 +0,0 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
# Test what the broker does if receiving a PUBACK in response to a QoS 2 PUBREL.
|
||||
|
||||
from mosq_test_helper import *
|
||||
|
||||
def do_test(proto_ver):
|
||||
rc = 1
|
||||
keepalive = 60
|
||||
|
||||
connect_packet = mosq_test.gen_connect("subpub-qos2-test", keepalive=keepalive, proto_ver=proto_ver)
|
||||
connack_packet = mosq_test.gen_connack(rc=0, proto_ver=proto_ver)
|
||||
|
||||
mid = 1
|
||||
subscribe_packet = mosq_test.gen_subscribe(mid, "subpub/qos2", 2, proto_ver=proto_ver)
|
||||
suback_packet = mosq_test.gen_suback(mid, 2, proto_ver=proto_ver)
|
||||
|
||||
helper_connect = mosq_test.gen_connect("helper", keepalive=keepalive, proto_ver=proto_ver)
|
||||
helper_connack = mosq_test.gen_connack(rc=0, proto_ver=proto_ver)
|
||||
|
||||
mid = 1
|
||||
publish1s_packet = mosq_test.gen_publish("subpub/qos2", qos=2, mid=mid, payload="message", proto_ver=proto_ver)
|
||||
pubrec1s_packet = mosq_test.gen_pubrec(mid, proto_ver=proto_ver)
|
||||
pubrel1s_packet = mosq_test.gen_pubrel(mid, proto_ver=proto_ver)
|
||||
pubcomp1s_packet = mosq_test.gen_pubcomp(mid, proto_ver=proto_ver)
|
||||
|
||||
mid = 1
|
||||
publish1r_packet = mosq_test.gen_publish("subpub/qos2", qos=2, mid=mid, payload="message", proto_ver=proto_ver)
|
||||
pubrec1r_packet = mosq_test.gen_pubrec(mid, proto_ver=proto_ver)
|
||||
pubrel1r_packet = mosq_test.gen_pubrel(mid, proto_ver=proto_ver)
|
||||
puback1r_packet = mosq_test.gen_puback(mid, proto_ver=proto_ver)
|
||||
|
||||
pingreq_packet = mosq_test.gen_pingreq()
|
||||
pingresp_packet = mosq_test.gen_pingresp()
|
||||
|
||||
port = mosq_test.get_port()
|
||||
broker = mosq_test.start_broker(filename=os.path.basename(__file__), port=port)
|
||||
|
||||
try:
|
||||
sock = mosq_test.do_client_connect(connect_packet, connack_packet, timeout=20, port=port)
|
||||
mosq_test.do_send_receive(sock, subscribe_packet, suback_packet, "suback")
|
||||
|
||||
helper = mosq_test.do_client_connect(helper_connect, helper_connack, timeout=20, port=port)
|
||||
mosq_test.do_send_receive(helper, publish1s_packet, pubrec1s_packet, "pubrec 1s")
|
||||
mosq_test.do_send_receive(helper, pubrel1s_packet, pubcomp1s_packet, "pubcomp 1s")
|
||||
helper.close()
|
||||
|
||||
mosq_test.expect_packet(sock, "publish 1r", publish1r_packet)
|
||||
mosq_test.do_send_receive(sock, pubrec1s_packet, pubrel1s_packet, "pubrel 1r")
|
||||
sock.send(puback1r_packet)
|
||||
sock.send(pingreq_packet)
|
||||
p = sock.recv(len(pingresp_packet))
|
||||
if len(p) == 0:
|
||||
rc = 0
|
||||
|
||||
sock.close()
|
||||
except socket.error as e:
|
||||
if e.errno == errno.ECONNRESET:
|
||||
# Connection has been closed by peer, this is the expected behaviour
|
||||
rc = 0
|
||||
except mosq_test.TestError:
|
||||
pass
|
||||
finally:
|
||||
broker.terminate()
|
||||
broker.wait()
|
||||
(stdo, stde) = broker.communicate()
|
||||
if rc:
|
||||
print(stde.decode('utf-8'))
|
||||
print("proto_ver=%d" % (proto_ver))
|
||||
exit(rc)
|
||||
|
||||
|
||||
do_test(proto_ver=4)
|
||||
do_test(proto_ver=5)
|
||||
exit(0)
|
||||
@@ -1,76 +0,0 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
# Test what the broker does if receiving a PUBCOMP in response to a QoS 2 PUBLISH.
|
||||
|
||||
from mosq_test_helper import *
|
||||
|
||||
def helper(port, proto_ver):
|
||||
connect_packet = mosq_test.gen_connect("helper", keepalive=60, proto_ver=proto_ver)
|
||||
connack_packet = mosq_test.gen_connack(rc=0, proto_ver=proto_ver)
|
||||
|
||||
mid = 1
|
||||
publish1s_packet = mosq_test.gen_publish("subpub/qos2", qos=2, mid=mid, payload="message", proto_ver=proto_ver)
|
||||
pubrec1s_packet = mosq_test.gen_pubrec(mid, proto_ver=proto_ver)
|
||||
pubrel1s_packet = mosq_test.gen_pubrel(mid, proto_ver=proto_ver)
|
||||
pubcomp1s_packet = mosq_test.gen_pubcomp(mid, proto_ver=proto_ver)
|
||||
|
||||
sock = mosq_test.do_client_connect(connect_packet, connack_packet, timeout=20, port=port)
|
||||
mosq_test.do_send_receive(sock, publish1s_packet, pubrec1s_packet, "pubrec 1s")
|
||||
mosq_test.do_send_receive(sock, pubrel1s_packet, pubcomp1s_packet, "pubcomp 1s")
|
||||
sock.close()
|
||||
|
||||
|
||||
def do_test(proto_ver):
|
||||
rc = 1
|
||||
keepalive = 60
|
||||
|
||||
connect_packet = mosq_test.gen_connect("subpub-qos2-test", keepalive=keepalive, proto_ver=proto_ver)
|
||||
connack_packet = mosq_test.gen_connack(rc=0, proto_ver=proto_ver)
|
||||
|
||||
mid = 1
|
||||
subscribe_packet = mosq_test.gen_subscribe(mid, "subpub/qos2", 2, proto_ver=proto_ver)
|
||||
suback_packet = mosq_test.gen_suback(mid, 2, proto_ver=proto_ver)
|
||||
|
||||
mid = 1
|
||||
publish1r_packet = mosq_test.gen_publish("subpub/qos2", qos=2, mid=mid, payload="message", proto_ver=proto_ver)
|
||||
pubcomp1r_packet = mosq_test.gen_pubcomp(mid, proto_ver=proto_ver)
|
||||
|
||||
pingreq_packet = mosq_test.gen_pingreq()
|
||||
pingresp_packet = mosq_test.gen_pingresp()
|
||||
|
||||
port = mosq_test.get_port()
|
||||
broker = mosq_test.start_broker(filename=os.path.basename(__file__), port=port)
|
||||
|
||||
try:
|
||||
sock = mosq_test.do_client_connect(connect_packet, connack_packet, timeout=20, port=port)
|
||||
mosq_test.do_send_receive(sock, subscribe_packet, suback_packet, "suback")
|
||||
|
||||
helper(port, proto_ver)
|
||||
|
||||
mosq_test.expect_packet(sock, "publish 1r", publish1r_packet)
|
||||
sock.send(pubcomp1r_packet)
|
||||
sock.send(pingreq_packet)
|
||||
p = sock.recv(len(pingresp_packet))
|
||||
if len(p) == 0:
|
||||
rc = 0
|
||||
|
||||
sock.close()
|
||||
except socket.error as e:
|
||||
if e.errno == errno.ECONNRESET:
|
||||
# Connection has been closed by peer, this is the expected behaviour
|
||||
rc = 0
|
||||
except mosq_test.TestError:
|
||||
pass
|
||||
finally:
|
||||
broker.terminate()
|
||||
broker.wait()
|
||||
(stdo, stde) = broker.communicate()
|
||||
if rc:
|
||||
print(stde.decode('utf-8'))
|
||||
print("proto_ver=%d" % (proto_ver))
|
||||
exit(rc)
|
||||
|
||||
|
||||
do_test(proto_ver=4)
|
||||
do_test(proto_ver=5)
|
||||
exit(0)
|
||||
@@ -1,43 +0,0 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
# Test whether a SUBSCRIBE to a topic with QoS 0 results in the correct SUBACK packet.
|
||||
|
||||
from mosq_test_helper import *
|
||||
|
||||
def do_test(proto_ver):
|
||||
rc = 1
|
||||
mid = 53
|
||||
keepalive = 60
|
||||
connect_packet = mosq_test.gen_connect("subscribe-qos0-test", keepalive=keepalive, proto_ver=proto_ver)
|
||||
connack_packet = mosq_test.gen_connack(rc=0, proto_ver=proto_ver)
|
||||
|
||||
subscribe_packet = mosq_test.gen_subscribe(mid, "qos0/test", 0, proto_ver=proto_ver)
|
||||
suback_packet = mosq_test.gen_suback(mid, 0, proto_ver=proto_ver)
|
||||
|
||||
port = mosq_test.get_port()
|
||||
broker = mosq_test.start_broker(filename=os.path.basename(__file__), port=port)
|
||||
|
||||
try:
|
||||
time.sleep(0.5)
|
||||
|
||||
sock = mosq_test.do_client_connect(connect_packet, connack_packet, port=port)
|
||||
mosq_test.do_send_receive(sock, subscribe_packet, suback_packet, "suback")
|
||||
|
||||
rc = 0
|
||||
|
||||
sock.close()
|
||||
except mosq_test.TestError:
|
||||
pass
|
||||
finally:
|
||||
broker.terminate()
|
||||
broker.wait()
|
||||
(stdo, stde) = broker.communicate()
|
||||
if rc:
|
||||
print(stde.decode('utf-8'))
|
||||
print("proto_ver=%d" % (proto_ver))
|
||||
exit(rc)
|
||||
|
||||
|
||||
do_test(proto_ver=4)
|
||||
do_test(proto_ver=5)
|
||||
exit(0)
|
||||
@@ -1,41 +0,0 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
# Test whether a SUBSCRIBE to a topic with QoS 1 results in the correct SUBACK packet.
|
||||
|
||||
from mosq_test_helper import *
|
||||
|
||||
def do_test(proto_ver):
|
||||
rc = 1
|
||||
mid = 79
|
||||
keepalive = 60
|
||||
connect_packet = mosq_test.gen_connect("subscribe-qos1-test", keepalive=keepalive, proto_ver=proto_ver)
|
||||
connack_packet = mosq_test.gen_connack(rc=0, proto_ver=proto_ver)
|
||||
|
||||
subscribe_packet = mosq_test.gen_subscribe(mid, "qos1/test", 1, proto_ver=proto_ver)
|
||||
suback_packet = mosq_test.gen_suback(mid, 1, proto_ver=proto_ver)
|
||||
|
||||
port = mosq_test.get_port()
|
||||
broker = mosq_test.start_broker(filename=os.path.basename(__file__), port=port)
|
||||
|
||||
try:
|
||||
sock = mosq_test.do_client_connect(connect_packet, connack_packet, port=port)
|
||||
mosq_test.do_send_receive(sock, subscribe_packet, suback_packet, "suback")
|
||||
|
||||
rc = 0
|
||||
|
||||
sock.close()
|
||||
except mosq_test.TestError:
|
||||
pass
|
||||
finally:
|
||||
broker.terminate()
|
||||
broker.wait()
|
||||
(stdo, stde) = broker.communicate()
|
||||
if rc:
|
||||
print(stde.decode('utf-8'))
|
||||
print("proto_ver=%d" % (proto_ver))
|
||||
exit(rc)
|
||||
|
||||
|
||||
do_test(proto_ver=4)
|
||||
do_test(proto_ver=5)
|
||||
exit(0)
|
||||
@@ -1,41 +0,0 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
# Test whether a SUBSCRIBE to a topic with QoS 2 results in the correct SUBACK packet.
|
||||
|
||||
from mosq_test_helper import *
|
||||
|
||||
def do_test(proto_ver):
|
||||
rc = 1
|
||||
mid = 3
|
||||
keepalive = 60
|
||||
connect_packet = mosq_test.gen_connect("subscribe-qos2-test", keepalive=keepalive, proto_ver=proto_ver)
|
||||
connack_packet = mosq_test.gen_connack(rc=0, proto_ver=proto_ver)
|
||||
|
||||
subscribe_packet = mosq_test.gen_subscribe(mid, "qos2/test", 2, proto_ver=proto_ver)
|
||||
suback_packet = mosq_test.gen_suback(mid, 2, proto_ver=proto_ver)
|
||||
|
||||
port = mosq_test.get_port()
|
||||
broker = mosq_test.start_broker(filename=os.path.basename(__file__), port=port)
|
||||
|
||||
try:
|
||||
sock = mosq_test.do_client_connect(connect_packet, connack_packet, port=port)
|
||||
mosq_test.do_send_receive(sock, subscribe_packet, suback_packet, "suback")
|
||||
|
||||
rc = 0
|
||||
|
||||
sock.close()
|
||||
except mosq_test.TestError:
|
||||
pass
|
||||
finally:
|
||||
broker.terminate()
|
||||
broker.wait()
|
||||
(stdo, stde) = broker.communicate()
|
||||
if rc:
|
||||
print(stde.decode('utf-8'))
|
||||
print("proto_ver=%d" % (proto_ver))
|
||||
exit(rc)
|
||||
|
||||
|
||||
do_test(proto_ver=4)
|
||||
do_test(proto_ver=5)
|
||||
exit(0)
|
||||
@@ -1,48 +0,0 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
# Test whether a UNSUBSCRIBE with no topic results in a disconnect. MQTT-3.10.3-2
|
||||
|
||||
from mosq_test_helper import *
|
||||
|
||||
def gen_unsubscribe_invalid_no_topic(mid):
|
||||
pack_format = "!BBH"
|
||||
return struct.pack(pack_format, 162, 2, mid)
|
||||
|
||||
def do_test(proto_ver):
|
||||
rc = 1
|
||||
mid = 3
|
||||
keepalive = 60
|
||||
connect_packet = mosq_test.gen_connect("unsubscribe-invalid-no-topic-test", keepalive=keepalive, proto_ver=proto_ver)
|
||||
connack_packet = mosq_test.gen_connack(rc=0, proto_ver=proto_ver)
|
||||
|
||||
unsubscribe_packet = gen_unsubscribe_invalid_no_topic(mid)
|
||||
|
||||
port = mosq_test.get_port()
|
||||
broker = mosq_test.start_broker(filename=os.path.basename(__file__), port=port)
|
||||
|
||||
try:
|
||||
sock = mosq_test.do_client_connect(connect_packet, connack_packet, port=port)
|
||||
if proto_ver == 4:
|
||||
mosq_test.do_send_receive(sock, unsubscribe_packet, b"", "disconnect")
|
||||
else:
|
||||
disconnect_packet = mosq_test.gen_disconnect(proto_ver=5, reason_code=mqtt5_rc.MQTT_RC_MALFORMED_PACKET)
|
||||
mosq_test.do_send_receive(sock, unsubscribe_packet, disconnect_packet, "disconnect")
|
||||
|
||||
rc = 0
|
||||
|
||||
sock.close()
|
||||
except mosq_test.TestError:
|
||||
pass
|
||||
finally:
|
||||
broker.terminate()
|
||||
broker.wait()
|
||||
(stdo, stde) = broker.communicate()
|
||||
if rc:
|
||||
print(stde.decode('utf-8'))
|
||||
print("proto_ver=%d" % (proto_ver))
|
||||
exit(rc)
|
||||
|
||||
|
||||
do_test(proto_ver=4)
|
||||
do_test(proto_ver=5)
|
||||
exit(0)
|
||||
@@ -1,45 +0,0 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
# Test whether a UNSUBSCRIBE to a topic with QoS 0 results in the correct UNSUBACK packet.
|
||||
# This doesn't assume a subscription exists.
|
||||
|
||||
from mosq_test_helper import *
|
||||
|
||||
def do_test(proto_ver):
|
||||
rc = 1
|
||||
mid = 53
|
||||
keepalive = 60
|
||||
connect_packet = mosq_test.gen_connect("unsubscribe-qos0-test", keepalive=keepalive, proto_ver=proto_ver)
|
||||
connack_packet = mosq_test.gen_connack(rc=0, proto_ver=proto_ver)
|
||||
|
||||
unsubscribe_packet = mosq_test.gen_unsubscribe(mid, "qos0/test", proto_ver=proto_ver)
|
||||
if proto_ver == 5:
|
||||
unsuback_packet = mosq_test.gen_unsuback(mid, proto_ver=proto_ver, reason_code=17)
|
||||
else:
|
||||
unsuback_packet = mosq_test.gen_unsuback(mid, proto_ver=proto_ver)
|
||||
|
||||
port = mosq_test.get_port()
|
||||
broker = mosq_test.start_broker(filename=os.path.basename(__file__), port=port)
|
||||
|
||||
try:
|
||||
sock = mosq_test.do_client_connect(connect_packet, connack_packet, port=port)
|
||||
mosq_test.do_send_receive(sock, unsubscribe_packet, unsuback_packet, "unsuback")
|
||||
|
||||
rc = 0
|
||||
|
||||
sock.close()
|
||||
except mosq_test.TestError:
|
||||
pass
|
||||
finally:
|
||||
broker.terminate()
|
||||
broker.wait()
|
||||
(stdo, stde) = broker.communicate()
|
||||
if rc:
|
||||
print(stde.decode('utf-8'))
|
||||
print("proto_ver=%d" % (proto_ver))
|
||||
exit(rc)
|
||||
|
||||
|
||||
do_test(proto_ver=4)
|
||||
do_test(proto_ver=5)
|
||||
exit(0)
|
||||
@@ -1,44 +0,0 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
# Test whether a SUBSCRIBE to a topic with QoS 1 results in the correct SUBACK packet.
|
||||
|
||||
from mosq_test_helper import *
|
||||
|
||||
def do_test(proto_ver):
|
||||
rc = 1
|
||||
mid = 79
|
||||
keepalive = 60
|
||||
connect_packet = mosq_test.gen_connect("unsubscribe-qos1-test", keepalive=keepalive, proto_ver=proto_ver)
|
||||
connack_packet = mosq_test.gen_connack(rc=0, proto_ver=proto_ver)
|
||||
|
||||
unsubscribe_packet = mosq_test.gen_unsubscribe(mid, "qos1/test", proto_ver=proto_ver)
|
||||
if proto_ver == 5:
|
||||
unsuback_packet = mosq_test.gen_unsuback(mid, proto_ver=proto_ver, reason_code=17)
|
||||
else:
|
||||
unsuback_packet = mosq_test.gen_unsuback(mid, proto_ver=proto_ver)
|
||||
|
||||
port = mosq_test.get_port()
|
||||
broker = mosq_test.start_broker(filename=os.path.basename(__file__), port=port)
|
||||
|
||||
try:
|
||||
sock = mosq_test.do_client_connect(connect_packet, connack_packet, port=port)
|
||||
mosq_test.do_send_receive(sock, unsubscribe_packet, unsuback_packet, "unsuback")
|
||||
|
||||
rc = 0
|
||||
|
||||
sock.close()
|
||||
except mosq_test.TestError:
|
||||
pass
|
||||
finally:
|
||||
broker.terminate()
|
||||
broker.wait()
|
||||
(stdo, stde) = broker.communicate()
|
||||
if rc:
|
||||
print(stde.decode('utf-8'))
|
||||
print("proto_ver=%d" % (proto_ver))
|
||||
exit(rc)
|
||||
|
||||
|
||||
do_test(proto_ver=4)
|
||||
do_test(proto_ver=5)
|
||||
exit(0)
|
||||
@@ -1,50 +0,0 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
# Test whether a UNSUBSCRIBE to multiple topics with QoS 2 results in the
|
||||
# correct UNSUBACK packet, when one subscription exists and the other does not.
|
||||
|
||||
from mosq_test_helper import *
|
||||
|
||||
def do_test(proto_ver):
|
||||
rc = 1
|
||||
keepalive = 60
|
||||
connect_packet = mosq_test.gen_connect("unsubscribe-qos2-test", keepalive=keepalive, proto_ver=proto_ver)
|
||||
connack_packet = mosq_test.gen_connack(rc=0, proto_ver=proto_ver)
|
||||
|
||||
mid = 1
|
||||
subscribe_packet = mosq_test.gen_subscribe(mid, "qos2/two", 2, proto_ver=proto_ver)
|
||||
suback_packet = mosq_test.gen_suback(mid, 2, proto_ver=proto_ver)
|
||||
|
||||
mid = 3
|
||||
unsubscribe_packet = mosq_test.gen_unsubscribe_multiple(mid, ["qos2/one", "qos2/two"], proto_ver=proto_ver)
|
||||
if proto_ver == 5:
|
||||
unsuback_packet = mosq_test.gen_unsuback(mid, proto_ver=proto_ver, reason_code=[17, 0])
|
||||
else:
|
||||
unsuback_packet = mosq_test.gen_unsuback(mid, proto_ver=proto_ver)
|
||||
|
||||
port = mosq_test.get_port()
|
||||
broker = mosq_test.start_broker(filename=os.path.basename(__file__), port=port)
|
||||
|
||||
try:
|
||||
sock = mosq_test.do_client_connect(connect_packet, connack_packet, port=port)
|
||||
mosq_test.do_send_receive(sock, subscribe_packet, suback_packet, "suback")
|
||||
mosq_test.do_send_receive(sock, unsubscribe_packet, unsuback_packet, "unsuback")
|
||||
|
||||
rc = 0
|
||||
|
||||
sock.close()
|
||||
except mosq_test.TestError:
|
||||
pass
|
||||
finally:
|
||||
broker.terminate()
|
||||
broker.wait()
|
||||
(stdo, stde) = broker.communicate()
|
||||
if rc:
|
||||
print(stde.decode('utf-8'))
|
||||
print("proto_ver=%d" % (proto_ver))
|
||||
exit(rc)
|
||||
|
||||
|
||||
do_test(proto_ver=4)
|
||||
do_test(proto_ver=5)
|
||||
exit(0)
|
||||
@@ -1,44 +0,0 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
# Test whether a SUBSCRIBE to a topic with QoS 2 results in the correct SUBACK packet.
|
||||
|
||||
from mosq_test_helper import *
|
||||
|
||||
def do_test(proto_ver):
|
||||
rc = 1
|
||||
mid = 3
|
||||
keepalive = 60
|
||||
connect_packet = mosq_test.gen_connect("unsubscribe-qos2-test", keepalive=keepalive, proto_ver=proto_ver)
|
||||
connack_packet = mosq_test.gen_connack(rc=0, proto_ver=proto_ver)
|
||||
|
||||
unsubscribe_packet = mosq_test.gen_unsubscribe(mid, "qos2/test", proto_ver=proto_ver)
|
||||
if proto_ver == 5:
|
||||
unsuback_packet = mosq_test.gen_unsuback(mid, proto_ver=proto_ver, reason_code=17)
|
||||
else:
|
||||
unsuback_packet = mosq_test.gen_unsuback(mid, proto_ver=proto_ver)
|
||||
|
||||
port = mosq_test.get_port()
|
||||
broker = mosq_test.start_broker(filename=os.path.basename(__file__), port=port)
|
||||
|
||||
try:
|
||||
sock = mosq_test.do_client_connect(connect_packet, connack_packet, port=port)
|
||||
mosq_test.do_send_receive(sock, unsubscribe_packet, unsuback_packet, "unsuback")
|
||||
|
||||
rc = 0
|
||||
|
||||
sock.close()
|
||||
except mosq_test.TestError:
|
||||
pass
|
||||
finally:
|
||||
broker.terminate()
|
||||
broker.wait()
|
||||
(stdo, stde) = broker.communicate()
|
||||
if rc:
|
||||
print(stde.decode('utf-8'))
|
||||
print("proto_ver=%d" % (proto_ver))
|
||||
exit(rc)
|
||||
|
||||
|
||||
do_test(proto_ver=4)
|
||||
do_test(proto_ver=5)
|
||||
exit(0)
|
||||
@@ -25,7 +25,7 @@ def do_test(proto_ver):
|
||||
if proto_ver == 4:
|
||||
mosq_test.do_send_receive(sock, publish_packet, b"", "puback")
|
||||
else:
|
||||
disconnect_packet = mosq_test.gen_disconnect(proto_ver=5, reason_code=mqtt5_rc.MQTT_RC_PROTOCOL_ERROR)
|
||||
disconnect_packet = mosq_test.gen_disconnect(proto_ver=5, reason_code=mqtt5_rc.MQTT_RC_MALFORMED_PACKET)
|
||||
mosq_test.do_send_receive(sock, publish_packet, disconnect_packet, "puback")
|
||||
|
||||
rc = 0
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user