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

[#66706] Responds with 403 and proper message when enterprise plan is not enough.

Pavel Balashoub5e5b00c63c8
diff --git a/app/models/enterprise_token.rb b/app/models/enterprise_token.rb
index 809cbc579ab..4b371f1f282 100644
--- a/app/models/enterprise_token.rb
+++ b/app/models/enterprise_token.rb
@@ -31,6 +31,12 @@ class EnterpriseToken < ApplicationRecord
EXPIRING_SOON_DAYS = 30
class << self
+ def get_feature_plan(feature)
+ OpenProject::Token::FEATURES_PER_PLAN.find do |_plan, features|
+ features.include?(feature.to_sym)
+ end&.first
+ end
+
def all_tokens
all.sort_by(&:sort_key)
end
diff --git a/config/initializers/scimitar.rb b/config/initializers/scimitar.rb
index 02e9e2b92f5..c1c296cc723 100644
--- a/config/initializers/scimitar.rb
+++ b/config/initializers/scimitar.rb
@@ -35,7 +35,15 @@ Rails.application.config.to_prepare do
)
Scimitar.engine_configuration = Scimitar::EngineConfiguration.new(
custom_authenticator: lambda do
- if !EnterpriseToken.allows_to?(:scim_api) || !OpenProject::FeatureDecisions.scim_api_active?
+ if !EnterpriseToken.allows_to?(:scim_api)
+ plan = EnterpriseToken.get_feature_plan(:scim_api)
+ error = Scimitar::ErrorResponse.new(
+ status: 403,
+ detail: "This endpoint requires an enterprise subscription of at least #{plan}"
+ )
+ return handle_scim_error(error)
+ end
+ if !OpenProject::FeatureDecisions.scim_api_active?
return handle_scim_error(Scimitar::AuthenticationError.new)
end
diff --git a/spec/requests/scim_v2/authentication_spec.rb b/spec/requests/scim_v2/authentication_spec.rb
index 6592a02334f..b882dd9ee4d 100644
--- a/spec/requests/scim_v2/authentication_spec.rb
+++ b/spec/requests/scim_v2/authentication_spec.rb
@@ -173,10 +173,11 @@ RSpec.describe "SCIM API Authentication" do
response_body = JSON.parse(last_response.body)
expect(response_body).to eq(
- { "detail" => "Requires authentication", "schemas" => ["urn:ietf:params:scim:api:messages:2.0:Error"],
- "status" => "401" }
+ { "detail" => "This endpoint requires an enterprise subscription of at least corporate",
+ "schemas" => ["urn:ietf:params:scim:api:messages:2.0:Error"],
+ "status" => "403" }
)
- expect(last_response).to have_http_status(401)
+ expect(last_response).to have_http_status(403)
end
end
end
diff --git a/spec/requests/scim_v2/service_provider_config_spec.rb b/spec/requests/scim_v2/service_provider_config_spec.rb
index fdf55759804..de80e59efc8 100644
--- a/spec/requests/scim_v2/service_provider_config_spec.rb
+++ b/spec/requests/scim_v2/service_provider_config_spec.rb
@@ -30,7 +30,7 @@
require "spec_helper"
-RSpec.describe "SCIM API ServiceProviderConfig", with_ee: [:scim_api] do
+RSpec.describe "SCIM API ServiceProviderConfig" do
let(:oidc_provider_slug) { "keycloak" }
let(:oidc_provider) { create(:oidc_provider, slug: oidc_provider_slug) }
let(:headers) { { "CONTENT_TYPE" => "application/scim+json", "HTTP_AUTHORIZATION" => "Bearer #{token.plaintext_token}" } }
@@ -41,50 +41,12 @@ RSpec.describe "SCIM API ServiceProviderConfig", with_ee: [:scim_api] do
before { token }
describe "GET /scim_v2/ServiceProviderConfig" do
- context "with the feature flag enabled", with_flag: { scim_api: true } do
- it "responds with full ServiceProviderConfig information if authorization is correct" do
- get "/scim_v2/ServiceProviderConfig", {}, headers
-
- response_body = JSON.parse(last_response.body)
- expect(response_body).to include("authenticationSchemes" => [{ "description" => "https://www.openproject.org/docs/system-admin-guide/authentication/scim/#a-static-access-token",
- "name" => "OAuth2",
- "type" => "oauth2" },
- { "description" => "https://www.openproject.org/docs/system-admin-guide/authentication/scim/#b-oauth-20-client-credentials",
- "name" => "OAuth Bearer Token",
- "type" => "oauthbearertoken" },
- { "description" => "https://www.openproject.org/docs/system-admin-guide/authentication/scim/#c-jwt-from-identity-provider",
- "name" => "OpenID Provider JWT",
- "type" => "oidcjwt" }],
- "bulk" => { "supported" => false },
- "changePassword" => { "supported" => false },
- "etag" => { "supported" => false },
- "filter" => { "maxResults" => 100,
- "supported" => true },
- "patch" => { "supported" => true },
- "schemas" => ["urn:ietf:params:scim:schemas:core:2.0:ServiceProviderConfig"],
- "sort" => { "supported" => false })
- end
-
- context "when authorization header contains an invalid token" do
- let(:token) { object_double(Doorkeeper::AccessToken.new, plaintext_token: "123123") }
-
- it "responds with 401 Unauthorized" do
+ context "with enterprise token supporting scim_api", with_ee: [:scim_api] do
+ context "with the feature flag enabled", with_flag: { scim_api: true } do
+ it "responds with full ServiceProviderConfig information if authorization is correct" do
get "/scim_v2/ServiceProviderConfig", {}, headers
- expect(last_response).to have_http_status(401)
- expect(last_response.body).to eq("invalid_token")
- end
- end
-
- context "when there is no authorization header at all" do
- let(:token) { object_double(Doorkeeper::AccessToken.new, plaintext_token: "123123") }
-
- it "responds with limited ServiceProviderConfig information" do
- get "/scim_v2/ServiceProviderConfig", {}, { "CONTENT_TYPE" => "application/scim+json" }
-
- expect(last_response).to have_http_status(200)
response_body = JSON.parse(last_response.body)
- expect(response_body.keys).to eq(["meta", "schemas", "authenticationSchemes"])
expect(response_body).to include("authenticationSchemes" => [{ "description" => "https://www.openproject.org/docs/system-admin-guide/authentication/scim/#a-static-access-token",
"name" => "OAuth2",
"type" => "oauth2" },
@@ -94,21 +56,76 @@ RSpec.describe "SCIM API ServiceProviderConfig", with_ee: [:scim_api] do
{ "description" => "https://www.openproject.org/docs/system-admin-guide/authentication/scim/#c-jwt-from-identity-provider",
"name" => "OpenID Provider JWT",
"type" => "oidcjwt" }],
- "schemas" => ["urn:ietf:params:scim:schemas:core:2.0:ServiceProviderConfig"])
+ "bulk" => { "supported" => false },
+ "changePassword" => { "supported" => false },
+ "etag" => { "supported" => false },
+ "filter" => { "maxResults" => 100,
+ "supported" => true },
+ "patch" => { "supported" => true },
+ "schemas" => ["urn:ietf:params:scim:schemas:core:2.0:ServiceProviderConfig"],
+ "sort" => { "supported" => false })
+ end
+
+ context "when authorization header contains an invalid token" do
+ let(:token) { object_double(Doorkeeper::AccessToken.new, plaintext_token: "123123") }
+
+ it "responds with 401 Unauthorized" do
+ get "/scim_v2/ServiceProviderConfig", {}, headers
+
+ expect(last_response).to have_http_status(401)
+ expect(last_response.body).to eq("invalid_token")
+ end
+ end
+
+ context "when there is no authorization header at all" do
+ let(:token) { object_double(Doorkeeper::AccessToken.new, plaintext_token: "123123") }
+
+ it "responds with limited ServiceProviderConfig information" do
+ get "/scim_v2/ServiceProviderConfig", {}, { "CONTENT_TYPE" => "application/scim+json" }
+
+ expect(last_response).to have_http_status(200)
+ response_body = JSON.parse(last_response.body)
+ expect(response_body.keys).to eq(["meta", "schemas", "authenticationSchemes"])
+ expect(response_body).to include("authenticationSchemes" => [{ "description" => "https://www.openproject.org/docs/system-admin-guide/authentication/scim/#a-static-access-token",
+ "name" => "OAuth2",
+ "type" => "oauth2" },
+ { "description" => "https://www.openproject.org/docs/system-admin-guide/authentication/scim/#b-oauth-20-client-credentials",
+ "name" => "OAuth Bearer Token",
+ "type" => "oauthbearertoken" },
+ { "description" => "https://www.openproject.org/docs/system-admin-guide/authentication/scim/#c-jwt-from-identity-provider",
+ "name" => "OpenID Provider JWT",
+ "type" => "oidcjwt" }],
+ "schemas" => ["urn:ietf:params:scim:schemas:core:2.0:ServiceProviderConfig"])
+ end
+ end
+ end
+
+ context "with the feature flag disabled", with_flag: { scim_api: false } do
+ it do
+ get "/scim_v2/ServiceProviderConfig", {}, headers
+
+ response_body = JSON.parse(last_response.body)
+ expect(response_body).to eq(
+ { "detail" => "Requires authentication",
+ "schemas" => ["urn:ietf:params:scim:api:messages:2.0:Error"],
+ "status" => "401" }
+ )
+ expect(last_response).to have_http_status(401)
end
end
end
- context "with the feature flag disabled", with_flag: { scim_api: false } do
+ context "with enterprise token not supporting scim_api", with_ee: [] do
it do
get "/scim_v2/ServiceProviderConfig", {}, headers
response_body = JSON.parse(last_response.body)
expect(response_body).to eq(
- { "detail" => "Requires authentication", "schemas" => ["urn:ietf:params:scim:api:messages:2.0:Error"],
- "status" => "401" }
+ { "detail" => "This endpoint requires an enterprise subscription of at least corporate",
+ "schemas" => ["urn:ietf:params:scim:api:messages:2.0:Error"],
+ "status" => "403" }
)
- expect(last_response).to have_http_status(401)
+ expect(last_response).to have_http_status(403)
end
end
end