devise 1.1.9 → 1.2.rc
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of devise might be problematic. Click here for more details.
- data/CHANGELOG.rdoc +34 -26
- data/README.rdoc +134 -100
- data/app/controllers/devise/confirmations_controller.rb +1 -1
- data/app/controllers/devise/omniauth_callbacks_controller.rb +26 -0
- data/app/controllers/devise/passwords_controller.rb +1 -1
- data/app/controllers/devise/registrations_controller.rb +59 -6
- data/app/controllers/devise/sessions_controller.rb +3 -2
- data/app/controllers/devise/unlocks_controller.rb +1 -1
- data/app/helpers/devise_helper.rb +4 -2
- data/app/mailers/devise/mailer.rb +27 -10
- data/app/views/devise/confirmations/new.html.erb +1 -1
- data/app/views/devise/passwords/edit.html.erb +2 -2
- data/app/views/devise/passwords/new.html.erb +1 -1
- data/app/views/devise/registrations/edit.html.erb +1 -1
- data/app/views/devise/registrations/new.html.erb +1 -1
- data/app/views/devise/sessions/new.html.erb +1 -1
- data/app/views/devise/shared/_links.erb +6 -0
- data/app/views/devise/unlocks/new.html.erb +1 -1
- data/config/locales/en.yml +9 -2
- data/lib/devise.rb +116 -58
- data/lib/devise/controllers/helpers.rb +103 -107
- data/lib/devise/controllers/internal_helpers.rb +23 -7
- data/lib/devise/controllers/scoped_views.rb +4 -6
- data/lib/devise/controllers/url_helpers.rb +3 -5
- data/lib/devise/encryptors/base.rb +1 -1
- data/lib/devise/encryptors/restful_authentication_sha1.rb +4 -4
- data/lib/devise/failure_app.rb +29 -21
- data/lib/devise/hooks/forgetable.rb +2 -1
- data/lib/devise/hooks/rememberable.rb +11 -9
- data/lib/devise/mapping.rb +12 -5
- data/lib/devise/models.rb +0 -14
- data/lib/devise/models/authenticatable.rb +40 -30
- data/lib/devise/models/confirmable.rb +11 -15
- data/lib/devise/models/database_authenticatable.rb +23 -35
- data/lib/devise/models/encryptable.rb +65 -0
- data/lib/devise/models/lockable.rb +8 -7
- data/lib/devise/models/omniauthable.rb +23 -0
- data/lib/devise/models/recoverable.rb +5 -3
- data/lib/devise/models/registerable.rb +13 -0
- data/lib/devise/models/rememberable.rb +38 -30
- data/lib/devise/models/timeoutable.rb +20 -3
- data/lib/devise/models/token_authenticatable.rb +19 -7
- data/lib/devise/models/validatable.rb +16 -4
- data/lib/devise/modules.rb +15 -8
- data/lib/devise/omniauth.rb +47 -0
- data/lib/devise/omniauth/config.rb +30 -0
- data/lib/devise/omniauth/test_helpers.rb +57 -0
- data/lib/devise/omniauth/url_helpers.rb +29 -0
- data/lib/devise/orm/active_record.rb +2 -0
- data/lib/devise/orm/mongoid.rb +4 -2
- data/lib/devise/rails.rb +26 -46
- data/lib/devise/rails/routes.rb +64 -20
- data/lib/devise/rails/warden_compat.rb +18 -20
- data/lib/devise/schema.rb +13 -14
- data/lib/devise/strategies/authenticatable.rb +33 -7
- data/lib/devise/strategies/database_authenticatable.rb +1 -1
- data/lib/devise/strategies/rememberable.rb +1 -1
- data/lib/devise/strategies/token_authenticatable.rb +6 -2
- data/lib/devise/test_helpers.rb +11 -1
- data/lib/devise/version.rb +1 -1
- data/lib/generators/active_record/templates/migration.rb +1 -0
- data/lib/generators/devise/orm_helpers.rb +3 -2
- data/lib/generators/templates/devise.rb +70 -39
- data/test/controllers/helpers_test.rb +43 -67
- data/test/controllers/internal_helpers_test.rb +29 -8
- data/test/controllers/url_helpers_test.rb +2 -1
- data/test/failure_app_test.rb +56 -21
- data/test/generators/generators_test_helper.rb +4 -0
- data/test/generators/install_generator_test.rb +14 -0
- data/test/generators/views_generator_test.rb +37 -0
- data/test/integration/authenticatable_test.rb +147 -62
- data/test/integration/database_authenticatable_test.rb +22 -0
- data/test/integration/http_authenticatable_test.rb +12 -2
- data/test/integration/omniauthable_test.rb +107 -0
- data/test/integration/recoverable_test.rb +39 -20
- data/test/integration/registerable_test.rb +30 -4
- data/test/integration/rememberable_test.rb +57 -34
- data/test/integration/timeoutable_test.rb +10 -1
- data/test/integration/token_authenticatable_test.rb +12 -17
- data/test/mailers/confirmation_instructions_test.rb +4 -0
- data/test/mailers/reset_password_instructions_test.rb +4 -0
- data/test/mailers/unlock_instructions_test.rb +4 -0
- data/test/mapping_test.rb +37 -3
- data/test/models/confirmable_test.rb +3 -3
- data/test/models/database_authenticatable_test.rb +14 -71
- data/test/models/encryptable_test.rb +65 -0
- data/test/models/lockable_test.rb +17 -1
- data/test/models/recoverable_test.rb +17 -0
- data/test/models/rememberable_test.rb +186 -125
- data/test/models/token_authenticatable_test.rb +1 -13
- data/test/models_test.rb +5 -5
- data/test/omniauth/url_helpers_test.rb +47 -0
- data/test/rails_app/app/active_record/admin.rb +4 -1
- data/test/rails_app/app/active_record/user.rb +5 -4
- data/test/rails_app/app/controllers/{sessions_controller.rb → admins/sessions_controller.rb} +1 -1
- data/test/rails_app/app/controllers/home_controller.rb +9 -0
- data/test/rails_app/app/controllers/users/omniauth_callbacks_controller.rb +7 -0
- data/test/rails_app/app/mongoid/admin.rb +4 -1
- data/test/rails_app/app/mongoid/shim.rb +16 -3
- data/test/rails_app/app/mongoid/user.rb +5 -5
- data/test/rails_app/config/initializers/devise.rb +52 -28
- data/test/rails_app/config/routes.rb +14 -6
- data/test/rails_app/db/migrate/20100401102949_create_tables.rb +21 -17
- data/test/rails_app/db/schema.rb +17 -51
- data/test/rails_app/lib/shared_admin.rb +9 -0
- data/test/rails_app/lib/shared_user.rb +23 -0
- data/test/routes_test.rb +42 -9
- data/test/support/integration.rb +3 -3
- data/test/support/webrat/integrations/rails.rb +7 -0
- data/test/test_helper.rb +2 -0
- data/test/test_helpers_test.rb +29 -0
- metadata +60 -30
- data/Gemfile +0 -27
- data/Gemfile.lock +0 -115
- data/Rakefile +0 -55
- data/TODO +0 -3
- data/lib/devise/encryptors/bcrypt.rb +0 -19
- data/lib/generators/devise_install_generator.rb +0 -4
- data/lib/generators/devise_views_generator.rb +0 -4
- data/test/indifferent_hash.rb +0 -33
- data/test/support/test_silencer.rb +0 -5
@@ -22,16 +22,16 @@ class HelpersTest < ActionController::TestCase
|
|
22
22
|
end
|
23
23
|
|
24
24
|
test 'get resource instance variable from env' do
|
25
|
-
@controller.instance_variable_set(:@user,
|
26
|
-
assert_equal
|
25
|
+
@controller.instance_variable_set(:@user, user = User.new)
|
26
|
+
assert_equal user, @controller.resource
|
27
27
|
end
|
28
28
|
|
29
29
|
test 'set resource instance variable from env' do
|
30
|
-
|
31
|
-
@controller.send(:resource=,
|
30
|
+
user = @controller.send(:resource_class).new
|
31
|
+
@controller.send(:resource=, user)
|
32
32
|
|
33
|
-
assert_equal
|
34
|
-
assert_equal
|
33
|
+
assert_equal user, @controller.send(:resource)
|
34
|
+
assert_equal user, @controller.instance_variable_get(:@user)
|
35
35
|
end
|
36
36
|
|
37
37
|
test 'resources methods are not controller actions' do
|
@@ -39,13 +39,34 @@ class HelpersTest < ActionController::TestCase
|
|
39
39
|
end
|
40
40
|
|
41
41
|
test 'require no authentication tests current mapping' do
|
42
|
-
@controller.expects(:resource_name).returns(:user).twice
|
43
42
|
@mock_warden.expects(:authenticated?).with(:user).returns(true)
|
43
|
+
@mock_warden.expects(:user).with(:user).returns(User.new)
|
44
44
|
@controller.expects(:redirect_to).with(root_path)
|
45
45
|
@controller.send :require_no_authentication
|
46
46
|
end
|
47
|
-
|
47
|
+
|
48
|
+
test 'signed in resource returns signed in resource for current scope' do
|
49
|
+
@mock_warden.expects(:authenticate).with(:scope => :user).returns(User.new)
|
50
|
+
assert_kind_of User, @controller.signed_in_resource
|
51
|
+
end
|
52
|
+
|
48
53
|
test 'is a devise controller' do
|
49
54
|
assert @controller.devise_controller?
|
50
55
|
end
|
56
|
+
|
57
|
+
test 'does not issue blank flash messages' do
|
58
|
+
MyController.send(:public, :set_flash_message)
|
59
|
+
I18n.stubs(:t).returns(' ')
|
60
|
+
@controller.set_flash_message :notice, :send_instructions
|
61
|
+
assert flash[:notice].nil?
|
62
|
+
MyController.send(:protected, :set_flash_message)
|
63
|
+
end
|
64
|
+
|
65
|
+
test 'issues non-blank flash messages normally' do
|
66
|
+
MyController.send(:public, :set_flash_message)
|
67
|
+
I18n.stubs(:t).returns('non-blank')
|
68
|
+
@controller.set_flash_message :notice, :send_instructions
|
69
|
+
assert flash[:notice] == 'non-blank'
|
70
|
+
MyController.send(:protected, :set_flash_message)
|
71
|
+
end
|
51
72
|
end
|
@@ -20,7 +20,7 @@ class RoutesTest < ActionController::TestCase
|
|
20
20
|
send(:"#{prepend_path}user_#{name}_url", :param => 123)
|
21
21
|
|
22
22
|
@request.path = nil
|
23
|
-
# With an
|
23
|
+
# With an object
|
24
24
|
assert_equal @controller.send(:"#{prepend_path}#{name}_path", User.new),
|
25
25
|
send(:"#{prepend_path}user_#{name}_path")
|
26
26
|
assert_equal @controller.send(:"#{prepend_path}#{name}_url", User.new),
|
@@ -54,5 +54,6 @@ class RoutesTest < ActionController::TestCase
|
|
54
54
|
assert_path_and_url :registration
|
55
55
|
assert_path_and_url :registration, :new
|
56
56
|
assert_path_and_url :registration, :edit
|
57
|
+
assert_path_and_url :registration, :cancel
|
57
58
|
end
|
58
59
|
end
|
data/test/failure_app_test.rb
CHANGED
@@ -13,11 +13,11 @@ class FailureTest < ActiveSupport::TestCase
|
|
13
13
|
'REQUEST_METHOD' => 'GET',
|
14
14
|
'warden.options' => { :scope => :user },
|
15
15
|
'rack.session' => {},
|
16
|
-
'action_dispatch.request.formats' => Array(env_params.delete('formats') ||
|
16
|
+
'action_dispatch.request.formats' => Array(env_params.delete('formats') || :html),
|
17
17
|
'rack.input' => "",
|
18
18
|
'warden' => OpenStruct.new(:message => nil)
|
19
19
|
}.merge!(env_params)
|
20
|
-
|
20
|
+
|
21
21
|
@response = Devise::FailureApp.call(env).to_a
|
22
22
|
@request = ActionDispatch::Request.new(env)
|
23
23
|
end
|
@@ -28,6 +28,11 @@ class FailureTest < ActiveSupport::TestCase
|
|
28
28
|
assert_equal 302, @response.first
|
29
29
|
end
|
30
30
|
|
31
|
+
test 'return 302 status for wildcard requests' do
|
32
|
+
call_failure 'action_dispatch.request.formats' => nil, 'HTTP_ACCEPT' => '*/*'
|
33
|
+
assert_equal 302, @response.first
|
34
|
+
end
|
35
|
+
|
31
36
|
test 'return to the default redirect location' do
|
32
37
|
call_failure
|
33
38
|
assert_equal 'You need to sign in or sign up before continuing.', @request.flash[:alert]
|
@@ -72,37 +77,68 @@ class FailureTest < ActiveSupport::TestCase
|
|
72
77
|
assert_equal 401, @response.first
|
73
78
|
end
|
74
79
|
|
75
|
-
test 'return
|
80
|
+
test 'return 401 status for unknown formats' do
|
81
|
+
call_failure 'formats' => []
|
82
|
+
assert_equal 401, @response.first
|
83
|
+
end
|
84
|
+
|
85
|
+
test 'return WWW-authenticate headers if model allows' do
|
76
86
|
call_failure('formats' => :xml)
|
77
87
|
assert_equal 'Basic realm="Application"', @response.second["WWW-Authenticate"]
|
78
88
|
end
|
79
89
|
|
80
|
-
test '
|
81
|
-
swap Devise, :
|
82
|
-
call_failure('formats' => :
|
83
|
-
|
84
|
-
assert_equal 'http://test.host/users/sign_in', @response.second["Location"]
|
85
|
-
assert_nil @response.second['WWW-Authenticate']
|
90
|
+
test 'does not return WWW-authenticate headers if model does not allow' do
|
91
|
+
swap Devise, :http_authenticatable => false do
|
92
|
+
call_failure('formats' => :xml)
|
93
|
+
assert_nil @response.second["WWW-Authenticate"]
|
86
94
|
end
|
87
95
|
end
|
88
96
|
|
89
|
-
test '
|
90
|
-
swap Devise, :
|
91
|
-
call_failure('formats' => :html
|
97
|
+
test 'works for any non navigational format' do
|
98
|
+
swap Devise, :navigational_formats => [] do
|
99
|
+
call_failure('formats' => :html)
|
92
100
|
assert_equal 401, @response.first
|
93
|
-
assert_equal 'Basic realm="Application"', @response.second["WWW-Authenticate"]
|
94
101
|
end
|
95
102
|
end
|
96
|
-
|
97
|
-
test 'uses the
|
103
|
+
|
104
|
+
test 'uses the failure message as response body' do
|
98
105
|
call_failure('formats' => :xml, 'warden' => OpenStruct.new(:message => :invalid))
|
99
106
|
assert_match '<error>Invalid email or password.</error>', @response.third.body
|
100
107
|
end
|
101
108
|
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
109
|
+
context 'on ajax call' do
|
110
|
+
context 'when http_authenticatable_on_xhr is false' do
|
111
|
+
test 'dont return 401 with navigational formats' do
|
112
|
+
swap Devise, :http_authenticatable_on_xhr => false do
|
113
|
+
call_failure('formats' => :html, 'HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest')
|
114
|
+
assert_equal 302, @response.first
|
115
|
+
assert_equal 'http://test.host/users/sign_in', @response.second["Location"]
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
test 'dont return 401 with non navigational formats' do
|
120
|
+
swap Devise, :http_authenticatable_on_xhr => false do
|
121
|
+
call_failure('formats' => :json, 'HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest')
|
122
|
+
assert_equal 302, @response.first
|
123
|
+
assert_equal 'http://test.host/users/sign_in', @response.second["Location"]
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
context 'when http_authenticatable_on_xhr is true' do
|
129
|
+
test 'return 401' do
|
130
|
+
swap Devise, :http_authenticatable_on_xhr => true do
|
131
|
+
call_failure('formats' => :html, 'HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest')
|
132
|
+
assert_equal 401, @response.first
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
test 'skip WWW-Authenticate header' do
|
137
|
+
swap Devise, :http_authenticatable_on_xhr => true do
|
138
|
+
call_failure('formats' => :html, 'HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest')
|
139
|
+
assert_nil @response.second['WWW-Authenticate']
|
140
|
+
end
|
141
|
+
end
|
106
142
|
end
|
107
143
|
end
|
108
144
|
end
|
@@ -110,8 +146,7 @@ class FailureTest < ActiveSupport::TestCase
|
|
110
146
|
context 'With recall' do
|
111
147
|
test 'calls the original controller' do
|
112
148
|
env = {
|
113
|
-
"
|
114
|
-
"warden.options" => { :recall => "new", :attempted_path => "/users/sign_in" },
|
149
|
+
"warden.options" => { :recall => "devise/sessions#new", :attempted_path => "/users/sign_in" },
|
115
150
|
"devise.mapping" => Devise.mappings[:user],
|
116
151
|
"warden" => stub_everything
|
117
152
|
}
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__),"generators_test_helper.rb")
|
2
|
+
|
3
|
+
class InstallGeneratorTest < Rails::Generators::TestCase
|
4
|
+
tests Devise::Generators::InstallGenerator
|
5
|
+
destination File.expand_path("../tmp", File.dirname(__FILE__))
|
6
|
+
setup :prepare_destination
|
7
|
+
|
8
|
+
test "Assert all files are properly created" do
|
9
|
+
run_generator
|
10
|
+
assert_file "config/initializers/devise.rb"
|
11
|
+
assert_file "config/locales/devise.en.yml"
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__),"generators_test_helper.rb")
|
2
|
+
|
3
|
+
class ViewsGeneratorTest < Rails::Generators::TestCase
|
4
|
+
tests Devise::Generators::ViewsGenerator
|
5
|
+
destination File.expand_path("../tmp", File.dirname(__FILE__))
|
6
|
+
setup :prepare_destination
|
7
|
+
|
8
|
+
test "Assert all views are properly created with no params" do
|
9
|
+
run_generator
|
10
|
+
assert_files
|
11
|
+
end
|
12
|
+
|
13
|
+
test "Assert all views are properly created with scope param param" do
|
14
|
+
run_generator %w(users)
|
15
|
+
assert_files "users"
|
16
|
+
|
17
|
+
run_generator %w(admins)
|
18
|
+
assert_files "admins"
|
19
|
+
end
|
20
|
+
|
21
|
+
def assert_files(scope = nil, template_engine = nil)
|
22
|
+
scope = "devise" if scope.nil?
|
23
|
+
assert_file "app/views/#{scope}/confirmations/new.html.erb"
|
24
|
+
assert_file "app/views/#{scope}/mailer/confirmation_instructions.html.erb"
|
25
|
+
assert_file "app/views/#{scope}/mailer/reset_password_instructions.html.erb"
|
26
|
+
assert_file "app/views/#{scope}/mailer/unlock_instructions.html.erb"
|
27
|
+
assert_file "app/views/#{scope}/passwords/edit.html.erb"
|
28
|
+
assert_file "app/views/#{scope}/passwords/new.html.erb"
|
29
|
+
assert_file "app/views/#{scope}/registrations/new.html.erb"
|
30
|
+
assert_file "app/views/#{scope}/registrations/edit.html.erb"
|
31
|
+
assert_file "app/views/#{scope}/sessions/new.html.erb"
|
32
|
+
assert_file "app/views/#{scope}/shared/_links.erb"
|
33
|
+
assert_file "app/views/#{scope}/unlocks/new.html.erb"
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
@@ -1,15 +1,6 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
3
|
class AuthenticationSanityTest < ActionController::IntegrationTest
|
4
|
-
|
5
|
-
def setup
|
6
|
-
Devise.sign_out_all_scopes = false
|
7
|
-
end
|
8
|
-
|
9
|
-
def teardown
|
10
|
-
Devise.sign_out_all_scopes = false
|
11
|
-
end
|
12
|
-
|
13
4
|
test 'home should be accessible without sign in' do
|
14
5
|
visit '/'
|
15
6
|
assert_response :success
|
@@ -18,14 +9,12 @@ class AuthenticationSanityTest < ActionController::IntegrationTest
|
|
18
9
|
|
19
10
|
test 'sign in as user should not authenticate admin scope' do
|
20
11
|
sign_in_as_user
|
21
|
-
|
22
12
|
assert warden.authenticated?(:user)
|
23
13
|
assert_not warden.authenticated?(:admin)
|
24
14
|
end
|
25
15
|
|
26
16
|
test 'sign in as admin should not authenticate user scope' do
|
27
17
|
sign_in_as_admin
|
28
|
-
|
29
18
|
assert warden.authenticated?(:admin)
|
30
19
|
assert_not warden.authenticated?(:user)
|
31
20
|
end
|
@@ -33,59 +22,61 @@ class AuthenticationSanityTest < ActionController::IntegrationTest
|
|
33
22
|
test 'sign in as both user and admin at same time' do
|
34
23
|
sign_in_as_user
|
35
24
|
sign_in_as_admin
|
36
|
-
|
37
25
|
assert warden.authenticated?(:user)
|
38
26
|
assert warden.authenticated?(:admin)
|
39
27
|
end
|
40
28
|
|
41
29
|
test 'sign out as user should not touch admin authentication if sign_out_all_scopes is false' do
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
30
|
+
swap Devise, :sign_out_all_scopes => false do
|
31
|
+
sign_in_as_user
|
32
|
+
sign_in_as_admin
|
33
|
+
get destroy_user_session_path
|
34
|
+
assert_not warden.authenticated?(:user)
|
35
|
+
assert warden.authenticated?(:admin)
|
36
|
+
end
|
48
37
|
end
|
49
38
|
|
50
39
|
test 'sign out as admin should not touch user authentication if sign_out_all_scopes is false' do
|
51
|
-
|
52
|
-
|
40
|
+
swap Devise, :sign_out_all_scopes => false do
|
41
|
+
sign_in_as_user
|
42
|
+
sign_in_as_admin
|
53
43
|
|
54
|
-
|
55
|
-
|
56
|
-
|
44
|
+
get destroy_admin_session_path
|
45
|
+
assert_not warden.authenticated?(:admin)
|
46
|
+
assert warden.authenticated?(:user)
|
47
|
+
end
|
57
48
|
end
|
58
49
|
|
59
50
|
test 'sign out as user should also sign out admin if sign_out_all_scopes is true' do
|
60
|
-
Devise
|
61
|
-
|
62
|
-
|
51
|
+
swap Devise, :sign_out_all_scopes => true do
|
52
|
+
sign_in_as_user
|
53
|
+
sign_in_as_admin
|
63
54
|
|
64
|
-
|
65
|
-
|
66
|
-
|
55
|
+
get destroy_user_session_path
|
56
|
+
assert_not warden.authenticated?(:user)
|
57
|
+
assert_not warden.authenticated?(:admin)
|
58
|
+
end
|
67
59
|
end
|
68
60
|
|
69
61
|
test 'sign out as admin should also sign out user if sign_out_all_scopes is true' do
|
70
|
-
Devise
|
71
|
-
|
72
|
-
|
62
|
+
swap Devise, :sign_out_all_scopes => true do
|
63
|
+
sign_in_as_user
|
64
|
+
sign_in_as_admin
|
73
65
|
|
74
|
-
|
75
|
-
|
76
|
-
|
66
|
+
get destroy_admin_session_path
|
67
|
+
assert_not warden.authenticated?(:admin)
|
68
|
+
assert_not warden.authenticated?(:user)
|
69
|
+
end
|
77
70
|
end
|
78
71
|
|
79
72
|
test 'not signed in as admin should not be able to access admins actions' do
|
80
73
|
get admins_path
|
81
|
-
|
82
74
|
assert_redirected_to new_admin_session_path
|
83
75
|
assert_not warden.authenticated?(:admin)
|
84
76
|
end
|
85
77
|
|
86
78
|
test 'not signed in as admin should not be able to access private route restricted to admins' do
|
87
79
|
get private_path
|
88
|
-
|
89
80
|
assert_redirected_to new_admin_session_path
|
90
81
|
assert_not warden.authenticated?(:admin)
|
91
82
|
end
|
@@ -94,7 +85,6 @@ class AuthenticationSanityTest < ActionController::IntegrationTest
|
|
94
85
|
sign_in_as_user
|
95
86
|
assert warden.authenticated?(:user)
|
96
87
|
assert_not warden.authenticated?(:admin)
|
97
|
-
|
98
88
|
get private_path
|
99
89
|
assert_redirected_to new_admin_session_path
|
100
90
|
end
|
@@ -237,6 +227,25 @@ class AuthenticationSessionTest < ActionController::IntegrationTest
|
|
237
227
|
assert_equal "Cart", @controller.user_session[:cart]
|
238
228
|
end
|
239
229
|
|
230
|
+
test 'does not explode when invalid user class is stored in session' do
|
231
|
+
klass = User
|
232
|
+
paths = ActiveSupport::Dependencies.autoload_paths.dup
|
233
|
+
|
234
|
+
begin
|
235
|
+
sign_in_as_user
|
236
|
+
assert warden.authenticated?(:user)
|
237
|
+
|
238
|
+
Object.send :remove_const, :User
|
239
|
+
ActiveSupport::Dependencies.autoload_paths.clear
|
240
|
+
|
241
|
+
visit "/users"
|
242
|
+
assert_not warden.authenticated?(:user)
|
243
|
+
ensure
|
244
|
+
Object.const_set(:User, klass)
|
245
|
+
ActiveSupport::Dependencies.autoload_paths.replace(paths)
|
246
|
+
end
|
247
|
+
end
|
248
|
+
|
240
249
|
test 'session id is changed on sign in' do
|
241
250
|
get '/users'
|
242
251
|
session_id = request.session["session_id"]
|
@@ -288,25 +297,13 @@ class AuthenticationWithScopesTest < ActionController::IntegrationTest
|
|
288
297
|
end
|
289
298
|
end
|
290
299
|
end
|
291
|
-
|
292
|
-
test 'uses the mapping from router' do
|
293
|
-
sign_in_as_user :visit => "/as/sign_in"
|
294
|
-
assert warden.authenticated?(:user)
|
295
|
-
assert_not warden.authenticated?(:admin)
|
296
|
-
end
|
297
|
-
|
298
|
-
test 'uses the mapping from nested devise_for call' do
|
299
|
-
sign_in_as_user :visit => "/devise_for/sign_in"
|
300
|
-
assert warden.authenticated?(:user)
|
301
|
-
assert_not warden.authenticated?(:admin)
|
302
|
-
end
|
303
300
|
end
|
304
301
|
|
305
302
|
class AuthenticationOthersTest < ActionController::IntegrationTest
|
306
303
|
test 'uses the custom controller with the custom controller view' do
|
307
304
|
get '/admin_area/sign_in'
|
308
305
|
assert_contain 'Sign in'
|
309
|
-
assert_contain 'Welcome to "sessions" controller!'
|
306
|
+
assert_contain 'Welcome to "admins/sessions" controller!'
|
310
307
|
assert_contain 'Welcome to "sessions/new" view!'
|
311
308
|
end
|
312
309
|
|
@@ -315,6 +312,11 @@ class AuthenticationOthersTest < ActionController::IntegrationTest
|
|
315
312
|
assert_equal 404, response.status
|
316
313
|
end
|
317
314
|
|
315
|
+
test 'does not intercept Rails 401 responses' do
|
316
|
+
get '/unauthenticated'
|
317
|
+
assert_equal 401, response.status
|
318
|
+
end
|
319
|
+
|
318
320
|
test 'render 404 on roles without mapping' do
|
319
321
|
assert_raise AbstractController::ActionNotFound do
|
320
322
|
get '/sign_in'
|
@@ -328,28 +330,111 @@ class AuthenticationOthersTest < ActionController::IntegrationTest
|
|
328
330
|
end
|
329
331
|
end
|
330
332
|
|
331
|
-
test 'registration in xml format' do
|
333
|
+
test 'registration in xml format works when recognizing path' do
|
332
334
|
assert_nothing_raised do
|
333
335
|
post user_registration_path(:format => 'xml', :user => {:email => "test@example.com", :password => "invalid"} )
|
334
336
|
end
|
335
337
|
end
|
336
338
|
|
337
|
-
test '
|
338
|
-
|
339
|
-
|
339
|
+
test 'uses the mapping from router' do
|
340
|
+
sign_in_as_user :visit => "/as/sign_in"
|
341
|
+
assert warden.authenticated?(:user)
|
342
|
+
assert_not warden.authenticated?(:admin)
|
343
|
+
end
|
340
344
|
|
341
|
-
|
345
|
+
test 'uses the mapping from nested devise_for call' do
|
346
|
+
sign_in_as_user :visit => "/devise_for/sign_in"
|
347
|
+
assert warden.authenticated?(:user)
|
348
|
+
assert_not warden.authenticated?(:admin)
|
349
|
+
end
|
350
|
+
end
|
351
|
+
|
352
|
+
class AuthenticationRequestKeysTest < ActionController::IntegrationTest
|
353
|
+
test 'request keys are used on authentication' do
|
354
|
+
host! 'foo.bar.baz'
|
355
|
+
|
356
|
+
swap Devise, :request_keys => [:subdomain] do
|
357
|
+
User.expects(:find_for_authentication).with(:subdomain => 'foo', :email => 'user@test.com').returns(create_user)
|
342
358
|
sign_in_as_user
|
343
359
|
assert warden.authenticated?(:user)
|
360
|
+
end
|
361
|
+
end
|
344
362
|
|
345
|
-
|
346
|
-
|
363
|
+
test 'invalid request keys raises NoMethodError' do
|
364
|
+
swap Devise, :request_keys => [:unknown_method] do
|
365
|
+
assert_raise NoMethodError do
|
366
|
+
sign_in_as_user
|
367
|
+
end
|
347
368
|
|
348
|
-
visit "/users"
|
349
369
|
assert_not warden.authenticated?(:user)
|
350
|
-
ensure
|
351
|
-
Object.const_set(:User, klass)
|
352
|
-
ActiveSupport::Dependencies.autoload_paths.replace(paths)
|
353
370
|
end
|
354
371
|
end
|
372
|
+
|
373
|
+
test 'blank request keys cause authentication to abort' do
|
374
|
+
host! 'test.com'
|
375
|
+
|
376
|
+
swap Devise, :request_keys => [:subdomain] do
|
377
|
+
sign_in_as_user
|
378
|
+
assert_contain "Invalid email or password."
|
379
|
+
assert_not warden.authenticated?(:user)
|
380
|
+
end
|
381
|
+
end
|
382
|
+
|
383
|
+
test 'blank request keys cause authentication to abort unless if marked as not required' do
|
384
|
+
host! 'test.com'
|
385
|
+
|
386
|
+
swap Devise, :request_keys => { :subdomain => false } do
|
387
|
+
sign_in_as_user
|
388
|
+
assert warden.authenticated?(:user)
|
389
|
+
end
|
390
|
+
end
|
391
|
+
end
|
392
|
+
|
393
|
+
class AuthenticationSignOutViaTest < ActionController::IntegrationTest
|
394
|
+
def sign_in!(scope)
|
395
|
+
sign_in_as_admin(:visit => send("new_#{scope}_session_path"))
|
396
|
+
assert warden.authenticated?(scope)
|
397
|
+
end
|
398
|
+
|
399
|
+
test 'allow sign out via delete when sign_out_via provides only delete' do
|
400
|
+
sign_in!(:sign_out_via_delete)
|
401
|
+
delete destroy_sign_out_via_delete_session_path
|
402
|
+
assert_not warden.authenticated?(:sign_out_via_delete)
|
403
|
+
end
|
404
|
+
|
405
|
+
test 'do not allow sign out via get when sign_out_via provides only delete' do
|
406
|
+
sign_in!(:sign_out_via_delete)
|
407
|
+
get destroy_sign_out_via_delete_session_path
|
408
|
+
assert warden.authenticated?(:sign_out_via_delete)
|
409
|
+
end
|
410
|
+
|
411
|
+
test 'allow sign out via post when sign_out_via provides only post' do
|
412
|
+
sign_in!(:sign_out_via_post)
|
413
|
+
post destroy_sign_out_via_post_session_path
|
414
|
+
assert_not warden.authenticated?(:sign_out_via_post)
|
415
|
+
end
|
416
|
+
|
417
|
+
test 'do not allow sign out via get when sign_out_via provides only post' do
|
418
|
+
sign_in!(:sign_out_via_post)
|
419
|
+
get destroy_sign_out_via_delete_session_path
|
420
|
+
assert warden.authenticated?(:sign_out_via_post)
|
421
|
+
end
|
422
|
+
|
423
|
+
test 'allow sign out via delete when sign_out_via provides delete and post' do
|
424
|
+
sign_in!(:sign_out_via_delete_or_post)
|
425
|
+
delete destroy_sign_out_via_delete_or_post_session_path
|
426
|
+
assert_not warden.authenticated?(:sign_out_via_delete_or_post)
|
427
|
+
end
|
428
|
+
|
429
|
+
test 'allow sign out via post when sign_out_via provides delete and post' do
|
430
|
+
sign_in!(:sign_out_via_delete_or_post)
|
431
|
+
post destroy_sign_out_via_delete_or_post_session_path
|
432
|
+
assert_not warden.authenticated?(:sign_out_via_delete_or_post)
|
433
|
+
end
|
434
|
+
|
435
|
+
test 'do not allow sign out via get when sign_out_via provides delete and post' do
|
436
|
+
sign_in!(:sign_out_via_delete_or_post)
|
437
|
+
get destroy_sign_out_via_delete_or_post_session_path
|
438
|
+
assert warden.authenticated?(:sign_out_via_delete_or_post)
|
439
|
+
end
|
355
440
|
end
|