Skip to content

Commit

Permalink
Add tests for tenant identifier.
Browse files Browse the repository at this point in the history
Adds 3 tests that ensure tenant identifier shows up correctly:
* Setting and accessing via dialplan
* Setting in pjsip.conf and presence in AMI events
* Presence in ARI events

Also added a new directory (extra_gates) with a symbolic link to the
tenant_id tests to run gates beyond the normal ones for Asterisk
reviews.
  • Loading branch information
bkford authored and asterisk-org-access-app[bot] committed Sep 5, 2024
1 parent 10b9d47 commit 3220993
Show file tree
Hide file tree
Showing 15 changed files with 415 additions and 0 deletions.
1 change: 1 addition & 0 deletions tests/extra_gates/tenant_id
3 changes: 3 additions & 0 deletions tests/extra_gates/tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Enter tests here in the order they should be considered for execution:
tests:
- dir: 'tenant_id'
6 changes: 6 additions & 0 deletions tests/tenant_id/tenant_id_ami/configs/ast1/extensions.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[default]

exten => echo,1,NoOp()
same => n,Answer()
same => n,Echo()
same => n,Hangup()
17 changes: 17 additions & 0 deletions tests/tenant_id/tenant_id_ami/configs/ast1/pjsip.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[system]
type=system
timer_t1=100
timer_b=6400

[alice-transport]
type=transport
protocol=udp
bind=127.0.0.1

[alice]
type=endpoint
context=default
allow=!all,ulaw,alaw
media_address=127.0.0.1
transport=alice-transport
tenantid=Test ID
85 changes: 85 additions & 0 deletions tests/tenant_id/tenant_id_ami/sipp/echo.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE scenario SYSTEM "sipp.dtd">

<scenario name="INVITE to echo with SDP in initial INVITE">
<send retrans="500">
<![CDATA[
INVITE sip:echo@[remote_ip]:[remote_port] SIP/2.0
Via: SIP/2.0/[transport] [local_ip]:[local_port];branch=[branch]
From: test1 <sip:[service]@[local_ip]:[local_port]>;tag=[call_number]
To: test <sip:test@[remote_ip]:[remote_port]>
Call-ID: [call_id]
CSeq: 1 INVITE
Contact: <sip:test@[local_ip]:[local_port];transport=[transport]>
Max-Forwards: 70
Subject: Test
User-Agent: Test
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>

<recv response="200" rtd="true">
</recv>

<send>
<![CDATA[
ACK sip:echo@[remote_ip]:[remote_port] SIP/2.0
Via: SIP/2.0/[transport] [local_ip]:[local_port];branch=[branch]
From: test1 <sip:[service]@[local_ip]:[local_port]>;tag=[call_number]
To: test <sip:test@[remote_ip]:[remote_port]>[peer_tag_param]
Call-ID: [call_id]
CSeq: 1 ACK
Contact: <sip:test@[local_ip]:[local_port];transport=[transport]>
Max-Forwards: 70
Subject: Test
Content-Length: 0
]]>
</send>

<pause milliseconds="3000"/>

<send retrans="500">
<![CDATA[
BYE sip:echo@[remote_ip]:[remote_port] SIP/2.0
Via: SIP/2.0/[transport] [local_ip]:[local_port];branch=[branch]
From: test1 <sip:[service]@[local_ip]:[local_port]>;tag=[call_number]
To: test <sip:test@[remote_ip]:[remote_port]>[peer_tag_param]
Call-ID: [call_id]
CSeq: 2 BYE
Contact: <sip:test@[local_ip]:[local_port];transport=[transport]>
Max-Forwards: 70
Subject: Test
Content-Length: 0
]]>
</send>

<recv response="200" crlf="true">
</recv>

<!-- definition of the response time repartition table (unit is ms) -->
<ResponseTimeRepartition value="10, 20, 30, 40, 50, 100, 150, 200"/>

<!-- definition of the call length repartition table (unit is ms) -->
<CallLengthRepartition value="10, 50, 100, 500, 1000, 5000, 10000"/>

</scenario>

47 changes: 47 additions & 0 deletions tests/tenant_id/tenant_id_ami/test-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
info:
summary: 'Test tenantid presence in AMI Events'
description: |
This tests that tenantid is either present or not
in AMI events depending on whether it was set on
the channel.
test-modules:
test-object:
config-section: test-config
typename: 'sipp.SIPpTestCase'
modules:
-
config-section: ami-config
typename: 'ami.AMIEventModule'

test-config:
memcheck-delay-stop: 7
fail-on-any: False
test-iterations:
-
scenarios:
- { 'key-args': {'scenario': 'echo.xml', '-i': '127.0.0.1', '-p': '5061', '-s': 'alice'} }

ami-config:
-
type: 'headermatch'
conditions:
match:
Event: 'Newchannel'
Channel: 'PJSIP/alice-.{8}'
requirements:
match:
Tenantid: 'Test ID'
count: '1'

properties:
dependencies:
- python : 'twisted'
- python : 'starpy'
- asterisk : 'res_pjsip'
- asterisk : 'res_pjsip_session'
- asterisk : 'chan_pjsip'
- asterisk : 'app_echo'
tags:
- pjsip
- manager
7 changes: 7 additions & 0 deletions tests/tenant_id/tenant_id_ari/configs/ast1/extensions.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[default]

exten => s,1,NoOp()
same => n,Set(CHANNEL(tenantid)=Test ID)
same => n,Answer()
same => n,Stasis(testsuite)
same => n,Hangup()
14 changes: 14 additions & 0 deletions tests/tenant_id/tenant_id_ari/tenant_id.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
'''
Copyright (C) 2024, Sangoma, Inc.
Ben Ford <[email protected]>
This program is free software, distributed under the terms of
the GNU General Public License Version 2.
'''

def on_stasis_start(ari, event, obj):
channel = event.get('channel')
tenantid = channel.get('tenantid')
assert(tenantid == 'Test ID')
ari.delete('channels', event['channel']['id'])
return True
39 changes: 39 additions & 0 deletions tests/tenant_id/tenant_id_ari/test-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
testinfo:
summary: Tests that Tenant ID is present in Stasis events.
description: |
Put a channel in Stasis. If the event shows up with Tenant ID
present, end the test successfully.
test-modules:
add-test-to-search-path: True
test-object:
typename: ari.AriTestObject
modules:
- config-section: ari-config
typename: ari.WebSocketEventModule

ari-config:
apps: testsuite
events:
- conditions:
match:
type: StasisStart
application: testsuite
args: []
channel:
tenantid: "Test ID"
count: 1
callback:
module: tenant_id
method: on_stasis_start

properties:
dependencies:
- python : autobahn.websocket
- python : requests
- python : twisted
- python : starpy
- asterisk : res_ari_channels
- asterisk : app_echo
tags:
- ARI
12 changes: 12 additions & 0 deletions tests/tenant_id/tenant_id_dialplan/configs/ast1/extensions.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

[default]

exten => alice,1,NoOp()
same => n,Answer()
same => n,GotoIf($[${CHANNEL(tenantid)}]?:pass1)
same => n,UserEvent(Result, Status: failed, Message: TenantID was not empty when it was expected to be)
same => n(pass1),Set(CHANNEL(tenantid)=Testing123)
same => n,GotoIf($["${CHANNEL(tenantid)}" != "Testing123"]?:pass2)
same => n,UserEvent(Result, Status: failed, Message: TenantID was not the correct value)
same => n(pass2),UserEvent(Result, Status: passed)
same => n,Hangup()
34 changes: 34 additions & 0 deletions tests/tenant_id/tenant_id_dialplan/configs/ast1/pjsip.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[system]
type=system
timer_t1=100
timer_b=6400

[local-transport-template](!)
type=transport
bind=127.0.0.1:5061

[local-transport-udp](local-transport-template)
protocol=udp

[endpoint-template](!)
type=endpoint
context=default
allow=!all,ulaw,alaw

[aors-template](!)
type=aor

[identify-template](!)
type=identify

[alice-identify-ipv4](identify-template)
endpoint=alice
match=127.0.0.1:5062

[alice](aors-template)
contact=sip:127.0.0.1:5062

; alice is the caller
[alice](endpoint-template)
aors=alice
from_user=Alice
90 changes: 90 additions & 0 deletions tests/tenant_id/tenant_id_dialplan/sipp/uac-no-hangup.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE scenario SYSTEM "sipp.dtd">

<scenario name="Basic Sipstone UAC">
<send retrans="500">
<![CDATA[
INVITE sip:[service]@[remote_ip]:[remote_port] SIP/2.0
Via: SIP/2.0/[transport] [local_ip]:[local_port];branch=[branch]
From: alice <sip:alice@[local_ip]:[local_port]>;tag=[pid]SIPpTag00[call_number]
To: sut <sip:[service]@[remote_ip]:[remote_port]>
Call-ID: [call_id]
CSeq: 1 INVITE
Contact: sip:alice@[local_ip]:[local_port]
Max-Forwards: 70
Subject: Performance Test
Content-Type: application/sdp
Content-Length: [len]
v=0
o=user1 53655765 2353687637 IN IP[local_ip_type] [local_ip]
s=-
c=IN IP[media_ip_type] [media_ip]
t=0 0
m=audio [media_port] RTP/AVP 0
a=rtpmap:0 PCMU/8000
]]>
</send>

<recv response="100"
optional="true">
</recv>

<recv response="181"
optional="true">
</recv>

<recv response="180" optional="true">
</recv>

<recv response="183" optional="true">
</recv>

<recv response="200" rtd="true">
</recv>

<send>
<![CDATA[
ACK sip:[service]@[remote_ip]:[remote_port] SIP/2.0
Via: SIP/2.0/[transport] [local_ip]:[local_port];branch=[branch]
From: sipp <sip:sipp@[local_ip]:[local_port]>;tag=[pid]SIPpTag00[call_number]
To: sut <sip:[service]@[remote_ip]:[remote_port]>[peer_tag_param]
Call-ID: [call_id]
CSeq: 1 ACK
Contact: sip:sipp@[local_ip]:[local_port]
Max-Forwards: 70
Subject: Performance Test
Content-Length: 0
]]>
</send>

<recv request="BYE">
</recv>

<send>
<![CDATA[
SIP/2.0 200 OK
[last_Via:]
[last_From:]
[last_To:]
[last_Call-ID:]
[last_CSeq:]
Contact: <sip:[local_ip]:[local_port];transport=[transport]>
Content-Length: 0
]]>
</send>

<timewait milliseconds="1000"/>

<ResponseTimeRepartition value="10, 20, 30, 40, 50, 100, 150, 200"/>

<CallLengthRepartition value="10, 50, 100, 500, 1000, 5000, 10000"/>

</scenario>

Loading

0 comments on commit 3220993

Please sign in to comment.