1+ #!/usr/bin/env node
2+ /**
3+ * Test script for adjustEndpoints CNAME support
4+ */
5+
6+ // Mock logger
7+ const logger = {
8+ info : ( ) => { } ,
9+ warn : ( ) => { } ,
10+ debug : ( ) => { }
11+ } ;
12+
13+ // Mock validator
14+ const validator = {
15+ isValidEndpoint : ( endpoint ) => {
16+ // Simple validation - just check required fields exist
17+ return endpoint && endpoint . dnsName && endpoint . targets && endpoint . recordType ;
18+ }
19+ } ;
20+
21+ // Mock config
22+ const config = {
23+ contentType : 'application/external.dns.webhook+json;version=1'
24+ } ;
25+
26+ // Mock express objects
27+ const mockReq = {
28+ body : [ ] ,
29+ get : ( ) => null
30+ } ;
31+
32+ const mockRes = {
33+ status : function ( code ) { this . statusCode = code ; return this ; } ,
34+ json : function ( data ) { this . data = data ; return this ; } ,
35+ setHeader : function ( ) { } ,
36+ send : function ( data ) { this . sentData = data ; }
37+ } ;
38+
39+ // Import and test adjustEndpoints
40+ const adjustEndpoints = require ( './src/controllers/adjustEndpoints' ) ;
41+
42+ // Test data
43+ const testEndpoints = [
44+ { dnsName : 'a.example.com' , targets : [ '1.2.3.4' ] , recordType : 'A' } ,
45+ { dnsName : 'txt.example.com' , targets : [ 'test=value' ] , recordType : 'TXT' } ,
46+ { dnsName : 'cname.example.com' , targets : [ 'target.example.com' ] , recordType : 'CNAME' } ,
47+ { dnsName : 'invalid.example.com' , targets : [ '1.2.3.4' ] , recordType : 'AAAA' } // Should be filtered out
48+ ] ;
49+
50+ console . log ( 'Testing adjustEndpoints CNAME support...' ) ;
51+
52+ // Mock the request
53+ mockReq . body = testEndpoints ;
54+
55+ // Call adjustEndpoints
56+ adjustEndpoints ( mockReq , mockRes ) ;
57+
58+ // Parse the response
59+ const response = JSON . parse ( mockRes . sentData ) ;
60+ console . log ( 'Original endpoints:' , testEndpoints . length ) ;
61+ console . log ( 'Filtered endpoints:' , response . length ) ;
62+
63+ console . log ( 'Results:' ) ;
64+ response . forEach ( endpoint => {
65+ console . log ( ` ${ endpoint . recordType } : ${ endpoint . dnsName } ` ) ;
66+ } ) ;
67+
68+ const cnameCount = response . filter ( e => e . recordType === 'CNAME' ) . length ;
69+ const aCount = response . filter ( e => e . recordType === 'A' ) . length ;
70+ const txtCount = response . filter ( e => e . recordType === 'TXT' ) . length ;
71+ const invalidCount = response . filter ( e => e . recordType === 'AAAA' ) . length ;
72+
73+ console . log ( `\nSummary:` ) ;
74+ console . log ( ` A records: ${ aCount } ` ) ;
75+ console . log ( ` TXT records: ${ txtCount } ` ) ;
76+ console . log ( ` CNAME records: ${ cnameCount } ` ) ;
77+ console . log ( ` Invalid records: ${ invalidCount } ` ) ;
78+
79+ if ( cnameCount > 0 && invalidCount === 0 ) {
80+ console . log ( '\n✅ SUCCESS: CNAME records are now supported and invalid records are filtered!' ) ;
81+ } else {
82+ console . log ( '\n❌ FAILURE: CNAME support test failed' ) ;
83+ }
0 commit comments