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
[#61178] Fix specs and react on comments.
Pavel Balashou6f5bb5f68c3b
diff --git a/modules/storages/app/common/storages/peripherals/oauth_configurations/configuration_interface.rb b/modules/storages/app/common/storages/peripherals/oauth_configurations/configuration_interface.rbindex 699f3da46aa..dde493e85d2 100644--- a/modules/storages/app/common/storages/peripherals/oauth_configurations/configuration_interface.rb+++ b/modules/storages/app/common/storages/peripherals/oauth_configurations/configuration_interface.rb@@ -46,18 +46,16 @@ module Storagesdef extract_origin_user_id(oauth_client_token)auth_strategy = Registry- .resolve("#{storage_name}.authentication.user_bound")- .call(user: oauth_client_token.user)+ .resolve("#{@storage}.authentication.user_bound")+ .call(user: oauth_client_token.user, storage: @storage)Registry- .resolve("#{storage_name}.queries.user")+ .resolve("#{@storage}.queries.user").call(auth_strategy:, storage: @storage).match(on_success: ->(user) { user[:id] },on_failure: ->(error) { raise "UserQuery responed with #{error}" })end-- def storage_name = raise ::Storages::Errors::SubclassResponsibilityendendenddiff --git a/modules/storages/app/common/storages/peripherals/oauth_configurations/nextcloud_configuration.rb b/modules/storages/app/common/storages/peripherals/oauth_configurations/nextcloud_configuration.rbindex bab25bd16e0..9ae5e6a8fb1 100644--- a/modules/storages/app/common/storages/peripherals/oauth_configurations/nextcloud_configuration.rb+++ b/modules/storages/app/common/storages/peripherals/oauth_configurations/nextcloud_configuration.rb@@ -47,10 +47,6 @@ module Storages# rubocop:enable Lint/MissingSuper- def storage_name- "nextcloud"- end-def to_httpx_oauth_configStorageInteraction::AuthenticationStrategies::OAuthConfiguration.new(client_id: @oauth_client.client_id,diff --git a/modules/storages/app/common/storages/peripherals/oauth_configurations/one_drive_configuration.rb b/modules/storages/app/common/storages/peripherals/oauth_configurations/one_drive_configuration.rbindex 2a274685f2f..ef77ab91b07 100644--- a/modules/storages/app/common/storages/peripherals/oauth_configurations/one_drive_configuration.rb+++ b/modules/storages/app/common/storages/peripherals/oauth_configurations/one_drive_configuration.rb@@ -51,10 +51,6 @@ module Storages# rubocop:enable Lint/MissingSuper- def storage_name- "one_drive"- end-def to_httpx_oauth_configStorageInteraction::AuthenticationStrategies::OAuthConfiguration.new(client_id: @oauth_client.client_id,diff --git a/modules/storages/spec/common/storages/peripherals/storage_interaction/nextcloud/user_query_spec.rb b/modules/storages/spec/common/storages/peripherals/storage_interaction/nextcloud/user_query_spec.rbindex a2a551db258..0261cc0a0c1 100644--- a/modules/storages/spec/common/storages/peripherals/storage_interaction/nextcloud/user_query_spec.rb+++ b/modules/storages/spec/common/storages/peripherals/storage_interaction/nextcloud/user_query_spec.rb@@ -33,9 +33,6 @@ require_module_spec_helperRSpec.describe Storages::Peripherals::StorageInteraction::Nextcloud::UserQuery, :webmock dolet(:user) { create(:user) }- # let(:storage) do- # create(:nextcloud_storage_with_local_connection, :as_not_automatically_managed, oauth_client_token_user: user)- # endlet(:storage) docreate(:nextcloud_storage_with_local_connection,:as_automatically_managed,@@ -43,9 +40,11 @@ RSpec.describe Storages::Peripherals::StorageInteraction::Nextcloud::UserQuery,oauth_client_token_user: user)endlet(:userless_strategy) { Storages::Peripherals::Registry.resolve("nextcloud.authentication.userless").call }- let(:user_bound_strategy) { Storages::Peripherals::Registry.resolve("nextcloud.authentication.user_bound").call(user:) }+ let(:user_bound_strategy) do+ Storages::Peripherals::Registry.resolve("nextcloud.authentication.user_bound").call(user:, storage:)+ end- it "is registered as queries.group_users" do+ it "is registered" doexpect(Storages::Peripherals::Registry.resolve("#{storage}.queries.user")).to eq(described_class)enddiff --git a/modules/storages/spec/common/storages/peripherals/storage_interaction/one_drive/user_query_spec.rb b/modules/storages/spec/common/storages/peripherals/storage_interaction/one_drive/user_query_spec.rbindex 9bac434c6d1..d2041f8f517 100644--- a/modules/storages/spec/common/storages/peripherals/storage_interaction/one_drive/user_query_spec.rb+++ b/modules/storages/spec/common/storages/peripherals/storage_interaction/one_drive/user_query_spec.rb@@ -37,7 +37,9 @@ RSpec.describe Storages::Peripherals::StorageInteraction::OneDrive::UserQuery, :oauth_client_token_user: user)endlet(:user) { create(:user) }- let(:user_bound_strategy) { Storages::Peripherals::Registry.resolve("one_drive.authentication.user_bound").call(user:) }+ let(:user_bound_strategy) do+ Storages::Peripherals::Registry.resolve("one_drive.authentication.user_bound").call(user:, storage:)+ endlet(:auth_strategy) { user_bound_strategy }it "is registered" dodiff --git a/modules/storages/spec/support/payloads/nextcloud_user_query_success.xml b/modules/storages/spec/support/payloads/nextcloud_user_query_success.xmlnew file mode 100644index 00000000000..9a7ef03feb5--- /dev/null+++ b/modules/storages/spec/support/payloads/nextcloud_user_query_success.xml@@ -0,0 +1,65 @@+<?xml version="1.0"?>+<ocs>+ <meta>+ <status>ok</status>+ <statuscode>100</statuscode>+ <message>OK</message>+ <totalitems></totalitems>+ <itemsperpage></itemsperpage>+ </meta>+ <data>+ <enabled>1</enabled>+ <storageLocation>/var/www/html/data/admin</storageLocation>+ <id>admin</id>+ <lastLogin>1738833138000</lastLogin>+ <backend>Database</backend>+ <subadmin/>+ <quota>+ <free>447793922048</free>+ <used>37754592</used>+ <total>447831676640</total>+ <relative>0.01</relative>+ <quota>-3</quota>+ </quota>+ <manager></manager>+ <avatarScope>v2-federated</avatarScope>+ <email/>+ <emailScope>v2-federated</emailScope>+ <additional_mail/>+ <additional_mailScope/>+ <displayname>admin</displayname>+ <display-name>admin</display-name>+ <displaynameScope>v2-federated</displaynameScope>+ <phone></phone>+ <phoneScope>v2-local</phoneScope>+ <address></address>+ <addressScope>v2-local</addressScope>+ <website></website>+ <websiteScope>v2-local</websiteScope>+ <twitter></twitter>+ <twitterScope>v2-local</twitterScope>+ <fediverse></fediverse>+ <fediverseScope>v2-local</fediverseScope>+ <organisation></organisation>+ <organisationScope>v2-local</organisationScope>+ <role></role>+ <roleScope>v2-local</roleScope>+ <headline></headline>+ <headlineScope>v2-local</headlineScope>+ <biography></biography>+ <biographyScope>v2-local</biographyScope>+ <profile_enabled>1</profile_enabled>+ <profile_enabledScope>v2-local</profile_enabledScope>+ <groups>+ <element>admin</element>+ <element>OpenProject</element>+ </groups>+ <language>en</language>+ <locale></locale>+ <notify_email/>+ <backendCapabilities>+ <setDisplayName>1</setDisplayName>+ <setPassword>1</setPassword>+ </backendCapabilities>+ </data>+</ocs>diff --git a/spec/requests/oauth_clients/callback_flow_spec.rb b/spec/requests/oauth_clients/callback_flow_spec.rbindex b8f5a4ae4c2..28c27210000 100644--- a/spec/requests/oauth_clients/callback_flow_spec.rb+++ b/spec/requests/oauth_clients/callback_flow_spec.rb@@ -51,6 +51,7 @@ RSpec.describe "OAuthClient callback endpoint" doclient_id: "kETWr2XsjPxhVbN7Q5jmPq83xribuUTRzgfXthpYT0vSqyJWm4dOnivKzHiZasf0",client_secret: "J1sg4L5PYbM2RZL3pUyxTnamvfpcP5eUcCPmeCQHJO60Gy6CJIdDaF4yXOeC8BPS")end+ let(:storage) { oauth_client.integration }let(:rack_oauth2_client) { instance_double(Rack::OAuth2::Client) }let(:connection_manager) { instance_double(OAuthClients::ConnectionManager) }let(:uri) { URI(File.join("oauth_clients", oauth_client.client_id, "callback")) }@@ -103,12 +104,13 @@ RSpec.describe "OAuthClient callback endpoint" docontext "with valid params" docontext "without errors" do- before do+ it "redirects to the URL that was referenced by the state param and held by a cookie", :webmock do+ stub_request(:get, File.join(storage.host, "/ocs/v1.php/cloud/user"))+ .to_return(status: 200, body: File.read("modules/storages/spec/support/payloads/nextcloud_user_query_success.xml"), headers: {})+uri.query = URI.encode_www_form([["code", code], ["state", state]])get uri.to_s- end- it "redirects to the URL that was referenced by the state param and held by a cookie" doexpect(rack_oauth2_client).to have_received(:authorization_code=).with(code)expect(response).to have_http_status :foundexpect(response.location).to eq redirect_uridiff --git a/spec/services/oauth_clients/connection_manager_spec.rb b/spec/services/oauth_clients/connection_manager_spec.rbindex 826f2343f76..694f2aeb897 100644--- a/spec/services/oauth_clients/connection_manager_spec.rb+++ b/spec/services/oauth_clients/connection_manager_spec.rb@@ -116,73 +116,7 @@ RSpec.describe OAuthClients::ConnectionManager, :webmock, type: :model do"Authorization" => "Bearer yjTDZ...RYvRH","Ocs-Apirequest" => "true"}- ).to_return(status: 200, body: <<~XML, headers: {})- <?xml version="1.0"?>- <ocs>- <meta>- <status>ok</status>- <statuscode>100</statuscode>- <message>OK</message>- <totalitems></totalitems>- <itemsperpage></itemsperpage>- </meta>- <data>- <enabled>1</enabled>- <storageLocation>/var/www/html/data/admin</storageLocation>- <id>admin</id>- <lastLogin>1738833138000</lastLogin>- <backend>Database</backend>- <subadmin/>- <quota>- <free>447793922048</free>- <used>37754592</used>- <total>447831676640</total>- <relative>0.01</relative>- <quota>-3</quota>- </quota>- <manager></manager>- <avatarScope>v2-federated</avatarScope>- <email/>- <emailScope>v2-federated</emailScope>- <additional_mail/>- <additional_mailScope/>- <displayname>admin</displayname>- <display-name>admin</display-name>- <displaynameScope>v2-federated</displaynameScope>- <phone></phone>- <phoneScope>v2-local</phoneScope>- <address></address>- <addressScope>v2-local</addressScope>- <website></website>- <websiteScope>v2-local</websiteScope>- <twitter></twitter>- <twitterScope>v2-local</twitterScope>- <fediverse></fediverse>- <fediverseScope>v2-local</fediverseScope>- <organisation></organisation>- <organisationScope>v2-local</organisationScope>- <role></role>- <roleScope>v2-local</roleScope>- <headline></headline>- <headlineScope>v2-local</headlineScope>- <biography></biography>- <biographyScope>v2-local</biographyScope>- <profile_enabled>1</profile_enabled>- <profile_enabledScope>v2-local</profile_enabledScope>- <groups>- <element>admin</element>- <element>OpenProject</element>- </groups>- <language>en</language>- <locale></locale>- <notify_email/>- <backendCapabilities>- <setDisplayName>1</setDisplayName>- <setPassword>1</setPassword>- </backendCapabilities>- </data>- </ocs>- XML+ ).to_return(status: 200, body: File.read("modules/storages/spec/support/payloads/nextcloud_user_query_success.xml"), headers: {})endit "returns a valid ClientToken object and issues an appropriate event" dodiff --git a/spec/services/remote_identities/create_service_spec.rb b/spec/services/remote_identities/create_service_spec.rbindex cbf3e0e62d7..0d8fb885ae3 100644--- a/spec/services/remote_identities/create_service_spec.rb+++ b/spec/services/remote_identities/create_service_spec.rb@@ -4,23 +4,31 @@ require "spec_helper"require "services/base_services/behaves_like_create_service"-RSpec.describe RemoteIdentities::CreateService, type: :model do+RSpec.describe RemoteIdentities::CreateService, :webmock, type: :model dolet(:user) { create(:user) }let(:storage) { create(:nextcloud_storage_configured) }let(:oauth_config) { storage.oauth_configuration }- let(:oauth_token) { Rack::OAuth2::AccessToken.new(access_token: "sudo-access-token", user_id: "bob-from-accounting") }+ let(:oauth_client_token) do+ create(:oauth_client_token,+ user:,+ oauth_client: oauth_config.oauth_client)+ end++ subject(:service) { described_class.new(user:, oauth_config:, oauth_client_token:) }- subject(:service) { described_class.new(user:, oauth_config:, oauth_token:) }+ before do+ stub_request(:get, File.join(storage.host, "/ocs/v1.php/cloud/user")).to_return(status: 200, body: File.read("modules/storages/spec/support/payloads/nextcloud_user_query_success.xml"), headers: {})+ enddescribe ".call" doit "requires a user, a oauth configuration and a rack token" domethod = described_class.method :call- expect(method.parameters).to contain_exactly(%i[keyreq user], %i[keyreq oauth_config], %i[keyreq oauth_token])+ expect(method.parameters).to contain_exactly(%i[keyreq user], %i[keyreq oauth_config], %i[keyreq oauth_client_token])end- it "succeeds" do- expect(described_class.call(user:, oauth_config:, oauth_token:)).to be_success+ it "succeeds", :webmock do+ expect(described_class.call(user:, oauth_config:, oauth_client_token:)).to be_successendend@@ -39,19 +47,5 @@ RSpec.describe RemoteIdentities::CreateService, type: :model doresult = service.call.resultexpect(result).to be_a RemoteIdentityend-- context "if creation fails" do- let(:oauth_token) { Rack::OAuth2::AccessToken.new(access_token: "sudo-access-token") }-- it "is unsuccessful" do- expect(service.call).to be_failure- end-- it "exposes the errors" do- result = service.call- expect(result.errors.size).to eq(1)- expect(result.errors[:origin_user_id]).to eq(["can't be blank."])- end- endendend