This commit is contained in:
2025-05-25 11:18:12 +00:00
parent 58f4a123d2
commit 5b33623c2d
15 changed files with 832 additions and 764 deletions

View File

@ -9,7 +9,7 @@ let authServer: ITestServer;
tap.test('setup - start SMTP server with authentication', async () => {
authServer = await startTestServer({
port: 2580,
tlsEnabled: false,
tlsEnabled: true, // Enable STARTTLS capability
authRequired: true
});
@ -19,12 +19,16 @@ tap.test('setup - start SMTP server with authentication', async () => {
tap.test('CCMD-05: AUTH - should fail without credentials', async () => {
let errorCaught = false;
let noAuthClient: SmtpClient | null = null;
try {
const noAuthClient = createSmtpClient({
noAuthClient = createSmtpClient({
host: authServer.hostname,
port: authServer.port,
secure: false,
secure: false, // Start plain, upgrade with STARTTLS
tls: {
rejectUnauthorized: false // Accept self-signed certs for testing
},
connectionTimeout: 5000
// No auth provided
});
@ -41,6 +45,11 @@ tap.test('CCMD-05: AUTH - should fail without credentials', async () => {
errorCaught = true;
expect(error).toBeInstanceOf(Error);
console.log('✅ Authentication required error:', error.message);
} finally {
// Ensure client is closed even if test fails
if (noAuthClient) {
await noAuthClient.close();
}
}
expect(errorCaught).toBeTrue();
@ -50,7 +59,10 @@ tap.test('CCMD-05: AUTH - should authenticate with PLAIN mechanism', async () =>
const plainAuthClient = createSmtpClient({
host: authServer.hostname,
port: authServer.port,
secure: false,
secure: false, // Start plain, upgrade with STARTTLS
tls: {
rejectUnauthorized: false // Accept self-signed certs for testing
},
connectionTimeout: 5000,
auth: {
user: 'testuser',
@ -81,7 +93,10 @@ tap.test('CCMD-05: AUTH - should authenticate with LOGIN mechanism', async () =>
const loginAuthClient = createSmtpClient({
host: authServer.hostname,
port: authServer.port,
secure: false,
secure: false, // Start plain, upgrade with STARTTLS
tls: {
rejectUnauthorized: false // Accept self-signed certs for testing
},
connectionTimeout: 5000,
auth: {
user: 'testuser',
@ -112,7 +127,10 @@ tap.test('CCMD-05: AUTH - should auto-select authentication method', async () =>
const autoAuthClient = createSmtpClient({
host: authServer.hostname,
port: authServer.port,
secure: false,
secure: false, // Start plain, upgrade with STARTTLS
tls: {
rejectUnauthorized: false // Accept self-signed certs for testing
},
connectionTimeout: 5000,
auth: {
user: 'testuser',
@ -135,7 +153,10 @@ tap.test('CCMD-05: AUTH - should handle invalid credentials', async () => {
const badAuthClient = createSmtpClient({
host: authServer.hostname,
port: authServer.port,
secure: false,
secure: false, // Start plain, upgrade with STARTTLS
tls: {
rejectUnauthorized: false // Accept self-signed certs for testing
},
connectionTimeout: 5000,
auth: {
user: 'wronguser',
@ -157,7 +178,10 @@ tap.test('CCMD-05: AUTH - should handle special characters in credentials', asyn
const specialAuthClient = createSmtpClient({
host: authServer.hostname,
port: authServer.port,
secure: false,
secure: false, // Start plain, upgrade with STARTTLS
tls: {
rejectUnauthorized: false // Accept self-signed certs for testing
},
connectionTimeout: 5000,
auth: {
user: 'user@domain.com',
@ -186,7 +210,7 @@ tap.test('CCMD-05: AUTH - should prefer secure auth over TLS', async () => {
const tlsAuthClient = createSmtpClient({
host: tlsAuthServer.hostname,
port: tlsAuthServer.port,
secure: true,
secure: false, // Use STARTTLS
connectionTimeout: 5000,
auth: {
user: 'testuser',
@ -209,7 +233,10 @@ tap.test('CCMD-05: AUTH - should maintain auth state across multiple sends', asy
const persistentAuthClient = createSmtpClient({
host: authServer.hostname,
port: authServer.port,
secure: false,
secure: false, // Start plain, upgrade with STARTTLS
tls: {
rejectUnauthorized: false // Accept self-signed certs for testing
},
connectionTimeout: 5000,
auth: {
user: 'testuser',
@ -240,7 +267,10 @@ tap.test('CCMD-05: AUTH - should handle auth with connection pooling', async ()
const pooledAuthClient = createSmtpClient({
host: authServer.hostname,
port: authServer.port,
secure: false,
secure: false, // Start plain, upgrade with STARTTLS
tls: {
rejectUnauthorized: false // Accept self-signed certs for testing
},
pool: true,
maxConnections: 3,
connectionTimeout: 5000,