// Routes: every /agent/sandbox/* route that would call Google answers 503 // google_not_configured without a credential, before any network traffic. #include #include "support/GoogleRig.hpp" using namespace molo::example::test; int main() { setenv("GOOGLE_CLOUD_PROJECT", "test-project", 1); const std::string engine = "projects/test-project/locations/us-central1/reasoningEngines/1"; const std::string sandbox = engine + "/sandboxEnvironments/2"; GoogleRig rig(false); Fixture f(rig.client); struct Case { const char* route; std::string body; }; const Case cases[] = { {"/agent/sandbox/create", "{\"engine\":\"" + engine + "\",\"display_name\":\"d\"}"}, {"/agent/sandbox/list", "{\"engine\":\"" + engine + "\"}"}, {"/agent/sandbox/get", "{\"name\":\"" + sandbox + "\"}"}, {"/agent/sandbox/pause", "{\"name\":\"" + sandbox + "\"}"}, {"/agent/sandbox/resume", "{\"name\":\"" + sandbox + "\"}"}, {"/agent/sandbox/snapshot", "{\"name\":\"" + sandbox + "\",\"display_name\":\"s\"}"}, {"/agent/sandbox/snapshots", "{\"engine\":\"" + engine + "\"}"}, {"/agent/sandbox/templates", "{\"engine\":\"" + engine + "\"}"}, {"/agent/sandbox/execute", "{\"name\":\"" + sandbox + "\",\"code\":\"print(1)\\nprint(2)\"}"}, {"/agent/sandbox/shell", "{\"name\":\"" + sandbox + "\",\"command\":\"echo hi\"}"}, {"/agent/sandbox/computer", "{\"name\":\"" + sandbox + "\",\"action\":\"navigate\",\"url\":\"https://example.com\"}"}, {"/agent/sandbox/files", "{\"name\":\"" + sandbox + "\",\"op\":\"list\"}"}, {"/agent/sandbox/dataplane", "{\"name\":\"" + sandbox + "\",\"action\":\"health\"}"}, {"/agent/sandbox/dataplane", "{\"name\":\"" + sandbox + "\",\"action\":\"command\",\"command\":\"Page.reload\"}"}, {"/agent/sandbox/cdp", "{\"name\":\"" + sandbox + "\",\"method\":\"Page.reload\"}"}, {"/agent/sandbox/stream", "{\"name\":\"" + sandbox + "\",\"mode\":\"shell\",\"input\":\"echo hi\"}"}, {"/agent/sandbox/stream", "{\"name\":\"" + sandbox + "\",\"mode\":\"code\",\"input\":\"print(1)\"}"}, {"/agent/sandbox/operations", "{\"name\":\"" + sandbox + "/operations/1\",\"op\":\"get\"}"}, {"/agent/sandbox/operations", "{\"name\":\"" + sandbox + "/operations/1\",\"op\":\"wait\",\"timeout\":\"5\"}"}, {"/agent/sandbox/operations", "{\"name\":\"" + sandbox + "\",\"op\":\"list\"}"}, {"/agent/sandbox/operations", "{\"name\":\"" + sandbox + "/operations/1\",\"op\":\"cancel\"}"}, {"/agent/sandbox/resource", "{\"name\":\"" + engine + "/sandboxEnvironmentTemplates/7\",\"kind\":\"template\"}"}, {"/agent/sandbox/resource", "{\"name\":\"" + engine + "/sandboxEnvironmentSnapshots/8\",\"kind\":\"snapshot\"}"}, {"/agent/sandbox/template", "{\"engine\":\"" + engine + "\",\"display_name\":\"t\",\"category\":\"computer\"}"}, }; for (const Case& c : cases) { auto res = f.client->post(c.route, c.body, "application/json"); check(res.status == 503, std::string(c.route) + " answers 503"); check(contains(res.body, "google_not_configured"), std::string(c.route) + " names the error"); } auto del = f.client->request(molo::example::fw::Method::Delete, "/agent/sandbox/delete?name=" + sandbox); check(del.status == 503, "delete answers 503 without a credential"); auto del_op = f.client->request(molo::example::fw::Method::Delete, "/agent/sandbox/operation?name=" + sandbox + "/operations/1"); check(del_op.status == 503 && contains(del_op.body, "google_not_configured"), "operation delete answers 503 without a credential"); auto del_res = f.client->request( molo::example::fw::Method::Delete, "/agent/sandbox/resource?kind=template&name=" + engine + "/sandboxEnvironmentTemplates/7"); check(del_res.status == 503 && contains(del_res.body, "google_not_configured"), "template delete answers 503 without a credential"); check(contains(del.body, "google_not_configured"), "delete names the error"); check(rig.mock->send_count() == 0, "side effect: no upstream traffic"); return finish("agent/sandbox/not_configured"); }