diff options
author | Sebastian Geerken <devnull@localhost> | 2013-01-13 15:21:46 +0100 |
---|---|---|
committer | Sebastian Geerken <devnull@localhost> | 2013-01-13 15:21:46 +0100 |
commit | 5797bbb234071775fe6148a29c9224c04912c8c1 (patch) | |
tree | 4bd03596f875f886f7951e43526341b128c087c7 /test/cookies.c | |
parent | 657daf90e9a24bfeb3c38aca2682b5f36d86dff3 (diff) | |
parent | 927887827f2a440f1f1b39e58d87b12154098d4a (diff) |
Update with main repo.
Diffstat (limited to 'test/cookies.c')
-rw-r--r-- | test/cookies.c | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/test/cookies.c b/test/cookies.c index 1036779f..40661650 100644 --- a/test/cookies.c +++ b/test/cookies.c @@ -44,6 +44,7 @@ } D_STMT_END #define MSG(...) MSG_INNARDS("", __VA_ARGS__) +#define MSG_WARN(...) MSG_INNARDS("** WARNING **: ", __VA_ARGS__) #define MSG_ERR(...) MSG_INNARDS("** ERROR **: ", __VA_ARGS__) @@ -778,8 +779,87 @@ static void path() expect(__LINE__, "Cookie: name=val\r\n", "http", "p6.com", "/dir/subdir/s"); } +int Cookies_rc_check() +{ + const int line_maxlen = 4096; + FILE *stream; + char *filename; + char line[line_maxlen]; + bool_t default_deny = TRUE; + + /* Get a file pointer */ + filename = dStrconcat(dGethomedir(), "/.dillo/cookiesrc", NULL); + stream = fopen(filename, "r"); + dFree(filename); + + if (!stream) { + MSG_ERR("Cannot run test; cannot open cookiesrc.\n"); + return 1; + } + + /* Get all lines in the file */ + while (!feof(stream)) { + char *rc; + + line[0] = '\0'; + rc = fgets(line, line_maxlen, stream); + if (!rc && ferror(stream)) { + MSG_ERR("Error while reading rule from cookiesrc: %s\n", + dStrerror(errno)); + fclose(stream); + return 2; + } + + /* Remove leading and trailing whitespaces */ + dStrstrip(line); + + if (line[0] != '\0' && line[0] != '#') { + int domain_end, i = 0; + const char *rule; + + /* Get the domain */ + while (line[i] != '\0' && !dIsspace(line[i])) + i++; + domain_end = i; + + /* Skip past whitespace */ + while (dIsspace(line[i])) + i++; + line[domain_end] = '\0'; + + /* Get the rule */ + rule = line + i; + while (line[i] != '\0' && !dIsspace(line[i])) + i++; + line[i] = '\0'; + + if (!dStrAsciiCasecmp(line, "DEFAULT")) { + if (!dStrAsciiCasecmp(rule, "ACCEPT") || + !dStrAsciiCasecmp(rule, "ACCEPT_SESSION")) + default_deny = FALSE; + } else { + if (!dStrAsciiCasecmp(rule, "DENY")) + MSG_WARN("DENY rules in cookiesrc can interfere with test.\n"); + } + } + } + fclose(stream); + + if (default_deny) { + MSG_ERR("Cannot run test with cookiesrc default of deny.\n"); + return 1; + } else { + return 0; + } +} + int main() { + if (Cookies_rc_check()) { + MSG("If you change cookiesrc, remember to stop the DPIs via dpidc.\n"); + return 1; + } + a_Cookies_set("name=val", "ordinary.com", "/", NULL); expect(__LINE__, "Cookie: name=val\r\n", "http", "ordinary.com", "/"); @@ -959,5 +1039,9 @@ MSG("org should fail: %s\n", #endif MSG("TESTS: passed: %u failed: %u\n", passed, failed); + + MSG("Now that everything is full of fake cookies, you should run " + "'dpidc stop', plus delete cookies.txt if necessary.\n"); + return 0; } |