g5_authentication_client 0.5.2 → 0.5.3

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: c53ebcac18a16bd552178866980fafac5c8a0ae4
4
- data.tar.gz: 17ca20696af027a5535bc29e4d3e8d7ef23b7ab6
3
+ metadata.gz: 7463214386cb26b951d8a2046fc473956679b4af
4
+ data.tar.gz: e1d54d81273360a07c93795346943ad71e2e21dd
5
5
  SHA512:
6
- metadata.gz: e8ec55c0c2826bcd192a1920ac3dc53d51df2edea1ef00464ef889b3a4e8cdb079f6e0ff391e19c679cefb1451e661755e64470b79cd0cf045b215288bef81f7
7
- data.tar.gz: 088cf07f5d346f9b5de42d412a936fd1b676296d9f734e309f3536b166a43d660e034c70c033563aa9e4a402e5815e940a34d1b303752f2073c4651884c714e7
6
+ metadata.gz: 51a5fbf9a712e05f1c9ab9e977da28d30d99ae4dbe0ab9d561fea5df207e9ff7ce5569a501f888b2af0db94695494b18e1ca520c9352064079f066bbeed34836
7
+ data.tar.gz: 71e4dc676d3734ba9b35049506222d2e94b282889bb51e396ec73b404955cdbb86abae0c499e9da15956b67ebfea9611031186935822cfc34ff5a70324ae2c8b
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.2.2
1
+ 2.1.6
data/CHANGELOG.md CHANGED
@@ -1,3 +1,13 @@
1
+ ## v0.5.3
2
+
3
+ * `Client#username_pw_access_token`: raise error when username/password are blank
4
+ ([#29](https://github.com/G5/g5_authentication_client/pull/29))
5
+
6
+ ## v0.5.2
7
+
8
+ * convenience method for access tokens
9
+ ([#27](https://github.com/G5/g5_authentication_client/pull/27))
10
+
1
11
  ## v0.5.1 (2015-08-21)
2
12
 
3
13
  * Allow user attributes to be selectively updated
@@ -69,7 +69,7 @@ module G5AuthenticationClient
69
69
  # Tells whether a client instance will use the username/password credentials
70
70
  # @return [Boolean] whether the client will use username/password
71
71
  def allow_password_credentials?
72
- allow_password_credentials=='true' && !username.nil? && !password.nil?
72
+ allow_password_credentials=='true'
73
73
  end
74
74
 
75
75
  # Retrieves the access token as a string
@@ -185,12 +185,22 @@ module G5AuthenticationClient
185
185
  end
186
186
 
187
187
  def username_pw_access_token
188
+ raise_if_blank('username')
189
+ raise_if_blank('password')
188
190
  raise 'allow_password_credentials must be enabled for username/pw access' unless allow_password_credentials?
189
191
  oauth_client.password.get_token(username, password)
190
192
  end
191
193
 
192
194
  private
193
195
 
196
+ def raise_if_blank(client_attribute)
197
+ attr = send(client_attribute)
198
+ if attr.nil? || attr.strip == ''
199
+ raise G5AuthenticationClient::Error.
200
+ new("#{client_attribute} is blank, provide a #{client_attribute} by setting it in the client instance or adding a G5_AUTH_#{client_attribute.upcase} env variable.")
201
+ end
202
+ end
203
+
194
204
  def user_hash(h)
195
205
  user_params = h.reject { |k,v| k == 'id' || v.nil? || v.empty? }
196
206
  { user: user_params }
@@ -0,0 +1,5 @@
1
+ module G5AuthenticationClient
2
+ class Error < StandardError
3
+
4
+ end
5
+ end
@@ -1,3 +1,3 @@
1
1
  module G5AuthenticationClient
2
- VERSION = '0.5.2'
2
+ VERSION = '0.5.3'
3
3
  end
@@ -5,6 +5,7 @@ require 'g5_authentication_client/user'
5
5
  require 'g5_authentication_client/token_info'
6
6
  require 'g5_authentication_client/role'
7
7
  require 'g5_authentication_client/auth_token_helper'
8
+ require 'g5_authentication_client/error'
8
9
 
9
10
  module G5AuthenticationClient
10
11
  extend Configuration
@@ -17,7 +17,8 @@ describe G5AuthenticationClient::Client do
17
17
  let(:authorization_code){ 'code' }
18
18
  let(:allow_password_credentials){ 'false' }
19
19
 
20
- let(:options) do
20
+ let(:options) { default_options }
21
+ let(:default_options) do
21
22
  {
22
23
  debug: debug,
23
24
  logger: logger,
@@ -128,9 +129,6 @@ describe G5AuthenticationClient::Client do
128
129
  expect(client.allow_password_credentials).to eq('true')
129
130
  end
130
131
 
131
- it 'username_pw_access_token raises error when password credentials not enabled' do
132
- expect { client.username_pw_access_token }.to raise_error('allow_password_credentials must be enabled for username/pw access')
133
- end
134
132
  end
135
133
 
136
134
  context 'with non-default configuration' do
@@ -262,37 +260,12 @@ describe G5AuthenticationClient::Client do
262
260
 
263
261
  context 'when the allow_password_credentials is set to true' do
264
262
  let(:allow_password_credentials) {'true'}
265
-
266
- context 'with non-nil username and password' do
267
-
268
- it 'should be true' do
269
- expect(subject).to be true
270
- end
271
- end
272
-
273
- context 'when username is nil' do
274
- let(:username) {}
275
-
276
- it 'should be false' do
277
- expect(subject).to be false
278
- end
279
- end
280
-
281
- context 'when password is nil' do
282
- let(:password) {}
283
-
284
- it 'should be false' do
285
- expect(subject).to be false
286
- end
287
- end
263
+ it { is_expected.to be true }
288
264
  end
289
265
 
290
266
  context 'when the allow_password_credentials is set to false' do
291
267
  let(:allow_password_credentials) {'false'}
292
-
293
- it 'should be false' do
294
- expect(subject).to be false
295
- end
268
+ it { is_expected.to be false }
296
269
  end
297
270
  end
298
271
 
@@ -523,22 +496,33 @@ describe G5AuthenticationClient::Client do
523
496
  end
524
497
  end
525
498
 
526
- context 'stubbed get token' do
499
+ describe '#username_pw_access_token' do
527
500
  let(:token) {'asdf'}
528
501
  before do
529
502
  oauth_client = double(OAuth2::AccessToken, password: double(:pw, get_token: token))
530
503
  allow(client).to receive(:oauth_client).and_return(oauth_client)
504
+ client.allow_password_credentials = 'true'
531
505
  end
532
506
 
533
- describe '#username_pw_access_token' do
534
- let(:returned_token) { {access_token: 'asdf'} }
535
- before do
536
- client.allow_password_credentials = 'true'
537
- end
538
-
507
+ context 'allow_password_credentials is `true`' do
539
508
  it 'delegates token retrieval to oauth_client' do
540
509
  expect(client.username_pw_access_token).to eq(token)
541
510
  end
542
511
  end
512
+
513
+ context 'username is blank' do
514
+ let(:options) { default_options.merge(username: " ") }
515
+ it 'raises an error' do
516
+ expect { client.username_pw_access_token }.to raise_error(G5AuthenticationClient::Error, 'username is blank, provide a username by setting it in the client instance or adding a G5_AUTH_USERNAME env variable.')
517
+ end
518
+ end
519
+
520
+ context 'password is blank' do
521
+ let(:options) { default_options.merge(password: " ") }
522
+ it 'raises an error' do
523
+ expect { client.username_pw_access_token }.to raise_error(G5AuthenticationClient::Error, 'password is blank, provide a password by setting it in the client instance or adding a G5_AUTH_PASSWORD env variable.')
524
+ end
525
+ end
543
526
  end
527
+
544
528
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: g5_authentication_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.2
4
+ version: 0.5.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rob Revels
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-12-02 00:00:00.000000000 Z
12
+ date: 2016-01-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: modelish
@@ -215,6 +215,7 @@ files:
215
215
  - lib/g5_authentication_client/auth_token_helper.rb
216
216
  - lib/g5_authentication_client/client.rb
217
217
  - lib/g5_authentication_client/configuration.rb
218
+ - lib/g5_authentication_client/error.rb
218
219
  - lib/g5_authentication_client/role.rb
219
220
  - lib/g5_authentication_client/token_info.rb
220
221
  - lib/g5_authentication_client/user.rb
@@ -248,7 +249,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
248
249
  version: '0'
249
250
  requirements: []
250
251
  rubyforge_project: g5_authentication_client
251
- rubygems_version: 2.4.5
252
+ rubygems_version: 2.4.8
252
253
  signing_key:
253
254
  specification_version: 4
254
255
  summary: Client for the G5 Auth service