don't send to notification endpoints whose token has changed

fixes CNVS-22551

test plan
- see repro step on the ticket
- ensure multiple notifications aren't sent

Change-Id: Ia3e3b5623cd4c8bd78961e1857a045d81b0bc91f
Reviewed-on: https://gerrit.instructure.com/64174
Tested-by: Jenkins
Reviewed-by: Steven Burnett <sburnett@instructure.com>
QA-Review: Adrian Russell <arussell@instructure.com>
Product-Review: Joel Hough <joel@instructure.com>
This commit is contained in:
Joel Hough 2015-09-28 16:12:00 -06:00
parent d957b30a81
commit 4e6ce06247
2 changed files with 13 additions and 1 deletions

View File

@ -29,7 +29,7 @@ class NotificationEndpoint < ActiveRecord::Base
after_destroy :delete_platform_endpoint
def push_json(json)
return false unless endpoint_exists? && own_endpoint? && endpoint_enabled?
return false unless endpoint_exists? && own_endpoint? && endpoint_enabled? && !token_changed?
sns_client.publish(target_arn: self.arn, message: json, message_structure: 'json')
end
@ -65,6 +65,10 @@ class NotificationEndpoint < ActiveRecord::Base
endpoint_attributes['Enabled'] == 'true'
end
def token_changed?
self.token != endpoint_attributes['Token']
end
def create_platform_endpoint
# try to create new or find existing with our access_token
begin

View File

@ -59,6 +59,14 @@ describe NotificationEndpoint do
ne = @at.notification_endpoints.new(token: 'token')
expect(ne.push_json('json')).to be_falsey
end
it "returns false if the token has changed" do
sns_client = mock()
sns_client.expects(:get_endpoint_attributes).returns(attributes: {'Enabled' => 'true', 'CustomUserData' => @at.global_id.to_s, 'Token' => 'token2'})
NotificationEndpoint.any_instance.expects(:sns_client).returns(sns_client)
ne = @at.notification_endpoints.new(token: 'token')
expect(ne.push_json('json')).to be_falsey
end
end
describe "#destroy" do