dcrouter/test/suite/smtpclient_rfc-compliance/test.crfc-03.command-syntax.ts

67 lines
2.2 KiB
TypeScript
Raw Permalink Normal View History

2025-05-24 18:12:08 +00:00
import { expect, tap } from '@git.zone/tstest/tapbundle';
import { createTestServer } from '../../helpers/server.loader.js';
2025-05-26 14:50:55 +00:00
import { createTestSmtpClient } from '../../helpers/smtp.client.js';
import { Email } from '../../../ts/mail/core/classes.email.js';
2025-05-24 18:12:08 +00:00
2025-05-26 14:50:55 +00:00
tap.test('CRFC-03: SMTP Command Syntax Compliance', async () => {
console.log('\n📧 Testing SMTP Client Command Syntax Compliance');
console.log('=' .repeat(60));
2025-05-24 18:12:08 +00:00
2025-05-26 14:50:55 +00:00
const testServer = await createTestServer({});
2025-05-24 18:12:08 +00:00
2025-05-26 14:50:55 +00:00
try {
const smtpClient = createTestSmtpClient({
2025-05-24 18:12:08 +00:00
host: testServer.hostname,
2025-05-26 14:50:55 +00:00
port: testServer.port
2025-05-24 18:12:08 +00:00
});
2025-05-26 14:50:55 +00:00
console.log('\nTest 1: Valid email addresses');
const email1 = new Email({
2025-05-24 18:12:08 +00:00
from: 'sender@example.com',
to: ['recipient@example.com'],
2025-05-26 14:50:55 +00:00
subject: 'Valid email test',
text: 'Testing valid email addresses'
2025-05-24 18:12:08 +00:00
});
2025-05-26 14:50:55 +00:00
const result1 = await smtpClient.sendMail(email1);
console.log(' ✓ Valid email addresses accepted');
expect(result1).toBeDefined();
2025-05-24 18:12:08 +00:00
2025-05-26 14:50:55 +00:00
console.log('\nTest 2: Email with display names');
const email2 = new Email({
from: 'Test Sender <sender@example.com>',
to: ['Test Recipient <recipient@example.com>'],
subject: 'Display name test',
text: 'Testing email addresses with display names'
2025-05-24 18:12:08 +00:00
});
2025-05-26 14:50:55 +00:00
const result2 = await smtpClient.sendMail(email2);
console.log(' ✓ Display names handled correctly');
expect(result2).toBeDefined();
2025-05-24 18:12:08 +00:00
2025-05-26 14:50:55 +00:00
console.log('\nTest 3: Multiple recipients');
const email3 = new Email({
2025-05-24 18:12:08 +00:00
from: 'sender@example.com',
2025-05-26 14:50:55 +00:00
to: ['user1@example.com', 'user2@example.com'],
cc: ['cc@example.com'],
subject: 'Multiple recipients test',
text: 'Testing RCPT TO command with multiple recipients'
2025-05-24 18:12:08 +00:00
});
2025-05-26 14:50:55 +00:00
const result3 = await smtpClient.sendMail(email3);
console.log(' ✓ Multiple RCPT TO commands sent correctly');
expect(result3).toBeDefined();
2025-05-24 18:12:08 +00:00
2025-05-26 14:50:55 +00:00
console.log('\nTest 4: Connection test (HELO/EHLO)');
const verified = await smtpClient.verify();
console.log(' ✓ HELO/EHLO command syntax correct');
expect(verified).toBeDefined();
2025-05-24 18:12:08 +00:00
2025-05-26 14:50:55 +00:00
console.log('\n✅ CRFC-03: Command syntax compliance tests completed');
2025-05-24 18:12:08 +00:00
2025-05-26 14:50:55 +00:00
} finally {
testServer.server.close();
}
});
2025-05-24 18:12:08 +00:00
2025-05-26 14:50:55 +00:00
tap.start();