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 +4 -4
- data/.gitignore +1 -0
- data/lib/g5_authentication_client/client.rb +2 -1
- data/lib/g5_authentication_client/role.rb +18 -0
- data/lib/g5_authentication_client/user.rb +11 -2
- data/lib/g5_authentication_client/version.rb +1 -1
- data/spec/g5_authentication_client/client_spec.rb +28 -14
- data/spec/g5_authentication_client/role_spec.rb +56 -1
- data/spec/g5_authentication_client/user_spec.rb +2 -2
- metadata +13 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: be1c6787c15da921ae231923ddfc0f5a25cca85c
|
4
|
+
data.tar.gz: 1009843592202ef3931935186427c5a7e9f1c26e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0347cb1540549a6e5b8413a37ad09014f81ebd9c7fa9360043343e0f8146eefdc6f473241e9b7d4f6133e4bac830de7f201b85eac6b89b0e879afab725c4b730
|
7
|
+
data.tar.gz: 0d24eed79d02d968579eb2c10860906b663a5180033cd831abc876d44273a81767ba33d0b2606872cca4ff8ab552e14b3cf615898c9f09d575fb11b8ea34c905
|
data/.gitignore
CHANGED
@@ -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
|
-
|
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|
|
59
|
-
|
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!
|
@@ -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
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
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) { '
|
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)
|
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
|
+
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-
|
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.
|
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:
|