clearance 1.10.1 → 1.17.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of clearance might be problematic. Click here for more details.

Files changed (106) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +1 -0
  3. data/.travis.yml +20 -8
  4. data/.yardopts +3 -0
  5. data/Appraisals +13 -16
  6. data/Gemfile +7 -5
  7. data/Gemfile.lock +124 -130
  8. data/NEWS.md +171 -2
  9. data/README.md +99 -42
  10. data/app/controllers/clearance/passwords_controller.rb +35 -21
  11. data/app/controllers/clearance/sessions_controller.rb +17 -3
  12. data/app/controllers/clearance/users_controller.rb +10 -4
  13. data/app/mailers/clearance_mailer.rb +2 -3
  14. data/app/views/clearance_mailer/change_password.text.erb +1 -1
  15. data/app/views/layouts/application.html.erb +0 -1
  16. data/bin/setup +6 -2
  17. data/clearance.gemspec +5 -2
  18. data/config/locales/clearance.en.yml +9 -0
  19. data/gemfiles/rails_4.2.gemfile +20 -0
  20. data/gemfiles/rails_5.0.gemfile +21 -0
  21. data/gemfiles/rails_5.1.gemfile +21 -0
  22. data/gemfiles/rails_5.2.gemfile +21 -0
  23. data/lib/clearance/authentication.rb +63 -3
  24. data/lib/clearance/authorization.rb +48 -5
  25. data/lib/clearance/back_door.rb +55 -6
  26. data/lib/clearance/configuration.rb +50 -10
  27. data/lib/clearance/constraints/signed_in.rb +21 -0
  28. data/lib/clearance/constraints/signed_out.rb +12 -0
  29. data/lib/clearance/constraints.rb +12 -0
  30. data/lib/clearance/controller.rb +13 -0
  31. data/lib/clearance/default_sign_in_guard.rb +17 -0
  32. data/lib/clearance/engine.rb +18 -5
  33. data/lib/clearance/password_strategies/bcrypt.rb +16 -21
  34. data/lib/clearance/password_strategies/bcrypt_migration_from_sha1.rb +10 -0
  35. data/lib/clearance/password_strategies/blowfish.rb +10 -1
  36. data/lib/clearance/password_strategies/sha1.rb +9 -0
  37. data/lib/clearance/password_strategies.rb +13 -0
  38. data/lib/clearance/rack_session.rb +13 -0
  39. data/lib/clearance/rspec.rb +15 -4
  40. data/lib/clearance/session.rb +62 -13
  41. data/lib/clearance/session_status.rb +7 -0
  42. data/lib/clearance/sign_in_guard.rb +65 -0
  43. data/lib/clearance/test_unit.rb +3 -3
  44. data/lib/clearance/testing/controller_helpers.rb +57 -0
  45. data/lib/clearance/testing/deny_access_matcher.rb +36 -2
  46. data/lib/clearance/testing/helpers.rb +9 -25
  47. data/lib/clearance/testing/view_helpers.rb +32 -0
  48. data/lib/clearance/token.rb +7 -0
  49. data/lib/clearance/user.rb +183 -4
  50. data/lib/clearance/version.rb +1 -1
  51. data/lib/generators/clearance/install/install_generator.rb +28 -9
  52. data/lib/generators/clearance/install/templates/README +1 -1
  53. data/lib/generators/clearance/install/templates/clearance.rb +1 -0
  54. data/lib/generators/clearance/install/templates/db/migrate/{add_clearance_to_users.rb → add_clearance_to_users.rb.erb} +3 -3
  55. data/lib/generators/clearance/install/templates/db/migrate/{create_users.rb → create_users.rb.erb} +2 -2
  56. data/lib/generators/clearance/install/templates/user.rb.erb +3 -0
  57. data/lib/generators/clearance/routes/routes_generator.rb +23 -0
  58. data/lib/generators/clearance/routes/templates/routes.rb +7 -7
  59. data/lib/generators/clearance/specs/templates/factories/clearance.rb +2 -2
  60. data/lib/generators/clearance/specs/templates/features/clearance/user_signs_out_spec.rb.tt +1 -1
  61. data/lib/generators/clearance/specs/templates/features/clearance/visitor_resets_password_spec.rb.tt +12 -3
  62. data/lib/generators/clearance/specs/templates/features/clearance/visitor_signs_in_spec.rb.tt +3 -3
  63. data/lib/generators/clearance/specs/templates/features/clearance/visitor_signs_up_spec.rb.tt +1 -1
  64. data/lib/generators/clearance/specs/templates/features/clearance/visitor_updates_password_spec.rb.tt +2 -2
  65. data/lib/generators/clearance/specs/templates/support/features/clearance_helpers.rb +2 -2
  66. data/spec/acceptance/clearance_installation_spec.rb +15 -7
  67. data/spec/app_templates/app/models/rails5/user.rb +5 -0
  68. data/spec/app_templates/config/initializers/clearance.rb +2 -0
  69. data/spec/app_templates/testapp/Gemfile +1 -1
  70. data/spec/app_templates/testapp/app/controllers/home_controller.rb +5 -1
  71. data/spec/clearance/back_door_spec.rb +70 -6
  72. data/spec/clearance/session_spec.rb +4 -16
  73. data/spec/clearance/testing/controller_helpers_spec.rb +38 -0
  74. data/spec/clearance/testing/view_helpers_spec.rb +37 -0
  75. data/spec/configuration_spec.rb +79 -86
  76. data/spec/controllers/apis_controller_spec.rb +6 -2
  77. data/spec/controllers/forgeries_controller_spec.rb +12 -3
  78. data/spec/controllers/passwords_controller_spec.rb +74 -38
  79. data/spec/controllers/permissions_controller_spec.rb +13 -3
  80. data/spec/controllers/sessions_controller_spec.rb +40 -11
  81. data/spec/controllers/users_controller_spec.rb +16 -8
  82. data/spec/dummy/app/controllers/application_controller.rb +5 -1
  83. data/spec/dummy/application.rb +9 -11
  84. data/spec/factories.rb +5 -5
  85. data/spec/generators/clearance/install/install_generator_spec.rb +29 -3
  86. data/spec/generators/clearance/routes/routes_generator_spec.rb +5 -1
  87. data/spec/helpers/helper_helpers_spec.rb +10 -0
  88. data/spec/{user_spec.rb → models/user_spec.rb} +10 -1
  89. data/spec/password_strategies/blowfish_spec.rb +1 -1
  90. data/spec/requests/cookie_options_spec.rb +52 -0
  91. data/spec/requests/csrf_rotation_spec.rb +35 -0
  92. data/spec/requests/password_maintenance_spec.rb +18 -0
  93. data/spec/requests/token_expiration_spec.rb +54 -0
  94. data/spec/spec_helper.rb +22 -4
  95. data/spec/support/environment.rb +12 -0
  96. data/spec/support/generator_spec_helpers.rb +13 -1
  97. data/spec/support/http_method_shim.rb +25 -0
  98. data/spec/support/request_with_remember_token.rb +5 -0
  99. data/spec/views/view_helpers_spec.rb +10 -0
  100. metadata +69 -15
  101. data/gemfiles/rails3.2.gemfile +0 -18
  102. data/gemfiles/rails4.0.gemfile +0 -19
  103. data/gemfiles/rails4.1.gemfile +0 -18
  104. data/gemfiles/rails4.2.gemfile +0 -18
  105. data/lib/generators/clearance/install/templates/user.rb +0 -3
  106. data/spec/clearance/testing/helpers_spec.rb +0 -38
@@ -10,6 +10,7 @@ describe "Clearance Installation" do
10
10
 
11
11
  it "can successfully run specs" do
12
12
  app_name = "testapp"
13
+
13
14
  generate_test_app(app_name)
14
15
 
15
16
  Dir.chdir(app_name) do
@@ -22,13 +23,19 @@ describe "Clearance Installation" do
22
23
  end
23
24
 
24
25
  def generate_test_app(app_name)
25
- successfully "bundle exec rails new #{app_name} \
26
- --skip-gemfile \
27
- --skip-bundle \
28
- --skip-git \
29
- --skip-javascript \
30
- --skip-sprockets \
31
- --skip-keeps"
26
+ successfully <<-CMD.squish
27
+ bundle exec rails new #{app_name}
28
+ --no-rc
29
+ --skip-action-cable
30
+ --skip-active-storage
31
+ --skip-bootsnap
32
+ --skip-bundle
33
+ --skip-gemfile
34
+ --skip-git
35
+ --skip-javascript
36
+ --skip-keeps
37
+ --skip-sprockets
38
+ CMD
32
39
 
33
40
  FileUtils.rm_f("public/index.html")
34
41
  FileUtils.rm_f("app/views/layouts/application.html.erb")
@@ -70,6 +77,7 @@ describe "Clearance Installation" do
70
77
  end
71
78
 
72
79
  return_value = system("#{command} #{silencer}")
80
+
73
81
  expect(return_value).to eq true
74
82
  end
75
83
  end
@@ -0,0 +1,5 @@
1
+ class User < ApplicationRecord
2
+ def previously_existed?
3
+ true
4
+ end
5
+ end
@@ -0,0 +1,2 @@
1
+ Clearance.configure do |config|
2
+ end
@@ -2,6 +2,6 @@ gem "rails"
2
2
  gem "sqlite3"
3
3
  gem "rspec-rails"
4
4
  gem "capybara"
5
- gem "factory_girl_rails"
5
+ gem "factory_bot_rails"
6
6
  gem "database_cleaner"
7
7
  gem "clearance", path: "../.."
@@ -1,5 +1,9 @@
1
1
  class HomeController < ApplicationController
2
2
  def show
3
- render text: "", layout: "application"
3
+ if Rails::VERSION::MAJOR >= 5
4
+ render html: "", layout: "application"
5
+ else
6
+ render text: "", layout: "application"
7
+ end
4
8
  end
5
9
  end
@@ -1,8 +1,11 @@
1
- require 'spec_helper'
1
+ require "spec_helper"
2
+ require "support/environment"
2
3
 
3
4
  describe Clearance::BackDoor do
4
- it 'signs in as a given user' do
5
- user_id = '123'
5
+ include EnvironmentSupport
6
+
7
+ it "signs in as a given user" do
8
+ user_id = "123"
6
9
  user = double("user")
7
10
  allow(User).to receive(:find).with(user_id).and_return(user)
8
11
  env = env_for_user_id(user_id)
@@ -14,7 +17,7 @@ describe Clearance::BackDoor do
14
17
  expect(result).to eq mock_app.call(env)
15
18
  end
16
19
 
17
- it 'delegates directly without a user' do
20
+ it "delegates directly without a user" do
18
21
  env = env_without_user_id
19
22
  back_door = Clearance::BackDoor.new(mock_app)
20
23
 
@@ -24,8 +27,64 @@ describe Clearance::BackDoor do
24
27
  expect(result).to eq mock_app.call(env)
25
28
  end
26
29
 
30
+ it "can set the user via a block" do
31
+ env = env_for_username("foo")
32
+ user = double("user")
33
+ allow(User).to receive(:find_by).with(username: "foo").and_return(user)
34
+ back_door = Clearance::BackDoor.new(mock_app) do |username|
35
+ User.find_by(username: username)
36
+ end
37
+
38
+ result = back_door.call(env)
39
+
40
+ expect(env[:clearance]).to have_received(:sign_in).with(user)
41
+ expect(result).to eq mock_app.call(env)
42
+ end
43
+
44
+ it "can't be used outside the allowed environments" do
45
+ with_environment("RAILS_ENV" => "production") do
46
+ expect { Clearance::BackDoor.new(mock_app) }.
47
+ to raise_exception "Can't use auth backdoor outside of configured \
48
+ environments (test, ci, development).".squish
49
+ end
50
+ end
51
+
52
+ context "when the environments are disabled" do
53
+ before do
54
+ Clearance.configuration.allowed_backdoor_environments = nil
55
+ end
56
+
57
+ it "raises an error for a default allowed env" do
58
+ with_environment("RAILS_ENV" => "test") do
59
+ expect { Clearance::BackDoor.new(mock_app) }.
60
+ to raise_exception "BackDoor auth is disabled."
61
+ end
62
+ end
63
+ end
64
+
65
+ context "when the environments are not defaults" do
66
+ before do
67
+ Clearance.configuration.allowed_backdoor_environments = ['demo']
68
+ end
69
+
70
+ it "can be used with configured allowed environments" do
71
+ with_environment("RAILS_ENV" => "demo") do
72
+ user_id = "123"
73
+ user = double("user")
74
+ allow(User).to receive(:find).with(user_id).and_return(user)
75
+ env = env_for_user_id(user_id)
76
+ back_door = Clearance::BackDoor.new(mock_app)
77
+
78
+ result = back_door.call(env)
79
+
80
+ expect(env[:clearance]).to have_received(:sign_in).with(user)
81
+ expect(result).to eq mock_app.call(env)
82
+ end
83
+ end
84
+ end
85
+
27
86
  def env_without_user_id
28
- env_for_user_id('')
87
+ env_for_user_id("")
29
88
  end
30
89
 
31
90
  def env_for_user_id(user_id)
@@ -33,7 +92,12 @@ describe Clearance::BackDoor do
33
92
  Rack::MockRequest.env_for("/?as=#{user_id}").merge(clearance: clearance)
34
93
  end
35
94
 
95
+ def env_for_username(username)
96
+ clearance = double("clearance", sign_in: true)
97
+ Rack::MockRequest.env_for("/?as=#{username}").merge(clearance: clearance)
98
+ end
99
+
36
100
  def mock_app
37
- lambda { |env| [200, {}, ['okay']] }
101
+ lambda { |env| [200, {}, ["okay"]] }
38
102
  end
39
103
  end
@@ -32,15 +32,13 @@ describe Clearance::Session do
32
32
 
33
33
  context "with a custom cookie name" do
34
34
  it "sets a custom cookie name in the header" do
35
- Clearance.configuration.cookie_domain = "custom_token"
35
+ Clearance.configuration.cookie_name = "custom_cookie_name"
36
36
 
37
37
  session.sign_in user
38
38
  session.add_cookie_to_headers(headers)
39
39
 
40
- expect(headers["Set-Cookie"]).to match(/custom_token/)
40
+ expect(headers["Set-Cookie"]).to match(/custom_cookie_name=.+;/)
41
41
  end
42
-
43
- after { restore_default_config }
44
42
  end
45
43
 
46
44
  describe '#sign_in' do
@@ -113,7 +111,6 @@ describe Clearance::Session do
113
111
  expect(session.current_user).to be_nil
114
112
  end
115
113
 
116
-
117
114
  def stub_sign_in_guard(options)
118
115
  session_status = stub_status(options.fetch(:succeed))
119
116
 
@@ -150,7 +147,6 @@ describe Clearance::Session do
150
147
 
151
148
  context 'if httponly is set' do
152
149
  before do
153
- Clearance.configuration.httponly = true
154
150
  session.sign_in(user)
155
151
  end
156
152
 
@@ -159,12 +155,11 @@ describe Clearance::Session do
159
155
 
160
156
  expect(headers['Set-Cookie']).to match(/remember_token=.+; HttpOnly/)
161
157
  end
162
-
163
- after { restore_default_config }
164
158
  end
165
159
 
166
160
  context 'if httponly is not set' do
167
161
  before do
162
+ Clearance.configuration.httponly = false
168
163
  session.sign_in(user)
169
164
  end
170
165
 
@@ -196,6 +191,7 @@ describe Clearance::Session do
196
191
  expiration = -> { Time.now }
197
192
  with_custom_expiration expiration do
198
193
  session = Clearance::Session.new(env_without_remember_token)
194
+ session.sign_in user
199
195
  allow(session).to receive(:warn)
200
196
  session.add_cookie_to_headers headers
201
197
 
@@ -270,8 +266,6 @@ describe Clearance::Session do
270
266
 
271
267
  expect(headers['Set-Cookie']).to match(/remember_token=.+; secure/)
272
268
  end
273
-
274
- after { restore_default_config }
275
269
  end
276
270
  end
277
271
 
@@ -287,8 +281,6 @@ describe Clearance::Session do
287
281
 
288
282
  expect(headers['Set-Cookie']).to match(/domain=\.example\.com; path/)
289
283
  end
290
-
291
- after { restore_default_config }
292
284
  end
293
285
 
294
286
  context 'when not set' do
@@ -324,8 +316,6 @@ describe Clearance::Session do
324
316
 
325
317
  expect(headers['Set-Cookie']).to match(/path=\/user; expires/)
326
318
  end
327
-
328
- after { restore_default_config }
329
319
  end
330
320
  end
331
321
 
@@ -375,7 +365,5 @@ describe Clearance::Session do
375
365
  def with_custom_expiration(custom_duration)
376
366
  Clearance.configuration.cookie_expiration = custom_duration
377
367
  yield
378
- ensure
379
- restore_default_config
380
368
  end
381
369
  end
@@ -0,0 +1,38 @@
1
+ require "spec_helper"
2
+
3
+ describe Clearance::Testing::ControllerHelpers do
4
+ class TestClass
5
+ include Clearance::Testing::ControllerHelpers
6
+
7
+ def initialize
8
+ @request = Class.new do
9
+ def env
10
+ { clearance: Clearance::Session.new({}) }
11
+ end
12
+ end.new
13
+ end
14
+ end
15
+
16
+ describe "#sign_in" do
17
+ it "creates an instance of the clearance user model with FactoryBot" do
18
+ MyUserModel = Class.new
19
+ allow(FactoryBot).to receive(:create)
20
+ allow(Clearance.configuration).to receive(:user_model).
21
+ and_return(MyUserModel)
22
+
23
+ TestClass.new.sign_in
24
+
25
+ expect(FactoryBot).to have_received(:create).with(:my_user_model)
26
+ end
27
+ end
28
+
29
+ describe "#sign_in_as" do
30
+ it "returns the user if signed in successfully" do
31
+ user = build(:user)
32
+
33
+ returned_user = TestClass.new.sign_in_as user
34
+
35
+ expect(returned_user).to eq user
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,37 @@
1
+ require "spec_helper"
2
+
3
+ describe Clearance::Testing::ViewHelpers do
4
+ describe "#sign_in" do
5
+ it "sets the signed in user to a new user object" do
6
+ user_model = Class.new
7
+ allow(Clearance.configuration).to receive(:user_model).
8
+ and_return(user_model)
9
+
10
+ view = test_view_class.new
11
+ view.sign_in
12
+
13
+ expect(view.current_user).to be_an_instance_of(user_model)
14
+ end
15
+ end
16
+
17
+ describe "#sign_in_as" do
18
+ it "sets the signed in user to the object provided" do
19
+ user = double("User")
20
+
21
+ view = test_view_class.new
22
+ view.sign_in_as(user)
23
+
24
+ expect(view.current_user).to eq user
25
+ end
26
+ end
27
+
28
+ def test_view_class
29
+ Class.new do
30
+ include Clearance::Testing::ViewHelpers
31
+
32
+ def view
33
+ @view ||= extend Clearance::Testing::ViewHelpers::CurrentUser
34
+ end
35
+ end
36
+ end
37
+ end
@@ -1,150 +1,117 @@
1
- require 'spec_helper'
1
+ require "spec_helper"
2
2
 
3
3
  describe Clearance::Configuration do
4
- after { restore_default_config }
5
-
6
- context 'when no user_model_name is specified' do
7
- before do
8
- Clearance.configure do |config|
9
- end
10
- end
11
-
12
- it 'defaults to User' do
4
+ context "when no user_model_name is specified" do
5
+ it "defaults to User" do
13
6
  expect(Clearance.configuration.user_model).to eq ::User
14
7
  end
15
8
  end
16
9
 
17
- context 'when a custom user_model_name is specified' do
18
- before do
10
+ context "when a custom user_model_name is specified" do
11
+ it "is used instead of User" do
19
12
  MyUser = Class.new
13
+ Clearance.configure { |config| config.user_model = MyUser }
20
14
 
21
- Clearance.configure do |config|
22
- config.user_model = MyUser
23
- end
24
- end
25
-
26
- it 'is used instead of User' do
27
15
  expect(Clearance.configuration.user_model).to eq ::MyUser
28
16
  end
29
17
  end
30
18
 
31
- context 'when secure_cookie is set to true' do
32
- before do
33
- Clearance.configure do |config|
34
- config.secure_cookie = true
35
- end
36
- end
37
-
38
- it 'returns true' do
19
+ context "when secure_cookie is set to true" do
20
+ it "returns true" do
21
+ Clearance.configure { |config| config.secure_cookie = true }
39
22
  expect(Clearance.configuration.secure_cookie).to eq true
40
23
  end
41
24
  end
42
25
 
43
- context 'when secure_cookie is not specified' do
44
- before do
45
- Clearance.configure do |config|
46
- end
47
- end
48
-
49
- it 'defaults to false' do
26
+ context "when secure_cookie is not specified" do
27
+ it "defaults to false" do
50
28
  expect(Clearance.configuration.secure_cookie).to eq false
51
29
  end
52
30
  end
53
31
 
54
- context 'when no redirect URL specified' do
32
+ context "when no redirect URL specified" do
55
33
  it 'returns "/" as redirect URL' do
56
- expect(Clearance::Configuration.new.redirect_url).to eq '/'
34
+ expect(Clearance::Configuration.new.redirect_url).to eq "/"
57
35
  end
58
36
  end
59
37
 
60
- context 'when redirect URL is specified' do
61
- let(:new_redirect_url) { '/admin' }
62
-
63
- before do
64
- Clearance.configure do |config|
65
- config.redirect_url = new_redirect_url
66
- end
67
- end
38
+ context "when redirect URL is specified" do
39
+ it "returns new redirect URL" do
40
+ new_redirect_url = "/admin"
41
+ Clearance.configure { |config| config.redirect_url = new_redirect_url }
68
42
 
69
- it 'returns new redirect URL' do
70
43
  expect(Clearance.configuration.redirect_url).to eq new_redirect_url
71
44
  end
72
45
  end
73
46
 
74
- context 'when specifying sign in guards' do
75
- DummyGuard = Class.new
47
+ context "when specifying sign in guards" do
48
+ it "returns the stack with added guards" do
49
+ DummyGuard = Class.new
50
+ Clearance.configure { |config| config.sign_in_guards = [DummyGuard] }
76
51
 
77
- before do
78
- Clearance.configure do |config|
79
- config.sign_in_guards = [DummyGuard]
80
- end
81
- end
82
-
83
- it 'returns the stack with added guards' do
84
52
  expect(Clearance.configuration.sign_in_guards).to eq [DummyGuard]
85
53
  end
86
54
  end
87
55
 
88
- context 'when cookie domain is specified' do
89
- let(:domain) { '.example.com' }
90
-
91
- before do
92
- Clearance.configure do |config|
93
- config.cookie_domain = domain
94
- end
95
- end
56
+ context "when cookie domain is specified" do
57
+ it "returns configured value" do
58
+ domain = ".example.com"
59
+ Clearance.configure { |config| config.cookie_domain = domain }
96
60
 
97
- it 'returns configured value' do
98
61
  expect(Clearance.configuration.cookie_domain).to eq domain
99
62
  end
100
63
  end
101
64
 
102
- context 'when cookie path is specified' do
103
- let(:path) { '/user' }
104
-
105
- before do
106
- Clearance.configure do |config|
107
- config.cookie_path = path
108
- end
109
- end
65
+ context "when cookie path is specified" do
66
+ it "returns configured value" do
67
+ path = "/user"
68
+ Clearance.configure { |config| config.cookie_path = path }
110
69
 
111
- it 'returns configured value' do
112
70
  expect(Clearance.configuration.cookie_path).to eq path
113
71
  end
114
72
  end
115
73
 
116
- describe '#allow_sign_up?' do
117
- context 'when allow_sign_up is configured to false' do
118
- it 'returns false' do
74
+ describe "#allow_sign_up?" do
75
+ context "when allow_sign_up is configured to false" do
76
+ it "returns false" do
119
77
  Clearance.configure { |config| config.allow_sign_up = false }
120
78
  expect(Clearance.configuration.allow_sign_up?).to eq false
121
79
  end
122
80
  end
123
81
 
124
- context 'when allow_sign_up has not been configured' do
125
- it 'returns true' do
82
+ context "when allow_sign_up has not been configured" do
83
+ it "returns true" do
126
84
  expect(Clearance.configuration.allow_sign_up?).to eq true
127
85
  end
128
86
  end
129
87
  end
130
88
 
131
- describe '#user_actions' do
132
- context 'when allow_sign_up is configured to false' do
133
- it 'returns empty array' do
89
+ describe "#user_actions" do
90
+ context "when allow_sign_up is configured to false" do
91
+ it "returns empty array" do
134
92
  Clearance.configure { |config| config.allow_sign_up = false }
135
93
  expect(Clearance.configuration.user_actions).to eq []
136
94
  end
137
95
  end
138
96
 
139
- context 'when sign_up has not been configured' do
140
- it 'returns create' do
97
+ context "when sign_up has not been configured" do
98
+ it "returns create" do
141
99
  expect(Clearance.configuration.user_actions).to eq [:create]
142
100
  end
143
101
  end
144
102
  end
145
103
 
146
- describe '#user_id_parameter' do
147
- it 'returns the parameter key to use based on the user_model' do
104
+ describe "#user_parameter" do
105
+ it "returns the parameter key to use based on the user_model" do
106
+ Account = Class.new(ActiveRecord::Base)
107
+ Clearance.configure { |config| config.user_model = Account }
108
+
109
+ expect(Clearance.configuration.user_parameter).to eq :account
110
+ end
111
+ end
112
+
113
+ describe "#user_id_parameter" do
114
+ it "returns the parameter key to use based on the user_model" do
148
115
  CustomUser = Class.new(ActiveRecord::Base)
149
116
  Clearance.configure { |config| config.user_model = CustomUser }
150
117
 
@@ -152,12 +119,12 @@ describe Clearance::Configuration do
152
119
  end
153
120
  end
154
121
 
155
- describe '#routes_enabled?' do
156
- it 'is true by default' do
122
+ describe "#routes_enabled?" do
123
+ it "is true by default" do
157
124
  expect(Clearance.configuration.routes_enabled?).to be true
158
125
  end
159
126
 
160
- it 'is false when routes are set to false' do
127
+ it "is false when routes are set to false" do
161
128
  Clearance.configure { |config| config.routes = false }
162
129
  expect(Clearance.configuration.routes_enabled?).to be false
163
130
  end
@@ -177,4 +144,30 @@ describe Clearance::Configuration do
177
144
  expect(Clearance.configuration.reload_user_model).to be_nil
178
145
  end
179
146
  end
147
+
148
+ describe "#rotate_csrf_on_sign_in?" do
149
+ it "defaults to falsey and warns" do
150
+ Clearance.configuration = Clearance::Configuration.new
151
+ allow(Clearance.configuration).to receive(:warn)
152
+
153
+ expect(Clearance.configuration.rotate_csrf_on_sign_in?).to be_falsey
154
+ expect(Clearance.configuration).to have_received(:warn)
155
+ end
156
+
157
+ it "is true and does not warn when `rotate_csrf_on_sign_in` is true" do
158
+ Clearance.configure { |config| config.rotate_csrf_on_sign_in = true }
159
+ allow(Clearance.configuration).to receive(:warn)
160
+
161
+ expect(Clearance.configuration.rotate_csrf_on_sign_in?).to be true
162
+ expect(Clearance.configuration).not_to have_received(:warn)
163
+ end
164
+
165
+ it "is false and does not warn when `rotate_csrf_on_sign_in` is false" do
166
+ Clearance.configure { |config| config.rotate_csrf_on_sign_in = false }
167
+ allow(Clearance.configuration).to receive(:warn)
168
+
169
+ expect(Clearance.configuration.rotate_csrf_on_sign_in?).to be false
170
+ expect(Clearance.configuration).not_to have_received(:warn)
171
+ end
172
+ end
180
173
  end
@@ -3,10 +3,14 @@ require 'spec_helper'
3
3
  class ApisController < ActionController::Base
4
4
  include Clearance::Controller
5
5
 
6
- before_filter :require_login
6
+ if respond_to?(:before_action)
7
+ before_action :require_login
8
+ else
9
+ before_filter :require_login
10
+ end
7
11
 
8
12
  def show
9
- render text: 'response'
13
+ head :ok
10
14
  end
11
15
  end
12
16
 
@@ -4,7 +4,12 @@ class ForgeriesController < ActionController::Base
4
4
  include Clearance::Controller
5
5
 
6
6
  protect_from_forgery
7
- before_filter :require_login
7
+
8
+ if respond_to?(:before_action)
9
+ before_action :require_login
10
+ else
11
+ before_filter :require_login
12
+ end
8
13
 
9
14
  # This is off in test by default, but we need it for this test
10
15
  self.allow_forgery_protection = true
@@ -33,12 +38,16 @@ describe ForgeriesController do
33
38
 
34
39
  it 'succeeds with authentic token' do
35
40
  token = controller.send(:form_authenticity_token)
36
- post :create, authenticity_token: token
41
+ post :create, params: {
42
+ authenticity_token: token,
43
+ }
37
44
  expect(subject).to redirect_to(action: 'index')
38
45
  end
39
46
 
40
47
  it 'fails with invalid token' do
41
- post :create, authenticity_token: 'hax0r'
48
+ post :create, params: {
49
+ authenticity_token: "hax0r",
50
+ }
42
51
  expect(subject).to deny_access
43
52
  end
44
53