From c49b2c6ed2fabce87d87ca0e03821fca12d27be8 Mon Sep 17 00:00:00 2001 From: Stephen Paul Weber Date: Wed, 25 Aug 2021 12:48:57 -0500 Subject: [PATCH] No more legacy session for BTC Set the same key as web register manager, so that on next register jmp.chat the tel we were using in this flow will be used. Not needed if they came from web register, but will still extend expiry in that case and no harm. Clean up pending tel key on Finish. --- lib/registration.rb | 20 ++++++++------------ test/test_registration.rb | 5 +++++ 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/lib/registration.rb b/lib/registration.rb index bf41946fffaff3d5291df525c8e36c12815a8f2e..a34bdec776f1dd4bf1db1d3705ee50ee6c0dee48 100644 --- a/lib/registration.rb +++ b/lib/registration.rb @@ -157,6 +157,8 @@ class Registration class Bitcoin Payment.kinds[:bitcoin] = method(:new) + THIRTY_DAYS = 60 * 60 * 24 * 30 + def initialize(customer, tel) @customer = customer @customer_id = customer.customer_id @@ -165,20 +167,13 @@ class Registration attr_reader :customer_id, :tel - def legacy_session_save - sid = SecureRandom.hex - REDIS.mset( - "reg-sid_for-#{customer_id}", sid, - "reg-session_tel-#{sid}", tel - ) - end - def save EMPromise.all([ - legacy_session_save, - REDIS.mset( - "pending_tel_for-#{customer_id}", tel, - "pending_plan_for-#{customer_id}", @customer.plan_name + REDIS.setex("pending_tel_for-#{@customer.jid}", tel, THIRTY_DAYS), + REDIS.setex( + "pending_plan_for-#{customer_id}", + @customer.plan_name, + THIRTY_DAYS ) ]) end @@ -458,6 +453,7 @@ class Registration def customer_active_tel_purchased @customer.register!(@tel).catch(&method(:raise_setup_error)).then { EMPromise.all([ + REDIS.del("pending_tel_for-#{@customer.jid}"), REDIS.set("catapult_fwd-#{@tel}", cheogram_sip_addr), @customer.fwd_timeout = 25 # ~5 seconds / ring, 5 rings ]) diff --git a/test/test_registration.rb b/test/test_registration.rb index 06dd58ffcb8950365d6f6305843ce421641935d2..f82c9eb2e966ab3f1d6cc055b0a6de8a77fa3d3a 100644 --- a/test/test_registration.rb +++ b/test/test_registration.rb @@ -569,6 +569,11 @@ class RegistrationTest < Minitest::Test "sip:test%40example.net@sip.cheogram.com" ] ) + Registration::Finish::REDIS.expect( + :del, + nil, + ["pending_tel_for-test@example.net"] + ) BackendSgx::REDIS.expect( :set, nil,