Esempio n. 1
0
def check_received(remote_ip, msg, conn):
    x, new_request = conn.connection_data(msg)
    assert isinstance(new_request, NewRequest)
    new_msg = new_request.message
    via_hdr = new_msg.get('via')
    via = ViaHeader.topmost_via(via_hdr)
    assert remote_ip == via.received
Esempio n. 2
0
def test_via_params_ipv6():
    hdr = Header('Via')
    hdr.add_value(
        "SIP/2.0/TCP 192.168.1.1:5090;branch=branch_v;ttl=200;received=[::1];maddr=[::1]"
    )
    via = ViaHeader.topmost_via(hdr)
    assert via.received == ipaddress.IPv6Address('::1')
    assert via.maddr == ipaddress.IPv6Address('::1')
Esempio n. 3
0
def test_topmost_via():
    hdr = Header('Via')
    hdr.add_values([
        "SIP/2.0/UDP bigbox3.site3.atlanta.com;branch=z9hG4bK77ef4c2312983.1",
        "SIP/2.0/UDP pc33.atlanta.com;branch=z9hG4bK776asdhds"
    ])
    via = ViaHeader.topmost_via(hdr)
    assert SentProtocol('SIP', '2.0', Transport('UDP')) == via.sent_protocol
    assert 'bigbox3.site3.atlanta.com' == via.sent_by.host
    assert 5060 == via.sent_by.port
Esempio n. 4
0
def test_via_params_2():
    hdr = Header('Via')
    hdr.add_value(
        "SIP/2.0/TCP 192.168.1.1:5090;branch=branch_v;ttl=200;received=1.1.1.1;maddr=x.com"
    )
    via = ViaHeader.topmost_via(hdr)
    assert via.branch == Branch('branch_v')
    assert via.ttl == 200
    assert via.received == ipaddress.IPv4Address('1.1.1.1')
    assert via.maddr == 'x.com'
Esempio n. 5
0
def test_topmost_via_ipport():
    hdr = Header('via')
    hdr.add_values([
        "SIP/2.0/TCP 192.168.1.1:5090;branch=z9hG4bK77ef4c2312983.1",
        "SIP/2.0/UDP bigbox3.site3.atlanta.com;branch=z9hG4bK77ef4c2312983.1",
        "SIP/2.0/UDP pc33.atlanta.com;branch=z9hG4bK776asdhds"
    ])
    via = ViaHeader.topmost_via(hdr)
    assert SentProtocol('SIP', '2.0', Transport('TCP')) == via.sent_protocol
    assert ipaddress.IPv4Address('192.168.1.1') == via.sent_by.host
    assert 5090 == via.sent_by.port
Esempio n. 6
0
 def receive_request_process_via(self, msg):
     print(f'StatelessProxy.receive_request_process_via()')
     via_hdr = msg.get(VIA_HEADER)
     print(f'StatelessProxy.receive_request_process_via(): via header {via_hdr}')
     via = ViaHeader.topmost_via(via_hdr)
     print(f'StatelessProxy.receive_request_process_via(): topmost via {via}')
     self.maybe_add_received(via)
     print(f'StatelessProxy.receive_request_process_via(): via with received {via}')
     self.maybe_fill_rport(via)
     print(f'StatelessProxy.receive_request_process_via(): via with rport {via}')
     via_hdr.replace_topmost(via.assemble())
     print(f'StatelessProxy.receive_request_process_via(): via with replaced topmost {via_hdr}')
     msg.set_header(via_hdr)
Esempio n. 7
0
def test_topmost_via_with_spaces():
    hdr = Header('Via')
    hdr.add_value(
        'SIP / 2.0 / UDP first.example.com: 4000;ttl=16 ;maddr=224.2.0.1 ;branch=z9hG4bKa7c6a8dlze.1'
    )
    via = ViaHeader.topmost_via(hdr)
    assert via.sent_protocol.name == 'SIP'
    assert via.sent_protocol.version == '2.0'
    assert via.sent_protocol.transport == Transport('UDP')
    assert via.branch == Branch('z9hG4bKa7c6a8dlze.1')
    assert via.maddr == ipaddress.IPv4Address('224.2.0.1')
    assert via.ttl == 16
    assert via.sent_by.host == 'first.example.com'
    assert via.sent_by.port == 4000
Esempio n. 8
0
def test_via_gen_params():
    hdr = Header('Via')
    hdr.add_value('SIP/2.0/TCP 192.168.1.1:5090;branch=branch_v;my_param=abc')
    via = ViaHeader.topmost_via(hdr)
    assert via.get_raw_param('my_param') == 'abc'
Esempio n. 9
0
def test_assemble(via_str):
    via1 = ViaHeader(via_str)
    hdr = Header('Via')
    hdr.add_value(via1.assemble())
    via2 = ViaHeader.topmost_via(hdr)
    assert via1 == via2
Esempio n. 10
0
def check_no_received(msg, conn):
    x, new_request = conn.connection_data(msg)
    via_hdr = new_request.message.get('via')
    via = ViaHeader.topmost_via(via_hdr)
    assert via.received is None
Esempio n. 11
0
def check_rport(remote_port, msg, conn):
    x, new_request = conn.connection_data(msg)
    via_hdr = new_request.message.get('via')
    via = ViaHeader.topmost_via(via_hdr)
    assert remote_port == via.rport