update
This commit is contained in:
65
test/test.certificate-simple.ts
Normal file
65
test/test.certificate-simple.ts
Normal file
@ -0,0 +1,65 @@
|
||||
import { SmartProxy } from '../ts/proxies/smart-proxy/index.js';
|
||||
import { expect, tap } from '@push.rocks/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 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'
|
||||
};
|
||||
|
||||
const proxy = new SmartProxy({
|
||||
routes: [{
|
||||
name: 'static-test',
|
||||
match: { ports: 8080, path: '/test' },
|
||||
action: {
|
||||
type: 'static',
|
||||
handler: async () => testResponse
|
||||
}
|
||||
}]
|
||||
});
|
||||
|
||||
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);
|
||||
});
|
||||
|
||||
tap.start();
|
Reference in New Issue
Block a user