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
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
Properly check whether user is locked
Jan Sandbrinkcfcb7f38747b
diff --git a/lib_static/open_project/authentication/strategies/warden/doorkeeper_oauth.rb b/lib_static/open_project/authentication/strategies/warden/doorkeeper_oauth.rbindex 60adb896618..bd336317b5e 100644--- a/lib_static/open_project/authentication/strategies/warden/doorkeeper_oauth.rb+++ b/lib_static/open_project/authentication/strategies/warden/doorkeeper_oauth.rb@@ -43,7 +43,7 @@ module OpenProjectdef authenticate_user(id)user = id && User.find_by(id:)- if user+ if user&.active?success!(user)elsefail_with_header!(error: "invalid_token")diff --git a/spec/requests/api/v3/authentication_spec.rb b/spec/requests/api/v3/authentication_spec.rbindex 7d38c757421..cf01ce750e4 100644--- a/spec/requests/api/v3/authentication_spec.rb+++ b/spec/requests/api/v3/authentication_spec.rb@@ -149,6 +149,18 @@ RSpec.describe "API V3 Authentication" doendend+ context "when the token's resource owner is locked" do+ let(:token) { create(:oauth_access_token, resource_owner: user) }+ let(:oauth_access_token) { token.plaintext_token }+ let(:user) { create(:user, :locked) }++ it "returns unauthorized" do+ expect(last_response).to have_http_status :unauthorized+ expect(last_response.header["WWW-Authenticate"]).to eq('Bearer realm="OpenProject API", error="invalid_token"')+ expect(JSON.parse(last_response.body)).to eq(error_response_body)+ end+ end+context "when there is no resource owner on the token" dolet(:token) { create(:oauth_access_token, resource_owner: nil, application:) }let(:application) { create(:oauth_application) }@@ -173,6 +185,17 @@ RSpec.describe "API V3 Authentication" doit "authenticates successfully" doexpect(last_response).to have_http_status :okend++ context "and the client credentials user is locked" do+ let(:user) { create(:user, :locked) }+ let(:expected_message) { "You did not provide the correct credentials." }++ it "returns unauthorized" do+ expect(last_response).to have_http_status :unauthorized+ expect(last_response.header["WWW-Authenticate"]).to eq('Bearer realm="OpenProject API", error="invalid_token"')+ expect(JSON.parse(last_response.body)).to eq(error_response_body)+ end+ endendendend