Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Correctly handle when expires_in is a string

Jan Sandbrinkf41175c7d0d8
diff --git a/modules/openid_connect/lib/open_project/openid_connect/hooks/hook.rb b/modules/openid_connect/lib/open_project/openid_connect/hooks/hook.rb
index 3c344e33e08..2443a63a552 100644
--- a/modules/openid_connect/lib/open_project/openid_connect/hooks/hook.rb
+++ b/modules/openid_connect/lib/open_project/openid_connect/hooks/hook.rb
@@ -65,11 +65,20 @@ module OpenProject::OpenIDConnect
if OpenIDConnect::Provider.exists?(slug: context.dig(:auth_hash, :provider))
session["omniauth.oidc_access_token"] = context.dig(:auth_hash, :credentials, :token)
session["omniauth.oidc_refresh_token"] = context.dig(:auth_hash, :credentials, :refresh_token)
- session["omniauth.oidc_expires_in"] = context.dig(:auth_hash, :credentials, :expires_in)
+ session["omniauth.oidc_expires_in"] = parse_expires_in(context.dig(:auth_hash, :credentials, :expires_in))
end
nil
end
+
+ private
+
+ def parse_expires_in(expires_in)
+ expires_in = expires_in.to_i
+ return nil if expires_in.zero?
+
+ expires_in
+ end
end
end
end
diff --git a/modules/openid_connect/spec/lib/open_project/openid_connect/hooks/hook_spec.rb b/modules/openid_connect/spec/lib/open_project/openid_connect/hooks/hook_spec.rb
index 27f0e1fbb4c..a47c9bd49b1 100644
--- a/modules/openid_connect/spec/lib/open_project/openid_connect/hooks/hook_spec.rb
+++ b/modules/openid_connect/spec/lib/open_project/openid_connect/hooks/hook_spec.rb
@@ -66,6 +66,26 @@ RSpec.describe OpenProject::OpenIDConnect::Hooks::Hook do
expect(session).to be_empty
end
end
+
+ context "when expires_in is missing" do
+ let(:expires_in) { nil }
+
+ it "does not store an expires_in" do
+ call_hook
+
+ expect(session["omniauth.oidc_expires_in"]).to be_nil
+ end
+ end
+
+ context "when expires_in is passed as a string" do
+ let(:expires_in) { "7200" }
+
+ it "stores expires_in as integer" do
+ call_hook
+
+ expect(session["omniauth.oidc_expires_in"]).to eq(7200)
+ end
+ end
end
describe "#user_logged_in" do