[Asterisk-code-review] Add ARI test for duplicate IDs on channel creation. (testsuite[master])

Anonymous Coward asteriskteam at digium.com
Mon Oct 24 17:28:31 CDT 2016


Anonymous Coward #1000019 has submitted this change and it was merged. ( https://gerrit.asterisk.org/4160 )

Change subject: Add ARI test for duplicate IDs on channel creation.
......................................................................


Add ARI test for duplicate IDs on channel creation.

This is similar to the test for duplicate IDs for channel origination,
but instead focuses on the channel creation method that was added in
Asterisk 14.

Change-Id: If06ccfb4b3c1b49513a871512ba4e21ef0eabda0
---
A tests/rest_api/channels/create_duplicate_id/configs/ast1/extensions.conf
A tests/rest_api/channels/create_duplicate_id/duplicate_id.py
A tests/rest_api/channels/create_duplicate_id/test-config.yaml
M tests/rest_api/channels/tests.yaml
4 files changed, 122 insertions(+), 0 deletions(-)

Approvals:
  Kevin Harwell: Looks good to me, but someone else must approve
  Anonymous Coward #1000019: Verified
  Joshua Colp: Looks good to me, approved



diff --git a/tests/rest_api/channels/create_duplicate_id/configs/ast1/extensions.conf b/tests/rest_api/channels/create_duplicate_id/configs/ast1/extensions.conf
new file mode 100644
index 0000000..1e5104d
--- /dev/null
+++ b/tests/rest_api/channels/create_duplicate_id/configs/ast1/extensions.conf
@@ -0,0 +1,6 @@
+[default]
+
+exten => echo,1,NoOp()
+same => n,Answer()
+same => n,Echo()
+same => n,Hangup()
diff --git a/tests/rest_api/channels/create_duplicate_id/duplicate_id.py b/tests/rest_api/channels/create_duplicate_id/duplicate_id.py
new file mode 100644
index 0000000..93a504e
--- /dev/null
+++ b/tests/rest_api/channels/create_duplicate_id/duplicate_id.py
@@ -0,0 +1,46 @@
+'''
+Copyright (C) 2016, Digium, Inc.
+Mark Michelson <mmichelson at digium.com>
+
+This program is free software, distributed under the terms of
+the GNU General Public License Version 2.
+'''
+
+import logging
+from requests.exceptions import HTTPError
+import requests
+
+LOGGER = logging.getLogger(__name__)
+
+def try_create(ari, channel_id, other_channel_id):
+    try:
+        ari.post('channels',
+                 'create',
+                 endpoint='Local/echo at default',
+                 channelId=channel_id,
+                 otherChannelId=other_channel_id,
+                 app='testsuite',
+                 appArgs='FAIL')
+    except HTTPError as e:
+        if e.response.status_code != 409:
+            LOGGER.error("Unexpected response {0}".format(e.response))
+            return False
+        return True
+    except:
+        LOGGER.error("Unexpected exception when originating")
+        return False
+    else:
+        LOGGER.error("Originate succeeded when we expected failure")
+        return False
+
+
+def on_start(ari, event, obj):
+    if event['args'] == ['FAIL']:
+        LOGGER.error("Unexpected StasisStart on duplicate ID channel")
+        return False
+
+    passed = (try_create(ari, "eggs", "bacon") and
+              try_create(ari, "bacon", "eggs"))
+
+    ari.delete("channels", event['channel']['id'])
+    return passed
diff --git a/tests/rest_api/channels/create_duplicate_id/test-config.yaml b/tests/rest_api/channels/create_duplicate_id/test-config.yaml
new file mode 100644
index 0000000..1779a6b
--- /dev/null
+++ b/tests/rest_api/channels/create_duplicate_id/test-config.yaml
@@ -0,0 +1,69 @@
+testinfo:
+    summary: 'Ensure that duplicate channel IDs are not allowed during channel creation.'
+    description: |
+        'This test ensures that duplicate channel IDs are not allowed during channel
+        creation. When a duplicate channel ID is used, ARI should return a 409 response.
+        The test works as follows:
+            * A channel is originated with ID "eggs". This will succeed with a 200 response
+              and result in a StasisStart event.
+            * Once we get the Stasis Start, we attempt to create a channel using the same ID
+              in the following ways:
+                * Create, specifying channelID "eggs"
+                * Create, specifying otherChannelID "eggs"
+              These should each fail with a 409 response and no corresponding StasisStart. The
+              test fails if:
+                  * A create succeeds
+                  * A create fails with a non-409 status
+                  * A create fails with a non HTTP error
+                  * A StasisStart happens for a failed create
+            * Hang up the channel.'
+
+
+test-modules:
+    add-test-to-search-path: True
+    test-object:
+        typename: ari.AriOriginateTestObject
+        config-section: ari-config
+    modules:
+        -
+            config-section: event-config
+            typename: ari.WebSocketEventModule
+
+
+ari-config:
+    test-iterations:
+        -
+            endpoint: 'Local/echo at default'
+            channelId: 'eggs'
+            app: 'testsuite'
+
+
+event-config:
+    apps: testsuite
+    events:
+        -
+            conditions:
+                match:
+                    type: StasisStart
+                    application: testsuite
+                    args: []
+            count: 1
+            callback:
+                module: duplicate_id
+                method: on_start
+
+
+properties:
+    minversion: '14.2.0'
+    dependencies:
+        - python: 'autobahn.websocket'
+        - python: 'requests'
+        - python: 'twisted'
+        - python: 'starpy'
+        - asterisk: 'res_ari_channels'
+        - asterisk: 'res_stasis'
+    tags:
+        - ARI
+    issues:
+        - jira: 'ASTERISK-26241'
+
diff --git a/tests/rest_api/channels/tests.yaml b/tests/rest_api/channels/tests.yaml
index 94cbdea..6ed8d28 100644
--- a/tests/rest_api/channels/tests.yaml
+++ b/tests/rest_api/channels/tests.yaml
@@ -14,3 +14,4 @@
     - dir: 'create_dial_bridge'
     - dir: 'hold'
     - test: 'originate_duplicate_id'
+    - test: 'create_duplicate_id'

-- 
To view, visit https://gerrit.asterisk.org/4160
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: If06ccfb4b3c1b49513a871512ba4e21ef0eabda0
Gerrit-PatchSet: 1
Gerrit-Project: testsuite
Gerrit-Branch: master
Gerrit-Owner: Mark Michelson <mmichelson at digium.com>
Gerrit-Reviewer: Anonymous Coward #1000019
Gerrit-Reviewer: Joshua Colp <jcolp at digium.com>
Gerrit-Reviewer: Kevin Harwell <kharwell at digium.com>



More information about the asterisk-code-review mailing list