1 # -*- encoding: binary -*-
2 # Copyright (C) 2012-2017 all contributors <omgdav-public@bogomips.org>
3 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
4 require './test/integration'
5 class TestProppatch < Minitest::Test
6 include TestMogileFSIntegration
8 def test_proppatch_live
9 assert_equal 201, req("MKCOL", "/prop")[0].to_i
13 <?xml version="1.0" encoding="utf-8"?>
14 <D:propertyupdate xmlns:D="DAV:">
17 <getlastmodified xmlns="DAV:">#{t.httpdate}</getlastmodified>
23 input: StringIO.new(xml.strip!)
26 assert_equal 200, req("PROPPATCH", "/prop", opts)[0].to_i
27 assert_equal 666, @db[:paths][name: "prop"][:mtime]
30 def test_getcontenttype
31 path = "//D:multistatus/D:response/D:propstat/D:prop/D:getcontenttype"
32 assert_equal 201, req("PUT", "/type")[0].to_i
33 _, _, body = req("PROPFIND", "/type", "HTTP_DEPTH" => '0')
34 t = Nokogiri::XML(body).search(path)
35 assert_equal "application/octet-stream", t.text
38 <?xml version="1.0" encoding="utf-8"?>
39 <D:propertyupdate xmlns:D="DAV:">
42 <getcontenttype xmlns="DAV:">audio/flac</getcontenttype>
48 input: StringIO.new(xml.strip!)
51 assert_equal 200, req("PROPPATCH", "/type", opts)[0].to_i
52 _, _, body = req("PROPFIND", "/type", "HTTP_DEPTH" => '0')
53 t = Nokogiri::XML(body).search(path)
54 assert_equal "audio/flac", t.text
57 <?xml version="1.0" encoding="utf-8" ?>
58 <D:propertyupdate xmlns:D="DAV:"
59 xmlns:Z="http://ns.example.com/standards/z39.50/">
61 <D:prop><D:getcontenttype/></D:prop>
66 input: StringIO.new(xml.strip!)
68 assert_equal 200, req("PROPPATCH", "/type", opts)[0].to_i
69 _, _, body = req("PROPFIND", "/type", "HTTP_DEPTH" => '0')
70 t = Nokogiri::XML(body).search(path)
71 assert_equal "application/octet-stream", t.text
74 "HTTP_DESTINATION" => "http://example.com/type.txt",
75 "HTTP_HOST" => "example.com",
77 assert_equal 201, req("MOVE", "/type", opts)[0].to_i
78 _, _, body = req("PROPFIND", "/type.txt", "HTTP_DEPTH" => '0')
79 t = Nokogiri::XML(body).search(path)
80 assert_equal "text/plain", t.text
82 # try something invalid
86 "foo/bar paramet()=ff"
89 <?xml version="1.0" encoding="utf-8"?>
90 <D:propertyupdate xmlns:D="DAV:">
93 <getcontenttype xmlns="DAV:">#{bad}</getcontenttype>
98 opts = { input: StringIO.new(xml.strip!) }
99 assert_equal 400, req("PROPPATCH", "/type.txt", opts)[0].to_i, bad
100 assert_nil @db[:paths][name: "type.txt"][:contenttype]
104 <?xml version="1.0" encoding="utf-8"?>
105 <D:propertyupdate xmlns:D="DAV:">
108 <getcontenttype xmlns="DAV:">teXt/plain; chArset="ASCII"</getcontenttype>
113 opts = { input: StringIO.new(xml.strip!) }
114 assert_equal 200, req("PROPPATCH", "/type.txt", opts)[0].to_i
115 i = @db[:paths][name: "type.txt"][:contenttype]
116 assert_kind_of Integer, i
117 t = @db[:prop_mappings][id: i][:value]
118 assert_equal 'text/plain; charset="ASCII"', t
119 refute_equal i, @db[:prop_mappings][value: 'audio/flac'][:id]
122 def test_proppatch_dead
123 assert_equal 201, req("MKCOL", "/prop")[0].to_i
126 <?xml version="1.0" encoding="utf-8" ?>
127 <D:propertyupdate xmlns:D="DAV:"
128 xmlns:Z="http://ns.example.com/standards/z39.50/">
132 <Z:Author>Jim Whitehead</Z:Author>
133 <Z:Author>Roy Fielding</Z:Author>
138 <D:prop><Z:Copyright-Owner/></D:prop>
143 input: StringIO.new(xml.strip!)
146 assert_equal 200, req("PROPPATCH", "/prop", opts)[0].to_i
147 prop = @db[:paths][name: "prop"]
148 props = @app.dead_props_get(prop)
149 ns_prop = props["http://ns.example.com/standards/z39.50/"]
150 assert_instance_of Hash, ns_prop
151 authors = ns_prop["Authors"].strip
152 expect = "<Author>Jim Whitehead</Author>\n" \
153 " <Author>Roy Fielding</Author>"
154 assert_equal expect, authors