add additional test suite for webdav tests with enabled encryption dav-2 tip

Wed, 28 Jan 2026 19:58:08 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Wed, 28 Jan 2026 19:58:08 +0100
branch
dav-2
changeset 905
bc4238f9abdb
parent 904
7109de6bfad5

add additional test suite for webdav tests with enabled encryption

test/main.c file | annotate | diff | comparison | revisions
test/webdav.c file | annotate | diff | comparison | revisions
test/webdav.h file | annotate | diff | comparison | revisions
test/webdav_resource.c file | annotate | diff | comparison | revisions
test/wsgidav/wsgidav.yaml file | annotate | diff | comparison | revisions
--- a/test/main.c	Tue Jan 27 20:25:09 2026 +0100
+++ b/test/main.c	Wed Jan 28 19:58:08 2026 +0100
@@ -92,12 +92,25 @@
         cx_test_register(suite_webdav, test_dav_store_stream_webdav);
     }
     
+    CxTestSuite* suite_webdav_enc = cx_test_suite_new("libidav webdav encryption");
+    if(dav_client_tests) {
+        cx_test_register(suite_webdav_enc, init_webdav_encryption_tests);
+        cx_test_register(suite_webdav_enc, test_dav_load_webdav);
+        cx_test_register(suite_webdav_enc, test_dav_exists_webdav);
+        cx_test_register(suite_webdav_enc, test_dav_create_webdav);
+        cx_test_register(suite_webdav_enc, test_dav_store_content_webdav);
+        cx_test_register(suite_webdav_enc, test_dav_store_stream_webdav);
+    }
+    
     cx_test_run_stdout(suite);
     cx_test_suite_free(suite);
     
     cx_test_run_stdout(suite_webdav);
     cx_test_suite_free(suite_webdav);
     
+    cx_test_run_stdout(suite_webdav_enc);
+    cx_test_suite_free(suite_webdav_enc);
+    
     if(dav_client_tests) {
         wsgidav_stop();
     }
--- a/test/webdav.c	Tue Jan 27 20:25:09 2026 +0100
+++ b/test/webdav.c	Wed Jan 28 19:58:08 2026 +0100
@@ -28,13 +28,63 @@
 
 #include "webdav.h"
 
+#include <libidav/utils.h>
+
 static DavContext *test_webdav_context;
+static int encryption = 0;
+static DavKey default_encryption_key;
+static char default_encryption_key256[] = {
+    0x64, 0x4e, 0x8e, 0x45, 0x38, 0xea, 0x05, 0xae, 0x59, 0xfb, 0x4a, 0x6a, 0xe5, 0x57, 0xed, 0x73,
+    0x2d, 0x69, 0x4c, 0xab, 0xce, 0xaa, 0xb3, 0x43, 0x21, 0x11, 0x24, 0xe6, 0x67, 0xfa, 0x87, 0x3c
+};
 
 void test_webdav_init(void) {
     test_webdav_context = dav_context_new();
+    default_encryption_key.data = default_encryption_key256;
+    default_encryption_key.length = 32;
+    default_encryption_key.name = "libidav_testkey";
+    default_encryption_key.type = DAV_KEY_AES256;
+    dav_context_add_key(test_webdav_context, &default_encryption_key);
+}
+
+void test_session_enable_encryption(int enable) {
+    encryption = 1;
+}
+
+int test_session_is_encrypted(void) {
+    return encryption;
 }
 
 DavSession* get_test_webdav_session(void) {
-    DavSession *sn = dav_session_new_auth(test_webdav_context, "http://localhost:8182/", "dav", "testdavutils");
+    char *base_url = encryption ? "http://localhost:8182/enc" : "http://localhost:8182/";
+    DavSession *sn = dav_session_new_auth(test_webdav_context, base_url, "dav", "testdavutils");
+    if(encryption) {
+        sn->flags = DAV_SESSION_FULL_ENCRYPTION;
+        sn->key = &default_encryption_key;
+    }
     return sn;
 }
+
+CX_TEST(init_webdav_encryption_tests) {
+    CX_TEST_DO {
+        encryption = 1;
+        DavSession *sn = get_test_webdav_session();
+        
+        DavResource *res = dav_resource_new(sn, "/hello.txt");
+        cxstring content = cx_str("Hello World!\n");
+        dav_set_content_data(res, content.ptr, content.length);
+        int ret = dav_store(res);
+        CX_TEST_ASSERT(!ret);
+        
+        ret = dav_load(res);
+        CX_TEST_ASSERT(!ret);
+        const char *name = util_resource_name(res->href);
+        CX_TEST_ASSERT(strcmp(name, "hello.txt"));
+        char *crypto_name = dav_get_string_property_ns(res, DAV_NS, "crypto-name");
+        char *crypto_key = dav_get_string_property_ns(res, DAV_NS, "crypto-key");
+        CX_TEST_ASSERT(crypto_name != NULL && strlen(crypto_name) > 0);
+        CX_TEST_ASSERT(!cx_strcmp(crypto_key, "libidav_testkey"));
+        
+        dav_session_destroy(sn);
+    }
+}
--- a/test/webdav.h	Tue Jan 27 20:25:09 2026 +0100
+++ b/test/webdav.h	Wed Jan 28 19:58:08 2026 +0100
@@ -37,8 +37,12 @@
 #endif
 
 void test_webdav_init(void);
+void test_session_enable_encryption(int enable);
+int test_session_is_encrypted(void);
 DavSession* get_test_webdav_session(void);
 
+CX_TEST(init_webdav_encryption_tests);
+
 
 #ifdef __cplusplus
 }
--- a/test/webdav_resource.c	Tue Jan 27 20:25:09 2026 +0100
+++ b/test/webdav_resource.c	Wed Jan 28 19:58:08 2026 +0100
@@ -101,32 +101,34 @@
         int ret = dav_store(res);
         CX_TEST_ASSERT(!ret);
         CX_TEST_ASSERT(!dav_load(res));
-        CX_TEST_ASSERT(res->contentlength == content.length);
+        if(!test_session_is_encrypted()) {
+            CX_TEST_ASSERT(res->contentlength == content.length);
+        }
         dav_session_destroy(sn);
     }
 }
 
 CX_TEST(test_dav_store_stream_webdav) {
     CX_TEST_DO {
-        CX_TEST_DO {
-            FILE *f = fopen("test_dav_store_stream_webdav.txt", "w+");
-            cxstring line = cx_str("test_dav_store_stream_webdav test content\n");
-            for(int i=0;i<1000;i++) {
-                fwrite(line.ptr, 1, line.length, f);
-            }
-            fseek(f, 0, SEEK_SET);
-            size_t len = 1000 * line.length;
-            
-            DavSession *sn = get_test_webdav_session();
-            DavResource *res = dav_resource_new(sn, "/test_store_file.txt");
-            dav_set_content(res, f, (dav_read_func)fread, (dav_seek_func)fseek);
-            
-            int ret = dav_store(res);
-            CX_TEST_ASSERT(!ret);
-            CX_TEST_ASSERT(!dav_load(res));
+        FILE *f = fopen("test_dav_store_stream_webdav.txt", "w+");
+        cxstring line = cx_str("test_dav_store_stream_webdav test content\n");
+        for(int i=0;i<1000;i++) {
+            fwrite(line.ptr, 1, line.length, f);
+        }
+        fseek(f, 0, SEEK_SET);
+        size_t len = 1000 * line.length;
+
+        DavSession *sn = get_test_webdav_session();
+        DavResource *res = dav_resource_new(sn, "/test_store_file.txt");
+        dav_set_content(res, f, (dav_read_func)fread, (dav_seek_func)fseek);
+
+        int ret = dav_store(res);
+        CX_TEST_ASSERT(!ret);
+        CX_TEST_ASSERT(!dav_load(res));
+        if(!test_session_is_encrypted()) {
             CX_TEST_ASSERT(res->contentlength == len);
-            dav_session_destroy(sn);
-            fclose(f);
         }
+        dav_session_destroy(sn);
+        fclose(f);
     }
 }
--- a/test/wsgidav/wsgidav.yaml	Tue Jan 27 20:25:09 2026 +0100
+++ b/test/wsgidav/wsgidav.yaml	Wed Jan 28 19:58:08 2026 +0100
@@ -248,7 +248,7 @@
 #        kwargs:
 #            storage_path: 'wsgidav-props.shelve'
 
-property_manager: null
+property_manager: true
 
 #: Optional additional live property modification
 #: Note: by default live properties like file size and last-modified time are

mercurial