[Asterisk-code-review] Add ARI test for duplicate IDs in originations. (testsuite[master])

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


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

Change subject: Add ARI test for duplicate IDs in originations.
......................................................................


Add ARI test for duplicate IDs in originations.

Change-Id: I872b95d7985b6c7b0f015d99f147310bada02b71
---
A tests/rest_api/channels/originate_duplicate_id/configs/ast1/extensions.conf
A tests/rest_api/channels/originate_duplicate_id/duplicate_id.py
A tests/rest_api/channels/originate_duplicate_id/test-config.yaml
M tests/rest_api/channels/tests.yaml
4 files changed, 145 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/originate_duplicate_id/configs/ast1/extensions.conf b/tests/rest_api/channels/originate_duplicate_id/configs/ast1/extensions.conf
new file mode 100644
index 0000000..1e5104d
--- /dev/null
+++ b/tests/rest_api/channels/originate_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/originate_duplicate_id/duplicate_id.py b/tests/rest_api/channels/originate_duplicate_id/duplicate_id.py
new file mode 100644
index 0000000..dcb5a19
--- /dev/null
+++ b/tests/rest_api/channels/originate_duplicate_id/duplicate_id.py
@@ -0,0 +1,68 @@
+'''
+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_originate(ari, channel_id, other_channel_id):
+    try:
+        ari.post('channels',
+                 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 try_originate_id(ari, channel_id, other_channel_id):
+    try:
+        ari.post('channels',
+                 channel_id,
+                 endpoint='Local/echo at default',
+                 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_originate(ari, "eggs", "bacon") and
+              try_originate(ari, "bacon", "eggs") and
+              try_originate_id(ari, "eggs", "bacon") and
+              try_originate_id(ari, "bacon", "eggs"))
+
+    ari.delete("channels", event['channel']['id'])
+    return passed
diff --git a/tests/rest_api/channels/originate_duplicate_id/test-config.yaml b/tests/rest_api/channels/originate_duplicate_id/test-config.yaml
new file mode 100644
index 0000000..7555cac
--- /dev/null
+++ b/tests/rest_api/channels/originate_duplicate_id/test-config.yaml
@@ -0,0 +1,70 @@
+testinfo:
+    summary: 'Ensure that duplicate Channel IDs are not allowed'
+    description: |
+        'This test ensures that duplicate channel IDs are not allowed by ARI. When
+        a duplicate channel ID is used, ARI should return a 409 response. Here
+        is how this test works:
+            * A channel is originated with ID "eggs". This should succeed with a 200
+              response and we should get a StasisStart event.
+            * Once we get the StasisStart, we attempt in every way to originate a channel
+              with ID "eggs":
+                  * Originate, specifying channelID "eggs"
+                  * Originate, specifying otherChannelID "eggs"
+                  * OriginateWithId, specifying channelID "eggs"
+                  * OriginateWithId, specifying otherChannelID "eggs"
+              All of these should fail with a 409 response and no Stasis Start. The test
+              fails if:
+                  * An originate succeeds
+                  * An originate fails with a non-409 status
+                  * An originate fails with a non HTTP error
+                  * A StasisStart happens for any of the failed originates.
+            * 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: ['13.13.0', '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 96ac922..94cbdea 100644
--- a/tests/rest_api/channels/tests.yaml
+++ b/tests/rest_api/channels/tests.yaml
@@ -13,3 +13,4 @@
     - test: 'originate_to_dialplan'
     - dir: 'create_dial_bridge'
     - dir: 'hold'
+    - test: 'originate_duplicate_id'

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I872b95d7985b6c7b0f015d99f147310bada02b71
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