forked from letsencrypt/boulder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
names_test.go
234 lines (228 loc) · 5.38 KB
/
names_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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
package ratelimits
import (
"fmt"
"testing"
"github.com/letsencrypt/boulder/test"
)
func TestNameIsValid(t *testing.T) {
t.Parallel()
type args struct {
name Name
}
tests := []struct {
name string
args args
want bool
}{
{name: "Unknown", args: args{name: Unknown}, want: false},
{name: "9001", args: args{name: 9001}, want: false},
{name: "NewRegistrationsPerIPAddress", args: args{name: NewRegistrationsPerIPAddress}, want: true},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := tt.args.name.isValid()
test.AssertEquals(t, tt.want, got)
})
}
}
func TestValidateIdForName(t *testing.T) {
t.Parallel()
testCases := []struct {
limit Name
desc string
id string
err string
}{
{
limit: NewRegistrationsPerIPAddress,
desc: "valid IPv4 address",
id: "10.0.0.1",
},
{
limit: NewRegistrationsPerIPAddress,
desc: "valid IPv6 address",
id: "2001:0db8:85a3:0000:0000:8a2e:0370:7334",
},
{
limit: NewRegistrationsPerIPAddress,
desc: "empty string",
id: "",
err: "must be an IP address",
},
{
limit: NewRegistrationsPerIPAddress,
desc: "one space",
id: " ",
err: "must be an IP address",
},
{
limit: NewRegistrationsPerIPAddress,
desc: "invalid IPv4 address",
id: "10.0.0.9000",
err: "must be an IP address",
},
{
limit: NewRegistrationsPerIPAddress,
desc: "invalid IPv6 address",
id: "2001:0db8:85a3:0000:0000:8a2e:0370:7334:9000",
err: "must be an IP address",
},
{
limit: NewRegistrationsPerIPv6Range,
desc: "valid IPv6 address range",
id: "2001:0db8:0000::/48",
},
{
limit: NewRegistrationsPerIPv6Range,
desc: "invalid IPv6 CIDR range",
id: "2001:0db8:0000::/128",
err: "must be /48",
},
{
limit: NewRegistrationsPerIPv6Range,
desc: "invalid IPv6 CIDR",
id: "2001:0db8:0000::/48/48",
err: "must be an IPv6 CIDR range",
},
{
limit: NewRegistrationsPerIPv6Range,
desc: "IPv4 CIDR when we expect IPv6 CIDR range",
id: "10.0.0.0/16",
err: "must be /48",
},
{
limit: NewOrdersPerAccount,
desc: "valid regId",
id: "1234567890",
},
{
limit: NewOrdersPerAccount,
desc: "invalid regId",
id: "lol",
err: "must be an ACME registration Id",
},
{
limit: FailedAuthorizationsPerDomainPerAccount,
desc: "transaction: valid regId and domain",
id: "12345:example.com",
},
{
limit: FailedAuthorizationsPerDomainPerAccount,
desc: "transaction: invalid regId",
id: "12ea5:example.com",
err: "invalid regId",
},
{
limit: FailedAuthorizationsPerDomainPerAccount,
desc: "transaction: invalid domain",
id: "12345:examplecom",
err: "name needs at least one dot",
},
{
limit: FailedAuthorizationsPerDomainPerAccount,
desc: "override: valid regId",
id: "12345",
},
{
limit: FailedAuthorizationsPerDomainPerAccount,
desc: "override: invalid regId",
id: "12ea5",
err: "invalid regId",
},
{
limit: FailedAuthorizationsForPausingPerDomainPerAccount,
desc: "transaction: valid regId and domain",
id: "12345:example.com",
},
{
limit: FailedAuthorizationsForPausingPerDomainPerAccount,
desc: "transaction: invalid regId",
id: "12ea5:example.com",
err: "invalid regId",
},
{
limit: FailedAuthorizationsForPausingPerDomainPerAccount,
desc: "transaction: invalid domain",
id: "12345:examplecom",
err: "name needs at least one dot",
},
{
limit: FailedAuthorizationsForPausingPerDomainPerAccount,
desc: "override: valid regId",
id: "12345",
},
{
limit: FailedAuthorizationsForPausingPerDomainPerAccount,
desc: "override: invalid regId",
id: "12ea5",
err: "invalid regId",
},
{
limit: CertificatesPerDomainPerAccount,
desc: "transaction: valid regId and domain",
id: "12345:example.com",
},
{
limit: CertificatesPerDomainPerAccount,
desc: "transaction: invalid regId",
id: "12ea5:example.com",
err: "invalid regId",
},
{
limit: CertificatesPerDomainPerAccount,
desc: "transaction: invalid domain",
id: "12345:examplecom",
err: "name needs at least one dot",
},
{
limit: CertificatesPerDomainPerAccount,
desc: "override: valid regId",
id: "12345",
},
{
limit: CertificatesPerDomainPerAccount,
desc: "override: invalid regId",
id: "12ea5",
err: "invalid regId",
},
{
limit: CertificatesPerDomain,
desc: "valid domain",
id: "example.com",
},
{
limit: CertificatesPerDomain,
desc: "malformed domain",
id: "example:.com",
err: "name contains an invalid character",
},
{
limit: CertificatesPerDomain,
desc: "empty domain",
id: "",
err: "name is empty",
},
{
limit: CertificatesPerFQDNSet,
desc: "valid fqdnSet containing a single domain",
id: "example.com",
},
{
limit: CertificatesPerFQDNSet,
desc: "valid fqdnSet containing multiple domains",
id: "example.com,example.org",
},
}
for _, tc := range testCases {
t.Run(fmt.Sprintf("%s/%s", tc.limit, tc.desc), func(t *testing.T) {
t.Parallel()
err := validateIdForName(tc.limit, tc.id)
if tc.err != "" {
test.AssertError(t, err, "should have failed")
test.AssertContains(t, err.Error(), tc.err)
} else {
test.AssertNotError(t, err, "should have succeeded")
}
})
}
}