Debian Codegraph @

tests/tor_isolate_socks_auth_test.go

raw symbols SCIP
1 package testsscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tests`/
2
3 import (
4 "contextscip-go gomod github.com/golang/go/src go1.15 context/"
5 "strconvscip-go gomod github.com/golang/go/src go1.15 strconv/"
6 "stringsscip-go gomod github.com/golang/go/src go1.15 strings/"
7 "testingscip-go gomod github.com/golang/go/src go1.15 testing/"
8 "timescip-go gomod github.com/golang/go/src go1.15 time/"
9
10 "github.com/cretz/bine/torscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tor`/"
11 "golang.org/x/net/proxyscip-go gomod golang.org/x/net abc453219eb5 `golang.org/x/net/proxy`/"
12 )
13
14 // TestIsolateSocksAuth simply confirms the functionality of IsolateSOCKSAuth,
15 // namely that it uses a different circuit for different SOCKS credentials.
16 func TestIsolateSocksAuthscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tests`/TestIsolateSocksAuth().(t *testingscip-go gomod github.com/golang/go/src go1.15 testing/.Tscip-go gomod github.com/golang/go/src go1.15 testing/T#) {
17 // Create context w/ no isolate
18 ctx := NewTestContextscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tests`/NewTestContext().(t, &torscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tor`/.StartConfscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tor`/StartConf#{
19 NoAutoSocksPortscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tor`/StartConf#NoAutoSocksPort.: true,
20 ExtraArgsscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tor`/StartConf#ExtraArgs.: []string{"--SocksPort", "auto NoIsolateSOCKSAuth"},
21 })
22 // Make sure it reused the circuit (i.e. only has one) for both separate-auth calls
23 uniqueCircuitIDs := doSeparateAuthHttpCallsscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tests`/doSeparateAuthHttpCalls().(ctx)
24 ctx.Debugfscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tor`/Tor#Debugf().("Unique IDs without isolate: %v", uniqueCircuitIDs)
25 ctx.Requirescip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tests`/TestContext#Require..Lenscip-go gomod github.com/stretchr/testify v1.7.0 `github.com/stretchr/testify/require`/Assertions#Len().(uniqueCircuitIDs, 1)
26 // Create context w/ isolate
27 ctx = NewTestContextscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tests`/NewTestContext().(t, nil)
28 // Make sure it made a new circuit (i.e. has two) for each separate-auth call
29 uniqueCircuitIDs = doSeparateAuthHttpCallsscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tests`/doSeparateAuthHttpCalls().(ctx)
30 ctx.Debugfscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tor`/Tor#Debugf().("Unique IDs with isolate: %v", uniqueCircuitIDs)
31 ctx.Requirescip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tests`/TestContext#Require..Lenscip-go gomod github.com/stretchr/testify v1.7.0 `github.com/stretchr/testify/require`/Assertions#Len().(uniqueCircuitIDs, 2)
32 }
33
34 // Returns the map keyed with unique circuit IDs after second separate-auth HTTP call
35 func doSeparateAuthHttpCallsscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tests`/doSeparateAuthHttpCalls().(ctx *TestContextscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tests`/TestContext#) map[int]struct{} {
36 defer ctx.Closescip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tests`/TestContext#Close().()
37 enableCtx, enableCancel := contextscip-go gomod github.com/golang/go/src go1.15 context/.WithTimeoutscip-go gomod github.com/golang/go/src go1.15 context/WithTimeout().(ctx, 100*timescip-go gomod github.com/golang/go/src go1.15 time/.Secondscip-go gomod github.com/golang/go/src go1.15 time/Second.)
38 defer enableCancel()
39 ctx.Requirescip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tests`/TestContext#Require..NoErrorscip-go gomod github.com/stretchr/testify v1.7.0 `github.com/stretchr/testify/require`/Assertions#NoError().(ctx.EnableNetworkscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tor`/Tor#EnableNetwork().(enableCtx, true))
40 // Make HTTP call w/ an auth
41 client := httpClientscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tests`/httpClient().(ctx, &torscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tor`/.DialConfscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tor`/DialConf#{ProxyAuthscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tor`/DialConf#ProxyAuth.: &proxyscip-go gomod golang.org/x/net abc453219eb5 `golang.org/x/net/proxy`/.Authscip-go gomod golang.org/x/net abc453219eb5 `golang.org/x/net/proxy`/Auth#{"foo", "bar"}})
42 byts := httpGetscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tests`/httpGet().(ctx, client, "https://check.torproject.org/api/ip")
43 ctx.Debugfscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tor`/Tor#Debugf().("Read bytes: %v", string(byts))
44 // Confirm just size 1
45 ids := uniqueStreamCircuitIDsscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tests`/uniqueStreamCircuitIDs().(ctx)
46 ctx.Requirescip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tests`/TestContext#Require..Lenscip-go gomod github.com/stretchr/testify v1.7.0 `github.com/stretchr/testify/require`/Assertions#Len().(ids, 1)
47 // Now make call with another auth and just return circuit IDs
48 client = httpClientscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tests`/httpClient().(ctx, &torscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tor`/.DialConfscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tor`/DialConf#{ProxyAuthscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tor`/DialConf#ProxyAuth.: &proxyscip-go gomod golang.org/x/net abc453219eb5 `golang.org/x/net/proxy`/.Authscip-go gomod golang.org/x/net abc453219eb5 `golang.org/x/net/proxy`/Auth#{"baz", "qux"}})
49 byts = httpGetscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tests`/httpGet().(ctx, client, "https://check.torproject.org/api/ip")
50 ctx.Debugfscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tor`/Tor#Debugf().("Read bytes: %v", string(byts))
51 return uniqueStreamCircuitIDsscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tests`/uniqueStreamCircuitIDs().(ctx)
52 }
53
54 // Return each stream circuit as a key of an empty-val map
55 func uniqueStreamCircuitIDsscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tests`/uniqueStreamCircuitIDs().(ctx *TestContextscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tests`/TestContext#) map[int]struct{} {
56 ret := map[int]struct{}{}
57 vals, err := ctx.Controlscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tor`/Tor#Control..GetInfoscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/control`/Conn#GetInfo().("stream-status")
58 ctx.Requirescip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tests`/TestContext#Require..NoErrorscip-go gomod github.com/stretchr/testify v1.7.0 `github.com/stretchr/testify/require`/Assertions#NoError().(err)
59 for _, val := range vals {
60 ctx.Requirescip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tests`/TestContext#Require..Equalscip-go gomod github.com/stretchr/testify v1.7.0 `github.com/stretchr/testify/require`/Assertions#Equal().("stream-status", val.Keyscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/control`/KeyVal#Key.)
61 for _, line := range stringsscip-go gomod github.com/golang/go/src go1.15 strings/.Splitscip-go gomod github.com/golang/go/src go1.15 strings/Split().(val.Valscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/control`/KeyVal#Val., "\n") {
62 pieces := stringsscip-go gomod github.com/golang/go/src go1.15 strings/.Splitscip-go gomod github.com/golang/go/src go1.15 strings/Split().(stringsscip-go gomod github.com/golang/go/src go1.15 strings/.TrimSpacescip-go gomod github.com/golang/go/src go1.15 strings/TrimSpace().(line), " ")
63 if len(pieces) < 3 {
64 continue
65 }
66 i, err := strconvscip-go gomod github.com/golang/go/src go1.15 strconv/.Atoiscip-go gomod github.com/golang/go/src go1.15 strconv/Atoi().(pieces[2])
67 ctx.Requirescip-go gomod github.com/cretz/bine . `github.com/cretz/bine/tests`/TestContext#Require..NoErrorscip-go gomod github.com/stretchr/testify v1.7.0 `github.com/stretchr/testify/require`/Assertions#NoError().(err)
68 ret[i] = struct{}{}
69 }
70 }
71 return ret
72 }