@@ -65,6 +65,18 @@ describe('Utility Functions', () => {
6565 expect ( result ) . toBeInstanceOf ( Array ) ;
6666 expect ( result . length ) . toBe ( 4 ) ;
6767 } ) ;
68+
69+ it ( 'should return identical output for equivalent compressed and full IPv6 forms' , ( ) => {
70+ const compressed = utils . aton6 ( '2607:f0d0:1002:51::4' ) ;
71+ const expanded = utils . aton6 ( '2607:f0d0:1002:0051:0000:0000:0000:0004' ) ;
72+ expect ( compressed ) . toEqual ( expanded ) ;
73+ } ) ;
74+
75+ it ( 'should correctly expand omitted middle zero groups' , ( ) => {
76+ const actual = utils . aton6 ( '2001:db8:1::2' ) ;
77+ const expected = utils . aton6 ( '2001:0db8:0001:0000:0000:0000:0000:0002' ) ;
78+ expect ( actual ) . toEqual ( expected ) ;
79+ } ) ;
6880 } ) ;
6981
7082 describe ( '#ntoa6' , ( ) => {
@@ -94,7 +106,7 @@ describe('Utility Functions', () => {
94106 } ) ;
95107
96108 it ( 'should delegate to cmp6 for arrays' , ( ) => {
97- const result = utils . cmp ( [ 1 , 2 ] , [ 1 , 3 ] ) ;
109+ const result = utils . cmp ( [ 0 , 0 , 0 , 1 ] , [ 0 , 0 , 0 , 2 ] ) ;
98110 expect ( result ) . toBe ( - 1 ) ;
99111 } ) ;
100112
@@ -106,44 +118,24 @@ describe('Utility Functions', () => {
106118
107119 describe ( '#cmp6' , ( ) => {
108120 it ( 'should compare IPv6 arrays correctly' , ( ) => {
109- expect ( utils . cmp6 ( [ 0 , 0 ] , [ 0 , 1 ] ) ) . toBe ( - 1 ) ;
110- expect ( utils . cmp6 ( [ 0 , 1 ] , [ 0 , 0 ] ) ) . toBe ( 1 ) ;
111- expect ( utils . cmp6 ( [ 5 , 10 ] , [ 5 , 10 ] ) ) . toBe ( 0 ) ;
121+ expect ( utils . cmp6 ( [ 0 , 0 , 0 , 0 ] , [ 0 , 0 , 0 , 1 ] ) ) . toBe ( - 1 ) ;
122+ expect ( utils . cmp6 ( [ 0 , 0 , 0 , 1 ] , [ 0 , 0 , 0 , 0 ] ) ) . toBe ( 1 ) ;
123+ expect ( utils . cmp6 ( [ 5 , 10 , 15 , 20 ] , [ 5 , 10 , 15 , 20 ] ) ) . toBe ( 0 ) ;
112124 } ) ;
113125
114126 it ( 'should compare first element priority' , ( ) => {
115- expect ( utils . cmp6 ( [ 1 , 100 ] , [ 2 , 0 ] ) ) . toBe ( - 1 ) ;
116- expect ( utils . cmp6 ( [ 2 , 0 ] , [ 1 , 100 ] ) ) . toBe ( 1 ) ;
127+ expect ( utils . cmp6 ( [ 1 , 100 , 999 , 999 ] , [ 2 , 0 , 0 , 0 ] ) ) . toBe ( - 1 ) ;
128+ expect ( utils . cmp6 ( [ 2 , 0 , 0 , 0 ] , [ 1 , 100 , 999 , 999 ] ) ) . toBe ( 1 ) ;
117129 } ) ;
118130
119131 it ( 'should handle equal first elements' , ( ) => {
120- expect ( utils . cmp6 ( [ 1 , 2 ] , [ 1 , 3 ] ) ) . toBe ( - 1 ) ;
121- expect ( utils . cmp6 ( [ 1 , 3 ] , [ 1 , 2 ] ) ) . toBe ( 1 ) ;
122- } ) ;
123- } ) ;
124-
125- describe ( '#isPrivateIP' , ( ) => {
126- it ( 'should detect private IPv4 addresses' , ( ) => {
127- expect ( utils . isPrivateIP ( '10.0.0.1' ) ) . toBe ( true ) ;
128- expect ( utils . isPrivateIP ( '10.255.255.255' ) ) . toBe ( true ) ;
129- expect ( utils . isPrivateIP ( '192.168.0.1' ) ) . toBe ( true ) ;
130- expect ( utils . isPrivateIP ( '192.168.255.255' ) ) . toBe ( true ) ;
131- expect ( utils . isPrivateIP ( '172.16.0.1' ) ) . toBe ( true ) ;
132- expect ( utils . isPrivateIP ( '127.0.0.1' ) ) . toBe ( true ) ;
133- expect ( utils . isPrivateIP ( '169.254.1.1' ) ) . toBe ( true ) ;
134- } ) ;
135-
136- it ( 'should detect private IPv6 addresses' , ( ) => {
137- expect ( utils . isPrivateIP ( 'fc00::1' ) ) . toBe ( true ) ;
138- expect ( utils . isPrivateIP ( 'fe80::1' ) ) . toBe ( true ) ;
132+ expect ( utils . cmp6 ( [ 1 , 2 , 0 , 0 ] , [ 1 , 3 , 0 , 0 ] ) ) . toBe ( - 1 ) ;
133+ expect ( utils . cmp6 ( [ 1 , 3 , 0 , 0 ] , [ 1 , 2 , 0 , 0 ] ) ) . toBe ( 1 ) ;
139134 } ) ;
140135
141- it ( 'should not detect public IP addresses as private' , ( ) => {
142- expect ( utils . isPrivateIP ( '8.8.8.8' ) ) . toBe ( false ) ;
143- expect ( utils . isPrivateIP ( '1.1.1.1' ) ) . toBe ( false ) ;
144- expect ( utils . isPrivateIP ( '172.15.0.1' ) ) . toBe ( false ) ;
145- expect ( utils . isPrivateIP ( '172.32.0.1' ) ) . toBe ( false ) ;
146- expect ( utils . isPrivateIP ( '2001:db8::1' ) ) . toBe ( false ) ;
136+ it ( 'should compare lower 64 bits when upper 64 bits are equal' , ( ) => {
137+ expect ( utils . cmp6 ( [ 638054608 , 268566609 , 0 , 4 ] , [ 638054608 , 268566609 , 0 , 5 ] ) ) . toBe ( - 1 ) ;
138+ expect ( utils . cmp6 ( [ 638054608 , 268566609 , 4 , 4 ] , [ 638054608 , 268566609 , 0 , 4 ] ) ) . toBe ( 1 ) ;
147139 } ) ;
148140 } ) ;
149141} ) ;
0 commit comments