mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-30 16:33:16 +00:00
feat(shared): keywords for MapLibre's template and theme styles
The maplibre_style slot gains two values that name no style document: trek:template, which has MapLibre draw the user's map template the way Leaflet does, and trek:ofm-auto, OpenFreeMap Liberty in the light theme and OpenFreeMap Dark in the dark one. No stored row holds either, so no saved setting changes its meaning, and a client that predates them reads them as a foreign style and draws the default. mapConnectHostAllows reads a host-source entry the way the browser reads the policy (a wildcard never covers its apex, no port means the default one), so the client can ask whether a GL map may fetch a tile before it tries.
This commit is contained in:
@@ -1,4 +1,9 @@
|
||||
import { isMapConnectHost, mapExtraConnectHostsSchema, parseMapConnectHosts } from './map-connect-hosts';
|
||||
import {
|
||||
isMapConnectHost,
|
||||
mapConnectHostAllows,
|
||||
mapExtraConnectHostsSchema,
|
||||
parseMapConnectHosts,
|
||||
} from './map-connect-hosts';
|
||||
|
||||
import { describe, it, expect } from 'vitest';
|
||||
|
||||
@@ -88,3 +93,26 @@ describe('mapExtraConnectHostsSchema', () => {
|
||||
expect(result.error?.issues[0]?.message).toContain('tiles.example.com');
|
||||
});
|
||||
});
|
||||
|
||||
describe('mapConnectHostAllows', () => {
|
||||
it('MAP-HOSTS-ALLOW-001: a plain entry covers its own host on the default port only', () => {
|
||||
expect(mapConnectHostAllows('tiles.example.com', 'tiles.example.com')).toBe(true);
|
||||
expect(mapConnectHostAllows('tiles.example.com', 'tiles.example.com:443')).toBe(true);
|
||||
expect(mapConnectHostAllows('tiles.example.com', 'TILES.example.com')).toBe(true);
|
||||
expect(mapConnectHostAllows('tiles.example.com', 'tiles.example.com:8443')).toBe(false);
|
||||
expect(mapConnectHostAllows('tiles.example.com', 'a.tiles.example.com')).toBe(false);
|
||||
expect(mapConnectHostAllows('tiles.example.com', 'tiles.example.com.evil.test')).toBe(false);
|
||||
});
|
||||
|
||||
it('MAP-HOSTS-ALLOW-002: a port in the entry must be the URL port', () => {
|
||||
expect(mapConnectHostAllows('tiles.example.com:8443', 'tiles.example.com:8443')).toBe(true);
|
||||
expect(mapConnectHostAllows('tiles.example.com:8443', 'tiles.example.com')).toBe(false);
|
||||
});
|
||||
|
||||
it('MAP-HOSTS-ALLOW-003: a wildcard covers every subdomain and never the apex', () => {
|
||||
expect(mapConnectHostAllows('*.basemaps.cartocdn.com', 'a.basemaps.cartocdn.com')).toBe(true);
|
||||
expect(mapConnectHostAllows('*.basemaps.cartocdn.com', 'x.y.basemaps.cartocdn.com')).toBe(true);
|
||||
expect(mapConnectHostAllows('*.basemaps.cartocdn.com', 'basemaps.cartocdn.com')).toBe(false);
|
||||
expect(mapConnectHostAllows('*.basemaps.cartocdn.com', 'evilbasemaps.cartocdn.com')).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user