feat(clients): maps: Places, Address Validation, Solar, Pollen, Air Quality, Area Insights, Routes, web services, Street View, key handling
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,77 @@
|
||||
// Routes: every POST that would call Google Maps. No credential is 503
|
||||
// google_not_configured, bad input is 422 before any traffic, GET is 405, and
|
||||
// with a credential but no confirm the answer is a dry run that shows the
|
||||
// exact request and sends nothing.
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "support/GoogleRig.hpp"
|
||||
|
||||
using namespace molo::example::test;
|
||||
|
||||
namespace {
|
||||
struct Case {
|
||||
std::string path;
|
||||
std::string good;
|
||||
std::string bad;
|
||||
std::string expect_in_request; // proof of the exact request shape
|
||||
};
|
||||
} // namespace
|
||||
|
||||
int main() {
|
||||
const std::string json = "application/json";
|
||||
const std::vector<Case> cases = {
|
||||
{"/google/maps/places/search", "{\"query\":\"pizza\",\"limit\":\"3\"}", "{\"query\":\"\"}",
|
||||
"/v1/places:searchText?fields=places.id"},
|
||||
{"/google/maps/places/nearby", "{\"lat\":\"52.37\",\"lng\":\"4.89\",\"radius\":\"300\",\"type\":\"cafe\"}",
|
||||
"{\"lat\":\"99\",\"lng\":\"4.89\"}", "/v1/places:searchNearby"},
|
||||
{"/google/maps/places/autocomplete", "{\"input\":\"Dam\"}", "{}", "/v1/places:autocomplete"},
|
||||
{"/google/maps/places/details", "{\"place_id\":\"ChIJabc\"}", "{\"place_id\":\"a/../b\"}",
|
||||
"/v1/places/ChIJabc?fields="},
|
||||
{"/google/maps/address/validate", "{\"region\":\"NL\",\"lines\":\"Dam 1\"}", "{\"region\":\"NL\"}",
|
||||
"/v1:validateAddress"},
|
||||
{"/google/maps/solar", "{\"lat\":\"52.37\",\"lng\":\"4.89\"}", "{\"lat\":\"x\",\"lng\":\"4\"}",
|
||||
"/v1/buildingInsights:findClosest?location.latitude=52.37"},
|
||||
{"/google/maps/pollen", "{\"lat\":\"52.37\",\"lng\":\"4.89\",\"days\":\"2\"}",
|
||||
"{\"lat\":\"52.37\",\"lng\":\"4.89\",\"days\":\"9\"}", "/v1/forecast:lookup?"},
|
||||
{"/google/maps/air", "{\"lat\":\"52.37\",\"lng\":\"4.89\"}", "{\"lat\":\"52.37\"}",
|
||||
"/v1/currentConditions:lookup"},
|
||||
{"/google/maps/area", "{\"lat\":\"52.37\",\"lng\":\"4.89\",\"radius\":\"500\"}",
|
||||
"{\"lat\":\"52.37\",\"lng\":\"4.89\",\"radius\":\"0\"}", "/v1:computeInsights"},
|
||||
{"/google/maps/routes", "{\"origin\":\"52.37,4.89\",\"destination\":\"Utrecht Centraal\"}",
|
||||
"{\"origin\":\"52.37,4.89\"}", "/directions/v2:computeRoutes?fields=routes.duration"},
|
||||
{"/google/maps/geocode", "{\"address\":\"Dam 1 Amsterdam\"}", "{\"lat\":\"1\"}",
|
||||
"/maps/api/geocode/json?address=Dam%201%20Amsterdam"},
|
||||
{"/google/maps/timezone", "{\"lat\":\"52.37\",\"lng\":\"4.89\",\"timestamp\":\"1700000000\"}",
|
||||
"{\"lat\":\"52.37\",\"lng\":\"4.89\"}", "/maps/api/timezone/json?location=52.3700000"},
|
||||
{"/google/maps/elevation", "{\"locations\":\"52.37,4.89|52.38,4.90\"}", "{\"locations\":\"nope\"}",
|
||||
"/maps/api/elevation/json?locations=52.3700000"},
|
||||
{"/google/maps/streetview/list", "{\"limit\":\"2\"}", "{\"limit\":\"500\"}", "/v1/photos?pageSize=2"},
|
||||
};
|
||||
for (const Case& c : cases) {
|
||||
{
|
||||
GoogleRig rig(false);
|
||||
Fixture f(rig.client);
|
||||
auto res = f.client->post(c.path, c.good, json);
|
||||
check(res.status == 503, c.path + ": no credential is 503");
|
||||
check(contains(res.body, "google_not_configured"), c.path + ": error code google_not_configured");
|
||||
check(contains(res.headers.get("Content-Type"), "application/json"), c.path + ": error body is json");
|
||||
check(rig.mock->send_count() == 0, c.path + ": nothing sent without a credential");
|
||||
}
|
||||
{
|
||||
GoogleRig rig;
|
||||
Fixture f(rig.client);
|
||||
auto bad = f.client->post(c.path, c.bad, json);
|
||||
check(bad.status == 422, c.path + ": bad input is 422");
|
||||
check(contains(bad.body, "validation_error"), c.path + ": error code validation_error");
|
||||
check(f.client->get(c.path).status == 405, c.path + ": get is 405");
|
||||
auto dry = f.client->post(c.path, c.good, json);
|
||||
check(dry.status == 200, c.path + ": dry run is 200");
|
||||
check(contains(dry.body, "\"dry_run\":true"), c.path + ": answer says dry run");
|
||||
check(contains(dry.body, c.expect_in_request), c.path + ": exact request shown (" + c.expect_in_request + ")");
|
||||
check(!contains(dry.body, kTestKey), c.path + ": credential never shown");
|
||||
check(rig.mock->send_count() == 0, c.path + ": side effect: a dry run sends nothing");
|
||||
}
|
||||
}
|
||||
return finish("google/maps/calls");
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
// 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");
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
// Route: GET /google/maps, /google/maps/status, /google/maps/calls (never call Google)
|
||||
#include "support/GoogleRig.hpp"
|
||||
|
||||
using namespace molo::example::test;
|
||||
|
||||
int main() {
|
||||
{
|
||||
GoogleRig rig;
|
||||
Fixture f(rig.client);
|
||||
auto page = f.client->get("/google/maps");
|
||||
check(page.status == 200, "page is 200");
|
||||
check(contains(page.headers.get("Content-Type"), "text/html"), "page is html");
|
||||
check(contains(page.body, "viewport") || contains(page.body, "Google Maps Platform"), "page renders");
|
||||
check(contains(page.body, "/embedded/google_maps.js"), "page loads its script");
|
||||
|
||||
auto st = f.client->get("/google/maps/status");
|
||||
check(st.status == 200, "status is 200");
|
||||
check(contains(st.headers.get("Content-Type"), "application/json"), "status is json");
|
||||
check(contains(st.body, "\"configured\":true"), "configured with a key");
|
||||
check(contains(st.body, "\"max_points\":512"), "caps shown");
|
||||
check(!contains(st.body, kTestKey), "credential never shown");
|
||||
|
||||
auto calls = f.client->get("/google/maps/calls");
|
||||
check(calls.status == 200, "calls is 200");
|
||||
check(contains(calls.body, "places.places.searchText"), "places search declared");
|
||||
check(contains(calls.body, "\"source\":\"reference\""), "reference rows are marked");
|
||||
check(contains(calls.body, "directions/v2:computeRoutes"), "routes declared");
|
||||
check(!contains(calls.body, kTestKey), "no credential in the table");
|
||||
|
||||
check(f.client->post("/google/maps").status == 405, "page post is 405");
|
||||
check(f.client->post("/google/maps/status").status == 405, "status post is 405");
|
||||
check(f.client->post("/google/maps/calls").status == 405, "calls post is 405");
|
||||
check(rig.mock->send_count() == 0, "side effect: no upstream traffic");
|
||||
}
|
||||
{
|
||||
GoogleRig rig(false);
|
||||
Fixture f(rig.client);
|
||||
check(contains(f.client->get("/google/maps/status").body, "\"configured\":false"),
|
||||
"not configured without a key");
|
||||
check(f.client->get("/google/maps").status == 200, "page works without a credential");
|
||||
}
|
||||
return finish("google/maps/status");
|
||||
}
|
||||
Reference in New Issue
Block a user