Adjust test: make_safe_uri no longer strips query params.
[darkhttpd] / devel / test_make_safe_uri.c
1 #define main _main_disabled_
2 #include "../darkhttpd.c"
3 #undef main
4
5 static void
6 test(const char *input, const char *expected)
7 {
8 char *tmp = xstrdup(input);
9 char *out = make_safe_url(tmp);
10
11 if (expected == NULL) {
12 if (out == NULL)
13 printf("PASS: \"%s\" is unsafe\n", input);
14 else
15 printf("FAIL: \"%s\" is unsafe, but got \"%s\"\n",
16 input, out);
17 }
18 else if (out == NULL)
19 printf("FAIL: \"%s\" should become \"%s\", got unsafe\n",
20 input, expected);
21 else if (strcmp(out, expected) == 0)
22 printf("PASS: \"%s\" => \"%s\"\n", input, out);
23 else
24 printf("FAIL: \"%s\" => \"%s\", expecting \"%s\"\n",
25 input, out, expected);
26 free(tmp);
27 }
28
29 static char const *tests[] = {
30 "", NULL,
31 "/", "/",
32 "/.", "/",
33 "/./", "/",
34 "/../", NULL,
35 "/abc", "/abc",
36 "/abc/", "/abc/",
37 "/abc/.", "/abc",
38 "/abc/./", "/abc/",
39 "/abc/..", "/",
40 "/abc/../", "/",
41 "/abc/../def", "/def",
42 "/abc/../def/", "/def/",
43 "/abc/../def/..", "/",
44 "/abc/../def/../", "/",
45 "/abc/../def/../../", NULL,
46 "/abc/../def/.././", "/",
47 "/abc/../def/.././../", NULL,
48 "/a/b/c/../../d/", "/a/d/",
49 "/a/b/../../../c", NULL,
50 /* don't forget consolidate_slashes */
51 "//a///b////c/////", "/a/b/c/",
52 NULL
53 };
54
55 int
56 main(void)
57 {
58 const char **curr = tests;
59
60 while (curr[0] != NULL) {
61 test(curr[0], curr[1]);
62 curr += 2;
63 }
64
65 return 0;
66 }
67 /* vim:set tabstop=4 shiftwidth=4 expandtab tw=78: */