Commit 564627ed authored by Ghislain MARY's avatar Ghislain MARY
Browse files

Add some registration tests in Python.

parent afe5abba
......@@ -8,6 +8,7 @@ import sys
import time
test_domain = "sipopen.example.org"
test_username = "liblinphone_tester"
test_password = "secret"
test_route = "sip2.linphone.org"
......
......@@ -18,9 +18,10 @@ class RegisterCoreManager(CoreManager):
vtable['auth_info_requested'] = RegisterCoreManager.auth_info_requested
CoreManager.__init__(self, vtable=vtable)
def register_with_refresh(self, refresh, domain, route, late_auth_info = False, expected_final_state = linphone.RegistrationState.Ok):
def register_with_refresh_base(self, refresh, domain, route, late_auth_info = False, transport = linphone.SipTransports(5070, 5070, 5071, 0), expected_final_state = linphone.RegistrationState.Ok):
assert self.lc is not None
self.stats.reset()
self.lc.sip_transports = transport
proxy_cfg = self.lc.create_proxy_config()
from_address = create_address(domain)
proxy_cfg.identity = from_address.as_string()
......@@ -35,8 +36,6 @@ class RegisterCoreManager(CoreManager):
self.lc.add_proxy_config(proxy_cfg)
self.lc.default_proxy_config = proxy_cfg
#linphone_core_set_sip_transports(lc,&transport);
retry = 0
expected_count = 1
if refresh:
......@@ -69,6 +68,8 @@ class RegisterCoreManager(CoreManager):
else:
assert_equals(self.stats.number_of_LinphoneRegistrationCleared, 0)
def register_with_refresh(self, refresh, domain, route, late_auth_info = False, transport = linphone.SipTransports(5070, 5070, 5071, 0), expected_final_state = linphone.RegistrationState.Ok):
self.register_with_refresh_base(refresh, domain, route, late_auth_info, expected_final_state = expected_final_state)
self.stop()
# Not testable as the callbacks can not be called once the core destruction has started
#assert_equals(self.stats.number_of_LinphoneRegistrationCleared, 1)
......@@ -80,3 +81,67 @@ class TestRegister:
cm = RegisterCoreManager()
cm.register_with_refresh(False, None, None)
assert_equals(cm.stats.number_of_auth_info_requested, 0)
def test_simple_unregister(self):
cm = RegisterCoreManager()
cm.register_with_refresh_base(False, None, None)
pc = cm.lc.default_proxy_config
pc.edit()
cm.stats.reset() # clear stats
# nothing is supposed to arrive until done
assert_equals(CoreManager.wait_for_until(cm, cm, lambda cm1, cm2: cm1.stats.number_of_LinphoneRegistrationCleared == 1, 3000), False)
pc.register_enabled = False
pc.done()
assert_equals(CoreManager.wait_for(cm, cm, lambda cm1, cm2: cm1.stats.number_of_LinphoneRegistrationCleared == 1), True)
def test_simple_tcp_register(self):
cm = RegisterCoreManager()
cm.register_with_refresh(False, test_domain, "sip:{route};transport=tcp".format(route=test_route))
def test_simple_tcp_register_compatibility_mode(self):
cm = RegisterCoreManager()
cm.register_with_refresh(False, test_domain, "sip:{route}".format(route=test_route), transport=linphone.SipTransports(0, 5070, 0, 0))
def test_simple_tls_register(self):
cm = RegisterCoreManager()
cm.register_with_refresh(False, test_domain, "sip:{route};transport=tls".format(route=test_route))
def test_tls_register_with_alt_name(self):
cm = CoreManager('pauline_alt_rc', False)
cm.lc.root_ca = os.path.join(tester_resources_path, 'certificates', 'cn', 'cafile.pem')
cm.lc.refresh_registers()
assert_equals(CoreManager.wait_for(cm, cm, lambda cm1, cm2: cm1.stats.number_of_LinphoneRegistrationOk == 1), True)
assert_equals(cm.stats.number_of_LinphoneRegistrationFailed, 0)
def test_tls_wildcard_register(self):
cm = CoreManager('pauline_wild_rc', False)
cm.lc.root_ca = os.path.join(tester_resources_path, 'certificates', 'cn', 'cafile.pem')
cm.lc.refresh_registers()
assert_equals(CoreManager.wait_for(cm, cm, lambda cm1, cm2: cm1.stats.number_of_LinphoneRegistrationOk == 2), True)
assert_equals(cm.stats.number_of_LinphoneRegistrationFailed, 0)
def test_tls_certificate_failure(self):
cm = CoreManager('pauline_rc', False)
cm.lc.root_ca = os.path.join(tester_resources_path, 'certificates', 'cn', 'agent.pem') # bad root ca
cm.lc.network_reachable = True
assert_equals(CoreManager.wait_for(cm, cm, lambda cm1, cm2: cm1.stats.number_of_LinphoneRegistrationFailed == 1), True)
cm.lc.root_ca = None # no root ca
cm.lc.refresh_registers()
assert_equals(CoreManager.wait_for(cm, cm, lambda cm1, cm2: cm1.stats.number_of_LinphoneRegistrationFailed == 2), True)
cm.lc.root_ca = os.path.join(tester_resources_path, 'certificates', 'cn', 'cafile.pem') # good root ca
cm.lc.refresh_registers()
assert_equals(CoreManager.wait_for(cm, cm, lambda cm1, cm2: cm1.stats.number_of_LinphoneRegistrationOk == 1), True)
assert_equals(cm.stats.number_of_LinphoneRegistrationFailed, 2)
def test_tls_with_non_tls_server(self):
cm = CoreManager('marie_rc', False)
cm.lc.sip_transport_timeout = 3000
pc = cm.lc.default_proxy_config
pc.edit()
addr = linphone.Address.new(pc.server_addr)
port = addr.port
if port <= 0:
port = 5060
pc.server_addr = "sip:{domain}:{port};transport=tls".format(domain=addr.domain, port=port)
pc.done()
assert_equals(CoreManager.wait_for_until(cm, cm, lambda cm1, cm2: cm1.stats.number_of_LinphoneRegistrationFailed == 1, 5000), True)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment