fix - carto now requires api keys
All checks were successful
Release / tag (push) Successful in 2s
Release / build-and-release (push) Successful in 13s

This commit is contained in:
mr0xb 2026-08-26 22:41:52 -04:00
commit 3a3307e190
9 changed files with 100 additions and 6 deletions

View file

@ -624,3 +624,56 @@ func TestGenerateHTML_DayTitleInHeader(t *testing.T) {
t.Error("expected DayTitle in report HTML")
}
}
// ── map API key ────────────────────────────────────────────────────────────
func TestTileURLWithKey(t *testing.T) {
cases := []struct{ url, key, want string }{
{"https://basemaps.cartocdn.com/rastertiles/voyager/{z}/{x}/{y}.png", "XYZ",
"https://basemaps.cartocdn.com/rastertiles/voyager/{z}/{x}/{y}.png?key=XYZ"},
{"https://tiles.example/{z}/{x}/{y}.png?style=dark", "XYZ",
"https://tiles.example/{z}/{x}/{y}.png?style=dark&key=XYZ"},
{"https://tiles.example/{z}/{x}/{y}.png", "a b&c",
"https://tiles.example/{z}/{x}/{y}.png?key=a+b%26c"},
{"https://tiles.example/{z}/{x}/{y}.png", "",
"https://tiles.example/{z}/{x}/{y}.png"},
}
for _, c := range cases {
if got := tileURLWithKey(c.url, c.key); got != c.want {
t.Errorf("tileURLWithKey(%q, %q) = %q, want %q", c.url, c.key, got, c.want)
}
}
}
func TestGenerateHTML_MapAPIKeyInTileURL(t *testing.T) {
data := makeTestData()
ComputeStats(&data)
data.GeoLocations = []GeoPoint{
{IP: "1.1.1.1", Lat: 37.751, Lon: -97.822, Country: "United States", CountryCode: "US", Count: 2},
}
data.MapAPIKey = "secret-key"
html, err := GenerateHTML(data)
if err != nil {
t.Fatalf("GenerateHTML error: %v", err)
}
if !strings.Contains(html, "?key=secret-key") {
t.Error("expected map API key appended to the tile URL")
}
}
func TestGenerateHTML_NoMapAPIKeyLeavesTileURL(t *testing.T) {
data := makeTestData()
ComputeStats(&data)
data.GeoLocations = []GeoPoint{
{IP: "1.1.1.1", Lat: 37.751, Lon: -97.822, Country: "United States", CountryCode: "US", Count: 2},
}
html, err := GenerateHTML(data)
if err != nil {
t.Fatalf("GenerateHTML error: %v", err)
}
if strings.Contains(html, "key=") {
t.Error("did not expect a key query parameter when MapAPIKey is empty")
}
}