Skip to content

Commit

Permalink
Merge pull request #24 from mohamedhafez/fcm_url
Browse files Browse the repository at this point in the history
api key only needed for old google apis
  • Loading branch information
zaru authored Sep 14, 2016
2 parents 33e78f4 + 4818cd5 commit e86b7af
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/webpush/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def api_key
end

def api_key?
!(api_key.nil? || api_key.empty?) && @endpoint =~ /\Ahttps:\/\/.+\.googleapis\.com/
!(api_key.nil? || api_key.empty?) && @endpoint =~ /\Ahttps:\/\/(android|gcm-http)\.googleapis\.com/
end

def encrypted_payload?
Expand Down
8 changes: 7 additions & 1 deletion spec/webpush/request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,18 @@
end

describe 'from :api_key' do
it 'inserts Authorization header when api_key present, and endpoint is for Chrome' do
it 'inserts Authorization header when api_key present, and endpoint is for Chrome\'s non-standards-compliant GCM endpoints' do
request = Webpush::Request.new('https://gcm-http.googleapis.com/gcm/xyz', api_key: "api_key")

expect(request.headers['Authorization']).to eq("key=api_key")
end

it 'does not insert Authorization header for Chrome\'s new standards-compliant endpoints, even if api_key is present' do
request = Webpush::Request.new('https://fcm.googleapis.com/fcm/send/ABCD1234', api_key: "api_key")

expect(request.headers['Authorization']).to be_nil
end

it 'does not insert Authorization header when endpoint is not for Chrome, even if api_key is present' do
request = Webpush::Request.new('https://some.random.endpoint.com/xyz', api_key: "api_key")

Expand Down

0 comments on commit e86b7af

Please sign in to comment.