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
This commit is contained in:
Maurice
2026-11-07 11:45:00 +01:00
parent 37a4e84360
commit 354e30a075
12 changed files with 70 additions and 31 deletions
+2 -2
View File
@@ -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 }}
+1 -1
View File
@@ -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.
@@ -50,10 +50,10 @@ describe('MWalletButton', () => {
render(<MWalletButton tripId={42} reservationId={7} onError={onError} />);
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)));
});
});
+1 -1
View File
@@ -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.
+1 -1
View File
@@ -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.
-1
View File
@@ -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",
+1 -1
View File
@@ -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,
};
}
+1 -1
View File
@@ -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,
@@ -410,7 +410,10 @@ export class ReservationsRepository extends TrekRepository<Reservations> {
.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<number>('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)
@@ -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()
@@ -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<Record<string, unknown> | undefined> => ({ ...ROW })),
passContext: vi.fn(async (): Promise<Record<string, unknown> | 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<typeof Response>[0],
type = 'application/vnd.apple.pkpass',
) => safeFetchAdminConfigured.mockResolvedValue(new Response(body, { status, headers: { 'content-type': type } }));
async function refusal(promise: Promise<unknown>): Promise<number> {
try {
+1 -1
View File
@@ -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.