feat(clients): openai admin: organization admin API, usage, costs, audit logs, webhooks
121-call table checked against the OpenAI OpenAPI document, admin-key-only client, destructive guards, WebhookVerifier (Standard Webhooks HMAC-SHA256), demo routes under /ai/openai/admin, local and opt-in live tests. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
// 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");
|
||||
}
|
||||
Reference in New Issue
Block a user