diff -r 4adad7faf452 -r c337a7ac82a8 src/server/test/webdav.c --- a/src/server/test/webdav.c Sat Jan 25 21:37:38 2020 +0100 +++ b/src/server/test/webdav.c Sun Jan 26 10:13:11 2020 +0100 @@ -1076,11 +1076,12 @@ testutil_destroy_session(sn); } -static void init_test_webdav_propfind( +static void init_test_webdav_method( Session **out_sn, Request **out_rq, TestIOStream **out_st, pblock **out_pb, + const char *method, const char *request_body) { Session *sn; @@ -1089,7 +1090,7 @@ pblock *pb; sn = testutil_session(); - rq = testutil_request(sn->pool, "PROPFIND", "/"); + rq = testutil_request(sn->pool, method, "/"); pblock_nvinsert("path", "/", rq->vars); pblock_nvinsert("uri", "/", rq->reqpb); @@ -1117,7 +1118,7 @@ int ret; // Test 1 - init_test_webdav_propfind(&sn, &rq, &st, &pb, TEST_PROPFIND1); + init_test_webdav_method(&sn, &rq, &st, &pb, "PROPFIND", TEST_PROPFIND1); ret = webdav_propfind(pb, sn, rq); @@ -1134,7 +1135,7 @@ testutil_iostream_destroy(st); // Test2 - init_test_webdav_propfind(&sn, &rq, &st, &pb, TEST_PROPFIND2); + init_test_webdav_method(&sn, &rq, &st, &pb, "PROPFIND", TEST_PROPFIND2); ret = webdav_propfind(pb, sn, rq); @@ -1394,3 +1395,76 @@ UCX_TEST_END; testutil_destroy_session(sn); } + +#define xstreq(a, b) (!strcmp((const char*)a, (const char*)b)) + +UCX_TEST(test_webdav_proppatch) { + Session *sn; + Request *rq; + TestIOStream *st; + pblock *pb; + + UCX_TEST_BEGIN; + + int ret; + // Test 1 + init_test_webdav_method(&sn, &rq, &st, &pb, "PROPPATCH", TEST_PROPPATCH2); + rq->davCollection = &backend1; + ret = webdav_proppatch(pb, sn, rq); + + UCX_TEST_ASSERT(ret == REQ_PROCEED, "webdav_proppatch (1) failed"); + + xmlDoc *doc = xmlReadMemory( + st->buf->space, st->buf->size, NULL, NULL, 0); + UCX_TEST_ASSERT(doc, "proppatch1: response is not valid xml"); + + //printf("\n\n%.*s\n", (int)st->buf->size, st->buf->space); + + xmlNode *root = xmlDocGetRootElement(doc); + UCX_TEST_ASSERT(root, "proppatch1: no root"); + + xmlNode *nodeC = NULL; + xmlNode *node = root->children; + int depth = 1; + while(node) { + const xmlChar *name = node->name; + int nextNode = 1; + if(node->type != XML_ELEMENT_NODE) { + // nothing + } else if(depth == 1) { + if(xstreq(name, "response")) { + nextNode = 0; + } + } else if(depth == 2) { + if(xstreq(name, "propstat")) { + nextNode = 0; + } + } else if(depth == 3) { + if(xstreq(name, "prop")) { + nextNode = 0; + } + } else if(depth == 4) { + if(xstreq(name, "c")) { + nodeC = node; + break; + } + } + + if(nextNode) { + node = node->next; + } else { + node = node->children; + depth++; + } + } + + UCX_TEST_ASSERT(nodeC, "prop c not in response"); + UCX_TEST_ASSERT(!nodeC->children, "properties must not have a value"); + + testutil_destroy_session(sn); + xmlFreeDoc(doc); + testutil_iostream_destroy(st); + + + UCX_TEST_END; +}