feat(mail/delivery): add error-count based blocking to rate limiter; improve test SMTP server port selection; add tsbuild scripts and devDependency; remove stale backup file
This commit is contained in:
@@ -30,8 +30,19 @@ export interface ITestServer {
|
||||
* Starts a test SMTP server with the given configuration
|
||||
*/
|
||||
export async function startTestServer(config: ITestServerConfig): Promise<ITestServer> {
|
||||
// Find a free port if one wasn't specified
|
||||
// Using smartnetwork to find an available port in the range 10000-60000
|
||||
let port = config.port;
|
||||
if (port === undefined || port === 0) {
|
||||
const network = new plugins.smartnetwork.Network();
|
||||
port = await network.findFreePort(10000, 60000, { randomize: true });
|
||||
if (!port) {
|
||||
throw new Error('No free ports available in range 10000-60000');
|
||||
}
|
||||
}
|
||||
|
||||
const serverConfig = {
|
||||
port: config.port || 2525,
|
||||
port: port, // Use the found free port
|
||||
hostname: config.hostname || 'localhost',
|
||||
tlsEnabled: config.tlsEnabled || false,
|
||||
authRequired: config.authRequired || false,
|
||||
@@ -57,6 +68,7 @@ export async function startTestServer(config: ITestServerConfig): Promise<ITestS
|
||||
recordAuthenticationFailure: async (_ip: string) => {},
|
||||
recordSyntaxError: async (_ip: string) => {},
|
||||
recordCommandError: async (_ip: string) => {},
|
||||
recordError: (_key: string) => false, // Return false to not block during tests
|
||||
isBlocked: async (_ip: string) => false,
|
||||
cleanup: async () => {}
|
||||
};
|
||||
@@ -157,19 +169,19 @@ export async function startTestServer(config: ITestServerConfig): Promise<ITestS
|
||||
|
||||
// Create SMTP server
|
||||
const smtpServer = await createSmtpServer(mockEmailServer, smtpOptions);
|
||||
|
||||
|
||||
// Start the server
|
||||
await smtpServer.listen();
|
||||
|
||||
|
||||
// Wait for server to be ready
|
||||
await waitForServerReady(serverConfig.hostname, serverConfig.port);
|
||||
|
||||
|
||||
console.log(`✅ Test SMTP server started on ${serverConfig.hostname}:${serverConfig.port}`);
|
||||
|
||||
|
||||
return {
|
||||
server: mockEmailServer,
|
||||
smtpServer: smtpServer,
|
||||
port: serverConfig.port,
|
||||
port: serverConfig.port, // Return the port we already know
|
||||
hostname: serverConfig.hostname,
|
||||
config: serverConfig,
|
||||
startTime: Date.now()
|
||||
|
||||
Reference in New Issue
Block a user