105 route tests, matrix crawl, spec and README updated. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
28 lines
1.8 KiB
C++
28 lines
1.8 KiB
C++
// Route: GET/POST /governance/keys (+ revoke, whoami): API keys with scopes
|
|
#include "support/Assert.hpp"
|
|
|
|
using namespace molo::example::test;
|
|
using molo::example::fw::Method;
|
|
|
|
int main() {
|
|
Fixture f;
|
|
check(f.client->get("/governance/keys").status == 200, "form page");
|
|
auto bad = f.client->post("/governance/keys", "owner=&tier=gold", "application/x-www-form-urlencoded");
|
|
check(bad.status == 422 && contains(bad.body, "field-error"), "inline errors");
|
|
auto js = f.client->request(Method::Post, "/governance/keys", "owner=ada&tier=free&scopes=read", {{"Accept", "application/json"}});
|
|
check(js.status == 201 && contains(js.body, "mk_"), "issued");
|
|
std::string key = js.body.substr(js.body.find("mk_"), 35);
|
|
auto who = f.client->request(Method::Get, "/governance/whoami", "", {{"X-API-Key", key}});
|
|
check(who.status == 200 && contains(who.body, "ada"), "authenticates");
|
|
check(f.client->get("/governance/whoami").status == 401, "missing key 401");
|
|
check(f.client->request(Method::Get, "/governance/whoami", "", {{"X-API-Key", "mk_bogus"}}).status == 401, "unknown 401");
|
|
auto nos = f.client->request(Method::Post, "/governance/keys", "owner=bob&scopes=write", {{"Accept", "application/json"}});
|
|
std::string k2 = nos.body.substr(nos.body.find("mk_"), 35);
|
|
check(f.client->request(Method::Get, "/governance/whoami", "", {{"X-API-Key", k2}}).status == 403, "missing scope 403");
|
|
check(f.client->post("/governance/keys/key1/revoke").status == 200, "revoke");
|
|
auto rev = f.client->request(Method::Get, "/governance/whoami", "", {{"X-API-Key", key}});
|
|
check(rev.status == 401 && contains(rev.body, "Revoked"), "side effect: revoked key rejected");
|
|
check(f.client->post("/governance/keys/nope/revoke").status == 404, "unknown revoke 404");
|
|
return finish("governance/keys");
|
|
}
|