[asterisk-commits] wdoekes: testsuite/asterisk/trunk r2852 - in /asterisk/trunk: lib/python/aste...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Sun Dec 4 03:30:19 CST 2011
Author: wdoekes
Date: Sun Dec 4 03:30:13 2011
New Revision: 2852
URL: http://svnview.digium.com/svn/testsuite?view=rev&rev=2852
Log:
Add tests for allowexternaldomains=no and registering with domain-only names.
Review: https://reviewboard.asterisk.org/r/1606/
Added:
asterisk/trunk/tests/channels/SIP/sip_register_domain_acl/
asterisk/trunk/tests/channels/SIP/sip_register_domain_acl/configs/
asterisk/trunk/tests/channels/SIP/sip_register_domain_acl/configs/ast1/
asterisk/trunk/tests/channels/SIP/sip_register_domain_acl/configs/ast1/sip.conf (with props)
asterisk/trunk/tests/channels/SIP/sip_register_domain_acl/run-test (with props)
asterisk/trunk/tests/channels/SIP/sip_register_domain_acl/sipp/
asterisk/trunk/tests/channels/SIP/sip_register_domain_acl/sipp/reg200.xml (with props)
asterisk/trunk/tests/channels/SIP/sip_register_domain_acl/sipp/reg403.xml (with props)
asterisk/trunk/tests/channels/SIP/sip_register_domain_acl/sipp/reg404.xml (with props)
asterisk/trunk/tests/channels/SIP/sip_register_domain_acl/test-config.yaml (with props)
Modified:
asterisk/trunk/lib/python/asterisk/sipp.py
asterisk/trunk/tests/channels/SIP/tests.yaml
Modified: asterisk/trunk/lib/python/asterisk/sipp.py
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/lib/python/asterisk/sipp.py?view=diff&rev=2852&r1=2851&r2=2852
==============================================================================
--- asterisk/trunk/lib/python/asterisk/sipp.py (original)
+++ asterisk/trunk/lib/python/asterisk/sipp.py Sun Dec 4 03:30:13 2011
@@ -30,7 +30,7 @@
when a SIPp scenario must be integrated with a more complex test (using the TestCase
class, for example)
"""
- def __init__(self, test_dir, scenario):
+ def __init__(self, test_dir, scenario, positional_args=()):
"""
Arguments:
@@ -38,8 +38,8 @@
scenario - a SIPp scenario to execute. The scenario should
be a dictionary with the key 'scenario' being the filename
- of the SIPp scneario. Any other key-value pairs are treated as arguments
- to SIPp. For example, specity '-timeout' : '60s' to set the
+ of the SIPp scenario. Any other key-value pairs are treated as arguments
+ to SIPp. For example, specify '-timeout' : '60s' to set the
timeout option to SIPp to 60 seconds. If a parameter specified
is also one specified by default, the value provided will be used.
The default SIPp parameters include:
@@ -50,8 +50,15 @@
-i 127.0.0.1 - Use this as the local IP address for the Contact
headers, Via headers, etc.
-timeout 20s - Set a global test timeout of 20 seconds.
+
+ positional_args - certain SIPp parameters can be specified multiple
+ times, or take multiple arguments. Supply those through this iterable.
+ The canonical example being -key:
+ ('-key', 'extra_via_param', ';rport',
+ '-key', 'user_addr', 'sip:myname at myhost')
"""
self.scenario = scenario
+ self.positional_args = tuple(positional_args) # don't allow caller to mangle his own list
self.test_dir = test_dir
self.default_port = 5061
self.sipp = None
@@ -78,6 +85,7 @@
for (key, val) in default_args.items():
sipp_args.extend([ key, val ])
+ sipp_args.extend(self.positional_args)
logger.info("Executing SIPp scenario: %s" % self.scenario['scenario'])
logger.info(sipp_args)
Added: asterisk/trunk/tests/channels/SIP/sip_register_domain_acl/configs/ast1/sip.conf
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/channels/SIP/sip_register_domain_acl/configs/ast1/sip.conf?view=auto&rev=2852
==============================================================================
--- asterisk/trunk/tests/channels/SIP/sip_register_domain_acl/configs/ast1/sip.conf (added)
+++ asterisk/trunk/tests/channels/SIP/sip_register_domain_acl/configs/ast1/sip.conf Sun Dec 4 03:30:13 2011
@@ -1,0 +1,24 @@
+[general]
+bindaddr=127.0.0.1
+; no guests, or the tests fail
+allowguest=no
+; we expect 403 on bad user, not 404
+alwaysauthreject=yes
+
+; we only allow regs from the right domain
+allowexternaldomains=no
+autodomain=no
+domain=mydom.com
+domain=mydom2.com
+
+; normal someuser at domain
+[someuser]
+type=friend
+host=dynamic
+secret=somesecret
+
+; special domain-as-username matching
+[mydom.com]
+type=friend
+host=dynamic
+secret=mysecret
Propchange: asterisk/trunk/tests/channels/SIP/sip_register_domain_acl/configs/ast1/sip.conf
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: asterisk/trunk/tests/channels/SIP/sip_register_domain_acl/configs/ast1/sip.conf
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Propchange: asterisk/trunk/tests/channels/SIP/sip_register_domain_acl/configs/ast1/sip.conf
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: asterisk/trunk/tests/channels/SIP/sip_register_domain_acl/run-test
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/channels/SIP/sip_register_domain_acl/run-test?view=auto&rev=2852
==============================================================================
--- asterisk/trunk/tests/channels/SIP/sip_register_domain_acl/run-test (added)
+++ asterisk/trunk/tests/channels/SIP/sip_register_domain_acl/run-test Sun Dec 4 03:30:13 2011
@@ -1,0 +1,106 @@
+#!/usr/bin/env python
+'''
+Copyright (C) 2011, Digium, Inc.
+Walter Doekes <walter+asterisk at wjd.nu>
+
+This program is free software, distributed under the terms of
+the GNU General Public License Version 2.
+'''
+
+import sys
+import os
+import logging
+
+sys.path.append("lib/python")
+
+from asterisk.TestCase import TestCase
+from asterisk.sipp import SIPpScenario
+from twisted.internet import reactor
+from starpy import manager
+
+TEST_DIR = os.path.dirname(os.path.realpath(__file__))
+logger = logging.getLogger(__name__)
+
+SCENARIO_TABLE = (
+ ('USER', 'SECRET', 'USERADDR', 'RESP'),
+
+ ('baduser', 'badsecret', 'baduser at mydom.com', 403), # authreject
+ ('baduser', 'badsecret', 'baduser at 127.0.0.1', 403), # bad both
+
+ ('someuser', 'somesecret', 'someuser at mydom.com', 200), # ok
+ ('someuser', 'badsecret', 'someuser at mydom.com', 403), # bad pass
+ ('someuser', 'somesecret', 'someuser at mydom2.com', 200), # ok
+ ('someuser', 'somesecret', 'someuser at mydom3.com', 403), # bad domain
+ ('someuser', 'somesecret', 'someuser@', 404), # bad sip
+ ('someuser', 'somesecret', '@someuser', 403), # bad dom/sip
+
+ ('mydom.com', 'mysecret', 'mydom.com at mydom.com', 200), # ok
+ ('mydom.com', 'mysecret', 'mydom.com at mydom2.com', 200), # ok
+ ('mydom.com', 'mysecret', 'mydom.com', 200), # ok(!)
+ ('mydom.com', 'mysecret', 'mydom.com@', 404), # not ok
+ #('mydom.com', 'mysecret', '@mydom.com', 200), # ok(BAH!)
+)
+
+class SIPRegisterDomainAclTest(TestCase):
+ def __init__(self):
+ super(SIPRegisterDomainAclTest, self).__init__()
+
+ # Transform SCENARIO_TABLE into something usable. Use different
+ # ports so the answers won't conflict with each other.
+ scenario_head = dict(enumerate(SCENARIO_TABLE[0]))
+ scenario_list_of_dicts = []
+ for scenario in SCENARIO_TABLE[1:]:
+ scenario_list_of_dicts.append(
+ dict((scenario_head[i], v) for i, v in enumerate(scenario))
+ )
+ # Into a tuple of (scenario{}, positional_args())
+ self.scenario_defs = []
+ for i, scenario in enumerate(scenario_list_of_dicts):
+ self.scenario_defs.append(({
+ 'scenario': 'reg%d.xml' % scenario['RESP'],
+ '-p': str(5061 + i),
+ '-s': scenario['USER'],
+ '-ap': scenario['SECRET'],
+ '-timeout': '8s',
+ }, (
+ '-key', 'useraddr', scenario['USERADDR'],
+ )))
+
+ self.passed = False
+ self.create_asterisk()
+
+ def run(self):
+ super(SIPRegisterDomainAclTest, self).run()
+ self.create_ami_factory()
+
+ def ami_connect(self, ami):
+ super(SIPRegisterDomainAclTest, self).ami_connect(ami)
+
+ logger.debug("Connected to AMI")
+ passed = True
+ for scenario_def in self.scenario_defs:
+ scenario = SIPpScenario(TEST_DIR, scenario_def[0], scenario_def[1])
+ scenario.run()
+ if scenario.waitAndEvaluate() == False:
+ passed = False
+
+ # All done
+ self.passed = passed
+ self.stop_reactor()
+
+
+def main():
+ test = SIPRegisterDomainAclTest()
+ test.start_asterisk()
+ reactor.run()
+ test.stop_asterisk()
+ if test.passed:
+ return 0
+ return 1
+
+
+if __name__ == "__main__":
+ sys.exit(main())
+
+
+# vim:ts=8:sw=4:sts=4:expandtab:textwidth=79
Propchange: asterisk/trunk/tests/channels/SIP/sip_register_domain_acl/run-test
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: asterisk/trunk/tests/channels/SIP/sip_register_domain_acl/run-test
------------------------------------------------------------------------------
svn:executable = *
Propchange: asterisk/trunk/tests/channels/SIP/sip_register_domain_acl/run-test
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Propchange: asterisk/trunk/tests/channels/SIP/sip_register_domain_acl/run-test
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: asterisk/trunk/tests/channels/SIP/sip_register_domain_acl/sipp/reg200.xml
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/channels/SIP/sip_register_domain_acl/sipp/reg200.xml?view=auto&rev=2852
==============================================================================
--- asterisk/trunk/tests/channels/SIP/sip_register_domain_acl/sipp/reg200.xml (added)
+++ asterisk/trunk/tests/channels/SIP/sip_register_domain_acl/sipp/reg200.xml Sun Dec 4 03:30:13 2011
@@ -1,0 +1,51 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE scenario SYSTEM "sipp.dtd">
+
+<scenario name="Basic REGISTER, Walter Doekes 2011, with custom register useraddr">
+ <label id="register"/>
+
+ <send retrans="500">
+ <![CDATA[
+
+ REGISTER sip:[remote_ip]:[remote_port] SIP/2.0
+ Via: SIP/2.0/[transport] [local_ip]:[local_port];branch=[branch]
+ From: <sip:[useraddr]>;tag=[pid]SIPpTag00[call_number]
+ To: <sip:[useraddr]>
+ Contact: <sip:[service]@[local_ip]:[local_port];transport=[transport]>
+ Expires: 15
+ Call-ID: [call_id]
+ CSeq: 1 REGISTER
+ Content-Length: 0
+
+ ]]>
+ </send>
+
+ <recv response="200" optional="true" next="register-done"/>
+
+ <recv response="401" optional="true" next="register-with-auth" auth="true"/>
+
+ <recv response="407" auth="true"/>
+
+ <label id="register-with-auth"/>
+
+ <send retrans="500">
+ <![CDATA[
+
+ REGISTER sip:[remote_ip]:[remote_port] SIP/2.0
+ Via: SIP/2.0/[transport] [local_ip]:[local_port];branch=[branch]
+ From: <sip:[useraddr]>;tag=[pid]SIPpTag00[call_number]
+ To: <sip:[useraddr]>
+ Contact: <sip:[service]@[local_ip]:[local_port];transport=[transport]>
+ Expires: 15
+ [authentication]
+ Call-ID: [call_id]
+ CSeq: 2 REGISTER
+ Content-Length: 0
+
+ ]]>
+ </send>
+
+ <recv response="200"/>
+
+ <label id="register-done"/>
+</scenario><!-- vim: set ts=8 sw=2 sts=2 et ai: -->
Propchange: asterisk/trunk/tests/channels/SIP/sip_register_domain_acl/sipp/reg200.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: asterisk/trunk/tests/channels/SIP/sip_register_domain_acl/sipp/reg200.xml
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Propchange: asterisk/trunk/tests/channels/SIP/sip_register_domain_acl/sipp/reg200.xml
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: asterisk/trunk/tests/channels/SIP/sip_register_domain_acl/sipp/reg403.xml
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/channels/SIP/sip_register_domain_acl/sipp/reg403.xml?view=auto&rev=2852
==============================================================================
--- asterisk/trunk/tests/channels/SIP/sip_register_domain_acl/sipp/reg403.xml (added)
+++ asterisk/trunk/tests/channels/SIP/sip_register_domain_acl/sipp/reg403.xml Sun Dec 4 03:30:13 2011
@@ -1,0 +1,51 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE scenario SYSTEM "sipp.dtd">
+
+<scenario name="Basic REGISTER, Walter Doekes 2011, with custom register useraddr">
+ <label id="register"/>
+
+ <send retrans="500">
+ <![CDATA[
+
+ REGISTER sip:[remote_ip]:[remote_port] SIP/2.0
+ Via: SIP/2.0/[transport] [local_ip]:[local_port];branch=[branch]
+ From: <sip:[useraddr]>;tag=[pid]SIPpTag00[call_number]
+ To: <sip:[useraddr]>
+ Contact: <sip:[service]@[local_ip]:[local_port];transport=[transport]>
+ Expires: 15
+ Call-ID: [call_id]
+ CSeq: 1 REGISTER
+ Content-Length: 0
+
+ ]]>
+ </send>
+
+ <recv response="403" optional="true" next="register-done"/>
+
+ <recv response="401" optional="true" next="register-with-auth" auth="true"/>
+
+ <recv response="407" auth="true"/>
+
+ <label id="register-with-auth"/>
+
+ <send retrans="500">
+ <![CDATA[
+
+ REGISTER sip:[remote_ip]:[remote_port] SIP/2.0
+ Via: SIP/2.0/[transport] [local_ip]:[local_port];branch=[branch]
+ From: <sip:[useraddr]>;tag=[pid]SIPpTag00[call_number]
+ To: <sip:[useraddr]>
+ Contact: <sip:[service]@[local_ip]:[local_port];transport=[transport]>
+ Expires: 15
+ [authentication]
+ Call-ID: [call_id]
+ CSeq: 2 REGISTER
+ Content-Length: 0
+
+ ]]>
+ </send>
+
+ <recv response="403"/>
+
+ <label id="register-done"/>
+</scenario><!-- vim: set ts=8 sw=2 sts=2 et ai: -->
Propchange: asterisk/trunk/tests/channels/SIP/sip_register_domain_acl/sipp/reg403.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: asterisk/trunk/tests/channels/SIP/sip_register_domain_acl/sipp/reg403.xml
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Propchange: asterisk/trunk/tests/channels/SIP/sip_register_domain_acl/sipp/reg403.xml
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: asterisk/trunk/tests/channels/SIP/sip_register_domain_acl/sipp/reg404.xml
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/channels/SIP/sip_register_domain_acl/sipp/reg404.xml?view=auto&rev=2852
==============================================================================
--- asterisk/trunk/tests/channels/SIP/sip_register_domain_acl/sipp/reg404.xml (added)
+++ asterisk/trunk/tests/channels/SIP/sip_register_domain_acl/sipp/reg404.xml Sun Dec 4 03:30:13 2011
@@ -1,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE scenario SYSTEM "sipp.dtd">
+
+<scenario name="Basic REGISTER, Walter Doekes 2011, with custom register useraddr">
+ <label id="register"/>
+
+ <send retrans="500">
+ <![CDATA[
+
+ REGISTER sip:[remote_ip]:[remote_port] SIP/2.0
+ Via: SIP/2.0/[transport] [local_ip]:[local_port];branch=[branch]
+ From: <sip:[useraddr]>;tag=[pid]SIPpTag00[call_number]
+ To: <sip:[useraddr]>
+ Contact: <sip:[service]@[local_ip]:[local_port];transport=[transport]>
+ Expires: 15
+ Call-ID: [call_id]
+ CSeq: 1 REGISTER
+ Content-Length: 0
+
+ ]]>
+ </send>
+
+ <recv response="404"/>
+</scenario><!-- vim: set ts=8 sw=2 sts=2 et ai: -->
Propchange: asterisk/trunk/tests/channels/SIP/sip_register_domain_acl/sipp/reg404.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: asterisk/trunk/tests/channels/SIP/sip_register_domain_acl/sipp/reg404.xml
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Propchange: asterisk/trunk/tests/channels/SIP/sip_register_domain_acl/sipp/reg404.xml
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: asterisk/trunk/tests/channels/SIP/sip_register_domain_acl/test-config.yaml
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/channels/SIP/sip_register_domain_acl/test-config.yaml?view=auto&rev=2852
==============================================================================
--- asterisk/trunk/tests/channels/SIP/sip_register_domain_acl/test-config.yaml (added)
+++ asterisk/trunk/tests/channels/SIP/sip_register_domain_acl/test-config.yaml Sun Dec 4 03:30:13 2011
@@ -1,0 +1,11 @@
+testinfo:
+ summary: 'Test SIP registration for non-local domains'
+ description: |
+ 'Make sure that allowexternaldomains works properly'
+properties:
+ minversion: '1.8'
+ dependencies:
+ - python: 'twisted'
+ - sipp:
+ version: 'v3.1'
+ feature: 'TLS'
Propchange: asterisk/trunk/tests/channels/SIP/sip_register_domain_acl/test-config.yaml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: asterisk/trunk/tests/channels/SIP/sip_register_domain_acl/test-config.yaml
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Propchange: asterisk/trunk/tests/channels/SIP/sip_register_domain_acl/test-config.yaml
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: asterisk/trunk/tests/channels/SIP/tests.yaml
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/channels/SIP/tests.yaml?view=diff&rev=2852&r1=2851&r2=2852
==============================================================================
--- asterisk/trunk/tests/channels/SIP/tests.yaml (original)
+++ asterisk/trunk/tests/channels/SIP/tests.yaml Sun Dec 4 03:30:13 2011
@@ -13,6 +13,7 @@
- test: 'sip_one_legged_transfer'
- test: 'sip_one_legged_transfer_v6'
- test: 'sip_register'
+ - test: 'sip_register_domain_acl'
- test: 'sip_channel_params'
- test: 'sip_tls_call'
# - test: 'sip_srtp'
More information about the asterisk-commits
mailing list