smartproxy/test/test.certificate-simple.ts
2025-05-29 10:13:41 +00:00

60 lines
1.6 KiB
TypeScript

import { SmartProxy } from '../ts/proxies/smart-proxy/index.js';
import { expect, tap } from '@git.zone/tstest/tapbundle';
tap.test('should create SmartProxy with certificate routes', async () => {
const proxy = new SmartProxy({
routes: [{
name: 'test-route',
match: { ports: 8443, domains: 'test.example.com' },
action: {
type: 'forward',
target: { host: 'localhost', port: 8080 },
tls: {
mode: 'terminate',
certificate: 'auto',
acme: {
email: 'test@example.com',
useProduction: false
}
}
}
}]
});
expect(proxy).toBeDefined();
expect(proxy.settings.routes.length).toEqual(1);
});
tap.test('should handle socket handler route type', async () => {
// Create a test route with socket handler
const proxy = new SmartProxy({
routes: [{
name: 'socket-handler-test',
match: { ports: 8080, path: '/test' },
action: {
type: 'socket-handler',
socketHandler: (socket, context) => {
socket.once('data', (data) => {
const response = [
'HTTP/1.1 200 OK',
'Content-Type: text/plain',
'Content-Length: 23',
'Connection: close',
'',
'Hello from socket handler'
].join('\r\n');
socket.write(response);
socket.end();
});
}
}
}]
});
const route = proxy.settings.routes[0];
expect(route.action.type).toEqual('socket-handler');
expect(route.action.socketHandler).toBeDefined();
});
tap.start();