feat(dcrouter): Implement unified email configuration with pattern‐based routing and consolidated email processing. Migrate SMTP forwarding and store‐and‐forward into a single, configuration-driven system that supports glob pattern matching in domain rules.
This commit is contained in:
@ -2,9 +2,10 @@ import { tap, expect } from '@push.rocks/tapbundle';
|
||||
import * as plugins from '../ts/plugins.js';
|
||||
import {
|
||||
DcRouter,
|
||||
type IDcRouterOptions,
|
||||
type ISmtpForwardingConfig,
|
||||
type IDomainRoutingConfig
|
||||
type IDcRouterOptions,
|
||||
type IEmailConfig,
|
||||
type EmailProcessingMode,
|
||||
type IDomainRule
|
||||
} from '../ts/dcrouter/index.js';
|
||||
|
||||
tap.test('DcRouter class - basic functionality', async () => {
|
||||
@ -21,71 +22,97 @@ tap.test('DcRouter class - basic functionality', async () => {
|
||||
expect(router.options.tls.contactEmail).toEqual('test@example.com');
|
||||
});
|
||||
|
||||
tap.test('DcRouter class - HTTP routing configuration', async () => {
|
||||
// Create HTTP routing configuration
|
||||
const httpRoutes: IDomainRoutingConfig[] = [
|
||||
{
|
||||
domain: 'example.com',
|
||||
targetServer: '192.168.1.10',
|
||||
targetPort: 8080,
|
||||
useTls: true
|
||||
tap.test('DcRouter class - SmartProxy configuration', async () => {
|
||||
// Create SmartProxy configuration
|
||||
const smartProxyConfig: plugins.smartproxy.ISmartProxyOptions = {
|
||||
fromPort: 443,
|
||||
toPort: 8080,
|
||||
targetIP: '10.0.0.10',
|
||||
sniEnabled: true,
|
||||
acme: {
|
||||
port: 80,
|
||||
enabled: true,
|
||||
autoRenew: true,
|
||||
useProduction: false,
|
||||
renewThresholdDays: 30,
|
||||
accountEmail: 'admin@example.com'
|
||||
},
|
||||
{
|
||||
domain: '*.example.org',
|
||||
targetServer: '192.168.1.20',
|
||||
targetPort: 9000,
|
||||
useTls: false
|
||||
}
|
||||
];
|
||||
|
||||
const options: IDcRouterOptions = {
|
||||
httpDomainRoutes: httpRoutes,
|
||||
tls: {
|
||||
contactEmail: 'test@example.com'
|
||||
}
|
||||
};
|
||||
|
||||
const router = new DcRouter(options);
|
||||
expect(router.options.httpDomainRoutes.length).toEqual(2);
|
||||
expect(router.options.httpDomainRoutes[0].domain).toEqual('example.com');
|
||||
expect(router.options.httpDomainRoutes[1].domain).toEqual('*.example.org');
|
||||
});
|
||||
|
||||
tap.test('DcRouter class - SMTP forwarding configuration', async () => {
|
||||
// Create SMTP forwarding configuration
|
||||
const smtpForwarding: ISmtpForwardingConfig = {
|
||||
enabled: true,
|
||||
ports: [25, 587, 465],
|
||||
defaultServer: 'mail.example.com',
|
||||
defaultPort: 25,
|
||||
useTls: true,
|
||||
preserveSourceIp: true,
|
||||
domainRoutes: [
|
||||
globalPortRanges: [
|
||||
{ from: 80, to: 80 },
|
||||
{ from: 443, to: 443 }
|
||||
],
|
||||
domainConfigs: [
|
||||
{
|
||||
domain: 'example.com',
|
||||
server: 'mail1.example.com',
|
||||
port: 25
|
||||
},
|
||||
{
|
||||
domain: 'example.org',
|
||||
server: 'mail2.example.org',
|
||||
port: 587
|
||||
domains: ['example.com', 'www.example.com'],
|
||||
allowedIPs: ['0.0.0.0/0'],
|
||||
targetIPs: ['10.0.0.10'],
|
||||
portRanges: [
|
||||
{ from: 80, to: 80 },
|
||||
{ from: 443, to: 443 }
|
||||
]
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
const options: IDcRouterOptions = {
|
||||
smtpForwarding,
|
||||
smartProxyConfig,
|
||||
tls: {
|
||||
contactEmail: 'test@example.com'
|
||||
}
|
||||
};
|
||||
|
||||
const router = new DcRouter(options);
|
||||
expect(router.options.smtpForwarding.enabled).toEqual(true);
|
||||
expect(router.options.smtpForwarding.ports.length).toEqual(3);
|
||||
expect(router.options.smtpForwarding.domainRoutes.length).toEqual(2);
|
||||
expect(router.options.smtpForwarding.domainRoutes[0].domain).toEqual('example.com');
|
||||
expect(router.options.smartProxyConfig).toBeTruthy();
|
||||
expect(router.options.smartProxyConfig.domainConfigs.length).toEqual(1);
|
||||
expect(router.options.smartProxyConfig.domainConfigs[0].domains[0]).toEqual('example.com');
|
||||
});
|
||||
|
||||
tap.test('DcRouter class - Email configuration', async () => {
|
||||
// Create consolidated email configuration
|
||||
const emailConfig: IEmailConfig = {
|
||||
ports: [25, 587, 465],
|
||||
hostname: 'mail.example.com',
|
||||
maxMessageSize: 50 * 1024 * 1024, // 50MB
|
||||
|
||||
defaultMode: 'forward' as EmailProcessingMode,
|
||||
defaultServer: 'fallback-mail.example.com',
|
||||
defaultPort: 25,
|
||||
defaultTls: true,
|
||||
|
||||
domainRules: [
|
||||
{
|
||||
pattern: '*@example.com',
|
||||
mode: 'forward' as EmailProcessingMode,
|
||||
target: {
|
||||
server: 'mail1.example.com',
|
||||
port: 25,
|
||||
useTls: true
|
||||
}
|
||||
},
|
||||
{
|
||||
pattern: '*@example.org',
|
||||
mode: 'mta' as EmailProcessingMode,
|
||||
mtaOptions: {
|
||||
domain: 'example.org',
|
||||
allowLocalDelivery: true
|
||||
}
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
const options: IDcRouterOptions = {
|
||||
emailConfig,
|
||||
tls: {
|
||||
contactEmail: 'test@example.com'
|
||||
}
|
||||
};
|
||||
|
||||
const router = new DcRouter(options);
|
||||
expect(router.options.emailConfig).toBeTruthy();
|
||||
expect(router.options.emailConfig.ports.length).toEqual(3);
|
||||
expect(router.options.emailConfig.domainRules.length).toEqual(2);
|
||||
expect(router.options.emailConfig.domainRules[0].pattern).toEqual('*@example.com');
|
||||
expect(router.options.emailConfig.domainRules[1].pattern).toEqual('*@example.org');
|
||||
});
|
||||
|
||||
tap.test('DcRouter class - Domain pattern matching', async () => {
|
||||
|
Reference in New Issue
Block a user