g5_authenticatable 0.5.1 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/Gemfile +1 -0
- data/app/models/g5_authenticatable/user.rb +15 -1
- data/g5_authenticatable.gemspec +3 -3
- data/lib/g5_authenticatable/test/feature_helpers.rb +1 -1
- data/lib/g5_authenticatable/version.rb +1 -1
- data/spec/features/sign_in_spec.rb +2 -2
- data/spec/models/g5_authenticatable/user_spec.rb +152 -48
- metadata +8 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 93238b9dd28980b2722ffc334c98c7c29aed9952
|
4
|
+
data.tar.gz: cd9eaa8d01343dd9463a0a6a2cc082331ec89f49
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 39a183780b26fb0bb1c730797504f549bd7510d10e76bf6946b52d818de6b5215649eebb48717150cffa551e337e0cea7c85e3891c9ee3a1196b6437aa4c080f
|
7
|
+
data.tar.gz: 036629738e9fd3c4f1888f9bd53b82a1bf61485bf01305cc97da8ebb32c9a342d792ec2e3b68abc5db9eb91ecf6202f8f03079d5f7dcaf66d981ca1423eed60d
|
data/.gitignore
CHANGED
data/Gemfile
CHANGED
@@ -32,7 +32,19 @@ module G5Authenticatable
|
|
32
32
|
|
33
33
|
def update_roles_from_auth(auth_data)
|
34
34
|
roles.clear
|
35
|
-
auth_data.extra.roles.each
|
35
|
+
auth_data.extra.roles.each do |role|
|
36
|
+
if(role.type == 'GLOBAL')
|
37
|
+
add_role(role.name)
|
38
|
+
else
|
39
|
+
begin
|
40
|
+
the_class = Object.const_get(role.type)
|
41
|
+
resource = the_class.where(urn: role.urn).first
|
42
|
+
add_role(role.name, resource)
|
43
|
+
rescue => e
|
44
|
+
Rails.logger.error(e)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
36
48
|
end
|
37
49
|
|
38
50
|
private
|
@@ -45,5 +57,7 @@ module G5Authenticatable
|
|
45
57
|
organization_name: auth_data.extra.organization_name
|
46
58
|
}
|
47
59
|
end
|
60
|
+
|
61
|
+
|
48
62
|
end
|
49
63
|
end
|
data/g5_authenticatable.gemspec
CHANGED
@@ -20,9 +20,9 @@ Gem::Specification.new do |spec|
|
|
20
20
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
21
21
|
spec.require_paths = ['lib']
|
22
22
|
|
23
|
-
spec.add_dependency 'devise_g5_authenticatable', '~> 0.2
|
24
|
-
spec.add_dependency 'omniauth-g5', '~> 0.
|
25
|
-
spec.add_dependency 'g5_authenticatable_api', '~> 0.
|
23
|
+
spec.add_dependency 'devise_g5_authenticatable', '~> 0.2.2'
|
24
|
+
spec.add_dependency 'omniauth-g5', '~> 0.3'
|
25
|
+
spec.add_dependency 'g5_authenticatable_api', '~> 0.4.1'
|
26
26
|
spec.add_dependency 'rolify', '~> 4.0'
|
27
27
|
spec.add_dependency 'pundit', '~> 1.0'
|
28
28
|
end
|
@@ -28,7 +28,7 @@ describe 'Signing in' do
|
|
28
28
|
extra: {
|
29
29
|
title: updated_title,
|
30
30
|
organization_name: updated_organization_name,
|
31
|
-
roles: [{name: updated_role.name}],
|
31
|
+
roles: [{name: updated_role.name, type: 'GLOBAL', urn: nil}],
|
32
32
|
raw_info: {}
|
33
33
|
}
|
34
34
|
})
|
@@ -123,7 +123,7 @@ describe 'Signing in' do
|
|
123
123
|
extra: {
|
124
124
|
title: user_attributes[:title],
|
125
125
|
organization_name: user_attributes[:organization_name],
|
126
|
-
roles: [{name: role_attributes[:name]}],
|
126
|
+
roles: [{name: role_attributes[:name], type: 'GLOBAL', urn: nil}],
|
127
127
|
raw_info: {}
|
128
128
|
}
|
129
129
|
})
|
@@ -64,30 +64,31 @@ describe G5Authenticatable::User do
|
|
64
64
|
|
65
65
|
let(:params) { Hash.new }
|
66
66
|
let(:auth_data) do
|
67
|
-
OmniAuth::AuthHash.new(
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
'
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
'
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
'
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
67
|
+
OmniAuth::AuthHash.new(
|
68
|
+
{
|
69
|
+
'provider' => new_user_attributes[:provider],
|
70
|
+
'uid' => new_user_attributes[:uid],
|
71
|
+
'info' => {
|
72
|
+
'email' => new_user_attributes[:email],
|
73
|
+
'name' => "#{new_user_attributes[:first_name]} #{new_user_attributes[:last_name]}",
|
74
|
+
'first_name' => new_user_attributes[:first_name],
|
75
|
+
'last_name' => new_user_attributes[:last_name],
|
76
|
+
'phone' => new_user_attributes[:phone_number]
|
77
|
+
},
|
78
|
+
'credentials' => {
|
79
|
+
'token' => new_user_attributes[:g5_access_token],
|
80
|
+
'expires' => true,
|
81
|
+
'expires_at' => Time.now + 1000
|
82
|
+
},
|
83
|
+
'extra' => {
|
84
|
+
'title' => new_user_attributes[:title],
|
85
|
+
'organization_name' => new_user_attributes[:organization_name],
|
86
|
+
'roles' => [
|
87
|
+
{'name' => new_role_attributes[:name], 'type' => 'GLOBAL', 'urn' => nil}
|
88
|
+
],
|
89
|
+
'raw_info' => {}
|
90
|
+
}
|
91
|
+
})
|
91
92
|
end
|
92
93
|
|
93
94
|
let(:new_user_attributes) { FactoryGirl.attributes_for(:g5_authenticatable_user) }
|
@@ -180,7 +181,7 @@ describe G5Authenticatable::User do
|
|
180
181
|
phone_number: nil,
|
181
182
|
title: nil,
|
182
183
|
organization_name: nil
|
183
|
-
|
184
|
+
)
|
184
185
|
end
|
185
186
|
let(:role_name) { :my_role }
|
186
187
|
|
@@ -190,29 +191,30 @@ describe G5Authenticatable::User do
|
|
190
191
|
end
|
191
192
|
|
192
193
|
let(:auth_data) do
|
193
|
-
OmniAuth::AuthHash.new(
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
'
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
'
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
'
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
194
|
+
OmniAuth::AuthHash.new(
|
195
|
+
{
|
196
|
+
'provider' => user_attributes[:provider],
|
197
|
+
'uid' => user_attributes[:uid],
|
198
|
+
'info' => {
|
199
|
+
'email' => updated_attributes[:email],
|
200
|
+
'first_name' => updated_attributes[:first_name],
|
201
|
+
'last_name' => updated_attributes[:last_name],
|
202
|
+
'phone' => updated_attributes[:phone_number]
|
203
|
+
},
|
204
|
+
'credentials' => {
|
205
|
+
'token' => updated_attributes[:g5_access_token],
|
206
|
+
'expires' => true,
|
207
|
+
'expires_at' => Time.now + 1000
|
208
|
+
},
|
209
|
+
'extra' => {
|
210
|
+
'title' => updated_attributes[:title],
|
211
|
+
'organization_name' => updated_attributes[:organization_name],
|
212
|
+
'roles' => [
|
213
|
+
{name: updated_role_name, type: 'GLOBAL', urn: nil}
|
214
|
+
],
|
215
|
+
'raw_info' => {}
|
216
|
+
}
|
217
|
+
})
|
216
218
|
end
|
217
219
|
|
218
220
|
context 'when user info is the same' do
|
@@ -373,4 +375,106 @@ describe G5Authenticatable::User do
|
|
373
375
|
end
|
374
376
|
end
|
375
377
|
end
|
378
|
+
|
379
|
+
describe '#update_roles_from_auth' do
|
380
|
+
before do
|
381
|
+
user.roles = []
|
382
|
+
user.save!
|
383
|
+
end
|
384
|
+
|
385
|
+
let(:user2) { G5Authenticatable::User.create(user_attributes) }
|
386
|
+
let(:user_attributes2) { FactoryGirl.attributes_for(:g5_authenticatable_user) }
|
387
|
+
let(:mock_urn) { 'mock_urn' }
|
388
|
+
|
389
|
+
|
390
|
+
let(:mock_resource_class) { Class.new }
|
391
|
+
before { stub_const('MockResource', mock_resource_class) }
|
392
|
+
|
393
|
+
let(:mock_resource) { stub_model(mock_resource_class, urn: mock_urn) }
|
394
|
+
before do
|
395
|
+
allow(mock_resource_class).to receive(:where).with(urn: mock_urn).and_return([mock_resource])
|
396
|
+
end
|
397
|
+
|
398
|
+
let(:auth_data) do
|
399
|
+
OmniAuth::AuthHash.new(
|
400
|
+
{
|
401
|
+
'provider' => user_attributes[:provider],
|
402
|
+
'uid' => user_attributes[:uid],
|
403
|
+
'info' => {
|
404
|
+
'email' => user_attributes[:email],
|
405
|
+
'first_name' => user_attributes[:first_name],
|
406
|
+
'last_name' => user_attributes[:last_name],
|
407
|
+
'phone' => user_attributes[:phone_number]
|
408
|
+
},
|
409
|
+
'credentials' => {
|
410
|
+
'token' => user_attributes[:g5_access_token],
|
411
|
+
'expires' => true,
|
412
|
+
'expires_at' => Time.now + 1000
|
413
|
+
},
|
414
|
+
'extra' => {
|
415
|
+
'title' => user_attributes[:title],
|
416
|
+
'organization_name' => user_attributes[:organization_name],
|
417
|
+
'roles' => roles,
|
418
|
+
'raw_info' => {}
|
419
|
+
}
|
420
|
+
})
|
421
|
+
end
|
422
|
+
|
423
|
+
context 'with global role' do
|
424
|
+
let(:roles) { [
|
425
|
+
{name: 'admin', type: 'GLOBAL', urn: nil}
|
426
|
+
] }
|
427
|
+
|
428
|
+
it 'will add a global role' do
|
429
|
+
expect{ user.update_roles_from_auth(auth_data) }.to change{ user.roles.length }.from(0).to(1)
|
430
|
+
expect(user.roles.first.name).to eq('admin')
|
431
|
+
expect(user.roles.first.resource).to be_nil
|
432
|
+
end
|
433
|
+
end
|
434
|
+
|
435
|
+
context 'with a scoped role' do
|
436
|
+
let(:roles) { [
|
437
|
+
{name: 'viewer', type: 'MockResource', urn: mock_urn}
|
438
|
+
] }
|
439
|
+
|
440
|
+
it 'will add a scoped role' do
|
441
|
+
expect{ user.update_roles_from_auth(auth_data) }.to change{ user.roles.length }.from(0).to(1)
|
442
|
+
expect(user.roles.first.name).to eq('viewer')
|
443
|
+
expect(user.roles.first.resource_id).to eq(mock_resource.id)
|
444
|
+
expect(user.roles.first.resource_type).to eq('MockResource')
|
445
|
+
end
|
446
|
+
end
|
447
|
+
|
448
|
+
context 'with a more than 1 role' do
|
449
|
+
let(:roles) { [
|
450
|
+
{name: 'viewer', type: 'MockResource', urn: mock_urn},
|
451
|
+
{name: 'admin', type: 'GLOBAL', urn: nil}
|
452
|
+
] }
|
453
|
+
|
454
|
+
it 'will add a scoped role' do
|
455
|
+
expect{ user.update_roles_from_auth(auth_data) }.to change{ user.roles.length }.from(0).to(2)
|
456
|
+
end
|
457
|
+
end
|
458
|
+
context 'with 0 roles' do
|
459
|
+
let(:roles) { [] }
|
460
|
+
|
461
|
+
it 'will add a scoped role' do
|
462
|
+
expect{ user.update_roles_from_auth(auth_data) }.to_not change{ user.roles.length }.from(0)
|
463
|
+
end
|
464
|
+
end
|
465
|
+
|
466
|
+
context 'with a bad role type' do
|
467
|
+
let(:roles) { [
|
468
|
+
{name: 'viewer', type: 'MockResource', urn: mock_urn},
|
469
|
+
{name: 'viewer', type: 'BadResource', urn: mock_urn}
|
470
|
+
] }
|
471
|
+
|
472
|
+
it 'will skip the bad role' do
|
473
|
+
expect{ user.update_roles_from_auth(auth_data) }.to change{ user.roles.length }.from(0).to(1)
|
474
|
+
expect(user.roles.first.name).to eq('viewer')
|
475
|
+
expect(user.roles.first.resource_id).to eq(mock_resource.id)
|
476
|
+
expect(user.roles.first.resource_type).to eq('MockResource')
|
477
|
+
end
|
478
|
+
end
|
479
|
+
end
|
376
480
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: g5_authenticatable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- maeve
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-06-
|
11
|
+
date: 2015-06-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: devise_g5_authenticatable
|
@@ -16,48 +16,42 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
20
|
-
- - ">="
|
21
|
-
- !ruby/object:Gem::Version
|
22
|
-
version: 0.2.1
|
19
|
+
version: 0.2.2
|
23
20
|
type: :runtime
|
24
21
|
prerelease: false
|
25
22
|
version_requirements: !ruby/object:Gem::Requirement
|
26
23
|
requirements:
|
27
24
|
- - "~>"
|
28
25
|
- !ruby/object:Gem::Version
|
29
|
-
version:
|
30
|
-
- - ">="
|
31
|
-
- !ruby/object:Gem::Version
|
32
|
-
version: 0.2.1
|
26
|
+
version: 0.2.2
|
33
27
|
- !ruby/object:Gem::Dependency
|
34
28
|
name: omniauth-g5
|
35
29
|
requirement: !ruby/object:Gem::Requirement
|
36
30
|
requirements:
|
37
31
|
- - "~>"
|
38
32
|
- !ruby/object:Gem::Version
|
39
|
-
version: '0.
|
33
|
+
version: '0.3'
|
40
34
|
type: :runtime
|
41
35
|
prerelease: false
|
42
36
|
version_requirements: !ruby/object:Gem::Requirement
|
43
37
|
requirements:
|
44
38
|
- - "~>"
|
45
39
|
- !ruby/object:Gem::Version
|
46
|
-
version: '0.
|
40
|
+
version: '0.3'
|
47
41
|
- !ruby/object:Gem::Dependency
|
48
42
|
name: g5_authenticatable_api
|
49
43
|
requirement: !ruby/object:Gem::Requirement
|
50
44
|
requirements:
|
51
45
|
- - "~>"
|
52
46
|
- !ruby/object:Gem::Version
|
53
|
-
version: 0.
|
47
|
+
version: 0.4.1
|
54
48
|
type: :runtime
|
55
49
|
prerelease: false
|
56
50
|
version_requirements: !ruby/object:Gem::Requirement
|
57
51
|
requirements:
|
58
52
|
- - "~>"
|
59
53
|
- !ruby/object:Gem::Version
|
60
|
-
version: 0.
|
54
|
+
version: 0.4.1
|
61
55
|
- !ruby/object:Gem::Dependency
|
62
56
|
name: rolify
|
63
57
|
requirement: !ruby/object:Gem::Requirement
|