48 lines
2.9 KiB
C++
48 lines
2.9 KiB
C++
// Routes: POST /google/ops/iam, /google/ops/projects, /google/ops/logs
|
|||
|
|
#include "support/GoogleRig.hpp"
|
||
|
|
|
||
|
|
using namespace molo::example::test;
|
||
|
|
|
||
|
|
int main() {
|
||
|
|
setenv("GOOGLE_CLOUD_PROJECT", "test-project", 1);
|
||
|
|
GoogleRig rig(false);
|
||
|
|
Fixture f(rig.client);
|
||
|
|
auto iam = [&](const std::string& body) { return f.client->post("/google/ops/iam", body, "application/json"); };
|
||
|
|
auto proj = [&](const std::string& body) { return f.client->post("/google/ops/projects", body, "application/json"); };
|
||
|
|
auto logs = [&](const std::string& body) { return f.client->post("/google/ops/logs", body, "application/json"); };
|
||
|
|
|
||
|
|
check(iam("{\"action\":\"service_accounts\"}").status == 503, "service accounts without credential is 503");
|
||
|
|
check(iam("{\"action\":\"roles\"}").status == 503, "roles without credential is 503");
|
||
|
|
check(iam("{\"action\":\"test_permissions\",\"account\":\"a@p.iam.gserviceaccount.com\","
|
||
|
|
"\"permissions\":[\"iam.serviceAccounts.get\"]}").status == 503,
|
||
|
|
"test permissions without credential is 503");
|
||
|
|
check(iam("{\"action\":\"test_permissions\",\"account\":\"a@p.iam.gserviceaccount.com\"}").status == 422,
|
||
|
|
"missing permissions is 422");
|
||
|
|
check(iam("{\"action\":\"test_permissions\",\"account\":\"a/b\",\"permissions\":[\"x\"]}").status == 422,
|
||
|
|
"bad account is 422");
|
||
|
|
check(iam("{\"action\":\"sign_jwt\",\"account\":\"a@p.iam.gserviceaccount.com\","
|
||
|
|
"\"payload\":\"{\\\"sub\\\":\\\"x\\\"}\"}").status == 503,
|
||
|
|
"sign_jwt without credential is 503");
|
||
|
|
check(iam("{\"action\":\"sign_blob\",\"account\":\"a@p.iam.gserviceaccount.com\"}").status == 422,
|
||
|
|
"sign_blob without payload is 422");
|
||
|
|
check(iam("{\"action\":\"nope\"}").status == 422, "unknown iam action is 422");
|
||
|
|
|
||
|
|
check(proj("{\"action\":\"get\"}").status == 503, "project get without credential is 503");
|
||
|
|
check(proj("{\"action\":\"search\",\"query\":\"displayName:prod*\"}").status == 503, "search is 503");
|
||
|
|
check(proj("{\"action\":\"search\",\"query\":\"" + std::string(300, 'x') + "\"}").status == 422, "long query is 422");
|
||
|
|
check(proj("{\"action\":\"get\",\"project\":\"../x\"}").status == 422, "bad project is 422");
|
||
|
|
check(proj("{\"action\":\"nope\"}").status == 422, "unknown project action is 422");
|
||
|
|
|
||
|
|
check(logs("{\"filter\":\"severity>=ERROR\"}").status == 503, "logs without credential is 503");
|
||
|
|
check(logs("{\"limit\":0}").status == 422, "limit 0 is 422");
|
||
|
|
check(logs("{\"limit\":101}").status == 422, "limit over cap is 422");
|
||
|
|
check(logs("{\"limit\":\"5\"}").status == 422, "string limit is 422");
|
||
|
|
check(logs("{\"filter\":\"" + std::string(3000, 'x') + "\"}").status == 422, "long filter is 422");
|
||
|
|
|
||
|
|
check(f.client->get("/google/ops/iam").status == 405, "get iam is 405");
|
||
|
|
check(f.client->get("/google/ops/projects").status == 405, "get projects is 405");
|
||
|
|
check(f.client->get("/google/ops/logs").status == 405, "get logs is 405");
|
||
|
|
check(rig.mock->send_count() == 0, "nothing reached Google");
|
||
|
|
return finish("google/ops/iam");
|
||
|
|
}
|