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

[#57707] added unit test for add user to group

Eric Schubert2755f61fdf53
diff --git a/modules/storages/spec/common/storages/peripherals/storage_interaction/nextcloud/add_user_to_group_command_spec.rb b/modules/storages/spec/common/storages/peripherals/storage_interaction/nextcloud/add_user_to_group_command_spec.rb
new file mode 100644
index 00000000000..00cd9d46c1b
--- /dev/null
+++ b/modules/storages/spec/common/storages/peripherals/storage_interaction/nextcloud/add_user_to_group_command_spec.rb
@@ -0,0 +1,123 @@
+# frozen_string_literal: true
+
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) the OpenProject GmbH
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License version 3.
+#
+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+# Copyright (C) 2006-2013 Jean-Philippe Lang
+# Copyright (C) 2010-2013 the ChiliProject Team
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# See COPYRIGHT and LICENSE files for more details.
+#++
+
+require "spec_helper"
+require_module_spec_helper
+
+RSpec.describe Storages::Peripherals::StorageInteraction::Nextcloud::AddUserToGroupCommand, :webmock do
+ include NextcloudGroupUserHelper
+
+ let(:storage) { create(:nextcloud_storage_with_local_connection, :as_automatically_managed, username: "vcr") }
+ let(:auth_strategy) { Storages::Peripherals::Registry.resolve("nextcloud.authentication.userless").call }
+
+ describe "basic command setup" do
+ it "is registered as commands.add_user_to_group" do
+ expect(Storages::Peripherals::Registry
+ .resolve("#{storage}.commands.add_user_to_group")).to eq(described_class)
+ end
+
+ it "responds to #call with correct parameters" do
+ expect(described_class).to respond_to(:call)
+
+ method = described_class.method(:call)
+ expect(method.parameters).to contain_exactly(%i[keyreq storage],
+ %i[keyreq auth_strategy],
+ %i[keyreq user],
+ %i[keyreq group])
+ end
+ end
+
+ shared_examples_for "failing request" do |error_code:|
+ it "returns a failure" do
+ result = described_class.call(storage:, auth_strategy:, user:, group:)
+ expect(result).to be_failure
+
+ error = result.errors
+ expect(error.code).to eq(error_code)
+ expect(error.data.source).to eq(described_class)
+ end
+ end
+
+ context "if group exists", vcr: "nextcloud/add_user_to_group_success" do
+ let(:user) { "[email protected]" }
+ let(:group) { "Sith Assassins" }
+
+ before do
+ create_group(auth, storage, group)
+ end
+
+ after do
+ remove_group(auth, storage, group)
+ end
+
+ it "returns a success" do
+ members = group_members(group)
+ expect(members).not_to include(user)
+
+ result = described_class.call(storage:, auth_strategy:, user:, group:)
+ expect(result).to be_success
+
+ members = group_members(group)
+ expect(members).to include(user)
+ end
+ end
+
+ context "if target group does not exist", vcr: "nextcloud/add_user_to_group_not_existing_group" do
+ let(:user) { "[email protected]" }
+ let(:group) { "Sith Assassins" }
+
+ it_behaves_like "failing request", error_code: :group_does_not_exist
+ end
+
+ context "if user does not exist", vcr: "nextcloud/add_user_to_group_not_existing_user" do
+ let(:user) { "this is not the user you are looking for" }
+ let(:group) { "Sith Assassins" }
+
+ before do
+ create_group(auth, storage, group)
+ end
+
+ after do
+ remove_group(auth, storage, group)
+ end
+
+ it_behaves_like "failing request", error_code: :user_does_not_exist
+ end
+
+ private
+
+ def auth = Storages::Peripherals::StorageInteraction::Authentication[auth_strategy]
+
+ def group_members(group)
+ Storages::Peripherals::StorageInteraction::Nextcloud::GroupUsersQuery
+ .call(storage:, auth_strategy:, group:)
+ .result
+ end
+end
diff --git a/modules/storages/spec/common/storages/peripherals/storage_interaction/nextcloud/remove_user_from_group_command_spec.rb b/modules/storages/spec/common/storages/peripherals/storage_interaction/nextcloud/remove_user_from_group_command_spec.rb
index 38a5c130b27..993d769f68d 100644
--- a/modules/storages/spec/common/storages/peripherals/storage_interaction/nextcloud/remove_user_from_group_command_spec.rb
+++ b/modules/storages/spec/common/storages/peripherals/storage_interaction/nextcloud/remove_user_from_group_command_spec.rb
@@ -32,6 +32,8 @@ require "spec_helper"
require_module_spec_helper
RSpec.describe Storages::Peripherals::StorageInteraction::Nextcloud::RemoveUserFromGroupCommand, :webmock do
+ include NextcloudGroupUserHelper
+
let(:storage) { create(:nextcloud_storage_with_local_connection, :as_automatically_managed, username: "vcr") }
let(:auth_strategy) { Storages::Peripherals::Registry.resolve("nextcloud.authentication.userless").call }
@@ -68,18 +70,18 @@ RSpec.describe Storages::Peripherals::StorageInteraction::Nextcloud::RemoveUserF
let(:group) { "Sith Assassins" }
before do
- create_group(group)
+ create_group(auth, storage, group)
add_user_to_group(user, group)
# There is a bug in the group folder API that does not allow to remove a user from a group,
# if this is its last group
- create_group("Sith Assassins Backup")
+ create_group(auth, storage, "Sith Assassins Backup")
add_user_to_group(user, "Sith Assassins Backup")
end
after do
- remove_group(group)
- remove_group("Sith Assassins Backup")
+ remove_group(auth, storage, group)
+ remove_group(auth, storage, "Sith Assassins Backup")
end
it "returns a success" do
@@ -99,11 +101,11 @@ RSpec.describe Storages::Peripherals::StorageInteraction::Nextcloud::RemoveUserF
let(:group) { "Sith Assassins" }
before do
- create_group(group)
+ create_group(auth, storage, group)
end
after do
- remove_group(group)
+ remove_group(auth, storage, group)
end
it "returns a success" do
@@ -130,11 +132,11 @@ RSpec.describe Storages::Peripherals::StorageInteraction::Nextcloud::RemoveUserF
let(:group) { "Sith Assassins" }
before do
- create_group(group)
+ create_group(auth, storage, group)
end
after do
- remove_group(group)
+ remove_group(auth, storage, group)
end
it_behaves_like "failing request", error_code: :user_does_not_exist
@@ -144,19 +146,6 @@ RSpec.describe Storages::Peripherals::StorageInteraction::Nextcloud::RemoveUserF
def auth = Storages::Peripherals::StorageInteraction::Authentication[auth_strategy]
- def create_group(group)
- auth.call(storage:, http_options: { headers: { "OCS-APIRequest" => "true" } }) do |http|
- http.post(Storages::UrlBuilder.url(storage.uri, "ocs/v1.php/cloud/groups"),
- form: { "groupid" => group })
- end
- end
-
- def remove_group(group)
- auth.call(storage:, http_options: { headers: { "OCS-APIRequest" => "true" } }) do |http|
- http.delete(Storages::UrlBuilder.url(storage.uri, "/ocs/v1.php/cloud/groups", group))
- end
- end
-
def add_user_to_group(user, group)
Storages::Peripherals::StorageInteraction::Nextcloud::AddUserToGroupCommand
.call(storage:, auth_strategy:, user:, group:)
diff --git a/modules/storages/spec/support/fixtures/vcr_cassettes/nextcloud/add_user_to_group_not_existing_group.yml b/modules/storages/spec/support/fixtures/vcr_cassettes/nextcloud/add_user_to_group_not_existing_group.yml
new file mode 100644
index 00000000000..dd7c28ff9e2
--- /dev/null
+++ b/modules/storages/spec/support/fixtures/vcr_cassettes/nextcloud/add_user_to_group_not_existing_group.yml
@@ -0,0 +1,93 @@
+---
+http_interactions:
+- request:
+ method: post
+ uri: https://nextcloud.local/ocs/v1.php/cloud/users/[email protected]/groups
+ body:
+ encoding: ASCII-8BIT
+ string: groupid=Sith+Assassins
+ headers:
+ Authorization:
+ - Basic <BASIC_AUTH>
+ Ocs-Apirequest:
+ - 'true'
+ User-Agent:
+ - httpx.rb/1.3.1
+ Accept:
+ - "*/*"
+ Accept-Encoding:
+ - gzip, deflate
+ Content-Type:
+ - application/x-www-form-urlencoded
+ Content-Length:
+ - '22'
+ response:
+ status:
+ code: 200
+ message: OK
+ headers:
+ Cache-Control:
+ - no-cache, no-store, must-revalidate
+ Content-Encoding:
+ - gzip
+ Content-Security-Policy:
+ - default-src 'none';base-uri 'none';manifest-src 'self';frame-ancestors 'none'
+ Content-Type:
+ - application/xml; charset=utf-8
+ Date:
+ - Wed, 02 Oct 2024 11:25:38 GMT
+ Expires:
+ - Thu, 19 Nov 1981 08:52:00 GMT
+ Feature-Policy:
+ - autoplay 'none';camera 'none';fullscreen 'none';geolocation 'none';microphone
+ 'none';payment 'none'
+ Pragma:
+ - no-cache
+ Referrer-Policy:
+ - no-referrer
+ Server:
+ - Apache/2.4.59 (Debian)
+ Set-Cookie:
+ - oc07ul6b4oaw=3435fd5720e45f7b8eb20130c44e4770; path=/; secure; HttpOnly; SameSite=Lax,
+ oc_sessionPassphrase=TW49x9LS55SefYVqQZ1L2Ejx3aGIE1Ay%2FxY1j3Q61MDKF9eiz1i2CqXZvu6XeXPNWxMScSTqVYObWnGyg6eHyGJeD2QWUwETmLcuC%2BQplDh0a%2F6wcdV7aj8kK2xXccgn;
+ path=/; secure; HttpOnly; SameSite=Lax, oc07ul6b4oaw=3435fd5720e45f7b8eb20130c44e4770;
+ path=/; secure; HttpOnly; SameSite=Lax, __Host-nc_sameSiteCookielax=true;
+ path=/; httponly;secure; expires=Fri, 31-Dec-2100 23:59:59 GMT; SameSite=lax,
+ __Host-nc_sameSiteCookiestrict=true; path=/; httponly;secure; expires=Fri,
+ 31-Dec-2100 23:59:59 GMT; SameSite=strict, oc07ul6b4oaw=3435fd5720e45f7b8eb20130c44e4770;
+ path=/; secure; HttpOnly; SameSite=Lax, oc07ul6b4oaw=3435fd5720e45f7b8eb20130c44e4770;
+ path=/; secure; HttpOnly; SameSite=Lax, oc07ul6b4oaw=c7d0ee41e82aa556f87b6a6ca55af3d1;
+ path=/; secure; HttpOnly; SameSite=Lax, cookie_test=test; expires=Wed, 02
+ Oct 2024 12:25:38 GMT; Max-Age=3600
+ X-Content-Type-Options:
+ - nosniff
+ X-Frame-Options:
+ - SAMEORIGIN
+ X-Permitted-Cross-Domain-Policies:
+ - none
+ X-Powered-By:
+ - PHP/8.2.21
+ X-Request-Id:
+ - xj9v4dbGQQ60TqZbFMbx
+ X-Robots-Tag:
+ - noindex, nofollow
+ X-Xss-Protection:
+ - 1; mode=block
+ Content-Length:
+ - '137'
+ body:
+ encoding: UTF-8
+ string: |
+ <?xml version="1.0"?>
+ <ocs>
+ <meta>
+ <status>failure</status>
+ <statuscode>102</statuscode>
+ <message></message>
+ <totalitems></totalitems>
+ <itemsperpage></itemsperpage>
+ </meta>
+ <data/>
+ </ocs>
+ recorded_at: Wed, 02 Oct 2024 11:25:38 GMT
+recorded_with: VCR 6.3.1
diff --git a/modules/storages/spec/support/fixtures/vcr_cassettes/nextcloud/add_user_to_group_not_existing_user.yml b/modules/storages/spec/support/fixtures/vcr_cassettes/nextcloud/add_user_to_group_not_existing_user.yml
new file mode 100644
index 00000000000..d8556c81f83
--- /dev/null
+++ b/modules/storages/spec/support/fixtures/vcr_cassettes/nextcloud/add_user_to_group_not_existing_user.yml
@@ -0,0 +1,269 @@
+---
+http_interactions:
+- request:
+ method: post
+ uri: https://nextcloud.local/ocs/v1.php/cloud/groups
+ body:
+ encoding: ASCII-8BIT
+ string: groupid=Sith+Assassins
+ headers:
+ Authorization:
+ - Basic <BASIC_AUTH>
+ Ocs-Apirequest:
+ - 'true'
+ User-Agent:
+ - httpx.rb/1.3.1
+ Accept:
+ - "*/*"
+ Accept-Encoding:
+ - gzip, deflate
+ Content-Type:
+ - application/x-www-form-urlencoded
+ Content-Length:
+ - '22'
+ response:
+ status:
+ code: 200
+ message: OK
+ headers:
+ Cache-Control:
+ - no-cache, no-store, must-revalidate
+ Content-Encoding:
+ - gzip
+ Content-Security-Policy:
+ - default-src 'none';base-uri 'none';manifest-src 'self';frame-ancestors 'none'
+ Content-Type:
+ - application/xml; charset=utf-8
+ Date:
+ - Wed, 02 Oct 2024 11:26:27 GMT
+ Expires:
+ - Thu, 19 Nov 1981 08:52:00 GMT
+ Feature-Policy:
+ - autoplay 'none';camera 'none';fullscreen 'none';geolocation 'none';microphone
+ 'none';payment 'none'
+ Pragma:
+ - no-cache
+ Referrer-Policy:
+ - no-referrer
+ Server:
+ - Apache/2.4.59 (Debian)
+ Set-Cookie:
+ - oc07ul6b4oaw=6e29e61ff6fa4de7f5d56f0cf49cc52c; path=/; secure; HttpOnly; SameSite=Lax,
+ oc_sessionPassphrase=tGAd4gU2%2BBPEJb9XHKOBe%2FL%2FuM%2B4KrmRglE4Wdf3As3T1GiYvQOCyEYw7I%2FTvsKDHc0%2FPb5LYVMzPzDsr%2BKVisw7ACuqTaBQWngKO%2FE6zq4kVqsalobhswWZUrej0xyR;
+ path=/; secure; HttpOnly; SameSite=Lax, oc07ul6b4oaw=6e29e61ff6fa4de7f5d56f0cf49cc52c;
+ path=/; secure; HttpOnly; SameSite=Lax, __Host-nc_sameSiteCookielax=true;
+ path=/; httponly;secure; expires=Fri, 31-Dec-2100 23:59:59 GMT; SameSite=lax,
+ __Host-nc_sameSiteCookiestrict=true; path=/; httponly;secure; expires=Fri,
+ 31-Dec-2100 23:59:59 GMT; SameSite=strict, oc07ul6b4oaw=6e29e61ff6fa4de7f5d56f0cf49cc52c;
+ path=/; secure; HttpOnly; SameSite=Lax, oc07ul6b4oaw=6e29e61ff6fa4de7f5d56f0cf49cc52c;
+ path=/; secure; HttpOnly; SameSite=Lax, oc07ul6b4oaw=6830a7519835b414636bb523c047a1b7;
+ path=/; secure; HttpOnly; SameSite=Lax, cookie_test=test; expires=Wed, 02
+ Oct 2024 12:26:28 GMT; Max-Age=3600
+ X-Content-Type-Options:
+ - nosniff
+ X-Frame-Options:
+ - SAMEORIGIN
+ X-Permitted-Cross-Domain-Policies:
+ - none
+ X-Powered-By:
+ - PHP/8.2.21
+ X-Request-Id:
+ - FPpgIbsBw4hs1Flqa9Xc
+ X-Robots-Tag:
+ - noindex, nofollow
+ X-Xss-Protection:
+ - 1; mode=block
+ Content-Length:
+ - '140'
+ body:
+ encoding: UTF-8
+ string: |
+ <?xml version="1.0"?>
+ <ocs>
+ <meta>
+ <status>ok</status>
+ <statuscode>100</statuscode>
+ <message>OK</message>
+ <totalitems></totalitems>
+ <itemsperpage></itemsperpage>
+ </meta>
+ <data/>
+ </ocs>
+ recorded_at: Wed, 02 Oct 2024 11:26:28 GMT
+- request:
+ method: post
+ uri: https://nextcloud.local/ocs/v1.php/cloud/users/this%20is%20not%20the%20user%20you%20are%20looking%20for/groups
+ body:
+ encoding: ASCII-8BIT
+ string: groupid=Sith+Assassins
+ headers:
+ Authorization:
+ - Basic <BASIC_AUTH>
+ Ocs-Apirequest:
+ - 'true'
+ User-Agent:
+ - httpx.rb/1.3.1
+ Accept:
+ - "*/*"
+ Accept-Encoding:
+ - gzip, deflate
+ Content-Type:
+ - application/x-www-form-urlencoded
+ Content-Length:
+ - '22'
+ response:
+ status:
+ code: 200
+ message: OK
+ headers:
+ Cache-Control:
+ - no-cache, no-store, must-revalidate
+ Content-Encoding:
+ - gzip
+ Content-Security-Policy:
+ - default-src 'none';base-uri 'none';manifest-src 'self';frame-ancestors 'none'
+ Content-Type:
+ - application/xml; charset=utf-8
+ Date:
+ - Wed, 02 Oct 2024 11:26:28 GMT
+ Expires:
+ - Thu, 19 Nov 1981 08:52:00 GMT
+ Feature-Policy:
+ - autoplay 'none';camera 'none';fullscreen 'none';geolocation 'none';microphone
+ 'none';payment 'none'
+ Pragma:
+ - no-cache
+ Referrer-Policy:
+ - no-referrer
+ Server:
+ - Apache/2.4.59 (Debian)
+ Set-Cookie:
+ - oc07ul6b4oaw=a826152d87078fef00b3f65dcb838cd8; path=/; secure; HttpOnly; SameSite=Lax,
+ oc_sessionPassphrase=DBa0jjoKpCnNLE1w8Qqv8%2ByW%2F%2FOdnMmqk%2F3jkaISkMHf7KM4NTZf%2BoCtRYnv%2B4iJ0NEsG5lT4eemC3eMs5z7xSRaVVYnVRPCV62vafOiL291kA5x8yfFSk6KyWOEV%2Bz5;
+ path=/; secure; HttpOnly; SameSite=Lax, oc07ul6b4oaw=a826152d87078fef00b3f65dcb838cd8;
+ path=/; secure; HttpOnly; SameSite=Lax, __Host-nc_sameSiteCookielax=true;
+ path=/; httponly;secure; expires=Fri, 31-Dec-2100 23:59:59 GMT; SameSite=lax,
+ __Host-nc_sameSiteCookiestrict=true; path=/; httponly;secure; expires=Fri,
+ 31-Dec-2100 23:59:59 GMT; SameSite=strict, oc07ul6b4oaw=a826152d87078fef00b3f65dcb838cd8;
+ path=/; secure; HttpOnly; SameSite=Lax, oc07ul6b4oaw=a826152d87078fef00b3f65dcb838cd8;
+ path=/; secure; HttpOnly; SameSite=Lax, oc07ul6b4oaw=4d41faff7b5d32c94392cb85622d0f24;
+ path=/; secure; HttpOnly; SameSite=Lax, cookie_test=test; expires=Wed, 02
+ Oct 2024 12:26:28 GMT; Max-Age=3600
+ X-Content-Type-Options:
+ - nosniff
+ X-Frame-Options:
+ - SAMEORIGIN
+ X-Permitted-Cross-Domain-Policies:
+ - none
+ X-Powered-By:
+ - PHP/8.2.21
+ X-Request-Id:
+ - g29wLvuVk7lTdPKldRf3
+ X-Robots-Tag:
+ - noindex, nofollow
+ X-Xss-Protection:
+ - 1; mode=block
+ Content-Length:
+ - '138'
+ body:
+ encoding: UTF-8
+ string: |
+ <?xml version="1.0"?>
+ <ocs>
+ <meta>
+ <status>failure</status>
+ <statuscode>103</statuscode>
+ <message></message>
+ <totalitems></totalitems>
+ <itemsperpage></itemsperpage>
+ </meta>
+ <data/>
+ </ocs>
+ recorded_at: Wed, 02 Oct 2024 11:26:28 GMT
+- request:
+ method: delete
+ uri: https://nextcloud.local/ocs/v1.php/cloud/groups/Sith%20Assassins
+ body:
+ encoding: US-ASCII
+ string: ''
+ headers:
+ Authorization:
+ - Basic <BASIC_AUTH>
+ Ocs-Apirequest:
+ - 'true'
+ User-Agent:
+ - httpx.rb/1.3.1
+ Accept:
+ - "*/*"
+ Accept-Encoding:
+ - gzip, deflate
+ response:
+ status:
+ code: 200
+ message: OK
+ headers:
+ Cache-Control:
+ - no-cache, no-store, must-revalidate
+ Content-Encoding:
+ - gzip
+ Content-Security-Policy:
+ - default-src 'none';base-uri 'none';manifest-src 'self';frame-ancestors 'none'
+ Content-Type:
+ - application/xml; charset=utf-8
+ Date:
+ - Wed, 02 Oct 2024 11:26:28 GMT
+ Expires:
+ - Thu, 19 Nov 1981 08:52:00 GMT
+ Feature-Policy:
+ - autoplay 'none';camera 'none';fullscreen 'none';geolocation 'none';microphone
+ 'none';payment 'none'
+ Pragma:
+ - no-cache
+ Referrer-Policy:
+ - no-referrer
+ Server:
+ - Apache/2.4.59 (Debian)
+ Set-Cookie:
+ - oc07ul6b4oaw=273dbd9a2af4d7e9b5b84ff38b6405eb; path=/; secure; HttpOnly; SameSite=Lax,
+ oc_sessionPassphrase=Hi%2BExE5i6x4iNHg2U23x9V1KK4uVNUxkZnZNk5dZE5Y%2BL8vui8ULCqw74QOSZBj8YolgCGERIgqIu6LO9WowNg2nUp9s5D3AH3SfAmLWcC6qnN4O9oaUoNoma6%2BPE7K2;
+ path=/; secure; HttpOnly; SameSite=Lax, oc07ul6b4oaw=273dbd9a2af4d7e9b5b84ff38b6405eb;
+ path=/; secure; HttpOnly; SameSite=Lax, __Host-nc_sameSiteCookielax=true;
+ path=/; httponly;secure; expires=Fri, 31-Dec-2100 23:59:59 GMT; SameSite=lax,
+ __Host-nc_sameSiteCookiestrict=true; path=/; httponly;secure; expires=Fri,
+ 31-Dec-2100 23:59:59 GMT; SameSite=strict, oc07ul6b4oaw=273dbd9a2af4d7e9b5b84ff38b6405eb;
+ path=/; secure; HttpOnly; SameSite=Lax, oc07ul6b4oaw=273dbd9a2af4d7e9b5b84ff38b6405eb;
+ path=/; secure; HttpOnly; SameSite=Lax, oc07ul6b4oaw=a14f9be6dc6da2911faab1160e8e0724;
+ path=/; secure; HttpOnly; SameSite=Lax, cookie_test=test; expires=Wed, 02
+ Oct 2024 12:26:29 GMT; Max-Age=3600
+ X-Content-Type-Options:
+ - nosniff
+ X-Frame-Options:
+ - SAMEORIGIN
+ X-Permitted-Cross-Domain-Policies:
+ - none
+ X-Powered-By:
+ - PHP/8.2.21
+ X-Request-Id:
+ - hXSdanUWKSsQUM0cf83W
+ X-Robots-Tag:
+ - noindex, nofollow
+ X-Xss-Protection:
+ - 1; mode=block
+ Content-Length:
+ - '140'
+ body:
+ encoding: UTF-8
+ string: |
+ <?xml version="1.0"?>
+ <ocs>
+ <meta>
+ <status>ok</status>
+ <statuscode>100</statuscode>
+ <message>OK</message>
+ <totalitems></totalitems>
+ <itemsperpage></itemsperpage>
+ </meta>
+ <data/>
+ </ocs>
+ recorded_at: Wed, 02 Oct 2024 11:26:29 GMT
+recorded_with: VCR 6.3.1
diff --git a/modules/storages/spec/support/fixtures/vcr_cassettes/nextcloud/add_user_to_group_success.yml b/modules/storages/spec/support/fixtures/vcr_cassettes/nextcloud/add_user_to_group_success.yml
new file mode 100644
index 00000000000..c40034be2e9
--- /dev/null
+++ b/modules/storages/spec/support/fixtures/vcr_cassettes/nextcloud/add_user_to_group_success.yml
@@ -0,0 +1,447 @@
+---
+http_interactions:
+- request:
+ method: post
+ uri: https://nextcloud.local/ocs/v1.php/cloud/groups
+ body:
+ encoding: ASCII-8BIT
+ string: groupid=Sith+Assassins
+ headers:
+ Authorization:
+ - Basic <BASIC_AUTH>
+ Ocs-Apirequest:
+ - 'true'
+ User-Agent:
+ - httpx.rb/1.3.1
+ Accept:
+ - "*/*"
+ Accept-Encoding:
+ - gzip, deflate
+ Content-Type:
+ - application/x-www-form-urlencoded
+ Content-Length:
+ - '22'
+ response:
+ status:
+ code: 200
+ message: OK
+ headers:
+ Cache-Control:
+ - no-cache, no-store, must-revalidate
+ Content-Encoding:
+ - gzip
+ Content-Security-Policy:
+ - default-src 'none';base-uri 'none';manifest-src 'self';frame-ancestors 'none'
+ Content-Type:
+ - application/xml; charset=utf-8
+ Date:
+ - Wed, 02 Oct 2024 11:25:34 GMT
+ Expires:
+ - Thu, 19 Nov 1981 08:52:00 GMT
+ Feature-Policy:
+ - autoplay 'none';camera 'none';fullscreen 'none';geolocation 'none';microphone
+ 'none';payment 'none'
+ Pragma:
+ - no-cache
+ Referrer-Policy:
+ - no-referrer
+ Server:
+ - Apache/2.4.59 (Debian)
+ Set-Cookie:
+ - oc07ul6b4oaw=29c38c28dc035c4df7fa99eae76f6f52; path=/; secure; HttpOnly; SameSite=Lax,
+ oc_sessionPassphrase=sOAqPyCZcKXS31G07jTWDx1jvfRLOfqDO5DE6TDlB5Z29exjO1N2UuOxUpzQXAt%2FayieKwMDRspmz2GUhhYEu858Efob9jiJjCMA9GmhuxvR7Loi%2FFf4G9kT3yFp0hja;
+ path=/; secure; HttpOnly; SameSite=Lax, oc07ul6b4oaw=29c38c28dc035c4df7fa99eae76f6f52;
+ path=/; secure; HttpOnly; SameSite=Lax, __Host-nc_sameSiteCookielax=true;
+ path=/; httponly;secure; expires=Fri, 31-Dec-2100 23:59:59 GMT; SameSite=lax,
+ __Host-nc_sameSiteCookiestrict=true; path=/; httponly;secure; expires=Fri,
+ 31-Dec-2100 23:59:59 GMT; SameSite=strict, oc07ul6b4oaw=29c38c28dc035c4df7fa99eae76f6f52;
+ path=/; secure; HttpOnly; SameSite=Lax, oc07ul6b4oaw=29c38c28dc035c4df7fa99eae76f6f52;
+ path=/; secure; HttpOnly; SameSite=Lax, oc07ul6b4oaw=ef568b51d673191a020016ea13d56a03;
+ path=/; secure; HttpOnly; SameSite=Lax, cookie_test=test; expires=Wed, 02
+ Oct 2024 12:25:35 GMT; Max-Age=3600
+ X-Content-Type-Options:
+ - nosniff
+ X-Frame-Options:
+ - SAMEORIGIN
+ X-Permitted-Cross-Domain-Policies:
+ - none
+ X-Powered-By:
+ - PHP/8.2.21
+ X-Request-Id:
+ - 4fYFj0J9kuZychKCMXgQ
+ X-Robots-Tag:
+ - noindex, nofollow
+ X-Xss-Protection:
+ - 1; mode=block
+ Content-Length:
+ - '140'
+ body:
+ encoding: UTF-8
+ string: |
+ <?xml version="1.0"?>
+ <ocs>
+ <meta>
+ <status>ok</status>
+ <statuscode>100</statuscode>
+ <message>OK</message>
+ <totalitems></totalitems>
+ <itemsperpage></itemsperpage>
+ </meta>
+ <data/>
+ </ocs>
+ recorded_at: Wed, 02 Oct 2024 11:25:35 GMT
+- request:
+ method: get
+ uri: https://nextcloud.local/ocs/v1.php/cloud/groups/Sith%20Assassins
+ body:
+ encoding: US-ASCII
+ string: ''
+ headers:
+ Authorization:
+ - Basic <BASIC_AUTH>
+ Ocs-Apirequest:
+ - 'true'
+ User-Agent:
+ - httpx.rb/1.3.1
+ Accept:
+ - "*/*"
+ Accept-Encoding:
+ - gzip, deflate
+ response:
+ status:
+ code: 200
+ message: OK
+ headers:
+ Cache-Control:
+ - no-cache, no-store, must-revalidate
+ Content-Encoding:
+ - gzip
+ Content-Security-Policy:
+ - default-src 'none';base-uri 'none';manifest-src 'self';frame-ancestors 'none'
+ Content-Type:
+ - application/xml; charset=utf-8
+ Date:
+ - Wed, 02 Oct 2024 11:25:35 GMT
+ Expires:
+ - Thu, 19 Nov 1981 08:52:00 GMT
+ Feature-Policy:
+ - autoplay 'none';camera 'none';fullscreen 'none';geolocation 'none';microphone
+ 'none';payment 'none'
+ Pragma:
+ - no-cache
+ Referrer-Policy:
+ - no-referrer
+ Server:
+ - Apache/2.4.59 (Debian)
+ Set-Cookie:
+ - oc07ul6b4oaw=225fc966c9cae74eb094cafdbe879656; path=/; secure; HttpOnly; SameSite=Lax,
+ oc_sessionPassphrase=FPy4E3zSg1lroYXLap41QWQR266dBgJNS1132FYqmr8WHnLDNdB4H4JWn2v5irPaWlknD5tuyvEQTmnOgeo0SsEHKFsXWttOWQ9SHqHW2cJDS4T70fpQR%2BR1M34NiGcv;
+ path=/; secure; HttpOnly; SameSite=Lax, oc07ul6b4oaw=225fc966c9cae74eb094cafdbe879656;
+ path=/; secure; HttpOnly; SameSite=Lax, __Host-nc_sameSiteCookielax=true;
+ path=/; httponly;secure; expires=Fri, 31-Dec-2100 23:59:59 GMT; SameSite=lax,
+ __Host-nc_sameSiteCookiestrict=true; path=/; httponly;secure; expires=Fri,
+ 31-Dec-2100 23:59:59 GMT; SameSite=strict, oc07ul6b4oaw=225fc966c9cae74eb094cafdbe879656;
+ path=/; secure; HttpOnly; SameSite=Lax, oc07ul6b4oaw=225fc966c9cae74eb094cafdbe879656;
+ path=/; secure; HttpOnly; SameSite=Lax, oc07ul6b4oaw=d7695659c22f797e9188f91633325de3;
+ path=/; secure; HttpOnly; SameSite=Lax, cookie_test=test; expires=Wed, 02
+ Oct 2024 12:25:35 GMT; Max-Age=3600
+ X-Content-Type-Options:
+ - nosniff
+ X-Frame-Options:
+ - SAMEORIGIN
+ X-Permitted-Cross-Domain-Policies:
+ - none
+ X-Powered-By:
+ - PHP/8.2.21
+ X-Request-Id:
+ - CKH1JLn9C2evgkTvgo2g
+ X-Robots-Tag:
+ - noindex, nofollow
+ X-Xss-Protection:
+ - 1; mode=block
+ Content-Length:
+ - '146'
+ body:
+ encoding: UTF-8
+ string: |
+ <?xml version="1.0"?>
+ <ocs>
+ <meta>
+ <status>ok</status>
+ <statuscode>100</statuscode>
+ <message>OK</message>
+ <totalitems></totalitems>
+ <itemsperpage></itemsperpage>
+ </meta>
+ <data>
+ <users/>
+ </data>
+ </ocs>
+ recorded_at: Wed, 02 Oct 2024 11:25:35 GMT
+- request:
+ method: post
+ uri: https://nextcloud.local/ocs/v1.php/cloud/users/[email protected]/groups
+ body:
+ encoding: ASCII-8BIT
+ string: groupid=Sith+Assassins
+ headers:
+ Authorization:
+ - Basic <BASIC_AUTH>
+ Ocs-Apirequest:
+ - 'true'
+ User-Agent:
+ - httpx.rb/1.3.1
+ Accept:
+ - "*/*"
+ Accept-Encoding:
+ - gzip, deflate
+ Content-Type:
+ - application/x-www-form-urlencoded
+ Content-Length:
+ - '22'
+ response:
+ status:
+ code: 200
+ message: OK
+ headers:
+ Cache-Control:
+ - no-cache, no-store, must-revalidate
+ Content-Encoding:
+ - gzip
+ Content-Security-Policy:
+ - default-src 'none';base-uri 'none';manifest-src 'self';frame-ancestors 'none'
+ Content-Type:
+ - application/xml; charset=utf-8
+ Date:
+ - Wed, 02 Oct 2024 11:25:36 GMT
+ Expires:
+ - Thu, 19 Nov 1981 08:52:00 GMT
+ Feature-Policy:
+ - autoplay 'none';camera 'none';fullscreen 'none';geolocation 'none';microphone
+ 'none';payment 'none'
+ Pragma:
+ - no-cache
+ Referrer-Policy:
+ - no-referrer
+ Server:
+ - Apache/2.4.59 (Debian)
+ Set-Cookie:
+ - oc07ul6b4oaw=6a730fce6b319299d66a531a7b86d36e; path=/; secure; HttpOnly; SameSite=Lax,
+ oc_sessionPassphrase=42zY4dXqAQr86gRiePVi1u0dGtTA2wgwP1lb0YHagnB5Z7K1ZXwfuDISyDae47QfuFHV0xnBPAtJUfBocwlsg8O%2By8uPxdX%2BLSblXMuSVm76FodQfcAvafTkOHIsoTIn;
+ path=/; secure; HttpOnly; SameSite=Lax, oc07ul6b4oaw=6a730fce6b319299d66a531a7b86d36e;
+ path=/; secure; HttpOnly; SameSite=Lax, __Host-nc_sameSiteCookielax=true;
+ path=/; httponly;secure; expires=Fri, 31-Dec-2100 23:59:59 GMT; SameSite=lax,
+ __Host-nc_sameSiteCookiestrict=true; path=/; httponly;secure; expires=Fri,
+ 31-Dec-2100 23:59:59 GMT; SameSite=strict, oc07ul6b4oaw=6a730fce6b319299d66a531a7b86d36e;
+ path=/; secure; HttpOnly; SameSite=Lax, oc07ul6b4oaw=6a730fce6b319299d66a531a7b86d36e;
+ path=/; secure; HttpOnly; SameSite=Lax, oc07ul6b4oaw=00072ddc7f1494d72713b5fbd75cb7e1;
+ path=/; secure; HttpOnly; SameSite=Lax, cookie_test=test; expires=Wed, 02
+ Oct 2024 12:25:36 GMT; Max-Age=3600
+ X-Content-Type-Options:
+ - nosniff
+ X-Frame-Options:
+ - SAMEORIGIN
+ X-Permitted-Cross-Domain-Policies:
+ - none
+ X-Powered-By:
+ - PHP/8.2.21
+ X-Request-Id:
+ - O5bip5bJcCjFRSyFHn1L
+ X-Robots-Tag:
+ - noindex, nofollow
+ X-Xss-Protection:
+ - 1; mode=block
+ Content-Length:
+ - '140'
+ body:
+ encoding: UTF-8
+ string: |
+ <?xml version="1.0"?>
+ <ocs>
+ <meta>
+ <status>ok</status>
+ <statuscode>100</statuscode>
+ <message>OK</message>
+ <totalitems></totalitems>
+ <itemsperpage></itemsperpage>
+ </meta>
+ <data/>
+ </ocs>
+ recorded_at: Wed, 02 Oct 2024 11:25:36 GMT
+- request:
+ method: get
+ uri: https://nextcloud.local/ocs/v1.php/cloud/groups/Sith%20Assassins
+ body:
+ encoding: US-ASCII
+ string: ''
+ headers:
+ Authorization:
+ - Basic <BASIC_AUTH>
+ Ocs-Apirequest:
+ - 'true'
+ User-Agent:
+ - httpx.rb/1.3.1
+ Accept:
+ - "*/*"
+ Accept-Encoding:
+ - gzip, deflate
+ response:
+ status:
+ code: 200
+ message: OK
+ headers:
+ Cache-Control:
+ - no-cache, no-store, must-revalidate
+ Content-Encoding:
+ - gzip
+ Content-Security-Policy:
+ - default-src 'none';base-uri 'none';manifest-src 'self';frame-ancestors 'none'
+ Content-Type:
+ - application/xml; charset=utf-8
+ Date:
+ - Wed, 02 Oct 2024 11:25:36 GMT
+ Expires:
+ - Thu, 19 Nov 1981 08:52:00 GMT
+ Feature-Policy:
+ - autoplay 'none';camera 'none';fullscreen 'none';geolocation 'none';microphone
+ 'none';payment 'none'
+ Pragma:
+ - no-cache
+ Referrer-Policy:
+ - no-referrer
+ Server:
+ - Apache/2.4.59 (Debian)
+ Set-Cookie:
+ - oc07ul6b4oaw=9d07914f7ea36e57c18ad0cb3cb785d1; path=/; secure; HttpOnly; SameSite=Lax,
+ oc_sessionPassphrase=H5KgO68qsaNkITOxmEdBNqn950tik97izjPJn5blRavXvjcMNj3CmsMwvTuAVuKxJEsiNUJLt%2Fy%2BrUNsreNmeLqVyH264wXi5SUQhr67p4SgZpoB%2Fo6JzzXnMdSoeQBu;
+ path=/; secure; HttpOnly; SameSite=Lax, oc07ul6b4oaw=9d07914f7ea36e57c18ad0cb3cb785d1;
+ path=/; secure; HttpOnly; SameSite=Lax, __Host-nc_sameSiteCookielax=true;
+ path=/; httponly;secure; expires=Fri, 31-Dec-2100 23:59:59 GMT; SameSite=lax,
+ __Host-nc_sameSiteCookiestrict=true; path=/; httponly;secure; expires=Fri,
+ 31-Dec-2100 23:59:59 GMT; SameSite=strict, oc07ul6b4oaw=9d07914f7ea36e57c18ad0cb3cb785d1;
+ path=/; secure; HttpOnly; SameSite=Lax, oc07ul6b4oaw=9d07914f7ea36e57c18ad0cb3cb785d1;
+ path=/; secure; HttpOnly; SameSite=Lax, oc07ul6b4oaw=68ffd2c4e6f1f7c72cb9be37b2a24b77;
+ path=/; secure; HttpOnly; SameSite=Lax, cookie_test=test; expires=Wed, 02
+ Oct 2024 12:25:37 GMT; Max-Age=3600
+ X-Content-Type-Options:
+ - nosniff
+ X-Frame-Options:
+ - SAMEORIGIN
+ X-Permitted-Cross-Domain-Policies:
+ - none
+ X-Powered-By:
+ - PHP/8.2.21
+ X-Request-Id:
+ - 7wxA5bvmCIBKPBS0UxIO
+ X-Robots-Tag:
+ - noindex, nofollow
+ X-Xss-Protection:
+ - 1; mode=block
+ Content-Length:
+ - '171'
+ body:
+ encoding: UTF-8
+ string: |
+ <?xml version="1.0"?>
+ <ocs>
+ <meta>
+ <status>ok</status>
+ <statuscode>100</statuscode>
+ <message>OK</message>
+ <totalitems></totalitems>
+ <itemsperpage></itemsperpage>
+ </meta>
+ <data>
+ <users>
+ <element>[email protected]</element>
+ </users>
+ </data>
+ </ocs>
+ recorded_at: Wed, 02 Oct 2024 11:25:37 GMT
+- request:
+ method: delete
+ uri: https://nextcloud.local/ocs/v1.php/cloud/groups/Sith%20Assassins
+ body:
+ encoding: US-ASCII
+ string: ''
+ headers:
+ Authorization:
+ - Basic <BASIC_AUTH>
+ Ocs-Apirequest:
+ - 'true'
+ User-Agent:
+ - httpx.rb/1.3.1
+ Accept:
+ - "*/*"
+ Accept-Encoding:
+ - gzip, deflate
+ response:
+ status:
+ code: 200
+ message: OK
+ headers:
+ Cache-Control:
+ - no-cache, no-store, must-revalidate
+ Content-Encoding:
+ - gzip
+ Content-Security-Policy:
+ - default-src 'none';base-uri 'none';manifest-src 'self';frame-ancestors 'none'
+ Content-Type:
+ - application/xml; charset=utf-8
+ Date:
+ - Wed, 02 Oct 2024 11:25:37 GMT
+ Expires:
+ - Thu, 19 Nov 1981 08:52:00 GMT
+ Feature-Policy:
+ - autoplay 'none';camera 'none';fullscreen 'none';geolocation 'none';microphone
+ 'none';payment 'none'
+ Pragma:
+ - no-cache
+ Referrer-Policy:
+ - no-referrer
+ Server:
+ - Apache/2.4.59 (Debian)
+ Set-Cookie:
+ - oc07ul6b4oaw=d82222dcdd0eb6fb3088dfe245e068bd; path=/; secure; HttpOnly; SameSite=Lax,
+ oc_sessionPassphrase=BnYO9ZfQkH9a0nJhl9uZX8taeKhbYtZiypJ7q1elg3Y4vntAg4rB2AfG2qyPIIL584DKr%2B0pNS603exhjP%2FMC8%2BqU5dPUK1mpYVnziHNorjI8dVa7QMRtjulNMFOgijB;
+ path=/; secure; HttpOnly; SameSite=Lax, oc07ul6b4oaw=d82222dcdd0eb6fb3088dfe245e068bd;
+ path=/; secure; HttpOnly; SameSite=Lax, __Host-nc_sameSiteCookielax=true;
+ path=/; httponly;secure; expires=Fri, 31-Dec-2100 23:59:59 GMT; SameSite=lax,
+ __Host-nc_sameSiteCookiestrict=true; path=/; httponly;secure; expires=Fri,
+ 31-Dec-2100 23:59:59 GMT; SameSite=strict, oc07ul6b4oaw=d82222dcdd0eb6fb3088dfe245e068bd;
+ path=/; secure; HttpOnly; SameSite=Lax, oc07ul6b4oaw=d82222dcdd0eb6fb3088dfe245e068bd;
+ path=/; secure; HttpOnly; SameSite=Lax, oc07ul6b4oaw=aa7ee674b22ce356475afea0d9a74417;
+ path=/; secure; HttpOnly; SameSite=Lax, cookie_test=test; expires=Wed, 02
+ Oct 2024 12:25:37 GMT; Max-Age=3600
+ X-Content-Type-Options:
+ - nosniff
+ X-Frame-Options:
+ - SAMEORIGIN
+ X-Permitted-Cross-Domain-Policies:
+ - none
+ X-Powered-By:
+ - PHP/8.2.21
+ X-Request-Id:
+ - hcwsxM46t3lrHDK7Ypx7
+ X-Robots-Tag:
+ - noindex, nofollow
+ X-Xss-Protection:
+ - 1; mode=block
+ Content-Length:
+ - '140'
+ body:
+ encoding: UTF-8
+ string: |
+ <?xml version="1.0"?>
+ <ocs>
+ <meta>
+ <status>ok</status>
+ <statuscode>100</statuscode>
+ <message>OK</message>
+ <totalitems></totalitems>
+ <itemsperpage></itemsperpage>
+ </meta>
+ <data/>
+ </ocs>
+ recorded_at: Wed, 02 Oct 2024 11:25:37 GMT
+recorded_with: VCR 6.3.1
diff --git a/modules/storages/spec/support/nextcloud_group_user_helper.rb b/modules/storages/spec/support/nextcloud_group_user_helper.rb
new file mode 100644
index 00000000000..6507014908c
--- /dev/null
+++ b/modules/storages/spec/support/nextcloud_group_user_helper.rb
@@ -0,0 +1,42 @@
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) the OpenProject GmbH
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License version 3.
+#
+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+# Copyright (C) 2006-2013 Jean-Philippe Lang
+# Copyright (C) 2010-2013 the ChiliProject Team
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# See COPYRIGHT and LICENSE files for more details.
+#++
+
+module NextcloudGroupUserHelper
+ def create_group(authentication, storage, group)
+ authentication.call(storage:, http_options: { headers: { "OCS-APIRequest" => "true" } }) do |http|
+ http.post(Storages::UrlBuilder.url(storage.uri, "ocs/v1.php/cloud/groups"),
+ form: { "groupid" => group })
+ end
+ end
+
+ def remove_group(authentication, storage, group)
+ authentication.call(storage:, http_options: { headers: { "OCS-APIRequest" => "true" } }) do |http|
+ http.delete(Storages::UrlBuilder.url(storage.uri, "/ocs/v1.php/cloud/groups", group))
+ end
+ end
+end