add webdav_op_propfind_begin test that checks backend chaining webdav

Tue, 31 Dec 2019 11:57:02 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Tue, 31 Dec 2019 11:57:02 +0100
branch
webdav
changeset 218
2ba512b284b9
parent 217
8ed14d76db42
child 219
dd6c155c082a

add webdav_op_propfind_begin test that checks backend chaining

src/server/test/main.c file | annotate | diff | comparison | revisions
src/server/test/webdav.c file | annotate | diff | comparison | revisions
src/server/test/webdav.h file | annotate | diff | comparison | revisions
src/server/webdav/operation.c file | annotate | diff | comparison | revisions
--- a/src/server/test/main.c	Tue Dec 31 10:01:32 2019 +0100
+++ b/src/server/test/main.c	Tue Dec 31 11:57:02 2019 +0100
@@ -70,6 +70,7 @@
     ucx_test_register(suite, test_webdav_plist_iterator_remove_current);
     ucx_test_register(suite, test_msresponse_addproperty);
     ucx_test_register(suite, test_webdav_propfind_init);
+    ucx_test_register(suite, test_webdav_op_propfind_begin);
     
     // run tests
     ucx_test_run(suite, stdout);
--- a/src/server/test/webdav.c	Tue Dec 31 10:01:32 2019 +0100
+++ b/src/server/test/webdav.c	Tue Dec 31 11:57:02 2019 +0100
@@ -35,17 +35,23 @@
 #include "../webdav/requestparser.h"
 #include "../webdav/webdav.h"
 #include "../webdav/multistatus.h"
+#include "../webdav/operation.h"
 
 #include "webdav.h"
 
 /* ----------------------------- Test Backends --------------------------*/
 
+static int backend2_init_called = 0;
+static int backend2_propfind_do_called = 0;
+static int backend2_propfind_finish_called = 0;
+
 // backend2
 static int backend2_propfind_init(
         WebdavPropfindRequest *propfind,
         const char *path,
         WebdavPList **outPList)
 {
+    backend2_init_called = 1;
     return 0;
 }
 
@@ -56,10 +62,12 @@
             WebdavResource *resource,
             struct stat *s)
 {
+    backend2_propfind_do_called = 1;
     return 0;
 }
 
 static int backend2_propfind_finish(WebdavPropfindRequest *propfind) {
+    backend2_propfind_finish_called = 1;
     return 0;
 }
 
@@ -72,11 +80,19 @@
 };
 
 // backend1
+
+static int backend1_init_called = 0;
+static int backend1_propfind_do_called = 0;
+static int backend1_propfind_finish_called = 0;
+
+
 static int backend1_propfind_init(
         WebdavPropfindRequest *propfind,
         const char *path,
         WebdavPList **outPList)
 {
+    backend1_init_called = 1;
+    
     WebdavPList *plist = *outPList;
     WebdavProperty *p = plist->property;
     if(!strcmp(p->name, "displayname")) {
@@ -96,10 +112,12 @@
             WebdavResource *resource,
             struct stat *s)
 {
+    backend1_propfind_do_called = 1;
     return 0;
 }
 
 static int backend1_propfind_finish(WebdavPropfindRequest *propfind) {
+    backend1_propfind_finish_called = 1;
     return 0;
 }
 
@@ -111,6 +129,15 @@
     &backend2
 };
 
+static void reset_backends(void) {
+    backend1_init_called = 0;
+    backend1_propfind_do_called = 0;
+    backend1_propfind_finish_called = 0;
+    backend2_init_called = 0;
+    backend2_propfind_do_called = 0;
+    backend2_propfind_finish_called = 0;
+}
+
 /* ----------------------------------------------------------------------*/
 
 
@@ -146,6 +173,37 @@
     return 0;
 }
 
+static WebdavOperation* test_propfind_op(
+        Session **out_sn,
+        Request **out_rq,
+        const char *xml)
+{
+    WebdavPropfindRequest *propfind;
+    if(test_init(out_sn, out_rq, &propfind, xml)) {
+        return NULL;
+    }
+    
+    Multistatus *ms = multistatus_response(*out_sn, *out_rq);
+    if(!ms) {
+        return NULL;
+    }
+    // WebdavResponse is the public interface used by Backends
+    // for adding resources to the response
+    WebdavResponse *response = (WebdavResponse*)ms;
+    
+    UcxList *requests = NULL;
+    
+    // Initialize all Webdav Backends
+    if(webdav_propfind_init(&backend1, propfind, "/", &requests)) {
+        return NULL;
+    }
+    
+    return webdav_operation_create(
+            (*out_sn)->pool,
+            &backend1,
+            requests,
+            response);
+}
 
 UCX_TEST(test_propfind_parse) {
     Session *sn = testutil_session();
@@ -681,6 +739,8 @@
 }
 
 UCX_TEST(test_webdav_propfind_init) {
+    reset_backends();
+    
     Session *sn;
     Request *rq;
     WebdavPropfindRequest *propfind;
@@ -705,7 +765,29 @@
     UCX_TEST_ASSERT(p1->properties != p2->properties, "plists equal");
     UCX_TEST_ASSERT(p1->propcount == p2->propcount + 1, "first property not removed");
     
+    UCX_TEST_ASSERT(backend1_init_called == 1, "backend1 init not called");
+    UCX_TEST_ASSERT(backend2_init_called == 1, "backend2 init not called");
+    
     UCX_TEST_END;
     
     pool_destroy(sn->pool);
 }
+
+UCX_TEST(test_webdav_op_propfind_begin) {
+    reset_backends();
+    
+    Session *sn;
+    Request *rq;
+    
+    UCX_TEST_BEGIN;
+    WebdavOperation *op = test_propfind_op(&sn, &rq, TEST_PROPFIND1);
+    UCX_TEST_ASSERT(op, "WebdavOperation not created");
+    
+    int err = webdav_op_propfind_begin(op, "/", NULL, NULL);
+    UCX_TEST_ASSERT(err == 0, "err not 0");
+    UCX_TEST_ASSERT(backend1_propfind_do_called == 1, "backend1 propfind_do not called");
+    UCX_TEST_ASSERT(backend2_propfind_do_called == 1, "backend2 propfind_do not called");
+    
+    
+    UCX_TEST_END;
+}
--- a/src/server/test/webdav.h	Tue Dec 31 10:01:32 2019 +0100
+++ b/src/server/test/webdav.h	Tue Dec 31 11:57:02 2019 +0100
@@ -45,11 +45,12 @@
 UCX_TEST(test_rqbody2buffer);
 
 UCX_TEST(test_webdav_plist_iterator);
+UCX_TEST(test_webdav_plist_iterator_remove_current);
 
 UCX_TEST(test_msresponse_addproperty);
 
 UCX_TEST(test_webdav_propfind_init);
-UCX_TEST(test_webdav_plist_iterator_remove_current);
+UCX_TEST(test_webdav_op_propfind_begin);
 
 /* --------------------------- PROPFIND --------------------------- */
 
--- a/src/server/webdav/operation.c	Tue Dec 31 10:01:32 2019 +0100
+++ b/src/server/webdav/operation.c	Tue Dec 31 11:57:02 2019 +0100
@@ -74,11 +74,19 @@
     WebdavPropfindRequest *propfind = op->requests->data;
     
     // execute propfind_do of the first backend for the first resource
+    int ret = REQ_PROCEED;
     if(op->dav->propfind_do(propfind, op->response, NULL, resource, s)) {
-        return REQ_ABORTED;
+        ret = REQ_ABORTED;
+    } else {
+        // propfind_do successful, close resource if needed
+        // closing the resource will execute propfind_do of all remaining
+        // backends
+        if(!resource->isclosed) {
+            ret = resource->close(resource);
+        }
     }
     
-    return REQ_PROCEED;
+    return ret;
 }
 
 int webdav_op_propfind_children(

mercurial