[Asterisk-code-review] manager - Add a test for SendText via an AMI command (testsuite[master])
Friendly Automation
asteriskteam at digium.com
Tue Jul 7 08:11:22 CDT 2020
Friendly Automation has submitted this change. ( https://gerrit.asterisk.org/c/testsuite/+/14548 )
Change subject: manager - Add a test for SendText via an AMI command
......................................................................
manager - Add a test for SendText via an AMI command
Test the SendText AMI action. Specifically, ensure that the content type
and message are correctly sent.
Also, this patch updates the regex for event/action substitutions check
to allow escaping of braces, i.e. it won't try to subsitute if the brace
is escaped (ex: \{ abc \})
ASTERISK-28945
Change-Id: Id94d67be9952f8c67ee54162ef9a4431b70d8eaa
---
M lib/python/asterisk/pluggable_registry.py
A tests/manager/sendtext/configs/ast1/extensions.conf
A tests/manager/sendtext/configs/ast1/pjsip.conf
A tests/manager/sendtext/sipp/message_recv.xml
A tests/manager/sendtext/test-config.yaml
M tests/manager/tests.yaml
6 files changed, 166 insertions(+), 1 deletion(-)
Approvals:
Joshua Colp: Looks good to me, but someone else must approve
Benjamin Keith Ford: Looks good to me, but someone else must approve
George Joseph: Looks good to me, approved
Friendly Automation: Approved for Submit
diff --git a/lib/python/asterisk/pluggable_registry.py b/lib/python/asterisk/pluggable_registry.py
index 9a50a26..94a587f 100644
--- a/lib/python/asterisk/pluggable_registry.py
+++ b/lib/python/asterisk/pluggable_registry.py
@@ -52,7 +52,7 @@
if not isinstance(text, str):
return text
- for match in re.findall(r'{[^}]*}', text):
+ for match in re.findall(r'(?<!\\){[^}]*(?<!\\)}', text):
value = values
for var in match[1:-1].split('.'):
if not var in value:
diff --git a/tests/manager/sendtext/configs/ast1/extensions.conf b/tests/manager/sendtext/configs/ast1/extensions.conf
new file mode 100644
index 0000000..e0a4f7d
--- /dev/null
+++ b/tests/manager/sendtext/configs/ast1/extensions.conf
@@ -0,0 +1,6 @@
+[general]
+
+[default]
+exten = echo,1,Answer()
+ same = n,Echo()
+ same = n,Hangup()
diff --git a/tests/manager/sendtext/configs/ast1/pjsip.conf b/tests/manager/sendtext/configs/ast1/pjsip.conf
new file mode 100644
index 0000000..34c681f
--- /dev/null
+++ b/tests/manager/sendtext/configs/ast1/pjsip.conf
@@ -0,0 +1,24 @@
+[system]
+type=system
+timer_t1=100
+timer_b=6400
+
+[local]
+type=transport
+protocol=udp
+bind=0.0.0.0
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+[alice]
+type=aor
+contact=sip:alice at 127.0.0.1:5061
+max_contacts=1
+
+[alice]
+type=endpoint
+context=default
+aors=alice
+direct_media=no
+disallow=all
+allow=ulaw
diff --git a/tests/manager/sendtext/sipp/message_recv.xml b/tests/manager/sendtext/sipp/message_recv.xml
new file mode 100644
index 0000000..7850cce
--- /dev/null
+++ b/tests/manager/sendtext/sipp/message_recv.xml
@@ -0,0 +1,86 @@
+<?xml version="1.0" encoding="ISO-8859-1" ?>
+<!DOCTYPE scenario SYSTEM "sipp.dtd">
+
+<scenario name="INVITE to echo with SDP in initial INVITE">
+
+ <Global variables="extn" />
+
+ <send>
+ <![CDATA[
+ INVITE sip:[$extn]@[remote_ip]:[remote_port] SIP/2.0
+ Via: SIP/2.0/[transport] [local_ip]:[local_port];branch=[branch]
+ From: "Alice" <sip:[service]@[local_ip]:[local_port]>;tag=SIPPID-[pid]-[call_number]
+ To: conf <sip:[$extn]@[remote_ip]:[remote_port]>
+ Call-ID: [call_id]
+ CSeq: [cseq] INVITE
+ Contact: "Alice" <sip:[service]@[local_ip]:[local_port];transport=[transport]>
+ Allow: OPTIONS, SUBSCRIBE, NOTIFY, PUBLISH, INVITE, ACK, BYE, CANCEL, PRACK, REGISTER, REFER, MESSAGE
+ Content-Type: application/sdp
+ Content-Length: [len]
+
+ v=0
+ o=phoneA 53655765 2353687637 IN IP[local_ip_type] [local_ip]
+ s=-
+ c=IN IP[media_ip_type] [media_ip]
+ t=0 0
+ m=audio 6000 RTP/AVP 0
+ a=rtpmap:0 PCMU/8000
+ ]]>
+ </send>
+
+ <recv response="100" optional="true" />
+ <recv response="200" />
+
+ <send>
+ <![CDATA[
+ ACK sip:[$extn]@[remote_ip]:[remote_port] SIP/2.0
+ [last_Via:]
+ [last_From:]
+ [last_To:]
+ [last_Call-ID:]
+ CSeq: [cseq] ACK
+ [last_Contact:]
+ [last_Allow:]
+ Content-Length: 0
+ ]]>
+ </send>
+
+ <recv request="MESSAGE" timeout="5000">
+ <action>
+ <ereg regexp="application/x-asterisk\+json" search_in="hdr" header="Content-Type:" check_it="true" assign_to="dummy"/>
+ <ereg regexp="\{\"name"\: \"Sleeper\", \"status\": \"Awakened\"\}" search_in="body" check_it="true" assign_to="dummy"/>
+ </action>
+ </recv>
+
+ <send>
+ <![CDATA[
+ SIP/2.0 202 Accepted
+ [last_Via:]
+ [last_From:]
+ [last_To:]
+ [last_Call-ID:]
+ [last_CSeq:]
+ Allow: INVITE, ACK, MESSAGE, BYE
+ Content-Length: 0
+ ]]>
+ </send>
+
+ <pause milliseconds="2000"/>
+
+ <send>
+ <![CDATA[
+ BYE sip:[service]@[remote_ip]:[remote_port] SIP/2.0
+ [last_Via:]
+ From: "Alice" <sip:[service]@[local_ip]:[local_port]>;tag=SIPPID-[pid]-[call_number]
+ To: conf <sip:[$extn]@[remote_ip]:[remote_port]>[peer_tag_param]
+ [last_Call-ID:]
+ CSeq: [cseq+1] BYE
+ [last_Contact:]
+ Content-Length: 0
+ ]]>
+ </send>
+
+ <recv response="200" />
+
+ <Reference variables="dummy" />
+</scenario>
diff --git a/tests/manager/sendtext/test-config.yaml b/tests/manager/sendtext/test-config.yaml
new file mode 100644
index 0000000..0f3e467
--- /dev/null
+++ b/tests/manager/sendtext/test-config.yaml
@@ -0,0 +1,48 @@
+testinfo:
+ summary: 'Send a message via the AMI'
+ description: |
+ 'Using AMI send a message containing JSON to the specified channel'
+
+properties:
+ dependencies:
+ - app : 'sipp'
+ - asterisk : 'app_sendtext'
+ - asterisk : 'chan_pjsip'
+ - asterisk : 'res_pjsip'
+ tags:
+ - pjsip
+
+test-modules:
+ test-object:
+ config-section: test-object-config
+ typename: 'sipp.SIPpTestCase'
+ modules:
+ -
+ config-section: event-action-config
+ typename: 'pluggable_modules.EventActionModule'
+
+test-object-config:
+ memcheck-delay-stop: 7
+ test-iterations:
+ -
+ scenarios:
+ - { 'key-args': { 'scenario': 'message_recv.xml', '-p': '5061', '-s': 'alice' },
+ 'ordered-args': [ '-set', 'extn', 'echo' ] }
+
+event-action-config:
+ -
+ ami-events:
+ id: '0'
+ conditions:
+ match:
+ Event: 'Newchannel'
+ Channel: 'PJSIP/alice-*'
+ count: '1'
+ trigger-on-count: True
+ ami-actions:
+ action:
+ Action: 'SendText'
+ Channel: '{channel}'
+ Content-Type: 'application/x-asterisk+json'
+ Message: '\{"name": "Sleeper", "status": "Awakened"\}'
+
diff --git a/tests/manager/tests.yaml b/tests/manager/tests.yaml
index 6e6f8d5..1f0dccf 100644
--- a/tests/manager/tests.yaml
+++ b/tests/manager/tests.yaml
@@ -23,4 +23,5 @@
- test: 'response-time'
- test: 'escaped_values'
- dir: 'redirect'
+ - test: 'sendtext'
- test: 'playdtmf'
--
To view, visit https://gerrit.asterisk.org/c/testsuite/+/14548
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings
Gerrit-Project: testsuite
Gerrit-Branch: master
Gerrit-Change-Id: Id94d67be9952f8c67ee54162ef9a4431b70d8eaa
Gerrit-Change-Number: 14548
Gerrit-PatchSet: 2
Gerrit-Owner: Kevin Harwell <kharwell at digium.com>
Gerrit-Reviewer: Benjamin Keith Ford <bford at digium.com>
Gerrit-Reviewer: Friendly Automation
Gerrit-Reviewer: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Joshua Colp <jcolp at sangoma.com>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20200707/2d49a67b/attachment-0001.html>
More information about the asterisk-code-review
mailing list