2026-02-16 11:22:23 +00:00
|
|
|
import { expect, tap } from '@push.rocks/tapbundle';
|
|
|
|
|
import * as remoteingress from '../ts/index.js';
|
2024-03-24 14:44:44 +01:00
|
|
|
|
2026-02-16 11:22:23 +00:00
|
|
|
tap.test('should export RemoteIngressHub', async () => {
|
|
|
|
|
expect(remoteingress.RemoteIngressHub).toBeTypeOf('function');
|
|
|
|
|
});
|
2024-03-24 14:44:44 +01:00
|
|
|
|
2026-02-16 11:22:23 +00:00
|
|
|
tap.test('should export RemoteIngressEdge', async () => {
|
|
|
|
|
expect(remoteingress.RemoteIngressEdge).toBeTypeOf('function');
|
|
|
|
|
});
|
|
|
|
|
|
2026-02-17 19:36:40 +00:00
|
|
|
tap.test('should export encodeConnectionToken and decodeConnectionToken', async () => {
|
|
|
|
|
expect(remoteingress.encodeConnectionToken).toBeTypeOf('function');
|
|
|
|
|
expect(remoteingress.decodeConnectionToken).toBeTypeOf('function');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
tap.test('should roundtrip encode → decode a connection token', async () => {
|
|
|
|
|
const data: remoteingress.IConnectionTokenData = {
|
|
|
|
|
hubHost: 'hub.example.com',
|
|
|
|
|
hubPort: 8443,
|
|
|
|
|
edgeId: 'edge-001',
|
|
|
|
|
secret: 'super-secret-key',
|
|
|
|
|
};
|
|
|
|
|
const token = remoteingress.encodeConnectionToken(data);
|
|
|
|
|
const decoded = remoteingress.decodeConnectionToken(token);
|
|
|
|
|
expect(decoded.hubHost).toEqual(data.hubHost);
|
|
|
|
|
expect(decoded.hubPort).toEqual(data.hubPort);
|
|
|
|
|
expect(decoded.edgeId).toEqual(data.edgeId);
|
|
|
|
|
expect(decoded.secret).toEqual(data.secret);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
tap.test('should throw on malformed token', async () => {
|
|
|
|
|
let error: Error | undefined;
|
|
|
|
|
try {
|
|
|
|
|
remoteingress.decodeConnectionToken('not-valid-json!!!');
|
|
|
|
|
} catch (e) {
|
|
|
|
|
error = e as Error;
|
|
|
|
|
}
|
|
|
|
|
expect(error).toBeInstanceOf(Error);
|
|
|
|
|
expect(error!.message).toInclude('Invalid connection token');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
tap.test('should throw on token with missing fields', async () => {
|
|
|
|
|
// Encode a partial object (missing 'p' and 's')
|
|
|
|
|
const partial = Buffer.from(JSON.stringify({ h: 'host', e: 'edge' }), 'utf-8')
|
|
|
|
|
.toString('base64')
|
|
|
|
|
.replace(/\+/g, '-')
|
|
|
|
|
.replace(/\//g, '_')
|
|
|
|
|
.replace(/=+$/, '');
|
|
|
|
|
|
|
|
|
|
let error: Error | undefined;
|
|
|
|
|
try {
|
|
|
|
|
remoteingress.decodeConnectionToken(partial);
|
|
|
|
|
} catch (e) {
|
|
|
|
|
error = e as Error;
|
|
|
|
|
}
|
|
|
|
|
expect(error).toBeInstanceOf(Error);
|
|
|
|
|
expect(error!.message).toInclude('missing required fields');
|
|
|
|
|
});
|
|
|
|
|
|
2026-02-16 11:22:23 +00:00
|
|
|
export default tap.start();
|