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,62 @@
|
|
1
|
+
require 'test/test_helper'
|
2
|
+
|
3
|
+
class UnlockInstructionsTest < ActionMailer::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
setup_mailer
|
7
|
+
Devise.mailer_sender = 'test@example.com'
|
8
|
+
end
|
9
|
+
|
10
|
+
def user
|
11
|
+
@user ||= begin
|
12
|
+
user = create_user
|
13
|
+
user.lock_access!
|
14
|
+
user
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def mail
|
19
|
+
@mail ||= begin
|
20
|
+
user
|
21
|
+
ActionMailer::Base.deliveries.last
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
test 'email sent after locking the user' do
|
26
|
+
assert_not_nil mail
|
27
|
+
end
|
28
|
+
|
29
|
+
test 'content type should be set to html' do
|
30
|
+
assert_equal 'text/html', mail.content_type
|
31
|
+
end
|
32
|
+
|
33
|
+
test 'send unlock instructions to the user email' do
|
34
|
+
assert_equal [user.email], mail.to
|
35
|
+
end
|
36
|
+
|
37
|
+
test 'setup sender from configuration' do
|
38
|
+
assert_equal ['test@example.com'], mail.from
|
39
|
+
end
|
40
|
+
|
41
|
+
test 'setup subject from I18n' do
|
42
|
+
store_translations :en, :devise => { :mailer => { :unlock_instructions => 'Unlock instructions' } } do
|
43
|
+
assert_equal 'Unlock instructions', mail.subject
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
test 'subject namespaced by model' do
|
48
|
+
store_translations :en, :devise => { :mailer => { :user => { :unlock_instructions => 'User Unlock Instructions' } } } do
|
49
|
+
assert_equal 'User Unlock Instructions', mail.subject
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
test 'body should have user info' do
|
54
|
+
assert_match /#{user.email}/, mail.body
|
55
|
+
end
|
56
|
+
|
57
|
+
test 'body should have link to unlock the account' do
|
58
|
+
host = ActionMailer::Base.default_url_options[:host]
|
59
|
+
unlock_url_regexp = %r{<a href=\"http://#{host}/users/unlock\?unlock_token=#{user.unlock_token}">}
|
60
|
+
assert_match unlock_url_regexp, mail.body
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,158 @@
|
|
1
|
+
require 'test/test_helper'
|
2
|
+
|
3
|
+
class MappingTest < ActiveSupport::TestCase
|
4
|
+
|
5
|
+
test 'store options' do
|
6
|
+
mapping = Devise.mappings[:user]
|
7
|
+
|
8
|
+
assert_equal User, mapping.to
|
9
|
+
assert_equal User.devise_modules, mapping.for
|
10
|
+
assert_equal :users, mapping.as
|
11
|
+
end
|
12
|
+
|
13
|
+
test 'allows as to be given' do
|
14
|
+
assert_equal :admin_area, Devise.mappings[:admin].as
|
15
|
+
end
|
16
|
+
|
17
|
+
test 'allow custom scope to be given' do
|
18
|
+
assert_equal :accounts, Devise.mappings[:manager].as
|
19
|
+
end
|
20
|
+
|
21
|
+
test 'allows a controller depending on the mapping' do
|
22
|
+
mapping = Devise.mappings[:user]
|
23
|
+
assert mapping.allows?(:sessions)
|
24
|
+
assert mapping.allows?(:confirmations)
|
25
|
+
assert mapping.allows?(:passwords)
|
26
|
+
|
27
|
+
mapping = Devise.mappings[:admin]
|
28
|
+
assert mapping.allows?(:sessions)
|
29
|
+
assert_not mapping.allows?(:confirmations)
|
30
|
+
assert_not mapping.allows?(:passwords)
|
31
|
+
end
|
32
|
+
|
33
|
+
test 'find mapping by path' do
|
34
|
+
assert_nil Devise::Mapping.find_by_path("/foo/bar")
|
35
|
+
assert_equal Devise.mappings[:user], Devise::Mapping.find_by_path("/users/session")
|
36
|
+
end
|
37
|
+
|
38
|
+
test 'find mapping by customized path' do
|
39
|
+
assert_equal Devise.mappings[:admin], Devise::Mapping.find_by_path("/admin_area/session")
|
40
|
+
end
|
41
|
+
|
42
|
+
test 'find scope for a given object' do
|
43
|
+
assert_equal :user, Devise::Mapping.find_scope!(User)
|
44
|
+
assert_equal :user, Devise::Mapping.find_scope!(:user)
|
45
|
+
assert_equal :user, Devise::Mapping.find_scope!(User.new)
|
46
|
+
end
|
47
|
+
|
48
|
+
test 'find scope works with single table inheritance' do
|
49
|
+
assert_equal :user, Devise::Mapping.find_scope!(Class.new(User))
|
50
|
+
assert_equal :user, Devise::Mapping.find_scope!(Class.new(User).new)
|
51
|
+
end
|
52
|
+
|
53
|
+
test 'find scope raises an error if cannot be found' do
|
54
|
+
assert_raise RuntimeError do
|
55
|
+
Devise::Mapping.find_scope!(String)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
test 'return default path names' do
|
60
|
+
mapping = Devise.mappings[:user]
|
61
|
+
assert_equal 'sign_in', mapping.path_names[:sign_in]
|
62
|
+
assert_equal 'sign_out', mapping.path_names[:sign_out]
|
63
|
+
assert_equal 'password', mapping.path_names[:password]
|
64
|
+
assert_equal 'confirmation', mapping.path_names[:confirmation]
|
65
|
+
assert_equal 'sign_up', mapping.path_names[:sign_up]
|
66
|
+
assert_equal 'unlock', mapping.path_names[:unlock]
|
67
|
+
end
|
68
|
+
|
69
|
+
test 'allow custom path names to be given' do
|
70
|
+
mapping = Devise.mappings[:manager]
|
71
|
+
assert_equal 'login', mapping.path_names[:sign_in]
|
72
|
+
assert_equal 'logout', mapping.path_names[:sign_out]
|
73
|
+
assert_equal 'secret', mapping.path_names[:password]
|
74
|
+
assert_equal 'verification', mapping.path_names[:confirmation]
|
75
|
+
assert_equal 'register', mapping.path_names[:sign_up]
|
76
|
+
assert_equal 'unblock', mapping.path_names[:unlock]
|
77
|
+
end
|
78
|
+
|
79
|
+
test 'has an empty path as default path prefix' do
|
80
|
+
mapping = Devise.mappings[:user]
|
81
|
+
assert_equal '/', mapping.path_prefix
|
82
|
+
end
|
83
|
+
|
84
|
+
test 'allow path prefix to be configured' do
|
85
|
+
mapping = Devise.mappings[:manager]
|
86
|
+
assert_equal '/:locale/', mapping.path_prefix
|
87
|
+
end
|
88
|
+
|
89
|
+
test 'retrieve as from the proper position' do
|
90
|
+
assert_equal 1, Devise.mappings[:user].as_position
|
91
|
+
assert_equal 2, Devise.mappings[:manager].as_position
|
92
|
+
end
|
93
|
+
|
94
|
+
test 'raw path is returned' do
|
95
|
+
assert_equal '/users', Devise.mappings[:user].raw_path
|
96
|
+
assert_equal '/:locale/accounts', Devise.mappings[:manager].raw_path
|
97
|
+
end
|
98
|
+
|
99
|
+
test 'raw path ignores the relative_url_root' do
|
100
|
+
swap ActionController::Base, :relative_url_root => "/abc" do
|
101
|
+
assert_equal '/users', Devise.mappings[:user].raw_path
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
test 'parsed path is returned' do
|
106
|
+
begin
|
107
|
+
Devise.default_url_options {{ :locale => I18n.locale }}
|
108
|
+
assert_equal '/users', Devise.mappings[:user].parsed_path
|
109
|
+
assert_equal '/en/accounts', Devise.mappings[:manager].parsed_path
|
110
|
+
ensure
|
111
|
+
Devise.default_url_options {{ }}
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
test 'parsed path adds in the relative_url_root' do
|
116
|
+
swap ActionController::Base, :relative_url_root => '/abc' do
|
117
|
+
assert_equal '/abc/users', Devise.mappings[:user].parsed_path
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
test 'parsed path deals with a nil relative_url_root' do
|
122
|
+
swap ActionController::Base, :relative_url_root => nil do
|
123
|
+
assert_equal '/users', Devise.mappings[:user].raw_path
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
test 'should have default route options' do
|
128
|
+
assert_equal({}, Devise.mappings[:user].route_options)
|
129
|
+
end
|
130
|
+
|
131
|
+
test 'should allow passing route options to devise routes' do
|
132
|
+
assert_equal({ :requirements => { :extra => 'value' } }, Devise.mappings[:manager].route_options)
|
133
|
+
end
|
134
|
+
|
135
|
+
test 'sign_out_via defaults to :get' do
|
136
|
+
assert_equal :get, Devise.mappings[:user].sign_out_via
|
137
|
+
end
|
138
|
+
|
139
|
+
test 'allows custom sign_out_via to be given' do
|
140
|
+
assert_equal :delete, Devise.mappings[:sign_out_via_delete].sign_out_via
|
141
|
+
assert_equal :post, Devise.mappings[:sign_out_via_post].sign_out_via
|
142
|
+
assert_equal :any, Devise.mappings[:sign_out_via_anymethod].sign_out_via
|
143
|
+
end
|
144
|
+
|
145
|
+
test 'magic predicates' do
|
146
|
+
mapping = Devise.mappings[:user]
|
147
|
+
assert mapping.authenticatable?
|
148
|
+
assert mapping.confirmable?
|
149
|
+
assert mapping.recoverable?
|
150
|
+
assert mapping.rememberable?
|
151
|
+
|
152
|
+
mapping = Devise.mappings[:admin]
|
153
|
+
assert mapping.authenticatable?
|
154
|
+
assert_not mapping.confirmable?
|
155
|
+
assert_not mapping.recoverable?
|
156
|
+
assert_not mapping.rememberable?
|
157
|
+
end
|
158
|
+
end
|
@@ -0,0 +1,180 @@
|
|
1
|
+
require 'test/test_helper'
|
2
|
+
require 'digest/sha1'
|
3
|
+
|
4
|
+
class AuthenticatableTest < ActiveSupport::TestCase
|
5
|
+
|
6
|
+
def encrypt_password(user, pepper=User.pepper, stretches=User.stretches, encryptor=::Devise::Encryptors::Sha1)
|
7
|
+
encryptor.digest('123456', stretches, user.password_salt, pepper)
|
8
|
+
end
|
9
|
+
|
10
|
+
test 'should respond to password and password confirmation' do
|
11
|
+
user = new_user
|
12
|
+
assert user.respond_to?(:password)
|
13
|
+
assert user.respond_to?(:password_confirmation)
|
14
|
+
end
|
15
|
+
|
16
|
+
test 'should generate encrypted password and salt while setting password' do
|
17
|
+
user = new_user
|
18
|
+
assert_present user.password_salt
|
19
|
+
assert_present user.encrypted_password
|
20
|
+
end
|
21
|
+
|
22
|
+
test 'should not change password salt when updating' do
|
23
|
+
user = create_user
|
24
|
+
salt = user.password_salt
|
25
|
+
user.expects(:password_salt=).never
|
26
|
+
user.save!
|
27
|
+
assert_equal salt, user.password_salt
|
28
|
+
end
|
29
|
+
|
30
|
+
test 'should generate a base64 hash using SecureRandom for password salt' do
|
31
|
+
ActiveSupport::SecureRandom.expects(:base64).with(15).returns('friendly_token')
|
32
|
+
assert_equal 'friendly_token', new_user.password_salt
|
33
|
+
end
|
34
|
+
|
35
|
+
test 'should not generate salt if password is blank' do
|
36
|
+
assert_blank new_user(:password => nil).password_salt
|
37
|
+
assert_blank new_user(:password => '').password_salt
|
38
|
+
end
|
39
|
+
|
40
|
+
test 'should not generate encrypted password if password is blank' do
|
41
|
+
assert_blank new_user(:password => nil).encrypted_password
|
42
|
+
assert_blank new_user(:password => '').encrypted_password
|
43
|
+
end
|
44
|
+
|
45
|
+
test 'should encrypt password again if password has changed' do
|
46
|
+
user = create_user
|
47
|
+
encrypted_password = user.encrypted_password
|
48
|
+
user.password = user.password_confirmation = 'new_password'
|
49
|
+
user.save!
|
50
|
+
assert_not_equal encrypted_password, user.encrypted_password
|
51
|
+
end
|
52
|
+
|
53
|
+
test 'should fallback to sha1 as default encryption' do
|
54
|
+
user = new_user
|
55
|
+
assert_equal encrypt_password(user), user.encrypted_password
|
56
|
+
end
|
57
|
+
|
58
|
+
test 'should fallback to devise pepper default configuration' do
|
59
|
+
begin
|
60
|
+
Devise.pepper = ''
|
61
|
+
user = new_user
|
62
|
+
assert_equal encrypt_password(user), user.encrypted_password
|
63
|
+
assert_not_equal encrypt_password(user, 'another_pepper'), user.encrypted_password
|
64
|
+
|
65
|
+
Devise.pepper = 'new_pepper'
|
66
|
+
user = new_user
|
67
|
+
assert_equal encrypt_password(user, 'new_pepper'), user.encrypted_password
|
68
|
+
assert_not_equal encrypt_password(user, 'another_pepper'), user.encrypted_password
|
69
|
+
ensure
|
70
|
+
Devise.pepper = nil
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
test 'should fallback to devise stretches default configuration' do
|
75
|
+
swap Devise, :stretches => 1 do
|
76
|
+
user = new_user
|
77
|
+
assert_equal encrypt_password(user, nil, 1), user.encrypted_password
|
78
|
+
assert_not_equal encrypt_password(user, nil, 2), user.encrypted_password
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
test 'should respect encryptor configuration' do
|
83
|
+
User.instance_variable_set(:@encryptor_class, nil)
|
84
|
+
|
85
|
+
swap Devise, :encryptor => :sha512 do
|
86
|
+
begin
|
87
|
+
user = create_user
|
88
|
+
assert_equal user.encrypted_password, encrypt_password(user, User.pepper, User.stretches, ::Devise::Encryptors::Sha512)
|
89
|
+
ensure
|
90
|
+
User.instance_variable_set(:@encryptor_class, nil)
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
test 'should test for a valid password' do
|
96
|
+
user = create_user
|
97
|
+
assert user.valid_password?('123456')
|
98
|
+
assert_not user.valid_password?('654321')
|
99
|
+
end
|
100
|
+
|
101
|
+
test 'should authenticate a valid user with email and password and return it' do
|
102
|
+
user = create_user
|
103
|
+
User.any_instance.stubs(:confirmed?).returns(true)
|
104
|
+
authenticated_user = User.authenticate(:email => user.email, :password => user.password)
|
105
|
+
assert_equal authenticated_user, user
|
106
|
+
end
|
107
|
+
|
108
|
+
test 'should return nil when authenticating an invalid user by email' do
|
109
|
+
user = create_user
|
110
|
+
authenticated_user = User.authenticate(:email => 'another.email@email.com', :password => user.password)
|
111
|
+
assert_nil authenticated_user
|
112
|
+
end
|
113
|
+
|
114
|
+
test 'should return nil when authenticating an invalid user by password' do
|
115
|
+
user = create_user
|
116
|
+
authenticated_user = User.authenticate(:email => user.email, :password => 'another_password')
|
117
|
+
assert_nil authenticated_user
|
118
|
+
end
|
119
|
+
|
120
|
+
test 'should use authentication keys to retrieve users' do
|
121
|
+
swap Devise, :authentication_keys => [:username] do
|
122
|
+
user = create_user
|
123
|
+
assert_nil User.authenticate(:email => user.email, :password => user.password)
|
124
|
+
assert_not_nil User.authenticate(:username => user.username, :password => user.password)
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
test 'should allow overwriting find for authentication conditions' do
|
129
|
+
admin = Admin.create!(valid_attributes)
|
130
|
+
assert_not_nil Admin.authenticate(:email => admin.email, :password => admin.password)
|
131
|
+
end
|
132
|
+
|
133
|
+
test 'should respond to current password' do
|
134
|
+
assert new_user.respond_to?(:current_password)
|
135
|
+
end
|
136
|
+
|
137
|
+
test 'should update password with valid current password' do
|
138
|
+
user = create_user
|
139
|
+
assert user.update_with_password(:current_password => '123456',
|
140
|
+
:password => 'pass321', :password_confirmation => 'pass321')
|
141
|
+
assert user.reload.valid_password?('pass321')
|
142
|
+
end
|
143
|
+
|
144
|
+
test 'should add an error to current password when it is invalid' do
|
145
|
+
user = create_user
|
146
|
+
assert_not user.update_with_password(:current_password => 'other',
|
147
|
+
:password => 'pass321', :password_confirmation => 'pass321')
|
148
|
+
assert user.reload.valid_password?('123456')
|
149
|
+
assert_match /invalid/, user.errors[:current_password]
|
150
|
+
end
|
151
|
+
|
152
|
+
test 'should add an error to current password when it is blank' do
|
153
|
+
user = create_user
|
154
|
+
assert_not user.update_with_password(:password => 'pass321',
|
155
|
+
:password_confirmation => 'pass321')
|
156
|
+
assert user.reload.valid_password?('123456')
|
157
|
+
assert_match /blank/, user.errors[:current_password]
|
158
|
+
end
|
159
|
+
|
160
|
+
test 'should ignore password and its confirmation if they are blank' do
|
161
|
+
user = create_user
|
162
|
+
assert user.update_with_password(:current_password => '123456', :email => "new@email.com")
|
163
|
+
assert_equal "new@email.com", user.email
|
164
|
+
end
|
165
|
+
|
166
|
+
test 'should not update password with invalid confirmation' do
|
167
|
+
user = create_user
|
168
|
+
assert_not user.update_with_password(:current_password => '123456',
|
169
|
+
:password => 'pass321', :password_confirmation => 'other')
|
170
|
+
assert user.reload.valid_password?('123456')
|
171
|
+
end
|
172
|
+
|
173
|
+
test 'should clean up password fields on failure' do
|
174
|
+
user = create_user
|
175
|
+
assert_not user.update_with_password(:current_password => '123456',
|
176
|
+
:password => 'pass321', :password_confirmation => 'other')
|
177
|
+
assert user.password.blank?
|
178
|
+
assert user.password_confirmation.blank?
|
179
|
+
end
|
180
|
+
end
|
@@ -0,0 +1,228 @@
|
|
1
|
+
require 'test/test_helper'
|
2
|
+
|
3
|
+
class ConfirmableTest < ActiveSupport::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
setup_mailer
|
7
|
+
end
|
8
|
+
|
9
|
+
test 'should generate confirmation token after creating a record' do
|
10
|
+
assert_nil new_user.confirmation_token
|
11
|
+
assert_not_nil create_user.confirmation_token
|
12
|
+
end
|
13
|
+
|
14
|
+
test 'should never generate the same confirmation token for different users' do
|
15
|
+
confirmation_tokens = []
|
16
|
+
3.times do
|
17
|
+
token = create_user.confirmation_token
|
18
|
+
assert !confirmation_tokens.include?(token)
|
19
|
+
confirmation_tokens << token
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
test 'should confirm a user by updating confirmed at' do
|
24
|
+
user = create_user
|
25
|
+
assert_nil user.confirmed_at
|
26
|
+
assert user.confirm!
|
27
|
+
assert_not_nil user.confirmed_at
|
28
|
+
end
|
29
|
+
|
30
|
+
test 'should clear confirmation token while confirming a user' do
|
31
|
+
user = create_user
|
32
|
+
assert_present user.confirmation_token
|
33
|
+
user.confirm!
|
34
|
+
assert_nil user.confirmation_token
|
35
|
+
end
|
36
|
+
|
37
|
+
test 'should verify whether a user is confirmed or not' do
|
38
|
+
assert_not new_user.confirmed?
|
39
|
+
user = create_user
|
40
|
+
assert_not user.confirmed?
|
41
|
+
user.confirm!
|
42
|
+
assert user.confirmed?
|
43
|
+
end
|
44
|
+
|
45
|
+
test 'should not confirm a user already confirmed' do
|
46
|
+
user = create_user
|
47
|
+
assert user.confirm!
|
48
|
+
assert_nil user.errors[:email]
|
49
|
+
|
50
|
+
assert_not user.confirm!
|
51
|
+
assert_match /already confirmed/, user.errors[:email]
|
52
|
+
end
|
53
|
+
|
54
|
+
test 'should find and confirm an user automatically' do
|
55
|
+
user = create_user
|
56
|
+
confirmed_user = User.confirm_by_token(user.confirmation_token)
|
57
|
+
assert_equal confirmed_user, user
|
58
|
+
assert user.reload.confirmed?
|
59
|
+
end
|
60
|
+
|
61
|
+
test 'should return a new record with errors when a invalid token is given' do
|
62
|
+
confirmed_user = User.confirm_by_token('invalid_confirmation_token')
|
63
|
+
assert confirmed_user.new_record?
|
64
|
+
assert_match /invalid/, confirmed_user.errors[:confirmation_token]
|
65
|
+
end
|
66
|
+
|
67
|
+
test 'should return a new record with errors when a blank token is given' do
|
68
|
+
confirmed_user = User.confirm_by_token('')
|
69
|
+
assert confirmed_user.new_record?
|
70
|
+
assert_match /blank/, confirmed_user.errors[:confirmation_token]
|
71
|
+
end
|
72
|
+
|
73
|
+
test 'should generate errors for a user email if user is already confirmed' do
|
74
|
+
user = create_user
|
75
|
+
user.confirmed_at = Time.now
|
76
|
+
user.save
|
77
|
+
confirmed_user = User.confirm_by_token(user.confirmation_token)
|
78
|
+
assert confirmed_user.confirmed?
|
79
|
+
assert confirmed_user.errors[:email]
|
80
|
+
end
|
81
|
+
|
82
|
+
test 'should authenticate a confirmed user' do
|
83
|
+
user = create_user
|
84
|
+
user.confirm!
|
85
|
+
authenticated_user = User.authenticate(:email => user.email, :password => user.password)
|
86
|
+
assert_equal authenticated_user, user
|
87
|
+
end
|
88
|
+
|
89
|
+
test 'should send confirmation instructions by email' do
|
90
|
+
assert_email_sent do
|
91
|
+
create_user
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
test 'should not send confirmation when trying to save an invalid user' do
|
96
|
+
assert_email_not_sent do
|
97
|
+
user = new_user
|
98
|
+
user.stubs(:valid?).returns(false)
|
99
|
+
user.save
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
test 'should not generate a new token neither send e-mail if skip_confirmation! is invoked' do
|
104
|
+
user = new_user
|
105
|
+
user.skip_confirmation!
|
106
|
+
|
107
|
+
assert_email_not_sent do
|
108
|
+
user.save!
|
109
|
+
assert_nil user.confirmation_token
|
110
|
+
assert_not_nil user.confirmed_at
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
test 'should find a user to send confirmation instructions' do
|
115
|
+
user = create_user
|
116
|
+
confirmation_user = User.send_confirmation_instructions(:email => user.email)
|
117
|
+
assert_equal confirmation_user, user
|
118
|
+
end
|
119
|
+
|
120
|
+
test 'should return a new user if no email was found' do
|
121
|
+
confirmation_user = User.send_confirmation_instructions(:email => "invalid@email.com")
|
122
|
+
assert confirmation_user.new_record?
|
123
|
+
end
|
124
|
+
|
125
|
+
test 'should add error to new user email if no email was found' do
|
126
|
+
confirmation_user = User.send_confirmation_instructions(:email => "invalid@email.com")
|
127
|
+
assert confirmation_user.errors[:email]
|
128
|
+
assert_equal 'not found', confirmation_user.errors[:email]
|
129
|
+
end
|
130
|
+
|
131
|
+
test 'should send email instructions for the user confirm it\'s email' do
|
132
|
+
user = create_user
|
133
|
+
assert_email_sent do
|
134
|
+
User.send_confirmation_instructions(:email => user.email)
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
test 'should always have confirmation token when email is sent' do
|
139
|
+
user = new_user
|
140
|
+
user.instance_eval { def confirmation_required?; false end }
|
141
|
+
user.save
|
142
|
+
user.send_confirmation_instructions
|
143
|
+
assert_not_nil user.reload.confirmation_token
|
144
|
+
end
|
145
|
+
|
146
|
+
test 'should not resend email instructions if the user change his email' do
|
147
|
+
user = create_user
|
148
|
+
user.email = 'new_test@example.com'
|
149
|
+
assert_email_not_sent do
|
150
|
+
user.save!
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
test 'should not reset confirmation status or token when updating email' do
|
155
|
+
user = create_user
|
156
|
+
user.confirm!
|
157
|
+
user.email = 'new_test@example.com'
|
158
|
+
user.save!
|
159
|
+
|
160
|
+
user.reload
|
161
|
+
assert user.confirmed?
|
162
|
+
assert_nil user.confirmation_token
|
163
|
+
end
|
164
|
+
|
165
|
+
test 'should not be able to send instructions if the user is already confirmed' do
|
166
|
+
user = create_user
|
167
|
+
user.confirm!
|
168
|
+
assert_not user.resend_confirmation_token
|
169
|
+
assert user.confirmed?
|
170
|
+
assert_equal 'already confirmed', user.errors[:email]
|
171
|
+
end
|
172
|
+
|
173
|
+
test 'confirm time should fallback to devise confirm in default configuration' do
|
174
|
+
swap Devise, :confirm_within => 1.day do
|
175
|
+
user = new_user
|
176
|
+
user.confirmation_sent_at = 2.days.ago
|
177
|
+
assert_not user.active?
|
178
|
+
|
179
|
+
Devise.confirm_within = 3.days
|
180
|
+
assert user.active?
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
test 'should be active when confirmation sent at is not overpast' do
|
185
|
+
swap Devise, :confirm_within => 5.days do
|
186
|
+
Devise.confirm_within = 5.days
|
187
|
+
user = create_user
|
188
|
+
|
189
|
+
user.confirmation_sent_at = 4.days.ago
|
190
|
+
assert user.active?
|
191
|
+
|
192
|
+
user.confirmation_sent_at = 5.days.ago
|
193
|
+
assert_not user.active?
|
194
|
+
end
|
195
|
+
end
|
196
|
+
|
197
|
+
test 'should be active when already confirmed' do
|
198
|
+
user = create_user
|
199
|
+
assert_not user.confirmed?
|
200
|
+
assert_not user.active?
|
201
|
+
|
202
|
+
user.confirm!
|
203
|
+
assert user.confirmed?
|
204
|
+
assert user.active?
|
205
|
+
end
|
206
|
+
|
207
|
+
test 'should not be active when confirm in is zero' do
|
208
|
+
Devise.confirm_within = 0.days
|
209
|
+
user = create_user
|
210
|
+
user.confirmation_sent_at = Date.today
|
211
|
+
assert_not user.reload.active?
|
212
|
+
end
|
213
|
+
|
214
|
+
test 'should not be active without confirmation' do
|
215
|
+
user = create_user
|
216
|
+
user.confirmation_sent_at = nil
|
217
|
+
user.save
|
218
|
+
assert_not user.reload.active?
|
219
|
+
end
|
220
|
+
|
221
|
+
test 'should be active without confirmation when confirmation is not required' do
|
222
|
+
user = create_user
|
223
|
+
user.instance_eval { def confirmation_required?; false end }
|
224
|
+
user.confirmation_sent_at = nil
|
225
|
+
user.save
|
226
|
+
assert user.reload.active?
|
227
|
+
end
|
228
|
+
end
|