Files
smartvpn/test/test.integration.node.ts

87 lines
2.8 KiB
TypeScript
Raw Normal View History

2026-02-27 10:18:23 +00:00
import { tap, expect } from '@git.zone/tstest/tapbundle';
import { VpnClient, VpnServer } from '../ts/index.js';
import type { IVpnClientOptions, IVpnServerOptions } from '../ts/index.js';
// Integration test: both client and server daemon spawns, keypair generation, full IPC roundtrip
let server: VpnServer;
let client: VpnClient;
tap.test('Integration: spawn server daemon', async () => {
const options: IVpnServerOptions = {
transport: { transport: 'stdio' },
};
server = new VpnServer(options);
const started = await server['bridge'].start();
expect(started).toBeTrue();
expect(server.running).toBeTrue();
});
tap.test('Integration: server generateKeypair', async () => {
const keypair = await server.generateKeypair();
expect(keypair.publicKey).toBeTypeofString();
expect(keypair.privateKey).toBeTypeofString();
// Verify base64-encoded 32-byte keys = 44 chars
expect(keypair.publicKey.length).toEqual(44);
expect(keypair.privateKey.length).toEqual(44);
});
tap.test('Integration: server getStatus is disconnected', async () => {
const status = await server.getStatus();
expect(status.state).toEqual('disconnected');
});
tap.test('Integration: server listClients returns empty', async () => {
const clients = await server.listClients();
expect(clients).toBeArray();
expect(clients.length).toEqual(0);
});
tap.test('Integration: server getStatistics returns zeros', async () => {
const stats = await server.getStatistics();
expect(stats.bytesSent).toEqual(0);
expect(stats.bytesReceived).toEqual(0);
expect(stats.activeClients).toEqual(0);
expect(stats.totalConnections).toEqual(0);
});
tap.test('Integration: spawn client daemon', async () => {
const options: IVpnClientOptions = {
transport: { transport: 'stdio' },
};
client = new VpnClient(options);
const started = await client.start();
expect(started).toBeTrue();
expect(client.running).toBeTrue();
});
tap.test('Integration: client getStatus is disconnected', async () => {
const status = await client.getStatus();
expect(status.state).toEqual('disconnected');
});
tap.test('Integration: client getStatistics returns zeros', async () => {
const stats = await client.getStatistics();
expect(stats.bytesSent).toEqual(0);
expect(stats.bytesReceived).toEqual(0);
expect(stats.packetsSent).toEqual(0);
expect(stats.packetsReceived).toEqual(0);
expect(stats.keepalivesSent).toEqual(0);
expect(stats.keepalivesReceived).toEqual(0);
expect(stats.uptimeSeconds).toEqual(0);
});
tap.test('Integration: stop client daemon', async () => {
client.stop();
await new Promise((resolve) => setTimeout(resolve, 500));
expect(client.running).toBeFalse();
});
tap.test('Integration: stop server daemon', async () => {
server.stop();
await new Promise((resolve) => setTimeout(resolve, 500));
expect(server.running).toBeFalse();
});
export default tap.start();