googleauth 0.5.1 → 0.5.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -104,7 +104,8 @@ describe Google::Auth::ClientId do
104
104
 
105
105
  it 'should raise error' do
106
106
  expect { Google::Auth::ClientId.from_hash(config) }.to raise_error(
107
- /Expected top level property/)
107
+ /Expected top level property/
108
+ )
108
109
  end
109
110
  end
110
111
 
@@ -119,7 +120,8 @@ describe Google::Auth::ClientId do
119
120
 
120
121
  it 'should raise error' do
121
122
  expect { Google::Auth::ClientId.from_hash(config) }.to raise_error(
122
- /Client id can not be nil/)
123
+ /Client id can not be nil/
124
+ )
123
125
  end
124
126
  end
125
127
 
@@ -134,7 +136,8 @@ describe Google::Auth::ClientId do
134
136
 
135
137
  it 'should raise error' do
136
138
  expect { Google::Auth::ClientId.from_hash(config) }.to raise_error(
137
- /Client secret can not be nil/)
139
+ /Client secret can not be nil/
140
+ )
138
141
  end
139
142
  end
140
143
  end
@@ -37,7 +37,7 @@ require 'googleauth/compute_engine'
37
37
  require 'spec_helper'
38
38
 
39
39
  describe Google::Auth::GCECredentials do
40
- MD_URI = 'http://169.254.169.254/computeMetadata/v1/instance/service-accounts/default/token'
40
+ MD_URI = 'http://169.254.169.254/computeMetadata/v1/instance/service-accounts/default/token'.freeze
41
41
  GCECredentials = Google::Auth::GCECredentials
42
42
 
43
43
  before(:example) do
@@ -64,8 +64,8 @@ describe Google::Auth::GCECredentials do
64
64
  stub = stub_request(:get, MD_URI)
65
65
  .to_return(status: 404,
66
66
  headers: { 'Metadata-Flavor' => 'Google' })
67
- blk = proc { @client.fetch_access_token! }
68
- expect(&blk).to raise_error Signet::AuthorizationError
67
+ expect { @client.fetch_access_token! }
68
+ .to raise_error Signet::AuthorizationError
69
69
  expect(stub).to have_been_requested
70
70
  end
71
71
 
@@ -73,10 +73,24 @@ describe Google::Auth::GCECredentials do
73
73
  stub = stub_request(:get, MD_URI)
74
74
  .to_return(status: 503,
75
75
  headers: { 'Metadata-Flavor' => 'Google' })
76
- blk = proc { @client.fetch_access_token! }
77
- expect(&blk).to raise_error Signet::AuthorizationError
76
+ expect { @client.fetch_access_token! }
77
+ .to raise_error Signet::AuthorizationError
78
78
  expect(stub).to have_been_requested
79
79
  end
80
+
81
+ it 'should fail with Signet::AuthorizationError if request times out' do
82
+ allow_any_instance_of(Faraday::Connection).to receive(:get)
83
+ .and_raise(Faraday::TimeoutError)
84
+ expect { @client.fetch_access_token! }
85
+ .to raise_error Signet::AuthorizationError
86
+ end
87
+
88
+ it 'should fail with Signet::AuthorizationError if request fails' do
89
+ allow_any_instance_of(Faraday::Connection).to receive(:get)
90
+ .and_raise(Faraday::ConnectionFailed, nil)
91
+ expect { @client.fetch_access_token! }
92
+ .to raise_error Signet::AuthorizationError
93
+ end
80
94
  end
81
95
  end
82
96
 
@@ -45,7 +45,8 @@ describe '#get_application_default' do
45
45
  @var_name = ENV_VAR
46
46
  @credential_vars = [
47
47
  ENV_VAR, PRIVATE_KEY_VAR, CLIENT_EMAIL_VAR, CLIENT_ID_VAR,
48
- CLIENT_SECRET_VAR, REFRESH_TOKEN_VAR, ACCOUNT_TYPE_VAR]
48
+ CLIENT_SECRET_VAR, REFRESH_TOKEN_VAR, ACCOUNT_TYPE_VAR
49
+ ]
49
50
  @original_env_vals = {}
50
51
  @credential_vars.each { |var| @original_env_vals[var] = ENV[var] }
51
52
  @home = ENV['HOME']
@@ -74,10 +75,9 @@ describe '#get_application_default' do
74
75
  Dir.mktmpdir do |dir|
75
76
  ENV.delete(@var_name) unless ENV[@var_name].nil? # no env var
76
77
  ENV['HOME'] = dir # no config present in this tmp dir
77
- blk = proc do
78
+ expect do
78
79
  Google::Auth.get_application_default(@scope, options)
79
- end
80
- expect(&blk).to raise_error RuntimeError
80
+ end.to raise_error RuntimeError
81
81
  end
82
82
  expect(stub).to have_been_requested
83
83
  end
@@ -215,10 +215,9 @@ describe '#get_application_default' do
215
215
  FileUtils.mkdir_p(File.dirname(key_path))
216
216
  File.write(key_path, cred_json_text)
217
217
  ENV[@var_name] = key_path
218
- blk = proc do
218
+ expect do
219
219
  Google::Auth.get_application_default(@scope, options)
220
- end
221
- expect(&blk).to raise_error RuntimeError
220
+ end.to raise_error RuntimeError
222
221
  end
223
222
  end
224
223
 
@@ -229,20 +228,18 @@ describe '#get_application_default' do
229
228
  FileUtils.mkdir_p(File.dirname(key_path))
230
229
  File.write(key_path, cred_json_text)
231
230
  ENV['HOME'] = dir
232
- blk = proc do
231
+ expect do
233
232
  Google::Auth.get_application_default(@scope, options)
234
- end
235
- expect(&blk).to raise_error RuntimeError
233
+ end.to raise_error RuntimeError
236
234
  end
237
235
  end
238
236
 
239
237
  it 'fails if env vars are set' do
240
238
  ENV[PRIVATE_KEY_VAR] = cred_json[:private_key]
241
239
  ENV[CLIENT_EMAIL_VAR] = cred_json[:client_email]
242
- blk = proc do
240
+ expect do
243
241
  Google::Auth.get_application_default(@scope, options)
244
- end
245
- expect(&blk).to raise_error RuntimeError
242
+ end.to raise_error RuntimeError
246
243
  end
247
244
  end
248
245
  end
@@ -39,13 +39,15 @@ describe Google::Auth::ScopeUtil do
39
39
 
40
40
  it 'normalizes the email scope' do
41
41
  expect(normalized).to include(
42
- 'https://www.googleapis.com/auth/userinfo.email')
42
+ 'https://www.googleapis.com/auth/userinfo.email'
43
+ )
43
44
  expect(normalized).to_not include 'email'
44
45
  end
45
46
 
46
47
  it 'normalizes the profile scope' do
47
48
  expect(normalized).to include(
48
- 'https://www.googleapis.com/auth/userinfo.profile')
49
+ 'https://www.googleapis.com/auth/userinfo.profile'
50
+ )
49
51
  expect(normalized).to_not include 'profile'
50
52
  end
51
53
 
@@ -137,9 +137,10 @@ describe Google::Auth::ServiceAccountCredentials do
137
137
  _claim, _header = JWT.decode(params.assoc('assertion').last,
138
138
  @key.public_key)
139
139
  end
140
- stub_request(:post, 'https://www.googleapis.com/oauth2/v3/token')
140
+ stub_request(:post, 'https://www.googleapis.com/oauth2/v4/token')
141
141
  .with(body: hash_including(
142
- 'grant_type' => 'urn:ietf:params:oauth:grant-type:jwt-bearer'),
142
+ 'grant_type' => 'urn:ietf:params:oauth:grant-type:jwt-bearer'
143
+ ),
143
144
  &blk)
144
145
  .to_return(body: body,
145
146
  status: 200,
@@ -164,7 +165,8 @@ describe Google::Auth::ServiceAccountCredentials do
164
165
  before(:example) do
165
166
  @var_name = ENV_VAR
166
167
  @credential_vars = [
167
- ENV_VAR, PRIVATE_KEY_VAR, CLIENT_EMAIL_VAR, ACCOUNT_TYPE_VAR]
168
+ ENV_VAR, PRIVATE_KEY_VAR, CLIENT_EMAIL_VAR, ACCOUNT_TYPE_VAR
169
+ ]
168
170
  @original_env_vals = {}
169
171
  @credential_vars.each { |var| @original_env_vals[var] = ENV[var] }
170
172
  ENV[ACCOUNT_TYPE_VAR] = cred_json[:type]
@@ -294,7 +296,8 @@ describe Google::Auth::ServiceAccountJwtHeaderCredentials do
294
296
  before(:example) do
295
297
  @var_name = ENV_VAR
296
298
  @credential_vars = [
297
- ENV_VAR, PRIVATE_KEY_VAR, CLIENT_EMAIL_VAR, ACCOUNT_TYPE_VAR]
299
+ ENV_VAR, PRIVATE_KEY_VAR, CLIENT_EMAIL_VAR, ACCOUNT_TYPE_VAR
300
+ ]
298
301
  @original_env_vals = {}
299
302
  @credential_vars.each { |var| @original_env_vals[var] = ENV[var] }
300
303
  ENV[ACCOUNT_TYPE_VAR] = cred_json[:type]
@@ -45,7 +45,8 @@ describe Signet::OAuth2::Client do
45
45
  scope: 'https://www.googleapis.com/auth/userinfo.profile',
46
46
  issuer: 'app@example.com',
47
47
  audience: 'https://accounts.google.com/o/oauth2/token',
48
- signing_key: @key)
48
+ signing_key: @key
49
+ )
49
50
  end
50
51
 
51
52
  def make_auth_stubs(opts)
@@ -60,8 +61,8 @@ describe Signet::OAuth2::Client do
60
61
  end
61
62
  stub_request(:post, 'https://accounts.google.com/o/oauth2/token')
62
63
  .with(body: hash_including(
63
- 'grant_type' => 'urn:ietf:params:oauth:grant-type:jwt-bearer'),
64
- &blk)
64
+ 'grant_type' => 'urn:ietf:params:oauth:grant-type:jwt-bearer'
65
+ ), &blk)
65
66
  .to_return(body: body,
66
67
  status: 200,
67
68
  headers: { 'Content-Type' => 'application/json' })
@@ -42,8 +42,7 @@ module FakeFS
42
42
  class File
43
43
  # FakeFS doesn't implement. And since we don't need to actually lock,
44
44
  # just stub out...
45
- def flock(*)
46
- end
45
+ def flock(*); end
47
46
  end
48
47
  end
49
48
 
@@ -82,7 +82,8 @@ describe Google::Auth::UserAuthorizer do
82
82
 
83
83
  it 'should include the callback uri' do
84
84
  expect(URI(uri).query).to match(
85
- %r{redirect_uri=https://www.example.com/oauth/callback})
85
+ %r{redirect_uri=https://www.example.com/oauth/callback}
86
+ )
86
87
  end
87
88
 
88
89
  it 'should include the scope' do
@@ -139,7 +140,8 @@ describe Google::Auth::UserAuthorizer do
139
140
  MultiJson.dump(
140
141
  access_token: 'accesstoken',
141
142
  refresh_token: 'refreshtoken',
142
- expiration_time_millis: 1_441_234_742_000)
143
+ expiration_time_millis: 1_441_234_742_000
144
+ )
143
145
  end
144
146
 
145
147
  context 'with a valid user id' do
@@ -150,7 +152,8 @@ describe Google::Auth::UserAuthorizer do
150
152
 
151
153
  it 'should return an instance of UserRefreshCredentials' do
152
154
  expect(credentials).to be_instance_of(
153
- Google::Auth::UserRefreshCredentials)
155
+ Google::Auth::UserRefreshCredentials
156
+ )
154
157
  end
155
158
 
156
159
  it 'should return credentials with a valid refresh token' do
@@ -226,7 +229,8 @@ describe Google::Auth::UserAuthorizer do
226
229
  it 'should persist the expiry as milliseconds' do
227
230
  expected_expiry = expiry * 1000
228
231
  expect(MultiJson.load(token_json)['expiration_time_millis']).to eql(
229
- expected_expiry)
232
+ expected_expiry
233
+ )
230
234
  end
231
235
  end
232
236
 
@@ -238,14 +242,16 @@ describe Google::Auth::UserAuthorizer do
238
242
  end
239
243
 
240
244
  before(:example) do
241
- stub_request(:post, 'https://www.googleapis.com/oauth2/v3/token')
245
+ stub_request(:post, 'https://www.googleapis.com/oauth2/v4/token')
242
246
  .to_return(body: token_json, status: 200, headers: {
243
- 'Content-Type' => 'application/json' })
247
+ 'Content-Type' => 'application/json'
248
+ })
244
249
  end
245
250
 
246
251
  it 'should exchange a code for credentials' do
247
252
  credentials = authorizer.get_credentials_from_code(
248
- user_id: 'user1', code: 'code')
253
+ user_id: 'user1', code: 'code'
254
+ )
249
255
  expect(credentials.access_token).to eq '1/abc123'
250
256
  end
251
257
 
@@ -256,14 +262,15 @@ describe Google::Auth::UserAuthorizer do
256
262
 
257
263
  it 'should store credentials when requested' do
258
264
  authorizer.get_and_store_credentials_from_code(
259
- user_id: 'user1', code: 'code')
265
+ user_id: 'user1', code: 'code'
266
+ )
260
267
  expect(token_store.load('user1')).to_not be_nil
261
268
  end
262
269
  end
263
270
 
264
271
  context 'with invalid authorization code' do
265
272
  before(:example) do
266
- stub_request(:post, 'https://www.googleapis.com/oauth2/v3/token')
273
+ stub_request(:post, 'https://www.googleapis.com/oauth2/v4/token')
267
274
  .to_return(status: 400)
268
275
  end
269
276
 
@@ -286,20 +293,23 @@ describe Google::Auth::UserAuthorizer do
286
293
  MultiJson.dump(
287
294
  access_token: 'accesstoken',
288
295
  refresh_token: 'refreshtoken',
289
- expiration_time_millis: 1_441_234_742_000)
296
+ expiration_time_millis: 1_441_234_742_000
297
+ )
290
298
  end
291
299
 
292
300
  before(:example) do
293
301
  token_store.store('user1', token_json)
294
302
  stub_request(
295
- :get, 'https://accounts.google.com/o/oauth2/revoke?token=refreshtoken')
303
+ :get, 'https://accounts.google.com/o/oauth2/revoke?token=refreshtoken'
304
+ )
296
305
  .to_return(status: 200)
297
306
  end
298
307
 
299
308
  it 'should revoke the grant' do
300
309
  authorizer.revoke_authorization('user1')
301
310
  expect(a_request(
302
- :get, 'https://accounts.google.com/o/oauth2/revoke?token=refreshtoken'))
311
+ :get, 'https://accounts.google.com/o/oauth2/revoke?token=refreshtoken'
312
+ ))
303
313
  .to have_been_made
304
314
  end
305
315
 
@@ -68,7 +68,7 @@ describe Google::Auth::UserRefreshCredentials do
68
68
  body = MultiJson.dump('access_token' => access_token,
69
69
  'token_type' => 'Bearer',
70
70
  'expires_in' => 3600)
71
- stub_request(:post, 'https://www.googleapis.com/oauth2/v3/token')
71
+ stub_request(:post, 'https://www.googleapis.com/oauth2/v4/token')
72
72
  .with(body: hash_including('grant_type' => 'refresh_token'))
73
73
  .to_return(body: body,
74
74
  status: 200,
@@ -87,7 +87,8 @@ describe Google::Auth::UserRefreshCredentials do
87
87
  @var_name = ENV_VAR
88
88
  @credential_vars = [
89
89
  ENV_VAR, CLIENT_ID_VAR, CLIENT_SECRET_VAR, REFRESH_TOKEN_VAR,
90
- ACCOUNT_TYPE_VAR]
90
+ ACCOUNT_TYPE_VAR
91
+ ]
91
92
  @original_env_vals = {}
92
93
  @credential_vars.each { |var| @original_env_vals[var] = ENV[var] }
93
94
  @scope = 'https://www.googleapis.com/auth/userinfo.profile'
@@ -288,7 +289,24 @@ describe Google::Auth::UserRefreshCredentials do
288
289
  it 'raises an authorization error' do
289
290
  stub
290
291
  expect { @client.revoke! }.to raise_error(
291
- Signet::AuthorizationError)
292
+ Signet::AuthorizationError
293
+ )
294
+ end
295
+ end
296
+
297
+ describe 'when erros occured with request' do
298
+ it 'should fail with Signet::AuthorizationError if request times out' do
299
+ allow_any_instance_of(Faraday::Connection).to receive(:get)
300
+ .and_raise(Faraday::TimeoutError)
301
+ expect { @client.revoke! }
302
+ .to raise_error Signet::AuthorizationError
303
+ end
304
+
305
+ it 'should fail with Signet::AuthorizationError if request fails' do
306
+ allow_any_instance_of(Faraday::Connection).to receive(:get)
307
+ .and_raise(Faraday::ConnectionFailed, nil)
308
+ expect { @client.revoke! }
309
+ .to raise_error Signet::AuthorizationError
292
310
  end
293
311
  end
294
312
  end
@@ -52,13 +52,15 @@ describe Google::Auth::WebUserAuthorizer do
52
52
  let(:env) do
53
53
  Rack::MockRequest.env_for(
54
54
  'http://example.com:8080/test',
55
- 'REMOTE_ADDR' => '10.10.10.10')
55
+ 'REMOTE_ADDR' => '10.10.10.10'
56
+ )
56
57
  end
57
58
  let(:request) { Rack::Request.new(env) }
58
59
  it 'should include current url in state' do
59
60
  url = authorizer.get_authorization_url(request: request)
60
61
  expect(url).to match(
61
- %r{%22current_uri%22:%22http://example.com:8080/test%22})
62
+ %r{%22current_uri%22:%22http://example.com:8080/test%22}
63
+ )
62
64
  end
63
65
 
64
66
  it 'should include request forgery token in state' do
@@ -76,20 +78,23 @@ describe Google::Auth::WebUserAuthorizer do
76
78
  it 'should resolve callback against base URL' do
77
79
  url = authorizer.get_authorization_url(request: request)
78
80
  expect(url).to match(
79
- %r{redirect_uri=http://example.com:8080/oauth2callback})
81
+ %r{redirect_uri=http://example.com:8080/oauth2callback}
82
+ )
80
83
  end
81
84
 
82
85
  it 'should allow overriding the current URL' do
83
86
  url = authorizer.get_authorization_url(
84
87
  request: request,
85
- redirect_to: '/foo')
88
+ redirect_to: '/foo'
89
+ )
86
90
  expect(url).to match %r{%22current_uri%22:%22/foo%22}
87
91
  end
88
92
 
89
93
  it 'should pass through login hint' do
90
94
  url = authorizer.get_authorization_url(
91
95
  request: request,
92
- login_hint: 'user@example.com')
96
+ login_hint: 'user@example.com'
97
+ )
93
98
  expect(url).to match(/login_hint=user@example.com/)
94
99
  end
95
100
  end
@@ -102,7 +107,7 @@ describe Google::Auth::WebUserAuthorizer do
102
107
  end
103
108
 
104
109
  before(:example) do
105
- stub_request(:post, 'https://www.googleapis.com/oauth2/v3/token')
110
+ stub_request(:post, 'https://www.googleapis.com/oauth2/v4/token')
106
111
  .to_return(body: token_json,
107
112
  status: 200,
108
113
  headers: { 'Content-Type' => 'application/json' })
@@ -113,7 +118,8 @@ describe Google::Auth::WebUserAuthorizer do
113
118
  'http://example.com:8080/oauth2callback?code=authcode&'\
114
119
  'state=%7B%22current_uri%22%3A%22%2Ffoo%22%2C%22'\
115
120
  'session_id%22%3A%22abc%22%7D',
116
- 'REMOTE_ADDR' => '10.10.10.10')
121
+ 'REMOTE_ADDR' => '10.10.10.10'
122
+ )
117
123
  end
118
124
  let(:request) { Rack::Request.new(env) }
119
125
 
@@ -123,7 +129,8 @@ describe Google::Auth::WebUserAuthorizer do
123
129
 
124
130
  it 'should return credentials when valid code present' do
125
131
  expect(credentials).to be_instance_of(
126
- Google::Auth::UserRefreshCredentials)
132
+ Google::Auth::UserRefreshCredentials
133
+ )
127
134
  end
128
135
 
129
136
  it 'should return next URL to redirect to' do
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.5.1
4
+ version: 0.5.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: 2016-01-06 00:00:00.000000000 Z
11
+ date: 2017-07-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0.9'
19
+ version: '0.12'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0.9'
26
+ version: '0.12'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: logging
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -120,7 +120,6 @@ files:
120
120
  - ".gitignore"
121
121
  - ".rspec"
122
122
  - ".rubocop.yml"
123
- - ".rubocop_todo.yml"
124
123
  - ".travis.yml"
125
124
  - CHANGELOG.md
126
125
  - CONTRIBUTING.md
@@ -179,7 +178,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
179
178
  version: '0'
180
179
  requirements: []
181
180
  rubyforge_project:
182
- rubygems_version: 2.4.3
181
+ rubygems_version: 2.6.8
183
182
  signing_key:
184
183
  specification_version: 4
185
184
  summary: Google Auth Library for Ruby
@@ -199,4 +198,3 @@ test_files:
199
198
  - spec/googleauth/user_refresh_spec.rb
200
199
  - spec/googleauth/web_user_authorizer_spec.rb
201
200
  - spec/spec_helper.rb
202
- has_rdoc: