Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -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: 4dcc01fe5d07933400c82695bf9574097ee19d43
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
6 changes: 4 additions & 2 deletions PARITY.md
Original file line number Diff line number Diff line change
@@ -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 `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 |
| --- | --- | --- |
Expand All @@ -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 |
Expand Down Expand Up @@ -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.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
9 changes: 8 additions & 1 deletion src/uri.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
31 changes: 31 additions & 0 deletions test/test-domain.test.mjs
Original file line number Diff line number Diff line change
@@ -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);
});
}
Loading