Skip to content

Commit bdb7b39

Browse files
committed
Delete restricted keys from the GCM payload
1 parent 5d17496 commit bdb7b39

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

lib/pusher/native_notification/client.rb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,13 @@ def url(path = nil)
6666
# that there is an accompanying `title` and `icon`
6767
# field
6868
def validate_payload(payload)
69-
# Restricted keys
70-
RESTRICTED_GCM_PAYLOAD_KEYS.each { |k| payload.delete(k) }
71-
7269
unless (payload.has_key?(:apns) || payload.has_key?(:gcm))
7370
raise Pusher::Error, "GCM or APNS data must be provided"
7471
end
7572

7673
if (gcm_payload = payload[:gcm])
74+
# Restricted keys
75+
RESTRICTED_GCM_PAYLOAD_KEYS.each { |k| gcm_payload.delete(k) }
7776
if (ttl = gcm_payload[:time_to_live])
7877

7978
if ttl.to_i < 0 || ttl.to_i > GCM_TTL

spec/client_spec.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -656,7 +656,7 @@
656656
@client.notify(["test"], payload)
657657
end
658658

659-
it "should delete restricted keys before sending a notification" do
659+
it "should delete restricted gcm keys before sending a notification" do
660660
notification_host_regexp = %r{hedwig-staging.herokuapp.com}
661661
payload = {
662662
interests: ["test"],
@@ -678,7 +678,8 @@
678678
:body => MultiJson.encode({ :foo => "bar" })
679679
})
680680

681-
@client.notify(["test"], payload.merge!(to: "blah", registration_ids: ["reg1", "reg2"]))
681+
payload[:gcm].merge!(to: "blah", registration_ids: ["reg1", "reg2"])
682+
@client.notify(["test"], payload)
682683
end
683684

684685
it "should raise an error for an invalid webhook url field" do

0 commit comments

Comments
 (0)