rails_sso 0.4.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c2a497053dd237b714c1b0b91a2439715979f799
4
- data.tar.gz: e1182450ba793d89369d5f7a39e2cc065322e8bc
3
+ metadata.gz: 26aee36b2cf776c7887e8076d19fb8a06ee868f1
4
+ data.tar.gz: 1b2d7f063181a77747f38479578cfae1ef43b350
5
5
  SHA512:
6
- metadata.gz: ba6952eae5f2ac284edf0fe57cd81e032545506bd09f87caf13bdb022baa150090c2824c80a8a48362c9dbc2032c4ee94341cf55a539341048ecfb6c1daa03a2
7
- data.tar.gz: 7792868a6d5856dbf3a0cae4276563ab1ea81e6b5c9b0cd65096be40a9b7c27763e4d8e05cf680788305f472033f2ae446bf733eab1d76e4184c6517c56ba085
6
+ metadata.gz: d3e99e4f290a9c6158b76b043e7ced982a7e8745914d9d550d3f72c1e3384b95416023016122a64631c37ebcf6e9aaa629d8250e73330077485aae50c5d00d6c
7
+ data.tar.gz: 2af36a116a0f166d01c5a5240be0bd78d6993b05927e522f84794981d30304f2d04db3e0cbbeeee995c1219910e0e62beb32d8236e19a5694e643c1e2ecbb364
data/README.md CHANGED
@@ -71,14 +71,33 @@ Available helpers for controllers and views:
71
71
  Available filters and helpers for controllers:
72
72
 
73
73
  * `authenticate_user!`
74
- * `save_access_token!`
75
- * `invalidate_access_token!`
74
+ * `sign_in_with_access_token!(access_token)`
75
+ * `sign_out!`
76
+ * `warden`
77
+ * `sso_app`
76
78
 
77
79
  Available helpers for views:
78
80
 
79
81
  * `sso.sign_in_path`
80
82
  * `sso.sign_out_path`
81
83
 
84
+ ## Testing & Development mode
85
+
86
+ You can turn on "test mode" by enabling [OmniAuth test mode](https://github.com/intridea/omniauth/wiki/Integration-Testing).
87
+
88
+ ```ruby
89
+ OmniAuth.config.test_mode = true
90
+ ```
91
+
92
+ To mock user data use OmniAuth `mock_auth` feature with your provider.
93
+
94
+ ```ruby
95
+ OmniAuth.config.mock_auth[:example] = OmniAuth::AuthHash.new({
96
+ name: 'John Kowalski',
97
+ uid: '42'
98
+ })
99
+ ```
100
+
82
101
  ## Contributing
83
102
 
84
103
  1. Fork it
data/lib/rails_sso/app.rb CHANGED
@@ -30,6 +30,8 @@ module RailsSso
30
30
  end
31
31
 
32
32
  def access_token
33
+ return mock_token if OmniAuth.config.test_mode
34
+
33
35
  OAuth2::AccessToken.new(strategy.client, session[:access_token], {
34
36
  refresh_token: session[:refresh_token]
35
37
  })
@@ -43,16 +45,41 @@ module RailsSso
43
45
 
44
46
  def provider_client
45
47
  @provider_client ||= RailsSso::Client.new(RailsSso.provider_url) do |conn|
46
- if RailsSso.use_cache
47
- conn.use :http_cache,
48
- store: Rails.cache,
49
- logger: Rails.logger,
50
- serializer: Marshal,
51
- shared_cache: false
48
+ case
49
+ when OmniAuth.config.test_mode
50
+ mock_connection(conn)
51
+ else
52
+ setup_connection(conn)
52
53
  end
54
+ end
55
+ end
56
+
57
+ private
58
+
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
53
67
 
54
- conn.adapter Faraday.default_adapter
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, {}, mock_auth] }
55
74
  end
56
75
  end
76
+
77
+ def mock_auth
78
+ OmniAuth.config.mock_auth[RailsSso.provider_name.to_sym].to_json
79
+ end
80
+
81
+ def mock_token
82
+ RailsSso::TokenMock.new
83
+ end
57
84
  end
58
85
  end
@@ -21,6 +21,12 @@ module RailsSso
21
21
  call_app!
22
22
  end
23
23
 
24
+ def mock_call!(*)
25
+ setup_sso!
26
+
27
+ super
28
+ end
29
+
24
30
  def setup_sso!
25
31
  env['sso'] ||= RailsSso::App.new(self, session)
26
32
  end
@@ -5,7 +5,7 @@ module RailsSso
5
5
  end
6
6
 
7
7
  def valid?
8
- session[:access_token].present?
8
+ session[:access_token].present? || OmniAuth.config.test_mode
9
9
  end
10
10
 
11
11
  def authenticate!
@@ -0,0 +1,17 @@
1
+ require 'faraday'
2
+
3
+ module RailsSso
4
+ class TokenMock
5
+ attr_reader :connection
6
+
7
+ delegate :get, :post, :put, :patch, :delete, to: :connection
8
+
9
+ def initialize(*)
10
+ @connection = Faraday.new do |builder|
11
+ builder.adapter :test do |stub|
12
+ stub.delete(RailsSso.provider_sign_out_path) { |env| [200, {}, ''] }
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -1,3 +1,3 @@
1
1
  module RailsSso
2
- VERSION = "0.4.0"
2
+ VERSION = "0.5.0"
3
3
  end
data/lib/rails_sso.rb CHANGED
@@ -40,3 +40,4 @@ require 'rails_sso/client'
40
40
  require 'rails_sso/response_error'
41
41
  require 'rails_sso/sso_strategy'
42
42
  require 'rails_sso/failure_app'
43
+ require 'rails_sso/token_mock'
@@ -4548,3 +4548,46 @@ RailsSso::ResponseErrorTest: test_assigns_unauthenticated_error_message_from_loc
4548
4548
  ----------------------------------------------------------------------------
4549
4549
  RailsSso::ResponseErrorTest: test_assigns_unknown_error_message_from_locales
4550
4550
  ----------------------------------------------------------------------------
4551
+ -----------------------------------------------------------------------------
4552
+ RailsSso::FailureAppTest: test_.call_runs_respond_action_and_redirects_to_sso
4553
+ -----------------------------------------------------------------------------
4554
+ ---------------------------------------------------------------------
4555
+ RailsSso::FetchUserTest: test_unauthenticated_call_should_raise_error
4556
+ ---------------------------------------------------------------------
4557
+ -----------------------------------------------------------------------------------------------------
4558
+ RailsSso::FetchUserTest: test_success_call_should_fetch_user_with_access_token_and_return_parsed_data
4559
+ -----------------------------------------------------------------------------------------------------
4560
+ -------------------------------------------------------------
4561
+ RailsSso::FetchUserTest: test_unknown_call_should_raise_error
4562
+ -------------------------------------------------------------
4563
+ ----------------------------------------------------
4564
+ RailsSso::ResponseErrorTest: test_assigns_error_code
4565
+ ----------------------------------------------------
4566
+ ----------------------------------------------------------------------------
4567
+ RailsSso::ResponseErrorTest: test_assigns_unknown_error_message_from_locales
4568
+ ----------------------------------------------------------------------------
4569
+ ------------------------------------------------------------------------------------
4570
+ RailsSso::ResponseErrorTest: test_assigns_unauthenticated_error_message_from_locales
4571
+ ------------------------------------------------------------------------------------
4572
+ ----------------------------------------------------
4573
+ SsoRoutesTest: test_should_route_/:provider/callback
4574
+ ----------------------------------------------------
4575
+ ------------------------------------------
4576
+ SsoRoutesTest: test_should_route_/sign_out
4577
+ ------------------------------------------
4578
+ ------------------------------------------------------------------------------------------------
4579
+ RailsSso::SessionsControllerTest: test_create_should_save_access_token_and_redirect_to_root_path
4580
+ ------------------------------------------------------------------------------------------------
4581
+ Processing by RailsSso::SessionsController#create as HTML
4582
+ Parameters: {"provider"=>"developer"}
4583
+ Redirected to http://test.host/
4584
+ Completed 302 Found in 0ms
4585
+ -------------------------------------------------------------------------------------------------------
4586
+ RailsSso::SessionsControllerTest: test_destroy_should_invalidate_access_token_and_redirect_to_root_path
4587
+ -------------------------------------------------------------------------------------------------------
4588
+ Processing by RailsSso::SessionsController#destroy as HTML
4589
+ Redirected to http://test.host/
4590
+ Completed 302 Found in 0ms
4591
+ ------------------------
4592
+ RailsSsoTest: test_truth
4593
+ ------------------------
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.0
4
+ version: 0.5.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-04-09 00:00:00.000000000 Z
11
+ date: 2015-04-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -132,6 +132,7 @@ files:
132
132
  - lib/rails_sso/helpers.rb
133
133
  - lib/rails_sso/response_error.rb
134
134
  - lib/rails_sso/sso_strategy.rb
135
+ - lib/rails_sso/token_mock.rb
135
136
  - lib/rails_sso/version.rb
136
137
  - lib/tasks/rails_sso_tasks.rake
137
138
  - test/controllers/rails_sso/sessions_controller_test.rb