mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-28 23:50:08 +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:
@@ -404,7 +404,7 @@ async function main() {
|
||||
}
|
||||
|
||||
// --- settings: per-user encrypted keys ---
|
||||
const encryptedSettingKeys = ['webhook_url', 'ntfy_token', 'mapbox_access_token', 'llm_api_key'];
|
||||
const encryptedSettingKeys = ['webhook_url', 'ntfy_token', 'mapbox_access_token', 'carto_api_key', 'llm_api_key'];
|
||||
const settingRows = db.prepare(
|
||||
`SELECT user_id, key, value FROM settings WHERE key IN (${encryptedSettingKeys.map(() => '?').join(', ')})`
|
||||
).all(...encryptedSettingKeys) as { user_id: number; key: string; value: string }[];
|
||||
|
||||
@@ -77,7 +77,7 @@ below.)
|
||||
|
||||
**Runtime-toggled** (read live on every access via `readEnv()` /
|
||||
`RuntimeEnvService`; tests mutate these mid-lifetime):
|
||||
TREK_MANAGED, PLACES_API_BASE, PLACES_API_KEY, MAPBOX_ACCESS_TOKEN, DEMO_MODE, NODE_ENV, APP_VERSION, APP_URL, TREK_API_DOCS_ENABLED,
|
||||
TREK_MANAGED, PLACES_API_BASE, PLACES_API_KEY, MAPBOX_ACCESS_TOKEN, CARTO_API_KEY, DEMO_MODE, NODE_ENV, APP_VERSION, APP_URL, TREK_API_DOCS_ENABLED,
|
||||
TREK_PLUGINS_ENABLED / _DEV_LINK / _DIR / _DATA_DIR / TREK_PLUGIN_PERMISSIONS,
|
||||
OIDC_*, SMTP_*, FORCE_HTTPS, COOKIE_SECURE, HSTS_INCLUDE_SUBDOMAINS,
|
||||
ALLOWED_ORIGINS, UNSPLASH_ACCESS_KEY, WEBAUTHN_*, TZ, ADMIN_EMAIL,
|
||||
|
||||
@@ -137,6 +137,8 @@ export function deriveMaps(raw: RawEnv) {
|
||||
placesApiKey: raw.PLACES_API_KEY || undefined,
|
||||
/** Public pk.* token shipped with a managed instance; reaches the browser by design. */
|
||||
mapboxToken: raw.MAPBOX_ACCESS_TOKEN || undefined,
|
||||
/** CARTO basemap key; without one the tiles come back watermarked (#2054). Public too. */
|
||||
cartoKey: raw.CARTO_API_KEY || undefined,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -140,6 +140,7 @@ export const envSchema = z.object({
|
||||
PLACES_API_BASE: url,
|
||||
PLACES_API_KEY: anyString,
|
||||
MAPBOX_ACCESS_TOKEN: anyString,
|
||||
CARTO_API_KEY: anyString,
|
||||
DEMO_MODE: boolStr,
|
||||
DEMO_ADMIN_USER: anyString,
|
||||
DEMO_ADMIN_EMAIL: anyString,
|
||||
|
||||
@@ -38,15 +38,23 @@ export const SENSITIVE_KEYS = new Set([
|
||||
*/
|
||||
const SENSITIVE_SUFFIXES = ['_token', '_key', '_secret', '_password', '_pass', '_verifier'];
|
||||
|
||||
function isSensitiveName(name: string): boolean {
|
||||
const lower = name.toLowerCase();
|
||||
return SENSITIVE_KEYS.has(lower) || SENSITIVE_SUFFIXES.some((suffix) => lower.endsWith(suffix));
|
||||
}
|
||||
|
||||
/** Deep-redacts every key in `SENSITIVE_KEYS` (case-insensitive) from a request-log value. */
|
||||
export function redact(value: unknown): unknown {
|
||||
if (!value || typeof value !== 'object') return value;
|
||||
if (Array.isArray(value)) return (value as unknown[]).map(redact);
|
||||
const entries = value as Record<string, unknown>;
|
||||
// PUT /api/settings names the setting instead of using it as the field:
|
||||
// {key: 'carto_api_key', value: '<secret>'}. Neither field name is sensitive
|
||||
// on its own, so without this the secret goes into the debug log in cleartext.
|
||||
const namedSecret = typeof entries.key === 'string' && isSensitiveName(entries.key);
|
||||
const out: Record<string, unknown> = {};
|
||||
for (const [k, v] of Object.entries(value as Record<string, unknown>)) {
|
||||
const lower = k.toLowerCase();
|
||||
const sensitive = SENSITIVE_KEYS.has(lower) || SENSITIVE_SUFFIXES.some((suffix) => lower.endsWith(suffix));
|
||||
out[k] = sensitive ? '[REDACTED]' : redact(v);
|
||||
for (const [k, v] of Object.entries(entries)) {
|
||||
out[k] = isSensitiveName(k) || (namedSecret && k === 'value') ? '[REDACTED]' : redact(v);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
@@ -181,7 +189,10 @@ export function applyGlobalMiddleware(
|
||||
"https://nominatim.openstreetmap.org", "https://overpass-api.de",
|
||||
"https://places.googleapis.com", "https://api.openweathermap.org",
|
||||
"https://en.wikipedia.org", "https://commons.wikimedia.org",
|
||||
"https://*.basemaps.cartocdn.com",
|
||||
// Both forms here too: CARTO documents the apex host on its key page,
|
||||
// so that is the template users paste in, and the {s} sharded form is
|
||||
// what TREK ships (#2054).
|
||||
"https://basemaps.cartocdn.com", "https://*.basemaps.cartocdn.com",
|
||||
// Both forms: a CSP wildcard host never matches the apex, and OSM
|
||||
// serves everything from the bare tile.openstreetmap.org since it
|
||||
// retired the a/b/c/d shards (#1733). The sharded hosts stay listed
|
||||
|
||||
@@ -70,8 +70,14 @@ export function isManagedBlocked(env: RuntimeEnvService): boolean {
|
||||
* the one that reaches the browser: a managed instance ships with the operator's
|
||||
* public pk.* token, injected when the settings are read, and a per-user value
|
||||
* saved over it would only break the map for that user.
|
||||
*
|
||||
* carto_api_key is the same shape, injected on read and public in the browser,
|
||||
* and it is the operator's for one more reason: the key is registered to
|
||||
* whoever runs the instance, and CARTO's terms hold that account answerable for
|
||||
* the tiles it fetches.
|
||||
*/
|
||||
export const MANAGED_LOCKED_SETTING_KEYS = [
|
||||
'carto_api_key',
|
||||
'llm_api_key',
|
||||
'llm_base_url',
|
||||
'llm_model',
|
||||
|
||||
@@ -5,6 +5,7 @@ import { JourneyDomainService } from './journey-domain.service';
|
||||
import { JournalRpc } from './journal.rpc';
|
||||
import { PluginGuardsModule } from '../plugins/host/plugin-guards.module';
|
||||
import { JourneyShareService } from './journey-share.service';
|
||||
import { SettingsModule } from '../settings/settings.module';
|
||||
|
||||
/**
|
||||
* Leaf module holding the journey domain itself, without the controllers.
|
||||
@@ -16,9 +17,14 @@ import { JourneyShareService } from './journey-share.service';
|
||||
*
|
||||
* RealtimeModule is imported explicitly even though it is @Global, so a
|
||||
* single-domain e2e TestingModule can still resolve the broadcast.
|
||||
*
|
||||
* SettingsModule is the one addition to that shape: the public journey payload
|
||||
* carries the owner's CARTO tile key, and resolving that (per-user value, admin
|
||||
* instance default, managed-instance key, all decrypted) is SettingsService's
|
||||
* job rather than a second copy of its SQL here.
|
||||
*/
|
||||
@Module({
|
||||
imports: [RealtimeModule, TrekPhotosModule, PluginGuardsModule],
|
||||
imports: [RealtimeModule, TrekPhotosModule, PluginGuardsModule, SettingsModule],
|
||||
providers: [JourneyDomainService, JourneyShareService, JournalRpc],
|
||||
exports: [JourneyDomainService, JourneyShareService],
|
||||
})
|
||||
|
||||
@@ -2,6 +2,7 @@ import { Injectable } from '@nestjs/common';
|
||||
import crypto from 'crypto';
|
||||
import { DatabaseService } from '../database/database.service';
|
||||
import { JourneyDomainService } from './journey-domain.service';
|
||||
import { SettingsService } from '../settings/settings.service';
|
||||
|
||||
interface JourneySharePermissions {
|
||||
share_timeline?: boolean;
|
||||
@@ -33,6 +34,7 @@ export class JourneyShareService {
|
||||
constructor(
|
||||
private readonly db: DatabaseService,
|
||||
private readonly journey: JourneyDomainService,
|
||||
private readonly settings: SettingsService,
|
||||
) {}
|
||||
|
||||
createOrUpdateJourneyShareLink(
|
||||
@@ -238,6 +240,16 @@ export class JourneyShareService {
|
||||
}));
|
||||
}
|
||||
|
||||
// Same reason as the trip share payload: CARTO watermarks every tile fetched
|
||||
// without a key (#2054) and the public journey map has no logged-in user to
|
||||
// read one from, so the owner's key travels with it. Only a valid share token
|
||||
// gets this far. getUserSettings composes the owner's own value, the admin
|
||||
// instance default and the managed-instance key in that order; carto_api_key is
|
||||
// encrypted at rest but deliberately unmasked, since it is useless until it
|
||||
// reaches a browser.
|
||||
const ownerCartoKey = this.settings.getUserSettings(journey.user_id)['carto_api_key'];
|
||||
const cartoApiKey = typeof ownerCartoKey === 'string' ? ownerCartoKey.trim() : '';
|
||||
|
||||
return {
|
||||
journey: {
|
||||
title: journey.title,
|
||||
@@ -252,6 +264,7 @@ export class JourneyShareService {
|
||||
// would hand out places the map was deliberately turned off for.
|
||||
gallery: shareGallery ? (shareMap ? gallery : stripPhotoGps(gallery)) : [],
|
||||
stats,
|
||||
cartoApiKey,
|
||||
permissions: {
|
||||
share_timeline: shareTimeline,
|
||||
share_gallery: shareGallery,
|
||||
|
||||
@@ -4,7 +4,13 @@ import { decrypt_api_key, maybe_encrypt_api_key } from '../common/crypto/apiKeyC
|
||||
import { MASKED_SETTING_VALUE, normalizeAppearance } from '@trek/shared';
|
||||
import { readEnv } from '../../app-config';
|
||||
|
||||
const ENCRYPTED_SETTING_KEYS = new Set(['webhook_url', 'ntfy_token', 'mapbox_access_token', 'llm_api_key']);
|
||||
const ENCRYPTED_SETTING_KEYS = new Set([
|
||||
'webhook_url',
|
||||
'ntfy_token',
|
||||
'mapbox_access_token',
|
||||
'carto_api_key',
|
||||
'llm_api_key',
|
||||
]);
|
||||
// Encrypted keys that are masked (••••••••) when returned to the client.
|
||||
// Keys not in this set but in ENCRYPTED_SETTING_KEYS are decrypted and returned.
|
||||
const MASKED_SETTING_KEYS = new Set(['webhook_url', 'ntfy_token', 'llm_api_key']);
|
||||
@@ -19,6 +25,10 @@ export const DEFAULTABLE_USER_SETTING_KEYS = [
|
||||
'default_currency',
|
||||
'blur_booking_codes',
|
||||
'map_tile_url',
|
||||
// CARTO stamps an "API KEY REQUIRED" watermark into keyless tiles (#2054), and
|
||||
// the key is per-instance rather than per-person: defaultable so one admin
|
||||
// value clears the watermark for everybody at once.
|
||||
'carto_api_key',
|
||||
// Instance-wide GL map defaults: admins can set Mapbox token/style or
|
||||
// tokenless MapLibre/OpenFreeMap style defaults for new users (#920).
|
||||
'map_provider',
|
||||
@@ -216,6 +226,12 @@ export class SettingsService {
|
||||
merged.map_provider = 'mapbox-gl';
|
||||
}
|
||||
}
|
||||
// Injected the same way, but without touching map_provider: a CARTO key only
|
||||
// says whose basemap account the tiles are billed to, nothing about which
|
||||
// renderer the user wants.
|
||||
if (readEnv().managed.enabled && managedMaps.cartoKey) {
|
||||
merged.carto_api_key = managedMaps.cartoKey;
|
||||
}
|
||||
|
||||
return merged;
|
||||
}
|
||||
|
||||
@@ -280,15 +280,27 @@ export class ShareService {
|
||||
// honours per-user → admin-default; we then fall back to trip currency → EUR
|
||||
// (`||` on purpose: an empty-string trip currency also falls back).
|
||||
let baseCurrency = (trip as { currency?: string }).currency || 'EUR';
|
||||
if (shareRow.created_by != null) {
|
||||
const ownerDefault = this.settings.getUserSettings(shareRow.created_by)['default_currency'];
|
||||
if (typeof ownerDefault === 'string' && ownerDefault.trim()) {
|
||||
baseCurrency = ownerDefault.trim();
|
||||
}
|
||||
const ownerSettings: Record<string, unknown> = shareRow.created_by != null
|
||||
? this.settings.getUserSettings(shareRow.created_by)
|
||||
: {};
|
||||
const ownerDefault = ownerSettings['default_currency'];
|
||||
if (typeof ownerDefault === 'string' && ownerDefault.trim()) {
|
||||
baseCurrency = ownerDefault.trim();
|
||||
}
|
||||
|
||||
// CARTO stamps an "API KEY REQUIRED" watermark into every tile fetched without
|
||||
// a key (#2054), and a public viewer has no settings of their own to hold one,
|
||||
// so the owner's key travels in this payload. Nothing without a valid share
|
||||
// token reaches it, and the key is public in the browser anyway. getUserSettings
|
||||
// is the right accessor here even though it is the client-facing one:
|
||||
// carto_api_key is encrypted at rest but deliberately unmasked (same as the
|
||||
// Mapbox token, both have to reach a browser), and it is the only accessor that
|
||||
// composes per-user value → admin instance default → managed-instance key.
|
||||
const ownerCartoKey = ownerSettings['carto_api_key'];
|
||||
const cartoApiKey = typeof ownerCartoKey === 'string' ? ownerCartoKey.trim() : '';
|
||||
|
||||
return {
|
||||
trip, baseCurrency, categories, permissions,
|
||||
trip, baseCurrency, cartoApiKey, categories, permissions,
|
||||
days, assignments, dayNotes, places,
|
||||
reservations, accommodations,
|
||||
packing, budget,
|
||||
|
||||
@@ -183,7 +183,7 @@ export function createMcpTestRegistry(): McpRegistry {
|
||||
new CollectionsMcp(new CollectionsService(dbService, permissionsService, realtimeService, notificationsStub(), generalStorage), dbService, authService, addonsService),
|
||||
new TransitMcp(new TransitService(), daysService, reservationsService, dbService, authService, guards),
|
||||
new AtlasMcp(new AtlasService(dbService), addonsService, authService),
|
||||
new JourneyMcp(journeyDomain, new JourneyShareService(dbService, journeyDomain), addonsService, authService),
|
||||
new JourneyMcp(journeyDomain, new JourneyShareService(dbService, journeyDomain, new SettingsService(dbService)), addonsService, authService),
|
||||
new NotificationsMcp(makeNotificationsService(dbService, realtimeService), authService),
|
||||
],
|
||||
{ accessPolicy: trekMcpAccessPolicy, validateAccess: trekMcpValidateAccess },
|
||||
|
||||
@@ -524,6 +524,27 @@ describe('Shared trip — display currency (issue #1361)', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('Shared trip: CARTO tile key (issue #2054)', () => {
|
||||
it('SHARE-029: the payload carries the owner\'s carto_api_key, behind it the admin instance default', async () => {
|
||||
const { user } = createUser(testDb);
|
||||
const trip = createTrip(testDb, user.id);
|
||||
testDb.prepare("INSERT INTO app_settings (key, value) VALUES ('default_user_setting_carto_api_key', 'instance-key')").run();
|
||||
|
||||
const { body: { token } } = await request(app)
|
||||
.post(`/api/trips/${trip.id}/share-link`)
|
||||
.set('Cookie', authCookie(user.id))
|
||||
.send({ share_map: true });
|
||||
|
||||
const inherited = await request(app).get(`/api/shared/${token}`);
|
||||
expect(inherited.status).toBe(200);
|
||||
expect(inherited.body.cartoApiKey).toBe('instance-key');
|
||||
|
||||
testDb.prepare("INSERT INTO settings (user_id, key, value) VALUES (?, 'carto_api_key', 'owner-key')").run(user.id);
|
||||
const own = await request(app).get(`/api/shared/${token}`);
|
||||
expect(own.body.cartoApiKey).toBe('owner-key');
|
||||
});
|
||||
});
|
||||
|
||||
describe('Shared trip — place photos in shared links (issue #1100)', () => {
|
||||
const PLACE_ID = 'ChIJsharedPhoto1100';
|
||||
const PROXY_URL = `/api/maps/place-photo/${encodeURIComponent(PLACE_ID)}/bytes`;
|
||||
|
||||
@@ -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