-
Notifications
You must be signed in to change notification settings - Fork 17
/
access_test.go
60 lines (50 loc) · 1.69 KB
/
access_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// Copyright (C) 2020 Storj Labs, Inc.
// See LICENSE for copying information.
package uplink_test
import (
"context"
"net"
"testing"
"github.com/stretchr/testify/require"
"github.com/zeebo/errs"
"storj.io/uplink"
)
func TestRequestAccessWithPassphraseAndConcurrency_KnownAddress(t *testing.T) {
const apiKey = "13Yqe3oHi5dcnGhMu2ru3cmePC9iEYv6nDrYMbLRh4wre1KtVA9SFwLNAuuvWwc43b9swRsrfsnrbuTHQ6TJKVt4LjGnaARN9PhxJEu"
ctx := context.Background()
sentinelError := errs.Class("test sentinel")
knownAddresses := []string{
"us-central-1.tardigrade.io:7777",
"mars.tardigrade.io:7777",
"asia-east-1.tardigrade.io:7777",
"saturn.tardigrade.io:7777",
"europe-west-1.tardigrade.io:7777",
"jupiter.tardigrade.io:7777",
"satellite.stefan-benten.de:7777",
"saltlake.tardigrade.io:7777",
}
{ // check that known addresses gain ids and make it to dialing
config := uplink.Config{
DialContext: func(ctx context.Context, network string, address string) (net.Conn, error) {
return nil, sentinelError.New("%s", address)
},
}
for _, address := range knownAddresses {
_, err := config.RequestAccessWithPassphrase(ctx, address, apiKey, "password")
require.Error(t, err)
require.Contains(t, err.Error(), address)
require.True(t, sentinelError.Has(err))
}
}
{ // check that unknown addresses do not gain an id
config := uplink.Config{
DialContext: func(ctx context.Context, network, address string) (net.Conn, error) {
t.Fail()
return nil, errs.New("should not be called")
},
}
_, err := config.RequestAccessWithPassphrase(ctx, "someaddr.example:7777", apiKey, "password")
require.Error(t, err)
require.Contains(t, err.Error(), "node id is required")
}
}