@@ -2,94 +2,12 @@ package tapdance
22
33import (
44 "crypto/hmac"
5- "crypto/rand"
65 "encoding/hex"
76 "testing"
87
98 pb "github.com/refraction-networking/gotapdance/protobuf"
109)
1110
12- func TestSelectIpv4 (t * testing.T ) {
13-
14- _ddIPSelector , err := newDDIpSelector ([]string {"192.122.190.0/24" , "2001:48a8:687f:1::/64" }, false )
15- if err != nil {
16- t .Fatal ("Failed IP selector initialization " , err )
17- }
18-
19- for _ , _net := range _ddIPSelector .nets {
20- if _net .IP .To4 () == nil {
21- t .Fatal ("Encountered Non IPv4 Network block" )
22- }
23- }
24-
25- seed := make ([]byte , 16 )
26- _ , err = rand .Read (seed )
27- if err != nil {
28- t .Fatalf ("Crypto/Rand error -- %s\n " , err )
29- }
30-
31- darDecoyIPAddr , err := _ddIPSelector .selectIpAddr (seed )
32- if err != nil {
33- t .Fatalf ("Error selecting decoy address -- %s\n " , err )
34- }
35- if darDecoyIPAddr .To4 () == nil {
36- t .Fatal ("No IPv4 address Selected" )
37- }
38-
39- seed = []byte {
40- 0x0 , 0x1 , 0x2 , 0x3 , 0x4 , 0x5 , 0x6 , 0x7 ,
41- 0x8 , 0x9 , 0xA , 0xB , 0xC , 0xD , 0xE , 0xF ,
42- }
43-
44- phantomIPAddr4 , phantomIPAddr6 , err := SelectPhantom (seed , v4 )
45- if err != nil || phantomIPAddr4 == nil {
46- t .Fatalf ("Failed to select IP address (support: v4): %v" , err )
47- } else if phantomIPAddr6 != nil {
48- t .Fatalf ("Chose v6 address when v4 specified" )
49- } else if phantomIPAddr4 .String () != "141.219.19.101" {
50- t .Fatalf ("Incorrect Address chosen: %v" , phantomIPAddr4 .String ())
51- }
52- }
53-
54- func TestSelectIpv6 (t * testing.T ) {
55-
56- _ddIPSelector , err := newDDIpSelector ([]string {"192.122.190.0/24" , "2001:48a8:687f:1::/64" }, true )
57- if err != nil {
58- t .Fatal ("Failed IP selector initialization " , err )
59- }
60-
61- for _ , _net := range _ddIPSelector .nets {
62- if _net .IP .To16 () == nil && _net .IP .To4 () == nil {
63- t .Fatal ("Encountered Unknown Network block" )
64- }
65- }
66-
67- seed := make ([]byte , 16 )
68- _ , err = rand .Read (seed )
69- if err != nil {
70- t .Fatalf ("Crypto/Rand error -- %s\n " , err )
71- }
72-
73- _ , err = _ddIPSelector .selectIpAddr (seed )
74- if err != nil {
75- t .Fatalf ("Error selecting decoy address -- %s\n " , err )
76- }
77-
78- seed = []byte {
79- 0x0 , 0x1 , 0x2 , 0x3 , 0x4 , 0x5 , 0x6 , 0x7 ,
80- 0x8 , 0x9 , 0xA , 0xB , 0xC , 0xD , 0xE , 0xF ,
81- }
82-
83- phantomIPAddr4 , phantomIPAddr6 , err := SelectPhantom (seed , v6 )
84- if err != nil || phantomIPAddr6 == nil || phantomIPAddr4 != nil {
85- t .Fatalf ("Failed to select IP address (support: v6): %v" , err )
86- } else if phantomIPAddr4 != nil {
87- t .Fatalf ("Chose v4 address when v6 specified" )
88- } else if phantomIPAddr6 .String () != "2001:48a8:687f:1:305:709:b11:2024" {
89- t .Fatalf ("Incorrect Address chosen: %s" , phantomIPAddr6 .String ())
90- }
91- }
92-
9311func TestSelectBoth (t * testing.T ) {
9412 seed := []byte {
9513 0x0 , 0x1 , 0x2 , 0x3 , 0x4 , 0x5 , 0x6 , 0x7 ,
@@ -103,9 +21,9 @@ func TestSelectBoth(t *testing.T) {
10321 t .Fatalf ("Failed to select IPv4 address (support: both): %v" , err )
10422 } else if phantomIPAddr6 == nil {
10523 t .Fatalf ("Failed to select IPv6 address (support: both): %v" , err )
106- } else if phantomIPAddr6 .String () != "2001:48a8:687f:1:305:709:b11:2024 " {
24+ } else if phantomIPAddr6 .String () != "2001:48a8:687f:1:41d3:ff12:45b:73c8 " {
10725 t .Fatalf ("Incorrect Address chosen: %s" , phantomIPAddr6 .String ())
108- } else if phantomIPAddr4 .String () != "141.219.19.101 " {
26+ } else if phantomIPAddr4 .String () != "192.122.190.194 " {
10927 t .Fatalf ("Incorrect Address chosen: %v" , phantomIPAddr4 .String ())
11028 }
11129}
0 commit comments