This commit is contained in:
2025-05-29 10:13:41 +00:00
parent 200a735876
commit 6a08bbc558
14 changed files with 211 additions and 303 deletions

View File

@ -25,41 +25,36 @@ tap.test('should create SmartProxy with certificate routes', async () => {
expect(proxy.settings.routes.length).toEqual(1);
});
tap.test('should handle static route type', async () => {
// Create a test route with static handler
const testResponse = {
status: 200,
headers: { 'Content-Type': 'text/plain' },
body: 'Hello from static route'
};
tap.test('should handle socket handler route type', async () => {
// Create a test route with socket handler
const proxy = new SmartProxy({
routes: [{
name: 'static-test',
name: 'socket-handler-test',
match: { ports: 8080, path: '/test' },
action: {
type: 'static',
handler: async () => testResponse
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('static');
expect(route.action.handler).toBeDefined();
// Test the handler
const result = await route.action.handler!({
port: 8080,
path: '/test',
clientIp: '127.0.0.1',
serverIp: '127.0.0.1',
isTls: false,
timestamp: Date.now(),
connectionId: 'test-123'
});
expect(result).toEqual(testResponse);
expect(route.action.type).toEqual('socket-handler');
expect(route.action.socketHandler).toBeDefined();
});
tap.start();