firebase-admin 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e89fa65facd66a7e21d693667661a8606669580f70d8c538a21fe08a3ef8cff0
4
- data.tar.gz: 27ca309672952d220435693027320e58497055345054a80a6ae41b6a2b541707
3
+ metadata.gz: 1e0160923e857a6f2bb9010287cdc66fc7f7b06f10ed9644a13d8423f06ed417
4
+ data.tar.gz: 469ed074842e19e352ec98c0e1232c85eed7dd56464e33a7b7669f6a7e35c619
5
5
  SHA512:
6
- metadata.gz: 7f0b56ee6d005dad74eb3bdeae6fbb2b6f6ea3e151e0957690cee98d521348893e74ef179eebe9f67e08c9066903aaf79a25a4b8870c979105aa01ed5020800d
7
- data.tar.gz: c3a6dc64332ee9b362f2c6399c57f684233b1e697d3ddd14d64f55f77915bebec36309e173049ea6d2150359971de68361dedb219b401870ba24f473297dabff
6
+ metadata.gz: 634a6bb2e8ccb27851b527859e98460b9fa2b101ff24ec87fbcff5843474529d2fa71f0c20794659ab9938dda3e891cb6c2fda9116ffb00969c0b6ef00e2faf6
7
+ data.tar.gz: 8eb5c88f3b47ec5f0a8aff837d5c6db40d6ae890a70e39b0cfcb024b6dd443da449a6091dbcbe19091d255870a8edc3fa40240b8c7d5e07be453b8f7f3c97b67
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- firebase-admin (0.1.3)
4
+ firebase-admin (0.1.4)
5
5
  addressable (~> 2.7)
6
6
  faraday (~> 1.3)
7
7
  faraday_middleware (~> 1.0)
@@ -165,19 +165,39 @@ module FirebaseAdmin
165
165
  end
166
166
 
167
167
  def service_account_email
168
- default_credentials.fetch('client_email') { ENV['GOOGLE_CLIENT_EMAIL'] }
168
+ email = default_credentials.fetch('client_email') { ENV['GOOGLE_CLIENT_EMAIL'] }
169
+ if email.nil? || email == ''
170
+ raise InvalidCredentials,
171
+ "No client email provided via 'GOOGLE_APPLICATION_CREDENTIALS' or 'GOOGLE_CLIENT_EMAIL'"
172
+ end
173
+
174
+ email
169
175
  end
170
176
 
171
177
  def private_key
172
178
  key = default_credentials.fetch('private_key') { unescape(ENV['GOOGLE_PRIVATE_KEY']) }
179
+ if key.nil? || key == ''
180
+ raise InvalidCredentials,
181
+ "No private key provided via 'GOOGLE_APPLICATION_CREDENTIALS' or 'GOOGLE_PRIVATE_KEY'"
182
+ end
183
+
173
184
  OpenSSL::PKey::RSA.new(key)
174
185
  end
175
186
 
176
187
  def default_credentials
177
- @default_credentials ||= begin
178
- credentials_path = ENV['GOOGLE_APPLICATION_CREDENTIALS']
179
- JSON.parse(File.read(credentials_path)) if credentials_path
188
+ @default_credentials ||= read_default_credentials
189
+ end
190
+
191
+ def read_default_credentials
192
+ credentials_path = ENV['GOOGLE_APPLICATION_CREDENTIALS']
193
+ if credentials_path && File.exist?(credentials_path)
194
+ JSON.parse(File.read(credentials_path))
195
+ else
196
+ {}
180
197
  end
198
+ rescue StandardError => e
199
+ raise InvalidCredentials,
200
+ "Failed reading credentials from '#{ENV['GOOGLE_APPLICATION_CREDENTIALS']}'. Error: #{e.message}"
181
201
  end
182
202
  end
183
203
  end
@@ -25,4 +25,7 @@ module FirebaseAdmin
25
25
 
26
26
  # Raised when Firebase returns the HTTP status code 429
27
27
  class RateLimitExceeded < Error; end
28
+
29
+ # Raised when no valid credentials are found
30
+ class InvalidCredentials < Error; end
28
31
  end
@@ -1,3 +1,3 @@
1
1
  module FirebaseAdmin
2
- VERSION = '0.1.3'.freeze unless defined?(::FirebaseAdmin::VERSION)
2
+ VERSION = '0.1.4'.freeze unless defined?(::FirebaseAdmin::VERSION)
3
3
  end
@@ -50,11 +50,22 @@ describe FirebaseAdmin::Client do
50
50
  end
51
51
  end
52
52
 
53
+ context 'when GOOGLE_APPLICATION_CREDENTIALS points to an invalid file' do
54
+ before do
55
+ ENV['GOOGLE_APPLICATION_CREDENTIALS'] = fixture('google_credentials_invalid.json').path
56
+ end
57
+
58
+ it 'raises an error' do
59
+ expect { @client.create_custom_token('user-123') }.to raise_error FirebaseAdmin::InvalidCredentials
60
+ end
61
+ end
62
+
53
63
  context 'when credentials are set via GOOGLE_CLIENT_EMAIL / GOOGLE_PRIVATE_KEY' do
54
64
  let(:email) { 'example@example.com' }
55
65
  let(:private_key) { fixture('example_key').read }
56
66
 
57
67
  before do
68
+ ENV['GOOGLE_APPLICATION_CREDENTIALS'] = nil
58
69
  ENV['GOOGLE_CLIENT_EMAIL'] = email
59
70
  ENV['GOOGLE_PRIVATE_KEY'] = private_key
60
71
  end
@@ -65,6 +76,18 @@ describe FirebaseAdmin::Client do
65
76
  expect(token_data['uid']).to eq('user-123')
66
77
  end
67
78
  end
79
+
80
+ context 'when no credentials are provided' do
81
+ before do
82
+ ENV['GOOGLE_APPLICATION_CREDENTIALS'] = nil
83
+ ENV['GOOGLE_CLIENT_EMAIL'] = nil
84
+ ENV['GOOGLE_PRIVATE_KEY'] = nil
85
+ end
86
+
87
+ it 'raises an error' do
88
+ expect { @client.create_custom_token('user-123') }.to raise_error FirebaseAdmin::InvalidCredentials
89
+ end
90
+ end
68
91
  end
69
92
 
70
93
  describe '.sign_in_for_uid' do
@@ -0,0 +1 @@
1
+ invalid
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: firebase-admin
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Colin Harris
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-03-31 00:00:00.000000000 Z
11
+ date: 2021-04-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -188,6 +188,7 @@ files:
188
188
  - spec/fixtures/example_key
189
189
  - spec/fixtures/gateway_timeout.html
190
190
  - spec/fixtures/google_credentials.json
191
+ - spec/fixtures/google_credentials_invalid.json
191
192
  - spec/fixtures/update_account.json
192
193
  - spec/spec_helper.rb
193
194
  homepage: https://github.com/col/firebase-admin
@@ -225,5 +226,6 @@ test_files:
225
226
  - spec/fixtures/example_key
226
227
  - spec/fixtures/gateway_timeout.html
227
228
  - spec/fixtures/google_credentials.json
229
+ - spec/fixtures/google_credentials_invalid.json
228
230
  - spec/fixtures/update_account.json
229
231
  - spec/spec_helper.rb