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

@ -35,7 +35,6 @@ import {
createHttpToHttpsRedirect,
createCompleteHttpsServer,
createLoadBalancerRoute,
createStaticFileRoute,
createApiRoute,
createWebSocketRoute
} from '../ts/proxies/smart-proxy/utils/route-helpers.js';
@ -87,9 +86,8 @@ tap.test('Routes: Should create HTTP to HTTPS redirect', async () => {
// Validate the route configuration
expect(redirectRoute.match.ports).toEqual(80);
expect(redirectRoute.match.domains).toEqual('example.com');
expect(redirectRoute.action.type).toEqual('redirect');
expect(redirectRoute.action.redirect?.to).toEqual('https://{domain}:443{path}');
expect(redirectRoute.action.redirect?.status).toEqual(301);
expect(redirectRoute.action.type).toEqual('socket-handler');
expect(redirectRoute.action.socketHandler).toBeDefined();
});
tap.test('Routes: Should create complete HTTPS server with redirects', async () => {
@ -111,8 +109,8 @@ tap.test('Routes: Should create complete HTTPS server with redirects', async ()
// Validate HTTP redirect route
const redirectRoute = routes[1];
expect(redirectRoute.match.ports).toEqual(80);
expect(redirectRoute.action.type).toEqual('redirect');
expect(redirectRoute.action.redirect?.to).toEqual('https://{domain}:443{path}');
expect(redirectRoute.action.type).toEqual('socket-handler');
expect(redirectRoute.action.socketHandler).toBeDefined();
});
tap.test('Routes: Should create load balancer route', async () => {
@ -190,24 +188,7 @@ tap.test('Routes: Should create WebSocket route', async () => {
}
});
tap.test('Routes: Should create static file route', async () => {
// Create a static file route
const staticRoute = createStaticFileRoute('static.example.com', '/var/www/html', {
serveOnHttps: true,
certificate: 'auto',
indexFiles: ['index.html', 'index.htm', 'default.html'],
name: 'Static File Route'
});
// Validate the route configuration
expect(staticRoute.match.domains).toEqual('static.example.com');
expect(staticRoute.action.type).toEqual('static');
expect(staticRoute.action.static?.root).toEqual('/var/www/html');
expect(staticRoute.action.static?.index).toBeInstanceOf(Array);
expect(staticRoute.action.static?.index).toInclude('index.html');
expect(staticRoute.action.static?.index).toInclude('default.html');
expect(staticRoute.action.tls?.mode).toEqual('terminate');
});
// Static file serving has been removed - should be handled by external servers
tap.test('SmartProxy: Should create instance with route-based config', async () => {
// Create TLS certificates for testing
@ -515,11 +496,6 @@ tap.test('Route Integration - Combining Multiple Route Types', async () => {
certificate: 'auto'
}),
// Static assets
createStaticFileRoute('static.example.com', '/var/www/assets', {
serveOnHttps: true,
certificate: 'auto'
}),
// Legacy system with passthrough
createHttpsPassthroughRoute('legacy.example.com', { host: 'legacy-server', port: 443 })
@ -540,11 +516,11 @@ tap.test('Route Integration - Combining Multiple Route Types', async () => {
expect(webServerMatch.action.target.host).toEqual('web-server');
}
// Web server (HTTP redirect)
// Web server (HTTP redirect via socket handler)
const webRedirectMatch = findBestMatchingRoute(routes, { domain: 'example.com', port: 80 });
expect(webRedirectMatch).not.toBeUndefined();
if (webRedirectMatch) {
expect(webRedirectMatch.action.type).toEqual('redirect');
expect(webRedirectMatch.action.type).toEqual('socket-handler');
}
// API server
@ -572,16 +548,7 @@ tap.test('Route Integration - Combining Multiple Route Types', async () => {
expect(wsMatch.action.websocket?.enabled).toBeTrue();
}
// Static assets
const staticMatch = findBestMatchingRoute(routes, {
domain: 'static.example.com',
port: 443
});
expect(staticMatch).not.toBeUndefined();
if (staticMatch) {
expect(staticMatch.action.type).toEqual('static');
expect(staticMatch.action.static.root).toEqual('/var/www/assets');
}
// Static assets route was removed - static file serving should be handled externally
// Legacy system
const legacyMatch = findBestMatchingRoute(routes, {