test/webdav.c

branch
dav-2
changeset 905
bc4238f9abdb
parent 902
06fa328989ee
equal deleted inserted replaced
904:7109de6bfad5 905:bc4238f9abdb
26 * POSSIBILITY OF SUCH DAMAGE. 26 * POSSIBILITY OF SUCH DAMAGE.
27 */ 27 */
28 28
29 #include "webdav.h" 29 #include "webdav.h"
30 30
31 #include <libidav/utils.h>
32
31 static DavContext *test_webdav_context; 33 static DavContext *test_webdav_context;
34 static int encryption = 0;
35 static DavKey default_encryption_key;
36 static char default_encryption_key256[] = {
37 0x64, 0x4e, 0x8e, 0x45, 0x38, 0xea, 0x05, 0xae, 0x59, 0xfb, 0x4a, 0x6a, 0xe5, 0x57, 0xed, 0x73,
38 0x2d, 0x69, 0x4c, 0xab, 0xce, 0xaa, 0xb3, 0x43, 0x21, 0x11, 0x24, 0xe6, 0x67, 0xfa, 0x87, 0x3c
39 };
32 40
33 void test_webdav_init(void) { 41 void test_webdav_init(void) {
34 test_webdav_context = dav_context_new(); 42 test_webdav_context = dav_context_new();
43 default_encryption_key.data = default_encryption_key256;
44 default_encryption_key.length = 32;
45 default_encryption_key.name = "libidav_testkey";
46 default_encryption_key.type = DAV_KEY_AES256;
47 dav_context_add_key(test_webdav_context, &default_encryption_key);
48 }
49
50 void test_session_enable_encryption(int enable) {
51 encryption = 1;
52 }
53
54 int test_session_is_encrypted(void) {
55 return encryption;
35 } 56 }
36 57
37 DavSession* get_test_webdav_session(void) { 58 DavSession* get_test_webdav_session(void) {
38 DavSession *sn = dav_session_new_auth(test_webdav_context, "http://localhost:8182/", "dav", "testdavutils"); 59 char *base_url = encryption ? "http://localhost:8182/enc" : "http://localhost:8182/";
60 DavSession *sn = dav_session_new_auth(test_webdav_context, base_url, "dav", "testdavutils");
61 if(encryption) {
62 sn->flags = DAV_SESSION_FULL_ENCRYPTION;
63 sn->key = &default_encryption_key;
64 }
39 return sn; 65 return sn;
40 } 66 }
67
68 CX_TEST(init_webdav_encryption_tests) {
69 CX_TEST_DO {
70 encryption = 1;
71 DavSession *sn = get_test_webdav_session();
72
73 DavResource *res = dav_resource_new(sn, "/hello.txt");
74 cxstring content = cx_str("Hello World!\n");
75 dav_set_content_data(res, content.ptr, content.length);
76 int ret = dav_store(res);
77 CX_TEST_ASSERT(!ret);
78
79 ret = dav_load(res);
80 CX_TEST_ASSERT(!ret);
81 const char *name = util_resource_name(res->href);
82 CX_TEST_ASSERT(strcmp(name, "hello.txt"));
83 char *crypto_name = dav_get_string_property_ns(res, DAV_NS, "crypto-name");
84 char *crypto_key = dav_get_string_property_ns(res, DAV_NS, "crypto-key");
85 CX_TEST_ASSERT(crypto_name != NULL && strlen(crypto_name) > 0);
86 CX_TEST_ASSERT(!cx_strcmp(crypto_key, "libidav_testkey"));
87
88 dav_session_destroy(sn);
89 }
90 }

mercurial