<p>Kevin Harwell has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/c/testsuite/+/14518">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">manager - Add a test for SendText via an AMI command<br><br>Test the SendText AMI action. Specifically, ensure that the content type<br>and message are correctly sent.<br><br>Also, this patch updates the regex for event/action substitutions check<br>to allow escaping of braces, i.e. it won't try to subsitute if the brace<br>is escaped (ex: \{ abc \})<br><br>ASTERISK-28945<br><br>Change-Id: Id94d67be9952f8c67ee54162ef9a4431b70d8eaa<br>---<br>M lib/python/asterisk/pluggable_registry.py<br>A tests/manager/sendtext/configs/ast1/extensions.conf<br>A tests/manager/sendtext/configs/ast1/pjsip.conf<br>A tests/manager/sendtext/sipp/message_recv.xml<br>A tests/manager/sendtext/test-config.yaml<br>M tests/manager/tests.yaml<br>6 files changed, 166 insertions(+), 1 deletion(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.asterisk.org:29418/testsuite refs/changes/18/14518/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/lib/python/asterisk/pluggable_registry.py b/lib/python/asterisk/pluggable_registry.py</span><br><span>index 9a50a26..94a587f 100644</span><br><span>--- a/lib/python/asterisk/pluggable_registry.py</span><br><span>+++ b/lib/python/asterisk/pluggable_registry.py</span><br><span>@@ -52,7 +52,7 @@</span><br><span> if not isinstance(text, str):</span><br><span> return text</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- for match in re.findall(r'{[^}]*}', text):</span><br><span style="color: hsl(120, 100%, 40%);">+ for match in re.findall(r'(?<!\\){[^}]*(?<!\\)}', text):</span><br><span> value = values</span><br><span> for var in match[1:-1].split('.'):</span><br><span> if not var in value:</span><br><span>diff --git a/tests/manager/sendtext/configs/ast1/extensions.conf b/tests/manager/sendtext/configs/ast1/extensions.conf</span><br><span>new file mode 100644</span><br><span>index 0000000..e0a4f7d</span><br><span>--- /dev/null</span><br><span>+++ b/tests/manager/sendtext/configs/ast1/extensions.conf</span><br><span>@@ -0,0 +1,6 @@</span><br><span style="color: hsl(120, 100%, 40%);">+[general]</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+[default]</span><br><span style="color: hsl(120, 100%, 40%);">+exten = echo,1,Answer()</span><br><span style="color: hsl(120, 100%, 40%);">+ same = n,Echo()</span><br><span style="color: hsl(120, 100%, 40%);">+ same = n,Hangup()</span><br><span>diff --git a/tests/manager/sendtext/configs/ast1/pjsip.conf b/tests/manager/sendtext/configs/ast1/pjsip.conf</span><br><span>new file mode 100644</span><br><span>index 0000000..34c681f</span><br><span>--- /dev/null</span><br><span>+++ b/tests/manager/sendtext/configs/ast1/pjsip.conf</span><br><span>@@ -0,0 +1,24 @@</span><br><span style="color: hsl(120, 100%, 40%);">+[system]</span><br><span style="color: hsl(120, 100%, 40%);">+type=system</span><br><span style="color: hsl(120, 100%, 40%);">+timer_t1=100</span><br><span style="color: hsl(120, 100%, 40%);">+timer_b=6400</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+[local]</span><br><span style="color: hsl(120, 100%, 40%);">+type=transport</span><br><span style="color: hsl(120, 100%, 40%);">+protocol=udp</span><br><span style="color: hsl(120, 100%, 40%);">+bind=0.0.0.0</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+[alice]</span><br><span style="color: hsl(120, 100%, 40%);">+type=aor</span><br><span style="color: hsl(120, 100%, 40%);">+contact=sip:alice@127.0.0.1:5061</span><br><span style="color: hsl(120, 100%, 40%);">+max_contacts=1</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+[alice]</span><br><span style="color: hsl(120, 100%, 40%);">+type=endpoint</span><br><span style="color: hsl(120, 100%, 40%);">+context=default</span><br><span style="color: hsl(120, 100%, 40%);">+aors=alice</span><br><span style="color: hsl(120, 100%, 40%);">+direct_media=no</span><br><span style="color: hsl(120, 100%, 40%);">+disallow=all</span><br><span style="color: hsl(120, 100%, 40%);">+allow=ulaw</span><br><span>diff --git a/tests/manager/sendtext/sipp/message_recv.xml b/tests/manager/sendtext/sipp/message_recv.xml</span><br><span>new file mode 100644</span><br><span>index 0000000..7850cce</span><br><span>--- /dev/null</span><br><span>+++ b/tests/manager/sendtext/sipp/message_recv.xml</span><br><span>@@ -0,0 +1,86 @@</span><br><span style="color: hsl(120, 100%, 40%);">+<?xml version="1.0" encoding="ISO-8859-1" ?></span><br><span style="color: hsl(120, 100%, 40%);">+<!DOCTYPE scenario SYSTEM "sipp.dtd"></span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+<scenario name="INVITE to echo with SDP in initial INVITE"></span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ <Global variables="extn" /></span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ <send></span><br><span style="color: hsl(120, 100%, 40%);">+ <![CDATA[</span><br><span style="color: hsl(120, 100%, 40%);">+ INVITE sip:[$extn]@[remote_ip]:[remote_port] SIP/2.0</span><br><span style="color: hsl(120, 100%, 40%);">+ Via: SIP/2.0/[transport] [local_ip]:[local_port];branch=[branch]</span><br><span style="color: hsl(120, 100%, 40%);">+ From: "Alice" <sip:[service]@[local_ip]:[local_port]>;tag=SIPPID-[pid]-[call_number]</span><br><span style="color: hsl(120, 100%, 40%);">+ To: conf <sip:[$extn]@[remote_ip]:[remote_port]></span><br><span style="color: hsl(120, 100%, 40%);">+ Call-ID: [call_id]</span><br><span style="color: hsl(120, 100%, 40%);">+ CSeq: [cseq] INVITE</span><br><span style="color: hsl(120, 100%, 40%);">+ Contact: "Alice" <sip:[service]@[local_ip]:[local_port];transport=[transport]></span><br><span style="color: hsl(120, 100%, 40%);">+ Allow: OPTIONS, SUBSCRIBE, NOTIFY, PUBLISH, INVITE, ACK, BYE, CANCEL, PRACK, REGISTER, REFER, MESSAGE</span><br><span style="color: hsl(120, 100%, 40%);">+ Content-Type: application/sdp</span><br><span style="color: hsl(120, 100%, 40%);">+ Content-Length: [len]</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ v=0</span><br><span style="color: hsl(120, 100%, 40%);">+ o=phoneA 53655765 2353687637 IN IP[local_ip_type] [local_ip]</span><br><span style="color: hsl(120, 100%, 40%);">+ s=-</span><br><span style="color: hsl(120, 100%, 40%);">+ c=IN IP[media_ip_type] [media_ip]</span><br><span style="color: hsl(120, 100%, 40%);">+ t=0 0</span><br><span style="color: hsl(120, 100%, 40%);">+ m=audio 6000 RTP/AVP 0</span><br><span style="color: hsl(120, 100%, 40%);">+ a=rtpmap:0 PCMU/8000</span><br><span style="color: hsl(120, 100%, 40%);">+ ]]></span><br><span style="color: hsl(120, 100%, 40%);">+ </send></span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ <recv response="100" optional="true" /></span><br><span style="color: hsl(120, 100%, 40%);">+ <recv response="200" /></span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ <send></span><br><span style="color: hsl(120, 100%, 40%);">+ <![CDATA[</span><br><span style="color: hsl(120, 100%, 40%);">+ ACK sip:[$extn]@[remote_ip]:[remote_port] SIP/2.0</span><br><span style="color: hsl(120, 100%, 40%);">+ [last_Via:]</span><br><span style="color: hsl(120, 100%, 40%);">+ [last_From:]</span><br><span style="color: hsl(120, 100%, 40%);">+ [last_To:]</span><br><span style="color: hsl(120, 100%, 40%);">+ [last_Call-ID:]</span><br><span style="color: hsl(120, 100%, 40%);">+ CSeq: [cseq] ACK</span><br><span style="color: hsl(120, 100%, 40%);">+ [last_Contact:]</span><br><span style="color: hsl(120, 100%, 40%);">+ [last_Allow:]</span><br><span style="color: hsl(120, 100%, 40%);">+ Content-Length: 0</span><br><span style="color: hsl(120, 100%, 40%);">+ ]]></span><br><span style="color: hsl(120, 100%, 40%);">+ </send></span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ <recv request="MESSAGE" timeout="5000"></span><br><span style="color: hsl(120, 100%, 40%);">+ <action></span><br><span style="color: hsl(120, 100%, 40%);">+ <ereg regexp="application/x-asterisk\+json" search_in="hdr" header="Content-Type:" check_it="true" assign_to="dummy"/></span><br><span style="color: hsl(120, 100%, 40%);">+ <ereg regexp="\{\"name"\: \"Sleeper\", \"status\": \"Awakened\"\}" search_in="body" check_it="true" assign_to="dummy"/></span><br><span style="color: hsl(120, 100%, 40%);">+ </action></span><br><span style="color: hsl(120, 100%, 40%);">+ </recv></span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ <send></span><br><span style="color: hsl(120, 100%, 40%);">+ <![CDATA[</span><br><span style="color: hsl(120, 100%, 40%);">+ SIP/2.0 202 Accepted</span><br><span style="color: hsl(120, 100%, 40%);">+ [last_Via:]</span><br><span style="color: hsl(120, 100%, 40%);">+ [last_From:]</span><br><span style="color: hsl(120, 100%, 40%);">+ [last_To:]</span><br><span style="color: hsl(120, 100%, 40%);">+ [last_Call-ID:]</span><br><span style="color: hsl(120, 100%, 40%);">+ [last_CSeq:]</span><br><span style="color: hsl(120, 100%, 40%);">+ Allow: INVITE, ACK, MESSAGE, BYE</span><br><span style="color: hsl(120, 100%, 40%);">+ Content-Length: 0</span><br><span style="color: hsl(120, 100%, 40%);">+ ]]></span><br><span style="color: hsl(120, 100%, 40%);">+ </send></span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ <pause milliseconds="2000"/></span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ <send></span><br><span style="color: hsl(120, 100%, 40%);">+ <![CDATA[</span><br><span style="color: hsl(120, 100%, 40%);">+ BYE sip:[service]@[remote_ip]:[remote_port] SIP/2.0</span><br><span style="color: hsl(120, 100%, 40%);">+ [last_Via:]</span><br><span style="color: hsl(120, 100%, 40%);">+ From: "Alice" <sip:[service]@[local_ip]:[local_port]>;tag=SIPPID-[pid]-[call_number]</span><br><span style="color: hsl(120, 100%, 40%);">+ To: conf <sip:[$extn]@[remote_ip]:[remote_port]>[peer_tag_param]</span><br><span style="color: hsl(120, 100%, 40%);">+ [last_Call-ID:]</span><br><span style="color: hsl(120, 100%, 40%);">+ CSeq: [cseq+1] BYE</span><br><span style="color: hsl(120, 100%, 40%);">+ [last_Contact:]</span><br><span style="color: hsl(120, 100%, 40%);">+ Content-Length: 0</span><br><span style="color: hsl(120, 100%, 40%);">+ ]]></span><br><span style="color: hsl(120, 100%, 40%);">+ </send></span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ <recv response="200" /></span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ <Reference variables="dummy" /></span><br><span style="color: hsl(120, 100%, 40%);">+</scenario></span><br><span>diff --git a/tests/manager/sendtext/test-config.yaml b/tests/manager/sendtext/test-config.yaml</span><br><span>new file mode 100644</span><br><span>index 0000000..0f3e467</span><br><span>--- /dev/null</span><br><span>+++ b/tests/manager/sendtext/test-config.yaml</span><br><span>@@ -0,0 +1,48 @@</span><br><span style="color: hsl(120, 100%, 40%);">+testinfo:</span><br><span style="color: hsl(120, 100%, 40%);">+ summary: 'Send a message via the AMI'</span><br><span style="color: hsl(120, 100%, 40%);">+ description: |</span><br><span style="color: hsl(120, 100%, 40%);">+ 'Using AMI send a message containing JSON to the specified channel'</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+properties:</span><br><span style="color: hsl(120, 100%, 40%);">+ dependencies:</span><br><span style="color: hsl(120, 100%, 40%);">+ - app : 'sipp'</span><br><span style="color: hsl(120, 100%, 40%);">+ - asterisk : 'app_sendtext'</span><br><span style="color: hsl(120, 100%, 40%);">+ - asterisk : 'chan_pjsip'</span><br><span style="color: hsl(120, 100%, 40%);">+ - asterisk : 'res_pjsip'</span><br><span style="color: hsl(120, 100%, 40%);">+ tags:</span><br><span style="color: hsl(120, 100%, 40%);">+ - pjsip</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+test-modules:</span><br><span style="color: hsl(120, 100%, 40%);">+ test-object:</span><br><span style="color: hsl(120, 100%, 40%);">+ config-section: test-object-config</span><br><span style="color: hsl(120, 100%, 40%);">+ typename: 'sipp.SIPpTestCase'</span><br><span style="color: hsl(120, 100%, 40%);">+ modules:</span><br><span style="color: hsl(120, 100%, 40%);">+ -</span><br><span style="color: hsl(120, 100%, 40%);">+ config-section: event-action-config</span><br><span style="color: hsl(120, 100%, 40%);">+ typename: 'pluggable_modules.EventActionModule'</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+test-object-config:</span><br><span style="color: hsl(120, 100%, 40%);">+ memcheck-delay-stop: 7</span><br><span style="color: hsl(120, 100%, 40%);">+ test-iterations:</span><br><span style="color: hsl(120, 100%, 40%);">+ -</span><br><span style="color: hsl(120, 100%, 40%);">+ scenarios:</span><br><span style="color: hsl(120, 100%, 40%);">+ - { 'key-args': { 'scenario': 'message_recv.xml', '-p': '5061', '-s': 'alice' },</span><br><span style="color: hsl(120, 100%, 40%);">+ 'ordered-args': [ '-set', 'extn', 'echo' ] }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+event-action-config:</span><br><span style="color: hsl(120, 100%, 40%);">+ -</span><br><span style="color: hsl(120, 100%, 40%);">+ ami-events:</span><br><span style="color: hsl(120, 100%, 40%);">+ id: '0'</span><br><span style="color: hsl(120, 100%, 40%);">+ conditions:</span><br><span style="color: hsl(120, 100%, 40%);">+ match:</span><br><span style="color: hsl(120, 100%, 40%);">+ Event: 'Newchannel'</span><br><span style="color: hsl(120, 100%, 40%);">+ Channel: 'PJSIP/alice-*'</span><br><span style="color: hsl(120, 100%, 40%);">+ count: '1'</span><br><span style="color: hsl(120, 100%, 40%);">+ trigger-on-count: True</span><br><span style="color: hsl(120, 100%, 40%);">+ ami-actions:</span><br><span style="color: hsl(120, 100%, 40%);">+ action:</span><br><span style="color: hsl(120, 100%, 40%);">+ Action: 'SendText'</span><br><span style="color: hsl(120, 100%, 40%);">+ Channel: '{channel}'</span><br><span style="color: hsl(120, 100%, 40%);">+ Content-Type: 'application/x-asterisk+json'</span><br><span style="color: hsl(120, 100%, 40%);">+ Message: '\{"name": "Sleeper", "status": "Awakened"\}'</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span>diff --git a/tests/manager/tests.yaml b/tests/manager/tests.yaml</span><br><span>index 6e6f8d5..1f0dccf 100644</span><br><span>--- a/tests/manager/tests.yaml</span><br><span>+++ b/tests/manager/tests.yaml</span><br><span>@@ -23,4 +23,5 @@</span><br><span> - test: 'response-time'</span><br><span> - test: 'escaped_values'</span><br><span> - dir: 'redirect'</span><br><span style="color: hsl(120, 100%, 40%);">+ - test: 'sendtext'</span><br><span> - test: 'playdtmf'</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/c/testsuite/+/14518">change 14518</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.asterisk.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.asterisk.org/c/testsuite/+/14518"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: testsuite </div>
<div style="display:none"> Gerrit-Branch: 16 </div>
<div style="display:none"> Gerrit-Change-Id: Id94d67be9952f8c67ee54162ef9a4431b70d8eaa </div>
<div style="display:none"> Gerrit-Change-Number: 14518 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Kevin Harwell <kharwell@digium.com> </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>