Exemplo n.º 1
0
client_args = sys.argv[1:]
env = dict(os.environ)
env['LD_LIBRARY_PATH'] = '../../lib:../../lib/cpp'
try:
    pp = env['PYTHONPATH']
except KeyError:
    pp = ''
env['PYTHONPATH'] = '../../lib/python:' + pp
client = subprocess.Popen(client_args, env=env)

try:
    (conn, address) = sock.accept()
    conn.settimeout(10)
    connect_recvd = conn.recv(len(connect_packet))

    if mosq_test.packet_matches("connect", connect_recvd, connect_packet):
        conn.send(connack_packet)
        conn.send(publish_packet)
        pubrec_recvd = conn.recv(len(pubrec_packet))

        if mosq_test.packet_matches("pubrec", pubrec_recvd, pubrec_packet):
            # Should be repeated due to timeout
            pubrec_recvd = conn.recv(len(pubrec_packet))
            if mosq_test.packet_matches("pubrec", pubrec_recvd, pubrec_packet):
                conn.send(pubrel_packet)
                pubcomp_recvd = conn.recv(len(pubcomp_packet))
                if mosq_test.packet_matches("pubcomp", pubcomp_recvd,
                                            pubcomp_packet):
                    rc = 0

    conn.close()
Exemplo n.º 2
0
client_args = sys.argv[1:]
env = dict(os.environ)
env['LD_LIBRARY_PATH'] = '../../lib:../../lib/cpp'
try:
    pp = env['PYTHONPATH']
except KeyError:
    pp = ''
env['PYTHONPATH'] = '../../lib/python:'+pp
client = subprocess.Popen(client_args, env=env)

try:
    (conn, address) = sock.accept()
    conn.settimeout(10)
    connect_recvd = conn.recv(len(connect_packet))

    if mosq_test.packet_matches("connect", connect_recvd, connect_packet):
        conn.send(connack_packet)
        subscribe_recvd = conn.recv(len(subscribe_packet))

        if mosq_test.packet_matches("subscribe", subscribe_recvd, subscribe_packet):
            conn.send(suback_packet)
            disconnect_recvd = conn.recv(len(disconnect_packet))
        
            if mosq_test.packet_matches("disconnect", disconnect_recvd, disconnect_packet):
                rc = 0
        
    conn.close()
finally:
    client.terminate()
    client.wait()
    sock.close()
Exemplo n.º 3
0
import subprocess
import socket
import time

import inspect, os, sys
# From http://stackoverflow.com/questions/279237/python-import-a-module-from-a-folder
cmd_subfolder = os.path.realpath(os.path.abspath(os.path.join(os.path.split(inspect.getfile( inspect.currentframe() ))[0],"..")))
if cmd_subfolder not in sys.path:
    sys.path.insert(0, cmd_subfolder)

import mosq_test

rc = 1
keepalive = 60
connect_packet = mosq_test.gen_connect("test-helper", keepalive=keepalive, will_topic="will/qos0/test", will_payload="will-message")
connack_packet = mosq_test.gen_connack(rc=0)

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

if mosq_test.packet_matches("connack", connack_recvd, connack_packet):
    rc = 0

sock.close()
    
exit(rc)

Exemplo n.º 4
0
suback_packet = mosq_test.gen_suback(mid, 0)

publish_packet = mosq_test.gen_publish("will/qos0/test", qos=0, payload=struct.pack("!4sB7s", "will", 0, "message"))

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(30)
    sock.connect(("localhost", 1888))
    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):
            will = subprocess.Popen(['./07-will-null-helper.py'])
            will.wait()

            publish_recvd = sock.recv(len(publish_packet))

            if mosq_test.packet_matches("publish", publish_recvd, publish_packet):
                rc = 0

    sock.close()
finally:
    broker.terminate()
Exemplo n.º 5
0
                                             payload="retained message")
subscribe_packet = mosq_test.gen_subscribe(mid, "retain/qos0/test", 0)
suback_packet = mosq_test.gen_suback(mid, 0)

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.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):
            sock.send(publish_packet)
            publish_recvd = sock.recv(len(publish_fresh_packet))

            if mosq_test.packet_matches("publish", publish_recvd,
                                        publish_fresh_packet):
                rc = 0
    sock.close()
finally:
    broker.terminate()
    broker.wait()
if cmd_subfolder not in sys.path:
    sys.path.insert(0, cmd_subfolder)

import mosq_test

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

mid = 128
publish_packet = mosq_test.gen_publish("bridge/disconnect/test", qos=1, mid=mid, payload="disconnect-message")
puback_packet = mosq_test.gen_puback(mid)

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

if mosq_test.packet_matches("helper connack", connack_recvd, connack_packet):
    sock.send(publish_packet)
    puback_recvd = sock.recv(len(puback_packet))

    if mosq_test.packet_matches("helper puback", puback_recvd, puback_packet):
        rc = 0

sock.close()
    
exit(rc)

client_args = sys.argv[1:]
env = dict(os.environ)
env['LD_LIBRARY_PATH'] = '../../lib:../../lib/cpp'
try:
    pp = env['PYTHONPATH']
except KeyError:
    pp = ''
env['PYTHONPATH'] = '../../lib/python:' + pp
client = subprocess.Popen(client_args, env=env)

try:
    (conn, address) = sock.accept()
    conn.settimeout(5)
    connect_recvd = conn.recv(len(connect_packet))

    if mosq_test.packet_matches("connect", connect_recvd, connect_packet):
        conn.send(connack_packet)
        publish_recvd = conn.recv(len(publish_packet))

        if mosq_test.packet_matches("publish", publish_recvd, publish_packet):
            # Delay for > 3 seconds (message retry time)
            publish_recvd = conn.recv(len(publish_packet_dup))

            if mosq_test.packet_matches("dup publish", publish_recvd,
                                        publish_packet_dup):
                conn.send(puback_packet)
                disconnect_recvd = conn.recv(len(disconnect_packet))

                if mosq_test.packet_matches("disconnect", disconnect_recvd,
                                            disconnect_packet):
                    rc = 0
client_args = sys.argv[1:]
env = dict(os.environ)
env['LD_LIBRARY_PATH'] = '../../lib:../../lib/cpp'
try:
    pp = env['PYTHONPATH']
except KeyError:
    pp = ''
env['PYTHONPATH'] = '../../lib/python:'+pp
client = subprocess.Popen(client_args, env=env)

try:
    (conn, address) = sock.accept()
    conn.settimeout(10)
    connect_recvd = conn.recv(len(connect_packet))

    if mosq_test.packet_matches("connect", connect_recvd, connect_packet):
        conn.send(connack_packet)
        conn.send(publish_packet)
        pubrec_recvd = conn.recv(len(pubrec_packet))

        if mosq_test.packet_matches("pubrec", pubrec_recvd, pubrec_packet):
            # Should be repeated due to timeout
            pubrec_recvd = conn.recv(len(pubrec_packet))
            if mosq_test.packet_matches("pubrec", pubrec_recvd, pubrec_packet):
                conn.send(pubrel_packet)
                pubcomp_recvd = conn.recv(len(pubcomp_packet))
                if mosq_test.packet_matches("pubcomp", pubcomp_recvd, pubcomp_packet):
                    rc = 0

    conn.close()
finally:
Exemplo n.º 9
0
ssock.settimeout(40)
ssock.bind(('', 1888))
ssock.listen(5)

broker = subprocess.Popen(
    ['../../src/mosquitto', '-c', '06-bridge-br2b-disconnect-qos2.conf'],
    stderr=subprocess.PIPE)

try:
    time.sleep(0.5)

    (bridge, address) = ssock.accept()
    bridge.settimeout(10)
    connect_recvd = bridge.recv(len(connect_packet))

    if mosq_test.packet_matches("connect", connect_recvd, connect_packet):
        bridge.send(connack_packet)
        subscribe_recvd = bridge.recv(len(subscribe_packet))
        if mosq_test.packet_matches("subscribe", subscribe_recvd,
                                    subscribe_packet):
            bridge.send(suback_packet)

            pub = subprocess.Popen(
                ['./06-bridge-br2b-disconnect-qos2-helper.py'])
            if pub.wait():
                exit(1)

            publish_recvd = bridge.recv(len(publish_packet))
            if mosq_test.packet_matches("publish", publish_recvd,
                                        publish_packet):
                bridge.close()
Exemplo n.º 10
0
client_args = sys.argv[1:]
env = dict(os.environ)
env['LD_LIBRARY_PATH'] = '../../lib:../../lib/cpp'
try:
    pp = env['PYTHONPATH']
except KeyError:
    pp = ''
env['PYTHONPATH'] = '../../lib/python:' + pp
client = subprocess.Popen(client_args, env=env)

try:
    (conn, address) = sock.accept()
    conn.settimeout(keepalive + 10)
    connect_recvd = conn.recv(len(connect_packet))

    if mosq_test.packet_matches("connect", connect_recvd, connect_packet):
        conn.send(connack_packet)
        pingreq_recvd = conn.recv(len(pingreq_packet))

        if mosq_test.packet_matches("pingreq", pingreq_recvd, pingreq_packet):
            rc = 0

    conn.close()
finally:
    client.terminate()
    client.wait()
    sock.close()

exit(rc)
Exemplo n.º 11
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(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
Exemplo n.º 12
0
client_args = sys.argv[1:]
env = dict(os.environ)
env['LD_LIBRARY_PATH'] = '../../lib:../../lib/cpp'
try:
    pp = env['PYTHONPATH']
except KeyError:
    pp = ''
env['PYTHONPATH'] = '../../lib/python:'+pp
client = subprocess.Popen(client_args, env=env)

try:
    (conn, address) = sock.accept()
    conn.settimeout(10)
    connect_recvd = conn.recv(len(connect_packet))

    if mosq_test.packet_matches("connect", connect_recvd, connect_packet):
        conn.send(connack_packet)
        conn.send(publish_packet)
        puback_recvd = conn.recv(len(puback_packet))

        if mosq_test.packet_matches("puback", puback_recvd, puback_packet):
            rc = 0

    conn.close()
finally:
    for i in range(0, 5):
        if client.returncode != None:
            break
        time.sleep(0.1)

    client.terminate()
Exemplo n.º 13
0
pubrec_packet2 = mosq_test.gen_pubrec(mid)
pubrel_packet2 = mosq_test.gen_pubrel(mid)
pubcomp_packet2 = mosq_test.gen_pubcomp(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(10)
    sock.connect(("localhost", 1888))
    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):
            sock.send(publish_packet)
            pubrec_recvd = sock.recv(len(pubrec_packet))

            if mosq_test.packet_matches("pubrec", pubrec_recvd, pubrec_packet):
                sock.send(pubrel_packet)
                pubcomp_recvd = sock.recv(len(pubcomp_packet))

                if mosq_test.packet_matches("pubcomp", pubcomp_recvd, pubcomp_packet):
                    publish_recvd = sock.recv(len(publish_packet2))

                    if mosq_test.packet_matches("publish2", publish_recvd, publish_packet2):
ssock.settimeout(40)
ssock.bind(('', 1888))
ssock.listen(5)

broker = subprocess.Popen(
    ['../../src/mosquitto', '-c', '06-bridge-b2br-disconnect-qos1.conf'],
    stderr=subprocess.PIPE)

try:
    time.sleep(0.5)

    (bridge, address) = ssock.accept()
    bridge.settimeout(10)
    connect_recvd = bridge.recv(len(connect_packet))

    if mosq_test.packet_matches("connect", connect_recvd, connect_packet):
        bridge.send(connack_packet)
        subscribe_recvd = bridge.recv(len(subscribe_packet))
        if mosq_test.packet_matches("subscribe", subscribe_recvd,
                                    subscribe_packet):
            bridge.send(suback_packet)

            bridge.send(publish_packet)
            # Bridge doesn't have time to respond but should expect us to retry
            # and so remove PUBACK.
            bridge.close()

            (bridge, address) = ssock.accept()
            bridge.settimeout(10)
            connect_recvd = bridge.recv(len(connect_packet))
Exemplo n.º 15
0
broker = subprocess.Popen(
    ['../../src/mosquitto', '-c', '03-publish-b2c-timeout-qos2.conf'],
    stderr=subprocess.PIPE)

try:
    time.sleep(0.5)

    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    sock.settimeout(
        60)  # 60 seconds timeout is much longer than 5 seconds message retry.
    sock.connect(("localhost", 1888))
    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-publish-b2c-timeout-qos2-helper.py'])
            pub.wait()
            # Should have now received a publish command
            publish_recvd = sock.recv(len(publish_packet))

            if mosq_test.packet_matches("publish", publish_recvd,
                                        publish_packet):
                # Wait for longer than 5 seconds to get republish with dup set
                # This is covered by the 8 second timeout
                publish_recvd = sock.recv(len(publish_dup_packet))
Exemplo n.º 16
0
import mosq_test

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

mid = 128
publish_packet = mosq_test.gen_publish("qos1/disconnect/test",
                                       qos=1,
                                       mid=mid,
                                       payload="disconnect-message")
puback_packet = mosq_test.gen_puback(mid)

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

if mosq_test.packet_matches("helper connack", connack_recvd, connack_packet):
    sock.send(publish_packet)
    puback_recvd = sock.recv(len(puback_packet))

    if mosq_test.packet_matches("helper puback", puback_recvd, puback_packet):
        rc = 0

sock.close()

exit(rc)
keepalive = 60
connect_packet = mosq_test.gen_connect("test-helper", keepalive=keepalive)
connack_packet = mosq_test.gen_connack(rc=0)

mid = 312
publish_packet = mosq_test.gen_publish("qos2/timeout/test", qos=2, mid=mid, payload="timeout-message")
pubrec_packet = mosq_test.gen_pubrec(mid)
pubrel_packet = mosq_test.gen_pubrel(mid)
pubcomp_packet = mosq_test.gen_pubcomp(mid)

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

if mosq_test.packet_matches("helper connack", connack_recvd, connack_packet):
    sock.send(publish_packet)
    pubrec_recvd = sock.recv(len(pubrec_packet))

    if mosq_test.packet_matches("helper pubrec", pubrec_recvd, pubrec_packet):
        sock.send(pubrel_packet)
        pubcomp_recvd = sock.recv(len(pubcomp_packet))

        if mosq_test.packet_matches("helper pubcomp", pubcomp_recvd, pubcomp_packet):
            rc = 0

sock.close()

exit(rc)

Exemplo n.º 18
0
client_args = sys.argv[1:]
env = dict(os.environ)
env['LD_LIBRARY_PATH'] = '../../lib:../../lib/cpp'
try:
    pp = env['PYTHONPATH']
except KeyError:
    pp = ''
env['PYTHONPATH'] = '../../lib/python:' + pp
client = subprocess.Popen(client_args, env=env)

try:
    (conn, address) = sock.accept()
    conn.settimeout(10)
    connect_recvd = conn.recv(len(connect_packet))

    if mosq_test.packet_matches("connect", connect_recvd, connect_packet):
        conn.send(connack_packet)
        subscribe_recvd = conn.recv(len(subscribe_packet))

        if mosq_test.packet_matches("subscribe", subscribe_recvd,
                                    subscribe_packet):
            conn.send(suback_packet)
            disconnect_recvd = conn.recv(len(disconnect_packet))

            if mosq_test.packet_matches("disconnect", disconnect_recvd,
                                        disconnect_packet):
                rc = 0

    conn.close()
finally:
    client.terminate()
ssock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
ssock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
ssock.settimeout(40)
ssock.bind(('', 1888))
ssock.listen(5)

broker = subprocess.Popen(['../../src/mosquitto', '-c', '06-bridge-b2br-disconnect-qos2.conf'], stderr=subprocess.PIPE)

try:
    time.sleep(0.5)

    (bridge, address) = ssock.accept()
    bridge.settimeout(10)
    connect_recvd = bridge.recv(len(connect_packet))

    if mosq_test.packet_matches("connect", connect_recvd, connect_packet):
        bridge.send(connack_packet)
        subscribe_recvd = bridge.recv(len(subscribe_packet))
        if mosq_test.packet_matches("subscribe", subscribe_recvd, subscribe_packet):
            bridge.send(suback_packet)

            bridge.send(publish_packet)
            bridge.close()

            (bridge, address) = ssock.accept()
            bridge.settimeout(10)
            connect_recvd = bridge.recv(len(connect_packet))

            if mosq_test.packet_matches("connect", connect_recvd, connect_packet):
                bridge.send(connack_packet)
                subscribe_recvd = bridge.recv(len(subscribe2_packet))
Exemplo n.º 20
0
client_args = sys.argv[1:]
env = dict(os.environ)
env['LD_LIBRARY_PATH'] = '../../lib:../../lib/cpp'
try:
    pp = env['PYTHONPATH']
except KeyError:
    pp = ''
env['PYTHONPATH'] = '../../lib/python:' + pp
client = subprocess.Popen(client_args, env=env)

try:
    (conn, address) = sock.accept()
    conn.settimeout(10)
    connect_recvd = conn.recv(len(connect_packet))

    if mosq_test.packet_matches("connect", connect_recvd, connect_packet):
        conn.send(connack_packet)
        conn.send(publish_packet)
        puback_recvd = conn.recv(len(puback_packet))

        if mosq_test.packet_matches("puback", puback_recvd, puback_packet):
            rc = 0

    conn.close()
finally:
    for i in range(0, 5):
        if client.returncode != None:
            break
        time.sleep(0.1)

    client.terminate()
Exemplo n.º 21
0
client_args = sys.argv[1:]
env = dict(os.environ)
env["LD_LIBRARY_PATH"] = "../../lib:../../lib/cpp"
try:
    pp = env["PYTHONPATH"]
except KeyError:
    pp = ""
env["PYTHONPATH"] = "../../lib/python:" + pp
client = subprocess.Popen(client_args, env=env)

try:
    (conn, address) = sock.accept()
    conn.settimeout(10)
    connect_recvd = conn.recv(len(connect_packet))

    if mosq_test.packet_matches("connect", connect_recvd, connect_packet):
        conn.send(connack_packet)
        publish_recvd = conn.recv(len(publish_packet))

        if mosq_test.packet_matches("publish", publish_recvd, publish_packet):
            disconnect_recvd = conn.recv(len(disconnect_packet))

            if mosq_test.packet_matches("disconnect", disconnect_recvd, disconnect_packet):
                rc = 0

    conn.close()
finally:
    client.terminate()
    client.wait()
    sock.close()
client_args = sys.argv[1:]
env = dict(os.environ)
env['LD_LIBRARY_PATH'] = '../../lib:../../lib/cpp'
try:
    pp = env['PYTHONPATH']
except KeyError:
    pp = ''
env['PYTHONPATH'] = '../../lib/python:' + pp
client = subprocess.Popen(client_args, env=env)

try:
    (conn, address) = sock.accept()
    conn.settimeout(5)
    connect_recvd = conn.recv(len(connect_packet))

    if mosq_test.packet_matches("connect", connect_recvd, connect_packet):
        conn.send(connack_packet)
        publish_recvd = conn.recv(len(publish_packet))

        if mosq_test.packet_matches("publish", publish_recvd, publish_packet):
            # Disconnect client. It should reconnect.
            conn.close()

            (conn, address) = sock.accept()
            conn.settimeout(15)
            connect_recvd = conn.recv(len(connect_packet))

            if mosq_test.packet_matches("connect", connect_recvd,
                                        connect_packet):
                conn.send(connack_packet)
                publish_recvd = conn.recv(len(publish_dup_packet))
client_args = sys.argv[1:]
env = dict(os.environ)
env['LD_LIBRARY_PATH'] = '../../lib:../../lib/cpp'
try:
    pp = env['PYTHONPATH']
except KeyError:
    pp = ''
env['PYTHONPATH'] = '../../lib/python:'+pp
client = subprocess.Popen(client_args, env=env)

try:
    (conn, address) = sock.accept()
    conn.settimeout(keepalive+10)
    connect_recvd = conn.recv(len(connect_packet))

    if mosq_test.packet_matches("connect", connect_recvd, connect_packet):
        conn.send(connack_packet)
        pingreq_recvd = conn.recv(len(pingreq_packet))

        if mosq_test.packet_matches("pingreq", pingreq_recvd, pingreq_packet):
            rc = 0

    conn.close()
finally:
    client.terminate()
    client.wait()
    sock.close()

exit(rc)

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

broker = subprocess.Popen(['../../src/mosquitto', '-c', '06-bridge-br2b-disconnect-qos2.conf'], stderr=subprocess.PIPE)

try:
    time.sleep(0.5)

    (bridge, address) = ssock.accept()
    bridge.settimeout(10)
    connect_recvd = bridge.recv(len(connect_packet))

    if mosq_test.packet_matches("connect", connect_recvd, connect_packet):
        bridge.send(connack_packet)
        subscribe_recvd = bridge.recv(len(subscribe_packet))
        if mosq_test.packet_matches("subscribe", subscribe_recvd, subscribe_packet):
            bridge.send(suback_packet)

            pub = subprocess.Popen(['./06-bridge-br2b-disconnect-qos2-helper.py'])
            if pub.wait():
                exit(1)

            publish_recvd = bridge.recv(len(publish_packet))
            if mosq_test.packet_matches("publish", publish_recvd, publish_packet):
                bridge.close()

                (bridge, address) = ssock.accept()
                bridge.settimeout(10)
Exemplo n.º 25
0
mid = 312
publish_packet = mosq_test.gen_publish("qos2/disconnect/test",
                                       qos=2,
                                       mid=mid,
                                       payload="disconnect-message")
pubrec_packet = mosq_test.gen_pubrec(mid)
pubrel_packet = mosq_test.gen_pubrel(mid)
pubcomp_packet = mosq_test.gen_pubcomp(mid)

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

if mosq_test.packet_matches("helper connack", connack_recvd, connack_packet):
    sock.send(publish_packet)
    pubrec_recvd = sock.recv(32)

    if mosq_test.packet_matches("helper pubrec", pubrec_recvd, pubrec_packet):
        sock.send(pubrel_packet)
        pubcomp_recvd = sock.recv(len(pubcomp_packet))

        if mosq_test.packet_matches("helper pubcomp", pubcomp_recvd,
                                    pubcomp_packet):
            rc = 0

sock.close()

exit(rc)
Exemplo n.º 26
0
sock.settimeout(10)
sock.bind(('', 1888))
sock.listen(5)

client_args = sys.argv[1:]
env = dict(os.environ)
env['LD_LIBRARY_PATH'] = '../../lib:../../lib/cpp'
try:
    pp = env['PYTHONPATH']
except KeyError:
    pp = ''
env['PYTHONPATH'] = '../../lib/python:'+pp
client = subprocess.Popen(client_args, env=env)

try:
    (conn, address) = sock.accept()
    conn.settimeout(10)
    connect_recvd = conn.recv(len(connect_packet))

    if mosq_test.packet_matches("connect", connect_recvd, connect_packet):
        rc = 0

    conn.close()
finally:
    client.terminate()
    client.wait()
    sock.close()

exit(rc)

client_args = sys.argv[1:]
env = dict(os.environ)
env['LD_LIBRARY_PATH'] = '../../lib:../../lib/cpp'
try:
    pp = env['PYTHONPATH']
except KeyError:
    pp = ''
env['PYTHONPATH'] = '../../lib/python:' + pp
client = subprocess.Popen(client_args, env=env)

try:
    (conn, address) = ssock.accept()
    conn.settimeout(10)
    connect_recvd = conn.recv(len(connect_packet))

    if mosq_test.packet_matches("connect", connect_recvd, connect_packet):
        conn.send(connack_packet)
        disconnect_recvd = conn.recv(len(disconnect_packet))

        if mosq_test.packet_matches("disconnect", disconnect_recvd,
                                    disconnect_packet):
            rc = 0

    conn.close()
finally:
    client.terminate()
    client.wait()
    ssock.close()

exit(rc)
ssock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
ssock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
ssock.settimeout(40)
ssock.bind(('', 1888))
ssock.listen(5)

broker = subprocess.Popen(['../../src/mosquitto', '-c', '06-bridge-b2br-disconnect-qos1.conf'], stderr=subprocess.PIPE)

try:
    time.sleep(0.5)

    (bridge, address) = ssock.accept()
    bridge.settimeout(10)
    connect_recvd = bridge.recv(len(connect_packet))

    if mosq_test.packet_matches("connect", connect_recvd, connect_packet):
        bridge.send(connack_packet)
        subscribe_recvd = bridge.recv(len(subscribe_packet))
        if mosq_test.packet_matches("subscribe", subscribe_recvd, subscribe_packet):
            bridge.send(suback_packet)

            bridge.send(publish_packet)
            # Bridge doesn't have time to respond but should expect us to retry
            # and so remove PUBACK.
            bridge.close()

            (bridge, address) = ssock.accept()
            bridge.settimeout(10)
            connect_recvd = bridge.recv(len(connect_packet))

            if mosq_test.packet_matches("connect", connect_recvd, connect_packet):
rc = 1
keepalive = 10
connect_packet = mosq_test.gen_connect("connect-uname-pwd-test", keepalive=keepalive, username="******", password="******")
connack_packet = mosq_test.gen_connack(rc=0)

broker = subprocess.Popen(['../../src/mosquitto', '-c', '09-plugin-auth-unpwd-success.conf'], stderr=subprocess.PIPE)

try:
    time.sleep(0.5)

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

    if mosq_test.packet_matches("connack", connack_recvd, connack_packet):
        rc = 0
finally:
    broker.terminate()
    broker.wait()
    if rc:
        (stdo, stde) = broker.communicate()
        print(stde)


exit(rc)

Exemplo n.º 30
0
pubrel_packet2 = mosq_test.gen_pubrel(mid)
pubcomp_packet2 = mosq_test.gen_pubcomp(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(10)
    sock.connect(("localhost", 1888))
    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):
            sock.send(publish_packet)
            pubrec_recvd = sock.recv(len(pubrec_packet))

            if mosq_test.packet_matches("pubrec", pubrec_recvd, pubrec_packet):
                sock.send(pubrel_packet)
                pubcomp_recvd = sock.recv(len(pubcomp_packet))

                if mosq_test.packet_matches("pubcomp", pubcomp_recvd,
                                            pubcomp_packet):
                    publish_recvd = sock.recv(len(publish_packet2))