def test_102(self): c = MqttClient("conformity:{seq}") sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) try: sock.connect(('127.0.0.1', 1883)) sock.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1) sock.setblocking(0) except Exception as e: debug(e) return False c._c.sock = sock c.forge( NC.CMD_CONNECT, 0, [ ('string', 'MqTt'), ('byte', NC.PROTOCOL_VERSION_4), ('string', 'ff') # client id ], send=True) try: c.send_pingreq() c._c.sock.getpeername() except socket.error as e: return True debug("connection still alive") return False
def test_020(self): c = MqttClient("cs:{seq}", connect=4, clean_session=0) c.subscribe("/cs/topic1/+", qos=2) c.disconnect() pub = MqttClient("pub:{seq}", connect=4) pubmsgs = { "/cs/topic1/q0": [0, env.gen_msg(42)], "/cs/topic1/q1": [1, env.gen_msg(42)], "/cs/topic1/q2": [2, env.gen_msg(42)], } for (topic, (qos, msg)) in pubmsgs.iteritems(): ack = pub.publish(topic, msg, qos=qos) if qos == 2: pub.pubrel(ack.mid) pub.disconnect() msgs = env.db.lrange("queue:" + c.clientid(), 0, -1) for (topic, qos, msgid) in [msgs[i:i + 3] for i in range(0, len(msgs), 3)]: content = env.db.get("msg:" + msgid) origin = pubmsgs.get(topic, [-1, ""]) #print topic, origin, qos, content if int(qos) != origin[0] or content != origin[1]: debug("{0}: {1}, {2}".format(origin, qos, content)) return False return True
def test_109(self): c = MqttClient("conformity:{seq}") sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) try: sock.connect(('127.0.0.1', 1883)) sock.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1) sock.setblocking(0) except Exception as e: debug(e) return False c._c.sock = sock pkt = MqttPkt() pkt.command = NC.CMD_CONNECT pkt.remaining_length = 12 + 26 # client_id = "ff" pkt.alloc() pkt.write_string("MQTT") pkt.write_byte(NC.PROTOCOL_VERSION_4) pkt.write_byte(0) # flags pkt.write_uint16(10) # keepalive pkt.write_string("ABCDEFGHIJKLMNOPQRSTUVWXYZ") # client id - 26 chars c._c.packet_queue(pkt) c._c.packet_write() c._c.loop() if c.conn_is_alive(): debug("connection still alive") return False return True
def test_108(self): c = MqttClient("conformity:{seq}") sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) try: sock.connect(('127.0.0.1', 1883)) sock.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1) sock.setblocking(0) except Exception as e: debug(e) return False c._c.sock = sock c.forge(NC.CMD_CONNECT, 0, [ ('string', 'MQTT'), ('byte' , NC.PROTOCOL_VERSION_4), ('byte' , 0), # flags ('uint16', 10), # keepalive ('string', '') # client id ], send=True) evt = c._c.pop_event() if not isinstance(evt, EventConnack) or evt.ret_code != 2: debug(evt); return False return True
def test_251(self): tfs = [ ("+", True), ("/+", True), ("+/", True), ("+/foo", True), ("/foo/+", True), ("/foo/+/", True), ("/foo/+/bar", True), ("+/foo/bar", True), ("foo+", False), ("foo+/bar", False), ("+foo/bar", False), ("foo/+bar", False), # ~ ("++", False), ("foo/++/bar", False), ] for (tf, isvalid) in tfs: sub = MqttClient("conformity:{seq}", connect=4) sub.subscribe(tf, qos=0, read_response=False) ack = sub.recv() if (isvalid and not isinstance(ack, EventSuback)) or \ (not isvalid and (ack is not None or sub.conn_is_alive())): debug("{0}: {1} ({2})".format(tf, ack, sub.conn_is_alive())) return False sub.disconnect() return True
def test_003(self): sub = MqttClient("sub:{seq}", connect=4) sub.subscribe('a/b', qos=1) pub = MqttClient("pub:{seq}", connect=4) msg = gen_msg() pub.publish('a/b', payload=msg, qos=1) pub.recv() e = sub.recv() if not isinstance(e, EventPublish) or \ e.msg.payload != msg or \ e.msg.qos != 1: debug('failing event: {0}'.format(e)) return False # send PUBACK sub.puback(e.msg.mid) puback_evt = pub.recv() # PUBACK mid == PUBLISH mid # validating [MQTT-2.3.1-6] if not isinstance(puback_evt, EventPuback) or \ puback_evt.mid != pub.get_last_mid(): debug('failing event: {0}'.format(puback_evt)) return False sub.unsubscribe('a/b') sub.disconnect(); pub.disconnect() return True
def test_202(self): pub = MqttClient("conformity-pub:{seq}", connect=4) sub = MqttClient("conformity-sub:{seq}", connect=4) sub.subscribe("foo/bar", qos=2) pub.publish("foo/bar", "wootwoot", qos=2, read_response=False) # PUB PUBREC evt = pub.recv() # sending PUBREL with wrong pktid pub.forge(NC.CMD_PUBREL, 2, [ ('uint16', (evt.mid+10)%65535) # wrong pktid ], send=True) # subscriber: PUBLISH never received evt = sub.recv() if evt is not None: debug(evt) return False evt = pub.recv() # publisher: PUBCOMP never received if evt is not None: debug(evt) return False pub.disconnect(); sub.disconnect() return True
def test_203(self): pub = MqttClient("conformity-pub:{seq}", connect=4) sub = MqttClient("conformity-sub:{seq}", connect=4) sub.subscribe("foo/bar", qos=2) pub.publish("foo/bar", "wootwoot", qos=2, read_response=False) # PUB PUBREC evt = pub.recv() pub.pubrel(pub.get_last_mid(), read_response=False) # subscr: receiving PUBLISH evt = sub.recv() sub.pubrec(evt.msg.mid, read_response=False) # subscr: receiving PUBREL evt = sub.recv() # sending PUBCOMP with wrong pktid sub.forge(NC.CMD_PUBCOMP, 0, [ ('uint16', (evt.mid+10)%65535) # wrong pktid ], send=True) evt = pub.recv() # publisher: PUBCOMP never received if evt is not None: debug(evt) return False pub.disconnect(); sub.disconnect() return True
def test_003(self): sub = MqttClient("sub:{seq}", connect=4) sub.subscribe('a/b', qos=2) pub = MqttClient("pub:{seq}", connect=4) msg = gen_msg() pub.publish('a/b', payload=msg, qos=1) e = sub.recv() if not isinstance(e, EventPublish) or \ e.msg.payload != msg or \ e.msg.qos != 1: debug('received event (supposely publish): {0}'.format(e)) return False # send PUBACK sub.puback(e.msg.mid) e2 = pub.recv() if not isinstance(e2, EventPuback) or \ e2.mid != pub.get_last_mid(): debug('received event (supposely puback): {0}'.format(e2)) return False sub.unsubscribe('a/b') sub.disconnect(); pub.disconnect() return True
def test_013(self): pub = MqttClient("conformity:{seq}", connect=4) sub = MqttClient("sub:{seq}", connect=4) sub.subscribe("/test/022/013/+", qos=2) pub.publish("/test/022/013/t1", 'hurry', retain=True, qos=1) msg = sub.recv() if not isinstance(msg, EventPublish) or \ msg.msg.topic != '/test/022/013/t1' or \ msg.msg.payload != 'hurry' or\ msg.msg.qos != 1 or\ msg.msg.retain: debug(msg) return False # same with empty payload pub.publish("/test/022/013/t2", 'up', retain=True, qos=2) pub.pubrel(pub.get_last_mid()) msg = sub.recv() if not isinstance(msg, EventPublish) or \ msg.msg.topic != '/test/022/013/t2' or \ msg.msg.payload != "up" or\ msg.msg.qos != 2 or\ msg.msg.retain: debug(msg) return False return True
def test_012(self): pub = MqttClient("conformity:{seq}", connect=4) sub = MqttClient("sub:{seq}", connect=4) sub.subscribe("/retain/+", qos=0) pub.publish("/retain/delivered", 'waze', retain=True) msg = sub.recv() if not isinstance(msg, EventPublish) or \ msg.msg.topic != '/retain/delivered' or \ msg.msg.payload != 'waze' or\ msg.msg.retain: debug(msg) return False # same with empty payload pub.publish("/retain/empty", '', retain=True) msg = sub.recv() if not isinstance(msg, EventPublish) or \ msg.msg.topic != '/retain/empty' or \ msg.msg.payload != None or\ msg.msg.retain: debug(msg) return False pub.disconnect() sub.disconnect() return True
def test_005(self): c = MqttClient( "reg:{seq}", ssl=True, ssl_opts={ 'ssl_version': SSL_VERSION, 'cert_reqs': ssl.CERT_REQUIRED, 'ca_certs': os.path.join(os.path.dirname(__file__), "../../", "etc/wave_cert.pem"), #'ciphers': 'HIGH:!DHE:!ECDHE' 'ciphers': 'AES256-SHA' }) evt = c.connect() debug("Using SSL: version={0}, cipher={1}".format( version(c._c.sock), c._c.sock.cipher())) if not isinstance(evt, EventConnack): return False c.disconnect() return True
def test_102(self): c = MqttClient("conformity:{seq}") sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) try: sock.connect(('127.0.0.1', 1883)) sock.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1) sock.setblocking(0) except Exception as e: debug(e) return False c._c.sock = sock c.forge(NC.CMD_CONNECT, 0, [ ('string', 'MqTt'), ('byte' , NC.PROTOCOL_VERSION_4), ('string', 'ff') # client id ], send=True) try: c.send_pingreq() c._c.sock.getpeername() except socket.error as e: return True debug("connection still alive") return False
def test_003(self): monitor = MqttClient("monitor:{seq}", connect=4) # NOTE: '/' prefix skips $ messages # TODO: remove it when '$' filter will be impl. monitor.subscribe("/#", qos=0) client = MqttClient("rabbit:{seq}", keepalive=2) will = {'topic': '/node/disconnect', 'message': client.clientid()} client.connect(version=4, will=will) time.sleep(1) client.send_pingreq() evt = monitor.recv() if monitor.recv() != None: debug(evt) return False time.sleep(4) evt = monitor.recv() if not isinstance(evt, EventPublish) or evt.msg.topic != will['topic'] or \ evt.msg.payload != will['message']: debug(evt) return False monitor.disconnect() return True
def test_021(self): """ throwing "anonymous" exception on binary pattern matching (mqtt_msg:decode_connect2()) """ client = MqttClient("rabbit:{seq}", raw_connect=True) client.forge(NC.CMD_CONNECT, 0, [ ('string', 'MQTT'), ('byte' , 4), # protocol level ('byte' , 4), # will=1 ('uint16', 60), # keepalive ('string', client._c.client_id), ('string', '/will/topic'), # will-topic ], send=True) if client.conn_is_alive(): debug("connection still alive") return False client = MqttClient("rabbit:{seq}", raw_connect=True) client.forge(NC.CMD_CONNECT, 0, [ ('string', 'MQTT'), ('byte' , 4), # protocol level ('byte' , 4), # will=1 ('uint16', 60), # keepalive ('string', client._c.client_id), ('string', '/will/topic'), # will-topic ('uint16', 4), # 4 bytes msg, BUT not message following ], send=True) if client.conn_is_alive(): debug("connection still alive") return False return True
def test_251(self): tfs = [ ("+" , True), ("/+" , True), ("+/" , True), ("+/foo" , True), ("/foo/+" , True), ("/foo/+/" , True), ("/foo/+/bar", True), ("+/foo/bar" , True), ("foo+" , False), ("foo+/bar" , False), ("+foo/bar" , False), ("foo/+bar" , False), # ~ ("++" , False), ("foo/++/bar", False), ] for (tf, isvalid) in tfs: sub = MqttClient("conformity:{seq}", connect=4) sub.subscribe(tf, qos=0, read_response=False) ack = sub.recv() if (isvalid and not isinstance(ack, EventSuback)) or \ (not isvalid and (ack is not None or sub.conn_is_alive())): debug("{0}: {1} ({2})".format(tf, ack, sub.conn_is_alive())) return False sub.disconnect() return True
def test_112(self): ## PINGREG c = MqttClient("conformity:{seq}", raw_connect=True) evt = c.connect(version=4) # flags shoud be 0 c.forge(NC.CMD_PINGREQ, 4, [], send=True) if c.conn_is_alive(): debug("connection still alive") return False ## SUBSCRIBE c = MqttClient("conformity2:{seq}", raw_connect=True) evt = c.connect(version=4) # flags shoud be 2 c.forge( NC.CMD_SUBSCRIBE, 3, [ ('uint16', 42), # identifier ('string', '/foo/bar'), # topic filter ('byte', 0) # qos ], send=True) if c.conn_is_alive(): debug("connection still alive") return False return True
def test_030(self): retain = MqttClient("retain:{seq}", connect=4) sub = MqttClient("subscr:{seq}", connect=4) msg = {'topic': "baby/ma/ma", 'payload': "The mother of your child(ren)", 'retain': True, 'qos': 1} retain.publish(**msg) sub.subscribe("baby/ma/+", qos=1, read_response=False) pubevt = None while True: evt = sub.recv() if isinstance(evt, EventSuback): continue if isinstance(evt, EventPublish) and\ evt.msg.qos == 1 and\ evt.msg.retain and\ evt.msg.topic == msg['topic'] and\ evt.msg.payload == msg['payload']: pubevt = evt; continue break if pubevt is None: debug("message not received") return False sub.puback(mid=pubevt.msg.mid) retain.disconnect(); sub.disconnect() return True
def test_105(self): c = MqttClient("conformity:{seq}") sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) try: sock.connect(('127.0.0.1', 1883)) sock.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1) sock.setblocking(0) except Exception as e: debug(e) return False c._c.sock = sock ret = c.forge( NC.CMD_CONNECT, 0, [ ('string', 'MQTT'), ('byte', NC.PROTOCOL_VERSION_4), ('byte', 1 << 6), # set password flag ('uint16', 60), # keepalive ('string', 'ff') # client id ], send=True) if ret != NC.ERR_CONN_LOST: debug("invalid error code: {0}".format(ret)) return False return True
def test_007(self): tmp = tempfile.mktemp(prefix='wave-testsuite-') subprocess.Popen("echo \"bar\"|../bin/mkpasswd -c {0} foo".format(tmp), shell=True, stdout=subprocess.PIPE).wait() yield app.set_auth(required=True, filename=tmp) yield auth.switch(tmp) c = MqttClient("auth:{seq}", connect=False, username="******", password="******") ret = c.connect(version=4) # auth rejected if not isinstance(ret, EventConnack) or ret.ret_code == 0: debug(ret) defer.returnValue(False) # updating password subprocess.Popen("echo \"baz\"|../bin/mkpasswd {0} foo".format(tmp), shell=True, stdout=subprocess.PIPE).wait() # file is monitored each 2 secs in debug context time.sleep(3) ret = c.connect(version=4) # auth accepted if not isinstance(ret, EventConnack) or ret.ret_code != 0: debug(ret) defer.returnValue(False) defer.returnValue(True)
def test_020(self): retain = MqttClient("retain:{seq}", connect=4) sub = MqttClient("subscriber:{seq}", connect=4) topic = "/woot/wo/ot" msg = "expression of simplistic ecstasy" retain.publish(topic, msg, retain=True) # exact match topic sub.subscribe("/woot/wo/ot", qos=0, read_response=False) while True: evt = sub.recv() if isinstance(evt, EventSuback): acked = True continue # receiving retained message if isinstance(evt, EventPublish) and\ evt.msg.topic == topic and\ evt.msg.payload == msg and\ evt.msg.retain: pubevt = evt continue break if not acked: debug("not acked") return False if pubevt is None: debug("message not received") return False return True
def test_203(self): pub = MqttClient("conformity-pub:{seq}", connect=4) sub = MqttClient("conformity-sub:{seq}", connect=4) sub.subscribe("foo/bar", qos=2) pub.publish("foo/bar", "wootwoot", qos=2, read_response=False) # PUB PUBREC evt = pub.recv() pub.pubrel(pub.get_last_mid(), read_response=False) # subscr: receiving PUBLISH evt = sub.recv() sub.pubrec(evt.msg.mid, read_response=False) # subscr: receiving PUBREL evt = sub.recv() # sending PUBCOMP with wrong pktid sub.forge( NC.CMD_PUBCOMP, 0, [('uint16', (evt.mid + 10) % 65535) # wrong pktid ], send=True) evt = pub.recv() # publisher: PUBCOMP never received if evt is not None: debug(evt) return False pub.disconnect() sub.disconnect() return True
def test_007(self): tmp = tempfile.mktemp(prefix='wave-testsuite-') subprocess.Popen("echo \"bar\"|../bin/mkpasswd -c {0} foo".format(tmp), shell=True, stdout=subprocess.PIPE).wait() yield app.set_auth(required= True, filename= tmp) yield auth.switch(tmp) c = MqttClient("auth:{seq}", connect=False, username="******", password="******") ret = c.connect(version=4) # auth rejected if not isinstance(ret, EventConnack) or ret.ret_code == 0: debug(ret) defer.returnValue(False) # updating password subprocess.Popen("echo \"baz\"|../bin/mkpasswd {0} foo".format(tmp), shell=True, stdout=subprocess.PIPE).wait() # file is monitored each 2 secs in debug context time.sleep(3) ret = c.connect(version=4) # auth accepted if not isinstance(ret, EventConnack) or ret.ret_code != 0: debug(ret) defer.returnValue(False) defer.returnValue(True)
def test_110(self): sub = MqttClient("unisub:{seq}", connect=4) pub = MqttClient("unipub:{seq}", connect=4) evt = sub.subscribe(u"ᛋᚳᛖᚪᛚ/+/ᚦᛖᚪᚻ", qos=0) if not isinstance(evt, EventSuback) or \ evt.mid != sub.get_last_mid(): debug(evt) return False topic = u"ᛋᚳᛖᚪᛚ/䑓/ᚦᛖᚪᚻ" content = u"На берегу пустынных волн" evt = pub.publish(topic, payload=content, qos=0) evt = sub.recv() if not isinstance(evt, EventPublish) or\ evt.msg.topic != topic: debug(evt) return false content2 = evt.msg.payload.decode('utf8') if content2 != content: debugt("payload differs: {0} != {1}".format(content, content2)) return False sub.disconnect() pub.disconnect() return True
def test_012(self): monitor = MqttClient("monitor:{seq}", connect=4) # NOTE: '/' prefix skips $ messages # TODO: remove it when '$' filter will be impl. monitor.subscribe("/#", qos=2) client = MqttClient("rabbit:{seq}") # no keepalive will = { 'topic': '/node/disconnect', 'message': client.clientid(), 'retain': True } client.connect(version=4, will=will) client.socket_close() evt = monitor.recv() if not isinstance(evt, EventPublish) or evt.msg.topic != will['topic'] or \ evt.msg.payload != will['message'] or \ evt.msg.qos != 0: debug(evt) return False if not evt.msg.retain: debug("evt remain flag set") return False monitor.disconnect() return True
def test_112(self): ## PINGREG c = MqttClient("conformity:{seq}", raw_connect=True) evt = c.connect(version=4) # flags shoud be 0 c.forge(NC.CMD_PINGREQ, 4, [], send=True) if c.conn_is_alive(): debug("connection still alive") return False ## SUBSCRIBE c = MqttClient("conformity2:{seq}", raw_connect=True) evt = c.connect(version=4) # flags shoud be 2 c.forge(NC.CMD_SUBSCRIBE, 3, [ ('uint16', 42), # identifier ('string', '/foo/bar'), # topic filter ('byte' , 0) # qos ], send=True) if c.conn_is_alive(): debug("connection still alive") return False return True
def test_012(self): pub = MqttClient("conformity:{seq}", connect=4) sub = MqttClient("sub:{seq}", connect=4) sub.subscribe("/retain/+", qos=0) pub.publish("/retain/delivered", 'waze', retain=True) msg = sub.recv() if not isinstance(msg, EventPublish) or \ msg.msg.topic != '/retain/delivered' or \ msg.msg.payload != 'waze' or\ msg.msg.retain: debug(msg) return False # same with empty payload pub.publish("/retain/empty", '', retain=True) msg = sub.recv() if not isinstance(msg, EventPublish) or \ msg.msg.topic != '/retain/empty' or \ msg.msg.payload != None or\ msg.msg.retain: debug(msg) return False pub.disconnect(); sub.disconnect() return True
def test_105(self): c = MqttClient("conformity:{seq}") sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) try: sock.connect(('127.0.0.1', 1883)) sock.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1) sock.setblocking(0) except Exception as e: debug(e) return False c._c.sock = sock ret = c.forge(NC.CMD_CONNECT, 0, [ ('string', 'MQTT'), ('byte' , NC.PROTOCOL_VERSION_4), ('byte' , 1 << 6), # set password flag ('uint16', 60), # keepalive ('string', 'ff') # client id ], send=True) if ret != NC.ERR_CONN_LOST: debug("invalid error code: {0}".format(ret)) return False return True
def test_200(self): pub = MqttClient("conformity-pub:{seq}", connect=4) sub = MqttClient("conformity-sub:{seq}", connect=4) sub.subscribe("foo/bar", qos=1) pub.publish("foo/bar", "wootwoot", qos=1) # reading PUBLISH evt = sub.recv() # sending PUBACK with wrong pktid sub.forge( NC.CMD_PUBACK, 0, [('uint16', (evt.msg.mid + 10) % 65535) # wrong pktid ], send=True) evt = pub.recv() # PUBACK from server is never received if evt is not None: debug(evt) return False pub.disconnect() sub.disconnect() return True
def test_108(self): c = MqttClient("conformity:{seq}") sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) try: sock.connect(('127.0.0.1', 1883)) sock.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1) sock.setblocking(0) except Exception as e: debug(e) return False c._c.sock = sock c.forge( NC.CMD_CONNECT, 0, [ ('string', 'MQTT'), ('byte', NC.PROTOCOL_VERSION_4), ('byte', 0), # flags ('uint16', 10), # keepalive ('string', '') # client id ], send=True) evt = c._c.pop_event() if not isinstance(evt, EventConnack) or evt.ret_code != 2: debug(evt) return False return True
def test_022(self): retain = MqttClient("retain:{seq}", connect=4) sub = MqttClient("subscriber:{seq}", connect=4) topic = "/woot/wo/ot"; msg = "expression of simplistic ecstasy" retain.publish(topic, msg, retain=True) # wildcard match topic sub.subscribe("/woot/#", qos=0, read_response=False) acked = False; pubevt = None while True: evt = sub.recv() if isinstance(evt, EventSuback): acked = True; continue # receiving retained message if isinstance(evt, EventPublish) and\ evt.msg.topic == topic and\ evt.msg.payload == msg and\ evt.msg.retain: pubevt = evt; continue break if not acked: debug("not acked") return False if pubevt is None: debug("message not received") return False retain.disconnect(); sub.disconnect() return True
def test_008(self): client = MqttClient("rabbit:{seq}", raw_connect=True) client.forge(NC.CMD_CONNECT, 0, [ ('string', 'MQTT'), ('byte' , 4), # protocol level ('byte' , 28), # will=1, will-qos=3 ('uint16', 60), # keepalive ], send=True) if client.conn_is_alive(): debug("connection still alive") return False client = MqttClient("rabbit:{seq}", raw_connect=True) client.forge(NC.CMD_CONNECT, 0, [ ('string', 'MQTT'), ('byte' , 4), # protocol level ('byte' , 12), # will=1, will-qos=1 ('uint16', 60), # keepalive ('string', client._c.client_id), # clientid ('string', '/foo/bar'),# will topic ('uint16', 0), # will payload len ('bytes' , ''), # will payload ], send=True) evt = client.recv() if not isinstance(evt, EventConnack): debug(evt) return False client.disconnect() return True
def test_221(self): c = MqttClient("conformity:{seq}", connect=4) ack = c.unsubscribe("foo/bar") if not isinstance(ack, EventUnsuback): debug(ack) return False return True
def test_223(self): c = MqttClient("conformity-sub:{seq}", connect=4) c.disconnect() if c.conn_is_alive(): debug("connection still alive") return False return True
def test_010(self): cli = MqttClient("ws:{seq}", port=8884, websocket=True, ssl=True, ssl_opts={'ssl_version': SSL_VERSION}) evt = cli.connect(version=4) if not isinstance(evt, EventConnack): debug(evt) return False cli.disconnect() return True
def test_270(self): pub = MqttClient("luser:{seq}", connect=4) pub.publish("$foo/bar", "test1") if pub.conn_is_alive(): debug("connection still alive") return False return True
def test_023(self): retain = MqttClient("retain:{seq}", connect=4) sub = MqttClient("subscr:{seq}", connect=4) # matching topics rs = { # match "dead/bea/t k/id/s": { 'topic': "dead/bea/t k/id/s", 'payload': "children that just aren't worth supporting", 'retain': True }, # match "dead/abe/t k/id/s": { 'topic': "dead/abe/t k/id/s", 'payload': "just children that aren't supporting worth", 'retain': True }, } for args in rs.values(): retain.publish(**args) # no match nors = { 'topic': "dead/be/a/t k/ids", 'payload': "children that just aren't worth supporting", 'retain': True } retain.publish(**nors) #NOTE: we must receive BOTH rs message, but NOT nors one #NOTE: PUBLISH messages MAY arrived BEFORE PUBACK sub.subscribe("dead/+/t k/#", qos=0, read_response=False) count = 0 while True: evt = sub.recv() if evt is None: break if isinstance(evt, EventSuback): continue if not isinstance(evt, EventPublish) or\ not evt.msg.retain or\ evt.msg.topic not in rs: debug(evt) return False count += 1 if count != len(rs): debug("not received enough messages") return False retain.disconnect() sub.disconnect() return True
def test_010(self): c = MqttClient("v311:{seq}", connect=4) evt = c.subscribe("/foo/bar", qos=0) c.disconnect() if not isinstance(evt, EventSuback): debug(evt) return False return True
def test_001(self): sub = MqttClient("sub:{seq}", connect=4) suback_evt = sub.subscribe('foo/bar', qos=1) if not isinstance(suback_evt, EventSuback) or \ suback_evt.mid != sub.get_last_mid() or \ suback_evt.granted_qos[0] != 1: debug('failing event: {0}'.format(suback_evt)) return False return True
def test_001(self): """ > exometer_report:list_reporters(). [{exometer_report_statsd,<0.143.0>}] """ reporters = yield exometer.reporters() if 'exometer_report_statsd' not in reporters: debug(reporters); defer.returnValue(False) defer.returnValue(True)
def test_222(self): sub = MqttClient("conformity-sub:{seq}", connect=4) ack = sub.unsubscribe_multi(["foo/bar", "bar/baz", "paper/+/scissor"]) if not isinstance(ack, EventUnsuback) or ack.mid != sub.get_last_mid(): debug(ack) return False sub.disconnect() return True
def test_002(self): yield app.set_auth(required=True) c = MqttClient("auth:{seq}", connect=False) ret = c.connect(version=4) if isinstance(ret, EventConnack) and ret.ret_code == 4: defer.returnValue(True) debug(ret) defer.returnValue(False)
def test_001(self): c = MqttClient("reg:{seq}", ssl=True, ssl_opts={'ssl_version': SSL_VERSION}) evt = c.connect() debug("Using SSL: version={0}, cipher={1}".format(version(c._c.sock), c._c.sock.cipher())) if not isinstance(evt, EventConnack): return False c.disconnect() return True
def test_001(self): c = MqttClient("v311:{seq}") evt = c.connect(version=4) if not isinstance(evt, EventConnack) or \ evt.ret_code: debug(evt) return False return True
def test_001(self): sub = MqttClient("sub:{seq}", connect=4) suback_evt = sub.subscribe('foo/bar', 2) if not isinstance(suback_evt, EventSuback) or \ suback_evt.mid != sub.get_last_mid() or \ suback_evt.granted_qos[0] != 2: debug(suback_evt) return False return True
def test_011(self): c = MqttClient("v311:{seq}", connect=4) e = c.publish("/foo/bar", payload="plop") # QOS = 0 : no response indented if e is not None: debug(e) c.disconnect() return False c.disconnect() return True
def test_003(self): tmp = tempfile.mktemp(prefix='wave-testsuite-') yield app.set_auth(required=True, filename=tmp); yield auth.switch(tmp) c = MqttClient("auth:{seq}", connect=False) ret = c.connect(version=4) if isinstance(ret, EventConnack) and ret.ret_code == 4: defer.returnValue(True) debug(ret) defer.returnValue(False)