2006-12-13 11:14:27 +03:00
|
|
|
#define main _main_disabled_
|
2011-01-18 16:48:59 +03:00
|
|
|
#include "../darkhttpd.c"
|
2006-12-13 11:14:27 +03:00
|
|
|
#undef main
|
|
|
|
|
|
|
|
static void
|
|
|
|
test(const char *input, const char *expected)
|
|
|
|
{
|
|
|
|
char *tmp = xstrdup(input);
|
2011-04-16 12:52:53 +04:00
|
|
|
char *out = make_safe_url(tmp);
|
2006-12-13 11:14:27 +03:00
|
|
|
|
|
|
|
if (expected == NULL) {
|
2006-12-13 11:16:16 +03:00
|
|
|
if (out == NULL)
|
2006-12-13 11:14:27 +03:00
|
|
|
printf("PASS: \"%s\" is unsafe\n", input);
|
2006-12-13 11:16:16 +03:00
|
|
|
else
|
2006-12-13 11:14:27 +03:00
|
|
|
printf("FAIL: \"%s\" is unsafe, but got \"%s\"\n",
|
|
|
|
input, out);
|
|
|
|
}
|
2006-12-13 11:16:16 +03:00
|
|
|
else if (out == NULL)
|
2006-12-13 11:14:27 +03:00
|
|
|
printf("FAIL: \"%s\" should become \"%s\", got unsafe\n",
|
|
|
|
input, expected);
|
2006-12-13 11:16:16 +03:00
|
|
|
else if (strcmp(out, expected) == 0)
|
2006-12-13 11:14:27 +03:00
|
|
|
printf("PASS: \"%s\" => \"%s\"\n", input, out);
|
|
|
|
else
|
|
|
|
printf("FAIL: \"%s\" => \"%s\", expecting \"%s\"\n",
|
|
|
|
input, out, expected);
|
2006-12-13 11:16:16 +03:00
|
|
|
free(tmp);
|
2006-12-13 11:14:27 +03:00
|
|
|
}
|
|
|
|
|
2006-12-13 11:41:05 +03:00
|
|
|
static char const *tests[] = {
|
2014-05-26 15:36:29 +04:00
|
|
|
"", NULL,
|
2006-12-13 11:14:27 +03:00
|
|
|
"/", "/",
|
|
|
|
"/.", "/",
|
|
|
|
"/./", "/",
|
|
|
|
"/../", NULL,
|
|
|
|
"/abc", "/abc",
|
|
|
|
"/abc/", "/abc/",
|
|
|
|
"/abc/.", "/abc",
|
|
|
|
"/abc/./", "/abc/",
|
|
|
|
"/abc/..", "/",
|
|
|
|
"/abc/../", "/",
|
|
|
|
"/abc/../def", "/def",
|
|
|
|
"/abc/../def/", "/def/",
|
|
|
|
"/abc/../def/..", "/",
|
|
|
|
"/abc/../def/../", "/",
|
|
|
|
"/abc/../def/../../", NULL,
|
|
|
|
"/abc/../def/.././", "/",
|
|
|
|
"/abc/../def/.././../", NULL,
|
|
|
|
"/a/b/c/../../d/", "/a/d/",
|
|
|
|
"/a/b/../../../c", NULL,
|
2006-12-13 11:17:56 +03:00
|
|
|
/* don't forget consolidate_slashes */
|
|
|
|
"//a///b////c/////", "/a/b/c/",
|
2014-05-26 15:36:29 +04:00
|
|
|
/* strip query params */
|
|
|
|
"/?a=b", "/",
|
|
|
|
"/index.html?", "/index.html",
|
|
|
|
"/index.html?a", "/index.html",
|
|
|
|
"/index.html?a=b", "/index.html",
|
2006-12-13 11:14:27 +03:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
int
|
2006-12-13 11:41:05 +03:00
|
|
|
main(void)
|
2006-12-13 11:14:27 +03:00
|
|
|
{
|
2006-12-13 11:41:05 +03:00
|
|
|
const char **curr = tests;
|
2006-12-13 11:14:27 +03:00
|
|
|
|
|
|
|
while (curr[0] != NULL) {
|
|
|
|
test(curr[0], curr[1]);
|
|
|
|
curr += 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
/* vim:set tabstop=4 shiftwidth=4 expandtab tw=78: */
|