diff -r cd74667f6c85 -r 4adad7faf452 src/server/test/webdav.c --- a/src/server/test/webdav.c Sat Jan 25 15:34:30 2020 +0100 +++ b/src/server/test/webdav.c Sat Jan 25 21:37:38 2020 +0100 @@ -47,6 +47,9 @@ static int backend2_init_called = 0; static int backend2_propfind_do_count = 0; static int backend2_propfind_finish_called = 0; +static int backend2_proppatch_commit = 0; +static int backend2_proppatch_do_count = 0; +static int backend2_proppatch_finish_count = 0; // backend2 static int backend2_propfind_init( @@ -74,10 +77,52 @@ return 0; } +static int backend2_proppatch_do( + WebdavProppatchRequest *request, + WebdavResource *response, + VFSFile *file, + WebdavPList **out_set, + WebdavPList **out_remove) +{ + backend2_proppatch_do_count++; + + if(*out_remove) { + return 1; // backend1 should remove all remove-props + } + + WebdavPListIterator i = webdav_plist_iterator(out_set); + WebdavPList *cur; + while(webdav_plist_iterator_next(&i, &cur)) { + if(!strcmp(cur->property->name, "a")) { + // property 'a' should already be removed by backend1 + return 1; + } else if(!strcmp(cur->property->name, "abort")) { + return 1; // test abort + } + response->addproperty(response, cur->property, 200); + webdav_plist_iterator_remove_current(&i); + } + + return 0; +} + +static int backend2_proppatch_finish( + WebdavProppatchRequest *request, + WebdavResource *response, + VFSFile *file, + WSBool commit) +{ + backend2_proppatch_finish_count++; + backend2_proppatch_commit = commit; + return 0; +} + static WebdavBackend backend2 = { backend2_propfind_init, backend2_propfind_do, backend2_propfind_finish, + backend2_proppatch_do, + backend2_proppatch_finish, 0, NULL }; @@ -87,6 +132,9 @@ static int backend1_init_called = 0; static int backend1_propfind_do_count = 0; static int backend1_propfind_finish_called = 0; +static int backend1_proppatch_commit = 0; +static int backend1_proppatch_do_count = 0; +static int backend1_proppatch_finish_count = 0; static int backend1_propfind_init( @@ -124,10 +172,55 @@ return 0; } +static int backend1_proppatch_do( + WebdavProppatchRequest *request, + WebdavResource *response, + VFSFile *file, + WebdavPList **out_set, + WebdavPList **out_remove) +{ + backend1_proppatch_do_count++; + + // remove everything from out_remove + WebdavPListIterator i = webdav_plist_iterator(out_remove); + WebdavPList *cur; + while(webdav_plist_iterator_next(&i, &cur)) { + response->addproperty(response, cur->property, 200); + webdav_plist_iterator_remove_current(&i); + } + + // remove property 'a' and fail at property 'fail' + i = webdav_plist_iterator(out_set); + while(webdav_plist_iterator_next(&i, &cur)) { + if(!strcmp(cur->property->name, "fail")) { + response->addproperty(response, cur->property, 403); + webdav_plist_iterator_remove_current(&i); + } else if(!strcmp(cur->property->name, "a")) { + response->addproperty(response, cur->property, 200); + webdav_plist_iterator_remove_current(&i); + } + } + + return 0; +} + +static int backend1_proppatch_finish( + WebdavProppatchRequest *request, + WebdavResource *response, + VFSFile *file, + WSBool commit) +{ + backend1_proppatch_finish_count++; + backend1_proppatch_commit = commit; + return 0; +} + WebdavBackend backend1 = { backend1_propfind_init, backend1_propfind_do, backend1_propfind_finish, + backend1_proppatch_do, + backend1_proppatch_finish, 0, &backend2 }; @@ -136,9 +229,15 @@ backend1_init_called = 0; backend1_propfind_do_count = 0; backend1_propfind_finish_called = 0; + backend1_proppatch_commit = 0; + backend1_proppatch_do_count = 0; + backend1_proppatch_finish_count = 0; backend2_init_called = 0; backend2_propfind_do_count = 0; backend2_propfind_finish_called = 0; + backend2_proppatch_commit = 0; + backend2_proppatch_do_count = 0; + backend2_proppatch_finish_count = 0; } /* ----------------------------------------------------------------------*/ @@ -1235,3 +1334,63 @@ UCX_TEST_END; testutil_destroy_session(sn); } + +UCX_TEST(test_webdav_op_proppatch) { + Session *sn; + Request *rq; + WebdavOperation *op; + + Multistatus *ms; + WebdavResource *res; + + WebdavProperty p[16]; + const char *names[] = {"a1", "a2", "a3", "a4", "a5", "a6", "a7", "a8", "a9"}; + for(int i=0;i<8;i++) { + p[i].namespace = webdav_dav_namespace(); + p[i].name = names[i]; + p[i].lang = NULL; + p[i].value.node = NULL; + p[1].vtype = 0; + } + + UCX_TEST_BEGIN; + + // TEST_PROPPATCH2 should succeed + reset_backends(); + op = test_proppatch_op1(&sn, &rq, TEST_PROPPATCH2); + UCX_TEST_ASSERT(op, "failed to create proppatch operation"); + + int ret = webdav_op_proppatch(op, "/", "/"); + UCX_TEST_ASSERT(ret == 0, "webdav_op_proppatch failed"); + UCX_TEST_ASSERT(backend1_proppatch_commit, "backend1 no commit"); + UCX_TEST_ASSERT(backend2_proppatch_commit, "backend2 no commit"); + UCX_TEST_ASSERT(backend1_proppatch_do_count == 1, "backend1 wrong count (1)"); + UCX_TEST_ASSERT(backend2_proppatch_do_count == 1, "backend1 wrong count (1)"); + UCX_TEST_ASSERT(backend1_proppatch_finish_count == 1, "backend1 wrong finish count (1)"); + UCX_TEST_ASSERT(backend2_proppatch_finish_count == 1, "backend1 wrong finish count (1)"); + + // TEST_PROPPATCH3 should fail (commit == FALSE) + reset_backends(); + op = test_proppatch_op1(&sn, &rq, TEST_PROPPATCH3); + UCX_TEST_ASSERT(op, "failed to create proppatch operation 2"); + + ret = webdav_op_proppatch(op, "/", "/"); + UCX_TEST_ASSERT(ret == 0, "webdav_op_proppatch failed (2)"); + UCX_TEST_ASSERT(!backend1_proppatch_commit, "backend1 commit"); + UCX_TEST_ASSERT(!backend2_proppatch_commit, "backend2 commit"); + + // TEST_PROPPATCH4 should abort + reset_backends(); + op = test_proppatch_op1(&sn, &rq, TEST_PROPPATCH4); + UCX_TEST_ASSERT(op, "failed to create proppatch operation 3"); + + ret = webdav_op_proppatch(op, "/", "/"); + UCX_TEST_ASSERT(ret != 0, "webdav_op_proppatch should fail"); + UCX_TEST_ASSERT(backend1_proppatch_do_count == 1, "backend1 wrong count (2)"); + UCX_TEST_ASSERT(backend2_proppatch_do_count == 1, "backend1 wrong count (2)"); + UCX_TEST_ASSERT(backend1_proppatch_finish_count == 1, "backend1 wrong finish count (2)"); + UCX_TEST_ASSERT(backend2_proppatch_finish_count == 0, "backend1 wrong finish count (2)"); + + UCX_TEST_END; + testutil_destroy_session(sn); +}