forked from joohoi/acme-dns
-
Notifications
You must be signed in to change notification settings - Fork 0
/
validation_test.go
108 lines (102 loc) · 2.85 KB
/
validation_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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
package main
import (
"github.com/satori/go.uuid"
"testing"
)
func TestGetValidUsername(t *testing.T) {
v1, _ := uuid.FromString("a097455b-52cc-4569-90c8-7a4b97c6eba8")
for i, test := range []struct {
uname string
output uuid.UUID
shouldErr bool
}{
{"a097455b-52cc-4569-90c8-7a4b97c6eba8", v1, false},
{"a-97455b-52cc-4569-90c8-7a4b97c6eba8", uuid.UUID{}, true},
{"", uuid.UUID{}, true},
{"&!#!25123!%!'%", uuid.UUID{}, true},
} {
ret, err := getValidUsername(test.uname)
if test.shouldErr && err == nil {
t.Errorf("Test %d: Expected error, but there was none", i)
}
if !test.shouldErr && err != nil {
t.Errorf("Test %d: Expected no error, but got [%v]", i, err)
}
if ret != test.output {
t.Errorf("Test %d: Expected return value %v, but got %v", i, test.output, ret)
}
}
}
func TestValidKey(t *testing.T) {
for i, test := range []struct {
key string
output bool
}{
{"", false},
{"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", true},
{"aaaaaaaa-aaa-aaaaaa-aaaaaaaa-aaa_aacaaaa", true},
{"aaaaaaaa-aaa-aaaaaa#aaaaaaaa-aaa_aacaaaa", false},
{"aaaaaaaa-aaa-aaaaaa-aaaaaaaa-aaa_aacaaaaa", false},
} {
ret := validKey(test.key)
if ret != test.output {
t.Errorf("Test %d: Expected return value %t, but got %t", i, test.output, ret)
}
}
}
func TestGetValidSubdomain(t *testing.T) {
for i, test := range []struct {
subdomain string
output bool
}{
{"a097455b-52cc-4569-90c8-7a4b97c6eba8", true},
{"a-97455b-52cc-4569-90c8-7a4b97c6eba8", false},
{"", false},
{"&!#!25123!%!'%", false},
} {
ret := validSubdomain(test.subdomain)
if ret != test.output {
t.Errorf("Test %d: Expected return value %t, but got %t", i, test.output, ret)
}
}
}
func TestValidTXT(t *testing.T) {
for i, test := range []struct {
txt string
output bool
}{
{"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", true},
{"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", false},
{"aaaaaaaaaaaaaaaaaaaaaaaaaaaa#aaaaaaaaaaaaaa", false},
{"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", false},
{"", false},
} {
ret := validTXT(test.txt)
if ret != test.output {
t.Errorf("Test %d: Expected return value %t, but got %t", i, test.output, ret)
}
}
}
func TestCorrectPassword(t *testing.T) {
for i, test := range []struct {
pw string
hash string
output bool
}{
{"PUrNTjU24JYNEOCeS2JcjaJGv1sinT80oV9--dpX",
"$2a$10$ldVoGU5yrdlbPzuPUbUfleVovGjaRelP9tql0IltVUJk778gf.2tu",
true},
{"PUrNTjU24JYNEOCeS2JcjaJGv1sinT80oV9--dpX",
"$2a$10$ldVoGU5yrdlbPzuPUbUfleVovGjaRelP9tql0IltVUJk778gf.2t",
false},
{"PUrNTjU24JYNEOCeS2JcjaJGv1sinT80oV9--dp",
"$2a$10$ldVoGU5yrdlbPzuPUbUfleVovGjaRelP9tql0IltVUJk778gf.2tu",
false},
{"", "", false},
} {
ret := correctPassword(test.pw, test.hash)
if ret != test.output {
t.Errorf("Test %d: Expected return value %t, but got %t", i, test.output, ret)
}
}
}