// Routes: DELETE /google/maps/streetview/photo/{id} (destructive: dry run // unless ?confirm=true) and POST /google/maps/keys/lint (local, no credential). #include "support/GoogleRig.hpp" using namespace molo::example::test; using molo::example::fw::Method; int main() { const std::string json = "application/json"; { GoogleRig rig(false); Fixture f(rig.client); auto res = f.client->request(Method::Delete, "/google/maps/streetview/photo/p1"); check(res.status == 503 && contains(res.body, "google_not_configured"), "delete without credential is 503"); check(rig.mock->send_count() == 0, "side effect: nothing sent"); } { GoogleRig rig; Fixture f(rig.client); auto res = f.client->request(Method::Delete, "/google/maps/streetview/photo/p1"); check(res.status == 200 && contains(res.body, "\"dry_run\":true"), "delete is a dry run by default"); check(contains(res.body, "\"method\":\"DELETE\"") && contains(res.body, "/v1/photo/p1"), "dry run shows the DELETE request"); check(rig.mock->send_count() == 0, "side effect: the dry run deleted nothing"); check(f.client->request(Method::Delete, "/google/maps/streetview/photo/a..b%2Fc").status != 200 || rig.mock->send_count() == 0, "odd ids never reach Google"); check(f.client->get("/google/maps/streetview/photo/p1").status == 405, "get is 405"); } { GoogleRig rig(false); Fixture f(rig.client); auto open = f.client->post("/google/maps/keys/lint", "{}", json); check(open.status == 200, "lint works without a credential"); check(contains(open.body, "\"scope\":\"local\""), "lint is local"); check(contains(open.body, "no application restriction") && contains(open.body, "no API restriction"), "an unrestricted key is reported"); auto good = f.client->post("/google/maps/keys/lint", "{\"referrers\":\"https://*.example.com/*\",\"apis\":\"places.googleapis.com\"}", json); check(good.status == 200 && contains(good.body, "\"findings\":[]"), "a restricted key has no findings"); check(contains(good.body, "allowedReferrers") && contains(good.body, "apiTargets"), "restrictions rendered"); auto both = f.client->post("/google/maps/keys/lint", "{\"referrers\":\"https://a.com/*\",\"ips\":\"1.2.3.4\"}", json); check(both.status == 422, "two application restriction kinds are 422"); check(f.client->get("/google/maps/keys/lint").status == 405, "get is 405"); } return finish("google/maps/delete_and_keys"); }