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:
@@ -48,85 +48,91 @@ tap.test('Storage Persistence Across Restarts', async () => {
|
||||
tap.test('DKIM Storage Integration', async () => {
|
||||
const testDir = plugins.path.join(paths.dataDir, '.test-integration-dkim');
|
||||
const keysDir = plugins.path.join(testDir, 'keys');
|
||||
|
||||
|
||||
// Ensure the keys directory exists before running the test
|
||||
await plugins.fs.promises.mkdir(keysDir, { recursive: true });
|
||||
|
||||
// Phase 1: Generate DKIM keys with storage
|
||||
{
|
||||
const storage = new StorageManager({ fsPath: testDir });
|
||||
const dkimCreator = new DKIMCreator(keysDir, storage);
|
||||
|
||||
|
||||
await dkimCreator.handleDKIMKeysForDomain('storage.example.com');
|
||||
|
||||
|
||||
// Verify keys exist
|
||||
const keys = await dkimCreator.readDKIMKeys('storage.example.com');
|
||||
expect(keys.privateKey).toBeTruthy();
|
||||
expect(keys.publicKey).toBeTruthy();
|
||||
}
|
||||
|
||||
|
||||
// Phase 2: New instance should find keys in storage
|
||||
{
|
||||
const storage = new StorageManager({ fsPath: testDir });
|
||||
const dkimCreator = new DKIMCreator(keysDir, storage);
|
||||
|
||||
|
||||
// Keys should be loaded from storage
|
||||
const keys = await dkimCreator.readDKIMKeys('storage.example.com');
|
||||
expect(keys.privateKey).toBeTruthy();
|
||||
expect(keys.publicKey).toBeTruthy();
|
||||
expect(keys.privateKey).toContain('BEGIN RSA PRIVATE KEY');
|
||||
}
|
||||
|
||||
|
||||
// Clean up
|
||||
await plugins.fs.promises.rm(testDir, { recursive: true, force: true }).catch(() => {});
|
||||
});
|
||||
|
||||
tap.test('Bounce Manager Storage Integration', async () => {
|
||||
const testDir = plugins.path.join(paths.dataDir, '.test-integration-bounce');
|
||||
|
||||
|
||||
// Phase 1: Add to suppression list with storage
|
||||
{
|
||||
const storage = new StorageManager({ fsPath: testDir });
|
||||
const bounceManager = new BounceManager({
|
||||
storageManager: storage
|
||||
});
|
||||
|
||||
|
||||
// Wait for constructor's async loadSuppressionList to complete
|
||||
await new Promise(resolve => setTimeout(resolve, 200));
|
||||
|
||||
// Add emails to suppression list
|
||||
bounceManager.addToSuppressionList('bounce1@example.com', 'Hard bounce: invalid_recipient');
|
||||
bounceManager.addToSuppressionList('bounce2@example.com', 'Soft bounce: temporary', Date.now() + 3600000);
|
||||
|
||||
|
||||
// Verify suppression
|
||||
expect(bounceManager.isEmailSuppressed('bounce1@example.com')).toEqual(true);
|
||||
expect(bounceManager.isEmailSuppressed('bounce2@example.com')).toEqual(true);
|
||||
|
||||
// Wait for async save to complete (addToSuppressionList saves asynchronously)
|
||||
await new Promise(resolve => setTimeout(resolve, 500));
|
||||
}
|
||||
|
||||
// Wait a moment to ensure async save completes
|
||||
await new Promise(resolve => setTimeout(resolve, 100));
|
||||
|
||||
|
||||
// Phase 2: New instance should load suppression list from storage
|
||||
{
|
||||
const storage = new StorageManager({ fsPath: testDir });
|
||||
const bounceManager = new BounceManager({
|
||||
storageManager: storage
|
||||
});
|
||||
|
||||
// Wait for async load
|
||||
await new Promise(resolve => setTimeout(resolve, 100));
|
||||
|
||||
|
||||
// Wait for async load to complete
|
||||
await new Promise(resolve => setTimeout(resolve, 500));
|
||||
|
||||
// Verify persistence
|
||||
expect(bounceManager.isEmailSuppressed('bounce1@example.com')).toEqual(true);
|
||||
expect(bounceManager.isEmailSuppressed('bounce2@example.com')).toEqual(true);
|
||||
expect(bounceManager.isEmailSuppressed('notbounced@example.com')).toEqual(false);
|
||||
|
||||
|
||||
// Check suppression info
|
||||
const info1 = bounceManager.getSuppressionInfo('bounce1@example.com');
|
||||
expect(info1).toBeTruthy();
|
||||
expect(info1?.reason).toContain('Hard bounce');
|
||||
expect(info1?.expiresAt).toBeUndefined(); // Permanent
|
||||
|
||||
|
||||
const info2 = bounceManager.getSuppressionInfo('bounce2@example.com');
|
||||
expect(info2).toBeTruthy();
|
||||
expect(info2?.reason).toContain('Soft bounce');
|
||||
expect(info2?.expiresAt).toBeGreaterThan(Date.now());
|
||||
}
|
||||
|
||||
|
||||
// Clean up
|
||||
await plugins.fs.promises.rm(testDir, { recursive: true, force: true }).catch(() => {});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user