Exemple #1
0
def test_self_subscribe(host, port):
    record = [
        Frame(send=True,
              data=Connect(client_id="test_selfsub",
                           flags=ConnectFlags(clean_session=True))),
        Frame(send=False, data=ConnACK(session_present=False, return_code=0)),
        Frame(send=True,
              data=Subscribe(
                  packet_identifier=1234,
                  topic_requests=[SubscriptionTopicRequest("foo", 2)])),
        Frame(send=False,
              data=SubACK(packet_identifier=1234, return_codes=[2])),
        Frame(send=True,
              data=Publish(duplicate=False,
                           qos_level=0,
                           topic_name="foo",
                           payload=b"abc",
                           retain=False)),
        Frame(send=False,
              data=Publish(duplicate=False,
                           qos_level=0,
                           topic_name="foo",
                           payload=b"abc",
                           retain=False)),
        Frame(send=True, data=Disconnect()),
        ConnectionLoss(),
    ]

    r = SelectReactor()
    f = ReplayClientFactory(r, record)
    e = TCP4ClientEndpoint(r, host, port)
    e.connect(f)
    r.run()

    return Result("self_subscribe", f.success, f.reason, f.client_transcript)
Exemple #2
0
def test_qos1_send_wrong_confirm(host, port):
    record = [
        Frame(
            send=True,
            data=Connect(client_id=u"test_wrong_confirm_qos1",
                         flags=ConnectFlags(clean_session=True))),
        Frame(
            send=False,
            data=ConnACK(session_present=False, return_code=0)),
        Frame(
            send=True,
            data=Subscribe(packet_identifier=1234,
                           topic_requests=[SubscriptionTopicRequest(u"foo", 2)])),
        Frame(
            send=False,
            data=SubACK(packet_identifier=1234, return_codes=[2])),
        Frame(
            send=True,
            data=Publish(duplicate=False, qos_level=1, topic_name=u"foo",
                         payload=b"abc", retain=False, packet_identifier=12)),
        Frame(
            send=False,
            data=[
                PubACK(packet_identifier=12),
                Publish(duplicate=False, qos_level=1, topic_name=u"foo",
                        payload=b"abc", retain=False, packet_identifier=1)]),
        # We send a pubrel to the packet_id expecting a puback
        Frame(
            send=True,
            data=PubREL(packet_identifier=1)),
        # ..aaaaand we get a pubcomp back (even though mosquitto warns).
        Frame(
            send=False,
            data=PubCOMP(packet_identifier=1)),
        Frame(
            send=True,
            data=Disconnect()),
        ConnectionLoss(),
    ]

    r = SelectReactor()
    f = ReplayClientFactory(r, record)
    e = TCP4ClientEndpoint(r, host, port)
    e.connect(f)
    r.run()

    return Result("qos1_wrong_confirm", f.success, f.reason, f.client_transcript)