From 354e30a0753530026872a36e5d9b4e818640758e Mon Sep 17 00:00:00 2001 From: Maurice Date: Sat, 7 Nov 2026 11:45:00 +0100 Subject: [PATCH] fix(ci): wallet passes pass the server gates - TREK_WALLET_PASS_URL read as a secret to the env check (the word PASS); it is TREK_WALLET_SIGNER_URL now, everywhere it is documented - findPassContext compared the TEXT accommodation_id with an integer id, which Postgres refuses; it compares them as numbers now, as both databases accept - the wallet-pass service test takes its subject from createTestModule instead of building it by hand, and no longer names the DOM-only BodyInit type - Reservations.repository.ts is formatted, so it leaves the format baseline - the wallet button test reads the translated texts the render helper gives --- charts/trek/templates/configmap.yaml | 4 +- charts/trek/values.yaml | 2 +- .../mobile/components/MWalletButton.test.tsx | 4 +- docker-compose.yml | 2 +- server/.env.example | 2 +- server/scripts/format-baseline.json | 1 - server/src/app-config/boot-derive.ts | 2 +- server/src/app-config/env.schema.ts | 2 +- .../repositories/Reservations.repository.ts | 5 +- .../nest/wallet-pass/wallet-pass.service.ts | 2 +- .../wallet-pass/wallet-pass.service.test.ts | 73 ++++++++++++++----- wiki/Environment-Variables.md | 2 +- 12 files changed, 70 insertions(+), 31 deletions(-) diff --git a/charts/trek/templates/configmap.yaml b/charts/trek/templates/configmap.yaml index 4dbcb2b8c..b4545d287 100644 --- a/charts/trek/templates/configmap.yaml +++ b/charts/trek/templates/configmap.yaml @@ -127,8 +127,8 @@ data: {{- if .Values.env.TREK_VALHALLA_URL }} TREK_VALHALLA_URL: {{ .Values.env.TREK_VALHALLA_URL | quote }} {{- end }} - {{- if .Values.env.TREK_WALLET_PASS_URL }} - TREK_WALLET_PASS_URL: {{ .Values.env.TREK_WALLET_PASS_URL | quote }} + {{- if .Values.env.TREK_WALLET_SIGNER_URL }} + TREK_WALLET_SIGNER_URL: {{ .Values.env.TREK_WALLET_SIGNER_URL | quote }} {{- end }} {{- if .Values.env.GOOGLE_LIST_DATA_BASE }} GOOGLE_LIST_DATA_BASE: {{ .Values.env.GOOGLE_LIST_DATA_BASE | quote }} diff --git a/charts/trek/values.yaml b/charts/trek/values.yaml index 2ee2e06aa..c2a4a4c53 100644 --- a/charts/trek/values.yaml +++ b/charts/trek/values.yaml @@ -159,7 +159,7 @@ env: # TREK_VALHALLA_URL: "" # The Valhalla of the TREK services, which this server relays routing to unless the admin picks another # routing service. The browser never talks to it. Defaults to https://valhalla.liketrek.com. - # TREK_WALLET_PASS_URL: "" + # TREK_WALLET_SIGNER_URL: "" # Signs the Apple Wallet pass of a booking when someone taps "Add to Apple Wallet" in the iOS app. # Only the pass's texts go there, once per tap. Never asked with TREK_SERVICES=off. # Defaults to https://push.liketrek.com/v1/wallet/pass. diff --git a/client/src/mobile/components/MWalletButton.test.tsx b/client/src/mobile/components/MWalletButton.test.tsx index b6625e881..cd0a8c0d6 100644 --- a/client/src/mobile/components/MWalletButton.test.tsx +++ b/client/src/mobile/components/MWalletButton.test.tsx @@ -50,10 +50,10 @@ describe('MWalletButton', () => { render(); wallet.add.mockResolvedValueOnce('undated'); fireEvent.click(screen.getByRole('button')); - await waitFor(() => expect(onError).toHaveBeenCalledWith('reservations.wallet.undated')); + await waitFor(() => expect(onError).toHaveBeenCalledWith(expect.stringMatching(/date/i))); await waitFor(() => expect(screen.getByRole('button')).not.toBeDisabled()); wallet.add.mockResolvedValueOnce('failed'); fireEvent.click(screen.getByRole('button')); - await waitFor(() => expect(onError).toHaveBeenLastCalledWith('reservations.wallet.failed')); + await waitFor(() => expect(onError).toHaveBeenLastCalledWith(expect.stringMatching(/could not be made/i))); }); }); diff --git a/docker-compose.yml b/docker-compose.yml index 031431286..c1d110bc5 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -66,7 +66,7 @@ services: # - TREK_SERVICES_KEY= # Optional. A key issued for this installation; it wins over the stored one and turns self-registration off. # - TREK_PHOTON_URL=https://photon.liketrek.com # Optional. The address search of the TREK services. With a key, search and reverse lookups ask it before Nominatim and fall back to Nominatim when it does not answer; never asked when NOMINATIM_URL is set. (default: https://photon.liketrek.com) # - TREK_VALHALLA_URL=https://valhalla.liketrek.com # Optional. The Valhalla of the TREK services, which this server relays routing to unless the admin picks another routing service; the browser never talks to it. (default: https://valhalla.liketrek.com) -# - TREK_WALLET_PASS_URL=https://push.liketrek.com/v1/wallet/pass # Optional. Signs the Apple Wallet pass of a booking when someone taps "Add to Apple Wallet" in the iOS app; only the pass's texts go there, once per tap, and are not stored. Never asked with TREK_SERVICES=off. (default: https://push.liketrek.com/v1/wallet/pass) +# - TREK_WALLET_SIGNER_URL=https://push.liketrek.com/v1/wallet/pass # Optional. Signs the Apple Wallet pass of a booking when someone taps "Add to Apple Wallet" in the iOS app; only the pass's texts go there, once per tap, and are not stored. Never asked with TREK_SERVICES=off. (default: https://push.liketrek.com/v1/wallet/pass) # - PLACES_API_KEY= # Optional. Google Maps API key (Places API (New) enabled) for place search, photos, details and Google transit. Overrides the key set in Admin > Settings > API Keys, whose field then shows this variable read-only. # - GOOGLE_LIST_DATA_BASE= # Optional. HTTP(S) base URL of a list-data service. Pasted URLs beginning with this base are imported directly; unset keeps the Google flow. # - AMAP_API_KEY= # Optional. Amap (高德地图) Web 服务 key for place search and geocoding inside mainland China. Overrides the key set in Admin > Settings > API Keys. A Web 端 (JS API) key is a different credential and is rejected with INVALID_USER_KEY. diff --git a/server/.env.example b/server/.env.example index 5926f56ab..46eb3f377 100644 --- a/server/.env.example +++ b/server/.env.example @@ -76,7 +76,7 @@ DEMO_MODE=false # Demo mode: resets data hourly # TREK_SERVICES_HOSTS=places.liketrek.com,photon.liketrek.com,valhalla.liketrek.com # Comma-separated hosts that receive the installation key over https. No other host ever sees it. (default: places.liketrek.com,photon.liketrek.com,valhalla.liketrek.com) # TREK_PHOTON_URL=https://photon.liketrek.com # The address search (Photon) of the TREK services. Once the installation holds a key, search and reverse lookups ask it before Nominatim and fall back to Nominatim whenever it does not answer. Never asked with TREK_SERVICES=off, without a key, or when NOMINATIM_URL is set. (default: https://photon.liketrek.com) # TREK_VALHALLA_URL=https://valhalla.liketrek.com # The Valhalla of the TREK services. Routes and elevation are asked of it unless Admin > Default user settings picks another routing service; the browser never talks to it, this server relays its questions with the installation key. (default: https://valhalla.liketrek.com) -# TREK_WALLET_PASS_URL=https://push.liketrek.com/v1/wallet/pass # Signs the Apple Wallet pass of a booking when someone taps "Add to Apple Wallet" in the iOS app. Only liketrek holds the pass certificate, so the pass's texts (the booking's name, times, places, seat or room and confirmation code, nothing else) go there once per tap and are not stored. Never asked with TREK_SERVICES=off. (default: https://push.liketrek.com/v1/wallet/pass) +# TREK_WALLET_SIGNER_URL=https://push.liketrek.com/v1/wallet/pass # Signs the Apple Wallet pass of a booking when someone taps "Add to Apple Wallet" in the iOS app. Only liketrek holds the pass certificate, so the pass's texts (the booking's name, times, places, seat or room and confirmation code, nothing else) go there once per tap and are not stored. Never asked with TREK_SERVICES=off. (default: https://push.liketrek.com/v1/wallet/pass) # PLACES_API_KEY= # Google Maps API key (Places API (New) enabled) for place search, photos, details and Google transit. Overrides the key set in Admin > Settings > API Keys, whose field then shows this variable read-only. The value never reaches the browser. # GOOGLE_LIST_DATA_BASE= # Optional HTTP(S) base URL of a list-data service, e.g. https://maps.example.com. Paste a URL beginning with this base to fetch and parse it directly. Unset keeps the original Google list import flow. diff --git a/server/scripts/format-baseline.json b/server/scripts/format-baseline.json index e1ce926b3..10980f381 100644 --- a/server/scripts/format-baseline.json +++ b/server/scripts/format-baseline.json @@ -1,7 +1,6 @@ [ "src/db/repositories/DayAssignments.repository.ts", "src/db/repositories/Places.repository.ts", - "src/db/repositories/Reservations.repository.ts", "src/db/repositories/Trips.repository.ts", "src/db/repositories/Users.repository.ts", "src/nest/atlas/atlas-geo.ts", diff --git a/server/src/app-config/boot-derive.ts b/server/src/app-config/boot-derive.ts index 80b1acb28..ade88329d 100644 --- a/server/src/app-config/boot-derive.ts +++ b/server/src/app-config/boot-derive.ts @@ -86,7 +86,7 @@ export function deriveServices(raw: RawEnv) { hosts: hosts?.length ? hosts : DEFAULT_SERVICE_HOSTS, photonUrl: stripTrailingSlashes(raw.TREK_PHOTON_URL?.trim() || DEFAULT_PHOTON_URL), valhallaUrl: stripTrailingSlashes(raw.TREK_VALHALLA_URL?.trim() || DEFAULT_VALHALLA_URL), - walletPassUrl: raw.TREK_WALLET_PASS_URL?.trim() || DEFAULT_WALLET_PASS_URL, + walletPassUrl: raw.TREK_WALLET_SIGNER_URL?.trim() || DEFAULT_WALLET_PASS_URL, }; } diff --git a/server/src/app-config/env.schema.ts b/server/src/app-config/env.schema.ts index e685f225f..e3a3ac42f 100644 --- a/server/src/app-config/env.schema.ts +++ b/server/src/app-config/env.schema.ts @@ -191,7 +191,7 @@ export const envSchema = z.object({ TREK_SERVICES_HOSTS: anyString, TREK_PHOTON_URL: url, TREK_VALHALLA_URL: url, - TREK_WALLET_PASS_URL: url, + TREK_WALLET_SIGNER_URL: url, PLACES_API_KEY: anyString, AMAP_API_BASE: url, AMAP_API_KEY: anyString, diff --git a/server/src/db/repositories/Reservations.repository.ts b/server/src/db/repositories/Reservations.repository.ts index 73414cce3..fb006d980 100644 --- a/server/src/db/repositories/Reservations.repository.ts +++ b/server/src/db/repositories/Reservations.repository.ts @@ -410,7 +410,10 @@ export class ReservationsRepository extends TrekRepository { .selectFrom('reservations as r') .innerJoin('trips as t', 't.id', 'r.trip_id') .leftJoin('places as p', 'p.id', 'r.place_id') - .leftJoin('day_accommodations as ap', 'ap.id', 'r.accommodation_id') + // accommodation_id is TEXT; compared as a number so Postgres takes it as well as SQLite ("14" and "14.0" alike). + .leftJoin('day_accommodations as ap', (join) => + join.on((eb) => eb(eb.cast('r.accommodation_id', 'numeric'), '=', eb.ref('ap.id'))), + ) .leftJoin('places as acc_p', 'acc_p.id', 'ap.place_id') .where('r.id', '=', id) .where('r.trip_id', '=', trip_id) diff --git a/server/src/nest/wallet-pass/wallet-pass.service.ts b/server/src/nest/wallet-pass/wallet-pass.service.ts index c17a2f439..e920bf487 100644 --- a/server/src/nest/wallet-pass/wallet-pass.service.ts +++ b/server/src/nest/wallet-pass/wallet-pass.service.ts @@ -28,7 +28,7 @@ export interface WalletPass { /** * A booking's Apple Wallet pass. Only liketrek holds the Pass Type ID * certificate, so the pass's texts go to the TREK services' signer - * (TREK_WALLET_PASS_URL) once per tap and come back as a signed .pkpass; the + * (TREK_WALLET_SIGNER_URL) once per tap and come back as a signed .pkpass; the * signer stores nothing. Off with the other TREK services (TREK_SERVICES=off). */ @Injectable() diff --git a/server/tests/unit/nest/wallet-pass/wallet-pass.service.test.ts b/server/tests/unit/nest/wallet-pass/wallet-pass.service.test.ts index a83e647dc..3b4fcb3a8 100644 --- a/server/tests/unit/nest/wallet-pass/wallet-pass.service.test.ts +++ b/server/tests/unit/nest/wallet-pass/wallet-pass.service.test.ts @@ -1,8 +1,14 @@ +import { servicesConfig } from '../../../../src/nest/app-config/tokens'; import { DomainError } from '../../../../src/nest/common/domain-error'; +import { RateLimitService } from '../../../../src/nest/common/rate-limit.service'; +import { ReservationsReadService } from '../../../../src/nest/reservations/reservations-read.service'; +import { WalletPassModule } from '../../../../src/nest/wallet-pass/wallet-pass.module'; import { filenameOf, parseMetadata, WalletPassService } from '../../../../src/nest/wallet-pass/wallet-pass.service'; import { loadWalletWords, walletLanguage } from '../../../../src/nest/wallet-pass/wallet-pass.words'; +import { createSnapshotTestDb } from '../../../helpers/db-mock'; +import { createTestModule, type TestModule } from '../../../helpers/test-module'; -import { beforeEach, describe, expect, it, vi } from 'vitest'; +import { afterAll, beforeAll, beforeEach, describe, expect, it, vi } from 'vitest'; const { safeFetchAdminConfigured } = vi.hoisted(() => ({ safeFetchAdminConfigured: vi.fn() })); vi.mock('../../../../src/utils/ssrfGuard', async (importOriginal) => ({ @@ -27,27 +33,58 @@ const ROW = { endpoints: [], }; +const db = createSnapshotTestDb(); +const config = { + mode: 'auto' as 'auto' | 'off', + key: null, + hosts: [], + walletPassUrl: 'https://push.liketrek.com/v1/wallet/pass', +}; +const reservations = { + getReservationWithJoins: vi.fn(), + passContext: vi.fn(), +}; +const rateLimit = { check: vi.fn() }; +let t: TestModule; +let service: WalletPassService; + +beforeAll(async () => { + t = await createTestModule({ + db, + imports: [WalletPassModule], + overrides: [ + { provide: servicesConfig.KEY, useValue: config }, + { provide: ReservationsReadService, useValue: reservations }, + { provide: RateLimitService, useValue: rateLimit }, + ], + }); + service = t.moduleRef.get(WalletPassService); +}); + +afterAll(async () => { + await t.close(); + db.close(); +}); + +/** The service from the module, with its collaborators set to a hotel booking that may have a pass. */ function make(mode: 'auto' | 'off' = 'auto') { - const reservations = { - getReservationWithJoins: vi.fn(async (): Promise | undefined> => ({ ...ROW })), - passContext: vi.fn(async (): Promise | undefined> => ({ - trip_title: 'Japan 2027', - place_lat: 34.985, - place_lng: 135.758, - place_name: 'Hotel Granvia Kyoto', - })), - }; - const rateLimit = { check: vi.fn(async () => true) }; - const service = new WalletPassService( - { mode, walletPassUrl: 'https://push.liketrek.com/v1/wallet/pass' } as never, - reservations as never, - rateLimit as never, - ); + config.mode = mode; + reservations.getReservationWithJoins.mockReset().mockImplementation(async () => ({ ...ROW })); + reservations.passContext.mockReset().mockImplementation(async () => ({ + trip_title: 'Japan 2027', + place_lat: 34.985, + place_lng: 135.758, + place_name: 'Hotel Granvia Kyoto', + })); + rateLimit.check.mockReset().mockImplementation(async () => true); return { service, reservations, rateLimit }; } -const signerAnswers = (status: number, body: BodyInit, type = 'application/vnd.apple.pkpass') => - safeFetchAdminConfigured.mockResolvedValue(new Response(body, { status, headers: { 'content-type': type } })); +const signerAnswers = ( + status: number, + body: ConstructorParameters[0], + type = 'application/vnd.apple.pkpass', +) => safeFetchAdminConfigured.mockResolvedValue(new Response(body, { status, headers: { 'content-type': type } })); async function refusal(promise: Promise): Promise { try { diff --git a/wiki/Environment-Variables.md b/wiki/Environment-Variables.md index 3ff6eec7e..9fbe0f5ad 100644 --- a/wiki/Environment-Variables.md +++ b/wiki/Environment-Variables.md @@ -398,7 +398,7 @@ TREK's own place index, the [TREK Places API](TREK-Places-API), answers the sugg | `TREK_SERVICES_HOSTS` | Comma-separated hosts that receive the installation key over https. | `places.liketrek.com,photon.liketrek.com,valhalla.liketrek.com` | | `TREK_PHOTON_URL` | The address search of the TREK services, a [Photon](https://github.com/komoot/photon) instance. Once the installation holds a key it is the geocoder in place of Nominatim: the OpenStreetMap half of search and suggestions, import geocoding, the right-click on the map and pasted map links, matching a Google place to its OpenStreetMap record and naming an opened OpenStreetMap place. An empty answer is the answer, and so is a miss (an error, a timeout, a refused key or a spent allowance): Nominatim is not asked in its place. It is never asked with `TREK_SERVICES=off`, without a key, or when `NOMINATIM_URL` is set. See [Address search](TREK-Places-API#address-search). | `https://photon.liketrek.com` | | `TREK_VALHALLA_URL` | The Valhalla of the TREK services. Routes, elevation and the description of a line go there unless the admin picks another routing service under Admin, Default user settings; this server relays them with the installation key, so the browser never talks to it. A trailing slash is stripped, and a value that is not a full URL aborts startup. | `https://valhalla.liketrek.com` | -| `TREK_WALLET_PASS_URL` | Signs a booking's Apple Wallet pass when someone taps **Add to Apple Wallet** in the iOS app. Only liketrek holds the pass certificate, so the pass's texts (the booking's name, times, places, seat or room and confirmation code, nothing else) go there once per tap and are not stored. Never asked with `TREK_SERVICES=off`; a value that is not a full URL aborts startup. | `https://push.liketrek.com/v1/wallet/pass` | +| `TREK_WALLET_SIGNER_URL` | Signs a booking's Apple Wallet pass when someone taps **Add to Apple Wallet** in the iOS app. Only liketrek holds the pass certificate, so the pass's texts (the booking's name, times, places, seat or room and confirmation code, nothing else) go there once per tap and are not stored. Never asked with `TREK_SERVICES=off`; a value that is not a full URL aborts startup. | `https://push.liketrek.com/v1/wallet/pass` | On Helm these go under `env:` in `values.yaml`, except `TREK_SERVICES_KEY`, which goes under `secretEnv:`. The chart passes `TREK_PLACES_ENABLED` through whenever it is set at all, so an unquoted `false` or `--set env.TREK_PLACES_ENABLED=false` reaches the container as well.