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

[37290] Use login service for logging in user (#9290)

Oliver Günther2cf8cd0d84b5
diff --git a/app/controllers/concerns/auth_source_sso.rb b/app/controllers/concerns/auth_source_sso.rb
index 41708f797d3..6d422c802b1 100644
--- a/app/controllers/concerns/auth_source_sso.rb
+++ b/app/controllers/concerns/auth_source_sso.rb
@@ -143,7 +143,7 @@ module AuthSourceSSO
end
def handle_sso_success(user)
- session[:user_id] = user.id
+ login_user(user)
session[:user_from_auth_header] = true
user
diff --git a/spec/controllers/concerns/auth_source_sso_spec.rb b/spec/controllers/concerns/auth_source_sso_spec.rb
index 282fdddc249..5cae56dd732 100644
--- a/spec/controllers/concerns/auth_source_sso_spec.rb
+++ b/spec/controllers/concerns/auth_source_sso_spec.rb
@@ -45,7 +45,7 @@ describe MyController, type: :controller do
let(:secret) { "42" }
let!(:auth_source) { DummyAuthSource.create name: "Dummy LDAP" }
- let!(:user) { FactoryBot.create :user, login: login, auth_source_id: auth_source.id }
+ let!(:user) { FactoryBot.create :user, login: login, auth_source_id: auth_source.id, last_login_on: 5.days.ago }
let(:login) { "h.wurst" }
shared_examples "auth source sso failure" do
@@ -106,6 +106,7 @@ describe MyController, type: :controller do
it "should log in given user" do
expect(response.body.squish).to have_content("Username h.wurst")
+ expect(user.reload.last_login_on).to be_within(10.seconds).of(Time.now)
end
end