rails_sso 0.1.3 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -48
- data/app/services/rails_sso/fetch_user.rb +1 -5
- data/lib/rails_sso/access_token.rb +2 -2
- data/lib/rails_sso/helpers.rb +4 -17
- data/lib/rails_sso/version.rb +1 -1
- data/lib/rails_sso.rb +0 -5
- data/test/dummy/config/initializers/sso.rb +0 -5
- data/test/dummy/log/test.log +162 -0
- data/test/services/rails_sso/fetch_user_test.rb +5 -12
- metadata +2 -5
- data/app/services/rails_sso/update_user.rb +0 -29
- data/test/services/rails_sso/update_user_test.rb +0 -79
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 297b750c108836e79da3b03ad4cbfb84341a4854
|
4
|
+
data.tar.gz: e9f74bbd907a1a149327e8bce747ef3454d78aaa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 62d7687593e7775cfa865c9bc56fcb6d49cef544da2f11ba8f7a1edac0a3a6e767784a7845a87aad73071a668d3c58d0b81828fd85cb1dbbdc6892824a91991f
|
7
|
+
data.tar.gz: dd07477eb293f068fccf01886dd68d225f0efda7cc0456623a402de8b08824340eafdc2b56a1d5bcbd66d9b27857a2089b69ee895f74d0edb2c7ca392eccea07
|
data/README.md
CHANGED
@@ -35,16 +35,6 @@ RailsSso.configure do |config|
|
|
35
35
|
config.provider_sign_out_path = '/api/v1/session'
|
36
36
|
# enable cache (will use Rails.cache store)
|
37
37
|
config.use_cache = Rails.application.config.action_controller.perform_caching
|
38
|
-
|
39
|
-
# user fields to synchronize from API
|
40
|
-
config.user_fields = [
|
41
|
-
:email,
|
42
|
-
:name,
|
43
|
-
:roles
|
44
|
-
]
|
45
|
-
|
46
|
-
# user repository class name
|
47
|
-
config.user_repository = 'UserRepository'
|
48
38
|
end
|
49
39
|
```
|
50
40
|
|
@@ -62,7 +52,7 @@ end
|
|
62
52
|
|
63
53
|
Available helpers for controllers and views:
|
64
54
|
|
65
|
-
* `
|
55
|
+
* `current_user_data`
|
66
56
|
* `user_signed_in?`
|
67
57
|
|
68
58
|
Available filters and helpers for controllers:
|
@@ -76,43 +66,6 @@ Available helpers for views:
|
|
76
66
|
* `sso.sign_in_path`
|
77
67
|
* `sso.sign_out_path`
|
78
68
|
|
79
|
-
## User Repository
|
80
|
-
|
81
|
-
Required methods:
|
82
|
-
|
83
|
-
* `find_by_sso_id(id)`
|
84
|
-
* `create_with_sso_id(id, attrs)`
|
85
|
-
* `update(record, attrs)`
|
86
|
-
|
87
|
-
Example with `ActiveRecord` user model:
|
88
|
-
|
89
|
-
```ruby
|
90
|
-
# app/repositories/user_repository.rb
|
91
|
-
|
92
|
-
class UserRepository
|
93
|
-
attr_accessor :adapter
|
94
|
-
|
95
|
-
def initialize(adapter = User)
|
96
|
-
self.adapter = adapter
|
97
|
-
end
|
98
|
-
|
99
|
-
def find_by_sso_id(id)
|
100
|
-
adapter.find_by(sso_id: id)
|
101
|
-
end
|
102
|
-
|
103
|
-
def create_with_sso_id(id, attrs)
|
104
|
-
adapter.new(attrs) do |user|
|
105
|
-
user.sso_id = id
|
106
|
-
user.save!
|
107
|
-
end
|
108
|
-
end
|
109
|
-
|
110
|
-
def update(record, attrs)
|
111
|
-
adapter.update(record.id, attrs)
|
112
|
-
end
|
113
|
-
end
|
114
|
-
```
|
115
|
-
|
116
69
|
## Contributing
|
117
70
|
|
118
71
|
1. Fork it
|
@@ -5,15 +5,11 @@ module RailsSso
|
|
5
5
|
end
|
6
6
|
|
7
7
|
def call
|
8
|
-
|
8
|
+
access_token.get(RailsSso.provider_profile_path).parsed
|
9
9
|
end
|
10
10
|
|
11
11
|
private
|
12
12
|
|
13
13
|
attr_reader :access_token
|
14
|
-
|
15
|
-
def get
|
16
|
-
access_token.get(RailsSso.provider_profile_path).parsed
|
17
|
-
end
|
18
14
|
end
|
19
15
|
end
|
@@ -26,9 +26,9 @@ module RailsSso
|
|
26
26
|
|
27
27
|
private
|
28
28
|
|
29
|
-
def client
|
29
|
+
def client(cache = RailsSso.use_cache)
|
30
30
|
strategy.client.tap do |c|
|
31
|
-
if
|
31
|
+
if cache
|
32
32
|
c.options[:connection_build] = Proc.new do |conn|
|
33
33
|
conn.use :http_cache,
|
34
34
|
store: Rails.cache,
|
data/lib/rails_sso/helpers.rb
CHANGED
@@ -2,18 +2,16 @@ module RailsSso
|
|
2
2
|
module Helpers
|
3
3
|
def self.included(base)
|
4
4
|
base.class_eval do
|
5
|
-
helper_method :
|
5
|
+
helper_method :current_user_data, :user_signed_in?
|
6
6
|
end
|
7
7
|
end
|
8
8
|
|
9
|
-
def
|
10
|
-
@current_user ||= fetch_user
|
11
|
-
cache_user(user)
|
12
|
-
end
|
9
|
+
def current_user_data
|
10
|
+
@current_user ||= fetch_user
|
13
11
|
end
|
14
12
|
|
15
13
|
def user_signed_in?
|
16
|
-
!!
|
14
|
+
!!current_user_data
|
17
15
|
end
|
18
16
|
|
19
17
|
def authenticate_user!
|
@@ -56,16 +54,5 @@ module RailsSso
|
|
56
54
|
RailsSso::FetchUser.new(access_token).call(&block)
|
57
55
|
end
|
58
56
|
end
|
59
|
-
|
60
|
-
def cache_user(data)
|
61
|
-
RailsSso::UpdateUser.new(data, update_user_options).call
|
62
|
-
end
|
63
|
-
|
64
|
-
def update_user_options
|
65
|
-
{
|
66
|
-
fields: RailsSso.user_fields,
|
67
|
-
repository: RailsSso.user_repository.new
|
68
|
-
}
|
69
|
-
end
|
70
57
|
end
|
71
58
|
end
|
data/lib/rails_sso/version.rb
CHANGED
data/lib/rails_sso.rb
CHANGED
data/test/dummy/log/test.log
CHANGED
@@ -2371,3 +2371,165 @@ Completed 302 Found in 0ms (ActiveRecord: 0.0ms)
|
|
2371
2371
|
RailsSsoTest: test_truth
|
2372
2372
|
------------------------
|
2373
2373
|
[1m[35m (0.0ms)[0m rollback transaction
|
2374
|
+
[1m[36m (0.1ms)[0m [1mbegin transaction[0m
|
2375
|
+
------------------------------------------------------------------------------------------------
|
2376
|
+
RailsSso::SessionsControllerTest: test_create_should_save_access_token_and_redirect_to_root_path
|
2377
|
+
------------------------------------------------------------------------------------------------
|
2378
|
+
Processing by RailsSso::SessionsController#create as HTML
|
2379
|
+
Parameters: {"provider"=>"developer"}
|
2380
|
+
nil
|
2381
|
+
Redirected to http://test.host/
|
2382
|
+
Completed 302 Found in 0ms (ActiveRecord: 0.0ms)
|
2383
|
+
[1m[35m (0.1ms)[0m rollback transaction
|
2384
|
+
[1m[36m (0.1ms)[0m [1mbegin transaction[0m
|
2385
|
+
-------------------------------------------------------------------------------------------------------
|
2386
|
+
RailsSso::SessionsControllerTest: test_destroy_should_invalidate_access_token_and_redirect_to_root_path
|
2387
|
+
-------------------------------------------------------------------------------------------------------
|
2388
|
+
Processing by RailsSso::SessionsController#destroy as HTML
|
2389
|
+
Redirected to http://test.host/
|
2390
|
+
Completed 302 Found in 0ms (ActiveRecord: 0.0ms)
|
2391
|
+
[1m[35m (0.1ms)[0m rollback transaction
|
2392
|
+
[1m[36m (0.1ms)[0m [1mbegin transaction[0m
|
2393
|
+
--------------------------------------------------------------------------------------------
|
2394
|
+
RailsSso::FetchUserTest: test_call_should_fetch_user_with_access_token_and_yield_parsed_data
|
2395
|
+
--------------------------------------------------------------------------------------------
|
2396
|
+
[1m[35m (0.1ms)[0m rollback transaction
|
2397
|
+
[1m[36m (0.1ms)[0m [1mbegin transaction[0m
|
2398
|
+
--------------------------------------------------------------------------------------------
|
2399
|
+
RailsSso::UpdateUserTest: test_call_should_update_user_if_exists_in_repository_and_return_it
|
2400
|
+
--------------------------------------------------------------------------------------------
|
2401
|
+
[1m[35m (0.1ms)[0m rollback transaction
|
2402
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
2403
|
+
------------------------------------------------------------------------------------------------
|
2404
|
+
RailsSso::UpdateUserTest: test_call_should_create_user_if_not_exists_in_repository_and_return_it
|
2405
|
+
------------------------------------------------------------------------------------------------
|
2406
|
+
[1m[35m (0.1ms)[0m rollback transaction
|
2407
|
+
[1m[36m (0.1ms)[0m [1mbegin transaction[0m
|
2408
|
+
------------------------
|
2409
|
+
RailsSsoTest: test_truth
|
2410
|
+
------------------------
|
2411
|
+
[1m[35m (0.1ms)[0m rollback transaction
|
2412
|
+
[1m[36m (0.1ms)[0m [1mbegin transaction[0m
|
2413
|
+
----------------------------------------------------
|
2414
|
+
SsoRoutesTest: test_should_route_/:provider/callback
|
2415
|
+
----------------------------------------------------
|
2416
|
+
[1m[35m (0.1ms)[0m rollback transaction
|
2417
|
+
[1m[36m (0.1ms)[0m [1mbegin transaction[0m
|
2418
|
+
------------------------------------------
|
2419
|
+
SsoRoutesTest: test_should_route_/sign_out
|
2420
|
+
------------------------------------------
|
2421
|
+
[1m[35m (0.0ms)[0m rollback transaction
|
2422
|
+
[1m[36m (0.1ms)[0m [1mbegin transaction[0m
|
2423
|
+
--------------------------------------------------------------------------------------------
|
2424
|
+
RailsSso::FetchUserTest: test_call_should_fetch_user_with_access_token_and_yield_parsed_data
|
2425
|
+
--------------------------------------------------------------------------------------------
|
2426
|
+
[1m[35m (0.1ms)[0m rollback transaction
|
2427
|
+
[1m[36m (0.1ms)[0m [1mbegin transaction[0m
|
2428
|
+
------------------------------------------
|
2429
|
+
SsoRoutesTest: test_should_route_/sign_out
|
2430
|
+
------------------------------------------
|
2431
|
+
[1m[35m (0.1ms)[0m rollback transaction
|
2432
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
2433
|
+
----------------------------------------------------
|
2434
|
+
SsoRoutesTest: test_should_route_/:provider/callback
|
2435
|
+
----------------------------------------------------
|
2436
|
+
[1m[35m (0.1ms)[0m rollback transaction
|
2437
|
+
[1m[36m (0.1ms)[0m [1mbegin transaction[0m
|
2438
|
+
------------------------------------------------------------------------------------------------
|
2439
|
+
RailsSso::SessionsControllerTest: test_create_should_save_access_token_and_redirect_to_root_path
|
2440
|
+
------------------------------------------------------------------------------------------------
|
2441
|
+
Processing by RailsSso::SessionsController#create as HTML
|
2442
|
+
Parameters: {"provider"=>"developer"}
|
2443
|
+
nil
|
2444
|
+
Redirected to http://test.host/
|
2445
|
+
Completed 302 Found in 0ms (ActiveRecord: 0.0ms)
|
2446
|
+
[1m[35m (0.1ms)[0m rollback transaction
|
2447
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
2448
|
+
-------------------------------------------------------------------------------------------------------
|
2449
|
+
RailsSso::SessionsControllerTest: test_destroy_should_invalidate_access_token_and_redirect_to_root_path
|
2450
|
+
-------------------------------------------------------------------------------------------------------
|
2451
|
+
Processing by RailsSso::SessionsController#destroy as HTML
|
2452
|
+
Redirected to http://test.host/
|
2453
|
+
Completed 302 Found in 0ms (ActiveRecord: 0.0ms)
|
2454
|
+
[1m[35m (0.1ms)[0m rollback transaction
|
2455
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
2456
|
+
------------------------
|
2457
|
+
RailsSsoTest: test_truth
|
2458
|
+
------------------------
|
2459
|
+
[1m[35m (0.0ms)[0m rollback transaction
|
2460
|
+
[1m[36m (0.1ms)[0m [1mbegin transaction[0m
|
2461
|
+
-------------------------------------------------------------------------------------------------------
|
2462
|
+
RailsSso::SessionsControllerTest: test_destroy_should_invalidate_access_token_and_redirect_to_root_path
|
2463
|
+
-------------------------------------------------------------------------------------------------------
|
2464
|
+
Processing by RailsSso::SessionsController#destroy as HTML
|
2465
|
+
Redirected to http://test.host/
|
2466
|
+
Completed 302 Found in 0ms (ActiveRecord: 0.0ms)
|
2467
|
+
[1m[35m (0.1ms)[0m rollback transaction
|
2468
|
+
[1m[36m (0.1ms)[0m [1mbegin transaction[0m
|
2469
|
+
------------------------------------------------------------------------------------------------
|
2470
|
+
RailsSso::SessionsControllerTest: test_create_should_save_access_token_and_redirect_to_root_path
|
2471
|
+
------------------------------------------------------------------------------------------------
|
2472
|
+
Processing by RailsSso::SessionsController#create as HTML
|
2473
|
+
Parameters: {"provider"=>"developer"}
|
2474
|
+
nil
|
2475
|
+
Redirected to http://test.host/
|
2476
|
+
Completed 302 Found in 0ms (ActiveRecord: 0.0ms)
|
2477
|
+
[1m[35m (0.1ms)[0m rollback transaction
|
2478
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
2479
|
+
---------------------------------------------------------------------------------------------
|
2480
|
+
RailsSso::FetchUserTest: test_call_should_fetch_user_with_access_token_and_return_parsed_data
|
2481
|
+
---------------------------------------------------------------------------------------------
|
2482
|
+
[1m[35m (0.1ms)[0m rollback transaction
|
2483
|
+
[1m[36m (0.1ms)[0m [1mbegin transaction[0m
|
2484
|
+
----------------------------------------------------
|
2485
|
+
SsoRoutesTest: test_should_route_/:provider/callback
|
2486
|
+
----------------------------------------------------
|
2487
|
+
[1m[35m (0.1ms)[0m rollback transaction
|
2488
|
+
[1m[36m (0.1ms)[0m [1mbegin transaction[0m
|
2489
|
+
------------------------------------------
|
2490
|
+
SsoRoutesTest: test_should_route_/sign_out
|
2491
|
+
------------------------------------------
|
2492
|
+
[1m[35m (0.0ms)[0m rollback transaction
|
2493
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
2494
|
+
------------------------
|
2495
|
+
RailsSsoTest: test_truth
|
2496
|
+
------------------------
|
2497
|
+
[1m[35m (0.0ms)[0m rollback transaction
|
2498
|
+
[1m[36m (0.1ms)[0m [1mbegin transaction[0m
|
2499
|
+
------------------------
|
2500
|
+
RailsSsoTest: test_truth
|
2501
|
+
------------------------
|
2502
|
+
[1m[35m (0.0ms)[0m rollback transaction
|
2503
|
+
[1m[36m (0.1ms)[0m [1mbegin transaction[0m
|
2504
|
+
-------------------------------------------------------------------------------------------------------
|
2505
|
+
RailsSso::SessionsControllerTest: test_destroy_should_invalidate_access_token_and_redirect_to_root_path
|
2506
|
+
-------------------------------------------------------------------------------------------------------
|
2507
|
+
Processing by RailsSso::SessionsController#destroy as HTML
|
2508
|
+
Redirected to http://test.host/
|
2509
|
+
Completed 302 Found in 0ms (ActiveRecord: 0.0ms)
|
2510
|
+
[1m[35m (0.1ms)[0m rollback transaction
|
2511
|
+
[1m[36m (0.1ms)[0m [1mbegin transaction[0m
|
2512
|
+
------------------------------------------------------------------------------------------------
|
2513
|
+
RailsSso::SessionsControllerTest: test_create_should_save_access_token_and_redirect_to_root_path
|
2514
|
+
------------------------------------------------------------------------------------------------
|
2515
|
+
Processing by RailsSso::SessionsController#create as HTML
|
2516
|
+
Parameters: {"provider"=>"developer"}
|
2517
|
+
nil
|
2518
|
+
Redirected to http://test.host/
|
2519
|
+
Completed 302 Found in 0ms (ActiveRecord: 0.0ms)
|
2520
|
+
[1m[35m (0.1ms)[0m rollback transaction
|
2521
|
+
[1m[36m (0.1ms)[0m [1mbegin transaction[0m
|
2522
|
+
---------------------------------------------------------------------------------------------
|
2523
|
+
RailsSso::FetchUserTest: test_call_should_fetch_user_with_access_token_and_return_parsed_data
|
2524
|
+
---------------------------------------------------------------------------------------------
|
2525
|
+
[1m[35m (0.1ms)[0m rollback transaction
|
2526
|
+
[1m[36m (0.1ms)[0m [1mbegin transaction[0m
|
2527
|
+
----------------------------------------------------
|
2528
|
+
SsoRoutesTest: test_should_route_/:provider/callback
|
2529
|
+
----------------------------------------------------
|
2530
|
+
[1m[35m (0.1ms)[0m rollback transaction
|
2531
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
2532
|
+
------------------------------------------
|
2533
|
+
SsoRoutesTest: test_should_route_/sign_out
|
2534
|
+
------------------------------------------
|
2535
|
+
[1m[35m (0.1ms)[0m rollback transaction
|
@@ -15,17 +15,11 @@ class RailsSso::FetchUserTest < ActiveSupport::TestCase
|
|
15
15
|
@access_token = AccessToken.new(setup_access_token_client)
|
16
16
|
end
|
17
17
|
|
18
|
-
test "call should fetch user with access token and
|
19
|
-
|
18
|
+
test "call should fetch user with access token and return parsed data" do
|
19
|
+
data = RailsSso::FetchUser.new(@access_token).call
|
20
20
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
assert_equal data['name'], user_data['name']
|
25
|
-
assert_equal data['email'], user_data['email']
|
26
|
-
end
|
27
|
-
|
28
|
-
assert called, 'RailsSso::FetchUser#call should yield fetched data'
|
21
|
+
assert_equal data['name'], user_data['name']
|
22
|
+
assert_equal data['email'], user_data['email']
|
29
23
|
end
|
30
24
|
|
31
25
|
def setup_access_token_client
|
@@ -39,8 +33,7 @@ class RailsSso::FetchUserTest < ActiveSupport::TestCase
|
|
39
33
|
def user_data
|
40
34
|
{
|
41
35
|
'name' => 'Kowalski',
|
42
|
-
'email' => 'jan@kowalski.pl'
|
43
|
-
'key' => 'value'
|
36
|
+
'email' => 'jan@kowalski.pl'
|
44
37
|
}
|
45
38
|
end
|
46
39
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_sso
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jan Dudulski
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-02-
|
11
|
+
date: 2015-02-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -106,7 +106,6 @@ files:
|
|
106
106
|
- Rakefile
|
107
107
|
- app/controllers/rails_sso/sessions_controller.rb
|
108
108
|
- app/services/rails_sso/fetch_user.rb
|
109
|
-
- app/services/rails_sso/update_user.rb
|
110
109
|
- config/initializers/omniauth.rb
|
111
110
|
- config/routes.rb
|
112
111
|
- lib/rails_sso.rb
|
@@ -156,7 +155,6 @@ files:
|
|
156
155
|
- test/rails_sso_test.rb
|
157
156
|
- test/routes/sso_routes_test.rb
|
158
157
|
- test/services/rails_sso/fetch_user_test.rb
|
159
|
-
- test/services/rails_sso/update_user_test.rb
|
160
158
|
- test/test_helper.rb
|
161
159
|
homepage: https://github.com/monterail/rails_sso
|
162
160
|
licenses:
|
@@ -187,7 +185,6 @@ test_files:
|
|
187
185
|
- test/rails_sso_test.rb
|
188
186
|
- test/test_helper.rb
|
189
187
|
- test/services/rails_sso/fetch_user_test.rb
|
190
|
-
- test/services/rails_sso/update_user_test.rb
|
191
188
|
- test/dummy/README.rdoc
|
192
189
|
- test/dummy/db/test.sqlite3
|
193
190
|
- test/dummy/public/favicon.ico
|
@@ -1,29 +0,0 @@
|
|
1
|
-
module RailsSso
|
2
|
-
class UpdateUser
|
3
|
-
def initialize(data, options = {})
|
4
|
-
@id, @data = data['id'], data.except('id')
|
5
|
-
@fields, @repository = options.values_at(:fields, :repository)
|
6
|
-
end
|
7
|
-
|
8
|
-
def call
|
9
|
-
if user = repository.find_by_sso_id(id)
|
10
|
-
repository.update(user, params)
|
11
|
-
user
|
12
|
-
else
|
13
|
-
repository.create_with_sso_id(id, params)
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
private
|
18
|
-
|
19
|
-
attr_reader :id, :data, :repository
|
20
|
-
|
21
|
-
def fields
|
22
|
-
@fields.map(&:to_s)
|
23
|
-
end
|
24
|
-
|
25
|
-
def params
|
26
|
-
data.slice(*fields)
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
@@ -1,79 +0,0 @@
|
|
1
|
-
require 'anima'
|
2
|
-
require 'test_helper'
|
3
|
-
|
4
|
-
class RailsSso::UpdateUserTest < ActiveSupport::TestCase
|
5
|
-
class User
|
6
|
-
include Anima.new('email', 'name')
|
7
|
-
|
8
|
-
attr_accessor :id
|
9
|
-
attr_writer :name, :email
|
10
|
-
end
|
11
|
-
|
12
|
-
class Repository
|
13
|
-
attr_reader :storage
|
14
|
-
|
15
|
-
def initialize
|
16
|
-
@storage = {}
|
17
|
-
end
|
18
|
-
|
19
|
-
def find_by_sso_id(id)
|
20
|
-
storage[id]
|
21
|
-
end
|
22
|
-
|
23
|
-
def create_with_sso_id(id, data)
|
24
|
-
@storage[id] = User.new(data).tap do |user|
|
25
|
-
user.id = id
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
def update(user, params)
|
30
|
-
params.each do |k, v|
|
31
|
-
user.send("#{k}=", v)
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
def setup
|
37
|
-
@repository = Repository.new
|
38
|
-
|
39
|
-
@options = {
|
40
|
-
repository: @repository,
|
41
|
-
fields: [:name, :email]
|
42
|
-
}
|
43
|
-
|
44
|
-
@data = {
|
45
|
-
'id' => 1,
|
46
|
-
'name' => 'Kowalski',
|
47
|
-
'email' => 'jan@kowalski.pl',
|
48
|
-
'key' => 'value'
|
49
|
-
}
|
50
|
-
end
|
51
|
-
|
52
|
-
test "call should create user if not exists in repository and return it" do
|
53
|
-
output = RailsSso::UpdateUser.new(@data, @options).call
|
54
|
-
|
55
|
-
assert_equal_user(@data, output)
|
56
|
-
|
57
|
-
user = @repository.find_by_sso_id(@data['id'])
|
58
|
-
|
59
|
-
assert_equal_user(@data, user)
|
60
|
-
end
|
61
|
-
|
62
|
-
test "call should update user if exists in repository and return it" do
|
63
|
-
@repository.create_with_sso_id(@data['id'], { 'email' => 'test@example.com', 'name' => 'Nowak' })
|
64
|
-
|
65
|
-
output = RailsSso::UpdateUser.new(@data, @options).call
|
66
|
-
|
67
|
-
assert_equal_user(@data, output)
|
68
|
-
|
69
|
-
user = @repository.find_by_sso_id(@data['id'])
|
70
|
-
|
71
|
-
assert_equal_user(@data, user)
|
72
|
-
end
|
73
|
-
|
74
|
-
def assert_equal_user(data, user)
|
75
|
-
assert_equal data['id'], user.id
|
76
|
-
assert_equal data['email'], user.email
|
77
|
-
assert_equal data['name'], user.name
|
78
|
-
end
|
79
|
-
end
|