@@ -22,20 +22,29 @@ func TestProxyHeader(t *testing.T) {
2222 Port : 25566 ,
2323 }
2424
25+ // Bare IPv6 addresses without brackets and port (as reported in issue #670)
26+ bareIPv6Src := connect .Addr ("2a09:bac6:d73f:28::4:31d" )
27+ bareIPv6Src2 := connect .Addr ("2a09:bac6:d73f:3046::4cf:74" )
28+
2529 testCases := []struct {
26- name string
27- srcAddr net.Addr
28- destAddr net.Addr
30+ name string
31+ srcAddr net.Addr
32+ destAddr net.Addr
33+ skipStrCompare bool // bare IPv6 addr strings differ from net.TCPAddr strings
2934 }{
30- {"virtual addr should not fail to write proxy header" , srcAddr , destAddr },
31- {"mix of v4 and v6 should not fail to write proxy header" , v4Addr , v6Addr },
32- {"mix of v6 and v4 should not fail to write proxy header" , v6Addr , v4Addr },
33- {"v4 addr should not fail to write proxy header" , v4Addr , v4Addr },
34- {"v6 addr should not fail to write proxy header" , v6Addr , v6Addr },
35- {"mix of v4 and virtual should not fail to write proxy header" , v4Addr , destAddr },
36- {"mix of v6 and virtual should not fail to write proxy header" , v6Addr , destAddr },
37- {"mix of virtual and v4 should not fail to write proxy header" , srcAddr , v4Addr },
38- {"mix of virtual and v6 should not fail to write proxy header" , srcAddr , v6Addr },
35+ {"virtual addr should not fail to write proxy header" , srcAddr , destAddr , false },
36+ {"mix of v4 and v6 should not fail to write proxy header" , v4Addr , v6Addr , false },
37+ {"mix of v6 and v4 should not fail to write proxy header" , v6Addr , v4Addr , false },
38+ {"v4 addr should not fail to write proxy header" , v4Addr , v4Addr , false },
39+ {"v6 addr should not fail to write proxy header" , v6Addr , v6Addr , false },
40+ {"mix of v4 and virtual should not fail to write proxy header" , v4Addr , destAddr , false },
41+ {"mix of v6 and virtual should not fail to write proxy header" , v6Addr , destAddr , false },
42+ {"mix of virtual and v4 should not fail to write proxy header" , srcAddr , v4Addr , false },
43+ {"mix of virtual and v6 should not fail to write proxy header" , srcAddr , v6Addr , false },
44+ {"bare IPv6 src should not panic" , bareIPv6Src , destAddr , true },
45+ {"bare IPv6 src2 should not panic" , bareIPv6Src2 , destAddr , true },
46+ {"bare IPv6 src with v4 dest should not panic" , bareIPv6Src , v4Addr , true },
47+ {"bare IPv6 src with v6 dest should not panic" , bareIPv6Src , v6Addr , true },
3948 }
4049
4150 for _ , tc := range testCases {
@@ -44,8 +53,10 @@ func TestProxyHeader(t *testing.T) {
4453 require .NotNil (t , header )
4554 require .NotNil (t , header .SourceAddr )
4655 require .NotNil (t , header .DestinationAddr )
47- require .Equal (t , tc .srcAddr .String (), header .SourceAddr .String ())
48- require .Equal (t , tc .destAddr .String (), header .DestinationAddr .String ())
56+ if ! tc .skipStrCompare {
57+ require .Equal (t , tc .srcAddr .String (), header .SourceAddr .String ())
58+ require .Equal (t , tc .destAddr .String (), header .DestinationAddr .String ())
59+ }
4960
5061 // Create a buffer to write the header
5162 buf := new (bytes.Buffer )
0 commit comments