Merge registry module (Agent Registry, Gateway, Identity)
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
// Route: GET /agent/registry/approvals and /audit (local state)
|
||||
#include "support/GoogleRig.hpp"
|
||||
#include <cstdlib>
|
||||
|
||||
using namespace molo::example::test;
|
||||
using molo::example::fw::Method;
|
||||
|
||||
int main() {
|
||||
GoogleRig rig(false);
|
||||
Fixture f(rig.client);
|
||||
auto a = f.client->get("/agent/registry/approvals");
|
||||
check(a.status == 200 && contains(a.body, "\"scope\":\"local\"") && contains(a.body, "\"approvals\":[]"),
|
||||
"empty local ledger");
|
||||
auto l = f.client->get("/agent/registry/audit");
|
||||
check(l.status == 200 && contains(l.body, "\"entries\":[]") && contains(l.body, "\"dropped\":0"),
|
||||
"empty audit trail");
|
||||
check(f.client->post("/agent/registry/approvals").status == 405, "approvals post is 405");
|
||||
check(f.client->post("/agent/registry/audit").status == 405, "audit post is 405");
|
||||
return finish("agent/registry/approvals");
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
// Route: POST /agent/registry/approve
|
||||
#include "agent/registry/cases.hpp"
|
||||
|
||||
using namespace molo::example::test;
|
||||
|
||||
int main() {
|
||||
check_google_post_route("/agent/registry/approve",
|
||||
"{\"name\":\"projects/test-project/locations/us-central1/agents/a1\",\"actor\":\"alice\"}",
|
||||
"{\"name\":\"agents/a1\",\"actor\":\"alice\"}",
|
||||
"short asset name");
|
||||
{
|
||||
GoogleRig rig;
|
||||
Fixture f(rig.client);
|
||||
check(f.client->post("/agent/registry/approve", "{\"name\":\"projects/test-project/locations/us-central1/agents/a1\"}", "application/json").status == 422,
|
||||
"missing actor is 422");
|
||||
check(contains(f.client->get("/agent/registry/approvals").body, "\"approvals\":[]"),
|
||||
"side effect: nothing recorded after rejected requests");
|
||||
}
|
||||
return finish("agent/registry/approve");
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
// Route: GET /agent/registry/calls (the declared call table)
|
||||
#include "support/GoogleRig.hpp"
|
||||
#include <cstdlib>
|
||||
|
||||
using namespace molo::example::test;
|
||||
using molo::example::fw::Method;
|
||||
|
||||
int main() {
|
||||
GoogleRig rig(false);
|
||||
Fixture f(rig.client);
|
||||
auto res = f.client->get("/agent/registry/calls");
|
||||
check(res.status == 200, "status 200");
|
||||
check(contains(res.headers.get("Content-Type"), "application/json"), "json");
|
||||
check(contains(res.body, "\"id\":\"agentregistry.v1.agents.search\""), "registry search declared");
|
||||
check(contains(res.body, "networkservices.projects.locations.agentGateways.create"), "gateway create declared");
|
||||
check(contains(res.body, "v1alpha/{+parent}/skills"), "alpha skills path declared");
|
||||
check(f.client->post("/agent/registry/calls").status == 405, "post is 405");
|
||||
check(rig.mock->send_count() == 0, "side effect: no upstream traffic");
|
||||
return finish("agent/registry/calls");
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
#pragma once
|
||||
|
||||
// Shared case for the registry route tests (not a test itself). Every route
|
||||
// that would call Google is a POST that must: answer 503 google_not_configured
|
||||
// without a credential, answer 422 validation_error on bad input before any
|
||||
// upstream call, and answer 405 to GET.
|
||||
|
||||
#include <cstdlib>
|
||||
#include <string>
|
||||
|
||||
#include "support/GoogleRig.hpp"
|
||||
|
||||
namespace molo::example::test {
|
||||
|
||||
inline void check_google_post_route(const std::string& path, const std::string& good_body,
|
||||
const std::string& bad_body, const std::string& what) {
|
||||
setenv("GOOGLE_CLOUD_PROJECT", "test-project", 1);
|
||||
const std::string json = "application/json";
|
||||
{
|
||||
GoogleRig rig(false);
|
||||
Fixture f(rig.client);
|
||||
auto res = f.client->post(path, good_body, json);
|
||||
check(res.status == 503, path + ": no credential is 503");
|
||||
check(contains(res.body, "google_not_configured"), "error code google_not_configured");
|
||||
check(contains(res.headers.get("Content-Type"), "application/json"), "error body is json");
|
||||
check(rig.mock->send_count() == 0, "side effect: no upstream traffic");
|
||||
}
|
||||
{
|
||||
GoogleRig rig;
|
||||
Fixture f(rig.client);
|
||||
auto res = f.client->post(path, bad_body, json);
|
||||
check(res.status == 422, path + ": " + what + " is 422");
|
||||
check(contains(res.body, "validation_error"), "error code validation_error");
|
||||
check(rig.mock->send_count() == 0, "side effect: rejected before any upstream call");
|
||||
check(f.client->get(path).status == 405, path + ": get is 405");
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace molo::example::test
|
||||
@@ -0,0 +1,29 @@
|
||||
// Route: DELETE /agent/registry/services/{id} and /gateways/{id} (explicit destructive routes)
|
||||
#include "support/GoogleRig.hpp"
|
||||
#include <cstdlib>
|
||||
|
||||
using namespace molo::example::test;
|
||||
using molo::example::fw::Method;
|
||||
|
||||
int main() {
|
||||
setenv("GOOGLE_CLOUD_PROJECT", "test-project", 1);
|
||||
{
|
||||
GoogleRig rig(false);
|
||||
Fixture f(rig.client);
|
||||
auto res = f.client->request(Method::Delete, "/agent/registry/services/my-service");
|
||||
check(res.status == 503 && contains(res.body, "google_not_configured"), "service delete: 503 without a credential");
|
||||
auto gw = f.client->request(Method::Delete, "/agent/registry/gateways/gw1");
|
||||
check(gw.status == 503 && contains(gw.body, "google_not_configured"), "gateway delete: 503 without a credential");
|
||||
check(rig.mock->send_count() == 0, "no upstream traffic");
|
||||
}
|
||||
{
|
||||
GoogleRig rig;
|
||||
Fixture f(rig.client);
|
||||
check(f.client->request(Method::Delete, "/agent/registry/services/BAD").status == 422, "bad service id is 422");
|
||||
check(f.client->request(Method::Delete, "/agent/registry/gateways/a..b").status == 422, "bad gateway id is 422");
|
||||
check(f.client->get("/agent/registry/services/my-service").status == 405, "get is 405: never deletes by accident");
|
||||
check(f.client->post("/agent/registry/services/my-service").status == 405, "post is 405");
|
||||
check(rig.mock->send_count() == 0, "side effect: rejected before any upstream call");
|
||||
}
|
||||
return finish("agent/registry/delete");
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
// Route: POST /agent/registry/deprecate
|
||||
#include "agent/registry/cases.hpp"
|
||||
|
||||
using namespace molo::example::test;
|
||||
|
||||
int main() {
|
||||
check_google_post_route("/agent/registry/deprecate",
|
||||
"{\"name\":\"projects/test-project/locations/us-central1/agents/a1\",\"actor\":\"alice\"}",
|
||||
"{\"name\":\"projects/test-project/locations/us-central1/agents/a1\",\"actor\":\"a\",\"replaced_by\":\"bad\"}",
|
||||
"bad replaced_by");
|
||||
return finish("agent/registry/deprecate");
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
// Route: POST /agent/registry/gateways/get
|
||||
#include "agent/registry/cases.hpp"
|
||||
|
||||
using namespace molo::example::test;
|
||||
|
||||
int main() {
|
||||
check_google_post_route("/agent/registry/gateways/get",
|
||||
"{\"id\":\"gw1\"}",
|
||||
"{\"id\":\"../x\"}",
|
||||
"bad gateway id");
|
||||
return finish("agent/registry/gateways/get");
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
// Route: POST /agent/registry/gateways/list and /policies/list
|
||||
#include "support/GoogleRig.hpp"
|
||||
#include <cstdlib>
|
||||
|
||||
using namespace molo::example::test;
|
||||
using molo::example::fw::Method;
|
||||
|
||||
int main() {
|
||||
setenv("GOOGLE_CLOUD_PROJECT", "test-project", 1);
|
||||
for (const char* path : {"/agent/registry/gateways/list", "/agent/registry/policies/list"}) {
|
||||
GoogleRig rig(false);
|
||||
Fixture f(rig.client);
|
||||
auto res = f.client->post(path);
|
||||
check(res.status == 503, std::string(path) + ": 503 without a credential");
|
||||
check(contains(res.body, "google_not_configured"), "error code google_not_configured");
|
||||
check(f.client->get(path).status == 405, std::string(path) + ": get is 405");
|
||||
check(rig.mock->send_count() == 0, "no upstream traffic");
|
||||
}
|
||||
{
|
||||
// Credential but no project: loud rejection, still no traffic.
|
||||
unsetenv("GOOGLE_CLOUD_PROJECT");
|
||||
GoogleRig rig;
|
||||
Fixture f(rig.client);
|
||||
auto res = f.client->post("/agent/registry/gateways/list");
|
||||
check(res.status == 422, "limit: a missing project is 422");
|
||||
check(rig.mock->send_count() == 0, "side effect: nothing sent without a project");
|
||||
}
|
||||
return finish("agent/registry/gateways/list");
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
// Route: POST /agent/registry/get
|
||||
#include "agent/registry/cases.hpp"
|
||||
|
||||
using namespace molo::example::test;
|
||||
|
||||
int main() {
|
||||
check_google_post_route("/agent/registry/get",
|
||||
"{\"kind\":\"agents\",\"id\":\"a1\"}",
|
||||
"{\"kind\":\"agents\",\"id\":\"../x\"}",
|
||||
"path traversal id");
|
||||
return finish("agent/registry/get");
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
// Route: POST /agent/registry/identity/audit
|
||||
#include "agent/registry/cases.hpp"
|
||||
|
||||
using namespace molo::example::test;
|
||||
|
||||
int main() {
|
||||
check_google_post_route("/agent/registry/identity/audit",
|
||||
"{\"principal\":\"principal://agents.global.org-1.system.id.goog/aiplatform/e1\"}",
|
||||
"{\"principal\":\"user:a@b.c\"}",
|
||||
"a principal that is not an agent");
|
||||
return finish("agent/registry/identity/audit");
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
// Route: POST /agent/registry/identity
|
||||
#include "agent/registry/cases.hpp"
|
||||
|
||||
using namespace molo::example::test;
|
||||
|
||||
int main() {
|
||||
check_google_post_route("/agent/registry/identity",
|
||||
"{\"engine_id\":\"e1\"}",
|
||||
"{\"engine_id\":\"a/b\"}",
|
||||
"bad engine id");
|
||||
return finish("agent/registry/identity");
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
// Route: POST /agent/registry/list
|
||||
#include "agent/registry/cases.hpp"
|
||||
|
||||
using namespace molo::example::test;
|
||||
|
||||
int main() {
|
||||
check_google_post_route("/agent/registry/list",
|
||||
"{\"kind\":\"agents\"}",
|
||||
"{\"kind\":\"widgets\"}",
|
||||
"unknown collection");
|
||||
{
|
||||
GoogleRig rig;
|
||||
Fixture f(rig.client);
|
||||
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");
|
||||
}
|
||||
return finish("agent/registry/list");
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
// Route: GET /agent/registry (page; never calls Google)
|
||||
#include "support/GoogleRig.hpp"
|
||||
#include <cstdlib>
|
||||
|
||||
using namespace molo::example::test;
|
||||
using molo::example::fw::Method;
|
||||
|
||||
int main() {
|
||||
setenv("GOOGLE_CLOUD_PROJECT", "test-project", 1);
|
||||
GoogleRig rig(false);
|
||||
Fixture f(rig.client);
|
||||
auto res = f.client->get("/agent/registry");
|
||||
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(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");
|
||||
return finish("agent/registry");
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
// Route: POST /agent/registry/identity/principal (local builder, no credential needed)
|
||||
#include "support/GoogleRig.hpp"
|
||||
#include <cstdlib>
|
||||
|
||||
using namespace molo::example::test;
|
||||
using molo::example::fw::Method;
|
||||
|
||||
int main() {
|
||||
const std::string json = "application/json";
|
||||
GoogleRig rig(false);
|
||||
Fixture f(rig.client);
|
||||
auto res = f.client->post("/agent/registry/identity/principal",
|
||||
"{\"org_id\":\"123\",\"project_number\":\"456\",\"agent\":\"engine-1\"}", json);
|
||||
check(res.status == 200, "status 200 without a credential");
|
||||
check(contains(res.body, "principal://agents.global.org-123.system.id.goog/aiplatform/engine-1"), "principal built");
|
||||
check(contains(res.body, "attribute.platformContainer/aiplatform/projects/456"), "project set built");
|
||||
check(contains(res.body, "attribute.platform/aiplatform"), "org set built");
|
||||
check(f.client->post("/agent/registry/identity/principal", "{\"org_id\":\"12x\"}", json).status == 422,
|
||||
"non numeric org is 422");
|
||||
check(f.client->post("/agent/registry/identity/principal", "{\"org_id\":\"1\",\"agent\":\"a/b\"}", json).status == 422,
|
||||
"bad agent name is 422");
|
||||
check(f.client->get("/agent/registry/identity/principal").status == 405, "get is 405");
|
||||
check(rig.mock->send_count() == 0, "side effect: no upstream traffic");
|
||||
return finish("agent/registry/identity/principal");
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
// Route: POST /agent/registry/reject
|
||||
#include "agent/registry/cases.hpp"
|
||||
|
||||
using namespace molo::example::test;
|
||||
|
||||
int main() {
|
||||
check_google_post_route("/agent/registry/reject",
|
||||
"{\"name\":\"projects/test-project/locations/us-central1/agents/a1\",\"actor\":\"alice\"}",
|
||||
"{\"name\":\"projects/test-project/locations/us-central1/agents/a1\"}",
|
||||
"missing actor");
|
||||
return finish("agent/registry/reject");
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
// Route: POST /agent/registry/search
|
||||
#include "agent/registry/cases.hpp"
|
||||
|
||||
using namespace molo::example::test;
|
||||
|
||||
int main() {
|
||||
check_google_post_route("/agent/registry/search",
|
||||
"{\"kind\":\"agents\",\"q\":\"billing\"}",
|
||||
"{\"kind\":\"endpoints\",\"q\":\"x\"}",
|
||||
"search on endpoints");
|
||||
{
|
||||
GoogleRig rig;
|
||||
Fixture f(rig.client);
|
||||
std::string long_q(600, 'x');
|
||||
check(f.client->post("/agent/registry/search", "{\"kind\":\"agents\",\"q\":\"" + long_q + "\"}", "application/json").status == 422,
|
||||
"limit: query over 512 chars is 422");
|
||||
}
|
||||
return finish("agent/registry/search");
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
// Route: POST /agent/registry/skills/state
|
||||
#include "agent/registry/cases.hpp"
|
||||
|
||||
using namespace molo::example::test;
|
||||
|
||||
int main() {
|
||||
check_google_post_route("/agent/registry/skills/state",
|
||||
"{\"id\":\"s1\",\"state\":\"active\"}",
|
||||
"{\"id\":\"s1\",\"state\":\"retired\"}",
|
||||
"unknown state");
|
||||
return finish("agent/registry/skills/state");
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
// Route: GET /agent/registry/status
|
||||
#include "support/GoogleRig.hpp"
|
||||
#include <cstdlib>
|
||||
|
||||
using namespace molo::example::test;
|
||||
using molo::example::fw::Method;
|
||||
|
||||
int main() {
|
||||
setenv("GOOGLE_CLOUD_PROJECT", "test-project", 1);
|
||||
{
|
||||
GoogleRig rig(false);
|
||||
Fixture f(rig.client);
|
||||
auto res = f.client->get("/agent/registry/status");
|
||||
check(res.status == 200, "status 200 without a credential");
|
||||
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(rig.mock->send_count() == 0, "side effect: no upstream traffic");
|
||||
}
|
||||
{
|
||||
GoogleRig rig;
|
||||
Fixture f(rig.client);
|
||||
auto res = f.client->get("/agent/registry/status");
|
||||
check(contains(res.body, "\"configured\":true"), "configured with a credential");
|
||||
check(!contains(res.body, kTestKey), "credential never shown");
|
||||
check(f.client->post("/agent/registry/status").status == 405, "post is 405");
|
||||
}
|
||||
return finish("agent/registry/status");
|
||||
}
|
||||
Reference in New Issue
Block a user