update
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
import { tap, expect } from '@git.zone/tstest/tapbundle';
|
||||
import { SzPlatformService } from '../ts/classes.platformservice.js';
|
||||
import { SpfVerifier, SpfQualifier, SpfMechanismType } from '../ts/mail/security/classes.spfverifier.js';
|
||||
import { DmarcVerifier, DmarcPolicy, DmarcAlignment } from '../ts/mail/security/classes.dmarcverifier.js';
|
||||
import { Email } from '../ts/mail/core/classes.email.js';
|
||||
@@ -8,54 +7,9 @@ import { Email } from '../ts/mail/core/classes.email.js';
|
||||
* Test email authentication systems: SPF and DMARC
|
||||
*/
|
||||
|
||||
// Setup platform service for testing
|
||||
let platformService: SzPlatformService;
|
||||
|
||||
tap.test('Setup test environment', async () => {
|
||||
// Create platform service with default config from the config module
|
||||
platformService = new SzPlatformService({
|
||||
id: 'test-platform-service',
|
||||
version: '1.0.0',
|
||||
environment: 'test',
|
||||
name: 'TestPlatformService',
|
||||
enabled: true,
|
||||
logging: {
|
||||
level: 'info',
|
||||
structured: true,
|
||||
correlationTracking: true
|
||||
},
|
||||
server: {
|
||||
enabled: true,
|
||||
host: '0.0.0.0',
|
||||
port: 3000,
|
||||
cors: true
|
||||
},
|
||||
email: {
|
||||
useMta: true,
|
||||
mtaConfig: {
|
||||
smtp: {
|
||||
enabled: true,
|
||||
port: 25,
|
||||
hostname: 'mta.test.local',
|
||||
maxSize: 10 * 1024 * 1024
|
||||
},
|
||||
security: {
|
||||
useDkim: true,
|
||||
verifyDkim: true,
|
||||
verifySpf: true,
|
||||
verifyDmarc: true
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
// Use start() instead of init() which doesn't exist
|
||||
await platformService.start();
|
||||
expect(platformService.mtaService).toBeTruthy();
|
||||
});
|
||||
|
||||
// SPF Verifier Tests
|
||||
tap.test('SPF Verifier - should parse SPF record', async () => {
|
||||
const spfVerifier = new SpfVerifier(platformService.mtaService);
|
||||
const spfVerifier = new SpfVerifier();
|
||||
|
||||
// Test valid SPF record parsing
|
||||
const record = 'v=spf1 a mx ip4:192.168.0.1/24 include:example.org ~all';
|
||||
@@ -89,7 +43,7 @@ tap.test('SPF Verifier - should parse SPF record', async () => {
|
||||
|
||||
// DMARC Verifier Tests
|
||||
tap.test('DMARC Verifier - should parse DMARC record', async () => {
|
||||
const dmarcVerifier = new DmarcVerifier(platformService.mtaService);
|
||||
const dmarcVerifier = new DmarcVerifier();
|
||||
|
||||
// Test valid DMARC record parsing
|
||||
const record = 'v=DMARC1; p=reject; sp=quarantine; pct=50; adkim=s; aspf=r; rua=mailto:dmarc@example.com';
|
||||
@@ -111,7 +65,7 @@ tap.test('DMARC Verifier - should parse DMARC record', async () => {
|
||||
});
|
||||
|
||||
tap.test('DMARC Verifier - should verify DMARC alignment', async () => {
|
||||
const dmarcVerifier = new DmarcVerifier(platformService.mtaService);
|
||||
const dmarcVerifier = new DmarcVerifier();
|
||||
|
||||
// Test email domains with DMARC alignment
|
||||
const email = new Email({
|
||||
@@ -142,7 +96,7 @@ tap.test('DMARC Verifier - should verify DMARC alignment', async () => {
|
||||
{ domain: 'anotherdomain.com', result: true } // DKIM - passed but not aligned
|
||||
);
|
||||
|
||||
// We can now see the actual DMARC result and update our expectations
|
||||
// Without a DNS manager, no DMARC record will be found
|
||||
|
||||
expect(dmarcResult2).toBeTruthy();
|
||||
expect(dmarcResult2.spfPassed).toEqual(true);
|
||||
@@ -150,14 +104,15 @@ tap.test('DMARC Verifier - should verify DMARC alignment', async () => {
|
||||
expect(dmarcResult2.spfDomainAligned).toEqual(false);
|
||||
expect(dmarcResult2.dkimDomainAligned).toEqual(false);
|
||||
|
||||
// The test environment is returning a 'reject' policy - we can verify that
|
||||
expect(dmarcResult2.policyEvaluated).toEqual('reject');
|
||||
expect(dmarcResult2.actualPolicy).toEqual('reject');
|
||||
expect(dmarcResult2.action).toEqual('reject');
|
||||
// Without a DMARC record, the default action is 'pass'
|
||||
expect(dmarcResult2.hasDmarc).toEqual(false);
|
||||
expect(dmarcResult2.policyEvaluated).toEqual(DmarcPolicy.NONE);
|
||||
expect(dmarcResult2.actualPolicy).toEqual(DmarcPolicy.NONE);
|
||||
expect(dmarcResult2.action).toEqual('pass');
|
||||
});
|
||||
|
||||
tap.test('DMARC Verifier - should apply policy correctly', async () => {
|
||||
const dmarcVerifier = new DmarcVerifier(platformService.mtaService);
|
||||
const dmarcVerifier = new DmarcVerifier();
|
||||
|
||||
// Create test email
|
||||
const email = new Email({
|
||||
@@ -233,10 +188,6 @@ tap.test('DMARC Verifier - should apply policy correctly', async () => {
|
||||
expect(email.mightBeSpam).toEqual(true);
|
||||
});
|
||||
|
||||
tap.test('Cleanup test environment', async () => {
|
||||
await platformService.stop();
|
||||
});
|
||||
|
||||
tap.test('stop', async () => {
|
||||
await tap.stopForcefully();
|
||||
});
|
||||
|
Reference in New Issue
Block a user