/* * test_updatesource.c -- McdeSys: which update sources root may use (make check) * * License: CNCL 1.0 (Could Not Care Less), see LICENSE at the top of the tree. * * The root update runs sysupgrade(8), which unpacks the sets and checks * nothing, and pkg_add -uu on the packages it is given. With an http:// * source anyone on the way could replace them, so only a directory, file:/// * and https:// are accepted (tasksd t0078, docs/reference/ * update-verification.txt). The other characters keep a source from meaning * more than a place to a shell, an option or a URL query. */ #include #include #include #include "private.h" /* mcde_sys_update_source_ok: the library's, not the API */ static const struct { const char *url; int ok; } cases[] = { { "/mnt/release", 1 }, /* a directory */ { "/home/user/makronix-0.99.10", 1 }, { "file:///mnt/release", 1 }, { "https://updates.example.org/makronix/0.99", 1 }, { "https://updates.example.org:8443/m", 1 }, { "https://10.0.0.5/m", 1 }, /* refused: the way can be read and changed */ { "http://updates.example.org/makronix", 0 }, { "HTTP://updates.example.org/makronix", 0 }, { "ftp://updates.example.org/makronix", 0 }, { "ssh://root@host/makronix", 0 }, { "HTTPS://updates.example.org/m", 0 }, /* only the form sysupgrade knows */ { "https://", 0 }, /* no host */ { "https:///m", 0 }, { "file://host/m", 0 }, /* a remote "file" */ { "file:/mnt/release", 0 }, { "relative/dir", 0 }, { "-oProxyCommand=id", 0 }, /* an option, not a place */ { "", 0 }, /* refused: characters that mean something */ { "/mnt/release; reboot", 0 }, { "/mnt/rel ease", 0 }, { "/mnt/$(id)", 0 }, { "/mnt/`id`", 0 }, { "https://host/m?x=1&y=2", 0 }, { "https://host/m#frag", 0 }, { "/mnt/it's", 0 }, { "/mnt/a\nb", 0 }, { "/mnt/a\\b", 0 }, }; int main(void) { size_t i; int failures = 0, ok; if (mcde_sys_update_source_ok(NULL) != 0) { printf("FAIL NULL: accepted\n"); failures++; } for (i = 0; i < sizeof cases / sizeof cases[0]; i++) { ok = mcde_sys_update_source_ok(cases[i].url) != 0; if (ok != cases[i].ok) { printf("FAIL \"%s\": %s\n", cases[i].url, ok ? "accepted" : "refused"); failures++; } } printf("test_updatesource: %d cases, %d failures\n", (int) (sizeof cases / sizeof cases[0]) + 1, failures); return failures != 0; }