]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
[Unit-tests] Add a unit-test for the compact form and full form of the Identity header.
authordhruvecosmob <dhruv.gupta@ecosmob.com>
Mon, 20 Sep 2021 06:39:28 +0000 (09:39 +0300)
committerAndrey Volk <andywolk@gmail.com>
Sat, 23 Oct 2021 19:00:57 +0000 (22:00 +0300)
tests/unit/Makefile.am
tests/unit/conf_test/freeswitch.xml [moved from tests/unit/conf_hold/freeswitch.xml with 92% similarity]
tests/unit/conf_test/gw/test_gateway.xml [moved from tests/unit/conf_hold/gw/holdtest.xml with 92% similarity]
tests/unit/switch_hold.c
tests/unit/switch_sip.c [new file with mode: 0644]

index 3f41d71dda70b09dbe05510020dbc2ec9baec32b..d24e30f62be6e0e8c3d892b81c9e6e3429d86f14 100644 (file)
@@ -4,7 +4,7 @@ noinst_PROGRAMS = switch_event switch_hash switch_ivr_originate switch_utils swi
                           switch_ivr_play_say switch_core_codec switch_rtp switch_xml
 noinst_PROGRAMS += switch_core_video switch_core_db switch_vad switch_packetizer switch_core_session test_sofia switch_ivr_async switch_core_asr switch_log
 
-noinst_PROGRAMS+= switch_hold
+noinst_PROGRAMS+= switch_hold switch_sip
 AM_LDFLAGS += -avoid-version -no-undefined $(SWITCH_AM_LDFLAGS) $(openssl_LIBS)
 AM_LDFLAGS += $(FREESWITCH_LIBS) $(switch_builddir)/libfreeswitch.la $(CORE_LIBS) $(APR_LIBS)
 
similarity index 92%
rename from tests/unit/conf_hold/freeswitch.xml
rename to tests/unit/conf_test/freeswitch.xml
index 883e3846e17a94d2206164157ab248fea2a8fcf0..80216bbe7db9b7eba0390b8f15cf732875cc3924 100644 (file)
@@ -15,6 +15,7 @@
                        <load module="mod_tone_stream"/>
                        <load module="mod_commands"/>
                        <load module="mod_sndfile"/>
+                       <load module="mod_hash"/>
       </modules>
     </configuration>
 
@@ -39,7 +40,7 @@
     <profile name="external">
         <gateways>
 
-           <gateway name="hold_unhold_test">
+           <gateway name="test_gateway">
                 <param name="username" value="not-used"/>
                 <param name="password" value="not-used"/>
                 <param name="proxy" value="$${local_ip_v4}:61068"/>
@@ -62,7 +63,7 @@
         <param name="p-asserted-id-parse" value="verbatim"/>
         <param name="username" value="SignalWire-STACK"/>
         <param name="user-agent-string" value="SignalWire STACK Unit Test"/>
-        <param name="sip-trace" value="yes"/>
+        <param name="sip-trace" value="no"/>
         <param name="sip-capture" value="no"/>
         <param name="rfc2833-pt" value="101"/>
         <param name="sip-port" value="61068"/>
         <param name="p-asserted-id-parse" value="verbatim"/>
         <param name="username" value="SignalWire-STACK"/>
         <param name="user-agent-string" value="SignalWire STACK Unit Test"/>
-        <param name="sip-trace" value="yes"/>
+        <param name="sip-trace" value="no"/>
         <param name="sip-capture" value="no"/>
         <param name="rfc2833-pt" value="101"/>
         <param name="sip-port" value="61069"/>
 
   <section name="dialplan" description="Regex/XML Dialplan">
     <context name="default">
+               <extension name="two">
+                       <condition field="destination_number" expression="^\+15553332901$">
+                               <action application="log" data="${sip_h_identity}"/>
+                               <action application="hash" data="insert/realm/identity_check/${sip_h_identity}"/>
+                               <action application="answer"/>
+                               <action application="park"/>
+                       </condition>
+               </extension>
                <extension name="one">
                        <condition field="destination_number" expression="^\+15553332900$">
                                <action application="set" data="absolute_codec_string=PCMU@20i"/>
                                <action application="info"/>
                                <action application="answer"/>
-                               <action application="park""/>
+                               <action application="park"/>
                        </condition>
                </extension>
     </context>
similarity index 92%
rename from tests/unit/conf_hold/gw/holdtest.xml
rename to tests/unit/conf_test/gw/test_gateway.xml
index d919ddb2d4f91eb09d389587547a50f852ecc6f6..8e8e0ac0758abde248e633a3988a938c52e83a44 100644 (file)
@@ -1,5 +1,5 @@
 <include/>
-    <gateway name="hold_unhold_test">
+    <gateway name="test_gateway">
       <param name="username" value="not-used"/>
       <param name="password" value="not-used"/>
       <param name="proxy" value="127.0.0.1"/>
index 9da8ccfc94407097ea532d665e4d9d66924ed206..e48865155bee0781aed141a594011ab1ba8c7d3f 100644 (file)
@@ -1,7 +1,7 @@
 #include <switch.h>
 #include <test/switch_test.h>
 
-FST_CORE_DB_BEGIN("./conf_hold")
+FST_CORE_DB_BEGIN("./conf_test")
 {
 FST_SUITE_BEGIN(switch_hold)
 {
@@ -23,7 +23,7 @@ FST_SUITE_BEGIN(switch_hold)
                switch_status_t status;
                switch_call_cause_t cause;
 
-               status = switch_ivr_originate(NULL, &session, &cause, "{ignore_early_media=true}sofia/gateway/hold_unhold_test/+15553332900", 2, NULL, NULL, NULL, NULL, NULL, SOF_NONE, NULL, NULL);
+               status = switch_ivr_originate(NULL, &session, &cause, "{ignore_early_media=true}sofia/gateway/test_gateway/+15553332900", 2, NULL, NULL, NULL, NULL, NULL, SOF_NONE, NULL, NULL);
                fst_requires(session);
                fst_check(status == SWITCH_STATUS_SUCCESS);
 
diff --git a/tests/unit/switch_sip.c b/tests/unit/switch_sip.c
new file mode 100644 (file)
index 0000000..238f00a
--- /dev/null
@@ -0,0 +1,95 @@
+#include <switch.h>
+#include <test/switch_test.h>
+
+FST_CORE_DB_BEGIN("./conf_test")
+{
+FST_SUITE_BEGIN(switch_sip)
+{
+       FST_SETUP_BEGIN()
+       {
+               fst_requires_module("mod_sofia");
+               fst_requires_module("mod_hash");
+       }
+       FST_SETUP_END()
+
+       FST_TEARDOWN_BEGIN()
+       {
+       }
+       FST_TEARDOWN_END()
+
+       FST_TEST_BEGIN(identity_compact_check)
+       {
+               switch_core_session_t *session = NULL;
+               switch_call_cause_t cause;
+               const char *data = "eyJhbGciOiJFUzI1NiIsInBwdCI6InNoYWtlbiI;info=<https://cert.sticr.att.net:8443/certs/att/a937bb15-38b9-45f1-aac0-8cd3f8fe0648>";
+               char *originate_str = switch_mprintf("{sip_h_Identity=%s}sofia/gateway/test_gateway/+15553332901", data);
+
+               switch_ivr_originate(NULL, &session, &cause, originate_str, 2, NULL, NULL, NULL, NULL, NULL, SOF_NONE, NULL, NULL);
+               switch_safe_free(originate_str);
+               fst_requires(session);
+
+               if (session) {
+                       switch_channel_t *channel = switch_core_session_get_channel(session);
+                       const char *uuid = switch_core_session_get_uuid(session);
+
+                       fst_requires(channel);
+                       if (uuid) {
+                               switch_stream_handle_t stream = { 0 };
+                               SWITCH_STANDARD_STREAM(stream);
+
+                               switch_api_execute("hash", "select/realm/identity_check", NULL, &stream);
+                               fst_check_string_equals(stream.data, data);
+                               switch_safe_free(stream.data);
+
+                               SWITCH_STANDARD_STREAM(stream);
+                               switch_api_execute("hash", "delete/realm/identity_check", NULL, &stream);
+                               switch_safe_free(stream.data);
+                       }
+
+                       switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING);
+                       switch_core_session_rwunlock(session);
+               }
+
+       }
+       FST_TEST_END()
+
+       FST_TEST_BEGIN(identity_full_check)
+       {
+               switch_core_session_t *session = NULL;
+               switch_call_cause_t cause;
+               const char *data = "eyJhbGciOiJFUzI1NiIsInBwdCI6InNoYWtlbiI;info=<https://cert.sticr.att.net:8443/certs/att/a937bb15-38b9-45f1-aac0-8cd3f8fe0648>;alg=ES256;ppt=shaken";
+               char *originate_str = switch_mprintf("{sip_h_Identity=%s}sofia/gateway/test_gateway/+15553332901", data);
+
+               switch_ivr_originate(NULL, &session, &cause, originate_str, 2, NULL, NULL, NULL, NULL, NULL, SOF_NONE, NULL, NULL);
+               switch_safe_free(originate_str);
+               fst_requires(session);
+
+               if (session) {
+                       switch_channel_t *channel = switch_core_session_get_channel(session);
+                       const char *uuid = switch_core_session_get_uuid(session);
+
+                       fst_requires(channel);
+                       if (uuid) {
+                               switch_stream_handle_t stream = { 0 };
+                               SWITCH_STANDARD_STREAM(stream);
+
+                               switch_api_execute("hash", "select/realm/identity_check", NULL, &stream);
+                               fst_check_string_equals(stream.data, data);
+                               switch_safe_free(stream.data);
+
+                               SWITCH_STANDARD_STREAM(stream);
+                               switch_api_execute("hash", "delete/realm/identity_check", NULL, &stream);
+                               switch_safe_free(stream.data);
+                       }
+
+                       switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING);
+                       switch_core_session_rwunlock(session);
+               }
+
+       }
+       FST_TEST_END()
+}
+FST_SUITE_END()
+}
+FST_CORE_END()
+