def pattern_test(sub_topic, pub_topic):
    rc = 1
    keepalive = 60
    connect_packet = mosq_test.gen_connect("pattern-sub-test",
                                           keepalive=keepalive)
    connack_packet = mosq_test.gen_connack(rc=0)

    publish_packet = mosq_test.gen_publish(pub_topic, qos=0, payload="message")
    publish_retained_packet = mosq_test.gen_publish(pub_topic,
                                                    qos=0,
                                                    retain=True,
                                                    payload="message")

    mid = 312
    subscribe_packet = mosq_test.gen_subscribe(mid, sub_topic, 0)
    suback_packet = mosq_test.gen_suback(mid, 0)

    mid = 234
    unsubscribe_packet = mosq_test.gen_unsubscribe(mid, sub_topic)
    unsuback_packet = mosq_test.gen_unsuback(mid)

    broker = subprocess.Popen(['../../src/mosquitto', '-p', '1888'],
                              stderr=subprocess.PIPE)

    try:
        time.sleep(0.5)

        sock = mosq_test.do_client_connect(connect_packet,
                                           connack_packet,
                                           timeout=20)
        sock.send(subscribe_packet)

        if mosq_test.expect_packet(sock, "suback", suback_packet):
            pub = subprocess.Popen(
                ['./03-pattern-matching-helper.py', pub_topic])
            pub.wait()

            if mosq_test.expect_packet(sock, "publish", publish_packet):
                sock.send(unsubscribe_packet)

                if mosq_test.expect_packet(sock, "unsuback", unsuback_packet):
                    sock.send(subscribe_packet)

                    if mosq_test.expect_packet(sock, "suback", suback_packet):
                        if mosq_test.expect_packet(sock, "publish retained",
                                                   publish_retained_packet):
                            rc = 0

        sock.close()
    finally:
        broker.terminate()
        broker.wait()
        if rc:
            (stdo, stde) = broker.communicate()
            print(stde)
            raise

    return rc
Example #2
0
def pattern_test(sub_topic, pub_topic):
    rc = 1
    keepalive = 60
    connect_packet = mosq_test.gen_connect("pattern-sub-test", keepalive=keepalive)
    connack_packet = mosq_test.gen_connack(rc=0)

    publish_packet = mosq_test.gen_publish(pub_topic, qos=0, payload="message")
    publish_retained_packet = mosq_test.gen_publish(pub_topic, qos=0, retain=True, payload="message")

    mid = 312
    subscribe_packet = mosq_test.gen_subscribe(mid, sub_topic, 0)
    suback_packet = mosq_test.gen_suback(mid, 0)

    mid = 234;
    unsubscribe_packet = mosq_test.gen_unsubscribe(mid, sub_topic)
    unsuback_packet = mosq_test.gen_unsuback(mid)

    broker = subprocess.Popen(['../../src/mosquitto', '-p', '1888'], stderr=subprocess.PIPE)

    try:
        time.sleep(0.5)

        sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        sock.connect(("localhost", 1888))
        sock.settimeout(20)
        sock.send(connect_packet)

        if mosq_test.expect_packet(sock, "connack", connack_packet):
            sock.send(subscribe_packet)

            if mosq_test.expect_packet(sock, "suback", suback_packet):
                pub = subprocess.Popen(['./03-pattern-matching-helper.py', pub_topic])
                pub.wait()

                if mosq_test.expect_packet(sock, "publish", publish_packet):
                    sock.send(unsubscribe_packet)

                    if mosq_test.expect_packet(sock, "unsuback", unsuback_packet):
                        sock.send(subscribe_packet)

                        if mosq_test.expect_packet(sock, "suback", suback_packet):
                            if mosq_test.expect_packet(sock, "publish retained", publish_retained_packet):
                                rc = 0

        sock.close()
    finally:
        broker.terminate()
        broker.wait()
        if rc:
            (stdo, stde) = broker.communicate()
            print(stde)

    return rc
Example #3
0
def pattern_test(sub_topic, pub_topic):
    rc = 1
    keepalive = 60
    connect_packet = mosq_test.gen_connect("pattern-sub-test", keepalive=keepalive)
    connack_packet = mosq_test.gen_connack(rc=0)

    publish_packet = mosq_test.gen_publish(pub_topic, qos=0, payload="message")
    publish_retained_packet = mosq_test.gen_publish(pub_topic, qos=0, retain=True, payload="message")

    mid = 312
    subscribe_packet = mosq_test.gen_subscribe(mid, sub_topic, 0)
    suback_packet = mosq_test.gen_suback(mid, 0)

    mid = 234;
    unsubscribe_packet = mosq_test.gen_unsubscribe(mid, sub_topic)
    unsuback_packet = mosq_test.gen_unsuback(mid)

    port = mosq_test.get_port()
    broker = subprocess.Popen(['../../src/mosquitto', '-p', str(port)], stdout=subprocess.PIPE, stderr=subprocess.PIPE)

    try:
        time.sleep(0.5)

        sock = mosq_test.do_client_connect(connect_packet, connack_packet, timeout=20, port=port)
        sock.send(subscribe_packet)

        if mosq_test.expect_packet(sock, "suback", suback_packet):
            pub = subprocess.Popen(['./03-pattern-matching-helper.py', pub_topic, str(port)], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
            pub.wait()
            (stdo, stde) = pub.communicate()

            if mosq_test.expect_packet(sock, "publish", publish_packet):
                sock.send(unsubscribe_packet)

                if mosq_test.expect_packet(sock, "unsuback", unsuback_packet):
                    sock.send(subscribe_packet)

                    if mosq_test.expect_packet(sock, "suback", suback_packet):
                        if mosq_test.expect_packet(sock, "publish retained", publish_retained_packet):
                            rc = 0

        sock.close()
    finally:
        broker.terminate()
        broker.wait()
        (stdo, stde) = broker.communicate()
        if rc:
            print(stde)
            print(stdo)
            raise

    return rc
import mosq_test

rc = 1
keepalive = 60
mid = 16
connect_packet = mosq_test.gen_connect("retain-qos0-rep-test", keepalive=keepalive)
connack_packet = mosq_test.gen_connack(rc=0)

publish_packet = mosq_test.gen_publish("retain/qos0/test", qos=0, payload="retained message", retain=True)
subscribe_packet = mosq_test.gen_subscribe(mid, "retain/qos0/test", 0)
suback_packet = mosq_test.gen_suback(mid, 0)

unsub_mid = 13
unsubscribe_packet = mosq_test.gen_unsubscribe(unsub_mid, "retain/qos0/test/")
unsuback_packet = mosq_test.gen_unsuback(unsub_mid)

broker = subprocess.Popen(['../../src/mosquitto', '-p', '1888'], stderr=subprocess.PIPE)

try:
    time.sleep(0.5)

    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    sock.settimeout(20)
    sock.connect(("localhost", 1888))
    sock.send(connect_packet)

    if mosq_test.expect_packet(sock, "connack", connack_packet):
        sock.send(publish_packet)
        sock.send(subscribe_packet)
import mosq_test

rc = 1
keepalive = 60
connect_packet = mosq_test.gen_connect("retain-clear-test", keepalive=keepalive)
connack_packet = mosq_test.gen_connack(rc=0)

publish_packet = mosq_test.gen_publish("retain/clear/test", qos=0, payload="retained message", retain=True)
retain_clear_packet = mosq_test.gen_publish("retain/clear/test", qos=0, payload=None, retain=True)
mid_sub = 592
subscribe_packet = mosq_test.gen_subscribe(mid_sub, "retain/clear/test", 0)
suback_packet = mosq_test.gen_suback(mid_sub, 0)

mid_unsub = 593
unsubscribe_packet = mosq_test.gen_unsubscribe(mid_unsub, "retain/clear/test")
unsuback_packet = mosq_test.gen_unsuback(mid_unsub)

cmd = ['../../src/mosquitto', '-p', '1888']
broker = mosq_test.start_broker(filename=os.path.basename(__file__), cmd=cmd)

try:
    sock = mosq_test.do_client_connect(connect_packet, connack_packet, timeout=4)
    # Send retained message
    sock.send(publish_packet)
    # Subscribe to topic, we should get the retained message back.
    sock.send(subscribe_packet)

    if mosq_test.expect_packet(sock, "suback", suback_packet):
        if mosq_test.expect_packet(sock, "publish", publish_packet):
            # Now unsubscribe from the topic before we clear the retained
            # message.
Example #6
0
publish_packet = mosq_test.gen_publish("retain/clear/test",
                                       qos=0,
                                       payload="retained message",
                                       retain=True)
retain_clear_packet = mosq_test.gen_publish("retain/clear/test",
                                            qos=0,
                                            payload=None,
                                            retain=True)
mid_sub = 592
subscribe_packet = mosq_test.gen_subscribe(mid_sub, "retain/clear/test", 0)
suback_packet = mosq_test.gen_suback(mid_sub, 0)

mid_unsub = 593
unsubscribe_packet = mosq_test.gen_unsubscribe(mid_unsub, "retain/clear/test")
unsuback_packet = mosq_test.gen_unsuback(mid_unsub)

cmd = ['../../src/mosquitto', '-p', '1888']
broker = mosq_test.start_broker(filename=os.path.basename(__file__), cmd=cmd)

try:
    sock = mosq_test.do_client_connect(connect_packet,
                                       connack_packet,
                                       timeout=4)
    # Send retained message
    sock.send(publish_packet)
    # Subscribe to topic, we should get the retained message back.
    sock.send(subscribe_packet)

    if mosq_test.expect_packet(sock, "suback", suback_packet):
        if mosq_test.expect_packet(sock, "publish", publish_packet):
mid_unknown = 2000

publish_packet = mosq_test.gen_publish("bridge/unknown/qos2", qos=1, payload="bridge-message", mid=mid)
puback_packet = mosq_test.gen_puback(mid)

pubrec_packet_unknown1 = mosq_test.gen_pubrec(mid_unknown+1)
pubrel_packet_unknown1 = mosq_test.gen_pubrel(mid_unknown+1)

pubrel_packet_unknown2 = mosq_test.gen_pubrel(mid_unknown+2)
pubcomp_packet_unknown2 = mosq_test.gen_pubcomp(mid_unknown+2)

pubcomp_packet_unknown3 = mosq_test.gen_pubcomp(mid_unknown+3)


unsubscribe_packet = mosq_test.gen_unsubscribe(1, "bridge/#")
unsuback_packet = mosq_test.gen_unsuback(1)


if os.environ.get('MOSQ_USE_VALGRIND') is not None:
    sleep_time = 5
else:
    sleep_time = 0.5


sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
sock.settimeout(10)
sock.bind(('', port1))
sock.listen(5)

broker = mosq_test.start_broker(filename=os.path.basename(__file__), port=port2, use_conf=True)
Example #8
0
publish_packet = mosq_test.gen_publish("bridge/unknown/qos2",
                                       qos=1,
                                       payload="bridge-message",
                                       mid=mid)
puback_packet = mosq_test.gen_puback(mid)

pubrec_packet_unknown1 = mosq_test.gen_pubrec(mid_unknown + 1)
pubrel_packet_unknown1 = mosq_test.gen_pubrel(mid_unknown + 1)

pubrel_packet_unknown2 = mosq_test.gen_pubrel(mid_unknown + 2)
pubcomp_packet_unknown2 = mosq_test.gen_pubcomp(mid_unknown + 2)

pubcomp_packet_unknown3 = mosq_test.gen_pubcomp(mid_unknown + 3)

unsubscribe_packet = mosq_test.gen_unsubscribe(1, "bridge/#")
unsuback_packet = mosq_test.gen_unsuback(1)

if os.environ.get('MOSQ_USE_VALGRIND') is not None:
    sleep_time = 5
else:
    sleep_time = 0.5

sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
sock.settimeout(10)
sock.bind(('', 1888))
sock.listen(5)

broker = mosq_test.start_broker(filename=os.path.basename(__file__), port=1889)
time.sleep(sleep_time)
def pattern_test(sub_topic, pub_topic):
    rc = 1
    keepalive = 60
    connect_packet = mosq_test.gen_connect("pattern-sub-test", keepalive=keepalive)
    connack_packet = mosq_test.gen_connack(rc=0)

    publish_packet = mosq_test.gen_publish(pub_topic, qos=0, payload="message")
    publish_retained_packet = mosq_test.gen_publish(pub_topic, qos=0, retain=True, payload="message")

    mid = 312
    subscribe_packet = mosq_test.gen_subscribe(mid, sub_topic, 0)
    suback_packet = mosq_test.gen_suback(mid, 0)

    mid = 234;
    unsubscribe_packet = mosq_test.gen_unsubscribe(mid, sub_topic)
    unsuback_packet = mosq_test.gen_unsuback(mid)

    broker = subprocess.Popen(['../../src/mosquitto', '-p', '1888'], stderr=subprocess.PIPE)

    try:
        time.sleep(0.5)

        sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        sock.connect(("localhost", 1888))
        sock.settimeout(5)
        sock.send(connect_packet)
        connack_recvd = sock.recv(len(connack_packet))

        if mosq_test.packet_matches("connack", connack_recvd, connack_packet):
            sock.send(subscribe_packet)
            suback_recvd = sock.recv(len(suback_packet))

            if mosq_test.packet_matches("suback", suback_recvd, suback_packet):
                pub = subprocess.Popen(['./03-pattern-matching-helper.py', pub_topic])
                pub.wait()

                publish_recvd = sock.recv(len(publish_packet))

                if mosq_test.packet_matches("publish", publish_recvd, publish_packet):
                    sock.send(unsubscribe_packet)
                    unsuback_recvd = sock.recv(len(unsuback_packet))

                    if mosq_test.packet_matches("unsuback", unsuback_recvd, unsuback_packet):
                        sock.send(subscribe_packet)
                        suback_recvd = sock.recv(len(suback_packet))

                        if mosq_test.packet_matches("suback", suback_recvd, suback_packet):
                            publish_retained_recvd = sock.recv(len(publish_retained_packet))

                            if mosq_test.packet_matches("publish retained", publish_retained_recvd, publish_retained_packet):
                                rc = 0

        sock.close()
    finally:
        broker.terminate()
        broker.wait()
        if rc:
            (stdo, stde) = broker.communicate()
            print(stde)

    return rc
Example #10
0
rc = 1
keepalive = 60
connect_packet = mosq_test.gen_connect("subhier-crash", keepalive=keepalive)
connack_packet = mosq_test.gen_connack(rc=0)

mid = 1
subscribe1_packet = mosq_test.gen_subscribe(mid, "topic/a", 0)
suback1_packet = mosq_test.gen_suback(mid, 0)

mid = 2
subscribe2_packet = mosq_test.gen_subscribe(mid, "topic/b", 0)
suback2_packet = mosq_test.gen_suback(mid, 0)

mid = 3
unsubscribe1_packet = mosq_test.gen_unsubscribe(mid, "topic/a")
unsuback1_packet = mosq_test.gen_unsuback(mid)

disconnect_packet = mosq_test.gen_disconnect()

port = mosq_test.get_port()
broker = mosq_test.start_broker(filename=os.path.basename(__file__), port=port)


def test():
    sock = mosq_test.do_client_connect(connect_packet,
                                       connack_packet,
                                       port=port)
    mosq_test.do_send_receive(sock, subscribe1_packet, suback1_packet,
                              "suback 1")
    mosq_test.do_send_receive(sock, subscribe2_packet, suback2_packet,
                              "suback 2")
Example #11
0
rc = 1
keepalive = 60
connect_packet = mosq_test.gen_connect("subhier-crash", keepalive=keepalive)
connack_packet = mosq_test.gen_connack(rc=0)

mid = 1
subscribe1_packet = mosq_test.gen_subscribe(mid, "topic/a", 0)
suback1_packet = mosq_test.gen_suback(mid, 0)

mid = 2
subscribe2_packet = mosq_test.gen_subscribe(mid, "topic/b", 0)
suback2_packet = mosq_test.gen_suback(mid, 0)

mid = 3
unsubscribe1_packet = mosq_test.gen_unsubscribe(mid, "topic/a")
unsuback1_packet = mosq_test.gen_unsuback(mid)

disconnect_packet = mosq_test.gen_disconnect()


port = mosq_test.get_port()
broker = mosq_test.start_broker(filename=os.path.basename(__file__), port=port)

def test():
    sock = mosq_test.do_client_connect(connect_packet, connack_packet, port=port)
    mosq_test.do_send_receive(sock, subscribe1_packet, suback1_packet, "suback 1")
    mosq_test.do_send_receive(sock, subscribe2_packet, suback2_packet, "suback 2")
    mosq_test.do_send_receive(sock, unsubscribe1_packet, unsuback1_packet, "unsuback")

    sock.send(disconnect_packet)
    sock.close()