36 #include "../webdav/webdav.h" |
36 #include "../webdav/webdav.h" |
37 #include "../webdav/multistatus.h" |
37 #include "../webdav/multistatus.h" |
38 |
38 |
39 #include "webdav.h" |
39 #include "webdav.h" |
40 |
40 |
41 static int test_init( |
|
42 Session **out_sn, |
|
43 Request **out_rq, |
|
44 WebdavPropfindRequest **out_propfind, |
|
45 const char *xml) |
|
46 { |
|
47 Session *sn = testutil_session(); |
|
48 Request *rq = testutil_request(sn->pool, "PROPFIND", "/"); |
|
49 |
|
50 int error = 0; |
|
51 |
|
52 WebdavPropfindRequest *propfind = propfind_parse( |
|
53 sn, |
|
54 rq, |
|
55 xml, |
|
56 strlen(xml), |
|
57 &error); |
|
58 |
|
59 if(error) { |
|
60 return 1; |
|
61 } |
|
62 |
|
63 if(!propfind || !propfind->properties) { |
|
64 return 1; |
|
65 } |
|
66 |
|
67 *out_sn = sn; |
|
68 *out_rq = rq; |
|
69 *out_propfind = propfind; |
|
70 return 0; |
|
71 } |
|
72 |
|
73 |
|
74 UCX_TEST(test_propfind_parse) { |
|
75 Session *sn = testutil_session(); |
|
76 Request *rq = testutil_request(sn->pool, "PROPFIND", "/"); |
|
77 |
|
78 UCX_TEST_BEGIN |
|
79 |
|
80 int error = 0; |
|
81 |
|
82 // |
|
83 // ----------------- TEST_PROPFIND1 ----------------- |
|
84 // test basic propfind request |
|
85 WebdavPropfindRequest *p1 = propfind_parse( |
|
86 sn, |
|
87 rq, |
|
88 TEST_PROPFIND1, |
|
89 strlen(TEST_PROPFIND1), |
|
90 &error); |
|
91 |
|
92 UCX_TEST_ASSERT(p1, "p1 is NULL"); |
|
93 UCX_TEST_ASSERT(p1->properties, "p1: no props"); |
|
94 UCX_TEST_ASSERT(!p1->allprop, "p1: allprop is TRUE"); |
|
95 UCX_TEST_ASSERT(!p1->propname, "p1: propname is TRUE"); |
|
96 UCX_TEST_ASSERT(p1->propcount == 6, "p1: wrong propcount"); |
|
97 |
|
98 // property 1: DAV:displayname |
|
99 WebdavPList *elm = p1->properties; |
|
100 UCX_TEST_ASSERT( |
|
101 !strcmp(elm->property->name, "displayname"), |
|
102 "p1: property 1 has wrong name"); |
|
103 UCX_TEST_ASSERT( |
|
104 !strcmp((char*)elm->property->namespace->href, "DAV:"), |
|
105 "p1: property 1 has wrong namespace"); |
|
106 |
|
107 // property 2: DAV:getcontentlength |
|
108 elm = elm->next; |
|
109 UCX_TEST_ASSERT(elm, "p1: property 2 missing"); |
|
110 UCX_TEST_ASSERT( |
|
111 !strcmp(elm->property->name, "getcontentlength"), |
|
112 "p1: property 2 has wrong name"); |
|
113 UCX_TEST_ASSERT( |
|
114 !strcmp((char*)elm->property->namespace->href, "DAV:"), |
|
115 "p1: property 2 has wrong namespace"); |
|
116 |
|
117 elm = elm->next; |
|
118 UCX_TEST_ASSERT(elm, "p1: property 3 missing"); |
|
119 elm = elm->next; |
|
120 UCX_TEST_ASSERT(elm, "p1: property 4 missing"); |
|
121 elm = elm->next; |
|
122 UCX_TEST_ASSERT(elm, "p1: property 5 missing"); |
|
123 |
|
124 // property 6: DAV:getetag |
|
125 elm = elm->next; |
|
126 UCX_TEST_ASSERT(elm, "p1: property 6 missing"); |
|
127 UCX_TEST_ASSERT( |
|
128 !strcmp(elm->property->name, "getetag"), |
|
129 "p1: property 6 has wrong name"); |
|
130 UCX_TEST_ASSERT( |
|
131 !strcmp((char*)elm->property->namespace->href, "DAV:"), |
|
132 "p1: property 6 has wrong namespace"); |
|
133 UCX_TEST_ASSERT(!elm->next, "p1: should not have property 7"); |
|
134 |
|
135 // |
|
136 // ----------------- TEST_PROPFIND2 ----------------- |
|
137 // test with multiple namespaces |
|
138 WebdavPropfindRequest *p2 = propfind_parse( |
|
139 sn, |
|
140 rq, |
|
141 TEST_PROPFIND2, |
|
142 strlen(TEST_PROPFIND2), |
|
143 &error); |
|
144 |
|
145 UCX_TEST_ASSERT(p2, "p2 is NULL"); |
|
146 UCX_TEST_ASSERT(p2->properties, "p2: no props"); |
|
147 UCX_TEST_ASSERT(!p2->allprop, "p2: allprop is TRUE"); |
|
148 UCX_TEST_ASSERT(!p2->propname, "p2: propname is TRUE"); |
|
149 |
|
150 // property 1: DAV:resourcetype |
|
151 elm = p2->properties; |
|
152 UCX_TEST_ASSERT( |
|
153 !strcmp(elm->property->name, "resourcetype"), |
|
154 "p2: property 1 has wrong name"); |
|
155 UCX_TEST_ASSERT( |
|
156 !strcmp((char*)elm->property->namespace->href, "DAV:"), |
|
157 "p2: property 1 has wrong namespace"); |
|
158 |
|
159 // property 2: X:testprop |
|
160 elm = elm->next; |
|
161 UCX_TEST_ASSERT(elm, "p2: property 2 missing"); |
|
162 UCX_TEST_ASSERT( |
|
163 !strcmp(elm->property->name, "testprop"), |
|
164 "p2: property 2 has wrong name"); |
|
165 UCX_TEST_ASSERT( |
|
166 !strcmp((char*)elm->property->namespace->href, "http://example.com/"), |
|
167 "p2: property 2 has wrong namespace"); |
|
168 |
|
169 // property 3: X:name |
|
170 elm = elm->next; |
|
171 UCX_TEST_ASSERT(elm, "p2: property 3 missing"); |
|
172 UCX_TEST_ASSERT( |
|
173 !strcmp(elm->property->name, "name"), |
|
174 "p2: property 3 has wrong name"); |
|
175 UCX_TEST_ASSERT( |
|
176 !strcmp((char*)elm->property->namespace->href, "http://example.com/"), |
|
177 "p2: property 3 has wrong namespace"); |
|
178 |
|
179 // property 4: Z:testprop |
|
180 elm = elm->next; |
|
181 UCX_TEST_ASSERT(elm, "p2: property 4 missing"); |
|
182 UCX_TEST_ASSERT( |
|
183 !strcmp(elm->property->name, "testprop"), |
|
184 "p2: property 4 has wrong name"); |
|
185 UCX_TEST_ASSERT( |
|
186 !strcmp((char*)elm->property->namespace->href, "testns"), |
|
187 "p2: property 4 has wrong namespace"); |
|
188 |
|
189 |
|
190 // |
|
191 // ----------------- TEST_PROPFIND3 ----------------- |
|
192 // test allprop |
|
193 WebdavPropfindRequest *p3 = propfind_parse(sn, rq, TEST_PROPFIND3, strlen(TEST_PROPFIND3), &error); |
|
194 |
|
195 UCX_TEST_ASSERT(p3, "p3 is NULL"); |
|
196 UCX_TEST_ASSERT(!p3->properties, "p2: has props"); |
|
197 UCX_TEST_ASSERT(p3->allprop, "p2: allprop is FALSE"); |
|
198 UCX_TEST_ASSERT(!p3->propname, "p2: propname is TRUE"); |
|
199 UCX_TEST_ASSERT(p3->propcount == 0, "p2: wrong propcount"); |
|
200 |
|
201 |
|
202 // |
|
203 // ----------------- TEST_PROPFIND4 ----------------- |
|
204 // test propname |
|
205 WebdavPropfindRequest *p4 = propfind_parse(sn, rq, TEST_PROPFIND4, strlen(TEST_PROPFIND4), &error); |
|
206 |
|
207 UCX_TEST_ASSERT(p4, "p4 is NULL"); |
|
208 UCX_TEST_ASSERT(!p4->properties, "p2: has props"); |
|
209 UCX_TEST_ASSERT(!p4->allprop, "p2: allprop is TRUE"); |
|
210 UCX_TEST_ASSERT(p4->propname, "p2: propname is FALSE"); |
|
211 |
|
212 |
|
213 // |
|
214 // ----------------- TEST_PROPFIND5 ----------------- |
|
215 // test duplicate check |
|
216 WebdavPropfindRequest *p5 = propfind_parse(sn, rq, TEST_PROPFIND5, strlen(TEST_PROPFIND5), &error); |
|
217 |
|
218 UCX_TEST_ASSERT(p5, "p5 is NULL"); |
|
219 UCX_TEST_ASSERT(p5->properties, "p5: no props"); |
|
220 UCX_TEST_ASSERT(!p5->allprop, "p5: allprop is TRUE"); |
|
221 UCX_TEST_ASSERT(!p5->propname, "p5: propname is TRUE"); |
|
222 UCX_TEST_ASSERT(p5->propcount == 4, "p5: wrong propcount"); |
|
223 |
|
224 // property 1: DAV:displayname |
|
225 elm = p5->properties; |
|
226 UCX_TEST_ASSERT(elm, "p5: property 1 missing"); |
|
227 UCX_TEST_ASSERT( |
|
228 !strcmp(elm->property->name, "displayname"), |
|
229 "p5: property 1 has wrong name"); |
|
230 UCX_TEST_ASSERT( |
|
231 !strcmp((char*)elm->property->namespace->href, "DAV:"), |
|
232 "p5: property 1 has wrong namespace"); |
|
233 |
|
234 elm = elm->next; |
|
235 UCX_TEST_ASSERT(elm, "p5: property 2 missing"); |
|
236 elm = elm->next; |
|
237 UCX_TEST_ASSERT(elm, "p5: property 3 missing"); |
|
238 |
|
239 // property 4: DAV:resourcetype |
|
240 elm = elm->next; |
|
241 UCX_TEST_ASSERT(elm, "p5: property 4 missing"); |
|
242 UCX_TEST_ASSERT( |
|
243 !strcmp(elm->property->name, "resourcetype"), |
|
244 "p5: property 4 has wrong name"); |
|
245 UCX_TEST_ASSERT( |
|
246 !strcmp((char*)elm->property->namespace->href, "DAV:"), |
|
247 "p5: property 4 has wrong namespace"); |
|
248 |
|
249 |
|
250 // |
|
251 // ----------------- TEST_PROPFIND6 ----------------- |
|
252 // test prop/allprop mix |
|
253 WebdavPropfindRequest *p6 = propfind_parse(sn, rq, TEST_PROPFIND6, strlen(TEST_PROPFIND6), &error); |
|
254 |
|
255 UCX_TEST_ASSERT(p6, "p5 is NULL"); |
|
256 UCX_TEST_ASSERT(!p6->properties, "p5: has props"); |
|
257 UCX_TEST_ASSERT(p6->allprop, "p5: allprop is FALSE"); |
|
258 UCX_TEST_ASSERT(!p6->propname, "p5: propname is TRUE"); |
|
259 UCX_TEST_ASSERT(p6->propcount == 0, "p5: wrong propcount"); |
|
260 |
|
261 UCX_TEST_END |
|
262 |
|
263 pool_destroy(sn->pool); |
|
264 } |
|
265 |
|
266 UCX_TEST(test_proppatch_parse) { |
|
267 Session *sn = testutil_session(); |
|
268 Request *rq = testutil_request(sn->pool, "PROPPATCH", "/"); |
|
269 |
|
270 UCX_TEST_BEGIN |
|
271 int error = 0; |
|
272 |
|
273 WebdavProppatchRequest *p1 = proppatch_parse(sn, rq, TEST_PROPPATCH1, strlen(TEST_PROPPATCH1), &error); |
|
274 |
|
275 UCX_TEST_ASSERT(p1->set, "p1: missing set props"); |
|
276 UCX_TEST_ASSERT(!p1->remove, "p1: has remove props"); |
|
277 UCX_TEST_ASSERT(p1->setcount == 2, "p1: wrong setcount"); |
|
278 UCX_TEST_ASSERT(p1->set->next, "p1: set plist broken"); |
|
279 UCX_TEST_ASSERT(!p1->set->next->next, "p1: set plist has no end"); |
|
280 UCX_TEST_ASSERT(p1->set->property, "p1: missing property ptr in plist"); |
|
281 UCX_TEST_ASSERT( |
|
282 !strcmp(p1->set->property->name, "test"), |
|
283 "p1: wrong property 1 name"); |
|
284 |
|
285 WebdavProppatchRequest *p2 = proppatch_parse(sn, rq, TEST_PROPPATCH2, strlen(TEST_PROPPATCH2), &error); |
|
286 |
|
287 UCX_TEST_ASSERT(p2->set, "p2: missing set props"); |
|
288 UCX_TEST_ASSERT(p2->remove, "p2: missing remove props"); |
|
289 UCX_TEST_ASSERT(p2->setcount == 4, "p2: wrong setcount"); |
|
290 UCX_TEST_ASSERT(p2->removecount == 1, "p2: wrong removecount"); |
|
291 |
|
292 UCX_TEST_ASSERT( |
|
293 !strcmp((char*)p2->set->property->namespace->href, "http://example.com/"), |
|
294 "p2: set property 1: wrong namespace"); |
|
295 UCX_TEST_ASSERT( |
|
296 !strcmp(p2->set->property->name, "a"), |
|
297 "p2: set property 1: wrong name"); |
|
298 WSXmlNode *p2set1 = p2->set->property->value.node; |
|
299 UCX_TEST_ASSERT( |
|
300 p2set1->type == WS_NODE_TEXT, |
|
301 "p2: set property 1: wrong type"); |
|
302 UCX_TEST_ASSERT( |
|
303 p2set1->content, |
|
304 "p2: set property 1: no text"); |
|
305 UCX_TEST_ASSERT( |
|
306 !strcmp((char*)p2set1->content, "test"), |
|
307 "p2: set property 1: wrong value"); |
|
308 |
|
309 WSXmlNode *p2set3 = p2->set->next->next->property->value.node; |
|
310 UCX_TEST_ASSERT(p2set3, "p2: set property 3 missing"); |
|
311 UCX_TEST_ASSERT( |
|
312 p2set3->type == WS_NODE_TEXT, |
|
313 "p2: set property 3: wrong type"); |
|
314 UCX_TEST_ASSERT( |
|
315 p2set3->next, |
|
316 "p2: set property 3: missing element X:name"); |
|
317 |
|
318 UCX_TEST_ASSERT( |
|
319 xmlHasProp(p2set3->next, BAD_CAST"test"), |
|
320 "p2: set property 3: missing attribute 'test'"); |
|
321 |
|
322 UCX_TEST_ASSERT( |
|
323 xmlHasProp(p2set3->next, BAD_CAST"abc"), |
|
324 "p2: set property 3: missing attribute 'abc"); |
|
325 |
|
326 xmlChar *value1 = xmlGetProp(p2set3->next, BAD_CAST"test"); |
|
327 UCX_TEST_ASSERT( |
|
328 !strcmp((char*) value1, "test1"), |
|
329 "p2: set property 3: wrong attribute value 1"); |
|
330 xmlFree(value1); |
|
331 |
|
332 xmlChar *value2 = xmlGetProp(p2set3->next, BAD_CAST"abc"); |
|
333 UCX_TEST_ASSERT( |
|
334 !strcmp((char*) value2, "def"), |
|
335 "p2: set property 3: wrong attribute value 2"); |
|
336 xmlFree(value2); |
|
337 |
|
338 UCX_TEST_ASSERT( |
|
339 !strcmp(p2->remove->property->name, "e"), |
|
340 "p2: wrong remove property"); |
|
341 |
|
342 UCX_TEST_END |
|
343 |
|
344 pool_destroy(sn->pool); |
|
345 } |
|
346 |
|
347 UCX_TEST(test_lock_parse) { |
|
348 Session *sn = testutil_session(); |
|
349 Request *rq = testutil_request(sn->pool, "LOCK", "/"); |
|
350 |
|
351 UCX_TEST_BEGIN |
|
352 int error = 0; |
|
353 |
|
354 WebdavLockRequest *l1 = lock_parse(sn, rq, TEST_LOCK1, strlen(TEST_LOCK1), &error); |
|
355 |
|
356 UCX_TEST_ASSERT(l1, "l1 is NULL"); |
|
357 UCX_TEST_ASSERT(l1->type == WEBDAV_LOCK_WRITE, "l1: wrong type"); |
|
358 UCX_TEST_ASSERT(l1->scope == WEBDAV_LOCK_SHARED, "l1: wrong scope"); |
|
359 UCX_TEST_ASSERT(l1->owner, "l1: owner is NULL"); |
|
360 UCX_TEST_ASSERT(!strcmp((char*)l1->owner->content, "User"), "l1: wrong owner"); |
|
361 |
|
362 UCX_TEST_END |
|
363 |
|
364 pool_destroy(sn->pool); |
|
365 } |
|
366 |
|
367 UCX_TEST(test_rqbody2buffer) { |
|
368 Session *sn; |
|
369 Request *rq; |
|
370 |
|
371 UCX_TEST_BEGIN; |
|
372 // |
|
373 // TEST 1 |
|
374 sn = testutil_session(); |
|
375 rq = testutil_request(sn->pool, "PUT", "/"); |
|
376 testutil_request_body(sn, rq, "Hello World!", 12); |
|
377 |
|
378 UcxBuffer *b1 = rqbody2buffer(sn, rq); |
|
379 UCX_TEST_ASSERT(b1->size == 12, "b1: wrong size"); |
|
380 UCX_TEST_ASSERT(!memcmp(b1->space,"Hello World!",12), "b1: wrong content"); |
|
381 |
|
382 ucx_buffer_free(b1); |
|
383 testutil_destroy_session(sn); |
|
384 |
|
385 // |
|
386 // TEST 2 |
|
387 size_t len1 = 25000; |
|
388 unsigned char *body1 = malloc(len1); |
|
389 for(int i=0;i<len1;i++) { |
|
390 body1[i] = i; |
|
391 } |
|
392 sn = testutil_session(); |
|
393 rq = testutil_request(sn->pool, "PUT", "/"); |
|
394 testutil_request_body(sn, rq, (char*)body1, len1); |
|
395 |
|
396 UcxBuffer *b2 = rqbody2buffer(sn, rq); |
|
397 UCX_TEST_ASSERT(b2->size == len1, "b2: wrong size"); |
|
398 UCX_TEST_ASSERT(!memcmp(b2->space, body1, len1), "b2: wrong content"); |
|
399 |
|
400 ucx_buffer_free(b2); |
|
401 testutil_destroy_session(sn); |
|
402 |
|
403 UCX_TEST_END; |
|
404 } |
|
405 |
|
406 UCX_TEST(test_webdav_plist_iterator) { |
|
407 Session *sn; |
|
408 Request *rq; |
|
409 WebdavPropfindRequest *propfind; |
|
410 |
|
411 UCX_TEST_BEGIN; |
|
412 UCX_TEST_ASSERT(!test_init(&sn, &rq, &propfind, TEST_PROPFIND1), "init failed"); |
|
413 |
|
414 WebdavPList *properties = propfind->properties; |
|
415 size_t count = 0; |
|
416 |
|
417 WebdavPListIterator i = webdav_plist_iterator(&properties); |
|
418 WebdavPList *cur; |
|
419 while(webdav_plist_iterator_next(&i, &cur)) { |
|
420 switch(i.index) { |
|
421 case 0: { |
|
422 UCX_TEST_ASSERT(!strcmp(cur->property->name, "displayname"), "wrong property 1"); |
|
423 break; |
|
424 } |
|
425 case 1: { |
|
426 UCX_TEST_ASSERT(!strcmp(cur->property->name, "getcontentlength"), "wrong property 2"); |
|
427 break; |
|
428 } |
|
429 case 2: { |
|
430 UCX_TEST_ASSERT(!strcmp(cur->property->name, "getcontenttype"), "wrong property 3"); |
|
431 break; |
|
432 } |
|
433 case 3: { |
|
434 UCX_TEST_ASSERT(!strcmp(cur->property->name, "getlastmodified"), "wrong property 4"); |
|
435 break; |
|
436 } |
|
437 case 4: { |
|
438 UCX_TEST_ASSERT(!strcmp(cur->property->name, "resourcetype"), "wrong property 5"); |
|
439 break; |
|
440 } |
|
441 case 5: { |
|
442 UCX_TEST_ASSERT(!strcmp(cur->property->name, "getetag"), "wrong property 6"); |
|
443 break; |
|
444 } |
|
445 } |
|
446 count++; |
|
447 } |
|
448 |
|
449 UCX_TEST_ASSERT(count == propfind->propcount, "wrong count"); |
|
450 |
|
451 |
|
452 UCX_TEST_END; |
|
453 testutil_destroy_session(sn); |
|
454 } |
|
455 |
|
456 UCX_TEST(test_webdav_plist_iterator_remove_current) { |
|
457 Session *sn; |
|
458 Request *rq; |
|
459 WebdavPropfindRequest *propfind; |
|
460 |
|
461 UCX_TEST_BEGIN; |
|
462 UCX_TEST_ASSERT(!test_init(&sn, &rq, &propfind, TEST_PROPFIND1), "init failed"); |
|
463 |
|
464 WebdavPList *properties1 = webdav_plist_clone(sn->pool, propfind->properties); |
|
465 WebdavPList *properties2 = webdav_plist_clone(sn->pool, propfind->properties); |
|
466 WebdavPList *properties3 = webdav_plist_clone(sn->pool, propfind->properties); |
|
467 WebdavPList *properties4 = webdav_plist_clone(sn->pool, propfind->properties); |
|
468 |
|
469 WebdavPListIterator i; |
|
470 WebdavPList *cur; |
|
471 |
|
472 // test removal of first element |
|
473 i = webdav_plist_iterator(&properties1); |
|
474 while(webdav_plist_iterator_next(&i, &cur)) { |
|
475 if(i.index == 0) { |
|
476 webdav_plist_iterator_remove_current(&i); |
|
477 } |
|
478 } |
|
479 |
|
480 UCX_TEST_ASSERT(!properties1->prev, "test1: prev not cleared"); |
|
481 UCX_TEST_ASSERT(!strcmp(properties1->property->name, "getcontentlength"), "test1: wrong property"); |
|
482 UCX_TEST_ASSERT(!strcmp(properties1->next->property->name, "getcontenttype"), "test1: wrong property 2"); |
|
483 UCX_TEST_ASSERT(properties1->next->prev == properties1, "test1: wrong link"); |
|
484 |
|
485 // test removal of second element |
|
486 i = webdav_plist_iterator(&properties2); |
|
487 while(webdav_plist_iterator_next(&i, &cur)) { |
|
488 if(i.index == 1) { |
|
489 webdav_plist_iterator_remove_current(&i); |
|
490 } |
|
491 } |
|
492 |
|
493 UCX_TEST_ASSERT(!strcmp(properties2->next->property->name, "getcontenttype"), "test2: wrong property"); |
|
494 UCX_TEST_ASSERT(properties2->next->prev == properties2, "test2: wrong link"); |
|
495 UCX_TEST_ASSERT(webdav_plist_size(properties2) == 5, "test2: wrong size"); |
|
496 |
|
497 // remove last element |
|
498 i = webdav_plist_iterator(&properties3); |
|
499 while(webdav_plist_iterator_next(&i, &cur)) { |
|
500 if(i.index == 5) { |
|
501 webdav_plist_iterator_remove_current(&i); |
|
502 } |
|
503 } |
|
504 |
|
505 UCX_TEST_ASSERT(webdav_plist_size(properties3) == 5, "test3: wrong size"); |
|
506 UCX_TEST_ASSERT(!strcmp(properties3->next->next->next->next->property->name, "resourcetype"), "test2: wrong property"); |
|
507 |
|
508 // remove all elements |
|
509 i = webdav_plist_iterator(&properties4); |
|
510 while(webdav_plist_iterator_next(&i, &cur)) { |
|
511 webdav_plist_iterator_remove_current(&i); |
|
512 switch(i.index) { |
|
513 case 0: { |
|
514 UCX_TEST_ASSERT(!strcmp(properties4->property->name, "getcontentlength"), "test4: wrong property 2"); |
|
515 UCX_TEST_ASSERT(properties4->prev == NULL, "test4: prev not NULL (0)"); |
|
516 break; |
|
517 } |
|
518 case 1: { |
|
519 UCX_TEST_ASSERT(!strcmp(properties4->property->name, "getcontenttype"), "test4: wrong property 3"); |
|
520 UCX_TEST_ASSERT(properties4->prev == NULL, "test4: prev not NULL (1)"); |
|
521 break; |
|
522 } |
|
523 case 2: { |
|
524 UCX_TEST_ASSERT(!strcmp(properties4->property->name, "getlastmodified"), "test4: wrong property 4"); |
|
525 UCX_TEST_ASSERT(properties4->prev == NULL, "test4: prev not NULL (2)"); |
|
526 break; |
|
527 } |
|
528 case 3: { |
|
529 UCX_TEST_ASSERT(!strcmp(properties4->property->name, "resourcetype"), "test4: wrong property 5"); |
|
530 UCX_TEST_ASSERT(properties4->prev == NULL, "test4: prev not NULL (3)"); |
|
531 break; |
|
532 } |
|
533 case 4: { |
|
534 UCX_TEST_ASSERT(!strcmp(properties4->property->name, "getetag"), "test4: wrong property 6"); |
|
535 UCX_TEST_ASSERT(properties4->prev == NULL, "test4: prev not NULL (4)"); |
|
536 break; |
|
537 } |
|
538 default: { |
|
539 UCX_TEST_ASSERT(i.index <= 5, "fail"); |
|
540 } |
|
541 } |
|
542 } |
|
543 |
|
544 UCX_TEST_ASSERT(properties4 == NULL, "test4: list not NULL"); |
|
545 |
|
546 UCX_TEST_END; |
|
547 testutil_destroy_session(sn); |
|
548 } |
|
549 |
|
550 UCX_TEST(test_msresponse_addproperty) { |
|
551 Session *sn = testutil_session(); |
|
552 Request *rq = testutil_request(sn->pool, "PROPFIND", "/"); |
|
553 Multistatus *ms = multistatus_response(sn, rq); |
|
554 MSResponse *r; |
|
555 |
|
556 UCX_TEST_BEGIN; |
|
557 |
|
558 r = (MSResponse*)ms->response.addresource((WebdavResponse*)ms, "/"); |
|
559 |
|
560 WebdavProperty p1; |
|
561 WebdavProperty p[16]; |
|
562 const char *names[] = {"a1", "a2", "a3", "a4", "a5", "a6", "a7", "a8", "a9"}; |
|
563 |
|
564 // init test data |
|
565 p1.namespace = webdav_dav_namespace(); |
|
566 p1.lang = NULL; |
|
567 p1.name = "test1"; |
|
568 p1.value.data = NULL; |
|
569 p1.vtype = 0; |
|
570 |
|
571 for(int i=0;i<8;i++) { |
|
572 p[i].namespace = webdav_dav_namespace(); |
|
573 p[i].name = names[i]; |
|
574 p[i].lang = NULL; |
|
575 p[i].value.node = NULL; |
|
576 p[1].vtype = 0; |
|
577 } |
|
578 |
|
579 UCX_TEST_ASSERT(!r->plist_begin && !r->plist_end, "plist not empty"); |
|
580 |
|
581 r->resource.addproperty((WebdavResource*)r, &p1, 200); |
|
582 UCX_TEST_ASSERT(r->plist_begin, "!plist_begin"); |
|
583 UCX_TEST_ASSERT(r->plist_begin == r->plist_end, "plist begin != end"); |
|
584 |
|
585 r->resource.addproperty((WebdavResource*)r, &p[0], 404); |
|
586 r->resource.addproperty((WebdavResource*)r, &p[1], 404); |
|
587 r->resource.addproperty((WebdavResource*)r, &p[2], 403); |
|
588 r->resource.addproperty((WebdavResource*)r, &p[3], 403); |
|
589 r->resource.addproperty((WebdavResource*)r, &p[4], 403); |
|
590 r->resource.addproperty((WebdavResource*)r, &p[5], 403); |
|
591 r->resource.addproperty((WebdavResource*)r, &p[6], 500); |
|
592 |
|
593 UCX_TEST_ASSERT(r->plist_begin == r->plist_end, "plist begin != end"); |
|
594 |
|
595 UCX_TEST_ASSERT(r->errors, "no prop errors"); |
|
596 UCX_TEST_ASSERT(r->errors->next, "no second error code"); |
|
597 UCX_TEST_ASSERT(r->errors->next->next, "no third error code"); |
|
598 UCX_TEST_ASSERT(!r->errors->next->next->next, "too many error codes"); |
|
599 |
|
600 UCX_TEST_ASSERT(ucx_list_size(r->errors->begin) == 2, "404 list size != 2"); |
|
601 UCX_TEST_ASSERT(ucx_list_size(r->errors->next->begin) == 4, "403 list size != 4"); |
|
602 UCX_TEST_ASSERT(ucx_list_size(r->errors->next->next->begin) == 1, "500 list size != 1"); |
|
603 |
|
604 UCX_TEST_END; |
|
605 } |
|
606 |
|
607 /* ----------------------------- Test Backends --------------------------*/ |
41 /* ----------------------------- Test Backends --------------------------*/ |
608 |
42 |
609 // backend2 |
43 // backend2 |
610 static int backend2_propfind_init( |
44 static int backend2_propfind_init( |
611 WebdavPropfindRequest *propfind, |
45 WebdavPropfindRequest *propfind, |
677 &backend2 |
111 &backend2 |
678 }; |
112 }; |
679 |
113 |
680 /* ----------------------------------------------------------------------*/ |
114 /* ----------------------------------------------------------------------*/ |
681 |
115 |
|
116 |
|
117 static int test_init( |
|
118 Session **out_sn, |
|
119 Request **out_rq, |
|
120 WebdavPropfindRequest **out_propfind, |
|
121 const char *xml) |
|
122 { |
|
123 Session *sn = testutil_session(); |
|
124 Request *rq = testutil_request(sn->pool, "PROPFIND", "/"); |
|
125 |
|
126 int error = 0; |
|
127 |
|
128 WebdavPropfindRequest *propfind = propfind_parse( |
|
129 sn, |
|
130 rq, |
|
131 xml, |
|
132 strlen(xml), |
|
133 &error); |
|
134 |
|
135 if(error) { |
|
136 return 1; |
|
137 } |
|
138 |
|
139 if(!propfind || !propfind->properties) { |
|
140 return 1; |
|
141 } |
|
142 |
|
143 *out_sn = sn; |
|
144 *out_rq = rq; |
|
145 *out_propfind = propfind; |
|
146 return 0; |
|
147 } |
|
148 |
|
149 |
|
150 UCX_TEST(test_propfind_parse) { |
|
151 Session *sn = testutil_session(); |
|
152 Request *rq = testutil_request(sn->pool, "PROPFIND", "/"); |
|
153 |
|
154 UCX_TEST_BEGIN |
|
155 |
|
156 int error = 0; |
|
157 |
|
158 // |
|
159 // ----------------- TEST_PROPFIND1 ----------------- |
|
160 // test basic propfind request |
|
161 WebdavPropfindRequest *p1 = propfind_parse( |
|
162 sn, |
|
163 rq, |
|
164 TEST_PROPFIND1, |
|
165 strlen(TEST_PROPFIND1), |
|
166 &error); |
|
167 |
|
168 UCX_TEST_ASSERT(p1, "p1 is NULL"); |
|
169 UCX_TEST_ASSERT(p1->properties, "p1: no props"); |
|
170 UCX_TEST_ASSERT(!p1->allprop, "p1: allprop is TRUE"); |
|
171 UCX_TEST_ASSERT(!p1->propname, "p1: propname is TRUE"); |
|
172 UCX_TEST_ASSERT(p1->propcount == 6, "p1: wrong propcount"); |
|
173 |
|
174 // property 1: DAV:displayname |
|
175 WebdavPList *elm = p1->properties; |
|
176 UCX_TEST_ASSERT( |
|
177 !strcmp(elm->property->name, "displayname"), |
|
178 "p1: property 1 has wrong name"); |
|
179 UCX_TEST_ASSERT( |
|
180 !strcmp((char*)elm->property->namespace->href, "DAV:"), |
|
181 "p1: property 1 has wrong namespace"); |
|
182 |
|
183 // property 2: DAV:getcontentlength |
|
184 elm = elm->next; |
|
185 UCX_TEST_ASSERT(elm, "p1: property 2 missing"); |
|
186 UCX_TEST_ASSERT( |
|
187 !strcmp(elm->property->name, "getcontentlength"), |
|
188 "p1: property 2 has wrong name"); |
|
189 UCX_TEST_ASSERT( |
|
190 !strcmp((char*)elm->property->namespace->href, "DAV:"), |
|
191 "p1: property 2 has wrong namespace"); |
|
192 |
|
193 elm = elm->next; |
|
194 UCX_TEST_ASSERT(elm, "p1: property 3 missing"); |
|
195 elm = elm->next; |
|
196 UCX_TEST_ASSERT(elm, "p1: property 4 missing"); |
|
197 elm = elm->next; |
|
198 UCX_TEST_ASSERT(elm, "p1: property 5 missing"); |
|
199 |
|
200 // property 6: DAV:getetag |
|
201 elm = elm->next; |
|
202 UCX_TEST_ASSERT(elm, "p1: property 6 missing"); |
|
203 UCX_TEST_ASSERT( |
|
204 !strcmp(elm->property->name, "getetag"), |
|
205 "p1: property 6 has wrong name"); |
|
206 UCX_TEST_ASSERT( |
|
207 !strcmp((char*)elm->property->namespace->href, "DAV:"), |
|
208 "p1: property 6 has wrong namespace"); |
|
209 UCX_TEST_ASSERT(!elm->next, "p1: should not have property 7"); |
|
210 |
|
211 // |
|
212 // ----------------- TEST_PROPFIND2 ----------------- |
|
213 // test with multiple namespaces |
|
214 WebdavPropfindRequest *p2 = propfind_parse( |
|
215 sn, |
|
216 rq, |
|
217 TEST_PROPFIND2, |
|
218 strlen(TEST_PROPFIND2), |
|
219 &error); |
|
220 |
|
221 UCX_TEST_ASSERT(p2, "p2 is NULL"); |
|
222 UCX_TEST_ASSERT(p2->properties, "p2: no props"); |
|
223 UCX_TEST_ASSERT(!p2->allprop, "p2: allprop is TRUE"); |
|
224 UCX_TEST_ASSERT(!p2->propname, "p2: propname is TRUE"); |
|
225 |
|
226 // property 1: DAV:resourcetype |
|
227 elm = p2->properties; |
|
228 UCX_TEST_ASSERT( |
|
229 !strcmp(elm->property->name, "resourcetype"), |
|
230 "p2: property 1 has wrong name"); |
|
231 UCX_TEST_ASSERT( |
|
232 !strcmp((char*)elm->property->namespace->href, "DAV:"), |
|
233 "p2: property 1 has wrong namespace"); |
|
234 |
|
235 // property 2: X:testprop |
|
236 elm = elm->next; |
|
237 UCX_TEST_ASSERT(elm, "p2: property 2 missing"); |
|
238 UCX_TEST_ASSERT( |
|
239 !strcmp(elm->property->name, "testprop"), |
|
240 "p2: property 2 has wrong name"); |
|
241 UCX_TEST_ASSERT( |
|
242 !strcmp((char*)elm->property->namespace->href, "http://example.com/"), |
|
243 "p2: property 2 has wrong namespace"); |
|
244 |
|
245 // property 3: X:name |
|
246 elm = elm->next; |
|
247 UCX_TEST_ASSERT(elm, "p2: property 3 missing"); |
|
248 UCX_TEST_ASSERT( |
|
249 !strcmp(elm->property->name, "name"), |
|
250 "p2: property 3 has wrong name"); |
|
251 UCX_TEST_ASSERT( |
|
252 !strcmp((char*)elm->property->namespace->href, "http://example.com/"), |
|
253 "p2: property 3 has wrong namespace"); |
|
254 |
|
255 // property 4: Z:testprop |
|
256 elm = elm->next; |
|
257 UCX_TEST_ASSERT(elm, "p2: property 4 missing"); |
|
258 UCX_TEST_ASSERT( |
|
259 !strcmp(elm->property->name, "testprop"), |
|
260 "p2: property 4 has wrong name"); |
|
261 UCX_TEST_ASSERT( |
|
262 !strcmp((char*)elm->property->namespace->href, "testns"), |
|
263 "p2: property 4 has wrong namespace"); |
|
264 |
|
265 |
|
266 // |
|
267 // ----------------- TEST_PROPFIND3 ----------------- |
|
268 // test allprop |
|
269 WebdavPropfindRequest *p3 = propfind_parse(sn, rq, TEST_PROPFIND3, strlen(TEST_PROPFIND3), &error); |
|
270 |
|
271 UCX_TEST_ASSERT(p3, "p3 is NULL"); |
|
272 UCX_TEST_ASSERT(!p3->properties, "p2: has props"); |
|
273 UCX_TEST_ASSERT(p3->allprop, "p2: allprop is FALSE"); |
|
274 UCX_TEST_ASSERT(!p3->propname, "p2: propname is TRUE"); |
|
275 UCX_TEST_ASSERT(p3->propcount == 0, "p2: wrong propcount"); |
|
276 |
|
277 |
|
278 // |
|
279 // ----------------- TEST_PROPFIND4 ----------------- |
|
280 // test propname |
|
281 WebdavPropfindRequest *p4 = propfind_parse(sn, rq, TEST_PROPFIND4, strlen(TEST_PROPFIND4), &error); |
|
282 |
|
283 UCX_TEST_ASSERT(p4, "p4 is NULL"); |
|
284 UCX_TEST_ASSERT(!p4->properties, "p2: has props"); |
|
285 UCX_TEST_ASSERT(!p4->allprop, "p2: allprop is TRUE"); |
|
286 UCX_TEST_ASSERT(p4->propname, "p2: propname is FALSE"); |
|
287 |
|
288 |
|
289 // |
|
290 // ----------------- TEST_PROPFIND5 ----------------- |
|
291 // test duplicate check |
|
292 WebdavPropfindRequest *p5 = propfind_parse(sn, rq, TEST_PROPFIND5, strlen(TEST_PROPFIND5), &error); |
|
293 |
|
294 UCX_TEST_ASSERT(p5, "p5 is NULL"); |
|
295 UCX_TEST_ASSERT(p5->properties, "p5: no props"); |
|
296 UCX_TEST_ASSERT(!p5->allprop, "p5: allprop is TRUE"); |
|
297 UCX_TEST_ASSERT(!p5->propname, "p5: propname is TRUE"); |
|
298 UCX_TEST_ASSERT(p5->propcount == 4, "p5: wrong propcount"); |
|
299 |
|
300 // property 1: DAV:displayname |
|
301 elm = p5->properties; |
|
302 UCX_TEST_ASSERT(elm, "p5: property 1 missing"); |
|
303 UCX_TEST_ASSERT( |
|
304 !strcmp(elm->property->name, "displayname"), |
|
305 "p5: property 1 has wrong name"); |
|
306 UCX_TEST_ASSERT( |
|
307 !strcmp((char*)elm->property->namespace->href, "DAV:"), |
|
308 "p5: property 1 has wrong namespace"); |
|
309 |
|
310 elm = elm->next; |
|
311 UCX_TEST_ASSERT(elm, "p5: property 2 missing"); |
|
312 elm = elm->next; |
|
313 UCX_TEST_ASSERT(elm, "p5: property 3 missing"); |
|
314 |
|
315 // property 4: DAV:resourcetype |
|
316 elm = elm->next; |
|
317 UCX_TEST_ASSERT(elm, "p5: property 4 missing"); |
|
318 UCX_TEST_ASSERT( |
|
319 !strcmp(elm->property->name, "resourcetype"), |
|
320 "p5: property 4 has wrong name"); |
|
321 UCX_TEST_ASSERT( |
|
322 !strcmp((char*)elm->property->namespace->href, "DAV:"), |
|
323 "p5: property 4 has wrong namespace"); |
|
324 |
|
325 |
|
326 // |
|
327 // ----------------- TEST_PROPFIND6 ----------------- |
|
328 // test prop/allprop mix |
|
329 WebdavPropfindRequest *p6 = propfind_parse(sn, rq, TEST_PROPFIND6, strlen(TEST_PROPFIND6), &error); |
|
330 |
|
331 UCX_TEST_ASSERT(p6, "p5 is NULL"); |
|
332 UCX_TEST_ASSERT(!p6->properties, "p5: has props"); |
|
333 UCX_TEST_ASSERT(p6->allprop, "p5: allprop is FALSE"); |
|
334 UCX_TEST_ASSERT(!p6->propname, "p5: propname is TRUE"); |
|
335 UCX_TEST_ASSERT(p6->propcount == 0, "p5: wrong propcount"); |
|
336 |
|
337 UCX_TEST_END |
|
338 |
|
339 pool_destroy(sn->pool); |
|
340 } |
|
341 |
|
342 UCX_TEST(test_proppatch_parse) { |
|
343 Session *sn = testutil_session(); |
|
344 Request *rq = testutil_request(sn->pool, "PROPPATCH", "/"); |
|
345 |
|
346 UCX_TEST_BEGIN |
|
347 int error = 0; |
|
348 |
|
349 WebdavProppatchRequest *p1 = proppatch_parse(sn, rq, TEST_PROPPATCH1, strlen(TEST_PROPPATCH1), &error); |
|
350 |
|
351 UCX_TEST_ASSERT(p1->set, "p1: missing set props"); |
|
352 UCX_TEST_ASSERT(!p1->remove, "p1: has remove props"); |
|
353 UCX_TEST_ASSERT(p1->setcount == 2, "p1: wrong setcount"); |
|
354 UCX_TEST_ASSERT(p1->set->next, "p1: set plist broken"); |
|
355 UCX_TEST_ASSERT(!p1->set->next->next, "p1: set plist has no end"); |
|
356 UCX_TEST_ASSERT(p1->set->property, "p1: missing property ptr in plist"); |
|
357 UCX_TEST_ASSERT( |
|
358 !strcmp(p1->set->property->name, "test"), |
|
359 "p1: wrong property 1 name"); |
|
360 |
|
361 WebdavProppatchRequest *p2 = proppatch_parse(sn, rq, TEST_PROPPATCH2, strlen(TEST_PROPPATCH2), &error); |
|
362 |
|
363 UCX_TEST_ASSERT(p2->set, "p2: missing set props"); |
|
364 UCX_TEST_ASSERT(p2->remove, "p2: missing remove props"); |
|
365 UCX_TEST_ASSERT(p2->setcount == 4, "p2: wrong setcount"); |
|
366 UCX_TEST_ASSERT(p2->removecount == 1, "p2: wrong removecount"); |
|
367 |
|
368 UCX_TEST_ASSERT( |
|
369 !strcmp((char*)p2->set->property->namespace->href, "http://example.com/"), |
|
370 "p2: set property 1: wrong namespace"); |
|
371 UCX_TEST_ASSERT( |
|
372 !strcmp(p2->set->property->name, "a"), |
|
373 "p2: set property 1: wrong name"); |
|
374 WSXmlNode *p2set1 = p2->set->property->value.node; |
|
375 UCX_TEST_ASSERT( |
|
376 p2set1->type == WS_NODE_TEXT, |
|
377 "p2: set property 1: wrong type"); |
|
378 UCX_TEST_ASSERT( |
|
379 p2set1->content, |
|
380 "p2: set property 1: no text"); |
|
381 UCX_TEST_ASSERT( |
|
382 !strcmp((char*)p2set1->content, "test"), |
|
383 "p2: set property 1: wrong value"); |
|
384 |
|
385 WSXmlNode *p2set3 = p2->set->next->next->property->value.node; |
|
386 UCX_TEST_ASSERT(p2set3, "p2: set property 3 missing"); |
|
387 UCX_TEST_ASSERT( |
|
388 p2set3->type == WS_NODE_TEXT, |
|
389 "p2: set property 3: wrong type"); |
|
390 UCX_TEST_ASSERT( |
|
391 p2set3->next, |
|
392 "p2: set property 3: missing element X:name"); |
|
393 |
|
394 UCX_TEST_ASSERT( |
|
395 xmlHasProp(p2set3->next, BAD_CAST"test"), |
|
396 "p2: set property 3: missing attribute 'test'"); |
|
397 |
|
398 UCX_TEST_ASSERT( |
|
399 xmlHasProp(p2set3->next, BAD_CAST"abc"), |
|
400 "p2: set property 3: missing attribute 'abc"); |
|
401 |
|
402 xmlChar *value1 = xmlGetProp(p2set3->next, BAD_CAST"test"); |
|
403 UCX_TEST_ASSERT( |
|
404 !strcmp((char*) value1, "test1"), |
|
405 "p2: set property 3: wrong attribute value 1"); |
|
406 xmlFree(value1); |
|
407 |
|
408 xmlChar *value2 = xmlGetProp(p2set3->next, BAD_CAST"abc"); |
|
409 UCX_TEST_ASSERT( |
|
410 !strcmp((char*) value2, "def"), |
|
411 "p2: set property 3: wrong attribute value 2"); |
|
412 xmlFree(value2); |
|
413 |
|
414 UCX_TEST_ASSERT( |
|
415 !strcmp(p2->remove->property->name, "e"), |
|
416 "p2: wrong remove property"); |
|
417 |
|
418 UCX_TEST_END |
|
419 |
|
420 pool_destroy(sn->pool); |
|
421 } |
|
422 |
|
423 UCX_TEST(test_lock_parse) { |
|
424 Session *sn = testutil_session(); |
|
425 Request *rq = testutil_request(sn->pool, "LOCK", "/"); |
|
426 |
|
427 UCX_TEST_BEGIN |
|
428 int error = 0; |
|
429 |
|
430 WebdavLockRequest *l1 = lock_parse(sn, rq, TEST_LOCK1, strlen(TEST_LOCK1), &error); |
|
431 |
|
432 UCX_TEST_ASSERT(l1, "l1 is NULL"); |
|
433 UCX_TEST_ASSERT(l1->type == WEBDAV_LOCK_WRITE, "l1: wrong type"); |
|
434 UCX_TEST_ASSERT(l1->scope == WEBDAV_LOCK_SHARED, "l1: wrong scope"); |
|
435 UCX_TEST_ASSERT(l1->owner, "l1: owner is NULL"); |
|
436 UCX_TEST_ASSERT(!strcmp((char*)l1->owner->content, "User"), "l1: wrong owner"); |
|
437 |
|
438 UCX_TEST_END |
|
439 |
|
440 pool_destroy(sn->pool); |
|
441 } |
|
442 |
|
443 UCX_TEST(test_rqbody2buffer) { |
|
444 Session *sn; |
|
445 Request *rq; |
|
446 |
|
447 UCX_TEST_BEGIN; |
|
448 // |
|
449 // TEST 1 |
|
450 sn = testutil_session(); |
|
451 rq = testutil_request(sn->pool, "PUT", "/"); |
|
452 testutil_request_body(sn, rq, "Hello World!", 12); |
|
453 |
|
454 UcxBuffer *b1 = rqbody2buffer(sn, rq); |
|
455 UCX_TEST_ASSERT(b1->size == 12, "b1: wrong size"); |
|
456 UCX_TEST_ASSERT(!memcmp(b1->space,"Hello World!",12), "b1: wrong content"); |
|
457 |
|
458 ucx_buffer_free(b1); |
|
459 testutil_destroy_session(sn); |
|
460 |
|
461 // |
|
462 // TEST 2 |
|
463 size_t len1 = 25000; |
|
464 unsigned char *body1 = malloc(len1); |
|
465 for(int i=0;i<len1;i++) { |
|
466 body1[i] = i; |
|
467 } |
|
468 sn = testutil_session(); |
|
469 rq = testutil_request(sn->pool, "PUT", "/"); |
|
470 testutil_request_body(sn, rq, (char*)body1, len1); |
|
471 |
|
472 UcxBuffer *b2 = rqbody2buffer(sn, rq); |
|
473 UCX_TEST_ASSERT(b2->size == len1, "b2: wrong size"); |
|
474 UCX_TEST_ASSERT(!memcmp(b2->space, body1, len1), "b2: wrong content"); |
|
475 |
|
476 ucx_buffer_free(b2); |
|
477 testutil_destroy_session(sn); |
|
478 |
|
479 UCX_TEST_END; |
|
480 } |
|
481 |
|
482 UCX_TEST(test_webdav_plist_iterator) { |
|
483 Session *sn; |
|
484 Request *rq; |
|
485 WebdavPropfindRequest *propfind; |
|
486 |
|
487 UCX_TEST_BEGIN; |
|
488 UCX_TEST_ASSERT(!test_init(&sn, &rq, &propfind, TEST_PROPFIND1), "init failed"); |
|
489 |
|
490 WebdavPList *properties = propfind->properties; |
|
491 size_t count = 0; |
|
492 |
|
493 WebdavPListIterator i = webdav_plist_iterator(&properties); |
|
494 WebdavPList *cur; |
|
495 while(webdav_plist_iterator_next(&i, &cur)) { |
|
496 switch(i.index) { |
|
497 case 0: { |
|
498 UCX_TEST_ASSERT(!strcmp(cur->property->name, "displayname"), "wrong property 1"); |
|
499 break; |
|
500 } |
|
501 case 1: { |
|
502 UCX_TEST_ASSERT(!strcmp(cur->property->name, "getcontentlength"), "wrong property 2"); |
|
503 break; |
|
504 } |
|
505 case 2: { |
|
506 UCX_TEST_ASSERT(!strcmp(cur->property->name, "getcontenttype"), "wrong property 3"); |
|
507 break; |
|
508 } |
|
509 case 3: { |
|
510 UCX_TEST_ASSERT(!strcmp(cur->property->name, "getlastmodified"), "wrong property 4"); |
|
511 break; |
|
512 } |
|
513 case 4: { |
|
514 UCX_TEST_ASSERT(!strcmp(cur->property->name, "resourcetype"), "wrong property 5"); |
|
515 break; |
|
516 } |
|
517 case 5: { |
|
518 UCX_TEST_ASSERT(!strcmp(cur->property->name, "getetag"), "wrong property 6"); |
|
519 break; |
|
520 } |
|
521 } |
|
522 count++; |
|
523 } |
|
524 |
|
525 UCX_TEST_ASSERT(count == propfind->propcount, "wrong count"); |
|
526 |
|
527 |
|
528 UCX_TEST_END; |
|
529 testutil_destroy_session(sn); |
|
530 } |
|
531 |
|
532 UCX_TEST(test_webdav_plist_iterator_remove_current) { |
|
533 Session *sn; |
|
534 Request *rq; |
|
535 WebdavPropfindRequest *propfind; |
|
536 |
|
537 UCX_TEST_BEGIN; |
|
538 UCX_TEST_ASSERT(!test_init(&sn, &rq, &propfind, TEST_PROPFIND1), "init failed"); |
|
539 |
|
540 WebdavPList *properties1 = webdav_plist_clone(sn->pool, propfind->properties); |
|
541 WebdavPList *properties2 = webdav_plist_clone(sn->pool, propfind->properties); |
|
542 WebdavPList *properties3 = webdav_plist_clone(sn->pool, propfind->properties); |
|
543 WebdavPList *properties4 = webdav_plist_clone(sn->pool, propfind->properties); |
|
544 |
|
545 WebdavPListIterator i; |
|
546 WebdavPList *cur; |
|
547 |
|
548 // test removal of first element |
|
549 i = webdav_plist_iterator(&properties1); |
|
550 while(webdav_plist_iterator_next(&i, &cur)) { |
|
551 if(i.index == 0) { |
|
552 webdav_plist_iterator_remove_current(&i); |
|
553 } |
|
554 } |
|
555 |
|
556 UCX_TEST_ASSERT(!properties1->prev, "test1: prev not cleared"); |
|
557 UCX_TEST_ASSERT(!strcmp(properties1->property->name, "getcontentlength"), "test1: wrong property"); |
|
558 UCX_TEST_ASSERT(!strcmp(properties1->next->property->name, "getcontenttype"), "test1: wrong property 2"); |
|
559 UCX_TEST_ASSERT(properties1->next->prev == properties1, "test1: wrong link"); |
|
560 |
|
561 // test removal of second element |
|
562 i = webdav_plist_iterator(&properties2); |
|
563 while(webdav_plist_iterator_next(&i, &cur)) { |
|
564 if(i.index == 1) { |
|
565 webdav_plist_iterator_remove_current(&i); |
|
566 } |
|
567 } |
|
568 |
|
569 UCX_TEST_ASSERT(!strcmp(properties2->next->property->name, "getcontenttype"), "test2: wrong property"); |
|
570 UCX_TEST_ASSERT(properties2->next->prev == properties2, "test2: wrong link"); |
|
571 UCX_TEST_ASSERT(webdav_plist_size(properties2) == 5, "test2: wrong size"); |
|
572 |
|
573 // remove last element |
|
574 i = webdav_plist_iterator(&properties3); |
|
575 while(webdav_plist_iterator_next(&i, &cur)) { |
|
576 if(i.index == 5) { |
|
577 webdav_plist_iterator_remove_current(&i); |
|
578 } |
|
579 } |
|
580 |
|
581 UCX_TEST_ASSERT(webdav_plist_size(properties3) == 5, "test3: wrong size"); |
|
582 UCX_TEST_ASSERT(!strcmp(properties3->next->next->next->next->property->name, "resourcetype"), "test2: wrong property"); |
|
583 |
|
584 // remove all elements |
|
585 i = webdav_plist_iterator(&properties4); |
|
586 while(webdav_plist_iterator_next(&i, &cur)) { |
|
587 webdav_plist_iterator_remove_current(&i); |
|
588 switch(i.index) { |
|
589 case 0: { |
|
590 UCX_TEST_ASSERT(!strcmp(properties4->property->name, "getcontentlength"), "test4: wrong property 2"); |
|
591 UCX_TEST_ASSERT(properties4->prev == NULL, "test4: prev not NULL (0)"); |
|
592 break; |
|
593 } |
|
594 case 1: { |
|
595 UCX_TEST_ASSERT(!strcmp(properties4->property->name, "getcontenttype"), "test4: wrong property 3"); |
|
596 UCX_TEST_ASSERT(properties4->prev == NULL, "test4: prev not NULL (1)"); |
|
597 break; |
|
598 } |
|
599 case 2: { |
|
600 UCX_TEST_ASSERT(!strcmp(properties4->property->name, "getlastmodified"), "test4: wrong property 4"); |
|
601 UCX_TEST_ASSERT(properties4->prev == NULL, "test4: prev not NULL (2)"); |
|
602 break; |
|
603 } |
|
604 case 3: { |
|
605 UCX_TEST_ASSERT(!strcmp(properties4->property->name, "resourcetype"), "test4: wrong property 5"); |
|
606 UCX_TEST_ASSERT(properties4->prev == NULL, "test4: prev not NULL (3)"); |
|
607 break; |
|
608 } |
|
609 case 4: { |
|
610 UCX_TEST_ASSERT(!strcmp(properties4->property->name, "getetag"), "test4: wrong property 6"); |
|
611 UCX_TEST_ASSERT(properties4->prev == NULL, "test4: prev not NULL (4)"); |
|
612 break; |
|
613 } |
|
614 default: { |
|
615 UCX_TEST_ASSERT(i.index <= 5, "fail"); |
|
616 } |
|
617 } |
|
618 } |
|
619 |
|
620 UCX_TEST_ASSERT(properties4 == NULL, "test4: list not NULL"); |
|
621 |
|
622 UCX_TEST_END; |
|
623 testutil_destroy_session(sn); |
|
624 } |
|
625 |
|
626 UCX_TEST(test_msresponse_addproperty) { |
|
627 Session *sn = testutil_session(); |
|
628 Request *rq = testutil_request(sn->pool, "PROPFIND", "/"); |
|
629 Multistatus *ms = multistatus_response(sn, rq); |
|
630 MSResponse *r; |
|
631 |
|
632 UCX_TEST_BEGIN; |
|
633 |
|
634 r = (MSResponse*)ms->response.addresource((WebdavResponse*)ms, "/"); |
|
635 |
|
636 WebdavProperty p1; |
|
637 WebdavProperty p[16]; |
|
638 const char *names[] = {"a1", "a2", "a3", "a4", "a5", "a6", "a7", "a8", "a9"}; |
|
639 |
|
640 // init test data |
|
641 p1.namespace = webdav_dav_namespace(); |
|
642 p1.lang = NULL; |
|
643 p1.name = "test1"; |
|
644 p1.value.data = NULL; |
|
645 p1.vtype = 0; |
|
646 |
|
647 for(int i=0;i<8;i++) { |
|
648 p[i].namespace = webdav_dav_namespace(); |
|
649 p[i].name = names[i]; |
|
650 p[i].lang = NULL; |
|
651 p[i].value.node = NULL; |
|
652 p[1].vtype = 0; |
|
653 } |
|
654 |
|
655 UCX_TEST_ASSERT(!r->plist_begin && !r->plist_end, "plist not empty"); |
|
656 |
|
657 r->resource.addproperty((WebdavResource*)r, &p1, 200); |
|
658 UCX_TEST_ASSERT(r->plist_begin, "!plist_begin"); |
|
659 UCX_TEST_ASSERT(r->plist_begin == r->plist_end, "plist begin != end"); |
|
660 |
|
661 r->resource.addproperty((WebdavResource*)r, &p[0], 404); |
|
662 r->resource.addproperty((WebdavResource*)r, &p[1], 404); |
|
663 r->resource.addproperty((WebdavResource*)r, &p[2], 403); |
|
664 r->resource.addproperty((WebdavResource*)r, &p[3], 403); |
|
665 r->resource.addproperty((WebdavResource*)r, &p[4], 403); |
|
666 r->resource.addproperty((WebdavResource*)r, &p[5], 403); |
|
667 r->resource.addproperty((WebdavResource*)r, &p[6], 500); |
|
668 |
|
669 UCX_TEST_ASSERT(r->plist_begin == r->plist_end, "plist begin != end"); |
|
670 |
|
671 UCX_TEST_ASSERT(r->errors, "no prop errors"); |
|
672 UCX_TEST_ASSERT(r->errors->next, "no second error code"); |
|
673 UCX_TEST_ASSERT(r->errors->next->next, "no third error code"); |
|
674 UCX_TEST_ASSERT(!r->errors->next->next->next, "too many error codes"); |
|
675 |
|
676 UCX_TEST_ASSERT(ucx_list_size(r->errors->begin) == 2, "404 list size != 2"); |
|
677 UCX_TEST_ASSERT(ucx_list_size(r->errors->next->begin) == 4, "403 list size != 4"); |
|
678 UCX_TEST_ASSERT(ucx_list_size(r->errors->next->next->begin) == 1, "500 list size != 1"); |
|
679 |
|
680 UCX_TEST_END; |
|
681 } |
|
682 |
682 UCX_TEST(test_webdav_propfind_init) { |
683 UCX_TEST(test_webdav_propfind_init) { |
683 Session *sn; |
684 Session *sn; |
684 Request *rq; |
685 Request *rq; |
685 WebdavPropfindRequest *propfind; |
686 WebdavPropfindRequest *propfind; |
686 UCX_TEST_BEGIN; |
687 UCX_TEST_BEGIN; |