Add support for Extended MKCOL (RFC5689)
This commit is contained in:
committed by
Brandon Robins
parent
46ff7a934f
commit
3b65768e40
51
spec/requests/mkcol_spec.rb
Normal file
51
spec/requests/mkcol_spec.rb
Normal file
@@ -0,0 +1,51 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
require 'support/request_helpers'
|
||||
require 'support/examples/ext_mkcol'
|
||||
|
||||
RSpec.describe 'mkcol', type: :request do
|
||||
before(:all) do
|
||||
tmp_dir = Rails.root.join('../../tmp').to_path
|
||||
Dir.mkdir tmp_dir unless File.exists? tmp_dir
|
||||
|
||||
webdav_dir = Rails.root.join('../../tmp/webdav').to_path
|
||||
FileUtils.rm_r webdav_dir if File.exists? webdav_dir
|
||||
Dir.mkdir webdav_dir
|
||||
end
|
||||
|
||||
before(:each) do
|
||||
allow(Calligraphy).to receive(:enable_digest_authentication)
|
||||
.and_return(false)
|
||||
end
|
||||
|
||||
it 'creates a collection with additional properties' do
|
||||
allow_any_instance_of(Calligraphy::FileResource).to receive(
|
||||
:valid_resourcetypes
|
||||
).and_return(%w[collection special-resource])
|
||||
|
||||
expect(Dir).to receive(:mkdir).and_call_original
|
||||
expect_any_instance_of(Calligraphy::FileResource).to receive(
|
||||
:proppatch
|
||||
)
|
||||
|
||||
mkcol '/webdav/special', headers: {
|
||||
RAW_POST_DATA: Support::Examples::ExtMkcol.rfc5689_3_4
|
||||
}
|
||||
|
||||
expect(response.body.empty?).to eq(true)
|
||||
expect(response.status).to eq(201)
|
||||
end
|
||||
|
||||
context 'with an invalid resource type' do
|
||||
it 'returns an error response' do
|
||||
mkcol '/webdav/special', headers: {
|
||||
RAW_POST_DATA: Support::Examples::ExtMkcol.rfc5689_3_4
|
||||
}
|
||||
|
||||
expect(response.status).to eq(403)
|
||||
expect(response.body).to include('mkcol-response')
|
||||
expect(response.body).to include('valid-resourcetype')
|
||||
end
|
||||
end
|
||||
end
|
||||
51
spec/requests/options_spec.rb
Normal file
51
spec/requests/options_spec.rb
Normal file
@@ -0,0 +1,51 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
require 'support/request_helpers'
|
||||
|
||||
RSpec.describe 'OPTIONS', type: :request do
|
||||
before(:each) do
|
||||
allow(Calligraphy).to receive(:enable_digest_authentication)
|
||||
.and_return(false)
|
||||
end
|
||||
|
||||
context 'when not using extended MKCOL support' do
|
||||
before(:each) do
|
||||
allow_any_instance_of(Calligraphy::FileResource).to receive(
|
||||
:enable_extended_mkcol?
|
||||
).and_return(false)
|
||||
end
|
||||
|
||||
it 'advertises support for all 3 WebDAV classes' do
|
||||
options '/webdav/special'
|
||||
|
||||
%w[1 2 3].each { |c| expect(response.headers['DAV']).to include(c) }
|
||||
end
|
||||
|
||||
it 'does not advertise support for extended-mkcol' do
|
||||
options '/webdav/special'
|
||||
|
||||
expect(response.headers['DAV']).to_not include('extended-mkcol')
|
||||
end
|
||||
end
|
||||
|
||||
context 'when using extended MKCOL support' do
|
||||
before(:each) do
|
||||
allow_any_instance_of(Calligraphy::FileResource).to receive(
|
||||
:enable_extended_mkcol?
|
||||
).and_return(true)
|
||||
end
|
||||
|
||||
it 'advertises support for all 3 WebDAV classes' do
|
||||
options '/webdav/special'
|
||||
|
||||
%w[1 2 3].each { |c| expect(response.headers['DAV']).to include(c) }
|
||||
end
|
||||
|
||||
it 'advertises support for extended-mkcol' do
|
||||
options '/webdav/special'
|
||||
|
||||
expect(response.headers['DAV']).to include('extended-mkcol')
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,22 +1,29 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
require 'support/request_helpers'
|
||||
|
||||
RSpec.describe 'Resource' do
|
||||
context 'base method' do
|
||||
resource_methods_without_inputs = %w(
|
||||
resource_methods_without_inputs = %w[
|
||||
ancestor_exist? collection? create_collection delete_collection etag
|
||||
exists? lock_is_exclusive? locked? read readable? refresh_lock
|
||||
creationdate displayname getcontentlanguage getcontentlength getcontenttype
|
||||
getetag getlastmodified lockdiscovery resourcetype supportedlock
|
||||
)
|
||||
resource_methods_with_inputs = %w(
|
||||
creationdate displayname getcontentlanguage getcontentlength
|
||||
getcontenttype getetag getlastmodified lockdiscovery resourcetype
|
||||
supportedlock
|
||||
]
|
||||
resource_methods_with_inputs = %w[
|
||||
copy copy_options lock locked_to_user? propfind proppatch unlock write
|
||||
)
|
||||
]
|
||||
|
||||
resource_methods_without_inputs.each do |method|
|
||||
describe "##{method}" do
|
||||
it 'raises NotImplementedError' do
|
||||
resource = Calligraphy::Resource.new
|
||||
expect{resource.send(method)}.to raise_exception(NotImplementedError)
|
||||
|
||||
expect { resource.send(method) }.to raise_exception(
|
||||
NotImplementedError
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -25,7 +32,10 @@ RSpec.describe 'Resource' do
|
||||
describe "##{method}" do
|
||||
it 'raises NotImplementedError' do
|
||||
resource = Calligraphy::Resource.new
|
||||
expect{resource.send(method, nil)}.to raise_exception(NotImplementedError)
|
||||
|
||||
expect { resource.send(method, nil) }.to raise_exception(
|
||||
NotImplementedError
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
26
spec/support/examples/ext_mkcol.rb
Normal file
26
spec/support/examples/ext_mkcol.rb
Normal file
@@ -0,0 +1,26 @@
|
||||
# frozen_string_literal: false
|
||||
|
||||
module Support
|
||||
module Examples
|
||||
module ExtMkcol
|
||||
# RFC5689: 3.4. Successful Extended MKCOL Request
|
||||
def self.rfc5689_3_4
|
||||
<<~XML
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<D:mkcol xmlns:D="DAV:"
|
||||
xmlns:E="http://example.com/ns/">
|
||||
<D:set>
|
||||
<D:prop>
|
||||
<D:resourcetype>
|
||||
<D:collection/>
|
||||
<E:special-resource/>
|
||||
</D:resourcetype>
|
||||
<D:displayname>Special Resource</D:displayname>
|
||||
</D:prop>
|
||||
</D:set>
|
||||
</D:mkcol>
|
||||
XML
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,7 +1,7 @@
|
||||
module ActionDispatch
|
||||
module Integration
|
||||
module RequestHelpers
|
||||
%w[copy move mkcol propfind proppatch lock unlock].each do |method|
|
||||
%w[copy move mkcol options propfind proppatch lock unlock].each do |method|
|
||||
define_method method do |path, **args|
|
||||
process method.to_sym, path, **args
|
||||
end
|
||||
Reference in New Issue
Block a user