33 lines
2.5 KiB
C++
33 lines
2.5 KiB
C++
// Routes: POST /ai/anthropic/admin/{organization,usage,cost,claude-code,webhook/verify}
|
|||
|
|
#include "support/Assert.hpp"
|
||
|
|
|
||
|
|
using namespace molo::example::test;
|
||
|
|
|
||
|
|
static const char* kJson = "application/json";
|
||
|
|
|
||
|
|
int main() {
|
||
|
|
Fixture f;
|
||
|
|
auto post = [&](const std::string& path, const std::string& body) { return f.client->post("/ai/anthropic/admin" + path, body, kJson); };
|
||
|
|
check(post("/organization", "{}").status == 503, "organization without credential is 503");
|
||
|
|
check(post("/usage", "{\"starting_at\":\"2026-10-01T00:00:00Z\"}").status == 503, "usage without credential is 503");
|
||
|
|
check(post("/usage", "{}").status == 422, "usage without starting_at is 422");
|
||
|
|
check(post("/usage", "{\"starting_at\":\"yesterday\"}").status == 422, "bad timestamp is 422");
|
||
|
|
check(post("/usage", "{\"starting_at\":\"2026-10-01T00:00:00Z\",\"limit\":32}").status == 422, "limit over 31 days is 422");
|
||
|
|
check(post("/usage", "{\"starting_at\":\"2026-10-01T00:00:00Z\",\"bucket_width\":\"5m\"}").status == 422, "bad bucket width is 422");
|
||
|
|
check(post("/cost", "{\"starting_at\":\"2026-10-01T00:00:00Z\"}").status == 503, "cost without credential is 503");
|
||
|
|
check(post("/cost", "{\"starting_at\":\"2026-10-01T00:00:00Z\",\"group_by\":[\"model\"]}").status == 422, "cost group_by model is 422");
|
||
|
|
check(post("/claude-code", "{\"starting_at\":\"2026-10-01\"}").status == 503, "claude code without credential is 503");
|
||
|
|
check(post("/claude-code", "{\"starting_at\":\"2026-10-01T00:00:00Z\"}").status == 422, "claude code needs a date");
|
||
|
|
check(post("/claude-code", "{\"starting_at\":\"2026-10-01\",\"limit\":1001}").status == 422, "claude code limit over 1000 is 422");
|
||
|
|
|
||
|
|
// local signature check, Standard Webhooks published key (timestamp is old: outside tolerance)
|
||
|
|
auto v = post("/webhook/verify", "{\"signing_key\":\"whsec_MfKQ9r8GKYqrTwjUPD8ILPZIo2LaLaSw\",\"payload\":\"{}\","
|
||
|
|
"\"webhook_id\":\"m\",\"webhook_timestamp\":\"1614265330\",\"webhook_signature\":\"v1,AAAA\"}");
|
||
|
|
check(v.status == 200 && contains(v.body, "\"valid\":false"), "bad signature is reported, not an error");
|
||
|
|
check(post("/webhook/verify", "{\"signing_key\":\"%%%\",\"payload\":\"{}\"}").status == 422, "bad signing key is 422");
|
||
|
|
check(post("/webhook/verify", "{}").status == 422, "missing key is 422");
|
||
|
|
for (const char* p : {"/organization", "/usage", "/cost", "/claude-code", "/webhook/verify"})
|
||
|
|
check(f.client->get(std::string("/ai/anthropic/admin") + p).status == 405, std::string("get ") + p + " is 405");
|
||
|
|
return finish("ai/anthropic/admin/report");
|
||
|
|
}
|