src/server/test/webdav.c

branch
webdav
changeset 241
4adad7faf452
parent 239
d5031c30022c
child 242
c337a7ac82a8
equal deleted inserted replaced
240:cd74667f6c85 241:4adad7faf452
45 /* ----------------------------- Test Backends --------------------------*/ 45 /* ----------------------------- Test Backends --------------------------*/
46 46
47 static int backend2_init_called = 0; 47 static int backend2_init_called = 0;
48 static int backend2_propfind_do_count = 0; 48 static int backend2_propfind_do_count = 0;
49 static int backend2_propfind_finish_called = 0; 49 static int backend2_propfind_finish_called = 0;
50 static int backend2_proppatch_commit = 0;
51 static int backend2_proppatch_do_count = 0;
52 static int backend2_proppatch_finish_count = 0;
50 53
51 // backend2 54 // backend2
52 static int backend2_propfind_init( 55 static int backend2_propfind_init(
53 WebdavPropfindRequest *propfind, 56 WebdavPropfindRequest *propfind,
54 const char *path, 57 const char *path,
72 static int backend2_propfind_finish(WebdavPropfindRequest *propfind) { 75 static int backend2_propfind_finish(WebdavPropfindRequest *propfind) {
73 backend2_propfind_finish_called = 1; 76 backend2_propfind_finish_called = 1;
74 return 0; 77 return 0;
75 } 78 }
76 79
80 static int backend2_proppatch_do(
81 WebdavProppatchRequest *request,
82 WebdavResource *response,
83 VFSFile *file,
84 WebdavPList **out_set,
85 WebdavPList **out_remove)
86 {
87 backend2_proppatch_do_count++;
88
89 if(*out_remove) {
90 return 1; // backend1 should remove all remove-props
91 }
92
93 WebdavPListIterator i = webdav_plist_iterator(out_set);
94 WebdavPList *cur;
95 while(webdav_plist_iterator_next(&i, &cur)) {
96 if(!strcmp(cur->property->name, "a")) {
97 // property 'a' should already be removed by backend1
98 return 1;
99 } else if(!strcmp(cur->property->name, "abort")) {
100 return 1; // test abort
101 }
102 response->addproperty(response, cur->property, 200);
103 webdav_plist_iterator_remove_current(&i);
104 }
105
106 return 0;
107 }
108
109 static int backend2_proppatch_finish(
110 WebdavProppatchRequest *request,
111 WebdavResource *response,
112 VFSFile *file,
113 WSBool commit)
114 {
115 backend2_proppatch_finish_count++;
116 backend2_proppatch_commit = commit;
117 return 0;
118 }
119
77 static WebdavBackend backend2 = { 120 static WebdavBackend backend2 = {
78 backend2_propfind_init, 121 backend2_propfind_init,
79 backend2_propfind_do, 122 backend2_propfind_do,
80 backend2_propfind_finish, 123 backend2_propfind_finish,
124 backend2_proppatch_do,
125 backend2_proppatch_finish,
81 0, 126 0,
82 NULL 127 NULL
83 }; 128 };
84 129
85 // backend1 130 // backend1
86 131
87 static int backend1_init_called = 0; 132 static int backend1_init_called = 0;
88 static int backend1_propfind_do_count = 0; 133 static int backend1_propfind_do_count = 0;
89 static int backend1_propfind_finish_called = 0; 134 static int backend1_propfind_finish_called = 0;
135 static int backend1_proppatch_commit = 0;
136 static int backend1_proppatch_do_count = 0;
137 static int backend1_proppatch_finish_count = 0;
90 138
91 139
92 static int backend1_propfind_init( 140 static int backend1_propfind_init(
93 WebdavPropfindRequest *propfind, 141 WebdavPropfindRequest *propfind,
94 const char *path, 142 const char *path,
122 static int backend1_propfind_finish(WebdavPropfindRequest *propfind) { 170 static int backend1_propfind_finish(WebdavPropfindRequest *propfind) {
123 backend1_propfind_finish_called = 1; 171 backend1_propfind_finish_called = 1;
124 return 0; 172 return 0;
125 } 173 }
126 174
175 static int backend1_proppatch_do(
176 WebdavProppatchRequest *request,
177 WebdavResource *response,
178 VFSFile *file,
179 WebdavPList **out_set,
180 WebdavPList **out_remove)
181 {
182 backend1_proppatch_do_count++;
183
184 // remove everything from out_remove
185 WebdavPListIterator i = webdav_plist_iterator(out_remove);
186 WebdavPList *cur;
187 while(webdav_plist_iterator_next(&i, &cur)) {
188 response->addproperty(response, cur->property, 200);
189 webdav_plist_iterator_remove_current(&i);
190 }
191
192 // remove property 'a' and fail at property 'fail'
193 i = webdav_plist_iterator(out_set);
194 while(webdav_plist_iterator_next(&i, &cur)) {
195 if(!strcmp(cur->property->name, "fail")) {
196 response->addproperty(response, cur->property, 403);
197 webdav_plist_iterator_remove_current(&i);
198 } else if(!strcmp(cur->property->name, "a")) {
199 response->addproperty(response, cur->property, 200);
200 webdav_plist_iterator_remove_current(&i);
201 }
202 }
203
204 return 0;
205 }
206
207 static int backend1_proppatch_finish(
208 WebdavProppatchRequest *request,
209 WebdavResource *response,
210 VFSFile *file,
211 WSBool commit)
212 {
213 backend1_proppatch_finish_count++;
214 backend1_proppatch_commit = commit;
215 return 0;
216 }
217
127 WebdavBackend backend1 = { 218 WebdavBackend backend1 = {
128 backend1_propfind_init, 219 backend1_propfind_init,
129 backend1_propfind_do, 220 backend1_propfind_do,
130 backend1_propfind_finish, 221 backend1_propfind_finish,
222 backend1_proppatch_do,
223 backend1_proppatch_finish,
131 0, 224 0,
132 &backend2 225 &backend2
133 }; 226 };
134 227
135 static void reset_backends(void) { 228 static void reset_backends(void) {
136 backend1_init_called = 0; 229 backend1_init_called = 0;
137 backend1_propfind_do_count = 0; 230 backend1_propfind_do_count = 0;
138 backend1_propfind_finish_called = 0; 231 backend1_propfind_finish_called = 0;
232 backend1_proppatch_commit = 0;
233 backend1_proppatch_do_count = 0;
234 backend1_proppatch_finish_count = 0;
139 backend2_init_called = 0; 235 backend2_init_called = 0;
140 backend2_propfind_do_count = 0; 236 backend2_propfind_do_count = 0;
141 backend2_propfind_finish_called = 0; 237 backend2_propfind_finish_called = 0;
238 backend2_proppatch_commit = 0;
239 backend2_proppatch_do_count = 0;
240 backend2_proppatch_finish_count = 0;
142 } 241 }
143 242
144 /* ----------------------------------------------------------------------*/ 243 /* ----------------------------------------------------------------------*/
145 244
146 245
1233 } 1332 }
1234 1333
1235 UCX_TEST_END; 1334 UCX_TEST_END;
1236 testutil_destroy_session(sn); 1335 testutil_destroy_session(sn);
1237 } 1336 }
1337
1338 UCX_TEST(test_webdav_op_proppatch) {
1339 Session *sn;
1340 Request *rq;
1341 WebdavOperation *op;
1342
1343 Multistatus *ms;
1344 WebdavResource *res;
1345
1346 WebdavProperty p[16];
1347 const char *names[] = {"a1", "a2", "a3", "a4", "a5", "a6", "a7", "a8", "a9"};
1348 for(int i=0;i<8;i++) {
1349 p[i].namespace = webdav_dav_namespace();
1350 p[i].name = names[i];
1351 p[i].lang = NULL;
1352 p[i].value.node = NULL;
1353 p[1].vtype = 0;
1354 }
1355
1356 UCX_TEST_BEGIN;
1357
1358 // TEST_PROPPATCH2 should succeed
1359 reset_backends();
1360 op = test_proppatch_op1(&sn, &rq, TEST_PROPPATCH2);
1361 UCX_TEST_ASSERT(op, "failed to create proppatch operation");
1362
1363 int ret = webdav_op_proppatch(op, "/", "/");
1364 UCX_TEST_ASSERT(ret == 0, "webdav_op_proppatch failed");
1365 UCX_TEST_ASSERT(backend1_proppatch_commit, "backend1 no commit");
1366 UCX_TEST_ASSERT(backend2_proppatch_commit, "backend2 no commit");
1367 UCX_TEST_ASSERT(backend1_proppatch_do_count == 1, "backend1 wrong count (1)");
1368 UCX_TEST_ASSERT(backend2_proppatch_do_count == 1, "backend1 wrong count (1)");
1369 UCX_TEST_ASSERT(backend1_proppatch_finish_count == 1, "backend1 wrong finish count (1)");
1370 UCX_TEST_ASSERT(backend2_proppatch_finish_count == 1, "backend1 wrong finish count (1)");
1371
1372 // TEST_PROPPATCH3 should fail (commit == FALSE)
1373 reset_backends();
1374 op = test_proppatch_op1(&sn, &rq, TEST_PROPPATCH3);
1375 UCX_TEST_ASSERT(op, "failed to create proppatch operation 2");
1376
1377 ret = webdav_op_proppatch(op, "/", "/");
1378 UCX_TEST_ASSERT(ret == 0, "webdav_op_proppatch failed (2)");
1379 UCX_TEST_ASSERT(!backend1_proppatch_commit, "backend1 commit");
1380 UCX_TEST_ASSERT(!backend2_proppatch_commit, "backend2 commit");
1381
1382 // TEST_PROPPATCH4 should abort
1383 reset_backends();
1384 op = test_proppatch_op1(&sn, &rq, TEST_PROPPATCH4);
1385 UCX_TEST_ASSERT(op, "failed to create proppatch operation 3");
1386
1387 ret = webdav_op_proppatch(op, "/", "/");
1388 UCX_TEST_ASSERT(ret != 0, "webdav_op_proppatch should fail");
1389 UCX_TEST_ASSERT(backend1_proppatch_do_count == 1, "backend1 wrong count (2)");
1390 UCX_TEST_ASSERT(backend2_proppatch_do_count == 1, "backend1 wrong count (2)");
1391 UCX_TEST_ASSERT(backend1_proppatch_finish_count == 1, "backend1 wrong finish count (2)");
1392 UCX_TEST_ASSERT(backend2_proppatch_finish_count == 0, "backend1 wrong finish count (2)");
1393
1394 UCX_TEST_END;
1395 testutil_destroy_session(sn);
1396 }

mercurial