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

[47619] Added fix and test for nil and empty string folder parameter for SetPermissionCommand

Andreas Pfohl460411a34368
diff --git a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/set_permissions_command.rb b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/set_permissions_command.rb
index e2065c25e0b..982080a2748 100644
--- a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/set_permissions_command.rb
+++ b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/set_permissions_command.rb
@@ -71,7 +71,7 @@ module Storages::Peripherals::StorageInteraction::Nextcloud
end
def requested_folder(folder)
- return '' if folder.nil?
+ raise ArgumentError.new("Folder can't be nil or empty string!") if folder.blank?
escape_whitespace(folder)
end
diff --git a/modules/storages/spec/common/peripherals/storage_requests_spec.rb b/modules/storages/spec/common/peripherals/storage_requests_spec.rb
index 632f7a83aa8..c92ccd832e0 100644
--- a/modules/storages/spec/common/peripherals/storage_requests_spec.rb
+++ b/modules/storages/spec/common/peripherals/storage_requests_spec.rb
@@ -127,123 +127,153 @@ describe Storages::Peripherals::StorageRequests, webmock: true do
end
context 'with Nextcloud storage type selected' do
- before do
- stub_request(:proppatch, "#{url}/remote.php/dav/files/OpenProject/JediProject")
- .with(
- body: expected_request_body,
- headers: {
- 'Authorization' => 'Basic T3BlblByb2plY3Q6T3BlblByb2plY3RTZWN1cmVQYXNzd29yZA=='
- }
- )
- .to_return(expected_response)
- end
-
- context 'when permissions can be set' do
- let(:expected_response_body) do
- <<~XML
- <?xml version="1.0"?>
- <d:multistatus
- xmlns:d="DAV:"
- xmlns:s="http://sabredav.org/ns"
- xmlns:oc="http://owncloud.org/ns"
- xmlns:nc="http://nextcloud.org/ns">
- <d:response>
- <d:href>/remote.php/dav/files/OpenProject/OpenProject/Project%231</d:href>
- <d:propstat>
- <d:prop>
- <nc:acl-list/>
- </d:prop>
- <d:status>HTTP/1.1 200 OK</d:status>
- </d:propstat>
- </d:response>
- </d:multistatus>
- XML
- end
- let(:expected_response) do
- {
- status: 207,
- body: expected_response_body,
- headers: {}
- }
+ context 'with outbound request' do
+ before do
+ stub_request(:proppatch, "#{url}/remote.php/dav/files/OpenProject/JediProject")
+ .with(
+ body: expected_request_body,
+ headers: {
+ 'Authorization' => 'Basic T3BlblByb2plY3Q6T3BlblByb2plY3RTZWN1cmVQYXNzd29yZA=='
+ }
+ )
+ .to_return(expected_response)
end
- it 'returns success when permissions can be set' do
- subject
- .set_permissions_command
- .match(
- on_success: ->(command) do
- result = command.call(folder: 'JediProject', permissions:)
- expect(result).to be_success
- end,
- on_failure: ->(error) do
- raise "Set permissions command could not be executed: #{error}"
- end
- )
+ context 'when permissions can be set' do
+ let(:expected_response_body) do
+ <<~XML
+ <?xml version="1.0"?>
+ <d:multistatus
+ xmlns:d="DAV:"
+ xmlns:s="http://sabredav.org/ns"
+ xmlns:oc="http://owncloud.org/ns"
+ xmlns:nc="http://nextcloud.org/ns">
+ <d:response>
+ <d:href>/remote.php/dav/files/OpenProject/OpenProject/Project%231</d:href>
+ <d:propstat>
+ <d:prop>
+ <nc:acl-list/>
+ </d:prop>
+ <d:status>HTTP/1.1 200 OK</d:status>
+ </d:propstat>
+ </d:response>
+ </d:multistatus>
+ XML
+ end
+ let(:expected_response) do
+ {
+ status: 207,
+ body: expected_response_body,
+ headers: {}
+ }
+ end
+
+ it 'returns success when permissions can be set' do
+ subject
+ .set_permissions_command
+ .match(
+ on_success: ->(command) do
+ result = command.call(folder: 'JediProject', permissions:)
+ expect(result).to be_success
+ end,
+ on_failure: ->(error) do
+ raise "Set permissions command could not be executed: #{error}"
+ end
+ )
+ end
end
- end
- context 'when the password is wrong' do
- let(:expected_response_body) do
- <<~XML
- <?xml version="1.0" encoding="utf-8"?>
- <d:error
- xmlns:d="DAV:"
- xmlns:s="http://sabredav.org/ns">
- <s:exception>Sabre\DAV\Exception\NotAuthenticated</s:exception>
- <s:message>No public access to this resource., No 'Authorization: Basic' header found. Either the client didn't send one, or the server is misconfigured, No 'Authorization: Bearer' header found. Either the client didn't send one, or the server is mis-configured, No 'Authorization: Basic' header found. Either the client didn't send one, or the server is misconfigured</s:message>
- </d:error>
- XML
+ context 'when the password is wrong' do
+ let(:expected_response_body) do
+ <<~XML
+ <?xml version="1.0" encoding="utf-8"?>
+ <d:error
+ xmlns:d="DAV:"
+ xmlns:s="http://sabredav.org/ns">
+ <s:exception>Sabre\DAV\Exception\NotAuthenticated</s:exception>
+ <s:message>No public access to this resource., No 'Authorization: Basic' header found. Either the client didn't send one, or the server is misconfigured, No 'Authorization: Bearer' header found. Either the client didn't send one, or the server is mis-configured, No 'Authorization: Basic' header found. Either the client didn't send one, or the server is misconfigured</s:message>
+ </d:error>
+ XML
+ end
+ let(:expected_response) do
+ {
+ status: 401,
+ body: expected_response_body,
+ headers: {}
+ }
+ end
+
+ it 'returns failure' do
+ subject
+ .set_permissions_command
+ .match(
+ on_success: ->(command) do
+ result = command.call(folder: 'JediProject', permissions:)
+ expect(result).to be_failure
+ end,
+ on_failure: ->(error) do
+ raise "Set permissions command could not be executed: #{error}"
+ end
+ )
+ end
end
- let(:expected_response) do
- {
- status: 401,
- body: expected_response_body,
- headers: {}
- }
+
+ context 'when the NC control user cannot read(see) the project folder' do
+ let(:expected_response_body) do
+ <<~XML
+ <?xml version="1.0" encoding="utf-8"?>
+ <d:error
+ xmlns:d="DAV:"
+ xmlns:s="http://sabredav.org/ns">
+ <s:exception>Sabre\DAV\Exception\NotFound</s:exception>
+ <s:message>File with name /OpenProject/JediProject could not be located</s:message>
+ </d:error>
+ XML
+ end
+ let(:expected_response) do
+ {
+ status: 404,
+ body: expected_response_body,
+ headers: {}
+ }
+ end
+
+ it 'returns failure' do
+ subject
+ .set_permissions_command
+ .match(
+ on_success: ->(command) do
+ result = command.call(folder: 'JediProject', permissions:)
+ expect(result).to be_failure
+ end,
+ on_failure: ->(error) do
+ raise "Set permissions command could not be executed: #{error}"
+ end
+ )
+ end
end
+ end
- it 'returns failure' do
+ context 'when forbidden values are given as folder' do
+ it 'raises an ArgumentError on nil' do
subject
.set_permissions_command
.match(
on_success: ->(command) do
- result = command.call(folder: 'JediProject', permissions:)
- expect(result).to be_failure
+ expect { command.call(folder: nil, permissions:) }.to raise_error(ArgumentError)
end,
on_failure: ->(error) do
raise "Set permissions command could not be executed: #{error}"
end
)
end
- end
- context 'when the NC control user cannot read(see) the project folder' do
- let(:expected_response_body) do
- <<~XML
- <?xml version="1.0" encoding="utf-8"?>
- <d:error
- xmlns:d="DAV:"
- xmlns:s="http://sabredav.org/ns">
- <s:exception>Sabre\DAV\Exception\NotFound</s:exception>
- <s:message>File with name /OpenProject/JediProject could not be located</s:message>
- </d:error>
- XML
- end
- let(:expected_response) do
- {
- status: 404,
- body: expected_response_body,
- headers: {}
- }
- end
-
- it 'returns failure' do
+ it 'raises an ArgumentError on empty string' do
subject
.set_permissions_command
.match(
on_success: ->(command) do
- result = command.call(folder: 'JediProject', permissions:)
- expect(result).to be_failure
+ expect { command.call(folder: '', permissions:) }.to raise_error(ArgumentError)
end,
on_failure: ->(error) do
raise "Set permissions command could not be executed: #{error}"