fix(tests): update tests and test helpers to current email/DNS APIs, use non-privileged ports, and improve robustness and resilience
This commit is contained in:
@@ -11,11 +11,12 @@ import type { IEmailDomainConfig } from '../ts/mail/routing/interfaces.js';
|
||||
class MockDcRouter {
|
||||
public storageManager: StorageManager;
|
||||
public options: any;
|
||||
|
||||
constructor(testDir: string, dnsDomain?: string) {
|
||||
|
||||
constructor(testDir: string, dnsNsDomains?: string[], dnsScopes?: string[]) {
|
||||
this.storageManager = new StorageManager({ fsPath: testDir });
|
||||
this.options = {
|
||||
dnsDomain
|
||||
dnsNsDomains,
|
||||
dnsScopes
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -78,12 +79,17 @@ tap.test('DNS Validator - Forward Mode', async () => {
|
||||
|
||||
tap.test('DNS Validator - Internal DNS Mode', async () => {
|
||||
const testDir = plugins.path.join(paths.dataDir, '.test-dns-internal');
|
||||
const mockRouter = new MockDcRouter(testDir, 'ns.myservice.com') as any;
|
||||
// Configure with dnsNsDomains array and dnsScopes that include the test domain
|
||||
const mockRouter = new MockDcRouter(
|
||||
testDir,
|
||||
['ns.myservice.com', 'ns2.myservice.com'], // dnsNsDomains
|
||||
['mail.example.com', 'mail2.example.com'] // dnsScopes - must include all internal-dns domains
|
||||
) as any;
|
||||
const validator = new MockDnsManager(mockRouter);
|
||||
|
||||
|
||||
// Setup NS delegation
|
||||
validator.setNsRecords('mail.example.com', ['ns.myservice.com']);
|
||||
|
||||
|
||||
const config: IEmailDomainConfig = {
|
||||
domain: 'mail.example.com',
|
||||
dnsMode: 'internal-dns',
|
||||
@@ -94,27 +100,27 @@ tap.test('DNS Validator - Internal DNS Mode', async () => {
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
const result = await validator.validateDomain(config);
|
||||
|
||||
|
||||
expect(result.valid).toEqual(true);
|
||||
expect(result.errors.length).toEqual(0);
|
||||
|
||||
// Test without NS delegation
|
||||
|
||||
// Test without NS delegation (domain is in scopes, but NS not yet delegated)
|
||||
validator.setNsRecords('mail2.example.com', ['other.nameserver.com']);
|
||||
|
||||
|
||||
const config2: IEmailDomainConfig = {
|
||||
domain: 'mail2.example.com',
|
||||
dnsMode: 'internal-dns'
|
||||
};
|
||||
|
||||
|
||||
const result2 = await validator.validateDomain(config2);
|
||||
|
||||
|
||||
// Should have warnings but still be valid (warnings don't make it invalid)
|
||||
expect(result2.valid).toEqual(true);
|
||||
expect(result2.warnings.length).toBeGreaterThan(0);
|
||||
expect(result2.requiredChanges.length).toBeGreaterThan(0);
|
||||
|
||||
|
||||
// Clean up
|
||||
await plugins.fs.promises.rm(testDir, { recursive: true, force: true }).catch(() => {});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user