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

[#46491] add unit test to cover nc user with whitespaces

Eric Schubert72e3549417e7
diff --git a/modules/storages/spec/common/peripherals/storage_requests_spec.rb b/modules/storages/spec/common/peripherals/storage_requests_spec.rb
index c615b524e92..71024a547ad 100644
--- a/modules/storages/spec/common/peripherals/storage_requests_spec.rb
+++ b/modules/storages/spec/common/peripherals/storage_requests_spec.rb
@@ -188,7 +188,7 @@ describe Storages::Peripherals::StorageRequests, webmock: true do
let(:root_path) { '' }
let(:xml) { create(:webdav_data, parent_path: parent, root_path:) }
let(:url) { "https://example.com#{root_path}" }
- let(:request_url) { "#{url}/remote.php/dav/files/#{origin_user_id}#{parent}" }
+ let(:request_url) { "#{url}/remote.php/dav/files/#{origin_user_id.gsub(' ', '%20')}#{parent}" }
before do
allow(OAuthClients::ConnectionManager).to receive(:new).and_return(connection_manager)
@@ -291,6 +291,25 @@ describe Storages::Peripherals::StorageRequests, webmock: true do
)
end
+ describe 'with origin user id containing whitespaces' do
+ let(:origin_user_id) { 'my user' }
+ let(:xml) { create(:webdav_data, origin_user_id:) }
+
+ it do
+ subject
+ .files_query(user:)
+ .match(
+ on_success: ->(query) {
+ result = query.call(parent)
+ expect(result.result.files[0].location).to eq('/Folder1')
+ },
+ on_failure: ->(error) { raise "Files query could not be created: #{error}" }
+ )
+
+ assert_requested(:propfind, request_url)
+ end
+ end
+
describe 'with parent query parameter' do
let(:parent) { '/Photos/Birds' }
diff --git a/modules/storages/spec/factories/webdav_data_factory.rb b/modules/storages/spec/factories/webdav_data_factory.rb
index 8a8d6d12fd0..c474c3634a8 100644
--- a/modules/storages/spec/factories/webdav_data_factory.rb
+++ b/modules/storages/spec/factories/webdav_data_factory.rb
@@ -29,6 +29,7 @@
FactoryBot.define do
factory :webdav_data, class: 'String' do
transient do
+ origin_user_id { 'admin' }
root_path { '' }
parent_path { '' }
end
@@ -36,7 +37,8 @@ FactoryBot.define do
skip_create
initialize_with do
- base_path = File.join(root_path, '/remote.php/dav/files/admin', parent_path)
+ url_safe_user_id = origin_user_id.gsub(' ', '%20')
+ base_path = File.join(root_path, '/remote.php/dav/files', url_safe_user_id, parent_path)
Nokogiri::XML::Builder.new do |xml|
xml['d'].multistatus(
@@ -53,7 +55,7 @@ FactoryBot.define do
xml['oc'].size('20028269')
xml['d'].getlastmodified('Fri, 28 Oct 2022 14:27:36 GMT')
xml['oc'].permissions('RGDNVCK')
- xml['oc'].send('owner-display-name', 'admin')
+ xml['oc'].send('owner-display-name', url_safe_user_id)
end
xml['d'].status('HTTP/1.1 200 OK')
end
@@ -72,7 +74,7 @@ FactoryBot.define do
xml['oc'].size('6592')
xml['d'].getlastmodified('Fri, 28 Oct 2022 14:31:26 GMT')
xml['oc'].permissions('RGDNVCK')
- xml['oc'].send('owner-display-name', 'admin')
+ xml['oc'].send('owner-display-name', url_safe_user_id)
end
xml['d'].status('HTTP/1.1 200 OK')
end
@@ -91,7 +93,7 @@ FactoryBot.define do
xml['oc'].size('8592')
xml['d'].getlastmodified('Fri, 28 Oct 2022 14:43:26 GMT')
xml['oc'].permissions('RGDNV')
- xml['oc'].send('owner-display-name', 'admin')
+ xml['oc'].send('owner-display-name', url_safe_user_id)
end
xml['d'].status('HTTP/1.1 200 OK')
end
@@ -111,7 +113,7 @@ FactoryBot.define do
xml['d'].getcontenttype('text/markdown')
xml['d'].getlastmodified('Thu, 14 Jul 2022 08:42:15 GMT')
xml['oc'].permissions('RGDNVW')
- xml['oc'].send('owner-display-name', 'admin')
+ xml['oc'].send('owner-display-name', url_safe_user_id)
end
xml['d'].status('HTTP/1.1 200 OK')
end
@@ -125,7 +127,7 @@ FactoryBot.define do
xml['d'].getcontenttype('application/pdf')
xml['d'].getlastmodified('Thu, 14 Jul 2022 08:42:15 GMT')
xml['oc'].permissions('RGDNV')
- xml['oc'].send('owner-display-name', 'admin')
+ xml['oc'].send('owner-display-name', url_safe_user_id)
end
xml['d'].status('HTTP/1.1 200 OK')
end