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

Fix SSO storage creation via API

Jan Sandbrinkcaafcde3b0a1
diff --git a/modules/storages/lib/api/v3/storages/storage_representer.rb b/modules/storages/lib/api/v3/storages/storage_representer.rb
index 57ecc69f4ef..0de7cde9efc 100644
--- a/modules/storages/lib/api/v3/storages/storage_representer.rb
+++ b/modules/storages/lib/api/v3/storages/storage_representer.rb
@@ -94,7 +94,6 @@ module API::V3::Storages
property :storageAudience,
skip_render: ->(represented:, **) { !represented.provider_type_nextcloud? },
- skip_parse: ->(represented:, **) { !represented.provider_type_nextcloud? },
getter: ->(represented:, **) { represented.provider_type_nextcloud? && represented.storage_audience },
setter: ->(fragment:, represented:, **) { represented.storage_audience = fragment }
@@ -169,8 +168,6 @@ module API::V3::Storages
{ href: method }
},
setter: ->(fragment:, **) {
- break unless represented.provider_type_nextcloud?
-
href = fragment["href"]
break if href.blank? || !AUTHENTICATION_METHOD_MAP.key?(href)
diff --git a/modules/storages/spec/requests/api/v3/storages/storages_api_spec.rb b/modules/storages/spec/requests/api/v3/storages/storages_api_spec.rb
index deac45d3306..5623c226a80 100644
--- a/modules/storages/spec/requests/api/v3/storages/storages_api_spec.rb
+++ b/modules/storages/spec/requests/api/v3/storages/storages_api_spec.rb
@@ -106,7 +106,7 @@ RSpec.describe "API v3 storages resource", :storage_server_helpers, :webmock, co
describe "POST /api/v3/storages" do
let(:path) { api_v3_paths.storages }
- let(:host) { "https://example.nextcloud.local" }
+ let(:host) { "https://example.nextcloud.local/" }
let(:name) { "APIStorage" }
let(:type) { "urn:openproject-org:api:v3:storages:Nextcloud" }
let(:params) do
@@ -137,6 +137,13 @@ RSpec.describe "API v3 storages resource", :storage_server_helpers, :webmock, co
it_behaves_like "successful response", 201
+ it "creates a storage", :aggregate_failures do
+ expect { last_response }.to change(Storages::NextcloudStorage, :count).by(1)
+
+ expect(Storages::NextcloudStorage.last.name).to eq(name)
+ expect(Storages::NextcloudStorage.last.host).to eq(host)
+ end
+
it { is_expected.to have_json_path("_embedded/oauthApplication/clientSecret") }
end
@@ -182,6 +189,24 @@ RSpec.describe "API v3 storages resource", :storage_server_helpers, :webmock, co
let(:message) { "Host is not a valid URL." }
end
end
+
+ context "when creating a storage for SSO authentication" do
+ let(:params) do
+ super().tap do |p|
+ p[:storageAudience] = "the-audience"
+ p[:_links][:authenticationMethod] = { href: "urn:openproject-org:api:v3:storages:authenticationMethod:OAuth2SSO" }
+ end
+ end
+
+ it_behaves_like "successful response", 201
+
+ it "creates a storage with SSO authentication", :aggregate_failures do
+ expect { last_response }.to change(Storages::NextcloudStorage, :count).by(1)
+
+ expect(Storages::NextcloudStorage.last.authentication_method).to eq("oauth2_sso")
+ expect(Storages::NextcloudStorage.last.storage_audience).to eq("the-audience")
+ end
+ end
end
context "as non-admin" do