g5_authenticatable 1.1.2.pre.1 → 1.1.2.rc.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +0 -2
- data/README.md +2 -2
- data/app/models/g5_authenticatable/user.rb +0 -1
- data/app/policies/g5_authenticatable/base_policy.rb +17 -7
- data/lib/g5_authenticatable/version.rb +1 -1
- data/spec/models/g5_authenticatable/user_spec.rb +125 -130
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c2cb34d3b28574111f10bb4db862b8b54276bd825763a7540294d353906e81e8
|
4
|
+
data.tar.gz: fa649cec65a016088cf63073e3503b546a7daeb19d0de5d5393a49480070e1a3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 744623d894aac98bc79523e84d9aab3c42a1ae59733bce8cb95e1c929685c1746b48dbed9c3fdad09f1c1207af6f66ce7c19c55aabb9352ea9624a3ed0d60303
|
7
|
+
data.tar.gz: 948276bb53c47074e9425cd2f1e9f3d9473b8521936b20d3fe3ab48b93858f5bd18eeb12ea45ea6cdb9da663bafb062d64f748974f1db83350b29410fea638fb
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -76,7 +76,7 @@ root to: 'home#index'
|
|
76
76
|
### Registering your OAuth application
|
77
77
|
|
78
78
|
1. Visit the auth server admin console and login:
|
79
|
-
* For development, visit https://auth
|
79
|
+
* For development, visit https://dev-auth.g5search.com/admin
|
80
80
|
* For production, visit https://auth.g5search.com/admin
|
81
81
|
2. Click "New Application"
|
82
82
|
3. Enter a name that recognizably identifies your application.
|
@@ -106,7 +106,7 @@ environment variables for your client application:
|
|
106
106
|
* `G5_AUTH_CLIENT_SECRET` - the OAuth 2.0 application secret from the auth server
|
107
107
|
* `G5_AUTH_REDIRECT_URI` - the OAuth 2.0 redirect URI registered with the auth server
|
108
108
|
* `G5_AUTH_ENDPOINT` - the endpoint URL (without any path info) for the G5 auth server.
|
109
|
-
Generally, this will be set to either `https://auth
|
109
|
+
Generally, this will be set to either `https://dev-auth.g5search.com` or
|
110
110
|
`https://auth.g5search.com` (the default).
|
111
111
|
|
112
112
|
If you need to make server-to-server API calls that are not associated with an
|
@@ -71,16 +71,26 @@ module G5Authenticatable
|
|
71
71
|
user.present? && user.has_role?(:super_admin)
|
72
72
|
end
|
73
73
|
|
74
|
-
def
|
75
|
-
user.present?
|
74
|
+
def check_for_role(role_name,global_scope=false)
|
75
|
+
if user.present?
|
76
|
+
query = user.roles.where(name: role_name)
|
77
|
+
query = query.where(resource_type: nil) if global_scope
|
78
|
+
return query.exists?
|
79
|
+
else
|
80
|
+
return false
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def admin?(global_scope=false)
|
85
|
+
check_for_role(:admin,global_scope)
|
76
86
|
end
|
77
87
|
|
78
|
-
def editor?
|
79
|
-
|
88
|
+
def editor?(global_scope=false)
|
89
|
+
check_for_role(:editor,global_scope)
|
80
90
|
end
|
81
91
|
|
82
|
-
def viewer?
|
83
|
-
|
92
|
+
def viewer?(global_scope=false)
|
93
|
+
check_for_role(:viewer,global_scope)
|
84
94
|
end
|
85
95
|
|
86
96
|
def has_global_role?
|
@@ -92,7 +102,7 @@ module G5Authenticatable
|
|
92
102
|
end
|
93
103
|
|
94
104
|
def global_role?
|
95
|
-
super_admin? || admin? || editor? || viewer?
|
105
|
+
super_admin? || admin?(true) || editor?(true) || viewer?(true)
|
96
106
|
end
|
97
107
|
end
|
98
108
|
end
|
@@ -9,11 +9,6 @@ RSpec.describe G5Authenticatable::User do
|
|
9
9
|
|
10
10
|
it { is_expected.to have_and_belong_to_many(:roles) }
|
11
11
|
|
12
|
-
it 'has an current_client_urn attr_accessor' do
|
13
|
-
subject.current_client_urn = 'foo'
|
14
|
-
expect(subject.current_client_urn).to eq('foo')
|
15
|
-
end
|
16
|
-
|
17
12
|
it 'should expose the email' do
|
18
13
|
expect(user.email).to eq(user_attributes[:email])
|
19
14
|
end
|
@@ -73,30 +68,30 @@ RSpec.describe G5Authenticatable::User do
|
|
73
68
|
full_name = [new_user_attributes[:first_name],
|
74
69
|
new_user_attributes[:last_name]].join(' ')
|
75
70
|
OmniAuth::AuthHash.new(
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
71
|
+
'uid' => new_user_attributes[:uid],
|
72
|
+
'provider' => new_user_attributes[:provider],
|
73
|
+
'info' => {
|
74
|
+
'email' => new_user_attributes[:email],
|
75
|
+
'name' => full_name,
|
76
|
+
'first_name' => new_user_attributes[:first_name],
|
77
|
+
'last_name' => new_user_attributes[:last_name],
|
78
|
+
'phone' => new_user_attributes[:phone_number]
|
79
|
+
},
|
80
|
+
'credentials' => {
|
81
|
+
'token' => new_user_attributes[:g5_access_token],
|
82
|
+
'expires' => true,
|
83
|
+
'expires_at' => Time.now + 1000
|
84
|
+
},
|
85
|
+
'extra' => {
|
86
|
+
'title' => new_user_attributes[:title],
|
87
|
+
'organization_name' => new_user_attributes[:organization_name],
|
88
|
+
'roles' => [
|
89
|
+
{ 'name' => new_role_attributes[:name],
|
90
|
+
'type' => 'GLOBAL',
|
91
|
+
'urn' => nil }
|
92
|
+
],
|
93
|
+
'raw_info' => {}
|
94
|
+
}
|
100
95
|
)
|
101
96
|
end
|
102
97
|
|
@@ -113,17 +108,17 @@ RSpec.describe G5Authenticatable::User do
|
|
113
108
|
|
114
109
|
it 'has the correct provider' do
|
115
110
|
expect(attributes_from_auth[:provider])
|
116
|
-
|
111
|
+
.to eq(new_user_attributes[:provider])
|
117
112
|
end
|
118
113
|
|
119
114
|
it 'has the correct first_name' do
|
120
115
|
expect(attributes_from_auth[:first_name])
|
121
|
-
|
116
|
+
.to eq(new_user_attributes[:first_name])
|
122
117
|
end
|
123
118
|
|
124
119
|
it 'has the correct last_name' do
|
125
120
|
expect(attributes_from_auth[:last_name])
|
126
|
-
|
121
|
+
.to eq(new_user_attributes[:last_name])
|
127
122
|
end
|
128
123
|
|
129
124
|
it 'has the correct email' do
|
@@ -132,7 +127,7 @@ RSpec.describe G5Authenticatable::User do
|
|
132
127
|
|
133
128
|
it 'has the correct phone_number' do
|
134
129
|
expect(attributes_from_auth[:phone_number])
|
135
|
-
|
130
|
+
.to eq(new_user_attributes[:phone_number])
|
136
131
|
end
|
137
132
|
|
138
133
|
it 'has the correct title' do
|
@@ -141,7 +136,7 @@ RSpec.describe G5Authenticatable::User do
|
|
141
136
|
|
142
137
|
it 'has the correct organization_name' do
|
143
138
|
expect(attributes_from_auth[:organization_name])
|
144
|
-
|
139
|
+
.to eq(new_user_attributes[:organization_name])
|
145
140
|
end
|
146
141
|
end
|
147
142
|
|
@@ -155,29 +150,29 @@ RSpec.describe G5Authenticatable::User do
|
|
155
150
|
full_name = [new_user_attributes[:first_name],
|
156
151
|
new_user_attributes[:last_name]].join(' ')
|
157
152
|
OmniAuth::AuthHash.new(
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
153
|
+
'provider' => new_user_attributes[:provider],
|
154
|
+
'info' => {
|
155
|
+
'email' => new_user_attributes[:email],
|
156
|
+
'name' => full_name,
|
157
|
+
'first_name' => new_user_attributes[:first_name],
|
158
|
+
'last_name' => new_user_attributes[:last_name],
|
159
|
+
'phone' => new_user_attributes[:phone_number]
|
160
|
+
},
|
161
|
+
'credentials' => {
|
162
|
+
'token' => new_user_attributes[:g5_access_token],
|
163
|
+
'expires' => true,
|
164
|
+
'expires_at' => Time.now + 1000
|
165
|
+
},
|
166
|
+
'extra' => {
|
167
|
+
'title' => new_user_attributes[:title],
|
168
|
+
'organization_name' => new_user_attributes[:organization_name],
|
169
|
+
'roles' => [
|
170
|
+
{ 'name' => new_role_attributes[:name],
|
171
|
+
'type' => 'GLOBAL',
|
172
|
+
'urn' => nil }
|
173
|
+
],
|
174
|
+
'raw_info' => {}
|
175
|
+
}
|
181
176
|
)
|
182
177
|
end
|
183
178
|
|
@@ -242,7 +237,7 @@ RSpec.describe G5Authenticatable::User do
|
|
242
237
|
|
243
238
|
it 'should set the organization_name from the session data' do
|
244
239
|
expect(new_user.organization_name)
|
245
|
-
|
240
|
+
.to eq(new_user_attributes[:organization_name])
|
246
241
|
end
|
247
242
|
|
248
243
|
it 'should assign the role from the session data' do
|
@@ -286,11 +281,11 @@ RSpec.describe G5Authenticatable::User do
|
|
286
281
|
|
287
282
|
let(:user_attributes) do
|
288
283
|
FactoryBot.attributes_for(:g5_authenticatable_user,
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
284
|
+
first_name: nil,
|
285
|
+
last_name: nil,
|
286
|
+
phone_number: nil,
|
287
|
+
title: nil,
|
288
|
+
organization_name: nil)
|
294
289
|
end
|
295
290
|
let(:role_name) { :my_role }
|
296
291
|
|
@@ -301,27 +296,27 @@ RSpec.describe G5Authenticatable::User do
|
|
301
296
|
|
302
297
|
let(:auth_data) do
|
303
298
|
OmniAuth::AuthHash.new(
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
299
|
+
'provider' => user_attributes[:provider],
|
300
|
+
'uid' => user_attributes[:uid],
|
301
|
+
'info' => {
|
302
|
+
'email' => updated_attributes[:email],
|
303
|
+
'first_name' => updated_attributes[:first_name],
|
304
|
+
'last_name' => updated_attributes[:last_name],
|
305
|
+
'phone' => updated_attributes[:phone_number]
|
306
|
+
},
|
307
|
+
'credentials' => {
|
308
|
+
'token' => updated_attributes[:g5_access_token],
|
309
|
+
'expires' => true,
|
310
|
+
'expires_at' => Time.now + 1000
|
311
|
+
},
|
312
|
+
'extra' => {
|
313
|
+
'title' => updated_attributes[:title],
|
314
|
+
'organization_name' => updated_attributes[:organization_name],
|
315
|
+
'roles' => [
|
316
|
+
{ name: updated_role_name, type: 'GLOBAL', urn: nil }
|
317
|
+
],
|
318
|
+
'raw_info' => {}
|
319
|
+
}
|
325
320
|
)
|
326
321
|
end
|
327
322
|
|
@@ -333,7 +328,7 @@ RSpec.describe G5Authenticatable::User do
|
|
333
328
|
|
334
329
|
it 'should update the access token' do
|
335
330
|
expect { updated_user }.to change { user.reload.g5_access_token }
|
336
|
-
|
331
|
+
.to(updated_attributes[:g5_access_token])
|
337
332
|
end
|
338
333
|
|
339
334
|
it 'should return the updated user' do
|
@@ -372,15 +367,15 @@ RSpec.describe G5Authenticatable::User do
|
|
372
367
|
context 'when user info has changed' do
|
373
368
|
let(:updated_attributes) do
|
374
369
|
{
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
370
|
+
uid: user.uid,
|
371
|
+
provider: user.provider,
|
372
|
+
email: 'updated.email@test.host',
|
373
|
+
g5_access_token: 'updatedtoken42',
|
374
|
+
first_name: 'Updated First Name',
|
375
|
+
last_name: 'Updated Last Name',
|
376
|
+
phone_number: '555.555.5555 x123',
|
377
|
+
title: 'Recently Promoted',
|
378
|
+
organization_name: 'Updated Department'
|
384
379
|
}
|
385
380
|
end
|
386
381
|
|
@@ -388,7 +383,7 @@ RSpec.describe G5Authenticatable::User do
|
|
388
383
|
|
389
384
|
it 'should update the access token' do
|
390
385
|
expect { updated_user }.to change { user.reload.g5_access_token }
|
391
|
-
|
386
|
+
.to(updated_attributes[:g5_access_token])
|
392
387
|
end
|
393
388
|
|
394
389
|
it 'should return the updated user' do
|
@@ -405,32 +400,32 @@ RSpec.describe G5Authenticatable::User do
|
|
405
400
|
|
406
401
|
it 'should update the email' do
|
407
402
|
expect { updated_user }.to change { user.reload.email }
|
408
|
-
|
403
|
+
.to(updated_attributes[:email])
|
409
404
|
end
|
410
405
|
|
411
406
|
it 'should update the first name' do
|
412
407
|
expect { updated_user }.to change { user.reload.first_name }
|
413
|
-
|
408
|
+
.to(updated_attributes[:first_name])
|
414
409
|
end
|
415
410
|
|
416
411
|
it 'should update the last name' do
|
417
412
|
expect { updated_user }.to change { user.reload.last_name }
|
418
|
-
|
413
|
+
.to(updated_attributes[:last_name])
|
419
414
|
end
|
420
415
|
|
421
416
|
it 'should update the phone number' do
|
422
417
|
expect { updated_user }.to change { user.reload.phone_number }
|
423
|
-
|
418
|
+
.to(updated_attributes[:phone_number])
|
424
419
|
end
|
425
420
|
|
426
421
|
it 'should update the title' do
|
427
422
|
expect { updated_user }.to change { user.reload.title }
|
428
|
-
|
423
|
+
.to(updated_attributes[:title])
|
429
424
|
end
|
430
425
|
|
431
426
|
it 'should update the organization_name' do
|
432
427
|
expect { updated_user }.to change { user.reload.organization_name }
|
433
|
-
|
428
|
+
.to(updated_attributes[:organization_name])
|
434
429
|
end
|
435
430
|
|
436
431
|
it 'should unassign the old role' do
|
@@ -508,25 +503,25 @@ RSpec.describe G5Authenticatable::User do
|
|
508
503
|
|
509
504
|
let(:auth_data) do
|
510
505
|
OmniAuth::AuthHash.new(
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
|
528
|
-
|
529
|
-
|
506
|
+
'provider' => user_attributes[:provider],
|
507
|
+
'uid' => user_attributes[:uid],
|
508
|
+
'info' => {
|
509
|
+
'email' => user_attributes[:email],
|
510
|
+
'first_name' => user_attributes[:first_name],
|
511
|
+
'last_name' => user_attributes[:last_name],
|
512
|
+
'phone' => user_attributes[:phone_number]
|
513
|
+
},
|
514
|
+
'credentials' => {
|
515
|
+
'token' => user_attributes[:g5_access_token],
|
516
|
+
'expires' => true,
|
517
|
+
'expires_at' => Time.now + 1000
|
518
|
+
},
|
519
|
+
'extra' => {
|
520
|
+
'title' => user_attributes[:title],
|
521
|
+
'organization_name' => user_attributes[:organization_name],
|
522
|
+
'roles' => roles,
|
523
|
+
'raw_info' => {}
|
524
|
+
}
|
530
525
|
)
|
531
526
|
end
|
532
527
|
|
@@ -537,7 +532,7 @@ RSpec.describe G5Authenticatable::User do
|
|
537
532
|
|
538
533
|
it 'will add a global role' do
|
539
534
|
expect { user.update_roles_from_auth(auth_data) }
|
540
|
-
|
535
|
+
.to change { user.roles.length }.from(0).to(1)
|
541
536
|
expect(user.roles.first.name).to eq('admin')
|
542
537
|
expect(user.roles.first.resource).to be_nil
|
543
538
|
end
|
@@ -550,7 +545,7 @@ RSpec.describe G5Authenticatable::User do
|
|
550
545
|
|
551
546
|
it 'will add a scoped role' do
|
552
547
|
expect { user.update_roles_from_auth(auth_data) }
|
553
|
-
|
548
|
+
.to change { user.roles.length }.from(0).to(1)
|
554
549
|
expect(user.roles.first.name).to eq('viewer')
|
555
550
|
expect(user.roles.first.resource_id).to eq(resource.id)
|
556
551
|
expect(user.roles.first.resource_type).to eq(resource.class.name)
|
@@ -560,14 +555,14 @@ RSpec.describe G5Authenticatable::User do
|
|
560
555
|
context 'with a more than 1 role' do
|
561
556
|
let(:roles) do
|
562
557
|
[
|
563
|
-
|
564
|
-
|
558
|
+
{ name: 'viewer', type: resource.class.name, urn: resource.urn },
|
559
|
+
{ name: 'admin', type: 'GLOBAL', urn: nil }
|
565
560
|
]
|
566
561
|
end
|
567
562
|
|
568
563
|
it 'will add a scoped role' do
|
569
564
|
expect { user.update_roles_from_auth(auth_data) }
|
570
|
-
|
565
|
+
.to change { user.roles.length }.from(0).to(2)
|
571
566
|
end
|
572
567
|
end
|
573
568
|
|
@@ -580,7 +575,7 @@ RSpec.describe G5Authenticatable::User do
|
|
580
575
|
|
581
576
|
it 'will add a scoped role' do
|
582
577
|
expect { user.update_roles_from_auth(auth_data) }
|
583
|
-
|
578
|
+
.to_not change { user.roles.length }
|
584
579
|
end
|
585
580
|
end
|
586
581
|
|
@@ -589,21 +584,21 @@ RSpec.describe G5Authenticatable::User do
|
|
589
584
|
|
590
585
|
it 'will add a scoped role' do
|
591
586
|
expect { user.update_roles_from_auth(auth_data) }
|
592
|
-
|
587
|
+
.to_not change { user.roles.length }.from(0)
|
593
588
|
end
|
594
589
|
end
|
595
590
|
|
596
591
|
context 'with a bad role type' do
|
597
592
|
let(:roles) do
|
598
593
|
[
|
599
|
-
|
600
|
-
|
594
|
+
{ name: 'viewer', type: resource.class.name, urn: resource.urn },
|
595
|
+
{ name: 'viewer', type: 'BadResource', urn: resource.urn }
|
601
596
|
]
|
602
597
|
end
|
603
598
|
|
604
599
|
it 'will skip the bad role' do
|
605
600
|
expect { user.update_roles_from_auth(auth_data) }
|
606
|
-
|
601
|
+
.to change { user.roles.length }.from(0).to(1)
|
607
602
|
expect(user.roles.first.name).to eq('viewer')
|
608
603
|
expect(user.roles.first.resource_id).to eq(resource.id)
|
609
604
|
expect(user.roles.first.resource_type).to eq(resource.class.name)
|
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: 1.1.2.
|
4
|
+
version: 1.1.2.rc.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- maeve
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-10-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: devise_g5_authenticatable
|