Merge sessions, registry, optimize, armor gaps
This commit is contained in:
@@ -0,0 +1,96 @@
|
||||
// Routes: GET /agent/armor/categories (no credential) and the Security
|
||||
// Command Center administration routes under /agent/armor/scc. Without a
|
||||
// credential a valid request answers 503 google_not_configured; bad input is
|
||||
// 422 before any traffic; a wrong verb is 405. Google replies are not scripted.
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "support/GoogleRig.hpp"
|
||||
|
||||
using namespace molo::example::test;
|
||||
using molo::example::fw::Method;
|
||||
|
||||
int main() {
|
||||
setenv("GOOGLE_CLOUD_PROJECT", "demo-project", 1);
|
||||
const std::string json = "application/json";
|
||||
const std::string finding = "organizations/1/sources/2/findings/f1";
|
||||
struct Route {
|
||||
std::string path, valid, invalid;
|
||||
};
|
||||
const std::vector<Route> routes = {
|
||||
{"/agent/armor/scc/availability", "{\"scope\":\"projects/demo-project\"}",
|
||||
"{\"scope\":\"projects/demo-project/locations/global\"}"},
|
||||
{"/agent/armor/scc/configs/list",
|
||||
"{\"kind\":\"muteConfigs\",\"parent\":\"projects/demo-project/locations/global\"}",
|
||||
"{\"kind\":\"widgets\",\"parent\":\"projects/demo-project\"}"},
|
||||
{"/agent/armor/scc/configs/get",
|
||||
"{\"kind\":\"muteConfigs\",\"name\":\"projects/demo-project/muteConfigs/m1\"}",
|
||||
"{\"kind\":\"muteConfigs\",\"name\":\"projects/demo-project\"}"},
|
||||
{"/agent/armor/scc/finding/state", "{\"finding\":\"" + finding + "\",\"state\":\"INACTIVE\"}",
|
||||
"{\"finding\":\"" + finding + "\",\"state\":\"MAYBE\"}"},
|
||||
{"/agent/armor/scc/finding/mute", "{\"finding\":\"" + finding + "\",\"mute\":\"MUTED\"}",
|
||||
"{\"finding\":\"organizations/1/sources/2\",\"mute\":\"MUTED\"}"},
|
||||
{"/agent/armor/scc/bulk-mute",
|
||||
"{\"parent\":\"projects/demo-project\",\"filter\":\"severity=\\\"LOW\\\"\",\"value\":\"MUTED\","
|
||||
"\"confirm\":\"bulk-mute\"}",
|
||||
"{\"parent\":\"projects/demo-project\",\"filter\":\"\",\"value\":\"MUTED\",\"confirm\":\"bulk-mute\"}"},
|
||||
{"/agent/armor/scc/operations/list", "{\"organization\":\"organizations/1\"}",
|
||||
"{\"organization\":\"projects/demo-project\"}"},
|
||||
};
|
||||
{
|
||||
GoogleRig rig(false);
|
||||
Fixture f(rig.client);
|
||||
for (const auto& r : routes) {
|
||||
auto res = f.client->post(r.path, r.valid, json);
|
||||
check(res.status == 503 && contains(res.body, "google_not_configured"),
|
||||
"503 google_not_configured: " + r.path);
|
||||
}
|
||||
auto del = f.client->request(Method::Delete,
|
||||
"/agent/armor/scc/configs?kind=muteConfigs&name=projects/demo-project/muteConfigs/m1");
|
||||
check(del.status == 503 && contains(del.body, "google_not_configured"), "delete config: 503 without a credential");
|
||||
check(rig.mock->send_count() == 0, "no upstream traffic without a credential");
|
||||
}
|
||||
{
|
||||
GoogleRig rig;
|
||||
Fixture f(rig.client);
|
||||
for (const auto& r : routes) {
|
||||
auto res = f.client->post(r.path, r.invalid, json);
|
||||
check(res.status == 422 && contains(res.body, "validation_error"), "422 on bad input: " + r.path);
|
||||
check(f.client->get(r.path).status == 405, "get is 405: " + r.path);
|
||||
}
|
||||
// Limit and guard cases.
|
||||
check(f.client->post("/agent/armor/scc/bulk-mute",
|
||||
"{\"parent\":\"projects/demo-project\",\"filter\":\"x\",\"value\":\"MUTED\"}", json)
|
||||
.status == 422,
|
||||
"bulk mute without confirm is 422");
|
||||
check(f.client->post("/agent/armor/scc/bulk-mute",
|
||||
"{\"parent\":\"projects/demo-project\",\"filter\":\"x\",\"value\":\"UNMUTED\","
|
||||
"\"confirm\":\"bulk-mute\"}", json).status == 422,
|
||||
"bulk mute value UNMUTED is not allowed (422)");
|
||||
check(f.client->request(Method::Delete, "/agent/armor/scc/configs?kind=x&name=y").status == 422,
|
||||
"delete config: unknown kind is 422");
|
||||
check(f.client->request(Method::Delete,
|
||||
"/agent/armor/scc/configs?kind=muteConfigs&name=projects/demo-project").status == 422,
|
||||
"delete config: a parent is not a config name (422)");
|
||||
check(f.client->post("/agent/armor/scc/configs").status == 405, "post on the delete route is 405");
|
||||
check(f.client->post("/agent/armor/findings", "{\"scope\":\"projects/demo-project\",\"family\":\"bogus\"}",
|
||||
json).status == 422,
|
||||
"findings: unknown family is 422");
|
||||
check(rig.mock->send_count() == 0, "side effect: rejected before any upstream call");
|
||||
}
|
||||
{
|
||||
// The category table needs no credential and never calls Google.
|
||||
GoogleRig rig(false);
|
||||
Fixture f(rig.client);
|
||||
auto res = f.client->get("/agent/armor/categories");
|
||||
check(res.status == 200 && contains(res.headers.get("Content-Type"), "application/json"), "categories 200 json");
|
||||
check(contains(res.body, "Execution: Container Escape") && contains(res.body, "AGENT_ENGINE_CONTAINER_ESCAPE"),
|
||||
"lists a documented runtime category and its module");
|
||||
check(contains(res.body, "AGENT_ENGINE_REVERSE_SHELL") && contains(res.body, "control_plane"),
|
||||
"lists both families");
|
||||
check(contains(res.body, "agentAnomaly"), "says how anomaly findings are recognised");
|
||||
check(f.client->post("/agent/armor/categories").status == 405, "post is 405");
|
||||
check(rig.mock->send_count() == 0, "side effect: GET never calls Google");
|
||||
}
|
||||
return finish("agent/armor/scc");
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
// Routes: POST /agent/optimize/synthetic, /operations/{list,get,wait,cancel},
|
||||
// DELETE /agent/optimize/operations, POST /agent/optimize/logs/write
|
||||
#include <cstdlib>
|
||||
#include <string>
|
||||
|
||||
#include "support/GoogleRig.hpp"
|
||||
|
||||
using namespace molo::example::test;
|
||||
using molo::example::fw::Method;
|
||||
|
||||
namespace {
|
||||
const std::string kJson = "application/json";
|
||||
const std::string kEval = "projects/test-proj/locations/us-central1/onlineEvaluators/1";
|
||||
const std::string kOp = kEval + "/operations/7";
|
||||
|
||||
struct Case {
|
||||
std::string path, good, bad;
|
||||
};
|
||||
} // namespace
|
||||
|
||||
int main() {
|
||||
setenv("GOOGLE_CLOUD_PROJECT", "test-proj", 1);
|
||||
const Case cases[] = {
|
||||
{"/agent/optimize/synthetic", "{\"request\":{\"taskDescription\":\"x\"}}", "{\"request\":{\"nope\":1}}"},
|
||||
{"/agent/optimize/operations/list", "{\"evaluator\":\"" + kEval + "\"}",
|
||||
"{\"evaluator\":\"projects/p/locations/l/evaluationRuns/r\"}"},
|
||||
{"/agent/optimize/operations/get", "{\"name\":\"" + kOp + "\"}", "{\"name\":\"operations/7\"}"},
|
||||
{"/agent/optimize/operations/wait", "{\"name\":\"" + kOp + "\",\"timeout_seconds\":\"60\"}",
|
||||
"{\"name\":\"" + kOp + "\",\"timeout_seconds\":\"61\"}"},
|
||||
{"/agent/optimize/operations/cancel", "{\"name\":\"" + kOp + "\"}", "{\"name\":\"\"}"},
|
||||
{"/agent/optimize/logs/write", "{\"log_id\":\"agent-check\",\"text\":\"hello\"}",
|
||||
"{\"log_id\":\"a/b\",\"text\":\"hello\"}"},
|
||||
};
|
||||
for (const Case& c : cases) {
|
||||
{
|
||||
GoogleRig none(false);
|
||||
Fixture f(none.client);
|
||||
auto res = f.client->post(c.path, c.good, kJson);
|
||||
check(res.status == 503 && contains(res.body, "google_not_configured"),
|
||||
c.path + ": no credential is a loud 503");
|
||||
check(none.mock->send_count() == 0, c.path + ": no network without a credential");
|
||||
}
|
||||
{
|
||||
GoogleRig keyed;
|
||||
Fixture f(keyed.client);
|
||||
auto res = f.client->post(c.path, c.bad, kJson);
|
||||
check(res.status == 422 && contains(res.body, "validation_error"), c.path + ": bad input is 422");
|
||||
check(f.client->get(c.path).status == 405, c.path + ": get is 405");
|
||||
check(keyed.mock->send_count() == 0, c.path + ": rejected before any upstream call");
|
||||
}
|
||||
}
|
||||
{
|
||||
GoogleRig none(false);
|
||||
Fixture f(none.client);
|
||||
auto del = f.client->request(Method::Delete, "/agent/optimize/operations?name=" + kOp);
|
||||
check(del.status == 503 && contains(del.body, "google_not_configured"),
|
||||
"delete operation: no credential is 503");
|
||||
check(none.mock->send_count() == 0, "no network without a credential");
|
||||
}
|
||||
{
|
||||
GoogleRig keyed;
|
||||
Fixture f(keyed.client);
|
||||
check(f.client->request(Method::Delete, "/agent/optimize/operations").status == 422,
|
||||
"delete: missing name is 422");
|
||||
check(f.client->request(Method::Delete, "/agent/optimize/operations?name=x").status == 422,
|
||||
"delete: bad name is 422");
|
||||
check(f.client->post("/agent/optimize/operations").status == 405, "post on the delete route is 405");
|
||||
check(keyed.mock->send_count() == 0, "side effect: rejected before any upstream call");
|
||||
}
|
||||
return finish("agent/optimize/gaps");
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
// Routes: POST /agent/registry/deny-policies/list, POST /agent/registry/boundaries/bindings
|
||||
#include "agent/registry/cases.hpp"
|
||||
|
||||
using namespace molo::example::test;
|
||||
|
||||
int main() {
|
||||
check_google_post_route("/agent/registry/deny-policies/list", "{\"project_number\":\"123456\"}",
|
||||
"{\"project_number\":\"my-project\"}", "non numeric project number");
|
||||
check_google_post_route("/agent/registry/boundaries/bindings",
|
||||
"{\"org_id\":\"42\",\"id\":\"pab-1\"}",
|
||||
"{\"org_id\":\"42\",\"id\":\"a/b\"}", "bad policy id");
|
||||
{
|
||||
GoogleRig rig;
|
||||
Fixture f(rig.client);
|
||||
check(f.client->post("/agent/registry/deny-policies/list", "{}", "application/json").status == 422,
|
||||
"limit: a missing project number is 422");
|
||||
check(f.client->post("/agent/registry/deny-policies/list",
|
||||
"{\"project_number\":\"" + std::string(21, '1') + "\"}", "application/json")
|
||||
.status == 422,
|
||||
"limit: 21 digits is 422");
|
||||
check(f.client->post("/agent/registry/boundaries/bindings", "{\"org_id\":\"x\",\"id\":\"pab-1\"}",
|
||||
"application/json").status == 422,
|
||||
"boundary bindings: bad org id is 422");
|
||||
check(rig.mock->send_count() == 0, "side effect: rejected before any upstream call");
|
||||
}
|
||||
return finish("agent/registry/iam");
|
||||
}
|
||||
@@ -14,6 +14,18 @@ int main() {
|
||||
check(f.client->post("/agent/registry/list", "{\"kind\":\"aiApplications\"}", "application/json").status == 422,
|
||||
"limit: a collection that is not listable here is 422");
|
||||
check(f.client->post("/agent/registry/list", "", "application/json").status == 422, "empty body is 422");
|
||||
check(f.client->post("/agent/registry/list", "{\"kind\":\"agents\",\"version\":\"v2\"}",
|
||||
"application/json").status == 422,
|
||||
"limit: an unknown API version is 422");
|
||||
}
|
||||
{
|
||||
// v1alpha is accepted as input and still needs a credential.
|
||||
GoogleRig rig(false);
|
||||
Fixture f(rig.client);
|
||||
auto res = f.client->post("/agent/registry/list", "{\"kind\":\"agents\",\"version\":\"v1alpha\"}",
|
||||
"application/json");
|
||||
check(res.status == 503 && contains(res.body, "google_not_configured"), "v1alpha without a credential is 503");
|
||||
check(rig.mock->send_count() == 0, "side effect: no upstream traffic");
|
||||
}
|
||||
return finish("agent/registry/list");
|
||||
}
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
// Routes: POST /agent/registry/operations/list, POST /agent/registry/operations/cancel,
|
||||
// DELETE /agent/registry/operations (explicit destructive route)
|
||||
#include "agent/registry/cases.hpp"
|
||||
|
||||
using namespace molo::example::test;
|
||||
using molo::example::fw::Method;
|
||||
|
||||
int main() {
|
||||
for (const char* scope : {"registry", "gateways", "policies"}) {
|
||||
std::string s = scope;
|
||||
check_google_post_route("/agent/registry/operations/list", "{\"scope\":\"" + s + "\"}",
|
||||
"{\"scope\":\"nowhere\"}", "unknown scope");
|
||||
check_google_post_route("/agent/registry/operations/cancel",
|
||||
"{\"scope\":\"" + s + "\",\"id\":\"op-1\"}",
|
||||
"{\"scope\":\"" + s + "\",\"id\":\"a/b\"}", "bad operation id");
|
||||
}
|
||||
{
|
||||
GoogleRig rig(false);
|
||||
Fixture f(rig.client);
|
||||
auto del = f.client->request(Method::Delete, "/agent/registry/operations?scope=gateways&id=op-1");
|
||||
check(del.status == 503 && contains(del.body, "google_not_configured"),
|
||||
"delete operation: 503 without a credential");
|
||||
check(rig.mock->send_count() == 0, "side effect: no upstream traffic");
|
||||
}
|
||||
{
|
||||
GoogleRig rig;
|
||||
Fixture f(rig.client);
|
||||
check(f.client->request(Method::Delete, "/agent/registry/operations?scope=x&id=op-1").status == 422,
|
||||
"delete: unknown scope is 422");
|
||||
check(f.client->request(Method::Delete, "/agent/registry/operations?scope=policies&id=a..b").status == 422,
|
||||
"delete: bad id is 422");
|
||||
check(f.client->request(Method::Delete, "/agent/registry/operations").status == 422,
|
||||
"delete: missing parameters are 422");
|
||||
check(f.client->get("/agent/registry/operations").status == 405, "get never deletes");
|
||||
check(f.client->post("/agent/registry/operations").status == 405, "post never deletes");
|
||||
check(rig.mock->send_count() == 0, "side effect: rejected before any upstream call");
|
||||
}
|
||||
return finish("agent/registry/operations");
|
||||
}
|
||||
@@ -13,6 +13,9 @@ int main() {
|
||||
check(res.status == 200, "status 200 without a credential");
|
||||
check(contains(res.headers.get("Content-Type"), "text/html"), "html");
|
||||
check(contains(res.body, "Agent registry") && contains(res.body, "agent_registry.js"), "page and script");
|
||||
check(contains(res.body, "id=\"r-truncated\""), "page has the loud truncation banner");
|
||||
check(contains(res.body, "id=\"r-version\"") && contains(res.body, "v1alpha"), "page offers v1alpha");
|
||||
check(contains(res.body, "ops-gateways"), "page offers the operations lists");
|
||||
check(f.client->post("/agent/registry").status == 405, "post is 405");
|
||||
check(f.client->get("/agent/registry/nope").status == 404, "unknown sub route is 404");
|
||||
check(rig.mock->send_count() == 0, "side effect: no upstream traffic");
|
||||
|
||||
@@ -15,6 +15,7 @@ int main() {
|
||||
check(contains(res.headers.get("Content-Type"), "application/json"), "json");
|
||||
check(contains(res.body, "\"configured\":false") && contains(res.body, "\"project_set\":true"), "state shown");
|
||||
check(contains(res.body, "\"max_ledger_entries\":5000"), "caps shown");
|
||||
check(contains(res.body, "\"max_items\":1000"), "the list item cap is stated");
|
||||
check(rig.mock->send_count() == 0, "side effect: no upstream traffic");
|
||||
}
|
||||
{
|
||||
|
||||
@@ -57,6 +57,26 @@ int main() {
|
||||
body("\"scope_key\":\"user_id\",\"scope_value\":\"1\""), body("\"scope_key\":\"\"")},
|
||||
{"/agent/sessions/memories/purge", body("\"filter\":\"scope.user_id=\\\"1\\\"\""),
|
||||
body("\"filter\":\"\"")},
|
||||
{"/agent/sessions/operations/list", body("\"parent\":\"" + kEngine + "/sessions/chat-1\""),
|
||||
body("\"parent\":\"" + kEngine + "/other/x\"")},
|
||||
{"/agent/sessions/operations/get", body("\"name\":\"" + kEngine + "/operations/7\""),
|
||||
body("\"name\":\"" + kEngine + "/operations/..\"")},
|
||||
{"/agent/sessions/operations/wait",
|
||||
body("\"name\":\"" + kEngine + "/operations/7\",\"timeout_seconds\":\"60\""),
|
||||
body("\"name\":\"" + kEngine + "/operations/7\",\"timeout_seconds\":\"61\"")},
|
||||
{"/agent/sessions/operations/cancel",
|
||||
body("\"name\":\"" + kEngine + "/memories/mem-1/operations/7\""),
|
||||
body("\"name\":\"operations/7\"")},
|
||||
{"/agent/sessions/serving-profiles/list", "{\"location\":\"us-central1\"}",
|
||||
"{\"location\":\"Bad Place\"}"},
|
||||
{"/agent/sessions/serving-profiles/get",
|
||||
"{\"location\":\"us-central1\",\"profile_id\":\"sp-1\"}",
|
||||
"{\"location\":\"us-central1\",\"profile_id\":\"Bad_Id\"}"},
|
||||
{"/agent/sessions/serving-profiles/create",
|
||||
"{\"location\":\"us-central1\",\"profile_id\":\"sp-1\",\"display_name\":\"Live\","
|
||||
"\"scope\":\"GEMINI_LIVE\"}",
|
||||
"{\"location\":\"us-central1\",\"profile_id\":\"sp-1\",\"display_name\":\"Live\","
|
||||
"\"scope\":\"EVERYTHING\"}"},
|
||||
};
|
||||
|
||||
GoogleRig rig(false);
|
||||
@@ -119,6 +139,30 @@ int main() {
|
||||
422,
|
||||
"delete memory: bad id is 422");
|
||||
|
||||
auto del_op = f.client->request(
|
||||
Method::Delete, "/agent/sessions/operations/operation?engine=" + kEngine +
|
||||
"&name=" + kEngine + "/operations/7");
|
||||
check(del_op.status == 503 && contains(del_op.body, "google_not_configured"),
|
||||
"delete operation: no credential is 503");
|
||||
check(f.client->request(Method::Delete,
|
||||
"/agent/sessions/operations/operation?engine=" + kEngine +
|
||||
"&name=" + kEngine + "/sessions").status == 422,
|
||||
"delete operation: a name that is no operation is 422");
|
||||
check(f.client->post("/agent/sessions/operations/operation").status == 405,
|
||||
"delete operation route: post is 405");
|
||||
auto del_profile = f.client->request(
|
||||
Method::Delete, "/agent/sessions/serving-profiles/profile?location=us-central1&id=sp-1");
|
||||
check(del_profile.status == 503 && contains(del_profile.body, "google_not_configured"),
|
||||
"delete serving profile: no credential is 503");
|
||||
check(f.client->request(Method::Delete,
|
||||
"/agent/sessions/serving-profiles/profile?location=us-central1&id=A_B")
|
||||
.status == 422,
|
||||
"delete serving profile: bad id is 422");
|
||||
check(f.client->post("/agent/sessions/operations/wait",
|
||||
body("\"name\":\"" + kEngine + "/operations/7\",\"timeout_seconds\":\"0\""),
|
||||
kJson).status == 422,
|
||||
"server-side wait of 0 seconds is 422");
|
||||
|
||||
check(rig.mock->send_count() == 0, "side effect: nothing reached the network");
|
||||
|
||||
// With a credential, validation still runs first and still stops traffic.
|
||||
|
||||
@@ -12,6 +12,8 @@ int main() {
|
||||
check(contains(page.headers.get("Content-Type"), "text/html"), "html");
|
||||
check(contains(page.body, "Agent sessions and memory"), "heading");
|
||||
check(contains(page.body, "/agent/sessions/memories/purge"), "lists the purge route");
|
||||
check(contains(page.body, "/agent/sessions/operations/wait"), "lists the server-side wait route");
|
||||
check(contains(page.body, "/agent/sessions/serving-profiles/list"), "lists serving profiles");
|
||||
check(contains(page.body, "viewport"), "mobile viewport meta from the base template");
|
||||
|
||||
auto status = f.client->get("/agent/sessions/status");
|
||||
@@ -20,6 +22,7 @@ int main() {
|
||||
check(contains(status.body, "\"configured\":true"), "configured with a credential");
|
||||
check(contains(status.body, "aiplatform v1beta1"), "names the API surface");
|
||||
check(contains(status.body, "\"max_top_k\":50"), "shows the top_k cap");
|
||||
check(contains(status.body, "\"max_server_wait_seconds\":60"), "shows the wait cap");
|
||||
check(!contains(status.body, kTestKey), "credential never shown");
|
||||
check(rig.mock->send_count() == 0, "side effect: GET pages never call Google");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user