From d5d2a985ba13e0949fe4e4fe819e0e731e7009c3 Mon Sep 17 00:00:00 2001 From: Greg Bowler Date: Thu, 5 Nov 2026 22:09:53 +0000 Subject: [PATCH 1/2] Allow HTTP providers on test domains --- .github/workflows/ci.yml | 41 +++++++++++++++++++++++++++++++++++++++ PARITY.md | 6 ++++-- README.md | 2 ++ src/uri.ts | 9 ++++++++- test/test-domain.test.mjs | 31 +++++++++++++++++++++++++++++ 5 files changed, 86 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/ci.yml create mode 100644 test/test-domain.test.mjs diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..8353816 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,41 @@ +name: CI +on: [push, pull_request] +permissions: + contents: read +jobs: + test: + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + node: ['22', '24'] + defaults: + run: + working-directory: typescript-client + steps: + - uses: actions/checkout@v6 + with: + path: typescript-client + - uses: actions/checkout@v6 + with: + repository: Authwave/php-client + ref: b35909368b3bd78bb3c7401c694aef02d6a560dd + path: php-client + - uses: actions/setup-node@v6 + with: + node-version: ${{ matrix.node }} + cache: npm + cache-dependency-path: typescript-client/package-lock.json + - uses: shivammathur/setup-php@v2 + with: + php-version: '8.5' + extensions: sodium, curl + tools: composer + coverage: none + - name: Install PHP reference dependencies + run: composer install --no-dev --no-interaction --prefer-dist + working-directory: php-client + - run: npm ci + - run: npm run format:check + - run: npm test + - run: npm run typecheck diff --git a/PARITY.md b/PARITY.md index 6529718..1243c60 100644 --- a/PARITY.md +++ b/PARITY.md @@ -1,6 +1,6 @@ # PHP reference parity -Reference: the sibling `Authwave/php-client` checkout. Every source class is represented below. Parity means equivalent client features and wire behavior, with the runtime adaptations described here; it is not a claim that PHP and JavaScript have identical type systems or every inherited PSR-7 URI operation. +Reference: `Authwave/php-client` commit `b35909368b3bd78bb3c7401c694aef02d6a560dd` (the sibling checkout in local tests). Every source class is represented below. Parity means equivalent client features and wire behavior, with the runtime adaptations described here; it is not a claim that PHP and JavaScript have identical type systems or every inherited PSR-7 URI operation. | PHP source | TypeScript source / export | Validation | | --- | --- | --- | @@ -14,7 +14,7 @@ Reference: the sibling `Authwave/php-client` checkout. Every source class is rep | `AuthwaveException.php` | `src/errors.ts`: `AuthwaveException` | Base inheritance | | `SessionNotStartedException.php` | `src/errors.ts`: same name | Absent session rejection | | `NotLoggedInException.php` | `src/errors.ts`: same name | Missing user, token, data | -| `InsecureProtocolException.php` | `src/errors.ts`: same name | HTTPS policy, localhost and literal `127.0.0.127` exceptions | +| `InsecureProtocolException.php` | `src/errors.ts`: same name | HTTPS policy, localhost, literal `127.0.0.127`, and HTTP `.test` exceptions | | `InvalidUserDataSerializationException.php` | `src/errors.ts`: same name | Low-level decoder shape validation | | `ResponseCipherDecryptionException.php` | `src/errors.ts`: same name | Declaration preserved; not thrown by normal response processing, as in PHP | | `ProviderUri/BaseProviderUri.php` | `src/uri.ts`: `BaseProviderUri` | Same constants, RFC1738 query encoding, hex return URI, provider origin | @@ -58,3 +58,5 @@ The differential suite executes PHP's actual source with fixed nonces and compar `test/core.test.mjs` covers the PHP unit-test behaviors and additional JSON/session checks. `test/parity.test.mjs` and `test/php-oracle.php` compare the two implementations directly. `test/runtime.test.mjs` exercises Node/Express over local HTTP and Next.js with actual `NextRequest`/`NextResponse` objects, including callback failures, session isolation, cookies, expiry, and failed persistence. Browser login/logout against a real configured Authwave provider is not automated here. No claim of live deployment verification is made. + +Provider HTTP policy also allows the `.test` hostname suffix (case-insensitive, ignoring trailing DNS dots), for local test providers. The exception does not allow other schemes. diff --git a/README.md b/README.md index 6bcc14b..76124d6 100644 --- a/README.md +++ b/README.md @@ -56,3 +56,5 @@ npm test The suite includes direct comparisons against the sibling PHP implementation, including byte-identical encrypted requests. PHP with Sodium and the PHP client's installed Composer dependencies are required. Set `AUTHWAVE_PHP_REFERENCE` to override the default `../php-client` path. Run just these comparisons using `npm run test:parity`. [PARITY.md](PARITY.md) maps every PHP source class and documents the runtime adaptations. Automated tests simulate provider responses; browser validation against your deployed provider remains a deployment check. + +For a local test provider, HTTP is supported for hosts ending in `.test`, such as `http://login.realtest.authwave.test:9090`. Configure local DNS or a hosts-file entry for the provider. This exception applies only to HTTP and the complete `.test` hostname suffix; `.authwave-test` and names such as `example.test.com` do not qualify. Other remote providers require HTTPS. Use test accounts on a trusted development network; the suffix does not encrypt traffic or guarantee that it stays on your machine. diff --git a/src/uri.ts b/src/uri.ts index ca850fa..1bdcbfc 100644 --- a/src/uri.ts +++ b/src/uri.ts @@ -64,7 +64,14 @@ export abstract class BaseProviderUri extends Uri { static readonly QUERY_STRING_DEPLOYMENT_ID = 'd'; constructor(baseUri: string) { const url = new URL(baseUri.includes('://') ? baseUri : `https://${baseUri}`); - if (url.hostname !== 'localhost' && url.hostname !== '127.0.0.127' && url.protocol !== 'https:') + const isTestHttp = + url.protocol === 'http:' && url.hostname.toLowerCase().replace(/\.+$/, '').endsWith('.test'); + if ( + url.hostname !== 'localhost' && + url.hostname !== '127.0.0.127' && + !isTestHttp && + url.protocol !== 'https:' + ) throw new InsecureProtocolException(url.protocol.slice(0, -1)); super(url.origin); } diff --git a/test/test-domain.test.mjs b/test/test-domain.test.mjs new file mode 100644 index 0000000..914ff7e --- /dev/null +++ b/test/test-domain.test.mjs @@ -0,0 +1,31 @@ +import test from 'node:test'; +import assert from 'node:assert/strict'; +import { AdminUri, InsecureProtocolException } from '../dist/index.js'; + +const cases = [ + ['http://login.realtest.authwave.test:9090', true], + ['http://app.test', true], + ['http://LOGIN.EXAMPLE.TEST:9090', true], + ['http://login.example.test.:9090', true], + ['http://localhost:9090', true], + ['http://127.0.0.127:9090', true], + ['https://login.authwave.com', true], + ['http://login.realtest.authwave-test:9090', false], + ['http://example.test.attacker.com', false], + ['http://exampletest', false], + ['http://test', false], + ['http://login.authwave.com', false], + ['ftp://example.test', false], +]; +for (const [host, allowed] of cases) { + test(`provider protocol: ${host}`, () => { + if (!allowed) { + assert.throws(() => new AdminUri(host), InsecureProtocolException); + return; + } + const uri = new AdminUri(host); + assert.equal(uri.getPath(), '/admin/'); + if (host.startsWith('http://')) assert.equal(uri.getScheme(), 'http'); + if (host.includes(':9090')) assert.equal(uri.getPort(), 9090); + }); +} From 48680ef4517c70231feaa0341a6e463fc349fa47 Mon Sep 17 00:00:00 2001 From: Greg Bowler Date: Thu, 5 Nov 2026 22:12:08 +0000 Subject: [PATCH 2/2] Use the verified PHP reference revision --- .github/workflows/ci.yml | 2 +- PARITY.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8353816..c83c80b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -19,7 +19,7 @@ jobs: - uses: actions/checkout@v6 with: repository: Authwave/php-client - ref: b35909368b3bd78bb3c7401c694aef02d6a560dd + ref: 4dcc01fe5d07933400c82695bf9574097ee19d43 path: php-client - uses: actions/setup-node@v6 with: diff --git a/PARITY.md b/PARITY.md index 1243c60..bfbfaf5 100644 --- a/PARITY.md +++ b/PARITY.md @@ -1,6 +1,6 @@ # PHP reference parity -Reference: `Authwave/php-client` commit `b35909368b3bd78bb3c7401c694aef02d6a560dd` (the sibling checkout in local tests). Every source class is represented below. Parity means equivalent client features and wire behavior, with the runtime adaptations described here; it is not a claim that PHP and JavaScript have identical type systems or every inherited PSR-7 URI operation. +Reference: `Authwave/php-client` commit `4dcc01fe5d07933400c82695bf9574097ee19d43` (the sibling checkout in local tests). Every source class is represented below. Parity means equivalent client features and wire behavior, with the runtime adaptations described here; it is not a claim that PHP and JavaScript have identical type systems or every inherited PSR-7 URI operation. | PHP source | TypeScript source / export | Validation | | --- | --- | --- |