2025-05-23 19:03:44 +00:00
|
|
|
import { tap, expect } from '@git.zone/tstest/tapbundle';
|
2025-05-23 21:20:39 +00:00
|
|
|
import { startTestServer, stopTestServer, type ITestServer } from '../../helpers/server.loader.js';
|
2025-05-23 19:49:25 +00:00
|
|
|
import type { SmtpServer } from '../../../ts/mail/delivery/smtpserver/index.js';
|
2025-05-23 21:20:39 +00:00
|
|
|
import { connectToSmtp, performSmtpHandshake, closeSmtpConnection } from '../../helpers/utils.js';
|
2025-05-23 19:03:44 +00:00
|
|
|
|
2025-05-23 19:49:25 +00:00
|
|
|
let testServer: SmtpServer;
|
2025-05-23 19:03:44 +00:00
|
|
|
|
|
|
|
tap.test('setup - start SMTP server with TLS support', async () => {
|
2025-05-23 21:20:39 +00:00
|
|
|
testServer = await startTestServer({
|
|
|
|
port: 2525,
|
|
|
|
tlsEnabled: true // Enable TLS support
|
|
|
|
});
|
2025-05-23 19:49:25 +00:00
|
|
|
|
|
|
|
await new Promise(resolve => setTimeout(resolve, 1000));
|
2025-05-23 19:03:44 +00:00
|
|
|
expect(testServer.port).toEqual(2525);
|
|
|
|
});
|
|
|
|
|
|
|
|
tap.test('CM-01: TLS Connection Test - server should advertise STARTTLS capability', async () => {
|
|
|
|
const startTime = Date.now();
|
|
|
|
|
|
|
|
try {
|
|
|
|
// Connect to SMTP server
|
|
|
|
const socket = await connectToSmtp(testServer.hostname, testServer.port);
|
|
|
|
expect(socket).toBeInstanceOf(Object);
|
|
|
|
|
|
|
|
// Perform handshake and get capabilities
|
|
|
|
const capabilities = await performSmtpHandshake(socket, 'test.example.com');
|
|
|
|
expect(capabilities).toBeArray();
|
|
|
|
|
|
|
|
// Check for STARTTLS support
|
|
|
|
const supportsStarttls = capabilities.some(cap => cap.toUpperCase().includes('STARTTLS'));
|
2025-05-23 21:20:39 +00:00
|
|
|
expect(supportsStarttls).toEqual(true);
|
2025-05-23 19:03:44 +00:00
|
|
|
|
|
|
|
// Close connection gracefully
|
|
|
|
await closeSmtpConnection(socket);
|
|
|
|
|
|
|
|
const duration = Date.now() - startTime;
|
|
|
|
console.log(`✅ TLS capability test completed in ${duration}ms`);
|
|
|
|
console.log(`📋 Server capabilities: ${capabilities.join(', ')}`);
|
|
|
|
|
|
|
|
} catch (error) {
|
|
|
|
const duration = Date.now() - startTime;
|
|
|
|
console.error(`❌ TLS connection test failed after ${duration}ms:`, error);
|
|
|
|
throw error;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
tap.test('CM-01: TLS Connection Test - verify TLS certificate configuration', async () => {
|
|
|
|
// This test verifies that the server has TLS certificates configured
|
2025-05-23 21:20:39 +00:00
|
|
|
expect(testServer.config.tlsEnabled).toEqual(true);
|
2025-05-23 19:03:44 +00:00
|
|
|
|
|
|
|
// The server should have loaded certificates during startup
|
|
|
|
// In production, this would validate actual certificate properties
|
|
|
|
console.log('✅ TLS configuration verified');
|
|
|
|
});
|
|
|
|
|
|
|
|
tap.test('cleanup - stop SMTP server', async () => {
|
2025-05-23 21:20:39 +00:00
|
|
|
await stopTestServer(testServer);
|
2025-05-23 19:03:44 +00:00
|
|
|
console.log('✅ Test server stopped');
|
|
|
|
});
|
|
|
|
|
|
|
|
tap.start();
|