test(dns): add comprehensive tests for DNS record creation

- Add test.dns-manager-creation.ts to verify DNS record creation
- Test MX, SPF, DMARC, and DKIM record registration
- Verify records are stored in StorageManager
- Update readme.hints.md with DNS architecture refactoring notes
This commit is contained in:
2025-05-30 09:29:03 +00:00
parent 37e1ecefd2
commit ad0ab6c103
2 changed files with 186 additions and 1 deletions

View File

@ -835,4 +835,48 @@ Rate limiting is now fully integrated into SMTP server handlers:
The only remaining item is implementing hour/day rate limits in the UnifiedRateLimiter, which would require:
1. Additional counters for hourly and daily windows
2. Separate tracking for these longer time periods
3. Cleanup logic for expired hourly/daily counters
3. Cleanup logic for expired hourly/daily counters
## DNS Architecture Refactoring (2025-05-30) - COMPLETED
### Overview
The DNS functionality has been refactored from UnifiedEmailServer to a dedicated DnsManager class for better discoverability and separation of concerns.
### Key Changes
1. **Renamed DnsValidator to DnsManager:**
- Extended functionality to handle both validation and creation of DNS records
- Added `ensureDnsRecords()` as the main entry point
- Moved DNS record creation logic from UnifiedEmailServer
2. **DnsManager Responsibilities:**
- Validate DNS configuration for all modes (forward, internal-dns, external-dns)
- Create DNS records for internal-dns domains
- Create DKIM records for all domains (when DKIMCreator is provided)
- Store DNS records in StorageManager for persistence
3. **DNS Record Creation Flow:**
```typescript
// In UnifiedEmailServer
const dnsManager = new DnsManager(this.dcRouter);
await dnsManager.ensureDnsRecords(domainConfigs, this.dkimCreator);
```
4. **Testing Pattern for DNS:**
- Mock the DNS server in tests by providing a mock `registerHandler` function
- Store handlers in a Map with key format: `${domain}:${types.join(',')}`
- Retrieve handlers with key format: `${domain}:${type}`
- Example mock implementation:
```typescript
this.dnsServer = {
registerHandler: (name: string, types: string[], handler: () => any) => {
const key = `${name}:${types.join(',')}`;
this.dnsHandlers.set(key, handler);
}
};
```
### Benefits
- DNS functionality is now easily discoverable in DnsManager
- Clear separation between DNS management and email server logic
- UnifiedEmailServer is simpler and more focused
- All DNS-related tests pass successfully