diff options
author | Vincent Douillet <vincent@vdouillet.fr> | 2024-09-11 11:20:31 +0200 |
---|---|---|
committer | Vincent Douillet <vincent@vdouillet.fr> | 2024-09-11 11:20:31 +0200 |
commit | 19e47daa9c1fb55f2cb9e639d5a6ef16b5bc4e88 (patch) | |
tree | 2b98ac0700a11cb142625d8355019c44b49c1850 /test.c | |
parent | 4e921ffa31fdca2425d326efda1c6d9ad190359a (diff) |
url: fix encoding for use in http context
Diffstat (limited to 'test.c')
-rw-r--r-- | test.c | 34 |
1 files changed, 34 insertions, 0 deletions
@@ -4,12 +4,15 @@ #include "browse.h" #include "http.h" #include "upload.h" +#include "url.h" /* minunit, see https://jera.com/techinfo/jtns/jtn002 */ #define mu_assert(message, test) do { if (!(test)) return message; } while (0) #define mu_run_test(test) do { char* message = test(); tests_run++; \ if(message) return message; } while (0) +#define BUF_SZ 1000 + int tests_run; static char * @@ -88,10 +91,41 @@ test_upload_post() } static char * +test_url_build() +{ + char dst[BUF_SZ], *expected; + size_t dst_len; + + expected = "/vault/browse"; + dst_len = url_build(dst, BUF_SZ, "/vault/browse", "", NULL); + mu_assert("test_url_build failed", dst_len > 0 && dst_len < BUF_SZ); + mu_assert("test_url_build failed", strncmp(expected, dst, BUF_SZ) == 0); + + expected = "/vault/browse/hello/world"; + dst_len = url_build(dst, BUF_SZ, "/vault/browse", "hello", "world", + NULL); + mu_assert("test_url_build failed", dst_len > 0 && dst_len < BUF_SZ); + mu_assert("test_url_build failed", strncmp(expected, dst, BUF_SZ) == 0); + + expected = "/vault/browse"; + dst_len = url_build(dst, BUF_SZ, "/vault/", "browse/", NULL); + mu_assert("test_url_build failed", dst_len > 0 && dst_len < BUF_SZ); + mu_assert("test_url_build failed", strncmp(expected, dst, BUF_SZ) == 0); + + dst_len = url_build(dst, BUF_SZ, "", "", NULL); + mu_assert("test_url_build failed", dst_len == 0); + + dst_len = url_build(dst, BUF_SZ, NULL); + mu_assert("test_url_build failed", dst_len == 0); + return 0; +} + +static char * all_tests() { mu_run_test(test_browse_invalid_traversal); mu_run_test(test_browse_path_too_long); + mu_run_test(test_url_build); mu_run_test(test_upload_post); return 0; } |