From 3220993aa8df248926a98f5912a1bd5ec1ca14bc Mon Sep 17 00:00:00 2001 From: Ben Ford Date: Tue, 21 May 2024 11:44:18 -0500 Subject: [PATCH] Add tests for tenant identifier. 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. --- tests/extra_gates/tenant_id | 1 + tests/extra_gates/tests.yaml | 3 + .../configs/ast1/extensions.conf | 6 ++ .../tenant_id_ami/configs/ast1/pjsip.conf | 17 ++++ tests/tenant_id/tenant_id_ami/sipp/echo.xml | 85 ++++++++++++++++++ .../tenant_id/tenant_id_ami/test-config.yaml | 47 ++++++++++ .../configs/ast1/extensions.conf | 7 ++ tests/tenant_id/tenant_id_ari/tenant_id.py | 14 +++ .../tenant_id/tenant_id_ari/test-config.yaml | 39 ++++++++ .../configs/ast1/extensions.conf | 12 +++ .../configs/ast1/pjsip.conf | 34 +++++++ .../tenant_id_dialplan/sipp/uac-no-hangup.xml | 90 +++++++++++++++++++ .../tenant_id_dialplan/test-config.yaml | 53 +++++++++++ tests/tenant_id/tests.yaml | 5 ++ tests/tests.yaml | 2 + 15 files changed, 415 insertions(+) create mode 120000 tests/extra_gates/tenant_id create mode 100644 tests/extra_gates/tests.yaml create mode 100644 tests/tenant_id/tenant_id_ami/configs/ast1/extensions.conf create mode 100644 tests/tenant_id/tenant_id_ami/configs/ast1/pjsip.conf create mode 100644 tests/tenant_id/tenant_id_ami/sipp/echo.xml create mode 100644 tests/tenant_id/tenant_id_ami/test-config.yaml create mode 100644 tests/tenant_id/tenant_id_ari/configs/ast1/extensions.conf create mode 100644 tests/tenant_id/tenant_id_ari/tenant_id.py create mode 100644 tests/tenant_id/tenant_id_ari/test-config.yaml create mode 100644 tests/tenant_id/tenant_id_dialplan/configs/ast1/extensions.conf create mode 100644 tests/tenant_id/tenant_id_dialplan/configs/ast1/pjsip.conf create mode 100644 tests/tenant_id/tenant_id_dialplan/sipp/uac-no-hangup.xml create mode 100644 tests/tenant_id/tenant_id_dialplan/test-config.yaml create mode 100644 tests/tenant_id/tests.yaml diff --git a/tests/extra_gates/tenant_id b/tests/extra_gates/tenant_id new file mode 120000 index 000000000..ffbe6aaf7 --- /dev/null +++ b/tests/extra_gates/tenant_id @@ -0,0 +1 @@ +./../tenant_id \ No newline at end of file diff --git a/tests/extra_gates/tests.yaml b/tests/extra_gates/tests.yaml new file mode 100644 index 000000000..fbbccd25c --- /dev/null +++ b/tests/extra_gates/tests.yaml @@ -0,0 +1,3 @@ +# Enter tests here in the order they should be considered for execution: +tests: + - dir: 'tenant_id' diff --git a/tests/tenant_id/tenant_id_ami/configs/ast1/extensions.conf b/tests/tenant_id/tenant_id_ami/configs/ast1/extensions.conf new file mode 100644 index 000000000..6199b225e --- /dev/null +++ b/tests/tenant_id/tenant_id_ami/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/tenant_id/tenant_id_ami/configs/ast1/pjsip.conf b/tests/tenant_id/tenant_id_ami/configs/ast1/pjsip.conf new file mode 100644 index 000000000..97a61b922 --- /dev/null +++ b/tests/tenant_id/tenant_id_ami/configs/ast1/pjsip.conf @@ -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 diff --git a/tests/tenant_id/tenant_id_ami/sipp/echo.xml b/tests/tenant_id/tenant_id_ami/sipp/echo.xml new file mode 100644 index 000000000..c8b0efc3d --- /dev/null +++ b/tests/tenant_id/tenant_id_ami/sipp/echo.xml @@ -0,0 +1,85 @@ + + + + + + ;tag=[call_number] + To: test + Call-ID: [call_id] + CSeq: 1 INVITE + Contact: + 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 + + ]]> + + + + + + + + + + ;tag=[call_number] + To: test [peer_tag_param] + Call-ID: [call_id] + CSeq: 1 ACK + Contact: + Max-Forwards: 70 + Subject: Test + Content-Length: 0 + + ]]> + + + + + + ;tag=[call_number] + To: test [peer_tag_param] + Call-ID: [call_id] + CSeq: 2 BYE + Contact: + Max-Forwards: 70 + Subject: Test + Content-Length: 0 + + ]]> + + + + + + + + + + + + + diff --git a/tests/tenant_id/tenant_id_ami/test-config.yaml b/tests/tenant_id/tenant_id_ami/test-config.yaml new file mode 100644 index 000000000..9fc9878c3 --- /dev/null +++ b/tests/tenant_id/tenant_id_ami/test-config.yaml @@ -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 diff --git a/tests/tenant_id/tenant_id_ari/configs/ast1/extensions.conf b/tests/tenant_id/tenant_id_ari/configs/ast1/extensions.conf new file mode 100644 index 000000000..597a7f661 --- /dev/null +++ b/tests/tenant_id/tenant_id_ari/configs/ast1/extensions.conf @@ -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() diff --git a/tests/tenant_id/tenant_id_ari/tenant_id.py b/tests/tenant_id/tenant_id_ari/tenant_id.py new file mode 100644 index 000000000..0634b8d64 --- /dev/null +++ b/tests/tenant_id/tenant_id_ari/tenant_id.py @@ -0,0 +1,14 @@ +''' +Copyright (C) 2024, Sangoma, Inc. +Ben Ford + +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 diff --git a/tests/tenant_id/tenant_id_ari/test-config.yaml b/tests/tenant_id/tenant_id_ari/test-config.yaml new file mode 100644 index 000000000..557215c2e --- /dev/null +++ b/tests/tenant_id/tenant_id_ari/test-config.yaml @@ -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 diff --git a/tests/tenant_id/tenant_id_dialplan/configs/ast1/extensions.conf b/tests/tenant_id/tenant_id_dialplan/configs/ast1/extensions.conf new file mode 100644 index 000000000..795985e99 --- /dev/null +++ b/tests/tenant_id/tenant_id_dialplan/configs/ast1/extensions.conf @@ -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() diff --git a/tests/tenant_id/tenant_id_dialplan/configs/ast1/pjsip.conf b/tests/tenant_id/tenant_id_dialplan/configs/ast1/pjsip.conf new file mode 100644 index 000000000..b40d085dc --- /dev/null +++ b/tests/tenant_id/tenant_id_dialplan/configs/ast1/pjsip.conf @@ -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 diff --git a/tests/tenant_id/tenant_id_dialplan/sipp/uac-no-hangup.xml b/tests/tenant_id/tenant_id_dialplan/sipp/uac-no-hangup.xml new file mode 100644 index 000000000..204532991 --- /dev/null +++ b/tests/tenant_id/tenant_id_dialplan/sipp/uac-no-hangup.xml @@ -0,0 +1,90 @@ + + + + + + ;tag=[pid]SIPpTag00[call_number] + To: sut + 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 + + ]]> + + + + + + + + + + + + + + + + + + + ;tag=[pid]SIPpTag00[call_number] + To: sut [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 + + ]]> + + + + + + + + Content-Length: 0 + + ]]> + + + + + + + + + + diff --git a/tests/tenant_id/tenant_id_dialplan/test-config.yaml b/tests/tenant_id/tenant_id_dialplan/test-config.yaml new file mode 100644 index 000000000..ac2145568 --- /dev/null +++ b/tests/tenant_id/tenant_id_dialplan/test-config.yaml @@ -0,0 +1,53 @@ +testinfo: + summary: 'Tests tenantid for a channel in dialplan' + description: | + 'Tests that tenantid is either present or not present + for a channel in dialplan depending on whether or not + it has been set.' + +test-modules: + test-object: + config-section: test-object-config + typename: 'sipp.SIPpTestCase' + modules: + - + config-section: ami-config + typename: 'ami.AMIEventModule' + +test-object-config: + memcheck-delay-stop: 7 + test-iterations: + - + scenarios: + - { 'key-args': { 'scenario': 'uac-no-hangup.xml', '-p': '5062', '-i': '127.0.0.1', + '-s': 'alice', '-rsa': '127.0.0.1:5061', '-s': 'alice', '-mp': '9050'} } + +ami-config: + - + id: '0' + type: 'headermatch' + count: '1' + conditions: + match: + Event: 'UserEvent' + requirements: + match: + Status: 'passed' + - + id: '0' + type: 'headermatch' + count: '0' + conditions: + match: + Event: 'UserEvent' + Status: 'failed' + +properties: + dependencies: + - python : 'twisted' + - python : 'starpy' + - asterisk : 'res_pjsip' + - asterisk : 'res_pjsip_session' + - asterisk : 'chan_pjsip' + tags: + - pjsip diff --git a/tests/tenant_id/tests.yaml b/tests/tenant_id/tests.yaml new file mode 100644 index 000000000..05b3f485e --- /dev/null +++ b/tests/tenant_id/tests.yaml @@ -0,0 +1,5 @@ +# Enter tests here in the order they should be considered for execution: +tests: + - test: 'tenant_id_ami' + - test: 'tenant_id_ari' + - test: 'tenant_id_dialplan' diff --git a/tests/tests.yaml b/tests/tests.yaml index fc5321a0f..a5d27f893 100644 --- a/tests/tests.yaml +++ b/tests/tests.yaml @@ -37,3 +37,5 @@ tests: - test: 'remote-test' - dir: 'codecs' - dir: 'rtp' + - dir: 'tenant_id' + - dir: 'extra_gates'