test/webdav.c

branch
dav-2
changeset 905
bc4238f9abdb
parent 902
06fa328989ee
--- 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);
+    }
+}

mercurial