Add support for allprop and propname

This commit is contained in:
Brandon Robins
2018-01-30 22:59:55 -06:00
parent 13b5dbc989
commit 9f21799206
4 changed files with 203 additions and 37 deletions

View File

@@ -0,0 +1,59 @@
# frozen_string_literal: false
require 'rails_helper'
require 'support/request_helpers'
require 'support/examples/propfind'
require 'support/examples/proppatch'
RSpec.describe 'PROPFIND', 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
context 'with xml defintiion' do
before(:each) do
put '/webdav/bar.html', headers: {
RAW_POST_DATA: 'hello world'
}
proppatch '/webdav/bar.html', headers: {
RAW_POST_DATA: Support::Examples::Proppatch.rfc4918_9_2_2
}
end
describe 'allprop' do
it 'returns all property names and values' do
propfind '/webdav/bar.html', headers: {
RAW_POST_DATA: Support::Examples::Propfind.allprop
}
expect(response.status).to eq(207)
expect(response.body).to include('Authors')
expect(response.body).to include('Author>')
expect(response.body).to include('Jim')
expect(response.body).to include('Roy')
end
end
describe 'propname' do
it 'returns all property names' do
propfind '/webdav/bar.html', headers: {
RAW_POST_DATA: Support::Examples::Propfind.propname
}
expect(response.status).to eq(207)
expect(response.body).to include('Authors/')
expect(response.body).to_not include('Author/')
end
end
end
end

View File

@@ -0,0 +1,25 @@
# frozen_string_literal: false
module Support
module Examples
module Propfind
def self.allprop
<<~XML
<?xml version="1.0" encoding="utf-8" ?>
<D:propfind xmlns:D="DAV:">
<D:allprop/>
</D:propfind>
XML
end
def self.propname
<<~XML
<?xml version="1.0" encoding="utf-8" ?>
<D:propfind xmlns:D="DAV:">
<D:propname/>
</D:propfind>
XML
end
end
end
end

View File

@@ -0,0 +1,28 @@
# frozen_string_literal: false
module Support
module Examples
module Proppatch
# RFC4918: 9.2.2
def self.rfc4918_9_2_2
<<~XML
<?xml version="1.0" encoding="utf-8" ?>
<D:propertyupdate xmlns:D="DAV:"
xmlns:Z="http://ns.example.com/standards/z39.50/">
<D:set>
<D:prop>
<Z:Authors>
<Z:Author>Jim Whitehead</Z:Author>
<Z:Author>Roy Fielding</Z:Author>
</Z:Authors>
</D:prop>
</D:set>
<D:remove>
<D:prop><Z:Copyright-Owner/></D:prop>
</D:remove>
</D:propertyupdate>
XML
end
end
end
end