From eecf45449fe07c107427ff15ede05d765049f5f3 Mon Sep 17 00:00:00 2001 From: Stephen Paul Weber Date: Mon, 17 May 2021 12:11:48 -0500 Subject: [PATCH] Configure number for inbound calls Adds the settings to redis that jmp-fwdcalls will use to route inbound calls. Not done by the sgx registration even though fwdcalls is currently a plug-over, and of course won't be once fwdcalls dies so do it here. --- .rubocop.yml | 4 ++++ lib/registration.rb | 22 +++++++++++++++++++++- test/test_registration.rb | 19 ++++++++++++++++++- 3 files changed, 43 insertions(+), 2 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 72686f4..6a57be3 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -10,6 +10,10 @@ Metrics/MethodLength: Exclude: - test/* +Metrics/ClassLength: + Exclude: + - test/* + Metrics/AbcSize: Exclude: - test/* diff --git a/lib/registration.rb b/lib/registration.rb index bb5d02b..2b64c12 100644 --- a/lib/registration.rb +++ b/lib/registration.rb @@ -1,5 +1,7 @@ # frozen_string_literal: true +require "erb" + require_relative "./oob" class Registration @@ -285,7 +287,7 @@ class Registration def write BandwidthTNOrder.create(@tel).then(&:poll).then( - ->(_) { @customer.register!(@tel).then { BLATHER << @reply } }, + ->(_) { customer_active_tel_purchased }, lambda do |_| @reply.note_type = :error @reply.note_text = @@ -295,5 +297,23 @@ class Registration end ) end + + protected + + def cheogram_sip_addr + "sip:#{ERB::Util.url_encode(@reply.to.stripped.to_s)}@sip.cheogram.com" + end + + def customer_active_tel_purchased + @customer.register!(@tel).then { + EMPromise.all([ + REDIS.set("catapult_fwd-#{@tel}", cheogram_sip_addr), + REDIS.set( + "catapult_fwd_timeout-#{@reply.to.stripped}", + 25 # ~5 seconds / ring, 5 rings + ) + ]) + }.then { BLATHER << @reply } + end end end diff --git a/test/test_registration.rb b/test/test_registration.rb index 3b88760..7320d2d 100644 --- a/test/test_registration.rb +++ b/test/test_registration.rb @@ -289,10 +289,13 @@ class RegistrationTest < Minitest::Test class FinishTest < Minitest::Test Registration::Finish::BLATHER = Minitest::Mock.new + Registration::Finish::REDIS = Minitest::Mock.new def setup + iq = Blather::Stanza::Iq::Command.new + iq.from = "test\\40example.com@cheogram.com" @finish = Registration::Finish.new( - Blather::Stanza::Iq::Command.new, + iq, Customer.new("test"), "+15555550000" ) @@ -322,6 +325,19 @@ class RegistrationTest < Minitest::Test EMPromise.resolve(OpenStruct.new(error?: false)), ["test", "+15555550000"] ) + Registration::Finish::REDIS.expect( + :set, + nil, + [ + "catapult_fwd-+15555550000", + "sip:test%5C40example.com%40cheogram.com@sip.cheogram.com" + ] + ) + Registration::Finish::REDIS.expect( + :set, + nil, + ["catapult_fwd_timeout-test\\40example.com@cheogram.com", 25] + ) Registration::Finish::BLATHER.expect( :<<, nil, @@ -337,6 +353,7 @@ class RegistrationTest < Minitest::Test @finish.write.sync assert_requested create_order BACKEND_SGX.verify + Registration::Finish::REDIS.verify Registration::Finish::BLATHER.verify end em :test_write -- 2.34.5