forked from keighl/postmark
-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathsender_signatures_test.go
208 lines (185 loc) · 6.11 KB
/
sender_signatures_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
package postmark
import (
"context"
"net/http"
"testing"
"goji.io/pat"
)
func TestGetSenderSignatures(t *testing.T) {
responseJSON := `{
"TotalCount": 2,
"SenderSignatures": [
{
"Domain": "wildbit.com",
"EmailAddress": "[email protected]",
"ReplyToEmailAddress": "[email protected]",
"Name": "JP Toto",
"Confirmed": true,
"ID": 36735
},
{
"Domain": "example.com",
"EmailAddress": "[email protected]",
"ReplyToEmailAddress": "",
"Name": "JP Toto",
"Confirmed": true,
"ID": 81605
}
]
}`
tMux.HandleFunc(pat.Get("/senders"), func(w http.ResponseWriter, _ *http.Request) {
_, _ = w.Write([]byte(responseJSON))
})
res, err := client.GetSenderSignatures(context.Background(), 50, 0)
if err != nil {
t.Fatalf("GetSenderSignatures: %s", err.Error())
}
if res.TotalCount != 2 {
t.Fatalf("GetSenderSignatures: wrong TotalCount!")
}
}
func TestGetSenderSignature(t *testing.T) {
responseJSON := `{
"Domain": "postmarkapp.com",
"EmailAddress": "[email protected]",
"ReplyToEmailAddress": "[email protected]",
"Name": "JP Toto",
"Confirmed": true,
"SPFVerified": true,
"SPFHost": "postmarkapp.com",
"SPFTextValue": "v=spf1 a mx include:spf.mtasv.net ~all",
"DKIMVerified": false,
"WeakDKIM": false,
"DKIMHost": "jan2013.pm._domainkey.postmarkapp.com",
"DKIMTextValue": "k=rsa; p=MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDJ...",
"DKIMPendingHost": "20131031155228.pm._domainkey.postmarkapp.com",
"DKIMPendingTextValue": "k=rsa; p=MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCFn...",
"DKIMRevokedHost": "",
"DKIMRevokedTextValue": "",
"SafeToRemoveRevokedKeyFromDNS": false,
"DKIMUpdateStatus": "Pending",
"ReturnPathDomain": "pm-bounces.postmarkapp.com",
"ReturnPathDomainVerified": false,
"ReturnPathDomainCNAMEValue": "pm.mtasv.net",
"ID": 1234,
"ConfirmationPersonalNote": "This is a note visible to the recipient to provide context of what Postmark is."
}`
tMux.HandleFunc(pat.Get("/senders/:signatureID"), func(w http.ResponseWriter, _ *http.Request) {
_, _ = w.Write([]byte(responseJSON))
})
res, err := client.GetSenderSignature(context.Background(), 1234)
if err != nil {
t.Fatalf("ServerSignature: %s", err.Error())
}
if res.Name != "JP Toto" {
t.Fatalf("ServerSignature: wrong name!")
}
}
func TestCreateSenderSignature(t *testing.T) {
responseJSON := `{
"Domain": "example.com",
"EmailAddress": "[email protected]",
"ReplyToEmailAddress": "[email protected]",
"Name": "John Doe",
"Confirmed": false,
"SPFVerified": false,
"SPFHost": "example.com",
"SPFTextValue": "v=spf1 a mx include:spf.mtasv.net ~all",
"DKIMVerified": false,
"WeakDKIM": false,
"DKIMHost": "",
"DKIMTextValue": "",
"DKIMPendingHost": "20140220130148.pm._domainkey.example.com",
"DKIMPendingTextValue": "k=rsa; p=MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCQ35xZciGB0g...",
"DKIMRevokedHost": "",
"DKIMRevokedTextValue": "",
"SafeToRemoveRevokedKeyFromDNS": false,
"DKIMUpdateStatus": "Pending",
"ReturnPathDomain": "pm-bounces.example.com",
"ReturnPathDomainVerified": true,
"ReturnPathDomainCNAMEValue": "pm.mtasv.net",
"ID": 1,
"ConfirmationPersonalNote": "This is a note visible to the recipient to provide context of what Postmark is."
}`
tMux.HandleFunc(pat.Post("/senders"), func(w http.ResponseWriter, _ *http.Request) {
_, _ = w.Write([]byte(responseJSON))
})
res, err := client.CreateSenderSignature(context.Background(), SenderSignatureCreateRequest{
FromEmail: "[email protected]",
Name: "John Doe",
ReplyToEmail: "[email protected]",
ReturnPathDomain: "pm-bounces.example.com",
ConfirmationPersonalNote: "This is a note visible to the recipient to provide context of what Postmark is.",
})
if err != nil {
t.Fatalf("CreateSenderSignature: %s", err.Error())
}
if res.Name != "John Doe" {
t.Fatalf("CreateSenderSignature: wrong name!")
}
}
func TestEditSenderSignature(t *testing.T) {
responseJSON := `{
"Domain": "example.com",
"EmailAddress": "[email protected]",
"ReplyToEmailAddress": "[email protected]",
"Name": "Jane Doe",
"Confirmed": false,
"SPFVerified": false,
"SPFHost": "crazydomain.com",
"SPFTextValue": "v=spf1 a mx include:spf.mtasv.net ~all",
"DKIMVerified": false,
"WeakDKIM": false,
"DKIMHost": "",
"DKIMTextValue": "",
"DKIMPendingHost": "20140220130148.pm._domainkey.crazydomain.com",
"DKIMPendingTextValue": "k=rsa; p=MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCQ35xZciGB0g...",
"DKIMRevokedHost": "",
"DKIMRevokedTextValue": "",
"SafeToRemoveRevokedKeyFromDNS": false,
"DKIMUpdateStatus": "Pending",
"ReturnPathDomain": "pm-bounces.example.com",
"ReturnPathDomainVerified": true,
"ReturnPathDomainCNAMEValue": "pm.mtasv.net",
"ID": 1,
"ConfirmationPersonalNote": "This is a note visible to the recipient to provide context of what Postmark is."
}`
tMux.HandleFunc(pat.Put("/senders/:signatureID"), func(w http.ResponseWriter, _ *http.Request) {
_, _ = w.Write([]byte(responseJSON))
})
res, err := client.EditSenderSignature(context.Background(), 1, SenderSignatureEditRequest{
Name: "Jane Doe",
ReplyToEmail: "[email protected]",
ReturnPathDomain: "pm-bounces.example.com",
ConfirmationPersonalNote: "This is a note visible to the recipient to provide context of what Postmark is.",
})
if err != nil {
t.Fatalf("EditSenderSignature: %s", err.Error())
}
if res.Name != "Jane Doe" {
t.Fatalf("EditSenderSignature: wrong name!")
}
}
func TestDeleteSenderSignature(t *testing.T) {
responseJSON := `{
"ErrorCode": 0,
"Message": "SenderSignature 1234 removed."
}`
tMux.HandleFunc(pat.Delete("/senders/:signatureID"), func(w http.ResponseWriter, _ *http.Request) {
_, _ = w.Write([]byte(responseJSON))
})
// Success
err := client.DeleteSenderSignature(context.Background(), 1234)
if err != nil {
t.Fatalf("DeleteSenderSignature: %s", err.Error())
}
// Failure
responseJSON = `{
"ErrorCode": 402,
"Message": "Invalid JSON"
}`
err = client.DeleteSenderSignature(context.Background(), 1234)
if err == nil {
t.Fatalf("DeleteSenderSignature should have failed")
}
}