Skip to content

Commit 4fbb779

Browse files
pshoppersideshow
authored andcommitted
Fix client push panic (#134)
* Fix(panic) fix client push panic * feat(test) check bad device token
1 parent 49125e3 commit 4fbb779

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

client.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,10 @@ func (c *Client) PushWithContext(ctx Context, n *Notification) (*Response, error
154154
}
155155

156156
url := fmt.Sprintf("%v/3/device/%v", c.Host, n.DeviceToken)
157-
req, _ := http.NewRequest("POST", url, bytes.NewBuffer(payload))
157+
req, err := http.NewRequest("POST", url, bytes.NewBuffer(payload))
158+
if err != nil {
159+
return nil, err
160+
}
158161

159162
if c.Token != nil {
160163
c.setTokenHeader(req)

client_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,15 @@ func TestClientBadTransportError(t *testing.T) {
102102
assert.Nil(t, res)
103103
}
104104

105+
func TestClientBadDeviceToken(t *testing.T) {
106+
n := &apns.Notification{}
107+
n.DeviceToken = "DGw\aOoD+HwSroh#Ug]%xzd]"
108+
n.Payload = []byte(`{"aps":{"alert":"Hello!"}}`)
109+
res, err := mockClient("https://api.push.apple.com").Push(n)
110+
assert.Error(t, err)
111+
assert.Nil(t, res)
112+
}
113+
105114
func TestClientNameToCertificate(t *testing.T) {
106115
crt, _ := certificate.FromP12File("certificate/_fixtures/certificate-valid.p12", "")
107116
client := apns.NewClient(crt)

0 commit comments

Comments
 (0)