Skip to content
This repository
Newer
Older
100644 245 lines (227 sloc) 9.694 kb
0012e3cd »
2008-01-05 moved all files into trunk subdir and created new tags dir
1 require File.dirname( __FILE__ ) + '/test_helper'
bad61a79 »
2008-09-19 Renamed from PluggableMongrelWebDAVHandler to more simply MongrelWebD…
2 require 'mongrel_webdav_handler'
0012e3cd »
2008-01-05 moved all files into trunk subdir and created new tags dir
3
4 unit_tests do
5 test "should set 404 status if resource does not exist" do
6 root_collection = mock
7 user = stub
8 params = { :resource_href => 'foo/bar' }
9 req_body = ''
10 xml = Builder::XmlMarkup.new( :target => req_body, :indent => 4 )
11 xml.instruct!
12 xml.D :propfind, 'xmlns:D' => 'DAV:', 'xmlns:t' => 'http://example.com/test' do
13 xml.D :prop do
14 xml.D :resourcetype
15 end
16 end
17 root_collection.expects( :find_by_href ).with( 'foo/bar' ).returns( nil )
bad61a79 »
2008-09-19 Renamed from PluggableMongrelWebDAVHandler to more simply MongrelWebD…
18 cmd = MongrelWebdavHandler::PropfindCommand.new( root_collection, user, params, StringIO.new( req_body ) )
0012e3cd »
2008-01-05 moved all files into trunk subdir and created new tags dir
19 assert_equal( { :status => 404 }, cmd.execute )
20 end
21
22 test "should set 400 status and do nothing if request body contains " +
23 "non-well-formed XML" do
24 root_collection = mock
25 user = stub
26 params = { :resource_href => 'foo/bar' }
27 req_body = '<not></wellformed>'
28 resource = stub
29 root_collection.expects( :find_by_href ).with( 'foo/bar' ).returns( resource )
bad61a79 »
2008-09-19 Renamed from PluggableMongrelWebDAVHandler to more simply MongrelWebD…
30 cmd = MongrelWebdavHandler::PropfindCommand.new( root_collection, user, params, StringIO.new( req_body ) )
0012e3cd »
2008-01-05 moved all files into trunk subdir and created new tags dir
31 expected = { :status => 400 }
32 assert_equal expected, cmd.execute
33 end
34
35 test "should set 400 status and do nothing if request body includes an " +
36 "empty namespace declaration" do
37 root_collection = mock
38 user = stub
39 params = { :resource_href => 'foo/bar' }
40 req_body = ''
41 xml = Builder::XmlMarkup.new( :target => req_body, :indent => 4 )
42 xml.instruct!
43 xml.D :propfind, 'xmlns:D' => 'DAV:', 'xmlns:t' => 'http://example.com/test' do
44 xml.D :prop do
45 xml.D :resourcetype
46 xml.t :someprop, 'xmlns:v' => ''
47 end
48 end
49 resource = stub
50 root_collection.expects( :find_by_href ).with( 'foo/bar' ).returns( resource )
bad61a79 »
2008-09-19 Renamed from PluggableMongrelWebDAVHandler to more simply MongrelWebD…
51 cmd = MongrelWebdavHandler::PropfindCommand.new( root_collection, user, params, StringIO.new( req_body ) )
0012e3cd »
2008-01-05 moved all files into trunk subdir and created new tags dir
52 assert_equal( { :status => 400 }, cmd.execute )
53 end
54
55 test "should set 207 status and return requested properties in a " +
56 "multistatus response for the specified collection with a depth of 0" do
57 root_collection = mock
58 user = stub
59 params = { :resource_href => 'foo/bar', :depth => 0, :script_name => '/baz' }
60 req_body = ''
61 xml = Builder::XmlMarkup.new( :target => req_body, :indent => 4 )
62 xml.instruct!
63 xml.D :propfind, 'xmlns:D' => 'DAV:', 'xmlns:t' => 'http://example.com/test',
64 'xmlns:u' => 'http://example.com/test2' do
65 xml.D :prop do
66 xml.D :resourcetype
67 xml.D :getcontentlength
68 xml.t :someprop
69 xml.u :emptyprop
70 xml.t :forbiddenprop
71 xml.t :notfoundprop
72 end
73 end
74
75 collection = stub( :href => 'foo/bar/', :collection? => true )
76 root_collection.expects( :find_by_href ).with( 'foo/bar' ).returns( collection )
77 collection.expects( :get_children ).with( 0 ).returns( [] )
78 collection.expects( :get_prop ).with( 'DAV:', 'getcontentlength' ).returns( [ 200, '50' ] )
79 collection.expects( :get_prop ).with( 'http://example.com/test', 'someprop' ).returns( [ 200, 'some <value>' ] )
80 collection.expects( :get_prop ).with( 'http://example.com/test2', 'emptyprop' ).returns( [ 200, nil ] )
81 collection.expects( :get_prop ).with( 'http://example.com/test', 'forbiddenprop' ).returns( [ 403, nil ] )
82 collection.expects( :get_prop ).with( 'http://example.com/test', 'notfoundprop' ).returns( [ 404, nil ] )
83
bad61a79 »
2008-09-19 Renamed from PluggableMongrelWebDAVHandler to more simply MongrelWebD…
84 cmd = MongrelWebdavHandler::PropfindCommand.new( root_collection, user, params, StringIO.new( req_body ) )
0012e3cd »
2008-01-05 moved all files into trunk subdir and created new tags dir
85
86 expected_body = ''
87 xml = Builder::XmlMarkup.new( :target => expected_body, :indent => 4 )
88 xml.instruct!
89 xml.multistatus 'xmlns' => 'DAV:', 'xmlns:a' => 'http://example.com/test',
90 'xmlns:b' => 'http://example.com/test2' do
91 xml.response do
92 xml.href '/baz/foo/bar/'
93 xml.propstat do
94 xml.prop do
95 xml.resourcetype do
96 xml.collection
97 end
98 xml.getcontentlength '50'
99 xml.a :someprop, 'some <value>'
100 xml.b :emptyprop
101 end
102 xml.status 'HTTP/1.1 200 OK'
103 end
104 xml.propstat do
105 xml.prop do
106 xml.a :forbiddenprop
107 end
108 xml.status 'HTTP/1.1 403 Forbidden'
109 end
110 xml.propstat do
111 xml.prop do
112 xml.a :notfoundprop
113 end
114 xml.status 'HTTP/1.1 404 Not Found'
115 end
116 end
117 end
118
119 result = cmd.execute
120 assert_equal 207, result[ :status ]
121 assert_equal( { 'Content-Type' => 'text/xml; charset="utf-8"' }, result[ :headers ] )
122 assert_equal expected_body, result[ :body ].read
123 end
124
125 test "should set 207 status and return requested properties in a " +
126 "multistatus response for the specified collection and all children with " +
127 "a depth of :all" do
128 root_collection = mock
129 user = stub
130 params = { :resource_href => 'foo/bar', :depth => :all, :script_name => '/baz' }
131 req_body = ''
132 xml = Builder::XmlMarkup.new( :target => req_body, :indent => 4 )
133 xml.instruct!
134 xml.D :propfind, 'xmlns:D' => 'DAV:', 'xmlns:t' => 'http://example.com/test' do
135 xml.D :prop do
136 xml.D :resourcetype
137 xml.t :someprop
138 end
139 end
140
141 collection = stub( :href => 'foo/bar/', :collection? => true )
142 child_a = stub( :href => 'foo/bar/child_a', :collection? => true )
143 child_b = stub( :href => 'foo/bar/child_a/child_b', :collection? => false )
144 root_collection.expects( :find_by_href ).with( 'foo/bar' ).returns( collection )
145 collection.expects( :get_children ).with( :all ).returns( [ child_a, child_b ] )
146 collection.expects( :get_prop ).with( 'http://example.com/test', 'someprop' ).returns( [ 200, 'some <value>' ] )
147 child_a.expects( :get_prop ).with( 'http://example.com/test', 'someprop' ).returns( [ 200, 'some <value> child_a' ] )
148 child_b.expects( :get_prop ).with( 'http://example.com/test', 'someprop' ).returns( [ 200, 'some <value> child_b' ] )
149
bad61a79 »
2008-09-19 Renamed from PluggableMongrelWebDAVHandler to more simply MongrelWebD…
150 cmd = MongrelWebdavHandler::PropfindCommand.new( root_collection, user, params, StringIO.new( req_body ) )
0012e3cd »
2008-01-05 moved all files into trunk subdir and created new tags dir
151
152 expected_body = ''
153 xml = Builder::XmlMarkup.new( :target => expected_body, :indent => 4 )
154 xml.instruct!
155 xml.multistatus 'xmlns' => 'DAV:', 'xmlns:a' => 'http://example.com/test' do
156 xml.response do
157 xml.href '/baz/foo/bar/'
158 xml.propstat do
159 xml.prop do
160 xml.resourcetype do
161 xml.collection
162 end
163 xml.a :someprop, 'some <value>'
164 end
165 xml.status 'HTTP/1.1 200 OK'
166 end
167 end
168 xml.response do
169 xml.href '/baz/foo/bar/child_a'
170 xml.propstat do
171 xml.prop do
172 xml.resourcetype do
173 xml.collection
174 end
175 xml.a :someprop, 'some <value> child_a'
176 end
177 xml.status 'HTTP/1.1 200 OK'
178 end
179 end
180 xml.response do
181 xml.href '/baz/foo/bar/child_a/child_b'
182 xml.propstat do
183 xml.prop do
184 xml.resourcetype {}
185 xml.a :someprop, 'some <value> child_b'
186 end
187 xml.status 'HTTP/1.1 200 OK'
188 end
189 end
190 end
191
192 result = cmd.execute
193 assert_equal 207, result[ :status ]
194 assert_equal( { 'Content-Type' => 'text/xml; charset="utf-8"' }, result[ :headers ] )
195 assert_equal expected_body, result[ :body ].read
196 end
197
198 test "should set 207 status and return default DAV properties in a " +
199 "multistatus response for the specified collection with a depth of 0 and " +
200 "an empty request body" do
201 root_collection = mock
202 user = stub
203 params = { :resource_href => 'foo/bar', :depth => 0, :script_name => '/baz' }
204 req_body = ''
205 fixed_time = Time.now
206 collection = stub( :href => 'foo/bar', :collection? => false )
207 root_collection.expects( :find_by_href ).with( 'foo/bar' ).returns( collection )
208 collection.expects( :get_children ).with( 0 ).returns( [] )
209 collection.expects( :get_prop ).with( 'DAV:', 'creationdate' ).returns( [ 200, fixed_time.xmlschema ] )
210 collection.expects( :get_prop ).with( 'DAV:', 'displayname' ).returns( [ 200, 'bar' ] )
211 collection.expects( :get_prop ).with( 'DAV:', 'getcontentlength' ).returns( [ 200, 50 ] )
212 collection.expects( :get_prop ).with( 'DAV:', 'getcontenttype' ).returns( [ 200, 'text/plain' ] )
213 collection.expects( :get_prop ).with( 'DAV:', 'getetag' ).returns( [ 200, 'abc-def-ghi' ] )
214 collection.expects( :get_prop ).with( 'DAV:', 'getlastmodified' ).returns( [ 200, fixed_time.httpdate ] )
215
216
bad61a79 »
2008-09-19 Renamed from PluggableMongrelWebDAVHandler to more simply MongrelWebD…
217 cmd = MongrelWebdavHandler::PropfindCommand.new( root_collection, user, params, StringIO.new( req_body ) )
0012e3cd »
2008-01-05 moved all files into trunk subdir and created new tags dir
218
219 expected_body = ''
220 xml = Builder::XmlMarkup.new( :target => expected_body, :indent => 4 )
221 xml.instruct!
222 xml.multistatus 'xmlns' => 'DAV:' do
223 xml.response do
224 xml.href '/baz/foo/bar'
225 xml.propstat do
226 xml.prop do
227 xml.resourcetype {}
228 xml.creationdate fixed_time.xmlschema
229 xml.displayname 'bar'
230 xml.getcontentlength 50
231 xml.getcontenttype 'text/plain'
232 xml.getetag 'abc-def-ghi'
233 xml.getlastmodified fixed_time.httpdate
234 end
235 xml.status 'HTTP/1.1 200 OK'
236 end
237 end
238 end
239
240 result = cmd.execute
241 assert_equal 207, result[ :status ]
242 assert_equal( { 'Content-Type' => 'text/xml; charset="utf-8"' }, result[ :headers ] )
243 assert_equal expected_body, result[ :body ].read
244 end
245 end
Something went wrong with that request. Please try again.