mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-01 08:53:13 +00:00
fix(maps): let users and admins enter a CARTO API key (#2060)
CARTO stamps an "API KEY REQUIRED" watermark onto every basemap tile fetched without a key since 26.08.2026, and both CartoDB presets plus the built-in fallback are CARTO. The key is free and needs no account, so add it as a setting rather than dropping the provider. carto_api_key sits next to mapbox_access_token: per user in Settings/Map, instance-wide under Admin/User Defaults, encrypted at rest, injected from CARTO_API_KEY on managed instances. Unlike Mapbox it never switches the map provider, since a raster key says nothing about the renderer. The key is appended as ?key= at render time instead of being stored in the template, so a saved URL stays portable and survives a rotation. That is also what reaches the four maps that pinned CARTO and ignored the user's tile setting: atlas, collections, the public trip share and the public journey. The two share pages read it from their token-gated payload, the same way baseCurrency already travels. Also lifts the release notice above page chrome. Its overlay sat at z-index 50, under the Vacay mode toolbar at 61, so the dialog was neither on top nor modal. Adds a six-step layer scale to index.css and moves the three notice shells onto it. Closes #2054 Closes #2052
This commit is contained in:
@@ -60,6 +60,22 @@ describe('globalMiddleware request-log redaction', () => {
|
||||
expect(out.grant_type).toBe('refresh_token');
|
||||
});
|
||||
|
||||
it('redacts the value of a {key, value} settings body when the key names a secret', () => {
|
||||
expect(redact({ key: 'carto_api_key', value: 'carto-secret' })).toEqual({
|
||||
key: 'carto_api_key',
|
||||
value: '[REDACTED]',
|
||||
});
|
||||
expect(redact({ key: 'mapbox_access_token', value: 'pk-1' })).toEqual({
|
||||
key: 'mapbox_access_token',
|
||||
value: '[REDACTED]',
|
||||
});
|
||||
// A harmless setting keeps its value: the name is what decides.
|
||||
expect(redact({ key: 'map_tile_url', value: 'https://tiles.example/{z}/{x}/{y}.png' })).toEqual({
|
||||
key: 'map_tile_url',
|
||||
value: 'https://tiles.example/{z}/{x}/{y}.png',
|
||||
});
|
||||
});
|
||||
|
||||
it('matches the suffix on the end of the key only, so identifiers stay readable', () => {
|
||||
expect(redact({ accessKeyId: 'ak-1', tokenCount: 5 })).toEqual({ accessKeyId: 'ak-1', tokenCount: 5 });
|
||||
});
|
||||
|
||||
@@ -39,10 +39,15 @@ import { RealtimeService } from '../../../src/nest/realtime/realtime.service';
|
||||
import { TrekPhotosRepository } from '../../../src/nest/photos/trek-photos.repository';
|
||||
import { JourneyDomainService } from '../../../src/nest/journey/journey-domain.service';
|
||||
import { JourneyShareService } from '../../../src/nest/journey/journey-share.service';
|
||||
import { SettingsService } from '../../../src/nest/settings/settings.service';
|
||||
import { db as dbConn } from '../../../src/db/database';
|
||||
|
||||
const dbs = new DatabaseService(dbConn);
|
||||
const svc = new JourneyShareService(dbs, new JourneyDomainService(dbs, new RealtimeService(), new TrekPhotosRepository(dbs)));
|
||||
const svc = new JourneyShareService(
|
||||
dbs,
|
||||
new JourneyDomainService(dbs, new RealtimeService(), new TrekPhotosRepository(dbs)),
|
||||
new SettingsService(dbs),
|
||||
);
|
||||
|
||||
beforeAll(() => {
|
||||
createTables(testDb);
|
||||
@@ -629,4 +634,16 @@ describe('getPublicJourney', () => {
|
||||
expect(result.entries).toHaveLength(1);
|
||||
expect((result.entries[0] as Record<string, unknown>).photos).toEqual([]); // inline photos withheld too
|
||||
});
|
||||
|
||||
it('JOURNEY-SHARE-030: cartoApiKey resolves owner setting → admin instance default → empty (#2054)', () => {
|
||||
const { user } = createUser(testDb);
|
||||
const journey = createJourney(testDb, user.id);
|
||||
const { token } = svc.createOrUpdateJourneyShareLink(journey.id, user.id, { share_map: true });
|
||||
|
||||
expect(svc.getPublicJourney(token)!.cartoApiKey).toBe('');
|
||||
testDb.prepare("INSERT INTO app_settings (key, value) VALUES ('default_user_setting_carto_api_key', 'instance-key')").run();
|
||||
expect(svc.getPublicJourney(token)!.cartoApiKey).toBe('instance-key');
|
||||
testDb.prepare("INSERT INTO settings (user_id, key, value) VALUES (?, 'carto_api_key', ' owner-key ')").run(user.id);
|
||||
expect(svc.getPublicJourney(token)!.cartoApiKey).toBe('owner-key');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -51,6 +51,7 @@ describe('managed key assignment', () => {
|
||||
|
||||
it('MANAGED-KEYS-005: the locked list is pinned verbatim', () => {
|
||||
expect([...MANAGED_LOCKED_SETTING_KEYS]).toEqual([
|
||||
'carto_api_key',
|
||||
'llm_api_key',
|
||||
'llm_base_url',
|
||||
'llm_model',
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
/**
|
||||
* Unit tests for the DI-native SettingsService — SET-SVC-001 through
|
||||
* SET-SVC-030 (001–026 moved 1:1 from the legacy
|
||||
* SET-SVC-034 (001–026 moved 1:1 from the legacy
|
||||
* tests/unit/services/settingsService.test.ts; 027–030 pin the post-migration
|
||||
* quirk fixes: null-serializes-as-'' and the bulk masked-sentinel skip).
|
||||
* quirk fixes: null-serializes-as-'' and the bulk masked-sentinel skip;
|
||||
* 031–034 cover the CARTO basemap key).
|
||||
* Uses a real in-memory SQLite DB; apiKeyCrypto is mocked to a passthrough
|
||||
* so we don't need real encryption for most tests.
|
||||
*/
|
||||
@@ -173,6 +174,60 @@ describe('getUserSettings', () => {
|
||||
testDb.prepare("INSERT INTO settings (user_id, key, value) VALUES (?, 'llm_api_key', '')").run(user.id);
|
||||
expect(svc.getUserSettings(user.id).llm_api_key).toBe('••••••••');
|
||||
});
|
||||
|
||||
// carto_api_key (#2054): encrypted at rest like the other credentials, but
|
||||
// Leaflet builds the tile URL in the browser, so it must come back readable.
|
||||
it('SET-SVC-031 — carto_api_key is stored encrypted and read back in cleartext, never masked', () => {
|
||||
const { user } = createUser(testDb);
|
||||
svc.upsertSetting(user.id, 'carto_api_key', 'carto-user');
|
||||
// Passthrough crypto mock: the stored row is whatever maybe_encrypt_api_key returned.
|
||||
const raw = testDb
|
||||
.prepare("SELECT value FROM settings WHERE user_id = ? AND key = 'carto_api_key'")
|
||||
.get(user.id) as { value: string };
|
||||
expect(raw.value).toBe('carto-user');
|
||||
expect(svc.getUserSettings(user.id).carto_api_key).toBe('carto-user');
|
||||
|
||||
// A digits-only key proves it takes the decrypt branch: a non-encrypted key
|
||||
// would come back JSON-parsed, as the number 12345.
|
||||
svc.upsertSetting(user.id, 'carto_api_key', '12345');
|
||||
expect(svc.getUserSettings(user.id).carto_api_key).toBe('12345');
|
||||
});
|
||||
|
||||
it('SET-SVC-032 — an empty user carto_api_key falls back to the admin default', () => {
|
||||
const { user } = createUser(testDb);
|
||||
setAdminDefault('carto_api_key', 'carto-admin');
|
||||
testDb.prepare("INSERT INTO settings (user_id, key, value) VALUES (?, 'carto_api_key', '')").run(user.id);
|
||||
expect(svc.getUserSettings(user.id).carto_api_key).toBe('carto-admin');
|
||||
});
|
||||
|
||||
it('SET-SVC-033 — a managed instance injects the operator key over both the user and the admin value', () => {
|
||||
const { user } = createUser(testDb);
|
||||
setAdminDefault('carto_api_key', 'carto-admin');
|
||||
testDb.prepare("INSERT INTO settings (user_id, key, value) VALUES (?, 'carto_api_key', 'carto-user')").run(user.id);
|
||||
vi.stubEnv('TREK_MANAGED', 'true');
|
||||
vi.stubEnv('CARTO_API_KEY', 'carto-operator');
|
||||
try {
|
||||
expect(svc.getUserSettings(user.id).carto_api_key).toBe('carto-operator');
|
||||
} finally {
|
||||
vi.unstubAllEnvs();
|
||||
}
|
||||
});
|
||||
|
||||
it('SET-SVC-034 — the injected CARTO key leaves map_provider alone', () => {
|
||||
const { user } = createUser(testDb);
|
||||
vi.stubEnv('TREK_MANAGED', 'true');
|
||||
vi.stubEnv('CARTO_API_KEY', 'carto-operator');
|
||||
vi.stubEnv('MAPBOX_ACCESS_TOKEN', '');
|
||||
try {
|
||||
// The Mapbox token flips a managed instance to GL because a token means a
|
||||
// renderer. A basemap key says nothing about which renderer the user wants.
|
||||
const s = svc.getUserSettings(user.id);
|
||||
expect(s.carto_api_key).toBe('carto-operator');
|
||||
expect(s.map_provider).toBeUndefined();
|
||||
} finally {
|
||||
vi.unstubAllEnvs();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// ── upsertSetting ─────────────────────────────────────────────────────────────
|
||||
|
||||
@@ -375,6 +375,15 @@ describe('getSharedTripData', () => {
|
||||
expect(byName['Uploaded']).toBe('/uploads/pic.jpg');
|
||||
expect(byName['Bare']).toBeNull();
|
||||
});
|
||||
|
||||
it('SHARE-SVC-027: cartoApiKey resolves owner setting → admin instance default → empty (#2054)', () => {
|
||||
const { user, token } = seedSharedTrip();
|
||||
expect(svc.getSharedTripData(token)!.cartoApiKey).toBe('');
|
||||
testDb.prepare("INSERT INTO app_settings (key, value) VALUES ('default_user_setting_carto_api_key', 'instance-key')").run();
|
||||
expect(svc.getSharedTripData(token)!.cartoApiKey).toBe('instance-key');
|
||||
testDb.prepare("INSERT INTO settings (user_id, key, value) VALUES (?, 'carto_api_key', ' owner-key ')").run(user.id);
|
||||
expect(svc.getSharedTripData(token)!.cartoApiKey).toBe('owner-key');
|
||||
});
|
||||
});
|
||||
|
||||
// ── getSharedPlacePhotoKey ───────────────────────────────────────────────────
|
||||
|
||||
Reference in New Issue
Block a user