@@ -9,6 +9,7 @@ import type { SinonSandbox } from 'sinon';
9
9
import sinon from 'sinon' ;
10
10
import { promisify } from 'util' ;
11
11
import { randomBytes } from 'crypto' ;
12
+ import { promises as dns } from 'dns' ;
12
13
13
14
// node-fetch@3 is ESM-only...
14
15
// eslint-disable-next-line @typescript-eslint/consistent-type-imports
@@ -485,4 +486,71 @@ describe('RFC8252HTTPServer', function () {
485
486
} ) ;
486
487
} ) ;
487
488
} ) ;
489
+
490
+ context ( 'with dns duplicates' , function ( ) {
491
+ const originalDnsLookup = dns . lookup ;
492
+ let dnsLookupStub : sinon . SinonStub ;
493
+
494
+ this . beforeEach ( function ( ) {
495
+ dnsLookupStub = sinon . stub ( ) ;
496
+ dns . lookup = dnsLookupStub ;
497
+ } ) ;
498
+
499
+ this . afterEach ( function ( ) {
500
+ dns . lookup = originalDnsLookup ;
501
+ } ) ;
502
+
503
+ it ( 'only filters exact duplicates' , async function ( ) {
504
+ dnsLookupStub . resolves ( [
505
+ { address : '127.0.0.1' , family : 4 } ,
506
+ { address : '127.0.0.1' , family : 4 } ,
507
+ { address : '[::1]' , family : 6 } ,
508
+ { address : '[::1]' , family : 6 } ,
509
+ ] ) ;
510
+
511
+ const interfaces = await RFC8252HTTPServer [ '_getAllInterfaces' ] . call (
512
+ 'localhost'
513
+ ) ;
514
+
515
+ expect ( interfaces ) . to . have . lengthOf ( 2 ) ;
516
+ expect ( interfaces [ 0 ] . address ) . to . equal ( '127.0.0.1' ) ;
517
+ expect ( interfaces [ 1 ] . address ) . to . equal ( '[::1]' ) ;
518
+ expect ( interfaces [ 0 ] . family ) . to . equal ( 4 ) ;
519
+ expect ( interfaces [ 1 ] . family ) . to . equal ( 6 ) ;
520
+ } ) ;
521
+
522
+ it ( 'keeps same addresses, different family' , async function ( ) {
523
+ dnsLookupStub . resolves ( [
524
+ { address : '127.0.0.1' , family : 4 } ,
525
+ { address : '127.0.0.1' , family : 6 } ,
526
+ ] ) ;
527
+
528
+ const interfaces = await RFC8252HTTPServer [ '_getAllInterfaces' ] . call (
529
+ 'localhost'
530
+ ) ;
531
+
532
+ expect ( interfaces ) . to . have . lengthOf ( 2 ) ;
533
+ expect ( interfaces [ 0 ] . address ) . to . equal ( '127.0.0.1' ) ;
534
+ expect ( interfaces [ 1 ] . address ) . to . equal ( '127.0.0.1' ) ;
535
+ expect ( interfaces [ 0 ] . family ) . to . equal ( 4 ) ;
536
+ expect ( interfaces [ 1 ] . family ) . to . equal ( 6 ) ;
537
+ } ) ;
538
+
539
+ it ( 'keeps same familes, different address' , async function ( ) {
540
+ dnsLookupStub . resolves ( [
541
+ { address : '127.0.0.1' , family : 4 } ,
542
+ { address : '192.168.1.15' , family : 4 } ,
543
+ ] ) ;
544
+
545
+ const interfaces = await RFC8252HTTPServer [ '_getAllInterfaces' ] . call (
546
+ 'localhost'
547
+ ) ;
548
+
549
+ expect ( interfaces ) . to . have . lengthOf ( 2 ) ;
550
+ expect ( interfaces [ 0 ] . address ) . to . equal ( '127.0.0.1' ) ;
551
+ expect ( interfaces [ 1 ] . address ) . to . equal ( '192.168.1.15' ) ;
552
+ expect ( interfaces [ 0 ] . family ) . to . equal ( 4 ) ;
553
+ expect ( interfaces [ 1 ] . family ) . to . equal ( 4 ) ;
554
+ } ) ;
555
+ } ) ;
488
556
} ) ;
0 commit comments