This commit is contained in:
2025-05-25 19:02:18 +00:00
parent 5b33623c2d
commit 4c9fd22a86
20 changed files with 1551 additions and 1451 deletions

View File

@ -1,15 +1,19 @@
import { tap, expect } from '@git.zone/tstest/tapbundle';
import { startTestSmtpServer } from '../../helpers/server.loader.js';
import { createSmtpClient } from '../../helpers/smtp.client.js';
import { startTestServer, stopTestServer, type ITestServer } from '../../helpers/server.loader.js';
import { createSmtpClient } from '../../../ts/mail/delivery/smtpclient/index.js';
import * as net from 'net';
import * as os from 'os';
let testServer: any;
let testServer: ITestServer;
tap.test('setup test SMTP server', async () => {
testServer = await startTestSmtpServer();
testServer = await startTestServer({
port: 2535,
tlsEnabled: false,
authRequired: false
});
expect(testServer).toBeTruthy();
expect(testServer.port).toBeGreaterThan(0);
expect(testServer.port).toEqual(2535);
});
tap.test('CCM-09: Check system IPv6 support', async () => {
@ -40,26 +44,11 @@ tap.test('CCM-09: IPv4 connection test', async () => {
debug: true
});
let connected = false;
let connectionFamily = '';
smtpClient.on('connection', (info: any) => {
connected = true;
if (info && info.socket) {
connectionFamily = info.socket.remoteFamily || '';
}
});
smtpClient.on('error', (error: Error) => {
console.error('IPv4 connection error:', error.message);
});
// Test connection
const result = await smtpClient.connect();
expect(result).toBeTruthy();
expect(smtpClient.isConnected()).toBeTruthy();
// Test connection using verify
const verified = await smtpClient.verify();
expect(verified).toBeTrue();
console.log(`Connected via IPv4, family: ${connectionFamily}`);
console.log('Successfully connected via IPv4');
await smtpClient.close();
});
@ -99,27 +88,15 @@ tap.test('CCM-09: IPv6 connection test (if supported)', async () => {
debug: true
});
let connected = false;
let connectionFamily = '';
smtpClient.on('connection', (info: any) => {
connected = true;
if (info && info.socket) {
connectionFamily = info.socket.remoteFamily || '';
}
});
smtpClient.on('error', (error: Error) => {
console.error('IPv6 connection error:', error.message);
});
try {
const result = await smtpClient.connect();
if (result && smtpClient.isConnected()) {
console.log(`Connected via IPv6, family: ${connectionFamily}`);
const verified = await smtpClient.verify();
if (verified) {
console.log('Successfully connected via IPv6');
await smtpClient.close();
} else {
console.log('IPv6 connection failed (server may not support IPv6)');
}
} catch (error) {
} catch (error: any) {
console.log('IPv6 connection failed (server may not support IPv6):', error.message);
}
});
@ -134,21 +111,10 @@ tap.test('CCM-09: Hostname resolution preference', async () => {
debug: true
});
let connectionInfo: any = null;
const verified = await smtpClient.verify();
expect(verified).toBeTrue();
smtpClient.on('connection', (info: any) => {
connectionInfo = info;
});
const result = await smtpClient.connect();
expect(result).toBeTruthy();
expect(smtpClient.isConnected()).toBeTruthy();
if (connectionInfo && connectionInfo.socket) {
console.log(`Connected to localhost via ${connectionInfo.socket.remoteFamily || 'unknown'}`);
console.log(`Local address: ${connectionInfo.socket.localAddress}`);
console.log(`Remote address: ${connectionInfo.socket.remoteAddress}`);
}
console.log('Successfully connected to localhost');
await smtpClient.close();
});
@ -169,11 +135,11 @@ tap.test('CCM-09: Happy Eyeballs algorithm simulation', async () => {
});
try {
const connected = await smtpClient.connect();
const verified = await smtpClient.verify();
const elapsed = Date.now() - startTime;
results.push({ address, time: elapsed, success: !!connected });
results.push({ address, time: elapsed, success: verified });
if (connected) {
if (verified) {
await smtpClient.close();
}
} catch (error) {
@ -194,8 +160,8 @@ tap.test('CCM-09: Happy Eyeballs algorithm simulation', async () => {
tap.test('cleanup test SMTP server', async () => {
if (testServer) {
await testServer.stop();
await stopTestServer(testServer);
}
});
export default tap.start();
tap.start();