35 lines
2.6 KiB
C++
35 lines
2.6 KiB
C++
// Route: POST /ai/anthropic/admin/call (validate, dry run for writes, 503 without credential)
|
|||
|
|
#include "support/Assert.hpp"
|
||
|
|
|
||
|
|
using namespace molo::example::test;
|
||
|
|
|
||
|
|
static const char* kJson = "application/json";
|
||
|
|
|
||
|
|
int main() {
|
||
|
|
Fixture f;
|
||
|
|
auto post = [&](const std::string& body) { return f.client->post("/ai/anthropic/admin/call", body, kJson); };
|
||
|
|
check(post("{\"call\":\"organization.invites.list\"}").status == 503, "read without credential is 503");
|
||
|
|
check(contains(post("{\"call\":\"organization.invites.list\"}").body, "not_configured"), "503 code is not_configured");
|
||
|
|
check(post("{}").status == 422, "missing call is 422");
|
||
|
|
check(post("{\"call\":\"nope.nothing\"}").status == 422, "unknown call is 422");
|
||
|
|
check(post("{\"call\":\"organization.invites.retrieve\"}").status == 422, "missing id is 422");
|
||
|
|
check(post("{\"call\":\"organization.invites.retrieve\",\"ids\":[\"a/b\"]}").status == 422, "bad id is 422");
|
||
|
|
check(post("{\"call\":\"organization.invites.list\",\"query\":{\"bogus\":1}}").status == 422, "unknown query param is 422");
|
||
|
|
check(post("{\"call\":\"organization.invites.list\",\"query\":{\"limit\":5000}}").status == 422, "limit over cap is 422");
|
||
|
|
check(post("{\"call\":\"organization.invites.create\",\"body\":{\"email\":\"a@b.c\"}}").status == 422, "missing required field is 422");
|
||
|
|
check(post("{\"call\":\"organization.invites.create\",\"body\":{\"email\":\"a@b.c\",\"role\":\"user\",\"x\":1}}").status == 422, "unknown field is 422");
|
||
|
|
check(post("{\"call\":\"sessions.events.stream\",\"ids\":[\"s1\"]}").status == 422, "stream calls are refused here");
|
||
|
|
check(post("not json").status == 422, "bad JSON is 422");
|
||
|
|
|
||
|
|
// writes and deletes are dry runs without confirm, even without a credential
|
||
|
|
auto dry = post("{\"call\":\"organization.invites.create\",\"body\":{\"email\":\"a@b.c\",\"role\":\"user\"}}");
|
||
|
|
check(dry.status == 200 && contains(dry.body, "\"dry_run\":true"), "create is a dry run");
|
||
|
|
auto del = post("{\"call\":\"organization.users.remove\",\"ids\":[\"user_01\"]}");
|
||
|
|
check(del.status == 200 && contains(del.body, "\"dry_run\":true") && contains(del.body, "DELETE"), "remove user is a dry run");
|
||
|
|
auto confirmed = post("{\"call\":\"organization.users.remove\",\"ids\":[\"user_01\"],\"confirm\":true}");
|
||
|
|
check(confirmed.status == 503, "confirmed delete without credential is 503");
|
||
|
|
check(post("{\"call\":\"organization.users.remove\",\"ids\":[\"user_01\"],\"confirm\":\"yes\"}").status == 422, "non-bool confirm is 422");
|
||
|
|
check(f.client->get("/ai/anthropic/admin/call").status == 405, "get is 405");
|
||
|
|
return finish("ai/anthropic/admin/call");
|
||
|
|
}
|