Wed, 28 Jan 2026 19:58:08 +0100
add additional test suite for webdav tests with enabled encryption
/* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * * Copyright 2026 Olaf Wintermann. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ #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) { 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); } }