1080-row Discovery-derived call table, validating Caller, typed facades, demo under /google/enterprise, Discovery checker, live read checks. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
52 lines
2.8 KiB
C++
52 lines
2.8 KiB
C++
// Route: POST /google/enterprise/call (any row of the table)
|
|
#include "google/enterprise/cases.hpp"
|
|
|
|
using namespace molo::example::test;
|
|
|
|
int main() {
|
|
const std::string get_ds =
|
|
"{\"api\":\"discoveryengine\",\"rpc\":\"discoveryengine.projects.locations.collections.dataStores.get\","
|
|
"\"path\":{\"name\":\"projects/p1/locations/global/collections/default_collection/dataStores/ds1\"}}";
|
|
check_enterprise_post_route("/google/enterprise/call", get_ds,
|
|
"{\"api\":\"discoveryengine\",\"rpc\":\"nope\",\"path\":{}}", "unknown rpc");
|
|
{
|
|
GoogleRig rig;
|
|
Fixture f(rig.client);
|
|
const std::string j = "application/json";
|
|
const std::string list = "\"rpc\":\"retail.projects.locations.catalogs.list\"";
|
|
check(f.client->post("/google/enterprise/call", "not json", j).status == 422, "bad json");
|
|
check(f.client->post("/google/enterprise/call", "[1]", j).status == 422, "array body");
|
|
check(f.client->post("/google/enterprise/call", "{\"rpc\":\"x\"}", j).status == 422, "api required");
|
|
check(f.client->post("/google/enterprise/call", "{\"api\":\"x\",\"rpc\":\"y\"}", j).status == 422, "unknown api");
|
|
check(f.client->post("/google/enterprise/call",
|
|
"{\"api\":\"retail\"," + list + ",\"path\":{\"parent\":\"../x\"}}", j).status == 422,
|
|
"path traversal");
|
|
check(f.client->post("/google/enterprise/call",
|
|
"{\"api\":\"retail\"," + list +
|
|
",\"path\":{\"parent\":\"projects/p/locations/global\"},\"query\":{\"bogus\":\"1\"}}",
|
|
j).status == 422,
|
|
"unknown query parameter");
|
|
check(f.client->post("/google/enterprise/call", std::string("{\"x\":\"") + std::string(300 * 1024, 'a') + "\"}", j)
|
|
.status == 413,
|
|
"oversize body is 413");
|
|
check(rig.mock->send_count() == 0, "side effect: nothing sent");
|
|
}
|
|
check_enterprise_dry_run(
|
|
"/google/enterprise/call",
|
|
"{\"api\":\"discoveryengine\",\"rpc\":\"discoveryengine.projects.locations.collections.dataStores.delete\","
|
|
"\"path\":{\"name\":\"projects/p1/locations/global/collections/default_collection/dataStores/ds1\"}}",
|
|
"dataStores/ds1");
|
|
{
|
|
// A read attempts exactly one upstream request, to the table-derived URL.
|
|
GoogleRig rig;
|
|
Fixture f(rig.client);
|
|
auto res = f.client->post("/google/enterprise/call", get_ds, "application/json");
|
|
check(res.status != 422 && res.status != 503, "a read gets past validation and credential");
|
|
auto seen = rig.mock->seen();
|
|
check(seen.size() == 1 && seen[0].method == "GET" &&
|
|
contains(seen[0].target, "/v1/projects/p1/locations/global/collections/default_collection/dataStores/ds1"),
|
|
"one GET to the table-derived path");
|
|
}
|
|
return finish("google/enterprise/call");
|
|
}
|