-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtls_test.go
88 lines (80 loc) · 2.51 KB
/
tls_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
package coreapi
import (
"fmt"
"testing"
)
func TestModuleTLS_Get_error(t *testing.T) {
m := ModuleTLS{rf: func(path, contentType string, body []byte) ([]byte, error) {
if path != "tls/get" {
t.Fatalf("unexpected path value, got %s", path)
}
if contentType != "text/plain" {
t.Fatalf("unexpected contentType value, got %s", contentType)
}
if string(body) != "domain.com" {
t.Fatalf("unexpected body value, got %s", string(body))
}
return nil, fmt.Errorf("err1")
}}
_, err := m.Get("domain.com")
if err == nil {
t.Fatalf("expected error, got nil")
}
if err.Error() != "failed to get tls info: err1" {
t.Fatalf("unexpected error value, got %s", err.Error())
}
}
func TestModuleTLS_Get_error_unmarshal(t *testing.T) {
m := ModuleTLS{rf: func(path, contentType string, body []byte) ([]byte, error) {
if path != "tls/get" {
t.Fatalf("unexpected path value, got %s", path)
}
if contentType != "text/plain" {
t.Fatalf("unexpected contentType value, got %s", contentType)
}
if string(body) != "domain.com" {
t.Fatalf("unexpected body value, got %s", string(body))
}
return []byte("xxx"), nil
}}
_, err := m.Get("domain.com")
if err == nil {
t.Fatalf("expected error, got nil")
}
if err.Error() != "failed to unmarshal tls info: invalid character 'x' looking for beginning of value" {
t.Fatalf("unexpected error value, got %s", err.Error())
}
}
func TestModuleTLS_Get(t *testing.T) {
m := ModuleTLS{rf: func(path, contentType string, body []byte) ([]byte, error) {
if path != "tls/get" {
t.Fatalf("unexpected path value, got %s", path)
}
if contentType != "text/plain" {
t.Fatalf("unexpected contentType value, got %s", contentType)
}
if string(body) != "domain.com" {
t.Fatalf("unexpected body value, got %s", string(body))
}
return []byte(`[{"issuer":"i","expiry":1,"dns_names":["n"],"email_addresses":["a"]}]`), nil
}}
resp, err := m.Get("domain.com")
if err != nil {
t.Fatalf("unexpected error, got %v", err)
}
if len(resp) != 1 {
t.Fatalf("unexpected response length, got %d", len(resp))
}
if resp[0].Issuer != "i" {
t.Fatalf("unexpected issuer value, got %s", resp[0].Issuer)
}
if resp[0].Expiry != 1 {
t.Fatalf("unexpected expiry value, got %d", resp[0].Expiry)
}
if len(resp[0].DNSNames) != 1 || resp[0].DNSNames[0] != "n" {
t.Fatalf("unexpected dns_names value, got %v", resp[0].DNSNames)
}
if len(resp[0].EmailAddresses) != 1 || resp[0].EmailAddresses[0] != "a" {
t.Fatalf("unexpected email_addresses value, got %v", resp[0].EmailAddresses)
}
}