googleauth 0.6.1 → 0.6.2

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
  SHA1:
3
- metadata.gz: 20f1964a6c443ddd357eea717d32661811107f7a
4
- data.tar.gz: 2992f66b0c91e8fdd679e57dbfa24d2e33d0752b
3
+ metadata.gz: cb647efa48b73b48d9bf0aec7c572f944f31de67
4
+ data.tar.gz: 915dd9da0fc858a9f4b9dbdceaa64228218ff87c
5
5
  SHA512:
6
- metadata.gz: e88fb60a02c07d2dbbe616ed0cd3d81b06e7acc119babe066f4cdf7c672b1680e90b75f2c8ae6f5e357331f16695043c450cb235e1f919016800c2495e6e03db
7
- data.tar.gz: 83c28449dbcfe52f7a34447599feb64b505e0def19aa14db1b2a809e39a84d859c05301dfa67b104094c6466c209b5ff9f2d6d8d859f7a3a8c11fe575f5a79ea
6
+ metadata.gz: b35a1ef32bc166af59bc0d0f491768957ff8f7d7a2d7cb303b375cd8f0fb90f6fda87d9fec4749850ce589393b94d69d181c8606d32c5b9cee04c8f8cae2744c
7
+ data.tar.gz: bc366d1b2a2dc4f49c4eced0ab9c2358070a47c88c3be922e36b68149f69f0b87ab215c8e6fa07c9677b3292664958f131a8efc3d3a36ce0a93c1c9a651bbdd1
@@ -84,7 +84,7 @@ module Google
84
84
  client ||= from_json_vars(scope)
85
85
 
86
86
  # Third try to find keyfile file from known file paths.
87
- client ||= from_default_vars(scope)
87
+ client ||= from_default_paths(scope)
88
88
 
89
89
  # Finally get instantiated client from Google::Auth
90
90
  client ||= from_application_default(scope)
@@ -99,6 +99,7 @@ module Google
99
99
  .each do |file|
100
100
  return new file, scope: scope
101
101
  end
102
+ nil
102
103
  end
103
104
 
104
105
  def self.from_json_vars(scope)
@@ -114,6 +115,7 @@ module Google
114
115
  self::JSON_ENV_VARS.map(&json).compact.each do |hash|
115
116
  return new hash, scope: scope
116
117
  end
118
+ nil
117
119
  end
118
120
 
119
121
  def self.from_default_paths(scope)
@@ -122,6 +124,7 @@ module Google
122
124
  .each do |file|
123
125
  return new file, scope: scope
124
126
  end
127
+ nil
125
128
  end
126
129
 
127
130
  def self.from_application_default(scope)
@@ -31,6 +31,6 @@ module Google
31
31
  # Module Auth provides classes that provide Google-specific authorization
32
32
  # used to access Google APIs.
33
33
  module Auth
34
- VERSION = '0.6.1'.freeze
34
+ VERSION = '0.6.2'.freeze
35
35
  end
36
36
  end
@@ -103,6 +103,137 @@ describe Google::Auth::Credentials, :private do
103
103
  mocked_signet
104
104
  end
105
105
 
106
- TestCredentials.default
106
+ creds = TestCredentials.default
107
+ expect(creds).to be_a_kind_of(TestCredentials)
108
+ expect(creds.client).to eq(mocked_signet)
109
+ end
110
+
111
+ it 'subclasses can use PATH_ENV_VARS to get keyfile path' do
112
+ class TestCredentials < Google::Auth::Credentials
113
+ SCOPE = 'http://example.com/scope'.freeze
114
+ PATH_ENV_VARS = ['PATH_ENV_DUMMY', 'PATH_ENV_TEST'].freeze
115
+ JSON_ENV_VARS = ['JSON_ENV_DUMMY'].freeze
116
+ DEFAULT_PATHS = ['~/default/path/to/file.txt'].freeze
117
+ end
118
+
119
+ allow(::ENV).to receive(:[]).with('PATH_ENV_DUMMY') { '/fake/path/to/file.txt' }
120
+ allow(::File).to receive(:file?).with('/fake/path/to/file.txt') { false }
121
+ allow(::ENV).to receive(:[]).with('PATH_ENV_TEST') { '/unknown/path/to/file.txt' }
122
+ allow(::File).to receive(:file?).with('/unknown/path/to/file.txt') { true }
123
+ allow(::File).to receive(:read).with('/unknown/path/to/file.txt') { JSON.generate(default_keyfile_hash) }
124
+
125
+ mocked_signet = double('Signet::OAuth2::Client')
126
+ allow(mocked_signet).to receive(:fetch_access_token!).and_return(true)
127
+ allow(Signet::OAuth2::Client).to receive(:new) do |options|
128
+ expect(options[:token_credential_uri]).to eq('https://accounts.google.com/o/oauth2/token')
129
+ expect(options[:audience]).to eq('https://accounts.google.com/o/oauth2/token')
130
+ expect(options[:scope]).to eq(['http://example.com/scope'])
131
+ expect(options[:issuer]).to eq(default_keyfile_hash['client_email'])
132
+ expect(options[:signing_key]).to be_a_kind_of(OpenSSL::PKey::RSA)
133
+
134
+ mocked_signet
135
+ end
136
+
137
+ creds = TestCredentials.default
138
+ expect(creds).to be_a_kind_of(TestCredentials)
139
+ expect(creds.client).to eq(mocked_signet)
140
+ end
141
+
142
+ it 'subclasses can use JSON_ENV_VARS to get keyfile contents' do
143
+ class TestCredentials < Google::Auth::Credentials
144
+ SCOPE = 'http://example.com/scope'.freeze
145
+ PATH_ENV_VARS = ['PATH_ENV_DUMMY'].freeze
146
+ JSON_ENV_VARS = ['JSON_ENV_DUMMY', 'JSON_ENV_TEST'].freeze
147
+ DEFAULT_PATHS = ['~/default/path/to/file.txt'].freeze
148
+ end
149
+
150
+ allow(::ENV).to receive(:[]).with('PATH_ENV_DUMMY') { '/fake/path/to/file.txt' }
151
+ allow(::File).to receive(:file?).with('/fake/path/to/file.txt') { false }
152
+ allow(::ENV).to receive(:[]).with('JSON_ENV_DUMMY') { nil }
153
+ allow(::ENV).to receive(:[]).with('JSON_ENV_TEST') { JSON.generate(default_keyfile_hash) }
154
+
155
+ mocked_signet = double('Signet::OAuth2::Client')
156
+ allow(mocked_signet).to receive(:fetch_access_token!).and_return(true)
157
+ allow(Signet::OAuth2::Client).to receive(:new) do |options|
158
+ expect(options[:token_credential_uri]).to eq('https://accounts.google.com/o/oauth2/token')
159
+ expect(options[:audience]).to eq('https://accounts.google.com/o/oauth2/token')
160
+ expect(options[:scope]).to eq(['http://example.com/scope'])
161
+ expect(options[:issuer]).to eq(default_keyfile_hash['client_email'])
162
+ expect(options[:signing_key]).to be_a_kind_of(OpenSSL::PKey::RSA)
163
+
164
+ mocked_signet
165
+ end
166
+
167
+ creds = TestCredentials.default
168
+ expect(creds).to be_a_kind_of(TestCredentials)
169
+ expect(creds.client).to eq(mocked_signet)
170
+ end
171
+
172
+ it 'subclasses can use DEFAULT_PATHS to get keyfile path' do
173
+ class TestCredentials < Google::Auth::Credentials
174
+ SCOPE = 'http://example.com/scope'.freeze
175
+ PATH_ENV_VARS = ['PATH_ENV_DUMMY'].freeze
176
+ JSON_ENV_VARS = ['JSON_ENV_DUMMY'].freeze
177
+ DEFAULT_PATHS = ['~/default/path/to/file.txt'].freeze
178
+ end
179
+
180
+ allow(::ENV).to receive(:[]).with('PATH_ENV_DUMMY') { '/fake/path/to/file.txt' }
181
+ allow(::File).to receive(:file?).with('/fake/path/to/file.txt') { false }
182
+ allow(::ENV).to receive(:[]).with('JSON_ENV_DUMMY') { nil }
183
+ allow(::File).to receive(:file?).with('~/default/path/to/file.txt') { true }
184
+ allow(::File).to receive(:read).with('~/default/path/to/file.txt') { JSON.generate(default_keyfile_hash) }
185
+
186
+ mocked_signet = double('Signet::OAuth2::Client')
187
+ allow(mocked_signet).to receive(:fetch_access_token!).and_return(true)
188
+ allow(Signet::OAuth2::Client).to receive(:new) do |options|
189
+ expect(options[:token_credential_uri]).to eq('https://accounts.google.com/o/oauth2/token')
190
+ expect(options[:audience]).to eq('https://accounts.google.com/o/oauth2/token')
191
+ expect(options[:scope]).to eq(['http://example.com/scope'])
192
+ expect(options[:issuer]).to eq(default_keyfile_hash['client_email'])
193
+ expect(options[:signing_key]).to be_a_kind_of(OpenSSL::PKey::RSA)
194
+
195
+ mocked_signet
196
+ end
197
+
198
+ creds = TestCredentials.default
199
+ expect(creds).to be_a_kind_of(TestCredentials)
200
+ expect(creds.client).to eq(mocked_signet)
201
+ end
202
+
203
+ it 'subclasses that find no matches default to Google::Auth.get_application_default' do
204
+ class TestCredentials < Google::Auth::Credentials
205
+ SCOPE = 'http://example.com/scope'.freeze
206
+ PATH_ENV_VARS = ['PATH_ENV_DUMMY'].freeze
207
+ JSON_ENV_VARS = ['JSON_ENV_DUMMY'].freeze
208
+ DEFAULT_PATHS = ['~/default/path/to/file.txt'].freeze
209
+ end
210
+
211
+ allow(::ENV).to receive(:[]).with('PATH_ENV_DUMMY') { '/fake/path/to/file.txt' }
212
+ allow(::File).to receive(:file?).with('/fake/path/to/file.txt') { false }
213
+ allow(::ENV).to receive(:[]).with('JSON_ENV_DUMMY') { nil }
214
+ allow(::File).to receive(:file?).with('~/default/path/to/file.txt') { false }
215
+
216
+ mocked_signet = double('Signet::OAuth2::Client')
217
+ allow(mocked_signet).to receive(:fetch_access_token!).and_return(true)
218
+ allow(Google::Auth).to receive(:get_application_default) do |scope|
219
+ expect(scope).to eq(TestCredentials::SCOPE)
220
+
221
+ # This should really be a Signet::OAuth2::Client object,
222
+ # but mocking is making that difficult, so return a valid hash instead.
223
+ default_keyfile_hash
224
+ end
225
+ allow(Signet::OAuth2::Client).to receive(:new) do |options|
226
+ expect(options[:token_credential_uri]).to eq('https://accounts.google.com/o/oauth2/token')
227
+ expect(options[:audience]).to eq('https://accounts.google.com/o/oauth2/token')
228
+ expect(options[:scope]).to eq(['http://example.com/scope'])
229
+ expect(options[:issuer]).to eq(default_keyfile_hash['client_email'])
230
+ expect(options[:signing_key]).to be_a_kind_of(OpenSSL::PKey::RSA)
231
+
232
+ mocked_signet
233
+ end
234
+
235
+ creds = TestCredentials.default
236
+ expect(creds).to be_a_kind_of(TestCredentials)
237
+ expect(creds.client).to eq(mocked_signet)
107
238
  end
108
239
  end
@@ -64,6 +64,8 @@ RSpec.configure do |config|
64
64
  include RSpec::LoggingHelper
65
65
  config.capture_log_messages
66
66
  config.include WebMock::API
67
+ config.filter_run focus: true
68
+ config.run_all_when_everything_filtered = true
67
69
  end
68
70
 
69
71
  module TestHelpers
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: googleauth
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.1
4
+ version: 0.6.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tim Emiola
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-10-18 00:00:00.000000000 Z
11
+ date: 2017-11-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -188,7 +188,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
188
188
  version: '0'
189
189
  requirements: []
190
190
  rubyforge_project:
191
- rubygems_version: 2.6.13
191
+ rubygems_version: 2.4.8
192
192
  signing_key:
193
193
  specification_version: 4
194
194
  summary: Google Auth Library for Ruby