/* tests/oauth_probe.c — run the OAuth rewrite on stdin, print the result on stdout. * * oauth_probe native < body.json > rewritten.json * oauth_probe compat < body.json > rewritten.json * * Exit 0 = rewritten, 3 = unchanged (already usable or not a shape it touches). * Lets a test look at the exact bytes the module produces without starting junction, * so a broken rewrite is visible as a JSON diff and not as "the API answered 429 * again" — the failure mode this module exists for looks identical to a quota error. */ #include #include #include #include "../src/oauth.h" int main(int argc, char **argv) { int compat = (argc > 1 && !strcmp(argv[1], "compat")); size_t cap = 1 << 16, len = 0; char *buf = malloc(cap); if (!buf) return 2; size_t r; while ((r = fread(buf + len, 1, cap - len, stdin)) > 0) { len += r; if (len == cap) { cap *= 2; char *nb = realloc(buf, cap); if (!nb) { free(buf); return 2; } buf = nb; } } char *out = NULL; size_t out_len = 0; int rc = j_oauth_body(buf, len, compat, &out, &out_len); free(buf); if (rc != 0) return rc == 1 ? 3 : 4; /* 3 = already marked, 4 = not a body we touch */ fwrite(out, 1, out_len, stdout); free(out); return 0; }