|
| 1 | +# Copyright (c) 2025 Sippy Software, Inc. All rights reserved. |
| 2 | +# |
| 3 | +# All rights reserved. |
| 4 | +# |
| 5 | +# Redistribution and use in source and binary forms, with or without modification, |
| 6 | +# are permitted provided that the following conditions are met: |
| 7 | +# |
| 8 | +# 1. Redistributions of source code must retain the above copyright notice, this |
| 9 | +# list of conditions and the following disclaimer. |
| 10 | +# |
| 11 | +# 2. Redistributions in binary form must reproduce the above copyright notice, |
| 12 | +# this list of conditions and the following disclaimer in the documentation and/or |
| 13 | +# other materials provided with the distribution. |
| 14 | +# |
| 15 | +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
| 16 | +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 17 | +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 18 | +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR |
| 19 | +# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 20 | +# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 21 | +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON |
| 22 | +# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 23 | +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 24 | +# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 25 | + |
| 26 | +from .reinv_frombob import a_test_reinv_frombob, b_test_reinv_frombob |
| 27 | +from .TExceptions import ScenarioFailure |
| 28 | + |
| 29 | +from sippy.SipAddress import SipAddress |
| 30 | +from sippy.SipContact import SipContact |
| 31 | +from sippy.SipURL import SipURL |
| 32 | +from sippy.UA import UA |
| 33 | + |
| 34 | + |
| 35 | +class _ReinviteTrackingUA(UA): |
| 36 | + """UA variant that keeps the R-URI of inbound in-dialog INVITEs.""" |
| 37 | + |
| 38 | + def recvRequest(self, req, *args, **kwargs): |
| 39 | + if req.getMethod() == 'INVITE': |
| 40 | + self.last_in_dialog_invite_ruri = str(req.getRURI()) |
| 41 | + return super(_ReinviteTrackingUA, self).recvRequest(req, *args, **kwargs) |
| 42 | + |
| 43 | +class a_test_nated_contact(a_test_reinv_frombob): |
| 44 | + cld = 'bob_nated_contact' |
| 45 | + cli = 'alice_nated_contact' |
| 46 | + name = f'{a_test_reinv_frombob.name}: NATed Contact preserved on re-INVITE' |
| 47 | + compact_sip = False |
| 48 | + nat_contact_ip = '192.168.255.10' |
| 49 | + nat_contact_port = 5090 |
| 50 | + |
| 51 | + def build_ua(self, tccfg): |
| 52 | + uaO = super(a_test_nated_contact, self).build_ua(tccfg, UA_class=_ReinviteTrackingUA) |
| 53 | + nat_contact = self._build_nat_contact() |
| 54 | + uaO.lContact = nat_contact |
| 55 | + self.expected_contact_uri = str(nat_contact.getUrl()) |
| 56 | + return uaO |
| 57 | + |
| 58 | + def _build_nat_contact(self): |
| 59 | + nat_url = SipURL(username = self.cli, host = self.nat_contact_ip, |
| 60 | + port = self.nat_contact_port) |
| 61 | + nat_address = SipAddress(url = nat_url) |
| 62 | + return SipContact(address = nat_address) |
| 63 | + |
| 64 | + def on_reinvite_connected(self, ua): |
| 65 | + super(a_test_nated_contact, self).on_reinvite_connected(ua) |
| 66 | + ruri = getattr(ua, 'last_in_dialog_invite_ruri', None) |
| 67 | + if ruri != self.expected_contact_uri: |
| 68 | + self.nerrs += 1 |
| 69 | + raise ScenarioFailure('%s: expected re-INVITE R-URI %s, got %s' % |
| 70 | + (self.failed_msg(), self.expected_contact_uri, ruri)) |
| 71 | + |
| 72 | +class b_test_nated_contact(b_test_reinv_frombob): |
| 73 | + cli = a_test_nated_contact.cld |
| 74 | + name = a_test_nated_contact.name |
0 commit comments