From b878e61f03d763042f7b310ce6bf5bc1f66778d9 Mon Sep 17 00:00:00 2001 From: Stephen Paul Weber Date: Mon, 11 Oct 2021 09:12:33 -0500 Subject: [PATCH 1/2] Catchable CustomerRepo::NotFound --- lib/customer_repo.rb | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/customer_repo.rb b/lib/customer_repo.rb index 169006a3d3ceaa337f7f6bd8e5740ed6b11892f9..c45c8fc50f056b67d978ee224495535244561c14 100644 --- a/lib/customer_repo.rb +++ b/lib/customer_repo.rb @@ -7,6 +7,8 @@ require_relative "legacy_customer" require_relative "polyfill" class CustomerRepo + class NotFound < RuntimeError; end + def initialize( redis: LazyObject.new { REDIS }, db: LazyObject.new { DB }, @@ -21,7 +23,7 @@ class CustomerRepo def find(customer_id) @redis.get("jmp_customer_jid-#{customer_id}").then do |jid| - raise "No jid" unless jid + raise NotFound, "No jid" unless jid find_inner(customer_id, jid) end end @@ -30,18 +32,16 @@ class CustomerRepo if jid.to_s =~ /\Acustomer_(.+)@#{CONFIG[:component][:jid]}\Z/ find($1) else - @redis.get("jmp_customer_id-#{jid}").then { |customer_id| - raise "No customer id" unless customer_id + @redis.get("jmp_customer_id-#{jid}").then do |customer_id| + next find_legacy_customer(jid) unless customer_id find_inner(customer_id, jid) - }.catch do - find_legacy_customer(jid) end end end def find_by_tel(tel) @redis.get("catapult_jid-#{tel}").then do |jid| - raise "No jid" unless jid + raise NotFound, "No jid" unless jid find_by_jid(jid) end end @@ -69,7 +69,7 @@ protected def find_legacy_customer(jid) @redis.lindex("catapult_cred-#{jid}", 3).then do |tel| - raise "No customer" unless tel + raise NotFound, "No customer" unless tel LegacyCustomer.new(Blather::JID.new(jid), tel) end end From 46b3f4f4c0dac319e1a9d5ed29465ccb6c8760dc Mon Sep 17 00:00:00 2001 From: Stephen Paul Weber Date: Mon, 11 Oct 2021 09:16:31 -0500 Subject: [PATCH 2/2] Customer not found, return auth error instead of panic --- sgx_jmp.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/sgx_jmp.rb b/sgx_jmp.rb index fc3407c5e73b63c2e2c8ff6866f1323c3e107675..80dce0e3bc0f2c6bc810482e4cac87f5b5e2a497 100644 --- a/sgx_jmp.rb +++ b/sgx_jmp.rb @@ -269,6 +269,8 @@ message( m.to = m.to.with(domain: customer.jid.domain) address["jid"] = customer.jid.to_s BLATHER << m + }.catch_only(CustomerRepo::NotFound) { |e| + BLATHER << iq.as_error("forbidden", :auth, e.message) }.catch { |e| panic(e, sentry_hub) } end