diff --git a/components/app/lib/call_platform/fake_client.rb b/components/app/lib/call_platform/fake_client.rb index c6cbc289a..55f5fd2ea 100644 --- a/components/app/lib/call_platform/fake_client.rb +++ b/components/app/lib/call_platform/fake_client.rb @@ -33,9 +33,34 @@ def audio_file_url end end + class DialTestNumber < TestNumber + Number = Data.define(:number) + + DIAL_TO = [ + Number.new(number: "85516701999"), + Number.new(number: "855715100999") + ].freeze + + def twiml_response + <<~TWIML + + + #{self.class.dial_to[0].number} + #{self.class.dial_to[1].number} + + + TWIML + end + + def self.dial_to + DIAL_TO + end + end + TEST_NUMBERS = [ TestNumber.new(number: "1111", twiml_response: "Hello World!"), - ConnectTestNumberWithTwiMLResponse.new(number: "2222") + ConnectTestNumberWithTwiMLResponse.new(number: "2222"), + DialTestNumber.new(number: "3333") ].freeze def create_inbound_call(params) @@ -62,6 +87,27 @@ def create_media_stream(**) AudioStreamResponse.new(id: SecureRandom.uuid) end + def create_outbound_calls(params) + DialTestNumber.dial_to.map do |n| + OutboundPhoneCallResponse.new( + sid: SecureRandom.uuid, + parent_call_sid: params.fetch(:parent_call_sid), + account_sid: SecureRandom.uuid, + from: params.fetch(:from) || "855715100850", + routing_parameters: { + destination: n.number, + dial_string_prefix: nil, + plus_prefix: false, + national_dialing: false, + host: "sip.example.com", + username: nil, + symmetric_latching: true + }, + address: nil + ) + end + end + private def validate_gateway_headers(params) diff --git a/components/app/spec/lib/call_platform/fake_client_spec.rb b/components/app/spec/lib/call_platform/fake_client_spec.rb index eaea0bc18..4c75a4208 100644 --- a/components/app/spec/lib/call_platform/fake_client_spec.rb +++ b/components/app/spec/lib/call_platform/fake_client_spec.rb @@ -45,6 +45,19 @@ module CallPlatform twiml: include("") ) end + + it "returns a mock response" do + client = FakeClient.new + + response = client.create_inbound_call( + to: "3333", + from: "+855715200987" + ) + + expect(response).to have_attributes( + twiml: include("") + ) + end end describe "#create_media_stream" do @@ -61,5 +74,34 @@ module CallPlatform ) end end + + describe "#create_outbound_calls" do + it "returns mock outbound calls" do + client = FakeClient.new + + response = client.create_outbound_calls( + destinations: [ "85516701999", "855715100999" ], + parent_call_sid: "0df546d9-3348-48a7-b797-5a18dac477d2", + from: nil + ) + + expect(response).to contain_exactly( + have_attributes( + from: "855715100850", + parent_call_sid: "0df546d9-3348-48a7-b797-5a18dac477d2", + routing_parameters: hash_including( + destination: "85516701999" + ) + ), + have_attributes( + from: "855715100850", + parent_call_sid: "0df546d9-3348-48a7-b797-5a18dac477d2", + routing_parameters: hash_including( + destination: "855715100999" + ) + ) + ) + end + end end end diff --git a/components/testing/tests/public_gateway/dial_test.sh b/components/testing/tests/public_gateway/dial_test.sh new file mode 100755 index 000000000..36ce458b5 --- /dev/null +++ b/components/testing/tests/public_gateway/dial_test.sh @@ -0,0 +1,68 @@ +#!/bin/sh + +set -e + +current_dir=$(dirname "$(readlink -f "$0")") +source $current_dir/support/test_helpers.sh +source $current_dir/../support/test_helpers.sh + +scenario=$current_dir/../../scenarios/uac_connect.xml +artifacts_dir=dial_test_files + +log_file="uac_connect_*_messages.log" +rm -f $log_file + +media_server="$(dig +short freeswitch)" + +reset_db +create_load_balancer_entry "gw" "5060" +create_address_entry $(hostname -i) +reload_opensips_tables + +rm -rf $artifacts_dir +mkdir -p $artifacts_dir + +# start tcpdump in background +nohup tcpdump -Xvv -i eth0 -s0 -w $artifacts_dir/uac_connect.pcap & +tcpdump_pid=$! + +sipp -sf $scenario public_gateway:5060 -key username "+855715100850" -s 3333 -m 1 -trace_msg > /dev/null + +reset_db + +# kill tcpdump +kill $tcpdump_pid + +# extract RTP from PCAP +# tshark -n -r $artifacts_dir/uac_connect.pcap -2 -R rtp -T fields -e rtp.payload | tr -d '\n',':' | xxd -r -p > $artifacts_dir/uac_connect.rtp +# # Convert RTP to wav +# sox -t al -r 8000 -c 1 $artifacts_dir/uac_connect.rtp $artifacts_dir/uac_connect_full_audio.wav +# # Cut the audio from the ws server +# ffmpeg -y -i $artifacts_dir/uac_connect_full_audio.wav -ss 8.5 -to 12 $artifacts_dir/uac_connect_ws_server_audio.wav 2> /dev/null +# # Remove silence +# ffmpeg -y -i $artifacts_dir/uac_connect_ws_server_audio.wav -af silenceremove=1:0:-30dB,areverse,silenceremove=1:0:-30dB,areverse $artifacts_dir/uac_connect_trimmed_ws_server_audio.wav 2> /dev/null +# # Cut the play verb audio +# ffmpeg -y -i $artifacts_dir/uac_connect_full_audio.wav -ss 12.2 $artifacts_dir/uac_connect_play_verb_audio.wav 2> /dev/null +# # Remove silence +# ffmpeg -y -i $artifacts_dir/uac_connect_play_verb_audio.wav -af silenceremove=1:0:-30dB,areverse,silenceremove=1:0:-30dB,areverse $artifacts_dir/uac_connect_trimmed_play_verb_audio.wav 2> /dev/null + +# ws_server_audio_md5=$(md5sum $artifacts_dir/uac_connect_trimmed_ws_server_audio.wav | head -c 32) +# play_verb_audio_md5=$(md5sum $artifacts_dir/uac_connect_trimmed_play_verb_audio.wav | head -c 32) +# expected_audio_md5="1c1542575c47ef620c8344438e75095f" + +# echo "Actual ws_server_audio_md5: $ws_server_audio_md5" +# echo "Actual play_verb_audio_md5: $play_verb_audio_md5" +# echo "Expected audio_md5: $expected_audio_md5" + +# if [[ "$ws_server_audio_md5" != "$expected_audio_md5" ]]; then +# exit 1 +# fi + +# if [[ "$play_verb_audio_md5" != "$expected_audio_md5" ]]; then +# exit 1 +# fi + +# # Assert correct IP in SDP +# if ! assert_in_file $log_file "c=IN IP4 $media_server"; then +# exit 1 +# fi