Skip to content

Commit

Permalink
[Unit-tests] Add a unit-test for the compact form and full form of th…
Browse files Browse the repository at this point in the history
…e Identity header.
  • Loading branch information
dhruvecosmob authored and andywolk committed Oct 23, 2021
1 parent 7bfc9a5 commit 715f9e4
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 8 deletions.
2 changes: 1 addition & 1 deletion tests/unit/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<load module="mod_tone_stream"/>
<load module="mod_commands"/>
<load module="mod_sndfile"/>
<load module="mod_hash"/>
</modules>
</configuration>

Expand All @@ -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"/>
Expand All @@ -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"/>
Expand Down Expand Up @@ -104,7 +105,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="61069"/>
Expand Down Expand Up @@ -144,12 +145,20 @@

<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>
Expand Down
Original file line number Diff line number Diff line change
@@ -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"/>
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/switch_hold.c
Original file line number Diff line number Diff line change
@@ -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)
{
Expand All @@ -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);

Expand Down
95 changes: 95 additions & 0 deletions tests/unit/switch_sip.c
Original file line number Diff line number Diff line change
@@ -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()

1 comment on commit 715f9e4

@andywolk
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.