コード例 #1
0
def test_optional_rule_matching_OPEN_CLOSE_CONNECTION():
    client_messages = make_messages("C:protocol-header",
                                    "C:connection.start-ok",
                                    "C:connection.tune-ok",
                                    "C:connection.open",
                                    "C:connection.close")
    server_messages = make_messages("S:connection.start",
                                    "S:connection.tune",
                                    "S:connection.open-ok",
                                    "S:connection.close-ok")
    protocol_analyzer = ProtocolDetective(client_messages, server_messages)

    protocol_analyzer._analyze_protocol_part("protocol")
    result = protocol_analyzer.processed_messages

    assert len(result) == 9
    assert result == make_messages("C:protocol-header",
                                   "S:connection.start",
                                   "C:connection.start-ok",
                                   "S:connection.tune",
                                   "C:connection.tune-ok",
                                   "C:connection.open",
                                   "S:connection.open-ok",
                                   "C:connection.close",
                                   "S:connection.close-ok"
                                   )
    assert all([not message.out_of_order for message in result])
コード例 #2
0
def test_atomic_rule_matching_DELIVER():
    client_messages = []
    server_messages = make_messages("S:basic.deliver",
                                    "S:BODY")
    protocol_analyzer = ProtocolDetective(client_messages, server_messages)

    protocol_analyzer._analyze_protocol_part("deliver")
    result = protocol_analyzer.processed_messages

    assert len(result) == 2
    assert result == make_messages("S:basic.deliver", "S:BODY")
    assert all([not message.out_of_order for message in result])
コード例 #3
0
def test_atomic_rule_matching_SINGLE_CHALLENGE_EXCHANGE():
    client_messages = make_messages("C:connection.secure-ok")
    server_messages = make_messages("S:connection.secure")
    protocol_analyzer = ProtocolDetective(client_messages, server_messages)

    protocol_analyzer._analyze_protocol_part("challenge")
    result = protocol_analyzer.processed_messages

    assert len(result) == 2
    assert result == make_messages("S:connection.secure",
                                   "C:connection.secure-ok")
    assert all([not message.out_of_order for message in result])
コード例 #4
0
def test_atomic_rule_matching_PUBLISH():
    client_messages = make_messages("C:basic.publish",
                                    "C:HEADER",
                                    "C:BODY")
    server_messages = []
    protocol_analyzer = ProtocolDetective(client_messages, server_messages)

    protocol_analyzer._analyze_protocol_part("publish")
    result = protocol_analyzer.processed_messages

    assert len(result) == 3
    assert result == make_messages("C:basic.publish",
                                   "C:HEADER",
                                   "C:BODY")
    assert all([not message.out_of_order for message in result])
コード例 #5
0
def test_atomic_rule_matching_SINGLE_CHALLENGE_EXCHANGE_ignore_heartbeats():
    client_messages = make_messages("C:HEARTBEAT", "C:connection.secure-ok")
    server_messages = make_messages("S:HEARTBEAT", "S:connection.secure")
    protocol_analyzer = ProtocolDetective(client_messages, server_messages)

    protocol_analyzer._analyze_protocol_part("challenge")
    result = protocol_analyzer.processed_messages

    assert len(result) == 4
    for message in make_messages("S:HEARTBEAT",
                                 "C:HEARTBEAT",
                                 "S:connection.secure",
                                 "C:connection.secure-ok"):
        assert message in result  # heartbeat frames could be anywhere in between
    server_request = get_message("S:connection.secure")
    client_response = get_message("C:connection.secure-ok")
    assert result.index(server_request) < result.index(client_response), \
        "Server request should have been before client response: %s" % result
    assert all([not message.out_of_order for message in result])
コード例 #6
0
def test_alternative_rule_matching_CLOSE_CONNECTION():
    # test client initiated close
    client_messages = make_messages("C:connection.close")
    server_messages = make_messages("S:connection.close-ok")
    protocol_analyzer = ProtocolDetective(client_messages, server_messages)

    protocol_analyzer._analyze_protocol_part("close-connection")
    result = protocol_analyzer.processed_messages

    assert len(result) == 2
    assert result == make_messages("C:connection.close",
                                   "S:connection.close-ok")
    assert all([not message.out_of_order for message in result])

    # test server initiated close
    client_messages = make_messages("C:connection.close-ok")
    server_messages = make_messages("S:connection.close")
    protocol_analyzer = ProtocolDetective(client_messages, server_messages)

    protocol_analyzer._analyze_protocol_part("close-connection")
    result = protocol_analyzer.processed_messages

    assert len(result) == 2
    assert result == make_messages("S:connection.close",
                                   "C:connection.close-ok")
    assert all([not message.out_of_order for message in result])
コード例 #7
0
def test_repetitive_rule_matching_CHANNEL():
    client_messages = make_messages("C:channel.open",
                                    "C:channel.flow",
                                    "C:basic.consume",
                                    "C:basic.publish",
                                    "C:HEADER",
                                    "C:BODY",
                                    "C:basic.ack",
                                    "C:channel.close")
    server_messages = make_messages("S:channel.open-ok",
                                    "S:channel.flow-ok",
                                    "S:basic.consume-ok",
                                    "S:basic.ack",
                                    "S:basic.ack",
                                    "S:basic.ack",
                                    "S:channel.close-ok")

    protocol_analyzer = ProtocolDetective(client_messages, server_messages)

    protocol_analyzer._analyze_protocol_part("channel")
    result = protocol_analyzer.processed_messages

    assert len(result) == 15
    assert result == make_messages("C:channel.open",
                                   "S:channel.open-ok",
                                   "C:channel.flow",
                                   "S:channel.flow-ok",
                                   "C:basic.consume",
                                   "S:basic.consume-ok",
                                   "C:basic.publish",
                                   "S:basic.ack",
                                   "C:HEADER",
                                   "S:basic.ack",
                                   "C:BODY",
                                   "S:basic.ack",
                                   "C:basic.ack",
                                   "C:channel.close",
                                   "S:channel.close-ok")
    assert all([not message.out_of_order for message in result])