devise_ennder 1.0.1.0.9
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.rdoc +397 -0
- data/INSTALL +94 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +272 -0
- data/Rakefile +53 -0
- data/TODO +2 -0
- data/app/controllers/confirmations_controller.rb +33 -0
- data/app/controllers/passwords_controller.rb +41 -0
- data/app/controllers/registrations_controller.rb +62 -0
- data/app/controllers/sessions_controller.rb +42 -0
- data/app/controllers/unlocks_controller.rb +41 -0
- data/app/models/devise_mailer.rb +68 -0
- data/app/models/user.rb +9 -0
- data/app/views/confirmations/new.html.erb +14 -0
- data/app/views/devise_mailer/confirmation_instructions.html.erb +6 -0
- data/app/views/devise_mailer/reset_password_instructions.html.erb +8 -0
- data/app/views/devise_mailer/unlock_instructions.html.erb +7 -0
- data/app/views/passwords/edit.html.erb +16 -0
- data/app/views/passwords/new.html.erb +12 -0
- data/app/views/registrations/edit.html.erb +25 -0
- data/app/views/registrations/new.html.erb +17 -0
- data/app/views/sessions/new.html.erb +17 -0
- data/app/views/shared/_devise_links.erb +19 -0
- data/app/views/shared/_user_nav.html.erb +15 -0
- data/app/views/unlocks/new.html.erb +12 -0
- data/config/locales/devise.en.yml +62 -0
- data/config/locales/devise.fr.yml +60 -0
- data/config/locales/en.yml +6 -0
- data/config/locales/fr.yml +18 -0
- data/config/routes.rb +4 -0
- data/db/migrate/20100506013336_devise_create_users.rb +23 -0
- data/lib/devise/controllers/helpers.rb +212 -0
- data/lib/devise/controllers/internal_helpers.rb +129 -0
- data/lib/devise/controllers/url_helpers.rb +41 -0
- data/lib/devise/encryptors/authlogic_sha512.rb +21 -0
- data/lib/devise/encryptors/base.rb +20 -0
- data/lib/devise/encryptors/bcrypt.rb +21 -0
- data/lib/devise/encryptors/clearance_sha1.rb +19 -0
- data/lib/devise/encryptors/restful_authentication_sha1.rb +22 -0
- data/lib/devise/encryptors/sha1.rb +27 -0
- data/lib/devise/encryptors/sha512.rb +27 -0
- data/lib/devise/failure_app.rb +70 -0
- data/lib/devise/hooks/activatable.rb +15 -0
- data/lib/devise/hooks/rememberable.rb +33 -0
- data/lib/devise/hooks/timeoutable.rb +18 -0
- data/lib/devise/hooks/trackable.rb +18 -0
- data/lib/devise/locales/en.yml +35 -0
- data/lib/devise/mapping.rb +130 -0
- data/lib/devise/models/activatable.rb +16 -0
- data/lib/devise/models/confirmable.rb +167 -0
- data/lib/devise/models/database_authenticatable.rb +144 -0
- data/lib/devise/models/http_authenticatable.rb +23 -0
- data/lib/devise/models/lockable.rb +150 -0
- data/lib/devise/models/recoverable.rb +80 -0
- data/lib/devise/models/registerable.rb +8 -0
- data/lib/devise/models/rememberable.rb +92 -0
- data/lib/devise/models/timeoutable.rb +28 -0
- data/lib/devise/models/token_authenticatable.rb +89 -0
- data/lib/devise/models/trackable.rb +16 -0
- data/lib/devise/models/validatable.rb +39 -0
- data/lib/devise/models.rb +117 -0
- data/lib/devise/orm/active_record.rb +41 -0
- data/lib/devise/orm/data_mapper.rb +83 -0
- data/lib/devise/orm/mongo_mapper.rb +52 -0
- data/lib/devise/rails/routes.rb +133 -0
- data/lib/devise/rails/warden_compat.rb +60 -0
- data/lib/devise/rails.rb +14 -0
- data/lib/devise/schema.rb +73 -0
- data/lib/devise/strategies/base.rb +16 -0
- data/lib/devise/strategies/database_authenticatable.rb +36 -0
- data/lib/devise/strategies/http_authenticatable.rb +59 -0
- data/lib/devise/strategies/rememberable.rb +37 -0
- data/lib/devise/strategies/token_authenticatable.rb +37 -0
- data/lib/devise/test_helpers.rb +90 -0
- data/lib/devise/version.rb +3 -0
- data/lib/devise.rb +269 -0
- data/lib/devise_ennder.rb +3 -0
- data/lib/tasks/devise_ennder_tasks.rake +11 -0
- data/test/controllers/helpers_test.rb +184 -0
- data/test/controllers/internal_helpers_test.rb +55 -0
- data/test/controllers/url_helpers_test.rb +47 -0
- data/test/devise_test.rb +74 -0
- data/test/encryptors_test.rb +31 -0
- data/test/failure_app_test.rb +44 -0
- data/test/integration/authenticatable_test.rb +332 -0
- data/test/integration/confirmable_test.rb +97 -0
- data/test/integration/http_authenticatable_test.rb +52 -0
- data/test/integration/lockable_test.rb +102 -0
- data/test/integration/rack_middleware_test.rb +47 -0
- data/test/integration/recoverable_test.rb +141 -0
- data/test/integration/registerable_test.rb +144 -0
- data/test/integration/rememberable_test.rb +72 -0
- data/test/integration/timeoutable_test.rb +68 -0
- data/test/integration/token_authenticatable_test.rb +55 -0
- data/test/integration/trackable_test.rb +64 -0
- data/test/mailers/confirmation_instructions_test.rb +86 -0
- data/test/mailers/reset_password_instructions_test.rb +68 -0
- data/test/mailers/unlock_instructions_test.rb +62 -0
- data/test/mapping_test.rb +158 -0
- data/test/models/authenticatable_test.rb +180 -0
- data/test/models/confirmable_test.rb +228 -0
- data/test/models/lockable_test.rb +202 -0
- data/test/models/recoverable_test.rb +138 -0
- data/test/models/rememberable_test.rb +135 -0
- data/test/models/timeoutable_test.rb +28 -0
- data/test/models/token_authenticatable_test.rb +51 -0
- data/test/models/trackable_test.rb +5 -0
- data/test/models/validatable_test.rb +106 -0
- data/test/models_test.rb +70 -0
- data/test/orm/active_record.rb +31 -0
- data/test/orm/mongo_mapper.rb +20 -0
- data/test/rails_app/app/active_record/admin.rb +7 -0
- data/test/rails_app/app/active_record/user.rb +7 -0
- data/test/rails_app/app/controllers/admins_controller.rb +6 -0
- data/test/rails_app/app/controllers/application_controller.rb +12 -0
- data/test/rails_app/app/controllers/home_controller.rb +4 -0
- data/test/rails_app/app/controllers/users_controller.rb +16 -0
- data/test/rails_app/app/helpers/application_helper.rb +3 -0
- data/test/rails_app/app/mongo_mapper/admin.rb +13 -0
- data/test/rails_app/app/mongo_mapper/user.rb +14 -0
- data/test/rails_app/config/boot.rb +110 -0
- data/test/rails_app/config/environment.rb +42 -0
- data/test/rails_app/config/environments/development.rb +17 -0
- data/test/rails_app/config/environments/production.rb +28 -0
- data/test/rails_app/config/environments/test.rb +28 -0
- data/test/rails_app/config/initializers/devise.rb +82 -0
- data/test/rails_app/config/initializers/inflections.rb +2 -0
- data/test/rails_app/config/initializers/new_rails_defaults.rb +24 -0
- data/test/rails_app/config/initializers/session_store.rb +15 -0
- data/test/rails_app/config/routes.rb +25 -0
- data/test/rails_app/vendor/plugins/devise/app/controllers/confirmations_controller.rb +33 -0
- data/test/rails_app/vendor/plugins/devise/app/controllers/passwords_controller.rb +41 -0
- data/test/rails_app/vendor/plugins/devise/app/controllers/registrations_controller.rb +53 -0
- data/test/rails_app/vendor/plugins/devise/app/controllers/sessions_controller.rb +42 -0
- data/test/rails_app/vendor/plugins/devise/app/controllers/unlocks_controller.rb +41 -0
- data/test/rails_app/vendor/plugins/devise/app/models/devise_mailer.rb +68 -0
- data/test/rails_app/vendor/plugins/devise/generators/devise/devise_generator.rb +15 -0
- data/test/rails_app/vendor/plugins/devise/generators/devise/lib/route_devise.rb +32 -0
- data/test/rails_app/vendor/plugins/devise/generators/devise/templates/migration.rb +23 -0
- data/test/rails_app/vendor/plugins/devise/generators/devise/templates/model.rb +9 -0
- data/test/rails_app/vendor/plugins/devise/generators/devise_install/devise_install_generator.rb +15 -0
- data/test/rails_app/vendor/plugins/devise/generators/devise_install/templates/devise.rb +105 -0
- data/test/rails_app/vendor/plugins/devise/generators/devise_views/devise_views_generator.rb +21 -0
- data/test/rails_app/vendor/plugins/devise/lib/devise/controllers/helpers.rb +212 -0
- data/test/rails_app/vendor/plugins/devise/lib/devise/controllers/internal_helpers.rb +129 -0
- data/test/rails_app/vendor/plugins/devise/lib/devise/controllers/url_helpers.rb +41 -0
- data/test/rails_app/vendor/plugins/devise/lib/devise/encryptors/authlogic_sha512.rb +21 -0
- data/test/rails_app/vendor/plugins/devise/lib/devise/encryptors/base.rb +20 -0
- data/test/rails_app/vendor/plugins/devise/lib/devise/encryptors/bcrypt.rb +21 -0
- data/test/rails_app/vendor/plugins/devise/lib/devise/encryptors/clearance_sha1.rb +19 -0
- data/test/rails_app/vendor/plugins/devise/lib/devise/encryptors/restful_authentication_sha1.rb +22 -0
- data/test/rails_app/vendor/plugins/devise/lib/devise/encryptors/sha1.rb +27 -0
- data/test/rails_app/vendor/plugins/devise/lib/devise/encryptors/sha512.rb +27 -0
- data/test/rails_app/vendor/plugins/devise/lib/devise/failure_app.rb +70 -0
- data/test/rails_app/vendor/plugins/devise/lib/devise/hooks/activatable.rb +15 -0
- data/test/rails_app/vendor/plugins/devise/lib/devise/hooks/rememberable.rb +33 -0
- data/test/rails_app/vendor/plugins/devise/lib/devise/hooks/timeoutable.rb +18 -0
- data/test/rails_app/vendor/plugins/devise/lib/devise/hooks/trackable.rb +18 -0
- data/test/rails_app/vendor/plugins/devise/lib/devise/mapping.rb +130 -0
- data/test/rails_app/vendor/plugins/devise/lib/devise/models/activatable.rb +16 -0
- data/test/rails_app/vendor/plugins/devise/lib/devise/models/confirmable.rb +167 -0
- data/test/rails_app/vendor/plugins/devise/lib/devise/models/database_authenticatable.rb +144 -0
- data/test/rails_app/vendor/plugins/devise/lib/devise/models/http_authenticatable.rb +23 -0
- data/test/rails_app/vendor/plugins/devise/lib/devise/models/lockable.rb +150 -0
- data/test/rails_app/vendor/plugins/devise/lib/devise/models/recoverable.rb +80 -0
- data/test/rails_app/vendor/plugins/devise/lib/devise/models/registerable.rb +8 -0
- data/test/rails_app/vendor/plugins/devise/lib/devise/models/rememberable.rb +92 -0
- data/test/rails_app/vendor/plugins/devise/lib/devise/models/timeoutable.rb +28 -0
- data/test/rails_app/vendor/plugins/devise/lib/devise/models/token_authenticatable.rb +89 -0
- data/test/rails_app/vendor/plugins/devise/lib/devise/models/trackable.rb +16 -0
- data/test/rails_app/vendor/plugins/devise/lib/devise/models/validatable.rb +39 -0
- data/test/rails_app/vendor/plugins/devise/lib/devise/models.rb +117 -0
- data/test/rails_app/vendor/plugins/devise/lib/devise/orm/active_record.rb +41 -0
- data/test/rails_app/vendor/plugins/devise/lib/devise/orm/data_mapper.rb +83 -0
- data/test/rails_app/vendor/plugins/devise/lib/devise/orm/mongo_mapper.rb +52 -0
- data/test/rails_app/vendor/plugins/devise/lib/devise/rails/routes.rb +133 -0
- data/test/rails_app/vendor/plugins/devise/lib/devise/rails/warden_compat.rb +60 -0
- data/test/rails_app/vendor/plugins/devise/lib/devise/rails.rb +14 -0
- data/test/rails_app/vendor/plugins/devise/lib/devise/schema.rb +73 -0
- data/test/rails_app/vendor/plugins/devise/lib/devise/strategies/base.rb +16 -0
- data/test/rails_app/vendor/plugins/devise/lib/devise/strategies/database_authenticatable.rb +36 -0
- data/test/rails_app/vendor/plugins/devise/lib/devise/strategies/http_authenticatable.rb +59 -0
- data/test/rails_app/vendor/plugins/devise/lib/devise/strategies/rememberable.rb +37 -0
- data/test/rails_app/vendor/plugins/devise/lib/devise/strategies/token_authenticatable.rb +37 -0
- data/test/rails_app/vendor/plugins/devise/lib/devise/test_helpers.rb +90 -0
- data/test/rails_app/vendor/plugins/devise/lib/devise/version.rb +3 -0
- data/test/rails_app/vendor/plugins/devise/lib/devise.rb +266 -0
- data/test/rails_app/vendor/plugins/devise/rails/init.rb +2 -0
- data/test/rails_app/vendor/plugins/devise/test/controllers/helpers_test.rb +184 -0
- data/test/rails_app/vendor/plugins/devise/test/controllers/internal_helpers_test.rb +55 -0
- data/test/rails_app/vendor/plugins/devise/test/controllers/url_helpers_test.rb +47 -0
- data/test/rails_app/vendor/plugins/devise/test/devise_test.rb +74 -0
- data/test/rails_app/vendor/plugins/devise/test/encryptors_test.rb +31 -0
- data/test/rails_app/vendor/plugins/devise/test/failure_app_test.rb +44 -0
- data/test/rails_app/vendor/plugins/devise/test/integration/authenticatable_test.rb +332 -0
- data/test/rails_app/vendor/plugins/devise/test/integration/confirmable_test.rb +97 -0
- data/test/rails_app/vendor/plugins/devise/test/integration/http_authenticatable_test.rb +52 -0
- data/test/rails_app/vendor/plugins/devise/test/integration/lockable_test.rb +102 -0
- data/test/rails_app/vendor/plugins/devise/test/integration/rack_middleware_test.rb +47 -0
- data/test/rails_app/vendor/plugins/devise/test/integration/recoverable_test.rb +141 -0
- data/test/rails_app/vendor/plugins/devise/test/integration/registerable_test.rb +144 -0
- data/test/rails_app/vendor/plugins/devise/test/integration/rememberable_test.rb +72 -0
- data/test/rails_app/vendor/plugins/devise/test/integration/timeoutable_test.rb +68 -0
- data/test/rails_app/vendor/plugins/devise/test/integration/token_authenticatable_test.rb +55 -0
- data/test/rails_app/vendor/plugins/devise/test/integration/trackable_test.rb +64 -0
- data/test/rails_app/vendor/plugins/devise/test/mailers/confirmation_instructions_test.rb +86 -0
- data/test/rails_app/vendor/plugins/devise/test/mailers/reset_password_instructions_test.rb +68 -0
- data/test/rails_app/vendor/plugins/devise/test/mailers/unlock_instructions_test.rb +62 -0
- data/test/rails_app/vendor/plugins/devise/test/mapping_test.rb +158 -0
- data/test/rails_app/vendor/plugins/devise/test/models/authenticatable_test.rb +180 -0
- data/test/rails_app/vendor/plugins/devise/test/models/confirmable_test.rb +228 -0
- data/test/rails_app/vendor/plugins/devise/test/models/lockable_test.rb +202 -0
- data/test/rails_app/vendor/plugins/devise/test/models/recoverable_test.rb +138 -0
- data/test/rails_app/vendor/plugins/devise/test/models/rememberable_test.rb +135 -0
- data/test/rails_app/vendor/plugins/devise/test/models/timeoutable_test.rb +28 -0
- data/test/rails_app/vendor/plugins/devise/test/models/token_authenticatable_test.rb +51 -0
- data/test/rails_app/vendor/plugins/devise/test/models/trackable_test.rb +5 -0
- data/test/rails_app/vendor/plugins/devise/test/models/validatable_test.rb +106 -0
- data/test/rails_app/vendor/plugins/devise/test/models_test.rb +70 -0
- data/test/rails_app/vendor/plugins/devise/test/orm/active_record.rb +31 -0
- data/test/rails_app/vendor/plugins/devise/test/orm/mongo_mapper.rb +20 -0
- data/test/rails_app/vendor/plugins/devise/test/rails_app/app/active_record/admin.rb +7 -0
- data/test/rails_app/vendor/plugins/devise/test/rails_app/app/active_record/user.rb +7 -0
- data/test/rails_app/vendor/plugins/devise/test/rails_app/app/controllers/admins_controller.rb +6 -0
- data/test/rails_app/vendor/plugins/devise/test/rails_app/app/controllers/application_controller.rb +12 -0
- data/test/rails_app/vendor/plugins/devise/test/rails_app/app/controllers/home_controller.rb +4 -0
- data/test/rails_app/vendor/plugins/devise/test/rails_app/app/controllers/users_controller.rb +16 -0
- data/test/rails_app/vendor/plugins/devise/test/rails_app/app/helpers/application_helper.rb +3 -0
- data/test/rails_app/vendor/plugins/devise/test/rails_app/app/mongo_mapper/admin.rb +13 -0
- data/test/rails_app/vendor/plugins/devise/test/rails_app/app/mongo_mapper/user.rb +14 -0
- data/test/rails_app/vendor/plugins/devise/test/rails_app/config/boot.rb +110 -0
- data/test/rails_app/vendor/plugins/devise/test/rails_app/config/environment.rb +42 -0
- data/test/rails_app/vendor/plugins/devise/test/rails_app/config/environments/development.rb +17 -0
- data/test/rails_app/vendor/plugins/devise/test/rails_app/config/environments/production.rb +28 -0
- data/test/rails_app/vendor/plugins/devise/test/rails_app/config/environments/test.rb +28 -0
- data/test/rails_app/vendor/plugins/devise/test/rails_app/config/initializers/devise.rb +82 -0
- data/test/rails_app/vendor/plugins/devise/test/rails_app/config/initializers/inflections.rb +2 -0
- data/test/rails_app/vendor/plugins/devise/test/rails_app/config/initializers/new_rails_defaults.rb +24 -0
- data/test/rails_app/vendor/plugins/devise/test/rails_app/config/initializers/session_store.rb +15 -0
- data/test/rails_app/vendor/plugins/devise/test/rails_app/config/routes.rb +25 -0
- data/test/rails_app/vendor/plugins/devise/test/routes_test.rb +131 -0
- data/test/rails_app/vendor/plugins/devise/test/support/assertions_helper.rb +37 -0
- data/test/rails_app/vendor/plugins/devise/test/support/integration_tests_helper.rb +71 -0
- data/test/rails_app/vendor/plugins/devise/test/support/test_silencer.rb +5 -0
- data/test/rails_app/vendor/plugins/devise/test/support/tests_helper.rb +39 -0
- data/test/rails_app/vendor/plugins/devise/test/test_helper.rb +21 -0
- data/test/rails_app/vendor/plugins/devise/test/test_helpers_test.rb +57 -0
- data/test/routes_test.rb +131 -0
- data/test/support/assertions_helper.rb +37 -0
- data/test/support/integration_tests_helper.rb +71 -0
- data/test/support/test_silencer.rb +5 -0
- data/test/support/tests_helper.rb +39 -0
- data/test/test_helper.rb +21 -0
- data/test/test_helpers_test.rb +57 -0
- metadata +515 -0
@@ -0,0 +1,184 @@
|
|
1
|
+
require 'test/test_helper'
|
2
|
+
require 'ostruct'
|
3
|
+
|
4
|
+
class MockController < ApplicationController
|
5
|
+
attr_accessor :env
|
6
|
+
|
7
|
+
def request
|
8
|
+
self
|
9
|
+
end
|
10
|
+
|
11
|
+
def path
|
12
|
+
''
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
class ControllerAuthenticableTest < ActionController::TestCase
|
17
|
+
tests MockController
|
18
|
+
|
19
|
+
def setup
|
20
|
+
@controller = MockController.new
|
21
|
+
@mock_warden = OpenStruct.new
|
22
|
+
@controller.env = { 'warden' => @mock_warden }
|
23
|
+
@controller.session = {}
|
24
|
+
end
|
25
|
+
|
26
|
+
test 'setup warden' do
|
27
|
+
assert_not_nil @controller.warden
|
28
|
+
end
|
29
|
+
|
30
|
+
test 'provide access to warden instance' do
|
31
|
+
assert_equal @controller.warden, @controller.env['warden']
|
32
|
+
end
|
33
|
+
|
34
|
+
test 'proxy signed_in? to authenticated' do
|
35
|
+
@mock_warden.expects(:authenticate?).with(:scope => :my_scope)
|
36
|
+
@controller.signed_in?(:my_scope)
|
37
|
+
end
|
38
|
+
|
39
|
+
test 'proxy anybody_signed_in? to signed_in?' do
|
40
|
+
Devise.mappings.keys.each { |scope| # :user, :admin, :manager
|
41
|
+
@controller.expects(:signed_in?).with(scope)
|
42
|
+
}
|
43
|
+
@controller.anybody_signed_in?
|
44
|
+
end
|
45
|
+
|
46
|
+
test 'proxy current_admin to authenticate with admin scope' do
|
47
|
+
@mock_warden.expects(:authenticate).with(:scope => :admin)
|
48
|
+
@controller.current_admin
|
49
|
+
end
|
50
|
+
|
51
|
+
test 'proxy current_user to authenticate with user scope' do
|
52
|
+
@mock_warden.expects(:authenticate).with(:scope => :user)
|
53
|
+
@controller.current_user
|
54
|
+
end
|
55
|
+
|
56
|
+
test 'proxy user_authenticate! to authenticate with user scope' do
|
57
|
+
@mock_warden.expects(:authenticate!).with(:scope => :user)
|
58
|
+
@controller.authenticate_user!
|
59
|
+
end
|
60
|
+
|
61
|
+
test 'proxy admin_authenticate! to authenticate with admin scope' do
|
62
|
+
@mock_warden.expects(:authenticate!).with(:scope => :admin)
|
63
|
+
@controller.authenticate_admin!
|
64
|
+
end
|
65
|
+
|
66
|
+
test 'proxy user_signed_in? to authenticate? with user scope' do
|
67
|
+
@mock_warden.expects(:authenticate?).with(:scope => :user)
|
68
|
+
@controller.user_signed_in?
|
69
|
+
end
|
70
|
+
|
71
|
+
test 'proxy admin_signed_in? to authenticate? with admin scope' do
|
72
|
+
@mock_warden.expects(:authenticate?).with(:scope => :admin)
|
73
|
+
@controller.admin_signed_in?
|
74
|
+
end
|
75
|
+
|
76
|
+
test 'proxy user_session to session scope in warden' do
|
77
|
+
@mock_warden.expects(:authenticate).with(:scope => :user).returns(true)
|
78
|
+
@mock_warden.expects(:session).with(:user).returns({})
|
79
|
+
@controller.user_session
|
80
|
+
end
|
81
|
+
|
82
|
+
test 'proxy admin_session to session scope in warden' do
|
83
|
+
@mock_warden.expects(:authenticate).with(:scope => :admin).returns(true)
|
84
|
+
@mock_warden.expects(:session).with(:admin).returns({})
|
85
|
+
@controller.admin_session
|
86
|
+
end
|
87
|
+
|
88
|
+
test 'sign in proxy to set_user on warden' do
|
89
|
+
user = User.new
|
90
|
+
@mock_warden.expects(:set_user).with(user, :scope => :user).returns(true)
|
91
|
+
@controller.sign_in(:user, user)
|
92
|
+
end
|
93
|
+
|
94
|
+
test 'sign in accepts a resource as argument' do
|
95
|
+
user = User.new
|
96
|
+
@mock_warden.expects(:set_user).with(user, :scope => :user).returns(true)
|
97
|
+
@controller.sign_in(user)
|
98
|
+
end
|
99
|
+
|
100
|
+
test 'sign out proxy to logout on warden' do
|
101
|
+
@mock_warden.expects(:user).with(:user).returns(true)
|
102
|
+
@mock_warden.expects(:logout).with(:user).returns(true)
|
103
|
+
@controller.sign_out(:user)
|
104
|
+
end
|
105
|
+
|
106
|
+
test 'sign out accepts a resource as argument' do
|
107
|
+
@mock_warden.expects(:user).with(:user).returns(true)
|
108
|
+
@mock_warden.expects(:logout).with(:user).returns(true)
|
109
|
+
@controller.sign_out(User.new)
|
110
|
+
end
|
111
|
+
|
112
|
+
test 'stored location for returns the location for a given scope' do
|
113
|
+
assert_nil @controller.stored_location_for(:user)
|
114
|
+
@controller.session[:"user.return_to"] = "/foo.bar"
|
115
|
+
assert_equal "/foo.bar", @controller.stored_location_for(:user)
|
116
|
+
end
|
117
|
+
|
118
|
+
test 'stored location for accepts a resource as argument' do
|
119
|
+
assert_nil @controller.stored_location_for(:user)
|
120
|
+
@controller.session[:"user.return_to"] = "/foo.bar"
|
121
|
+
assert_equal "/foo.bar", @controller.stored_location_for(User.new)
|
122
|
+
end
|
123
|
+
|
124
|
+
test 'stored location cleans information after reading' do
|
125
|
+
@controller.session[:"user.return_to"] = "/foo.bar"
|
126
|
+
assert_equal "/foo.bar", @controller.stored_location_for(:user)
|
127
|
+
assert_nil @controller.session[:"user.return_to"]
|
128
|
+
end
|
129
|
+
|
130
|
+
test 'after sign in path defaults to root path if none by was specified for the given scope' do
|
131
|
+
assert_equal root_path, @controller.after_sign_in_path_for(:user)
|
132
|
+
end
|
133
|
+
|
134
|
+
test 'after sign in path defaults to the scoped root path' do
|
135
|
+
assert_equal admin_root_path, @controller.after_sign_in_path_for(:admin)
|
136
|
+
end
|
137
|
+
|
138
|
+
test 'after sign out path defaults to the root path' do
|
139
|
+
assert_equal root_path, @controller.after_sign_out_path_for(:admin)
|
140
|
+
assert_equal root_path, @controller.after_sign_out_path_for(:user)
|
141
|
+
end
|
142
|
+
|
143
|
+
test 'sign in and redirect uses the stored location' do
|
144
|
+
user = User.new
|
145
|
+
@controller.session[:"user.return_to"] = "/foo.bar"
|
146
|
+
@mock_warden.expects(:set_user).with(user, :scope => :user).returns(true)
|
147
|
+
@controller.expects(:redirect_to).with("/foo.bar")
|
148
|
+
@controller.sign_in_and_redirect(user)
|
149
|
+
end
|
150
|
+
|
151
|
+
test 'sign in and redirect uses the configured after sign in path' do
|
152
|
+
admin = Admin.new
|
153
|
+
@mock_warden.expects(:set_user).with(admin, :scope => :admin).returns(true)
|
154
|
+
@controller.expects(:redirect_to).with(admin_root_path)
|
155
|
+
@controller.sign_in_and_redirect(admin)
|
156
|
+
end
|
157
|
+
|
158
|
+
test 'only redirect if skip is given' do
|
159
|
+
admin = Admin.new
|
160
|
+
@controller.expects(:redirect_to).with(admin_root_path)
|
161
|
+
@controller.sign_in_and_redirect(:admin, admin, true)
|
162
|
+
end
|
163
|
+
|
164
|
+
test 'sign out and redirect uses the configured after sign out path' do
|
165
|
+
@mock_warden.expects(:user).with(:admin).returns(true)
|
166
|
+
@mock_warden.expects(:logout).with(:admin).returns(true)
|
167
|
+
@controller.expects(:redirect_to).with(admin_root_path)
|
168
|
+
@controller.instance_eval "def after_sign_out_path_for(resource); admin_root_path; end"
|
169
|
+
@controller.sign_out_and_redirect(:admin)
|
170
|
+
end
|
171
|
+
|
172
|
+
test 'is not a devise controller' do
|
173
|
+
assert_not @controller.devise_controller?
|
174
|
+
end
|
175
|
+
|
176
|
+
test 'default url options are retrieved from devise' do
|
177
|
+
begin
|
178
|
+
Devise.default_url_options {{ :locale => I18n.locale }}
|
179
|
+
assert_equal({ :locale => :en }, @controller.send(:default_url_options))
|
180
|
+
ensure
|
181
|
+
Devise.default_url_options {{ }}
|
182
|
+
end
|
183
|
+
end
|
184
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'test/test_helper'
|
2
|
+
|
3
|
+
class MyController < ApplicationController
|
4
|
+
include Devise::Controllers::InternalHelpers
|
5
|
+
end
|
6
|
+
|
7
|
+
class HelpersTest < ActionController::TestCase
|
8
|
+
tests MyController
|
9
|
+
|
10
|
+
test 'get resource name from request path' do
|
11
|
+
@request.path = '/users/session'
|
12
|
+
assert_equal :user, @controller.resource_name
|
13
|
+
end
|
14
|
+
|
15
|
+
test 'get resource name from specific request path' do
|
16
|
+
@request.path = '/admin_area/session'
|
17
|
+
assert_equal :admin, @controller.resource_name
|
18
|
+
end
|
19
|
+
|
20
|
+
test 'get resource class from request path' do
|
21
|
+
@request.path = '/users/session'
|
22
|
+
assert_equal User, @controller.resource_class
|
23
|
+
end
|
24
|
+
|
25
|
+
test 'get resource instance variable from request path' do
|
26
|
+
@request.path = '/admin_area/session'
|
27
|
+
@controller.instance_variable_set(:@admin, admin = Admin.new)
|
28
|
+
assert_equal admin, @controller.resource
|
29
|
+
end
|
30
|
+
|
31
|
+
test 'set resource instance variable from request path' do
|
32
|
+
@request.path = '/admin_area/session'
|
33
|
+
|
34
|
+
admin = @controller.send(:resource_class).new
|
35
|
+
@controller.send(:resource=, admin)
|
36
|
+
|
37
|
+
assert_equal admin, @controller.send(:resource)
|
38
|
+
assert_equal admin, @controller.instance_variable_get(:@admin)
|
39
|
+
end
|
40
|
+
|
41
|
+
test 'resources methods are not controller actions' do
|
42
|
+
assert @controller.class.action_methods.empty?
|
43
|
+
end
|
44
|
+
|
45
|
+
test 'require no authentication tests current mapping' do
|
46
|
+
@controller.expects(:resource_name).returns(:user).twice
|
47
|
+
@mock_warden.expects(:authenticated?).with(:user).returns(true)
|
48
|
+
@controller.expects(:redirect_to).with(root_path)
|
49
|
+
@controller.send :require_no_authentication
|
50
|
+
end
|
51
|
+
|
52
|
+
test 'is a devise controller' do
|
53
|
+
assert @controller.devise_controller?
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'test/test_helper'
|
2
|
+
|
3
|
+
class RoutesTest < ActionController::TestCase
|
4
|
+
tests ApplicationController
|
5
|
+
|
6
|
+
def test_path_and_url(name, prepend_path=nil)
|
7
|
+
@request.path = '/users/session'
|
8
|
+
prepend_path = "#{prepend_path}_" if prepend_path
|
9
|
+
|
10
|
+
# Resource param
|
11
|
+
assert_equal @controller.send(:"#{prepend_path}#{name}_path", :user),
|
12
|
+
send(:"#{prepend_path}user_#{name}_path")
|
13
|
+
assert_equal @controller.send(:"#{prepend_path}#{name}_url", :user),
|
14
|
+
send(:"#{prepend_path}user_#{name}_url")
|
15
|
+
|
16
|
+
# Default url params
|
17
|
+
assert_equal @controller.send(:"#{prepend_path}#{name}_path", :user, :param => 123),
|
18
|
+
send(:"#{prepend_path}user_#{name}_path", :param => 123)
|
19
|
+
assert_equal @controller.send(:"#{prepend_path}#{name}_url", :user, :param => 123),
|
20
|
+
send(:"#{prepend_path}user_#{name}_url", :param => 123)
|
21
|
+
|
22
|
+
@request.path = nil
|
23
|
+
# With an AR object
|
24
|
+
assert_equal @controller.send(:"#{prepend_path}#{name}_path", User.new),
|
25
|
+
send(:"#{prepend_path}user_#{name}_path")
|
26
|
+
assert_equal @controller.send(:"#{prepend_path}#{name}_url", User.new),
|
27
|
+
send(:"#{prepend_path}user_#{name}_url")
|
28
|
+
end
|
29
|
+
|
30
|
+
|
31
|
+
test 'should alias session to mapped user session' do
|
32
|
+
test_path_and_url :session
|
33
|
+
test_path_and_url :session, :new
|
34
|
+
test_path_and_url :session, :destroy
|
35
|
+
end
|
36
|
+
|
37
|
+
test 'should alias password to mapped user password' do
|
38
|
+
test_path_and_url :password
|
39
|
+
test_path_and_url :password, :new
|
40
|
+
test_path_and_url :password, :edit
|
41
|
+
end
|
42
|
+
|
43
|
+
test 'should alias confirmation to mapped user confirmation' do
|
44
|
+
test_path_and_url :confirmation
|
45
|
+
test_path_and_url :confirmation, :new
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
require 'test/test_helper'
|
2
|
+
|
3
|
+
module Devise
|
4
|
+
def self.clean_warden_config!
|
5
|
+
@warden_config = nil
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
class DeviseTest < ActiveSupport::TestCase
|
10
|
+
test 'model options can be configured through Devise' do
|
11
|
+
swap Devise, :confirm_within => 113, :pepper => "foo" do
|
12
|
+
assert_equal 113, Devise.confirm_within
|
13
|
+
assert_equal "foo", Devise.pepper
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
test 'setup block yields self' do
|
18
|
+
Devise.setup do |config|
|
19
|
+
assert_equal Devise, config
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
test 'warden manager configuration' do
|
24
|
+
config = Warden::Config.new
|
25
|
+
Devise.configure_warden(config)
|
26
|
+
|
27
|
+
assert_equal Devise::FailureApp, config.failure_app
|
28
|
+
assert_equal [:rememberable, :http_authenticatable, :token_authenticatable, :database_authenticatable], config.default_strategies
|
29
|
+
assert_equal :user, config.default_scope
|
30
|
+
assert config.silence_missing_strategies?
|
31
|
+
end
|
32
|
+
|
33
|
+
test 'warden manager user configuration through a block' do
|
34
|
+
begin
|
35
|
+
@executed = false
|
36
|
+
Devise.warden do |config|
|
37
|
+
@executed = true
|
38
|
+
assert_kind_of Warden::Config, config
|
39
|
+
end
|
40
|
+
|
41
|
+
Devise.configure_warden(Warden::Config.new)
|
42
|
+
assert @executed
|
43
|
+
ensure
|
44
|
+
Devise.clean_warden_config!
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
test 'add new module using the helper method' do
|
49
|
+
assert_nothing_raised(Exception) { Devise.add_module(:coconut) }
|
50
|
+
assert_equal 1, Devise::ALL.select { |v| v == :coconut }.size
|
51
|
+
assert_not Devise::STRATEGIES.include?(:coconut)
|
52
|
+
assert_not defined?(Devise::Models::Coconut)
|
53
|
+
Devise::ALL.delete(:coconut)
|
54
|
+
|
55
|
+
assert_nothing_raised(Exception) { Devise.add_module(:banana, :strategy => true) }
|
56
|
+
assert_equal 1, Devise::STRATEGIES.select { |v| v == :banana }.size
|
57
|
+
Devise::ALL.delete(:banana)
|
58
|
+
Devise::STRATEGIES.delete(:banana)
|
59
|
+
|
60
|
+
assert_nothing_raised(Exception) { Devise.add_module(:kivi, :controller => :fruits) }
|
61
|
+
assert_not_nil Devise::CONTROLLERS[:fruits]
|
62
|
+
assert_equal 1, Devise::CONTROLLERS[:fruits].select { |v| v == :kivi }.size
|
63
|
+
Devise::ALL.delete(:kivi)
|
64
|
+
Devise::CONTROLLERS.delete(:fruits)
|
65
|
+
|
66
|
+
assert_nothing_raised(Exception) { Devise.add_module(:carrot, :route => :vegetable) }
|
67
|
+
assert_equal 1, Devise::ROUTES.select { |v| v == :vegetable }.size
|
68
|
+
Devise::ALL.delete(:carrot)
|
69
|
+
Devise::ROUTES.delete(:vegetable)
|
70
|
+
|
71
|
+
assert_nothing_raised(Exception) { Devise.add_module(:authenticatable_again, :model => 'devise/model/authenticatable') }
|
72
|
+
assert defined?(Devise::Models::AuthenticatableAgain)
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
gem 'bcrypt-ruby'
|
2
|
+
|
3
|
+
class Encryptors < ActiveSupport::TestCase
|
4
|
+
|
5
|
+
test 'should match a password created by authlogic' do
|
6
|
+
authlogic = "b623c3bc9c775b0eb8edb218a382453396fec4146422853e66ecc4b6bc32d7162ee42074dcb5f180a770dc38b5df15812f09bbf497a4a1b95fe5e7d2b8eb7eb4"
|
7
|
+
encryptor = Devise::Encryptors::AuthlogicSha512.digest('123mudar', 20, 'usZK_z_EAaF61Gwkw-ed', '')
|
8
|
+
assert_equal authlogic, encryptor
|
9
|
+
end
|
10
|
+
|
11
|
+
test 'should match a password created by restful_authentication' do
|
12
|
+
restful_authentication = "93110f71309ce91366375ea44e2a6f5cc73fa8d4"
|
13
|
+
encryptor = Devise::Encryptors::RestfulAuthenticationSha1.digest('123mudar', 10, '48901d2b247a54088acb7f8ea3e695e50fe6791b', 'fee9a51ec0a28d11be380ca6dee6b4b760c1a3bf')
|
14
|
+
assert_equal restful_authentication, encryptor
|
15
|
+
end
|
16
|
+
|
17
|
+
test 'should match a password created by clearance' do
|
18
|
+
clearance = "0f40bbae18ddefd7066276c3ef209d40729b0378"
|
19
|
+
encryptor = Devise::Encryptors::ClearanceSha1.digest('123mudar', nil, '65c58472c207c829f28c68619d3e3aefed18ab3f', nil)
|
20
|
+
assert_equal clearance, encryptor
|
21
|
+
end
|
22
|
+
|
23
|
+
Devise::ENCRYPTORS_LENGTH.each do |key, value|
|
24
|
+
test "should have length #{value} for #{key.inspect}" do
|
25
|
+
swap Devise, :encryptor => key do
|
26
|
+
encryptor = Devise::Encryptors.const_get(key.to_s.classify)
|
27
|
+
assert_equal value, encryptor.digest('a', 4, encryptor.salt, nil).size
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'test/test_helper'
|
2
|
+
require 'ostruct'
|
3
|
+
|
4
|
+
class FailureTest < ActiveSupport::TestCase
|
5
|
+
|
6
|
+
def call_failure(env_params={})
|
7
|
+
env = {'warden.options' => { :scope => :user }}.merge!(env_params)
|
8
|
+
Devise::FailureApp.call(env)
|
9
|
+
end
|
10
|
+
|
11
|
+
test 'return 302 status' do
|
12
|
+
assert_equal 302, call_failure.first
|
13
|
+
end
|
14
|
+
|
15
|
+
test 'return to the default redirect location' do
|
16
|
+
assert_equal '/users/sign_in?unauthenticated=true', call_failure.second['Location']
|
17
|
+
end
|
18
|
+
|
19
|
+
test 'uses the proxy failure message' do
|
20
|
+
warden = OpenStruct.new(:message => :test)
|
21
|
+
location = call_failure('warden' => warden).second['Location']
|
22
|
+
assert_equal '/users/sign_in?test=true', location
|
23
|
+
end
|
24
|
+
|
25
|
+
test 'uses the given message' do
|
26
|
+
warden = OpenStruct.new(:message => 'Hello world')
|
27
|
+
location = call_failure('warden' => warden).second['Location']
|
28
|
+
assert_equal '/users/sign_in?message=Hello+world', location
|
29
|
+
end
|
30
|
+
|
31
|
+
test 'setup default url' do
|
32
|
+
Devise::FailureApp.default_url = 'test/sign_in'
|
33
|
+
location = call_failure('warden.options' => { :scope => nil }).second['Location']
|
34
|
+
assert_equal '/test/sign_in?unauthenticated=true', location
|
35
|
+
end
|
36
|
+
|
37
|
+
test 'set content type to default text/plain' do
|
38
|
+
assert_equal 'text/plain', call_failure.second['Content-Type']
|
39
|
+
end
|
40
|
+
|
41
|
+
test 'setup a default message' do
|
42
|
+
assert_equal ['You are being redirected to /users/sign_in?unauthenticated=true'], call_failure.last
|
43
|
+
end
|
44
|
+
end
|