-
Notifications
You must be signed in to change notification settings - Fork 1
/
address_validator_test.go
75 lines (56 loc) · 2.36 KB
/
address_validator_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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package water
// package water instead of water_test to access unexported struct addressValidator and its unexported fields/methods
import "testing"
func Test_addressValidator_validate(t *testing.T) {
var a addressValidator
// test catchAll with nil denylist
a.catchAll = true
if err := a.validate("random net", "random address"); err != ErrAddressValidatorNotInitialized {
t.Errorf("Expected ErrAddressValidatorNotInitialized, got %v", err)
}
// test nil denylist entry
a.denylist = map[string][]string{
"denied address": nil,
}
if err := a.validate("random net", "denied address"); err != ErrAddressValidatorNotInitialized {
t.Errorf("Expected ErrAddressValidatorNotInitialized, got %v", err)
}
// test denied address on denied network
a.denylist["denied address"] = []string{"denied net"}
if err := a.validate("denied net", "denied address"); err != ErrAddressValidationDenied {
t.Errorf("Expected ErrAddressValidationDenied, got %v", err)
}
// test random network with denied address
if err := a.validate("random net", "denied address"); err != nil {
t.Errorf("Expected nil, got %v", err)
}
// test random address on denied network
if err := a.validate("denied net", "random address"); err != nil {
t.Errorf("Expected nil, got %v", err)
}
// test not catchAll with nil allowlist
a.catchAll = false
if err := a.validate("random net", "random address"); err != ErrAddressValidatorNotInitialized {
t.Errorf("Expected ErrAddressValidatorNotInitialized, got %v", err)
}
// test nil allowlist entry
a.allowlist = map[string][]string{
"allowed address": nil,
}
if err := a.validate("random net", "allowed address"); err != ErrAddressValidatorNotInitialized {
t.Errorf("Expected ErrAddressValidatorNotInitialized, got %v", err)
}
// test allowed address on allowed network
a.allowlist["allowed address"] = []string{"allowed net"}
if err := a.validate("allowed net", "allowed address"); err != nil {
t.Errorf("Expected nil, got %v", err)
}
// test random network with allowed address
if err := a.validate("random net", "allowed address"); err != ErrAddressValidationDenied {
t.Errorf("Expected ErrAddressValidationDenied, got %v", err)
}
// test random address on allowed network
if err := a.validate("allowed net", "random address"); err != ErrAddressValidationDenied {
t.Errorf("Expected ErrAddressValidationDenied, got %v", err)
}
}