27 lines
1.7 KiB
C++
27 lines
1.7 KiB
C++
// Route: POST /ai/openrouter/call (generic table call; dry run unless confirm)
|
|
#include "support/Assert.hpp"
|
|
|
|
using namespace molo::example::test;
|
|
|
|
int main() {
|
|
Fixture f;
|
|
auto post = [&](const std::string& body) { return f.client->post("/ai/openrouter/call", body, "application/json"); };
|
|
auto get = post("{\"call\":\"getModels\"}");
|
|
check(get.status == 503 && contains(get.body, "not_configured"), "read without key is 503");
|
|
check(contains(get.body, "OPENROUTER_API_KEY"), "names the variable to set");
|
|
auto mgmt = post("{\"call\":\"getCredits\"}");
|
|
check(mgmt.status == 503 && contains(mgmt.body, "OPENROUTER_MANAGEMENT_KEY"), "management read needs the management key");
|
|
auto dry = post("{\"call\":\"deleteKeys\",\"args\":{\"hash\":\"abc\"}}");
|
|
check(dry.status == 200 && contains(dry.body, "\"dry_run\":true"), "delete is a dry run");
|
|
check(contains(dry.body, "DELETE") && contains(dry.body, "/keys/abc"), "dry run shows the request");
|
|
auto secret = post("{\"call\":\"createBYOKKey\",\"body\":{\"provider\":\"openai\",\"key\":\"sk-verysecret\",\"name\":\"n\"}}");
|
|
check(secret.status == 200 && !contains(secret.body, "sk-verysecret"), "secrets are redacted in the dry run");
|
|
auto confirmed = post("{\"call\":\"deleteKeys\",\"args\":{\"hash\":\"abc\"},\"confirm\":true}");
|
|
check(confirmed.status == 503, "confirmed delete without key is 503");
|
|
check(post("{\"call\":\"uploadFile\"}").status == 422, "uploads are refused 422");
|
|
check(post("{\"call\":\"getKey\"}").status == 422, "validation precedes credentials");
|
|
check(post("{\"call\":\"getModels\",\"confirm\":\"yes\"}").status == 422, "confirm must be a boolean");
|
|
check(f.client->get("/ai/openrouter/call").status == 405, "get is 405");
|
|
return finish("ai/openrouter/call");
|
|
}
|