Files

52 lines
2.4 KiB
C++
Raw Permalink Normal View History

// 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");
}