-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathchallenge_test.go
108 lines (95 loc) · 2.37 KB
/
challenge_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 acme
import (
"testing"
)
func TestEncodeDns01KeyAuthorization(t *testing.T) {
tests := []struct {
KeyAuth string
Encoded string
}{
{
"YLhavngUj1w8B79rUzxB5imUvO8DPyLDHgce89NuMfw.4fqGG7OQog-EV3ovi0b_amhdzVNWxxswDUN9ypYhWpE",
"vKcNRAl8IQoDxFFQbEmXHgZ8O1rYk3JTFooIfYJDEEU",
},
}
for _, currentTest := range tests {
e := EncodeDNS01KeyAuthorization(currentTest.KeyAuth)
if e != currentTest.Encoded {
t.Fatalf("expected: %s, got: %s", currentTest.Encoded, e)
}
}
}
func TestClient_UpdateChallenge(t *testing.T) {
account, order := makeOrder(t)
auth, err := testClient.FetchAuthorization(account, order.Authorizations[0])
if err != nil {
t.Fatalf("unexpected error fetching authorization: %v", err)
}
chal := auth.ChallengeMap[ChallengeTypeDNS01]
preChallenge(account, auth, chal)
defer postChallenge(account, auth, chal)
updatedChal, err := testClient.UpdateChallenge(account, chal)
if err != nil {
t.Fatalf("expected no error, got: %v", err)
}
if updatedChal.Status != "valid" {
t.Fatalf("expected valid challenge, got: %s", chal.Status)
}
}
func TestClient_FetchChallenge(t *testing.T) {
account, order := makeOrder(t)
auth, err := testClient.FetchAuthorization(account, order.Authorizations[0])
if err != nil {
t.Fatalf("unexpected error fetching authorization: %v", err)
}
chal := auth.Challenges[0]
fetchedChal, err := testClient.FetchChallenge(account, chal.URL)
if err != nil {
t.Fatalf("expected no error, got: %v", err)
}
if chal.Token != fetchedChal.Token {
t.Fatalf("tokens different")
}
}
func Test_checkUpdatedChallengeStatus(t *testing.T) {
tests := []struct {
Status string
Finished bool
HasError bool
}{
{
Status: "pending",
},
{
Status: "processing",
},
{
Status: "valid",
Finished: true,
},
{
Status: "invalid",
Finished: true,
HasError: true,
},
{
Status: "blah",
Finished: true,
HasError: true,
},
}
for _, ct := range tests {
finished, err := checkUpdatedChallengeStatus(Challenge{
Status: ct.Status,
})
if ct.Finished != finished {
t.Fatalf("Finished mismatch on status %s, expected: %t got: %t", ct.Status, ct.Finished, finished)
}
if ct.HasError && err == nil {
t.Fatalf("status %s expected error, got none", ct.Status)
}
if !ct.HasError && err != nil {
t.Fatalf("status %s expected no error, got: %v", ct.Status, err)
}
}
}