fix multistatus response and add propfind tests webdav

Sat, 25 Jan 2020 09:00:27 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sat, 25 Jan 2020 09:00:27 +0100
branch
webdav
changeset 238
e820d433f405
parent 237
ee1680ef1ef2
child 239
d5031c30022c

fix multistatus response and add propfind tests

src/server/test/webdav.c file | annotate | diff | comparison | revisions
src/server/webdav/multistatus.c file | annotate | diff | comparison | revisions
--- a/src/server/test/webdav.c	Sun Jan 19 10:03:31 2020 +0100
+++ b/src/server/test/webdav.c	Sat Jan 25 09:00:27 2020 +0100
@@ -977,33 +977,80 @@
     testutil_destroy_session(sn);
 }
 
-UCX_TEST(test_webdav_propfind) {
-    Session *sn = testutil_session();
-    Request *rq = testutil_request(sn->pool, "PROPFIND", "/");
+static void init_test_webdav_propfind(
+        Session **out_sn,
+        Request **out_rq,
+        TestIOStream **out_st,
+        pblock **out_pb,
+        const char *request_body)
+{
+    Session *sn;
+    Request *rq; 
+    TestIOStream *st;
+    pblock *pb;
+    
+    sn = testutil_session();
+    rq = testutil_request(sn->pool, "PROPFIND", "/");
     
     pblock_nvinsert("path", "/", rq->vars);
     pblock_nvinsert("uri", "/", rq->reqpb);
     
-    
-    TestIOStream *st = testutil_iostream(2048, TRUE);
+    st = testutil_iostream(2048, TRUE);
     sn->csd = st;
     
-    testutil_request_body(sn, rq, TEST_PROPFIND1, strlen(TEST_PROPFIND1));
+    testutil_request_body(sn, rq, request_body, strlen(request_body));
+    
+    pb = pblock_create_pool(sn->pool, 4);
+    
+    *out_sn = sn;
+    *out_rq = rq;
+    *out_st = st;
+    *out_pb = pb;
+}
+
+UCX_TEST(test_webdav_propfind) {
+    Session *sn;
+    Request *rq; 
+    TestIOStream *st;
+    pblock *pb;
     
     UCX_TEST_BEGIN;
     
-    pblock *pb = pblock_create_pool(sn->pool, 4);
+    int ret;
+    // Test 1
+    init_test_webdav_propfind(&sn, &rq, &st, &pb, TEST_PROPFIND1);
     
-    int ret = webdav_propfind(pb, sn, rq);
+    ret = webdav_propfind(pb, sn, rq);
     
     UCX_TEST_ASSERT(ret == REQ_PROCEED, "webdav_propfind (1) failed");
     
     xmlDoc *doc = xmlReadMemory(
             st->buf->space, st->buf->size, NULL, NULL, 0);
-    UCX_TEST_ASSERT(doc, "response is not valid xml");
+    UCX_TEST_ASSERT(doc, "propfind1: response is not valid xml");
     
     //printf("\n\n%.*s\n", (int)st->buf->size, st->buf->space);
     
-    UCX_TEST_END;
     testutil_destroy_session(sn);
+    xmlFreeDoc(doc);
+    testutil_iostream_destroy(st);
+    
+    // Test2
+    init_test_webdav_propfind(&sn, &rq, &st, &pb, TEST_PROPFIND2);
+    
+    ret = webdav_propfind(pb, sn, rq);
+    
+    UCX_TEST_ASSERT(ret == REQ_PROCEED, "webdav_propfind (2) failed");
+    
+    xmlDoc *doc2 = xmlReadMemory(
+            st->buf->space, st->buf->size, NULL, NULL, 0);
+    UCX_TEST_ASSERT(doc, "propfind2: response is not valid xml");
+    
+    //printf("\n\n%.*s\n", (int)st->buf->size, st->buf->space);
+    
+    testutil_destroy_session(sn);
+    xmlFreeDoc(doc2);
+    testutil_iostream_destroy(st);
+    
+    UCX_TEST_END;
+    
 }
--- a/src/server/webdav/multistatus.c	Sun Jan 19 10:03:31 2020 +0100
+++ b/src/server/webdav/multistatus.c	Sat Jan 25 09:00:27 2020 +0100
@@ -99,7 +99,7 @@
         Writer *out)
 {
     // write: "<prefix:name"
-    writer_puts(out, S("    <"));
+    writer_putc(out, '<');
     writer_puts(out, sstr((char*)property->namespace->prefix));
     writer_putc(out, ':');
     writer_puts(out, sstr((char*)property->name));
@@ -217,7 +217,7 @@
             if(send_property(ms, errprop->property, NULL, FALSE, out)) {
                 return out->error;
             }
-            writer_puts(out, S("\n    "));
+            writer_putc(out, '\n');
             errprop = errprop->next;
         }
         

mercurial