smartproxy/test/test.certificate-simple.ts

60 lines
1.6 KiB
TypeScript
Raw Normal View History

2025-05-18 15:51:09 +00:00
import { SmartProxy } from '../ts/proxies/smart-proxy/index.js';
2025-05-19 12:04:26 +00:00
import { expect, tap } from '@git.zone/tstest/tapbundle';
2025-05-18 15:51:09 +00:00
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);
});
2025-05-29 10:13:41 +00:00
tap.test('should handle socket handler route type', async () => {
// Create a test route with socket handler
2025-05-18 15:51:09 +00:00
const proxy = new SmartProxy({
routes: [{
2025-05-29 10:13:41 +00:00
name: 'socket-handler-test',
2025-05-18 15:51:09 +00:00
match: { ports: 8080, path: '/test' },
action: {
2025-05-29 10:13:41 +00:00
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();
});
}
2025-05-18 15:51:09 +00:00
}
}]
});
const route = proxy.settings.routes[0];
2025-05-29 10:13:41 +00:00
expect(route.action.type).toEqual('socket-handler');
expect(route.action.socketHandler).toBeDefined();
2025-05-18 15:51:09 +00:00
});
tap.start();