add tests for propfind allprop webdav

Tue, 26 Apr 2022 15:19:12 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Tue, 26 Apr 2022 15:19:12 +0200
branch
webdav
changeset 316
4090fc1b1c52
parent 315
b608b7aa43a6
child 317
09676b559091

add tests for propfind allprop

src/server/plugins/postgresql/pgtest.c file | annotate | diff | comparison | revisions
src/server/plugins/postgresql/pgtest.h file | annotate | diff | comparison | revisions
--- a/src/server/plugins/postgresql/pgtest.c	Tue Apr 26 14:33:58 2022 +0200
+++ b/src/server/plugins/postgresql/pgtest.c	Tue Apr 26 15:19:12 2022 +0200
@@ -93,6 +93,7 @@
         ucx_test_register(suite, test_pg_webdav_create_from_resdata);
         ucx_test_register(suite, test_pg_prepare_tests);
         ucx_test_register(suite, test_pg_webdav_propfind);
+        ucx_test_register(suite, test_pg_webdav_propfind_allprop);
         
         PGresult *result = PQexec(test_connection, "BEGIN");
         PQclear(result);
@@ -156,7 +157,7 @@
                         if(value && value->type == XML_TEXT_NODE) {
                             property->value = sstrdup_a(a, scstr((const char*)value->content)).ptr;
                         }
-                        sstr_t pname = sstrcat(3, sstr(property->prefix), S(":"), sstr(property->name));
+                        sstr_t pname = sstrcat(2, sstr(property->namespace), sstr(property->name));
                         ucx_map_sstr_put(properties, pname, property);
                         free(pname.ptr);
                     }
@@ -566,9 +567,11 @@
     // test data:
     //
     // /propfind/
-    // /propfind/res1     (2 properties)
-    // /propfind/res2     (1 property)
+    // /propfind/res1     (2 properties: test, prop2)
+    // /propfind/res2     (1 property: test)
     // /propfind/res3
+    // /propfind/sub
+    // /propfind/sub/res4
     
     int ret;
     // Test 1
@@ -588,13 +591,13 @@
     
     UCX_TEST_ASSERT(ms->responses->count == 1, "propfind1: wrong response count");
     
-    TestProperty *p = ucx_map_cstr_get(r1->properties, "D:resourcetype");
+    TestProperty *p = ucx_map_cstr_get(r1->properties, "DAV:resourcetype");
     UCX_TEST_ASSERT(p, "propfind1: missing property 'resourcetype'");
     UCX_TEST_ASSERT(p->status == 200, "propfind1: wrong status code for property 'resourcetype'");
     
-    p = ucx_map_cstr_get(r1->properties, "D:getlastmodified");
+    p = ucx_map_cstr_get(r1->properties, "DAV:getlastmodified");
     UCX_TEST_ASSERT(p, "propfind1: missing property 'getlastmodified'");
-    UCX_TEST_ASSERT(p->status == 200, "propfind1: wrong status code for property 'getlastmodified'"); 
+    UCX_TEST_ASSERT(p->status == 200, "propfind1: wrong status code for property 'getlastmodified'");
     
     testutil_destroy_session(sn);
     test_multistatus_destroy(ms);
@@ -623,6 +626,12 @@
     r1 = ucx_map_cstr_get(ms->responses, "/propfind/res2");
     UCX_TEST_ASSERT(r1, "propfind2: missing /propfind/res2 response");
     
+    p = ucx_map_cstr_get(r1->properties, "http://example.com/test");
+    UCX_TEST_ASSERT(p, "propfind2: missing property 'test'");
+    UCX_TEST_ASSERT(p->status == 200, "propfind2: wrong status code for property 'test'");
+    UCX_TEST_ASSERT(!strcmp(p->value, "res2test"), "propfind2: wrong property value");
+    
+    
     testutil_destroy_session(sn);
     test_multistatus_destroy(ms);
     testutil_iostream_destroy(st);
@@ -636,7 +645,7 @@
     
     ret = webdav_propfind(pb, sn, rq);
     
-    printf("\n\n%.*s\n", (int)st->buf->size, st->buf->space);
+    //printf("\n\n%.*s\n", (int)st->buf->size, st->buf->space);
     
     UCX_TEST_ASSERT(ret == REQ_PROCEED, "webdav_propfind (3) failed");
     
@@ -648,6 +657,21 @@
     
     UCX_TEST_ASSERT(ms->responses->count == 6, "propfind3: wrong response count");
     
+    
+    r1 = ucx_map_cstr_get(ms->responses, "/propfind/res1");
+    UCX_TEST_ASSERT(r1, "propfind3: missing /propfind/sub/res1 response");
+    
+    p = ucx_map_cstr_get(r1->properties, "http://example.com/test");
+    UCX_TEST_ASSERT(p, "propfind3: missing property 'test'");
+    UCX_TEST_ASSERT(p->status == 200, "propfind3: wrong status code for property 'test'");
+    UCX_TEST_ASSERT(!strcmp(p->value, "testvalue"), "propfind3: wrong property value");
+    
+    p = ucx_map_cstr_get(r1->properties, "http://example.com/prop2");
+    UCX_TEST_ASSERT(p, "propfind3: missing property 'prop2'");
+    UCX_TEST_ASSERT(p->status == 200, "propfind3: wrong status code for property 'prop2'");
+    UCX_TEST_ASSERT(!strcmp(p->value, "value2"), "propfind3: wrong property value");
+    
+    
     r1 = ucx_map_cstr_get(ms->responses, "/propfind/sub/res4");
     UCX_TEST_ASSERT(r1, "propfind3: missing /propfind/sub/res4 response");
     
@@ -657,3 +681,123 @@
     
     UCX_TEST_END;
 }
+
+
+UCX_TEST(test_pg_webdav_propfind_allprop) {
+    Session *sn;
+    Request *rq; 
+    TestIOStream *st;
+    pblock *pb;
+    
+    UCX_TEST_BEGIN;
+    
+    // test data:
+    //
+    // /propfind/
+    // /propfind/res1     (2 properties: test, prop2)
+    // /propfind/res2     (1 property: test)
+    // /propfind/res3
+    // /propfind/sub
+    // /propfind/sub/res4
+    
+    int ret;
+    TestResponse *r1;
+    TestProperty *p;
+    // Test 1
+    init_test_webdav_method(&sn, &rq, &st, &pb, "PROPFIND", "/propfind/", PG_TEST_ALLPROP);
+    rq->davCollection = create_test_pgdav(sn, rq);
+    pblock_nvinsert("depth", "0", rq->headers);
+    
+    ret = webdav_propfind(pb, sn, rq);
+    
+    UCX_TEST_ASSERT(ret == REQ_PROCEED, "webdav_propfind (1) failed");
+    
+    TestMultistatus *ms = test_parse_multistatus(st->buf->space, st->buf->size);
+    UCX_TEST_ASSERT(ms, "propfind1: response is not valid xml");
+    
+    r1 = ucx_map_cstr_get(ms->responses, "/propfind/");
+    UCX_TEST_ASSERT(r1, "propfind1: missing /propfind/ response");
+    UCX_TEST_ASSERT(ms->responses->count == 1, "propfind1: wrong response count");
+    
+    p = ucx_map_cstr_get(r1->properties, "DAV:resourcetype");
+    UCX_TEST_ASSERT(r1, "propfind1: missing resourcetype property");
+    
+    testutil_destroy_session(sn);
+    test_multistatus_destroy(ms);
+    testutil_iostream_destroy(st);
+    
+    // Test 2
+    init_test_webdav_method(&sn, &rq, &st, &pb, "PROPFIND", "/propfind/", PG_TEST_ALLPROP);
+    rq->davCollection = create_test_pgdav(sn, rq);
+    pblock_nvinsert("depth", "1", rq->headers);
+    
+    ret = webdav_propfind(pb, sn, rq);
+    
+    //printf("\n\n%.*s\n", (int)st->buf->size, st->buf->space);
+    
+    UCX_TEST_ASSERT(ret == REQ_PROCEED, "webdav_propfind (2) failed");
+    
+    ms = test_parse_multistatus(st->buf->space, st->buf->size);
+    UCX_TEST_ASSERT(ms, "propfind2: response is not valid xml");
+    
+    r1 = ucx_map_cstr_get(ms->responses, "/propfind/");
+    UCX_TEST_ASSERT(r1, "propfind2: missing /propfind/ response");
+    UCX_TEST_ASSERT(ms->responses->count == 5, "propfind2: wrong response count");
+    
+    r1 = ucx_map_cstr_get(ms->responses, "/propfind/res1");
+    UCX_TEST_ASSERT(r1, "propfind2: missing /propfind/res1 response");
+    
+    p = ucx_map_cstr_get(r1->properties, "DAV:resourcetype");
+    UCX_TEST_ASSERT(r1, "propfind2: missing resourcetype property");
+    p = ucx_map_cstr_get(r1->properties, "http://example.com/test");
+    UCX_TEST_ASSERT(r1, "propfind2: missing test property");
+    p = ucx_map_cstr_get(r1->properties, "http://example.com/prop2");
+    UCX_TEST_ASSERT(r1, "propfind2: missing prop2 property");
+    
+    UCX_TEST_ASSERT(ucx_map_cstr_get(ms->responses, "/propfind/res2"), "propfind2: missing /propfind/res2 response");
+    UCX_TEST_ASSERT(ucx_map_cstr_get(ms->responses, "/propfind/res3"), "propfind2: missing /propfind/res3 response");
+    UCX_TEST_ASSERT(ucx_map_cstr_get(ms->responses, "/propfind/sub/"), "propfind2: missing /propfind/sub response");
+    
+    testutil_destroy_session(sn);
+    test_multistatus_destroy(ms);
+    testutil_iostream_destroy(st);
+    
+    // Test 3
+    init_test_webdav_method(&sn, &rq, &st, &pb, "PROPFIND", "/propfind/", PG_TEST_ALLPROP);
+    rq->davCollection = create_test_pgdav(sn, rq);
+    pblock_nvinsert("depth", "infinity", rq->headers);
+    
+    ret = webdav_propfind(pb, sn, rq);
+    
+    UCX_TEST_ASSERT(ret == REQ_PROCEED, "webdav_propfind (2) failed");
+    
+    ms = test_parse_multistatus(st->buf->space, st->buf->size);
+    UCX_TEST_ASSERT(ms, "propfind3: response is not valid xml");
+    
+    r1 = ucx_map_cstr_get(ms->responses, "/propfind/");
+    UCX_TEST_ASSERT(r1, "propfind3: missing /propfind/ response");
+    UCX_TEST_ASSERT(ms->responses->count == 6, "propfind3: wrong response count");
+    
+    r1 = ucx_map_cstr_get(ms->responses, "/propfind/res1");
+    UCX_TEST_ASSERT(r1, "propfind3: missing /propfind/res1 response");
+    
+    p = ucx_map_cstr_get(r1->properties, "DAV:resourcetype");
+    UCX_TEST_ASSERT(r1, "propfind3: missing resourcetype property");
+    p = ucx_map_cstr_get(r1->properties, "http://example.com/test");
+    UCX_TEST_ASSERT(r1, "propfind3: missing test property");
+    p = ucx_map_cstr_get(r1->properties, "http://example.com/prop2");
+    UCX_TEST_ASSERT(r1, "propfind3: missing prop2 property");
+    
+    UCX_TEST_ASSERT(ucx_map_cstr_get(ms->responses, "/propfind/res2"), "propfind3: missing /propfind/res2 response");
+    UCX_TEST_ASSERT(ucx_map_cstr_get(ms->responses, "/propfind/res3"), "propfind3: missing /propfind/res3 response");
+    UCX_TEST_ASSERT(ucx_map_cstr_get(ms->responses, "/propfind/sub/"), "propfind3: missing /propfind/sub response");
+    UCX_TEST_ASSERT(ucx_map_cstr_get(ms->responses, "/propfind/sub/res4"), "propfind3: missing /propfind/sub/res4 response");
+    
+    testutil_destroy_session(sn);
+    test_multistatus_destroy(ms);
+    testutil_iostream_destroy(st);
+    
+    
+    UCX_TEST_END;
+}
+
--- a/src/server/plugins/postgresql/pgtest.h	Tue Apr 26 14:33:58 2022 +0200
+++ b/src/server/plugins/postgresql/pgtest.h	Tue Apr 26 15:19:12 2022 +0200
@@ -58,6 +58,7 @@
 UCX_TEST(test_pg_webdav_create_from_resdata);
 UCX_TEST(test_pg_prepare_tests);
 UCX_TEST(test_pg_webdav_propfind);
+UCX_TEST(test_pg_webdav_propfind_allprop);
 
 
 /* --------------------------- PROPFIND --------------------------- */
@@ -90,6 +91,11 @@
             </D:prop> \
         </D:propfind>"
 
+#define PG_TEST_ALLPROP "<?xml version=\"1.0\" encoding=\"utf-8\" ?> \
+        <D:propfind xmlns:D=\"DAV:\" xmlns:X=\"http://example.com/\" > \
+            <D:allprop/> \
+        </D:propfind>"
+
 
 #ifdef __cplusplus
 }

mercurial