rails_sso 0.6.1 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d12b53a3fa35d972fe3f0288043f77b40b312ac7
4
- data.tar.gz: 45aee35ab335b031b7cc235e697ce38b21d6c80a
3
+ metadata.gz: 137bd49e5e81047d8cf47ca7381e38d41abba79e
4
+ data.tar.gz: 622652dc407b3304d6128a14031ac5d9063f334e
5
5
  SHA512:
6
- metadata.gz: 92a0ea90d785c9e04e4aa9b138532a0272d2669e81f8de9ff0751177ee85f1944564c64ab74fc962ffda0bc205dbd41a9d35ac97ca3072a9983b45f2071f4ab0
7
- data.tar.gz: 5997aa2aab73ccdd07e834adc7154530961980fb52125053d3af96b543a2af1f4947b51d1b0e645ec631352ce968a10ac36d0759a08beb141b653ea7b5734fc0
6
+ metadata.gz: f1e5ecd958a06f25df036cab1ab05dc693f29b7fb5b9b4a1dc6743d59a3f30cc0c387b77837804cf9f1ed9e56dcbf74c034b263bfd6a0d3de8612bc9e9d2acba
7
+ data.tar.gz: 90b4185586475bebf98010ae4e413ba3c65bc20dcb67a1809fcdf40b80500e144bdba86167769d9e196254ff79b83f2f1181b27e2bca07a635791ee11a431f73
data/README.md CHANGED
@@ -35,6 +35,8 @@ Configure initializer:
35
35
  # conifg/initializers/sso.rb
36
36
 
37
37
  RailsSso.configure do |config|
38
+ # include RailsSso::Helpers to ActionController::Base
39
+ config.magic_enabled = true
38
40
  # url of entity provider
39
41
  config.provider_url = 'https://example.com'
40
42
  # name of oauth2 provider
@@ -50,9 +52,12 @@ RailsSso.configure do |config|
50
52
  config.use_cache = Rails.application.config.action_controller.perform_caching
51
53
  # test & development mode
52
54
  config.test_mode = ENV['mock_sso']
53
- config.profile_mock = {
54
- user: 'John Blacksmith',
55
- uid: '169783'
55
+ config.access_token_mock = ENV['access_token_mock']
56
+ config.profiles_mock = {
57
+ '169783' => {
58
+ user: 'John Blacksmith',
59
+ uid: '169783'
60
+ }
56
61
  }
57
62
  # custom failure app
58
63
  # more: https://github.com/hassox/warden/wiki/Failures
@@ -72,6 +77,14 @@ end
72
77
 
73
78
  ## Usage
74
79
 
80
+ Include helpers to your controller if you disabled auto include:
81
+
82
+ ```ruby
83
+ class ApplicationController < ActionController::Base
84
+ include RailsSso::Helpers
85
+ end
86
+ ```
87
+
75
88
  Available helpers for controllers and views:
76
89
 
77
90
  * `current_user_data`
@@ -111,6 +124,8 @@ RailsSso.configure do |config|
111
124
  end
112
125
  ```
113
126
 
127
+ To mock signed out state set `profile_mock = nil`.
128
+
114
129
  ## Contributing
115
130
 
116
131
  1. Fork it
@@ -5,7 +5,7 @@ module RailsSso
5
5
  def create
6
6
  sign_in_with_access_token!(auth_hash.credentials)
7
7
 
8
- redirect_to root_path
8
+ redirect_to session.delete(:rails_sso_return_path) || root_path
9
9
  end
10
10
 
11
11
  def destroy
@@ -1,4 +1,6 @@
1
1
  RailsSso.configure do |config|
2
+ # include RailsSso::Helpers to ActionController::Base
3
+ config.magic_enabled = true
2
4
  # url of entity provider
3
5
  config.provider_url = 'https://example.com'
4
6
  # name of oauth2 provider
data/lib/rails_sso/app.rb CHANGED
@@ -1,9 +1,9 @@
1
1
  module RailsSso
2
2
  class App
3
- attr_reader :strategy, :session
3
+ attr_reader :strategy, :session, :provider_client
4
4
 
5
- def initialize(strategy, session)
6
- @strategy, @session = strategy, session
5
+ def initialize(strategy, session, provider_client)
6
+ @strategy, @session, @provider_client = strategy, session, provider_client
7
7
  end
8
8
 
9
9
  def fetch_user_data
@@ -43,41 +43,8 @@ module RailsSso
43
43
  end
44
44
  end
45
45
 
46
- def provider_client
47
- @provider_client ||= RailsSso::Client.new(RailsSso.provider_url) do |conn|
48
- case
49
- when RailsSso.test_mode
50
- mock_connection(conn)
51
- else
52
- setup_connection(conn)
53
- end
54
- end
55
- end
56
-
57
46
  private
58
47
 
59
- def setup_connection(conn)
60
- if RailsSso.use_cache
61
- conn.use :http_cache,
62
- store: Rails.cache,
63
- logger: Rails.logger,
64
- serializer: Marshal,
65
- shared_cache: false
66
- end
67
-
68
- conn.adapter Faraday.default_adapter
69
- end
70
-
71
- def mock_connection(conn)
72
- conn.adapter :test do |stub|
73
- stub.get(RailsSso.provider_profile_path) { |env| [200, {}, profile_mock] }
74
- end
75
- end
76
-
77
- def profile_mock
78
- RailsSso.profile_mock.to_json
79
- end
80
-
81
48
  def token_mock
82
49
  RailsSso::TokenMock.new
83
50
  end
@@ -3,8 +3,48 @@ require 'faraday-http-cache'
3
3
 
4
4
  module RailsSso
5
5
  class Client
6
- def initialize(url, &block)
7
- @connection = Faraday.new(url, &block)
6
+ def self.build(url, &block)
7
+ adapter = Faraday.new(url, &block)
8
+ new(adapter)
9
+ end
10
+
11
+ def self.build_real(url)
12
+ build(url) do |conn|
13
+ if RailsSso.use_cache
14
+ conn.use :http_cache,
15
+ store: Rails.cache,
16
+ logger: Rails.logger,
17
+ serializer: Marshal,
18
+ shared_cache: false
19
+ end
20
+
21
+ conn.adapter Faraday.default_adapter
22
+ end
23
+ end
24
+
25
+ def self.build_fake(url)
26
+ build(url) do |conn|
27
+ conn.adapter :test do |stub|
28
+ RailsSso.profile_mocks.each do |token, profile|
29
+ headers = {
30
+ "Content-Type" => "application/json",
31
+ "Authorization" => "Bearer #{token}"
32
+ }
33
+
34
+ stub.get(RailsSso.provider_profile_path, headers) do |env|
35
+ if profile.nil?
36
+ [401, { "Content-Type" => "application/json" }, ""]
37
+ else
38
+ [200, { "Content-Type" => "application/json" }, profile.to_json]
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
45
+
46
+ def initialize(adapter)
47
+ @connection = adapter
8
48
  end
9
49
 
10
50
  def token!(token)
@@ -39,8 +79,8 @@ module RailsSso
39
79
 
40
80
  def request(verb, url, params = {})
41
81
  connection.send(verb) do |req|
42
- req.headers['Authorization'] = "Bearer #{token}"
43
- req.headers['Content-Type'] = 'application/json'
82
+ req.headers["Authorization"] = "Bearer #{token}"
83
+ req.headers["Content-Type"] = "application/json"
44
84
 
45
85
  req.url(url)
46
86
  req.body = params.to_json
@@ -1,12 +1,14 @@
1
1
  module RailsSso
2
2
  class Engine < Rails::Engine
3
- initializer 'sso.helpers' do
4
- ActiveSupport.on_load(:action_controller) do
5
- include RailsSso::Helpers
3
+ initializer "sso.helpers" do
4
+ if RailsSso.magic_enabled
5
+ ActiveSupport.on_load(:action_controller) do
6
+ include RailsSso::Helpers
7
+ end
6
8
  end
7
9
  end
8
10
 
9
- initializer 'sso.omniauth', after: :load_config_initializers, before: :build_middleware_stack do |app|
11
+ initializer "sso.omniauth", after: :load_config_initializers, before: :build_middleware_stack do |app|
10
12
  if RailsSso.provider_name
11
13
  RailsSso.oauth2_strategy_class.class_eval do
12
14
  def setup_phase
@@ -28,7 +30,15 @@ module RailsSso
28
30
  end
29
31
 
30
32
  def setup_sso!
31
- env['sso'] ||= RailsSso::App.new(self, session)
33
+ env["sso"] ||= RailsSso::App.new(self, session, sso_client)
34
+ end
35
+
36
+ def sso_client
37
+ if RailsSso.test_mode
38
+ RailsSso::Client.build_fake(RailsSso.provider_url)
39
+ else
40
+ RailsSso::Client.build_real(RailsSso.provider_url)
41
+ end
32
42
  end
33
43
  end
34
44
 
@@ -11,7 +11,10 @@ module RailsSso
11
11
  end
12
12
 
13
13
  def authenticate_user!
14
- warden.authenticate!
14
+ unless user_signed_in?
15
+ session[:rails_sso_return_path] = request.path
16
+ warden.authenticate!
17
+ end
15
18
  end
16
19
 
17
20
  def user_signed_in?
@@ -5,18 +5,25 @@ module RailsSso
5
5
  end
6
6
 
7
7
  def valid?
8
- session[:access_token].present? || OmniAuth.config.test_mode
8
+ session[:access_token].present? || access_token_mock
9
9
  end
10
10
 
11
11
  def authenticate!
12
- env['sso'].fetch_user_data.tap do |user|
13
- if user.nil?
14
- fail! 'strategies.sso.failed'
15
- else
16
- success! user
17
- end
12
+ user = env["sso"].fetch_user_data
13
+
14
+ case
15
+ when user.nil?
16
+ fail! "strategies.sso.failed"
17
+ else
18
+ success! user
18
19
  end
19
20
  end
21
+
22
+ private
23
+
24
+ def access_token_mock
25
+ RailsSso.access_token_mock if RailsSso.test_mode
26
+ end
20
27
  end
21
28
  end
22
29
 
@@ -1,3 +1,3 @@
1
1
  module RailsSso
2
- VERSION = "0.6.1"
2
+ VERSION = "0.7.0"
3
3
  end
data/lib/rails_sso.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  module RailsSso
2
2
  mattr_accessor :application_controller
3
+ mattr_accessor :magic_enabled
3
4
 
4
5
  mattr_accessor :provider_url
5
6
  mattr_accessor :provider_name
@@ -12,15 +13,18 @@ module RailsSso
12
13
  mattr_accessor :use_cache
13
14
 
14
15
  mattr_accessor :test_mode
15
- mattr_accessor :profile_mock
16
+ mattr_accessor :profile_mocks
17
+ mattr_accessor :access_token_mock
16
18
 
17
19
  mattr_accessor :failure_app
18
20
 
19
21
  def self.configure
20
- self.application_controller = 'ApplicationController'
22
+ self.application_controller = "ApplicationController"
23
+ self.magic_enabled = true
21
24
  self.use_cache = false
22
25
  self.test_mode = false
23
- self.profile_mock = {}
26
+ self.profile_mocks = {}
27
+ self.access_token_mock = nil
24
28
  self.failure_app = RailsSso::FailureApp
25
29
 
26
30
  yield self
@@ -42,16 +46,22 @@ module RailsSso
42
46
  @@test_mode = value
43
47
  OmniAuth.config.test_mode = value
44
48
  end
49
+
50
+ def self.profile_mock
51
+ @@profile_mocks.fetch(@@access_token_mock) do
52
+ fail %Q{Mock "#{@@access_token_mock}" has not beed setup!}
53
+ end
54
+ end
45
55
  end
46
56
 
47
- require 'warden'
48
- require 'omniauth-oauth2'
49
- require 'rails_sso/version'
50
- require 'rails_sso/app'
51
- require 'rails_sso/engine'
52
- require 'rails_sso/helpers'
53
- require 'rails_sso/client'
54
- require 'rails_sso/response_error'
55
- require 'rails_sso/sso_strategy'
56
- require 'rails_sso/failure_app'
57
- require 'rails_sso/token_mock'
57
+ require "warden"
58
+ require "omniauth-oauth2"
59
+ require "rails_sso/version"
60
+ require "rails_sso/app"
61
+ require "rails_sso/engine"
62
+ require "rails_sso/helpers"
63
+ require "rails_sso/client"
64
+ require "rails_sso/response_error"
65
+ require "rails_sso/sso_strategy"
66
+ require "rails_sso/failure_app"
67
+ require "rails_sso/token_mock"
@@ -21,7 +21,7 @@ class RailsSso::SessionsControllerTest < ActionController::TestCase
21
21
  OmniAuth.config.mock_auth[:developer] = nil
22
22
  end
23
23
 
24
- test 'create should save access token and redirect to root path' do
24
+ test 'create should save access token and redirect to root path' do
25
25
  @controller.expects(:sign_in_with_access_token!).with(@auth_hash.credentials).once
26
26
 
27
27
  get :create, { provider: 'developer' }
@@ -44,3 +44,668 @@ SsoRoutesTest: test_should_route_/:provider/callback
44
44
  ------------------------------------------
45
45
  SsoRoutesTest: test_should_route_/sign_out
46
46
  ------------------------------------------
47
+ -----------------------------------------
48
+ RailsSso::SsoStrategyTest: test_something
49
+ -----------------------------------------
50
+ -----------------------------------------
51
+ RailsSso::SsoStrategyTest: test_something
52
+ -----------------------------------------
53
+ -----------------------------------------------------------------------------------------------------
54
+ RailsSso::SsoStrategyTest: test_authenticate!_returns_:success_when_access_token_available_in_session
55
+ -----------------------------------------------------------------------------------------------------
56
+ --------------------------------------------------------------------------------
57
+ RailsSso::SsoStrategyTest: test_authenticate!_returns_:success_when_in_test_mode
58
+ --------------------------------------------------------------------------------
59
+ -----------------------------------------------------------------------------------------------------
60
+ RailsSso::SsoStrategyTest: test_authenticate!_returns_:success_when_access_token_available_in_session
61
+ -----------------------------------------------------------------------------------------------------
62
+ ------------------------------------------------------------------------------------------
63
+ RailsSso::SsoStrategyTest: test_authenticate!_returns_:success_when_in_signed_in_test_mode
64
+ ------------------------------------------------------------------------------------------
65
+ -------------------------------------------------------------------------------------------
66
+ RailsSso::SsoStrategyTest: test_authenticate!_returns_:failure_when_in_signed_out_test_mode
67
+ -------------------------------------------------------------------------------------------
68
+ ------------------------------------------------------------------------------------------
69
+ RailsSso::SsoStrategyTest: test_authenticate!_returns_:success_when_in_signed_in_test_mode
70
+ ------------------------------------------------------------------------------------------
71
+ -------------------------------------------------------------------------------------------
72
+ RailsSso::SsoStrategyTest: test_authenticate!_returns_:failure_when_in_signed_out_test_mode
73
+ -------------------------------------------------------------------------------------------
74
+ -----------------------------------------------------------------------------------------------------
75
+ RailsSso::SsoStrategyTest: test_authenticate!_returns_:success_when_access_token_available_in_session
76
+ -----------------------------------------------------------------------------------------------------
77
+ ------------------------------------------------------------------------------------------
78
+ RailsSso::SsoStrategyTest: test_authenticate!_returns_:success_when_in_signed_in_test_mode
79
+ ------------------------------------------------------------------------------------------
80
+ -----------------------------------------------------------------------------------------------------
81
+ RailsSso::SsoStrategyTest: test_authenticate!_returns_:success_when_access_token_available_in_session
82
+ -----------------------------------------------------------------------------------------------------
83
+ -------------------------------------------------------------------------------------------
84
+ RailsSso::SsoStrategyTest: test_authenticate!_returns_:failure_when_in_signed_out_test_mode
85
+ -------------------------------------------------------------------------------------------
86
+ -------------------------------------------------------------------------------------------
87
+ RailsSso::SsoStrategyTest: test_authenticate!_returns_:failure_when_in_signed_out_test_mode
88
+ -------------------------------------------------------------------------------------------
89
+ -----------------------------------------------------------------------------------------------------
90
+ RailsSso::SsoStrategyTest: test_authenticate!_returns_:success_when_access_token_available_in_session
91
+ -----------------------------------------------------------------------------------------------------
92
+ ------------------------------------------------------------------------------------------
93
+ RailsSso::SsoStrategyTest: test_authenticate!_returns_:success_when_in_signed_in_test_mode
94
+ ------------------------------------------------------------------------------------------
95
+ -------------------------------------------------------------------------------------------
96
+ RailsSso::SsoStrategyTest: test_authenticate!_returns_:failure_when_in_signed_out_test_mode
97
+ -------------------------------------------------------------------------------------------
98
+ -----------------------------------------------------------------------------------------------------
99
+ RailsSso::SsoStrategyTest: test_authenticate!_returns_:success_when_access_token_available_in_session
100
+ -----------------------------------------------------------------------------------------------------
101
+ ------------------------------------------------------------------------------------------
102
+ RailsSso::SsoStrategyTest: test_authenticate!_returns_:success_when_in_signed_in_test_mode
103
+ ------------------------------------------------------------------------------------------
104
+ -------------------------------------------------------------------------------------------
105
+ RailsSso::SsoStrategyTest: test_authenticate!_returns_:failure_when_in_signed_out_test_mode
106
+ -------------------------------------------------------------------------------------------
107
+ -----------------------------------------------------------------------------------------------------
108
+ RailsSso::SsoStrategyTest: test_authenticate!_returns_:success_when_access_token_available_in_session
109
+ -----------------------------------------------------------------------------------------------------
110
+ ------------------------------------------------------------------------------------------
111
+ RailsSso::SsoStrategyTest: test_authenticate!_returns_:success_when_in_signed_in_test_mode
112
+ ------------------------------------------------------------------------------------------
113
+ -----------------------------------------------------------------------------------------------------
114
+ RailsSso::SsoStrategyTest: test_authenticate!_returns_:success_when_access_token_available_in_session
115
+ -----------------------------------------------------------------------------------------------------
116
+ ------------------------------------------------------------------------------------------
117
+ RailsSso::SsoStrategyTest: test_authenticate!_returns_:success_when_in_signed_in_test_mode
118
+ ------------------------------------------------------------------------------------------
119
+ -------------------------------------------------------------------------------------------
120
+ RailsSso::SsoStrategyTest: test_authenticate!_returns_:failure_when_in_signed_out_test_mode
121
+ -------------------------------------------------------------------------------------------
122
+ -----------------------------------------------------------------------------------------------------
123
+ RailsSso::SsoStrategyTest: test_authenticate!_returns_:success_when_access_token_available_in_session
124
+ -----------------------------------------------------------------------------------------------------
125
+ ------------------------------------------------------------------------------------------
126
+ RailsSso::SsoStrategyTest: test_authenticate!_returns_:success_when_in_signed_in_test_mode
127
+ ------------------------------------------------------------------------------------------
128
+ -------------------------------------------------------------------------------------------
129
+ RailsSso::SsoStrategyTest: test_authenticate!_returns_:failure_when_in_signed_out_test_mode
130
+ -------------------------------------------------------------------------------------------
131
+ ---------------------------------------------
132
+ RailsSso::SsoStrategyTest: test_mode_env_with
133
+ ---------------------------------------------
134
+ ------------------------------------------------------------------------------------------
135
+ RailsSso::SsoStrategyTest: test_authenticate!_returns_:success_when_in_signed_in_test_mode
136
+ ------------------------------------------------------------------------------------------
137
+ -------------------------------------------------------------------------------------------
138
+ RailsSso::SsoStrategyTest: test_authenticate!_returns_:failure_when_in_signed_out_test_mode
139
+ -------------------------------------------------------------------------------------------
140
+ -----------------------------------------------------------------------------------------------------
141
+ RailsSso::SsoStrategyTest: test_authenticate!_returns_:success_when_access_token_available_in_session
142
+ -----------------------------------------------------------------------------------------------------
143
+ ---------------------------------------------
144
+ RailsSso::SsoStrategyTest: test_mode_env_with
145
+ ---------------------------------------------
146
+ -------------------------------------------------------------------------------------------
147
+ RailsSso::SsoStrategyTest: test_authenticate!_returns_:failure_when_in_signed_out_test_mode
148
+ -------------------------------------------------------------------------------------------
149
+ ------------------------------------------------------------------------------------------
150
+ RailsSso::SsoStrategyTest: test_authenticate!_returns_:success_when_in_signed_in_test_mode
151
+ ------------------------------------------------------------------------------------------
152
+ -----------------------------------------------------------------------------------------------------
153
+ RailsSso::SsoStrategyTest: test_authenticate!_returns_:success_when_access_token_available_in_session
154
+ -----------------------------------------------------------------------------------------------------
155
+ -----------------------------------------------------------------------------------------------------
156
+ RailsSso::SsoStrategyTest: test_authenticate!_returns_:success_when_access_token_available_in_session
157
+ -----------------------------------------------------------------------------------------------------
158
+ ------------------------------------------------------------------------------------------
159
+ RailsSso::SsoStrategyTest: test_authenticate!_returns_:success_when_in_signed_in_test_mode
160
+ ------------------------------------------------------------------------------------------
161
+ -------------------------------------------------------------------------------------------
162
+ RailsSso::SsoStrategyTest: test_authenticate!_returns_:failure_when_in_signed_out_test_mode
163
+ -------------------------------------------------------------------------------------------
164
+ -------------------------------------------------------------------------------------------
165
+ RailsSso::SsoStrategyTest: test_authenticate!_returns_:failure_when_in_signed_out_test_mode
166
+ -------------------------------------------------------------------------------------------
167
+ -----------------------------------------------------------------------------------------------------
168
+ RailsSso::SsoStrategyTest: test_authenticate!_returns_:success_when_access_token_available_in_session
169
+ -----------------------------------------------------------------------------------------------------
170
+ ----------------------------------------------------------------------------------------------
171
+ RailsSso::SsoStrategyTest: test_authenticate!_returns_:failure_when_access_token_not_available
172
+ ----------------------------------------------------------------------------------------------
173
+ ------------------------------------------------------------------------------------------
174
+ RailsSso::SsoStrategyTest: test_authenticate!_returns_:success_when_in_signed_in_test_mode
175
+ ------------------------------------------------------------------------------------------
176
+ ------------------------------------------------------------------------------------------
177
+ RailsSso::SsoStrategyTest: test_authenticate!_returns_:success_when_in_signed_in_test_mode
178
+ ------------------------------------------------------------------------------------------
179
+ ----------------------------------------------------------------------------------------------
180
+ RailsSso::SsoStrategyTest: test_authenticate!_returns_:failure_when_access_token_not_available
181
+ ----------------------------------------------------------------------------------------------
182
+ -------------------------------------------------------------------------------------------
183
+ RailsSso::SsoStrategyTest: test_authenticate!_returns_:failure_when_in_signed_out_test_mode
184
+ -------------------------------------------------------------------------------------------
185
+ -----------------------------------------------------------------------------------------------------
186
+ RailsSso::SsoStrategyTest: test_authenticate!_returns_:success_when_access_token_available_in_session
187
+ -----------------------------------------------------------------------------------------------------
188
+ ------------------------------------------------------------------------------------------
189
+ RailsSso::SsoStrategyTest: test_authenticate!_returns_:success_when_in_signed_in_test_mode
190
+ ------------------------------------------------------------------------------------------
191
+ ----------------------------------------------------------------------------------------------
192
+ RailsSso::SsoStrategyTest: test_authenticate!_returns_:failure_when_access_token_not_available
193
+ ----------------------------------------------------------------------------------------------
194
+ -------------------------------------------------------------------------------------------
195
+ RailsSso::SsoStrategyTest: test_authenticate!_returns_:failure_when_in_signed_out_test_mode
196
+ -------------------------------------------------------------------------------------------
197
+ -----------------------------------------------------------------------------------------------------
198
+ RailsSso::SsoStrategyTest: test_authenticate!_returns_:success_when_access_token_available_in_session
199
+ -----------------------------------------------------------------------------------------------------
200
+ ----------------------------------------------
201
+ RailsSso::SsoStrategyTest: test_does_not_store
202
+ ----------------------------------------------
203
+ ------------------------------------------------------------------------------------------
204
+ RailsSso::SsoStrategyTest: test_authenticate!_returns_:success_when_in_signed_in_test_mode
205
+ ------------------------------------------------------------------------------------------
206
+ -----------------------------------------------------------------------------------------------------
207
+ RailsSso::SsoStrategyTest: test_authenticate!_returns_:success_when_access_token_available_in_session
208
+ -----------------------------------------------------------------------------------------------------
209
+ -------------------------------------------------------------------------------------------
210
+ RailsSso::SsoStrategyTest: test_authenticate!_returns_:failure_when_in_signed_out_test_mode
211
+ -------------------------------------------------------------------------------------------
212
+ -----------------------------------------------------------------------
213
+ RailsSso::SsoStrategyTest: test_says_valid_when_access_token_is_present
214
+ -----------------------------------------------------------------------
215
+ ----------------------------------------------------------------------------------------------
216
+ RailsSso::SsoStrategyTest: test_authenticate!_returns_:failure_when_access_token_not_available
217
+ ----------------------------------------------------------------------------------------------
218
+ ----------------------------------------------
219
+ RailsSso::SsoStrategyTest: test_does_not_store
220
+ ----------------------------------------------
221
+ ----------------------------------------------------------------------------------------------
222
+ RailsSso::SsoStrategyTest: test_authenticate!_returns_:failure_when_access_token_not_available
223
+ ----------------------------------------------------------------------------------------------
224
+ ------------------------------------------------------------------------------------------
225
+ RailsSso::SsoStrategyTest: test_authenticate!_returns_:success_when_in_signed_in_test_mode
226
+ ------------------------------------------------------------------------------------------
227
+ ---------------------------------------------------------------------
228
+ RailsSso::SsoStrategyTest: test_is_valid_when_access_token_is_present
229
+ ---------------------------------------------------------------------
230
+ ----------------------------------------------
231
+ RailsSso::SsoStrategyTest: test_does_not_store
232
+ ----------------------------------------------
233
+ --------------------------------------------------------------------
234
+ RailsSso::SsoStrategyTest: test_is_valid_when_in_signed_in_test_mode
235
+ --------------------------------------------------------------------
236
+ -------------------------------------------------------------------------------------------
237
+ RailsSso::SsoStrategyTest: test_authenticate!_returns_:failure_when_in_signed_out_test_mode
238
+ -------------------------------------------------------------------------------------------
239
+ -----------------------------------------------------------------------------------------------------
240
+ RailsSso::SsoStrategyTest: test_authenticate!_returns_:success_when_access_token_available_in_session
241
+ -----------------------------------------------------------------------------------------------------
242
+ ------------------------------------------------------------------------------------------
243
+ RailsSso::SsoStrategyTest: test_authenticate!_returns_:success_when_in_signed_in_test_mode
244
+ ------------------------------------------------------------------------------------------
245
+ ----------------------------------------------
246
+ RailsSso::SsoStrategyTest: test_does_not_store
247
+ ----------------------------------------------
248
+ --------------------------------------------------------------------
249
+ RailsSso::SsoStrategyTest: test_is_valid_when_in_signed_in_test_mode
250
+ --------------------------------------------------------------------
251
+ ---------------------------------------------------------------------
252
+ RailsSso::SsoStrategyTest: test_is_valid_when_access_token_is_present
253
+ ---------------------------------------------------------------------
254
+ ----------------------------------------------------------------------------------------------
255
+ RailsSso::SsoStrategyTest: test_authenticate!_returns_:failure_when_access_token_not_available
256
+ ----------------------------------------------------------------------------------------------
257
+ -----------------------------------------------------------------------------------------------------
258
+ RailsSso::SsoStrategyTest: test_authenticate!_returns_:success_when_access_token_available_in_session
259
+ -----------------------------------------------------------------------------------------------------
260
+ -------------------------------------------------------------------------------------------
261
+ RailsSso::SsoStrategyTest: test_authenticate!_returns_:failure_when_in_signed_out_test_mode
262
+ -------------------------------------------------------------------------------------------
263
+ ------------------------------------------------------------------------
264
+ RailsSso::SsoStrategyTest: test_is_invalid_when_access_token_not_present
265
+ ------------------------------------------------------------------------
266
+ ------------------------------------------------------------------------------------------
267
+ RailsSso::SsoStrategyTest: test_authenticate!_returns_:success_when_in_signed_in_test_mode
268
+ ------------------------------------------------------------------------------------------
269
+ ----------------------------------------------------------------------------------------------
270
+ RailsSso::SsoStrategyTest: test_authenticate!_returns_:failure_when_access_token_not_available
271
+ ----------------------------------------------------------------------------------------------
272
+ ------------------------------------------------------------------------
273
+ RailsSso::SsoStrategyTest: test_is_invalid_when_access_token_not_present
274
+ ------------------------------------------------------------------------
275
+ -------------------------------------------------------------------------------------------
276
+ RailsSso::SsoStrategyTest: test_authenticate!_returns_:failure_when_in_signed_out_test_mode
277
+ -------------------------------------------------------------------------------------------
278
+ --------------------------------------------------------------------
279
+ RailsSso::SsoStrategyTest: test_is_valid_when_in_signed_in_test_mode
280
+ --------------------------------------------------------------------
281
+ ----------------------------------------------
282
+ RailsSso::SsoStrategyTest: test_does_not_store
283
+ ----------------------------------------------
284
+ ---------------------------------------------------------------------
285
+ RailsSso::SsoStrategyTest: test_is_valid_when_access_token_is_present
286
+ ---------------------------------------------------------------------
287
+ -----------------------------------------------------------------------------------------------------
288
+ RailsSso::SsoStrategyTest: test_authenticate!_returns_:success_when_access_token_available_in_session
289
+ -----------------------------------------------------------------------------------------------------
290
+ -----------------------------------------------------------------------
291
+ RailsSso::SsoStrategyTest: test_is_invalid_when_in_signed_out_test_mode
292
+ -----------------------------------------------------------------------
293
+ ---------------------------------------------------------------------
294
+ RailsSso::SsoStrategyTest: test_is_valid_when_access_token_is_present
295
+ ---------------------------------------------------------------------
296
+ --------------------------------------------------------------------------------------
297
+ RailsSso::SsoStrategyTest: test_authenticate!_returns_:success_when_sso_can_fetch_user
298
+ --------------------------------------------------------------------------------------
299
+ ----------------------------------------------
300
+ RailsSso::SsoStrategyTest: test_does_not_store
301
+ ----------------------------------------------
302
+ ----------------------------------------------------------------------------------------------
303
+ RailsSso::SsoStrategyTest: test_authenticate!_returns_:failure_when_access_token_not_available
304
+ ----------------------------------------------------------------------------------------------
305
+ ------------------------------------------------------------------------
306
+ RailsSso::SsoStrategyTest: test_is_invalid_when_access_token_not_present
307
+ ------------------------------------------------------------------------
308
+ -----------------------------------------------------------------------
309
+ RailsSso::SsoStrategyTest: test_is_invalid_when_in_signed_out_test_mode
310
+ -----------------------------------------------------------------------
311
+ --------------------------------------------------------------------
312
+ RailsSso::SsoStrategyTest: test_is_valid_when_in_signed_in_test_mode
313
+ --------------------------------------------------------------------
314
+ -------------------------------------------------------------------------------------------
315
+ RailsSso::SsoStrategyTest: test_authenticate!_returns_:failure_when_in_signed_out_test_mode
316
+ -------------------------------------------------------------------------------------------
317
+ ------------------------------------------------------------------------------------------
318
+ RailsSso::SsoStrategyTest: test_authenticate!_returns_:success_when_in_signed_in_test_mode
319
+ ------------------------------------------------------------------------------------------
320
+ --------------------------------------------------------------------------------------
321
+ RailsSso::SsoStrategyTest: test_authenticate!_returns_:success_when_sso_can_fetch_user
322
+ --------------------------------------------------------------------------------------
323
+ ----------------------------------------------
324
+ RailsSso::SsoStrategyTest: test_does_not_store
325
+ ----------------------------------------------
326
+ ---------------------------------------------------------------------
327
+ RailsSso::SsoStrategyTest: test_is_valid_when_access_token_is_present
328
+ ---------------------------------------------------------------------
329
+ -----------------------------------------------------------------------
330
+ RailsSso::SsoStrategyTest: test_is_invalid_when_in_signed_out_test_mode
331
+ -----------------------------------------------------------------------
332
+ -----------------------------------------------------------------------------------------
333
+ RailsSso::SsoStrategyTest: test_authenticate!_returns_:failure_when_sso_cannot_fetch_user
334
+ -----------------------------------------------------------------------------------------
335
+ --------------------------------------------------------------------
336
+ RailsSso::SsoStrategyTest: test_is_valid_when_in_signed_in_test_mode
337
+ --------------------------------------------------------------------
338
+ ------------------------------------------------------------------------
339
+ RailsSso::SsoStrategyTest: test_is_invalid_when_access_token_not_present
340
+ ------------------------------------------------------------------------
341
+ --------------------------------------------------------------------------------------
342
+ RailsSso::SsoStrategyTest: test_is_invalid_when_in_test_mode_without_access_token_mock
343
+ --------------------------------------------------------------------------------------
344
+ ---------------------------------------------------------------------
345
+ RailsSso::SsoStrategyTest: test_is_valid_when_access_token_is_present
346
+ ---------------------------------------------------------------------
347
+ -----------------------------------------------------------------------------------------
348
+ RailsSso::SsoStrategyTest: test_authenticate!_returns_:failure_when_sso_cannot_fetch_user
349
+ -----------------------------------------------------------------------------------------
350
+ ----------------------------------------------
351
+ RailsSso::SsoStrategyTest: test_does_not_store
352
+ ----------------------------------------------
353
+ ---------------------------------------------------------------------------------
354
+ RailsSso::SsoStrategyTest: test_is_valid_when_in_test_mode_with_access_token_mock
355
+ ---------------------------------------------------------------------------------
356
+ --------------------------------------------------------------------------------------
357
+ RailsSso::SsoStrategyTest: test_authenticate!_returns_:success_when_sso_can_fetch_user
358
+ --------------------------------------------------------------------------------------
359
+ ------------------------------------------------------------------------
360
+ RailsSso::SsoStrategyTest: test_is_invalid_when_access_token_not_present
361
+ ------------------------------------------------------------------------
362
+ --------------------------------------------------------------------------------------
363
+ RailsSso::SsoStrategyTest: test_authenticate!_returns_:success_when_sso_can_fetch_user
364
+ --------------------------------------------------------------------------------------
365
+ --------------------------------------------------------------------------------------
366
+ RailsSso::SsoStrategyTest: test_is_invalid_when_in_test_mode_without_access_token_mock
367
+ --------------------------------------------------------------------------------------
368
+ ---------------------------------------------------------------------
369
+ RailsSso::SsoStrategyTest: test_is_valid_when_access_token_is_present
370
+ ---------------------------------------------------------------------
371
+ ---------------------------------------------------------------------------------
372
+ RailsSso::SsoStrategyTest: test_is_valid_when_in_test_mode_with_access_token_mock
373
+ ---------------------------------------------------------------------------------
374
+ ------------------------------------------------------------------------
375
+ RailsSso::SsoStrategyTest: test_is_invalid_when_access_token_not_present
376
+ ------------------------------------------------------------------------
377
+ -----------------------------------------------------------------------------------------
378
+ RailsSso::SsoStrategyTest: test_authenticate!_returns_:failure_when_sso_cannot_fetch_user
379
+ -----------------------------------------------------------------------------------------
380
+ ----------------------------------------------
381
+ RailsSso::SsoStrategyTest: test_does_not_store
382
+ ----------------------------------------------
383
+ ------------------------------------------------------------------------------------------------
384
+ RailsSso::SessionsControllerTest: test_create_should_save_access_token_and_redirect_to_root_path
385
+ ------------------------------------------------------------------------------------------------
386
+ Processing by RailsSso::SessionsController#create as HTML
387
+ Parameters: {"provider"=>"developer"}
388
+ Redirected to http://test.host/
389
+ Completed 302 Found in 3ms
390
+ -------------------------------------------------------------------------------------------------------
391
+ RailsSso::SessionsControllerTest: test_destroy_should_invalidate_access_token_and_redirect_to_root_path
392
+ -------------------------------------------------------------------------------------------------------
393
+ Processing by RailsSso::SessionsController#destroy as HTML
394
+ Redirected to http://test.host/
395
+ Completed 302 Found in 0ms
396
+ ---------------------------------------------------------------------
397
+ RailsSso::SsoStrategyTest: test_is_valid_when_access_token_is_present
398
+ ---------------------------------------------------------------------
399
+ ---------------------------------------------------------------------------------
400
+ RailsSso::SsoStrategyTest: test_is_valid_when_in_test_mode_with_access_token_mock
401
+ ---------------------------------------------------------------------------------
402
+ -----------------------------------------------------------------------------------------
403
+ RailsSso::SsoStrategyTest: test_authenticate!_returns_:failure_when_sso_cannot_fetch_user
404
+ -----------------------------------------------------------------------------------------
405
+ ----------------------------------------------
406
+ RailsSso::SsoStrategyTest: test_does_not_store
407
+ ----------------------------------------------
408
+ --------------------------------------------------------------------------------------
409
+ RailsSso::SsoStrategyTest: test_authenticate!_returns_:success_when_sso_can_fetch_user
410
+ --------------------------------------------------------------------------------------
411
+ --------------------------------------------------------------------------------------
412
+ RailsSso::SsoStrategyTest: test_is_invalid_when_in_test_mode_without_access_token_mock
413
+ --------------------------------------------------------------------------------------
414
+ ------------------------------------------------------------------------
415
+ RailsSso::SsoStrategyTest: test_is_invalid_when_access_token_not_present
416
+ ------------------------------------------------------------------------
417
+ ----------------------------------------------------
418
+ SsoRoutesTest: test_should_route_/:provider/callback
419
+ ----------------------------------------------------
420
+ ------------------------------------------
421
+ SsoRoutesTest: test_should_route_/sign_out
422
+ ------------------------------------------
423
+ ----------------------------------------------------
424
+ RailsSso::ResponseErrorTest: test_assigns_error_code
425
+ ----------------------------------------------------
426
+ ------------------------------------------------------------------------------------
427
+ RailsSso::ResponseErrorTest: test_assigns_unauthenticated_error_message_from_locales
428
+ ------------------------------------------------------------------------------------
429
+ ----------------------------------------------------------------------------
430
+ RailsSso::ResponseErrorTest: test_assigns_unknown_error_message_from_locales
431
+ ----------------------------------------------------------------------------
432
+ -----------------------------------------------------------------------------------------------------
433
+ RailsSso::FetchUserTest: test_success_call_should_fetch_user_with_access_token_and_return_parsed_data
434
+ -----------------------------------------------------------------------------------------------------
435
+ ---------------------------------------------------------------------
436
+ RailsSso::FetchUserTest: test_unauthenticated_call_should_raise_error
437
+ ---------------------------------------------------------------------
438
+ -------------------------------------------------------------
439
+ RailsSso::FetchUserTest: test_unknown_call_should_raise_error
440
+ -------------------------------------------------------------
441
+ ------------------------
442
+ RailsSsoTest: test_truth
443
+ ------------------------
444
+ ----------------------------------------------------------------------------
445
+ RailsSso::FailureAppTest: test_json_call_runs_respond_action_and_renders_401
446
+ ----------------------------------------------------------------------------
447
+ ------------------------------------------------------------------------------------
448
+ RailsSso::FailureAppTest: test_regular_call_runs_respond_action_and_redirects_to_sso
449
+ ------------------------------------------------------------------------------------
450
+ ------------------------------------------------------------------------------------------------
451
+ RailsSso::SessionsControllerTest: test_create_should_save_access_token_and_redirect_to_root_path
452
+ ------------------------------------------------------------------------------------------------
453
+ Processing by RailsSso::SessionsController#create as HTML
454
+ Parameters: {"provider"=>"developer"}
455
+ Redirected to http://test.host/
456
+ Completed 302 Found in 0ms
457
+ -------------------------------------------------------------------------------------------------------
458
+ RailsSso::SessionsControllerTest: test_destroy_should_invalidate_access_token_and_redirect_to_root_path
459
+ -------------------------------------------------------------------------------------------------------
460
+ Processing by RailsSso::SessionsController#destroy as HTML
461
+ Redirected to http://test.host/
462
+ Completed 302 Found in 0ms
463
+ ---------------------------------------------------------------------------
464
+ RailsSso::AppTest: test_#fetch_user_data_returns_data_based_on_access_token
465
+ ---------------------------------------------------------------------------
466
+ ---------------------------------------------------------------------------
467
+ RailsSso::AppTest: test_#fetch_user_data_returns_data_based_on_access_token
468
+ ---------------------------------------------------------------------------
469
+ ---------------------------------------------------------------------------
470
+ RailsSso::AppTest: test_#fetch_user_data_returns_data_based_on_access_token
471
+ ---------------------------------------------------------------------------
472
+ ---------------------------------------------------------------------------
473
+ RailsSso::AppTest: test_#fetch_user_data_returns_data_based_on_access_token
474
+ ---------------------------------------------------------------------------
475
+ ---------------------------------------------------------------------------
476
+ RailsSso::AppTest: test_#fetch_user_data_returns_data_based_on_access_token
477
+ ---------------------------------------------------------------------------
478
+ ---------------------------------------------------------------------------
479
+ RailsSso::AppTest: test_#fetch_user_data_returns_data_based_on_access_token
480
+ ---------------------------------------------------------------------------
481
+ ---------------------------------------------------------------------------
482
+ RailsSso::AppTest: test_#fetch_user_data_returns_data_based_on_access_token
483
+ ---------------------------------------------------------------------------
484
+ -------------------------------------------------------------------------------------------
485
+ RailsSso::AppTest: test_#fetch_user_data_when_unauthenticated_refresh_token_and_return_data
486
+ -------------------------------------------------------------------------------------------
487
+ ---------------------------------------------------------------------------
488
+ RailsSso::AppTest: test_#fetch_user_data_returns_data_based_on_access_token
489
+ ---------------------------------------------------------------------------
490
+ ---------------------------------------------------------------------------
491
+ RailsSso::AppTest: test_#fetch_user_data_returns_data_based_on_access_token
492
+ ---------------------------------------------------------------------------
493
+ -------------------------------------------------------------------------------------------
494
+ RailsSso::AppTest: test_#fetch_user_data_when_unauthenticated_refresh_token_and_return_data
495
+ -------------------------------------------------------------------------------------------
496
+ ---------------------------------------------------------------------------
497
+ RailsSso::AppTest: test_#fetch_user_data_returns_data_based_on_access_token
498
+ ---------------------------------------------------------------------------
499
+ -------------------------------------------------------------------------------------------
500
+ RailsSso::AppTest: test_#fetch_user_data_when_unauthenticated_refresh_token_and_return_data
501
+ -------------------------------------------------------------------------------------------
502
+ -----------------------------------------------------------------------
503
+ RailsSso::AppTest: test_#fetch_user_data_when_invalid_token_returns_nil
504
+ -----------------------------------------------------------------------
505
+ ---------------------------------------------------------------------------
506
+ RailsSso::AppTest: test_#fetch_user_data_returns_data_based_on_access_token
507
+ ---------------------------------------------------------------------------
508
+ ------------------------------------------------------------------------------------------
509
+ RailsSso::AppTest: test_#fetch_user_data_when_stale_token_refreshes_token_and_returns_data
510
+ ------------------------------------------------------------------------------------------
511
+ ---------------------------------------------------------------------------
512
+ RailsSso::AppTest: test_#fetch_user_data_returns_data_based_on_access_token
513
+ ---------------------------------------------------------------------------
514
+ ----------------------------------------------------------------------------------------------
515
+ RailsSso::AppTest: test_#fetch_user_data_when_invalid_token_returns_nil_and_reset_access_token
516
+ ----------------------------------------------------------------------------------------------
517
+ ------------------------------------------------------------------------------------------
518
+ RailsSso::AppTest: test_#fetch_user_data_when_stale_token_refreshes_token_and_returns_data
519
+ ------------------------------------------------------------------------------------------
520
+ ----------------------------------------------------------------------------------------------
521
+ RailsSso::AppTest: test_#fetch_user_data_when_invalid_token_returns_nil_and_reset_access_token
522
+ ----------------------------------------------------------------------------------------------
523
+ ------------------------------------------------------------------------------------------
524
+ RailsSso::AppTest: test_#fetch_user_data_when_stale_token_refreshes_token_and_returns_data
525
+ ------------------------------------------------------------------------------------------
526
+ ---------------------------------------------------------------------------
527
+ RailsSso::AppTest: test_#fetch_user_data_returns_data_based_on_access_token
528
+ ---------------------------------------------------------------------------
529
+ ---------------------------------------------------------------------------
530
+ RailsSso::AppTest: test_#fetch_user_data_returns_data_based_on_access_token
531
+ ---------------------------------------------------------------------------
532
+ ------------------------------------------------------------------------------------------
533
+ RailsSso::AppTest: test_#fetch_user_data_when_stale_token_refreshes_token_and_returns_data
534
+ ------------------------------------------------------------------------------------------
535
+ ----------------------------------------------------------------------------------------------
536
+ RailsSso::AppTest: test_#fetch_user_data_when_invalid_token_returns_nil_and_reset_access_token
537
+ ----------------------------------------------------------------------------------------------
538
+ ----------------------------------------------------------------------------------------------
539
+ RailsSso::AppTest: test_#fetch_user_data_when_invalid_token_returns_nil_and_reset_access_token
540
+ ----------------------------------------------------------------------------------------------
541
+ ---------------------------------------------------------------------------
542
+ RailsSso::AppTest: test_#fetch_user_data_returns_data_based_on_access_token
543
+ ---------------------------------------------------------------------------
544
+ ------------------------------------------------------------------------------------------
545
+ RailsSso::AppTest: test_#fetch_user_data_when_stale_token_refreshes_token_and_returns_data
546
+ ------------------------------------------------------------------------------------------
547
+ ----------------------------------------------------------------------------------------------
548
+ RailsSso::AppTest: test_#fetch_user_data_when_invalid_token_returns_nil_and_reset_access_token
549
+ ----------------------------------------------------------------------------------------------
550
+ ---------------------------------------------------------------------------
551
+ RailsSso::AppTest: test_#fetch_user_data_returns_data_based_on_access_token
552
+ ---------------------------------------------------------------------------
553
+ ------------------------------------------------------------------------------------------
554
+ RailsSso::AppTest: test_#fetch_user_data_when_stale_token_refreshes_token_and_returns_data
555
+ ------------------------------------------------------------------------------------------
556
+ ------------------------------------------------------------------------------------------
557
+ RailsSso::AppTest: test_#fetch_user_data_when_stale_token_refreshes_token_and_returns_data
558
+ ------------------------------------------------------------------------------------------
559
+ ---------------------------------------------------------------------------
560
+ RailsSso::AppTest: test_#fetch_user_data_returns_data_based_on_access_token
561
+ ---------------------------------------------------------------------------
562
+ ----------------------------------------------------------------------------------------------
563
+ RailsSso::AppTest: test_#fetch_user_data_when_invalid_token_returns_nil_and_reset_access_token
564
+ ----------------------------------------------------------------------------------------------
565
+ ---------------------------------------------------------------------------
566
+ RailsSso::AppTest: test_#fetch_user_data_returns_data_based_on_access_token
567
+ ---------------------------------------------------------------------------
568
+ ------------------------------------------------------------------------------------------
569
+ RailsSso::AppTest: test_#fetch_user_data_when_stale_token_refreshes_token_and_returns_data
570
+ ------------------------------------------------------------------------------------------
571
+ ----------------------------------------------------------------------------------------------
572
+ RailsSso::AppTest: test_#fetch_user_data_when_invalid_token_returns_nil_and_reset_access_token
573
+ ----------------------------------------------------------------------------------------------
574
+ ----------------------------------------------------------------------------------------------
575
+ RailsSso::AppTest: test_#fetch_user_data_when_invalid_token_returns_nil_and_reset_access_token
576
+ ----------------------------------------------------------------------------------------------
577
+ ------------------------------------------------------------------------------------------
578
+ RailsSso::AppTest: test_#fetch_user_data_when_stale_token_refreshes_token_and_returns_data
579
+ ------------------------------------------------------------------------------------------
580
+ ---------------------------------------------------------------------------
581
+ RailsSso::AppTest: test_#fetch_user_data_returns_data_based_on_access_token
582
+ ---------------------------------------------------------------------------
583
+ ----------------------------------------------------------------------------------------------
584
+ RailsSso::AppTest: test_#fetch_user_data_when_invalid_token_returns_nil_and_reset_access_token
585
+ ----------------------------------------------------------------------------------------------
586
+ ---------------------------------------------------------------------------
587
+ RailsSso::AppTest: test_#fetch_user_data_returns_data_based_on_access_token
588
+ ---------------------------------------------------------------------------
589
+ ---------------------------------------------------------------------------
590
+ RailsSso::AppTest: test_#fetch_user_data_returns_data_based_on_access_token
591
+ ---------------------------------------------------------------------------
592
+ ----------------------------------------------------------------------------------------------
593
+ RailsSso::AppTest: test_#fetch_user_data_when_invalid_token_returns_nil_and_reset_access_token
594
+ ----------------------------------------------------------------------------------------------
595
+ ---------------------------------------------------------------------------
596
+ RailsSso::AppTest: test_#fetch_user_data_returns_data_based_on_access_token
597
+ ---------------------------------------------------------------------------
598
+ ----------------------------------------------------------------------------------------------
599
+ RailsSso::AppTest: test_#fetch_user_data_when_invalid_token_returns_nil_and_reset_access_token
600
+ ----------------------------------------------------------------------------------------------
601
+ ---------------------------------------------------------------------------
602
+ RailsSso::AppTest: test_#fetch_user_data_returns_data_based_on_access_token
603
+ ---------------------------------------------------------------------------
604
+ ----------------------------------------------------------------------------------------------
605
+ RailsSso::AppTest: test_#fetch_user_data_when_invalid_token_returns_nil_and_reset_access_token
606
+ ----------------------------------------------------------------------------------------------
607
+ ---------------------------------------------------------------------------
608
+ RailsSso::AppTest: test_#fetch_user_data_returns_data_based_on_access_token
609
+ ---------------------------------------------------------------------------
610
+ ----------------------------------------------------------------------------------------------
611
+ RailsSso::AppTest: test_#fetch_user_data_when_invalid_token_returns_nil_and_reset_access_token
612
+ ----------------------------------------------------------------------------------------------
613
+ ----------------------------------------------------------------------------------------------
614
+ RailsSso::AppTest: test_#fetch_user_data_when_invalid_token_returns_nil_and_reset_access_token
615
+ ----------------------------------------------------------------------------------------------
616
+ ---------------------------------------------------------------------------
617
+ RailsSso::AppTest: test_#fetch_user_data_returns_data_based_on_access_token
618
+ ---------------------------------------------------------------------------
619
+ ---------------------------------------------------------------------------
620
+ RailsSso::AppTest: test_#fetch_user_data_returns_data_based_on_access_token
621
+ ---------------------------------------------------------------------------
622
+ ----------------------------------------------------------------------------------------------
623
+ RailsSso::AppTest: test_#fetch_user_data_when_invalid_token_returns_nil_and_reset_access_token
624
+ ----------------------------------------------------------------------------------------------
625
+ ----------------------------------------------------------------------------------------------
626
+ RailsSso::AppTest: test_#fetch_user_data_when_invalid_token_returns_nil_and_reset_access_token
627
+ ----------------------------------------------------------------------------------------------
628
+ ---------------------------------------------------------------------------
629
+ RailsSso::AppTest: test_#fetch_user_data_returns_data_based_on_access_token
630
+ ---------------------------------------------------------------------------
631
+ ---------------------------------------------------------------------------
632
+ RailsSso::AppTest: test_#fetch_user_data_returns_data_based_on_access_token
633
+ ---------------------------------------------------------------------------
634
+ ----------------------------------------------------------------------------------------------
635
+ RailsSso::AppTest: test_#fetch_user_data_when_invalid_token_returns_nil_and_reset_access_token
636
+ ----------------------------------------------------------------------------------------------
637
+ ----------------------------------------------------------------------------------------------
638
+ RailsSso::AppTest: test_#fetch_user_data_when_invalid_token_returns_nil_and_reset_access_token
639
+ ----------------------------------------------------------------------------------------------
640
+ ---------------------------------------------------------------------------
641
+ RailsSso::AppTest: test_#fetch_user_data_returns_data_based_on_access_token
642
+ ---------------------------------------------------------------------------
643
+ ---------------------------------------------------------------------------
644
+ RailsSso::AppTest: test_#fetch_user_data_returns_data_based_on_access_token
645
+ ---------------------------------------------------------------------------
646
+ ----------------------------------------------------------------------------------------------
647
+ RailsSso::AppTest: test_#fetch_user_data_when_invalid_token_returns_nil_and_reset_access_token
648
+ ----------------------------------------------------------------------------------------------
649
+ ----------------------------------------------------------------------------------------------
650
+ RailsSso::AppTest: test_#fetch_user_data_when_invalid_token_returns_nil_and_reset_access_token
651
+ ----------------------------------------------------------------------------------------------
652
+ ---------------------------------------------------------------------------
653
+ RailsSso::AppTest: test_#fetch_user_data_returns_data_based_on_access_token
654
+ ---------------------------------------------------------------------------
655
+ ------------------------------------------------------------------------------------------
656
+ RailsSso::AppTest: test_#fetch_user_data_when_stale_token_refreshes_token_and_returns_data
657
+ ------------------------------------------------------------------------------------------
658
+ ------------------------------------------------------------------------------------------
659
+ RailsSso::AppTest: test_#fetch_user_data_when_stale_token_refreshes_token_and_returns_data
660
+ ------------------------------------------------------------------------------------------
661
+ ---------------------------------------------------------------------------
662
+ RailsSso::AppTest: test_#fetch_user_data_returns_data_based_on_access_token
663
+ ---------------------------------------------------------------------------
664
+ ----------------------------------------------------------------------------------------------
665
+ RailsSso::AppTest: test_#fetch_user_data_when_invalid_token_returns_nil_and_reset_access_token
666
+ ----------------------------------------------------------------------------------------------
667
+ ---------------------------------------------------------------------------
668
+ RailsSso::AppTest: test_#fetch_user_data_returns_data_based_on_access_token
669
+ ---------------------------------------------------------------------------
670
+ ----------------------------------------------------------------------------------------------
671
+ RailsSso::AppTest: test_#fetch_user_data_when_invalid_token_returns_nil_and_reset_access_token
672
+ ----------------------------------------------------------------------------------------------
673
+ ------------------------------------------------------------------------------------------
674
+ RailsSso::AppTest: test_#fetch_user_data_when_stale_token_refreshes_token_and_returns_data
675
+ ------------------------------------------------------------------------------------------
676
+ ---------------------------------------------------------------------------
677
+ RailsSso::AppTest: test_#fetch_user_data_returns_data_based_on_access_token
678
+ ---------------------------------------------------------------------------
679
+ ------------------------------------------------------------------------------------------
680
+ RailsSso::AppTest: test_#fetch_user_data_when_stale_token_refreshes_token_and_returns_data
681
+ ------------------------------------------------------------------------------------------
682
+ ----------------------------------------------------------------------------------------------
683
+ RailsSso::AppTest: test_#fetch_user_data_when_invalid_token_returns_nil_and_reset_access_token
684
+ ----------------------------------------------------------------------------------------------
685
+ ----------------------------------------------------------------------------------------------
686
+ RailsSso::AppTest: test_#fetch_user_data_when_invalid_token_returns_nil_and_reset_access_token
687
+ ----------------------------------------------------------------------------------------------
688
+ ---------------------------------------------------------------------------
689
+ RailsSso::AppTest: test_#fetch_user_data_returns_data_based_on_access_token
690
+ ---------------------------------------------------------------------------
691
+ ------------------------------------------------------------------------------------------
692
+ RailsSso::AppTest: test_#fetch_user_data_when_stale_token_refreshes_token_and_returns_data
693
+ ------------------------------------------------------------------------------------------
694
+ ---------------------------------------------------------------------------
695
+ RailsSso::AppTest: test_#fetch_user_data_returns_data_based_on_access_token
696
+ ---------------------------------------------------------------------------
697
+ ------------------------------------------------------------------------------------------
698
+ RailsSso::AppTest: test_#fetch_user_data_when_stale_token_refreshes_token_and_returns_data
699
+ ------------------------------------------------------------------------------------------
700
+ ----------------------------------------------------------------------------------------------
701
+ RailsSso::AppTest: test_#fetch_user_data_when_invalid_token_returns_nil_and_reset_access_token
702
+ ----------------------------------------------------------------------------------------------
703
+ ---------------------------------------------------------------------------
704
+ RailsSso::AppTest: test_#fetch_user_data_returns_data_based_on_access_token
705
+ ---------------------------------------------------------------------------
706
+ ----------------------------------------------------------------------------------------------
707
+ RailsSso::AppTest: test_#fetch_user_data_when_invalid_token_returns_nil_and_reset_access_token
708
+ ----------------------------------------------------------------------------------------------
709
+ ------------------------------------------------------------------------------------------
710
+ RailsSso::AppTest: test_#fetch_user_data_when_stale_token_refreshes_token_and_returns_data
711
+ ------------------------------------------------------------------------------------------
@@ -0,0 +1,95 @@
1
+ require "test_helper"
2
+
3
+ class RailsSso::AppTest < ActiveSupport::TestCase
4
+ test "#fetch_user_data returns data based on access token" do
5
+ strategy = mock()
6
+ session = { access_token: "169783" }
7
+ client = RailsSso::Client.new(build_adapter)
8
+
9
+ app = RailsSso::App.new(strategy, session, client)
10
+
11
+ assert_equal user_data, app.fetch_user_data
12
+ end
13
+
14
+ test "#fetch_user_data when stale token refreshes token and returns data" do
15
+ new_token = mock()
16
+ new_token.stubs(:token).returns("169783")
17
+ new_token.stubs(:refresh_token).returns("new_refresh_token")
18
+ new_token.stubs(:options=)
19
+ adapter = build_adapter
20
+ adapter.stubs(:id).returns("123")
21
+ adapter.stubs(:secret).returns("456")
22
+ adapter.stubs(:get_token).returns(new_token)
23
+ strategy = mock()
24
+ strategy.stubs(:client).returns(adapter)
25
+ session = { access_token: "stale", refresh_token: "refresh_token" }
26
+ client = RailsSso::Client.new(adapter)
27
+
28
+ app = RailsSso::App.new(strategy, session, client)
29
+
30
+ assert_equal user_data, app.fetch_user_data
31
+ assert_equal "169783", session[:access_token]
32
+ assert_equal "new_refresh_token", session[:refresh_token]
33
+ end
34
+
35
+ test "#fetch_user_data when invalid token returns nil and reset access token" do
36
+ error_response = mock()
37
+ error_response.stubs(:error=)
38
+ error_response.stubs(:parsed).returns({
39
+ "error" => "401",
40
+ "error_description" => "error description"
41
+ })
42
+ error_response.stubs(:body).returns("")
43
+ adapter = build_adapter
44
+ adapter.stubs(:id).returns("123")
45
+ adapter.stubs(:secret).returns("456")
46
+ adapter.stubs(:get_token).raises(::OAuth2::Error.new(error_response))
47
+ strategy = mock()
48
+ strategy.stubs(:client).returns(adapter)
49
+ session = { access_token: "invalid", refresh_token: "invalid" }
50
+ client = RailsSso::Client.new(adapter)
51
+
52
+ app = RailsSso::App.new(strategy, session, client)
53
+
54
+ assert_equal nil, app.fetch_user_data
55
+ end
56
+
57
+ def user_data
58
+ { "uid" => "1234" }
59
+ end
60
+
61
+ def valid_headers
62
+ build_request_headers("169783")
63
+ end
64
+
65
+ def stale_headers
66
+ build_request_headers("stale")
67
+ end
68
+
69
+ def invalid_headers
70
+ build_request_headers("invalid")
71
+ end
72
+
73
+ def build_adapter
74
+ Faraday.new do |builder|
75
+ builder.adapter :test do |stub|
76
+ stub.get("/api/v1/me", invalid_headers) do |env|
77
+ [401, { "Content-Type" => "application/json" }, ""]
78
+ end
79
+ stub.get("/api/v1/me", stale_headers) do |env|
80
+ [401, { "Content-Type" => "application/json" }, ""]
81
+ end
82
+ stub.get("/api/v1/me", valid_headers) do |env|
83
+ [200, { "Content-Type" => "application/json" }, user_data]
84
+ end
85
+ end
86
+ end
87
+ end
88
+
89
+ def build_request_headers(token)
90
+ {
91
+ "Authorization" => "Bearer #{token}",
92
+ "Content-Type" => "application/json"
93
+ }
94
+ end
95
+ end
@@ -0,0 +1,60 @@
1
+ require "test_helper"
2
+
3
+ class RailsSso::SsoStrategyTest < ActiveSupport::TestCase
4
+ test "does not store" do
5
+ strategy = RailsSso::SsoStrategy.new(nil)
6
+
7
+ refute strategy.store?
8
+ end
9
+
10
+ test "is valid when access token is present" do
11
+ session = { access_token: "169783" }
12
+ env = { "rack.session" => session }
13
+ strategy = RailsSso::SsoStrategy.new(env)
14
+
15
+ assert strategy.valid?
16
+ end
17
+
18
+ test "is valid when in test mode with access token mock" do
19
+ env = { "rack.session" => {} }
20
+ strategy = RailsSso::SsoStrategy.new(env)
21
+ RailsSso.stubs(:test_mode).returns(true)
22
+ RailsSso.stubs(:access_token_mock).returns("169783")
23
+
24
+ assert strategy.valid?
25
+ end
26
+
27
+ test "is invalid when in test mode without access token mock" do
28
+ env = { "rack.session" => {} }
29
+ strategy = RailsSso::SsoStrategy.new(env)
30
+ RailsSso.stubs(:test_mode).returns(true)
31
+ RailsSso.stubs(:access_token_mock).returns(nil)
32
+
33
+ refute strategy.valid?
34
+ end
35
+
36
+ test "is invalid when access token not present" do
37
+ env = { "rack.session" => {} }
38
+ strategy = RailsSso::SsoStrategy.new(env)
39
+
40
+ refute strategy.valid?
41
+ end
42
+
43
+ test "authenticate! returns :success when sso can fetch user" do
44
+ sso_app = mock()
45
+ sso_app.stubs(:fetch_user_data).returns({ "uid" => "169783" })
46
+ env = { "sso" => sso_app }
47
+ strategy = RailsSso::SsoStrategy.new(env)
48
+
49
+ assert_equal :success, strategy.authenticate!
50
+ end
51
+
52
+ test "authenticate! returns :failure when sso cannot fetch user" do
53
+ sso_app = mock()
54
+ sso_app.stubs(:fetch_user_data).returns(nil)
55
+ env = { "sso" => sso_app }
56
+ strategy = RailsSso::SsoStrategy.new(env)
57
+
58
+ assert_equal :failure, strategy.authenticate!
59
+ end
60
+ 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.6.1
4
+ version: 0.7.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-07-17 00:00:00.000000000 Z
11
+ date: 2015-08-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -186,8 +186,10 @@ files:
186
186
  - test/dummy/public/422.html
187
187
  - test/dummy/public/500.html
188
188
  - test/dummy/public/favicon.ico
189
+ - test/lib/rails_sso/app_test.rb
189
190
  - test/lib/rails_sso/failure_app_test.rb
190
191
  - test/lib/rails_sso/response_error_test.rb
192
+ - test/lib/rails_sso/sso_strategy_test.rb
191
193
  - test/rails_sso_test.rb
192
194
  - test/routes/sso_routes_test.rb
193
195
  - test/services/rails_sso/fetch_user_test.rb
@@ -218,6 +220,8 @@ specification_version: 4
218
220
  summary: SSO Rails Engine
219
221
  test_files:
220
222
  - test/services/rails_sso/fetch_user_test.rb
223
+ - test/lib/rails_sso/app_test.rb
224
+ - test/lib/rails_sso/sso_strategy_test.rb
221
225
  - test/lib/rails_sso/response_error_test.rb
222
226
  - test/lib/rails_sso/failure_app_test.rb
223
227
  - test/rails_sso_test.rb