From d48161885733c96362c66b8f3630a9799f0db4f4 Mon Sep 17 00:00:00 2001 From: Zach Margolis Date: Wed, 29 May 2024 14:38:23 -0700 Subject: [PATCH 1/3] Unify SpHandoffBounce classes **Why**: Combines two separate one-method classes into one class, adds unit test coverage changelog: Internal, Source code, Unify related classes --- .../openid_connect/authorization_controller.rb | 8 ++++++-- .../add_handoff_time_to_session.rb | 9 --------- app/services/sp_handoff_bounce/is_bounced.rb | 13 ------------- 3 files changed, 6 insertions(+), 24 deletions(-) delete mode 100644 app/services/sp_handoff_bounce/add_handoff_time_to_session.rb delete mode 100644 app/services/sp_handoff_bounce/is_bounced.rb diff --git a/app/controllers/openid_connect/authorization_controller.rb b/app/controllers/openid_connect/authorization_controller.rb index 85e80de2676..76bfbada3a2 100644 --- a/app/controllers/openid_connect/authorization_controller.rb +++ b/app/controllers/openid_connect/authorization_controller.rb @@ -74,7 +74,7 @@ def check_sp_active end def check_sp_handoff_bounced - return unless SpHandoffBounce::IsBounced.call(sp_session) + return unless sp_handoff_bouncer.bounced? analytics.sp_handoff_bounced_detected redirect_to bounced_url true @@ -120,7 +120,7 @@ def resolved_authn_context_int_ial def handle_successful_handoff track_events - SpHandoffBounce::AddHandoffTimeToSession.call(sp_session) + sp_handoff_bouncer.add_handoff_time! redirect_user( @authorize_form.success_redirect_uri, @@ -261,5 +261,9 @@ def redirect_user(redirect_uri, issuer, user_uuid) ) end end + + def sp_handoff_bouncer + @sp_handoff_bouncer ||= SpHandoffBouncer.new(sp_session) + end end end diff --git a/app/services/sp_handoff_bounce/add_handoff_time_to_session.rb b/app/services/sp_handoff_bounce/add_handoff_time_to_session.rb deleted file mode 100644 index e3f96b83ccf..00000000000 --- a/app/services/sp_handoff_bounce/add_handoff_time_to_session.rb +++ /dev/null @@ -1,9 +0,0 @@ -# frozen_string_literal: true - -module SpHandoffBounce - class AddHandoffTimeToSession - def self.call(session) - session[:sp_handoff_start_time] = Time.zone.now - end - end -end diff --git a/app/services/sp_handoff_bounce/is_bounced.rb b/app/services/sp_handoff_bounce/is_bounced.rb deleted file mode 100644 index 5c4db9ebe6d..00000000000 --- a/app/services/sp_handoff_bounce/is_bounced.rb +++ /dev/null @@ -1,13 +0,0 @@ -# frozen_string_literal: true - -module SpHandoffBounce - class IsBounced - def self.call(session) - start_time = session[:sp_handoff_start_time] - return if start_time.blank? - tz = Time.zone - start_time = tz.parse(start_time) if start_time.instance_of?(String) - tz.now <= (start_time + IdentityConfig.store.sp_handoff_bounce_max_seconds.seconds) - end - end -end From 7763502a9b62b3a5591e116f4cf1a712bbd2acfe Mon Sep 17 00:00:00 2001 From: Zach Margolis Date: Wed, 29 May 2024 14:52:51 -0700 Subject: [PATCH 2/3] Commit missing class, oops --- app/services/sp_handoff_bouncer.rb | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 app/services/sp_handoff_bouncer.rb diff --git a/app/services/sp_handoff_bouncer.rb b/app/services/sp_handoff_bouncer.rb new file mode 100644 index 00000000000..8790d2a61fa --- /dev/null +++ b/app/services/sp_handoff_bouncer.rb @@ -0,0 +1,18 @@ +class SpHandoffBouncer + attr_reader :sp_session + + def initialize(sp_session) + @sp_session = sp_session + end + + def add_handoff_time!(now = Time.zone.now) + sp_session[:sp_handoff_start_time] = now + end + + def bounced?(now = Time.zone.now) + start_time = sp_session[:sp_handoff_start_time] + return false if start_time.blank? + start_time = Time.zone.parse(start_time) if start_time.instance_of?(String) + now <= (start_time + IdentityConfig.store.sp_handoff_bounce_max_seconds.seconds) + end +end From b57d6ff6c6d861ab272e7210423885e79680f144 Mon Sep 17 00:00:00 2001 From: Zach Margolis Date: Wed, 29 May 2024 14:53:28 -0700 Subject: [PATCH 3/3] lint fix --- app/services/sp_handoff_bouncer.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/services/sp_handoff_bouncer.rb b/app/services/sp_handoff_bouncer.rb index 8790d2a61fa..7f210bed49a 100644 --- a/app/services/sp_handoff_bouncer.rb +++ b/app/services/sp_handoff_bouncer.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class SpHandoffBouncer attr_reader :sp_session