def test_set_param_received_ipv6(): via = ViaHeader( 'SIP/2.0/TCP 192.168.1.1:5090;branch=branch_v;ttl=200;received=1.1.1.1;maddr=x.com' ) via.set_param(PARAM_RECEIVED, '[::1]') assert via.assemble( ) == 'SIP/2.0/TCP 192.168.1.1:5090;branch=branch_v;ttl=200;received=[::1];maddr=x.com' assert via.received == ipaddress.IPv6Address('::1') via = ViaHeader( 'SIP/2.0/TCP 192.168.1.1:5090;branch=branch_v;ttl=200;received=1.1.1.1;maddr=x.com' ) via.set_param(PARAM_RECEIVED, ipaddress.IPv6Address('::1')) assert via.assemble( ) == 'SIP/2.0/TCP 192.168.1.1:5090;branch=branch_v;ttl=200;received=[::1];maddr=x.com' assert via.received == ipaddress.IPv6Address('::1')
def test_set_rport_to_true(): via = ViaHeader( 'SIP/2.0/TCP 192.168.1.1:5090;branch=branch_v;ttl=200;rport=1234;maddr=x.com' ) via.set_param(PARAM_RPORT, True) assert via.assemble( ) == 'SIP/2.0/TCP 192.168.1.1:5090;branch=branch_v;ttl=200;rport;maddr=x.com' assert via.rport is True
def check_via_match(self, via): if self.check_via_match_address(via) and self.check_via_match_transport(via): return ViaMatchResult(result=ViaMatchResult.MATCH) else: expected = ViaHeader() expected.sent_by = SentBy(host=self.local_addr, port=self.local_port) expected.sent_protocol = SentProtocol(transport=self.transport, version='2.0', name='SIP') expected_str = expected.assemble() actual_str = via.assemble() return ViaMatchResult(result=ViaMatchResult.MISMATCH, expected=expected_str, actual=actual_str)
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