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