diff options
author | Vincent Douillet <vincent@vdouillet.fr> | 2024-09-09 13:52:35 +0200 |
---|---|---|
committer | Vincent Douillet <vincent@vdouillet.fr> | 2024-09-10 12:01:05 +0200 |
commit | 4e921ffa31fdca2425d326efda1c6d9ad190359a (patch) | |
tree | 8d0fe130bd26dedb5c0754249734608217bbd6b9 /test.c | |
parent | d7edafe299d44a0bec9d29e2b3a4ca853ffa1a80 (diff) |
upload: handle form submission
Diffstat (limited to 'test.c')
-rw-r--r-- | test.c | 39 |
1 files changed, 38 insertions, 1 deletions
@@ -1,7 +1,9 @@ #include <stdio.h> +#include <string.h> #include "browse.h" #include "http.h" +#include "upload.h" /* minunit, see https://jera.com/techinfo/jtns/jtn002 */ #define mu_assert(message, test) do { if (!(test)) return message; } while (0) @@ -27,7 +29,6 @@ test_browse_invalid_traversal() /* ...should return an error */ mu_assert("error, browse allowed invalid traversal!", ret.code >= KHTTP_400); - return 0; } @@ -47,7 +48,42 @@ test_browse_path_too_long() mu_assert("error, browse allowed invalid traversal!", ret.code >= KHTTP_400); + return 0; +} + +static char * +test_upload_post() +{ + char *file_content; + struct kreq r; + struct http_ret ret; + struct kpair fields[2]; + + file_content = "text file"; + + fields[0] = (struct kpair) { + .key = "file", + .file = "bob.txt", + .val = file_content, + .valsz = strlen(file_content) + }; + fields[1] = (struct kpair) { + .key = "file", + .file = "alice.txt", + .val = file_content, + .valsz = strlen(file_content) + }; + + r = (struct kreq) { + .pname = "/vault", + .path = "", + .method = KMETHOD_POST, + .fieldsz = 2, + .fields = fields + }; + ret = upload(&r); + mu_assert("error, POST upload failed!", ret.code <= KHTTP_400); return 0; } @@ -56,6 +92,7 @@ all_tests() { mu_run_test(test_browse_invalid_traversal); mu_run_test(test_browse_path_too_long); + mu_run_test(test_upload_post); return 0; } |