feat(clients): armor: Model Armor, SCC agent findings, GuardedModel, discovery-checked call table

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-24 04:38:50 +02:00
co-authored by Claude Sonnet 5.5
parent 6d744a433f
commit 4022be601d
24 changed files with 4237 additions and 3 deletions
+51
View File
@@ -0,0 +1,51 @@
// Routes: GET /agent/armor (page) and GET /agent/armor/status (credential and
// auth requirements). No Google traffic, no credential needed.
#include "support/GoogleRig.hpp"
using namespace molo::example::test;
int main() {
setenv("GOOGLE_CLOUD_PROJECT", "demo-project", 1);
{
// Arrange
GoogleRig rig;
Fixture f(rig.client);
// Act
auto page = f.client->get("/agent/armor");
auto js = f.client->get("/embedded/agent_armor.js");
// Assert
check(page.status == 200, "page 200");
check(contains(page.headers.get("Content-Type"), "text/html"), "page is html");
check(contains(page.body, "/embedded/agent_armor.js"), "script linked");
check(contains(page.body, "<select id=\"a-action\">"), "actions are a dropdown, not a button group");
check(contains(page.body, "width=device-width"), "viewport meta for small phones");
check(js.status == 200, "script served");
check(rig.mock->send_count() == 0, "side effect: no upstream traffic");
}
{
GoogleRig rig;
Fixture f(rig.client);
auto res = f.client->get("/agent/armor/status");
check(res.status == 200, "status 200");
check(contains(res.headers.get("Content-Type"), "application/json"), "status is json");
check(contains(res.body, "\"configured\":true"), "configured with a credential");
check(contains(res.body, "\"api_keys_accepted\":false"), "states that API keys are refused");
check(contains(res.body, "\"auth_env\":\"GOOGLE_ACCESS_TOKEN\""), "names the token variable");
check(contains(res.body, "modelarmor.us-central1.rep.googleapis.com"), "regional Model Armor host");
check(contains(res.body, "securitycenter.googleapis.com"), "Security Command Center host");
check(contains(res.body, "\"pi_and_jailbreak\""), "lists the typed filters");
check(!contains(res.body, kTestKey), "credential never shown");
check(rig.mock->send_count() == 0, "side effect: no upstream traffic");
}
{
GoogleRig rig(false);
Fixture f(rig.client);
check(contains(f.client->get("/agent/armor/status").body, "\"configured\":false"),
"not configured without a credential");
check(f.client->get("/agent/armor").status == 200, "page still renders without a credential");
}
Fixture f;
check(f.client->post("/agent/armor").status == 405, "post to the page is 405");
check(f.client->post("/agent/armor/status").status == 405, "post to status is 405");
return finish("agent/armor/page");
}
+101
View File
@@ -0,0 +1,101 @@
// Routes: every POST under /agent/armor. Without a credential a valid request
// answers 503 google_not_configured; bad input answers 422 before any
// traffic; GET answers 405. Google replies are not scripted anywhere.
#include "support/GoogleRig.hpp"
using namespace molo::example::test;
namespace {
const char* kJson = "application/json";
std::string big(std::size_t n) { return std::string(n, 'a'); }
} // namespace
int main() {
setenv("GOOGLE_CLOUD_PROJECT", "demo-project", 1);
unsetenv("GOOGLE_CLOUD_LOCATION");
struct Route {
std::string path;
std::string valid;
};
const std::vector<Route> routes = {
{"/agent/armor/sanitize/prompt", "{\"template_id\":\"t1\",\"text\":\"hello\"}"},
{"/agent/armor/sanitize/response", "{\"template_id\":\"t1\",\"text\":\"hello\",\"prompt\":\"q\"}"},
{"/agent/armor/guard", "{\"template_id\":\"t1\",\"text\":\"hello\"}"},
{"/agent/armor/templates/list", "{}"},
{"/agent/armor/templates/get", "{\"template_id\":\"t1\"}"},
{"/agent/armor/templates/create",
"{\"template_id\":\"t1\",\"pi\":\"HIGH\",\"rai\":\"HATE_SPEECH:HIGH,DANGEROUS\",\"malicious_uri\":\"true\"}"},
{"/agent/armor/templates/delete", "{\"template_id\":\"t1\",\"confirm\":\"delete\"}"},
{"/agent/armor/floor/get", "{}"},
{"/agent/armor/findings", "{\"scope\":\"organizations/1\",\"severity\":\"HIGH\"}"},
{"/agent/armor/dashboard", "{\"scope\":\"organizations/1\"}"},
};
{
// No credential: valid input is a loud 503, nothing leaves the process.
GoogleRig rig(false);
Fixture f(rig.client);
for (const auto& r : routes) {
auto res = f.client->post(r.path, r.valid, kJson);
check(res.status == 503 && contains(res.body, "google_not_configured"),
"503 google_not_configured: " + r.path);
}
check(rig.mock->send_count() == 0, "no upstream traffic without a credential");
}
{
// Bad input: 422 before any traffic, even with a credential.
GoogleRig rig;
Fixture f(rig.client);
auto expect422 = [&](const std::string& path, const std::string& body, const std::string& what) {
auto res = f.client->post(path, body, kJson);
check(res.status == 422 && contains(res.body, "validation_error"), "422 " + what);
};
expect422("/agent/armor/sanitize/prompt", "{\"text\":\"hello\"}", "prompt without template_id");
expect422("/agent/armor/sanitize/prompt", "{\"template_id\":\"../x\",\"text\":\"hello\"}", "prompt with a path-like template_id");
expect422("/agent/armor/sanitize/prompt", "{\"template_id\":\"t1\"}", "prompt without text");
expect422("/agent/armor/sanitize/response", "{\"template_id\":\"t1\"}", "response without text");
expect422("/agent/armor/guard", "{\"template_id\":\"t1\"}", "guard without text");
// Limit case: text over the 100000 character ceiling.
expect422("/agent/armor/sanitize/prompt",
"{\"template_id\":\"t1\",\"text\":\"" + big(100001) + "\"}", "prompt over the character cap");
expect422("/agent/armor/templates/get", "{}", "get without template_id");
expect422("/agent/armor/templates/list", "{\"page_size\":\"101\"}", "list over the page cap");
expect422("/agent/armor/templates/list", "{\"page_size\":\"x\"}", "list with a non-numeric page size");
expect422("/agent/armor/templates/create", "{\"template_id\":\"t1\",\"rai\":\"NOPE\"}", "unknown rai type");
expect422("/agent/armor/templates/create", "{\"template_id\":\"t1\",\"pi\":\"MAYBE\"}", "unknown confidence");
expect422("/agent/armor/templates/create", "{\"template_id\":\"t1\",\"enforcement\":\"MAYBE\"}", "unknown enforcement");
expect422("/agent/armor/templates/delete", "{\"template_id\":\"t1\"}", "delete without confirm");
expect422("/agent/armor/templates/delete", "{\"template_id\":\"t1\",\"confirm\":\"yes\"}", "delete with a wrong confirm");
expect422("/agent/armor/floor/get", "{\"scope\":\"buckets/1\"}", "floor with a bad scope");
expect422("/agent/armor/findings", "{\"scope\":\"buckets/1\"}", "findings with a bad scope");
expect422("/agent/armor/findings", "{\"scope\":\"organizations/1\",\"severity\":\"SEVERE\"}", "findings with a bad severity");
expect422("/agent/armor/findings", "{\"scope\":\"organizations/1\",\"page_size\":\"1001\"}", "findings over the page cap");
expect422("/agent/armor/findings", "{\"scope\":\"organizations/1\",\"max_pages\":\"11\"}", "findings over the page limit");
expect422("/agent/armor/findings", "{\"scope\":\"organizations/1\",\"max_pages\":\"0\"}", "findings with zero pages");
expect422("/agent/armor/findings", "{\"scope\":\"organizations/1\",\"order_by\":\"color\"}", "findings with a bad order_by");
expect422("/agent/armor/findings", "{\"scope\":\"organizations/1\",\"category\":\"a\\\"b\"}", "findings with a quote in a category");
expect422("/agent/armor/dashboard", "{\"scope\":\"organizations/1\",\"severity\":\"SEVERE\"}", "dashboard with a bad severity");
check(rig.mock->send_count() == 0, "no upstream traffic for rejected input");
}
{
// Missing project: loud 422, not a malformed URL.
GoogleRig rig;
Fixture f(rig.client);
unsetenv("GOOGLE_CLOUD_PROJECT");
auto res = f.client->post("/agent/armor/templates/get", "{\"template_id\":\"t1\"}", kJson);
check(res.status == 422 && contains(res.body, "GOOGLE_CLOUD_PROJECT"), "422 names the missing project");
check(rig.mock->send_count() == 0, "no upstream traffic without a project");
setenv("GOOGLE_CLOUD_PROJECT", "demo-project", 1);
}
{
// GET on a POST-only route is 405.
Fixture f;
for (const auto& r : routes)
check(f.client->get(r.path).status == 405, "GET is 405: " + r.path);
}
return finish("agent/armor/routes");
}