g5_authentication_client 0.4.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8f1b72b556d88ccf5d3db877677efbbd8f969c1b
4
- data.tar.gz: 21a75a23db8b2e8106999de8e481923701fd9fad
3
+ metadata.gz: be1c6787c15da921ae231923ddfc0f5a25cca85c
4
+ data.tar.gz: 1009843592202ef3931935186427c5a7e9f1c26e
5
5
  SHA512:
6
- metadata.gz: 5eb630f56608ad0dda5705d63ee64c9cba567621220c37b7459239c7755d9b4ee3c2bcb12bc36919ee05653ed8073e644773604684f784c662ac3b38a5bfb27a
7
- data.tar.gz: b216905352a09469399fa36194e8973cca41a22cb715d810a64af6792b66d75e74469119c4cb2cfcbe325ff1d5c579c42fcf84bd69439b4cc15238ad1afafcd7
6
+ metadata.gz: 0347cb1540549a6e5b8413a37ad09014f81ebd9c7fa9360043343e0f8146eefdc6f473241e9b7d4f6133e4bac830de7f201b85eac6b89b0e879afab725c4b730
7
+ data.tar.gz: 0d24eed79d02d968579eb2c10860906b663a5180033cd831abc876d44273a81767ba33d0b2606872cca4ff8ab552e14b3cf615898c9f09d575fb11b8ea34c905
data/.gitignore CHANGED
@@ -7,3 +7,4 @@ pkg/*
7
7
  doc/*
8
8
  .yardoc
9
9
  coverage
10
+ .idea
@@ -98,7 +98,8 @@ module G5AuthenticationClient
98
98
  def create_user(options={})
99
99
  user=User.new(options)
100
100
  user.validate_for_create!
101
- response=oauth_access_token.post('/v1/users', body: user_hash(user.to_hash))
101
+ body = user_hash(user.to_hash)
102
+ response=oauth_access_token.post('/v1/users', body: body)
102
103
  User.new(response.parsed)
103
104
  end
104
105
 
@@ -5,9 +5,27 @@ module G5AuthenticationClient
5
5
  class Role < Modelish::Base
6
6
  ignore_unknown_properties!
7
7
 
8
+ GLOBAL = 'GLOBAL'
9
+
8
10
  # @!attribute [rw] name
9
11
  # @return [String]
10
12
  # The name associated with this user role
11
13
  property :name, type: String, required: true
14
+
15
+ # @!attribute [rw] type
16
+ # @return [String]
17
+ # The role's type. If 'GLOBAL' then not role not associated with a resource
18
+ property :type, type: String, required: true
19
+
20
+ # @!attribute [rw] urn
21
+ # @return [String]
22
+ # The role's resource urn. Will be nil if type='GLOBAL'
23
+ property :urn, type: String
24
+
25
+ def validate_for_create!
26
+ validate!
27
+ raise ArgumentError.new("URN required when type != '#{GLOBAL}'") if urn.nil? && type != GLOBAL
28
+ end
29
+
12
30
  end
13
31
  end
@@ -55,8 +55,17 @@ module G5AuthenticationClient
55
55
  # @return [Array<G5AuthenticationClient::Role>]
56
56
  # The user's roles. Not required to create a user.
57
57
  property :roles, default: [],
58
- type: proc { |val| val.map { |r| Role.new(r) } },
59
- validator: proc { |val| "User roles must be valid" if val && val.detect { |r| !r.valid? } }
58
+ type: proc { |val|
59
+ val.map { |r|
60
+ Role.new(r)
61
+ }
62
+ },
63
+ validator: proc { |val|
64
+ "User roles must be valid" if val &&
65
+ val.detect { |r|
66
+ !r.valid?
67
+ }
68
+ }
60
69
 
61
70
  def validate_for_create!
62
71
  validate!
@@ -1,3 +1,3 @@
1
1
  module G5AuthenticationClient
2
- VERSION = '0.4.0'
2
+ VERSION = '0.5.0'
3
3
  end
@@ -43,29 +43,31 @@ describe G5AuthenticationClient::Client do
43
43
  {email: email,
44
44
  password: "#{password}x",
45
45
  id: user_id,
46
- roles: [{name: role_name}]}
46
+ roles: [{name: role_name, urn: role_urn, type: role_type}]}
47
47
  end
48
48
 
49
49
  let(:new_user_request) do
50
50
  {
51
- "email"=>email,
52
- "first_name"=>"",
53
- "last_name"=>"",
54
- "organization_name"=>"",
55
- "password"=>"#{password}x",
56
- "password_confirmation"=>"",
57
- "phone_number"=>"",
58
- "title"=>"",
59
- "roles"=>["name"=>role_name]
51
+ 'email'=>email,
52
+ 'first_name'=>'',
53
+ 'last_name'=>'',
54
+ 'organization_name'=>'',
55
+ 'password'=>"#{password}x",
56
+ 'password_confirmation'=>'',
57
+ 'phone_number'=>'',
58
+ 'title'=>'',
59
+ 'roles'=>['name'=>role_name,'urn'=> role_urn, 'type'=>role_type]
60
60
  }
61
61
  end
62
62
 
63
63
  let(:email){'foo@blah.com'}
64
64
  let(:password){'mybigtestpasswored'}
65
65
  let(:user_id){1}
66
- let(:role_name) { 'my_role' }
66
+ let(:role_name) { 'my_role_1' }
67
+ let(:role_type) { 'G5Updatable::Client1' }
68
+ let(:role_urn) { 'someurn1' }
67
69
  let(:returned_user){{id: user_id,email: email,roles:[returned_role]}}
68
- let(:returned_role) { {'name' => role_name} }
70
+ let(:returned_role) { {'name' => role_name, 'type' => role_type, 'urn' => role_urn} }
69
71
 
70
72
  context 'with default configuration' do
71
73
  subject(:client) { G5AuthenticationClient::Client.new }
@@ -291,13 +293,19 @@ describe G5AuthenticationClient::Client do
291
293
 
292
294
  before do
293
295
  stub_request(:post, "#{endpoint}/v1/users").
294
- with(:body => {"user"=>new_user_request}, headers: {'Authorization' => auth_header_value}).
295
296
  to_return(status: 200,
296
297
  body: returned_user.to_json,
297
298
  headers: {'Content-Type' => 'application/json'})
298
299
  end
299
300
 
300
301
  it_should_behave_like 'an oauth protected resource', G5AuthenticationClient::User
302
+
303
+ it 'will have the appropriate body and Authorization header' do
304
+ create_user
305
+ expect(a_request(:post, "#{endpoint}/v1/users").
306
+ with(body: Faraday::NestedParamsEncoder.encode({'user'=>new_user_request}), headers: {'Authorization' => auth_header_value})).
307
+ to have_been_made.once
308
+ end
301
309
  end
302
310
 
303
311
  describe '#update_user' do
@@ -305,13 +313,19 @@ describe G5AuthenticationClient::Client do
305
313
 
306
314
  before do
307
315
  stub_request(:put, /#{endpoint}\/v1\/users\/#{user_id}/).
308
- with(:body => { "user" => new_user_request }, headers: {'Authorization' => auth_header_value}).
309
316
  to_return(status: 200,
310
317
  body: returned_user.to_json,
311
318
  headers: {'Content-Type' => 'application/json'})
312
319
  end
313
320
 
314
321
  it_should_behave_like 'an oauth protected resource', G5AuthenticationClient::User
322
+
323
+ it 'will have the appropriate body and Authorization header' do
324
+ update_user
325
+ expect(a_request(:put, /#{endpoint}\/v1\/users\/#{user_id}/).
326
+ with(body: Faraday::NestedParamsEncoder.encode({'user'=>new_user_request}), headers: {'Authorization' => auth_header_value})).
327
+ to have_been_made.once
328
+ end
315
329
  end
316
330
 
317
331
  describe '#find_user_by_email' do
@@ -3,8 +3,16 @@ require 'spec_helper'
3
3
  describe G5AuthenticationClient::Role do
4
4
  subject(:role) { G5AuthenticationClient::Role.new(attributes) }
5
5
 
6
- let(:attributes) { {name: name} }
6
+ let(:attributes) do {
7
+ name: name,
8
+ type: type,
9
+ urn: urn,
10
+ }
11
+ end
12
+
7
13
  let(:name) { 'awesome_role' }
14
+ let(:type) { 'SomeClass' }
15
+ let(:urn) { 'some_urn' }
8
16
 
9
17
  context 'with default initialization' do
10
18
  let(:attributes) {}
@@ -12,12 +20,24 @@ describe G5AuthenticationClient::Role do
12
20
  it 'should have a nil name' do
13
21
  expect(role.name).to be_nil
14
22
  end
23
+ it 'has a nil type' do
24
+ expect(role.type).to be_nil
25
+ end
26
+ it 'has a nil urn' do
27
+ expect(role.urn).to be_nil
28
+ end
15
29
  end
16
30
 
17
31
  context 'with full initialization' do
18
32
  it 'should have the correct name' do
19
33
  expect(role.name).to eq(name)
20
34
  end
35
+ it 'should have the correct name' do
36
+ expect(role.type).to eq(type)
37
+ end
38
+ it 'should have the correct name' do
39
+ expect(role.urn).to eq(urn)
40
+ end
21
41
  end
22
42
 
23
43
  context 'when attributes include unknown properties' do
@@ -54,6 +74,41 @@ describe G5AuthenticationClient::Role do
54
74
  end
55
75
  end
56
76
 
77
+ describe '#validate_for_create!' do
78
+ subject(:validate_for_create) {role.validate_for_create!}
79
+
80
+ context 'when type not GLOBAL and no urn' do
81
+
82
+ let(:type) { 'not_global' }
83
+ let(:urn) { }
84
+
85
+ it 'will raise an error' do
86
+ expect { validate_for_create }.to raise_error
87
+ end
88
+ end
89
+
90
+ context 'when type GLOBAL and no urn' do
91
+
92
+ let(:type) { 'GLOBAL' }
93
+ let(:urn) { }
94
+
95
+ it 'will raise an error' do
96
+ expect { validate_for_create }.to_not raise_error
97
+ end
98
+ end
99
+
100
+ context 'when type not GLOBAL and existing urn' do
101
+
102
+ let(:type) { 'NOT_GLOBAL' }
103
+ let(:urn) { 'some_urn' }
104
+
105
+ it 'will raise an error' do
106
+ expect { validate_for_create }.to_not raise_error
107
+ end
108
+ end
109
+
110
+ end
111
+
57
112
  describe '#to_hash' do
58
113
  subject(:hash) { role.to_hash }
59
114
 
@@ -13,7 +13,7 @@ describe G5AuthenticationClient::User do
13
13
  title: title,
14
14
  organization_name: organization_name,
15
15
  phone_number: phone_number,
16
- roles: [{name: role_name}]
16
+ roles: [{name: role_name, type:'G5Updatable::Client', urn:'someurn'}]
17
17
  }
18
18
  end
19
19
 
@@ -243,7 +243,7 @@ describe G5AuthenticationClient::User do
243
243
  end
244
244
 
245
245
  it 'should have roles' do
246
- expect(to_hash['roles']).to eq([{'name' => role_name}])
246
+ expect(to_hash['roles']).to eq([{'name' => role_name, 'type'=>'G5Updatable::Client', 'urn'=>'someurn'}])
247
247
  end
248
248
  end
249
249
  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.4.0
4
+ version: 0.5.0
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-05-20 00:00:00.000000000 Z
12
+ date: 2015-06-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: modelish
@@ -246,9 +246,18 @@ required_rubygems_version: !ruby/object:Gem::Requirement
246
246
  version: '0'
247
247
  requirements: []
248
248
  rubyforge_project: g5_authentication_client
249
- rubygems_version: 2.2.3
249
+ rubygems_version: 2.4.7
250
250
  signing_key:
251
251
  specification_version: 4
252
252
  summary: Client for the G5 Auth service
253
- test_files: []
253
+ test_files:
254
+ - spec/g5_authentication_client/client_spec.rb
255
+ - spec/g5_authentication_client/configuration_spec.rb
256
+ - spec/g5_authentication_client/role_spec.rb
257
+ - spec/g5_authentication_client/token_info_spec.rb
258
+ - spec/g5_authentication_client/user_spec.rb
259
+ - spec/g5_authentication_client_spec.rb
260
+ - spec/spec_helper.rb
261
+ - spec/support/module_configured_attribute.rb
262
+ - spec/support/oauth_protected_resource.rb
254
263
  has_rdoc: