char *test_Dir_resolve_file() { Dir *test = Dir_create("tests/", "sample.html", "test/plain"); mu_assert(test != NULL, "Failed to make test dir."); FileRecord *rec = Dir_resolve_file(test, bfromcstr("/"), bfromcstr("/sample.json")); mu_assert(rec != NULL, "Failed to resolve file that should be there."); rec = Dir_resolve_file(test, bfromcstr("/"), bfromcstr("/")); mu_assert(rec != NULL, "Failed to find default file."); rec = Dir_resolve_file(test, bfromcstr("/"), bfromcstr("/../../../../../etc/passwd")); mu_assert(rec == NULL, "HACK! should not find this."); Dir_destroy(test); test = Dir_create("foobar/", "sample.html", "test/plan"); mu_assert(test != NULL, "Failed to make the failed dir."); rec = Dir_resolve_file(test, bfromcstr("/"), bfromcstr("/sample.json")); mu_assert(rec == NULL, "Should not get something from a bad base directory."); Dir_destroy(test); return NULL; }
char *test_Dir_resolve_file() { Dir *test = Dir_create( bfromcstr("tests/"), bfromcstr("sample.html"), bfromcstr("test/plain"), 0); mu_assert(test != NULL, "Failed to make test dir."); FileRecord *rec = Dir_resolve_file(test, bfromcstr("/"), bfromcstr("/sample.json")); mu_assert(rec != NULL, "Failed to resolve file that should be there."); rec = Dir_resolve_file(test, bfromcstr("/"), bfromcstr("/")); mu_assert(rec != NULL, "Failed to find default file."); rec = Dir_resolve_file(test, bfromcstr("/"), bfromcstr("/../../../../../etc/passwd")); mu_assert(rec == NULL, "HACK! should not find this."); rec = Dir_resolve_file(test, bfromcstr("/tests/"), bfromcstr("/test")); mu_assert(rec == NULL, "Should NOT find short paths."); rec = Dir_resolve_file(test, bfromcstr("/"), bfromcstr("/%E2%82%ACtonn%C3%A4nt%2520.tx%C3%BE")); mu_assert(rec != NULL, "Should find file with a percent-encoded name."); rec = Dir_resolve_file(test, bfromcstr("/"), bfromcstr("/%E2%82%ACtonn%C3%A4nt%2520/present.txt")); mu_assert(rec != NULL, "Should find file inside percent-encoded path."); Dir_destroy(test); test = Dir_create( bfromcstr("foobar/"), bfromcstr("sample.html"), bfromcstr("test/plan"), 0); mu_assert(test != NULL, "Failed to make the failed dir."); rec = Dir_resolve_file(test, bfromcstr("/"), bfromcstr("/sample.json")); mu_assert(rec == NULL, "Should not get something from a bad base directory."); Dir_destroy(test); return NULL; }
void backend_destroy_cb(Route *r, RouteMap *map) { (void)map; Backend *backend = (Backend *)r->data; if(backend) { if(backend->type == BACKEND_DIR) { Dir_destroy(backend->target.dir); } else if(backend->type == BACKEND_HANDLER) { // ignore handlers since those are typically shared } else if(backend->type == BACKEND_PROXY) { Proxy_destroy(backend->target.proxy); } else { log_err("Invalid backend type, don't know how to destroy: %d", backend->type); } free(backend); r->data = NULL; } }