[svn-commits] dlee: testsuite/asterisk/trunk r3879 - in /asterisk/trunk: lib/python/asteris...
SVN commits to the Digium repositories
svn-commits at lists.digium.com
Wed Jul 3 11:36:34 CDT 2013
Author: dlee
Date: Wed Jul 3 11:36:32 2013
New Revision: 3879
URL: http://svnview.digium.com/svn/testsuite?view=rev&rev=3879
Log:
Tests for ARI authentication.
Updated existing continue test to account for related changes.
Added:
asterisk/trunk/tests/rest_api/authentication/
- copied from r3878, asterisk/team/dlee/ari-authn/tests/rest_api/authentication/
Modified:
asterisk/trunk/lib/python/asterisk/ari.py
asterisk/trunk/tests/rest_api/continue/configs/ast1/stasis_http.conf
asterisk/trunk/tests/rest_api/tests.yaml
Modified: asterisk/trunk/lib/python/asterisk/ari.py
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/lib/python/asterisk/ari.py?view=diff&rev=3879&r1=3878&r2=3879
==============================================================================
--- asterisk/trunk/lib/python/asterisk/ari.py (original)
+++ asterisk/trunk/lib/python/asterisk/ari.py Wed Jul 3 11:36:32 2013
@@ -38,18 +38,22 @@
self.host = '127.0.0.1'
self.port = DEFAULT_PORT
self.test_object = test_object
+ username = module_config.get('username') or 'testsuite'
+ password = module_config.get('password') or 'testsuite'
+ userpass = (username, password)
#: ARI interface object
- self.ari = ARI(self.host, self.port)
+ self.ari = ARI(self.host, port=self.port, userpass=userpass)
#: Matchers for incoming events
self.event_matchers = [
EventMatcher(self.ari, e, test_object)
for e in module_config['events']]
- apps = module_config['apps']
+ apps = module_config.get('apps') or 'testsuite'
if isinstance(apps, list):
apps = ','.join(apps)
#: Twisted protocol factory for ARI WebSockets
self.factory = AriClientFactory(host=self.host, port=self.port,
- apps=apps, on_event=self.on_event)
+ apps=apps, on_event=self.on_event,
+ userpass=userpass)
def on_event(self, event):
'''Handle incoming events from the WebSocket.
@@ -63,7 +67,7 @@
class AriClientFactory(WebSocketClientFactory):
'''Twisted protocol factory for building ARI WebSocket clients.
'''
- def __init__(self, host, apps, on_event, port=DEFAULT_PORT,
+ def __init__(self, host, apps, on_event, userpass, port=DEFAULT_PORT,
timeout_secs=60):
'''Constructor
@@ -74,7 +78,8 @@
:param timeout_secs: Maximum time to try to connect to Asterisk.
'''
url = "ws://%s:%d/ws?%s" % \
- (host, port, urllib.urlencode({'app': apps}))
+ (host, port,
+ urllib.urlencode({'app': apps, 'api_key': '%s:%s' % userpass}))
WebSocketClientFactory.__init__(self, url, protocols=["stasis"])
self.on_event = on_event
self.timeout_secs = timeout_secs
@@ -148,14 +153,14 @@
'''Bare bones object for an ARI interface.
'''
- def __init__(self, host, port=DEFAULT_PORT):
+ def __init__(self, host, userpass, port=DEFAULT_PORT):
'''Constructor.
:param host: Hostname of Asterisk.
:param port: Port of the Asterisk webserver.
'''
self.base_url = "http://%s:%d/stasis" % (host, port)
-
+ self.userpass = userpass
def build_url(self, *args):
'''Build a URL from the given path.
@@ -177,9 +182,9 @@
:returns: requests.models.Response
:throws: requests.exceptions.HTTPError
'''
- url = self.build_url(*args, **kwargs)
+ url = self.build_url(*args)
logger.info("GET %s %r" % (url, kwargs))
- return raise_on_err(requests.get(url, params=kwargs))
+ return raise_on_err(requests.get(url, params=kwargs, auth=self.userpass))
def post(self, *args, **kwargs):
'''Send a POST request to ARI.
@@ -191,7 +196,7 @@
'''
url = self.build_url(*args, **kwargs)
logger.info("POST %s %r" % (url, kwargs))
- return raise_on_err(requests.post(url, params=kwargs))
+ return raise_on_err(requests.post(url, params=kwargs, auth=self.userpass))
def delete(self, *args, **kwargs):
'''Send a DELETE request to ARI.
@@ -203,7 +208,7 @@
'''
url = self.build_url(*args, **kwargs)
logger.info("DELETE %s %r" % (url, kwargs))
- return raise_on_err(requests.delete(url, params=kwargs))
+ return raise_on_err(requests.delete(url, params=kwargs, auth=self.userpass))
def raise_on_err(resp):
Modified: asterisk/trunk/tests/rest_api/continue/configs/ast1/stasis_http.conf
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/rest_api/continue/configs/ast1/stasis_http.conf?view=diff&rev=3879&r1=3878&r2=3879
==============================================================================
--- asterisk/trunk/tests/rest_api/continue/configs/ast1/stasis_http.conf (original)
+++ asterisk/trunk/tests/rest_api/continue/configs/ast1/stasis_http.conf Wed Jul 3 11:36:32 2013
@@ -1,2 +1,5 @@
[general]
enabled = yes
+
+[user-testsuite]
+password = testsuite
Modified: asterisk/trunk/tests/rest_api/tests.yaml
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/rest_api/tests.yaml?view=diff&rev=3879&r1=3878&r2=3879
==============================================================================
--- asterisk/trunk/tests/rest_api/tests.yaml (original)
+++ asterisk/trunk/tests/rest_api/tests.yaml Wed Jul 3 11:36:32 2013
@@ -1,3 +1,4 @@
# Enter tests here in the order they should be considered for execution:
tests:
- test: 'continue'
+ - test: 'authentication'
More information about the svn-commits
mailing list