-
Notifications
You must be signed in to change notification settings - Fork 604
/
certificate_authorities_test.go
102 lines (84 loc) · 2.71 KB
/
certificate_authorities_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
package cloudflare
import (
"context"
"fmt"
"net/http"
"testing"
"github.com/goccy/go-json"
"github.com/stretchr/testify/assert"
)
func TestListCertificateAuthoritiesHostnameAssociations(t *testing.T) {
setup()
defer teardown()
handler := func(w http.ResponseWriter, r *http.Request) {
assert.Equal(t, http.MethodGet, r.Method, "Expected method 'GET', got %s", r.Method)
assert.Equal(t, "72ef4d06-4752-4493-a60a-7421470fd585", r.URL.Query().Get("mtls_certificate_id"))
w.Header().Set("content-type", "application/json")
fmt.Fprintf(w, `{
"success": true,
"errors": [],
"messages": [],
"result": {
"hostnames": [
"admin.example.com",
"foobar.example.com"
]
}
}`)
}
hostnameAssociations := ListCertificateAuthoritiesHostnameAssociationsParams{
MTLSCertificateID: "72ef4d06-4752-4493-a60a-7421470fd585",
}
want := []HostnameAssociation{
"admin.example.com",
"foobar.example.com",
}
mux.HandleFunc("/zones/"+testZoneID+"/certificate_authorities/hostname_associations", handler)
actual, err := client.ListCertificateAuthoritiesHostnameAssociations(context.Background(), testZoneRC, hostnameAssociations)
if assert.NoError(t, err) {
assert.Equal(t, want, actual)
}
}
func TestUpdateCertificateAuthoritiesHostnameAssociations(t *testing.T) {
setup()
defer teardown()
handler := func(w http.ResponseWriter, r *http.Request) {
assert.Equal(t, http.MethodPut, r.Method, "Expected method 'PUT', got %s", r.Method)
wantReqHostnames := []HostnameAssociation{
"admin.example.com",
"foobar.example.com",
}
var req HostnameAssociationsUpdateRequest
assert.NoError(t, json.NewDecoder(r.Body).Decode(&req))
assert.Equal(t, "72ef4d06-4752-4493-a60a-7421470fd585", req.MTLSCertificateID)
assert.Equal(t, wantReqHostnames, req.Hostnames)
w.Header().Set("content-type", "application/json")
fmt.Fprintf(w, `{
"success": true,
"errors": [],
"messages": [],
"result": {
"hostnames": [
"admin.example.com",
"foobar.example.com"
]
}
}`)
}
hostnameAssociations := UpdateCertificateAuthoritiesHostnameAssociationsParams{
MTLSCertificateID: "72ef4d06-4752-4493-a60a-7421470fd585",
Hostnames: []HostnameAssociation{
"admin.example.com",
"foobar.example.com",
},
}
want := []HostnameAssociation{
"admin.example.com",
"foobar.example.com",
}
mux.HandleFunc("/zones/"+testZoneID+"/certificate_authorities/hostname_associations", handler)
actual, err := client.UpdateCertificateAuthoritiesHostnameAssociations(context.Background(), testZoneRC, hostnameAssociations)
if assert.NoError(t, err) {
assert.Equal(t, want, actual)
}
}