feat(clients): workspace: 20 Workspace APIs from Discovery, delegation sub claim, demo

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-25 15:03:45 +01:00
co-authored by Claude Sonnet 5.5
parent 3db67fcf1f
commit 54b564f9b9
24 changed files with 3949 additions and 3 deletions
@@ -0,0 +1,62 @@
// Routes: POST /google/workspace/call, /list, /delegation
// Reads: 422 on bad input, 503 google_not_configured without a credential.
// Writes, deletes and sends: dry run unless confirm:true. Nothing reaches Google.
#include "support/GoogleRig.hpp"
using namespace molo::example::test;
int main() {
GoogleRig rig(false);
Fixture f(rig.client);
const char* json = "application/json";
auto post = [&](const char* path, const std::string& body) { return f.client->post(path, body, json); };
auto read = post("/google/workspace/call", "{\"api\":\"gmail\",\"id\":\"gmail.users.getProfile\",\"params\":{\"userId\":\"me\"}}");
check(read.status == 503 && contains(read.body, "google_not_configured"), "valid read without credential is 503");
check(post("/google/workspace/call", "{}").status == 422, "api and id required");
check(post("/google/workspace/call", "{\"api\":\"nope\",\"id\":\"x\"}").status == 422, "unknown api is 422");
check(post("/google/workspace/call", "{\"api\":\"gmail\",\"id\":\"drive.files.list\"}").status == 422, "id of another api is 422");
check(post("/google/workspace/call", "{\"api\":\"gmail\",\"id\":\"gmail.users.getProfile\",\"params\":{}}").status == 422, "missing path param is 422");
check(post("/google/workspace/call", "{\"api\":\"gmail\",\"id\":\"gmail.users.getProfile\",\"params\":{\"userId\":\"me\",\"x\":1}}").status == 422, "unknown param is 422");
check(post("/google/workspace/call", "{\"api\":\"gmail\",\"id\":\"gmail.users.getProfile\",\"params\":[]}").status == 422, "params must be an object");
check(post("/google/workspace/call", "{\"api\":\"gmail\",\"id\":\"gmail.users.getProfile\",\"params\":{\"userId\":\"me\"},\"confirm\":\"yes\"}").status == 422, "confirm must be a bool");
check(post("/google/workspace/call", "not json").status == 422, "bad json is 422");
check(post("/google/workspace/call", "{\"api\":\"drive\",\"id\":\"drive.files.export\",\"params\":{\"fileId\":\"1\",\"mimeType\":\"text/plain\"}}").status == 422, "bytes responses are refused");
// sends, writes and deletes are dry runs by default, even without a credential
auto send = post("/google/workspace/call", "{\"api\":\"gmail\",\"id\":\"gmail.users.messages.send\",\"params\":{\"userId\":\"me\"},\"body\":{\"raw\":\"AAAA\"}}");
check(send.status == 200 && contains(send.body, "\"dry_run\":true") && contains(send.body, "\"kind\":\"send\"") &&
contains(send.body, "/gmail/v1/users/me/messages/send"),
"send is a dry run");
auto del = post("/google/workspace/call", "{\"api\":\"drive\",\"id\":\"drive.files.delete\",\"params\":{\"fileId\":\"abc\"}}");
check(del.status == 200 && contains(del.body, "\"dry_run\":true") && contains(del.body, "\"kind\":\"destroy\""), "delete is a dry run");
auto wr = post("/google/workspace/call", "{\"api\":\"sheets\",\"id\":\"sheets.spreadsheets.values.update\",\"params\":{\"spreadsheetId\":\"s\",\"range\":\"A1\",\"valueInputOption\":\"RAW\"},\"body\":{\"values\":[[1]]}}");
check(wr.status == 200 && contains(wr.body, "\"kind\":\"write\""), "write is a dry run");
check(post("/google/workspace/call", "{\"api\":\"gmail\",\"id\":\"gmail.users.messages.send\",\"params\":{\"userId\":\"me\"},\"body\":{\"nonsense\":1}}").status == 422, "unknown body field is 422 even for a dry run");
auto confirmed = post("/google/workspace/call", "{\"api\":\"gmail\",\"id\":\"gmail.users.messages.send\",\"params\":{\"userId\":\"me\"},\"body\":{\"raw\":\"AAAA\"},\"confirm\":true}");
check(confirmed.status == 503 && contains(confirmed.body, "google_not_configured"), "confirmed send without credential is 503");
// list
check(post("/google/workspace/list", "{\"api\":\"drive\",\"id\":\"drive.files.list\"}").status == 503, "list without credential is 503");
check(post("/google/workspace/list", "{\"api\":\"drive\",\"id\":\"drive.files.list\",\"maxPages\":9}").status == 422, "maxPages over 5 is 422");
check(post("/google/workspace/list", "{\"api\":\"gmail\",\"id\":\"gmail.users.getProfile\",\"params\":{\"userId\":\"me\"}}").status == 422, "no items array is 422");
check(post("/google/workspace/list", "{\"api\":\"gmail\",\"id\":\"gmail.users.messages.send\",\"params\":{\"userId\":\"me\"}}").status == 422, "list of a send is 422");
// delegation: local validation only
auto del_ok = post("/google/workspace/delegation", "{\"subject\":\"admin@example.com\",\"apis\":\"gmail,drive\"}");
check(del_ok.status == 200 && contains(del_ok.body, "\"impersonating\":true") && contains(del_ok.body, "gmail.readonly"), "delegation preview");
check(post("/google/workspace/delegation", "{\"subject\":\"not-an-email\",\"apis\":\"gmail\"}").status == 422, "bad subject is 422");
check(post("/google/workspace/delegation", "{\"apis\":\"nope\"}").status == 422, "unknown api is 422");
check(post("/google/workspace/delegation", "{}").status == 422, "apis required");
check(f.client->get("/google/workspace/call").status == 405, "get is 405");
check(f.client->get("/google/workspace/list").status == 405, "get list is 405");
check(rig.mock->send_count() == 0, "nothing reached Google");
// environment-built client (no injection): same contract
Fixture g;
auto env_read = g.client->post("/google/workspace/call", "{\"api\":\"calendar\",\"id\":\"calendar.calendarList.list\"}", json);
check(env_read.status == 503 && contains(env_read.body, "google_not_configured"), "env client without credential is 503");
return finish("google/workspace/call");
}