blob: 390cbc37476ca13b4fa1607f29a4e066d486ec7e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
#include <stdio.h>
#include "browse.h"
#include "http.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)
int tests_run;
static char *
test_browse_invalid_traversal()
{
struct kreq r;
struct http_ret ret;
/* attempt to traverse out of DATA_DIR... */
r = (struct kreq) {
.path = "..",
.suffix = "",
.mime = KMIME_TEXT_HTML
};
ret = browse(&r);
/* ...should return an error */
mu_assert("error, browse allowed invalid traversal!",
ret.code >= KHTTP_400);
return 0;
}
static char *
test_browse_path_too_long()
{
struct kreq r;
struct http_ret ret;
/* a lengthy path should cause URL overflow... */
r = (struct kreq) {
.path = "this/is/a/very/very/lengthy/path/that/should/overflow/the/maximum/allowed/path/length/of/PATH_MAX/well/of/course/this/limit/is/platform/dependent",
.suffix = "",
.mime = KMIME_TEXT_HTML
};
ret = browse(&r);
mu_assert("error, browse allowed invalid traversal!",
ret.code >= KHTTP_400);
return 0;
}
static char *
all_tests()
{
mu_run_test(test_browse_invalid_traversal);
mu_run_test(test_browse_path_too_long);
return 0;
}
int
main(void)
{
char *result = all_tests();
if (result != 0) {
printf("%s\n", result);
} else {
printf("ALL TESTS PASSED\n");
}
printf("Tests run: %d\n", tests_run);
return result != 0;
}
|