// Route: POST /ai/openai/admin/webhook/verify (local, no credential) #include "support/Assert.hpp" using namespace molo::example::test; int main() { Fixture f; auto v = [&](const std::string& b) { return f.client->post("/ai/openai/admin/webhook/verify", b, "application/json"); }; // Standard Webhooks reference vector; signature recomputed independently with python3 hmac. const std::string head = "{\"secret\":\"whsec_MfKQ9r8GKYqrTwjUPD8ILPZIo2LaLaSw\",\"now\":"; const std::string tail = ",\"headers\":{\"Webhook-Id\":\"msg_p5jXN8AQM9LWM0D4loKWxJek\",\"Webhook-Timestamp\":\"1614265330\"," "\"Webhook-Signature\":\"v1,g0hM9SsE+OTPJTGt/tmIKtSyZlE3uFJELVlNIOLJ1OE=\"},"; auto ok = v(head + "1614265330" + tail + "\"body\":\"{\\\"test\\\": 2432232314}\"}"); check(ok.status == 200 && contains(ok.body, "\"ok\":true"), "reference vector verifies"); check(contains(ok.body, "event_error"), "non-event body is reported, not fatal"); auto old = v(head + "1614266000" + tail + "\"body\":\"{\\\"test\\\": 2432232314}\"}"); check(old.status == 200 && contains(old.body, "timestamp_too_old"), "stale timestamp rejected"); auto tampered = v(head + "1614265330" + tail + "\"body\":\"{\\\"test\\\": 2432232315}\"}"); check(tampered.status == 200 && contains(tampered.body, "signature_mismatch"), "tampered body rejected"); check(v("{\"headers\":{},\"body\":\"x\"}").status == 422, "missing secret is 422"); check(v("{\"secret\":\"whsec_!!\",\"headers\":{},\"body\":\"x\"}").status == 422, "bad secret is 422"); check(v("{\"secret\":\"whsec_MfKQ9r8GKYqrTwjUPD8ILPZIo2LaLaSw\",\"body\":\"x\"}").status == 422, "missing headers is 422"); check(contains(f.client->get("/ai/openai/admin/status").body, "\"signature_mismatch\":1"), "counters exposed"); check(f.client->get("/ai/openai/admin/webhook/verify").status == 405, "get is 405"); return finish("ai/openai/admin/webhook_verify"); }