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");
}
@@ -0,0 +1,18 @@
// Route: GET /google/workspace (page, no credential needed)
#include "support/GoogleRig.hpp"
using namespace molo::example::test;
int main() {
GoogleRig rig(false);
Fixture f(rig.client);
auto res = f.client->get("/google/workspace");
check(res.status == 200, "status 200");
check(contains(res.headers.get("Content-Type"), "text/html"), "html");
check(contains(res.body, "Google Workspace") && contains(res.body, "viewport"), "page and mobile viewport");
check(contains(res.body, "/embedded/google_workspace.js"), "script wired");
check(contains(res.body, "<select"), "dropdowns, not a button wall");
check(f.client->post("/google/workspace", "{}", "application/json").status == 405, "post is 405");
check(rig.mock->send_count() == 0, "no network");
return finish("google/workspace");
}
@@ -0,0 +1,34 @@
// Routes: GET /google/workspace/{status,apis,calls,scopes}
#include "support/GoogleRig.hpp"
using namespace molo::example::test;
int main() {
GoogleRig rig(false);
Fixture f(rig.client);
auto st = f.client->get("/google/workspace/status");
check(st.status == 200 && contains(st.body, "\"configured\":false"), "status without credential");
check(contains(st.body, "\"apis\":20"), "twenty apis");
auto apis = f.client->get("/google/workspace/apis");
check(apis.status == 200 && contains(apis.body, "\"name\":\"gmail\"") &&
contains(apis.body, "\"name\":\"vault\"") && contains(apis.body, "\"name\":\"directory\""),
"apis listed");
check(contains(apis.body, "gmail.googleapis.com"), "service to enable shown");
auto calls = f.client->get("/google/workspace/calls?api=gmail&kind=s");
check(calls.status == 200 && contains(calls.body, "gmail.users.messages.send") &&
!contains(calls.body, "gmail.users.messages.list"),
"calls filtered by api and kind");
check(f.client->get("/google/workspace/calls?api=nope").status == 422, "unknown api is 422");
check(f.client->get("/google/workspace/calls?kind=x").status == 422, "unknown kind is 422");
auto all = f.client->get("/google/workspace/calls");
check(all.status == 200 && contains(all.body, "\"truncated\":true"), "unfiltered listing is capped");
auto scopes = f.client->get("/google/workspace/scopes?apis=gmail,drive&readonly=true");
check(scopes.status == 200 && contains(scopes.body, "gmail.readonly") && contains(scopes.body, "drive.readonly"),
"readonly scopes");
check(!contains(scopes.body, "auth/gmail.send"), "no write scope in the readonly set");
check(f.client->get("/google/workspace/scopes").status == 422, "apis required");
check(f.client->get("/google/workspace/scopes?apis=gmail&readonly=maybe").status == 422, "readonly must be a bool");
check(f.client->post("/google/workspace/status", "{}", "application/json").status == 405, "post is 405");
check(rig.mock->send_count() == 0, "no network");
return finish("google/workspace/status");
}