devise-security 0.14.2 → 0.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
 - data/README.md +125 -59
 - data/app/controllers/devise/paranoid_verification_code_controller.rb +13 -1
 - data/app/controllers/devise/password_expired_controller.rb +24 -6
 - data/app/views/devise/paranoid_verification_code/show.html.erb +3 -3
 - data/app/views/devise/password_expired/show.html.erb +5 -5
 - data/config/locales/bg.yml +41 -0
 - data/config/locales/by.yml +49 -0
 - data/config/locales/cs.yml +41 -0
 - data/config/locales/de.yml +15 -2
 - data/config/locales/en.yml +15 -2
 - data/config/locales/es.yml +10 -9
 - data/config/locales/fa.yml +41 -0
 - data/config/locales/fr.yml +1 -0
 - data/config/locales/hi.yml +42 -0
 - data/config/locales/it.yml +35 -4
 - data/config/locales/ja.yml +2 -1
 - data/config/locales/nl.yml +41 -0
 - data/config/locales/pt.yml +41 -0
 - data/config/locales/ru.yml +49 -0
 - data/config/locales/tr.yml +1 -0
 - data/config/locales/uk.yml +49 -0
 - data/config/locales/zh_CN.yml +41 -0
 - data/config/locales/zh_TW.yml +41 -0
 - data/lib/devise-security/controllers/helpers.rb +59 -50
 - data/lib/devise-security/hooks/password_expirable.rb +2 -0
 - data/lib/devise-security/hooks/session_limitable.rb +21 -11
 - data/lib/devise-security/models/database_authenticatable_patch.rb +15 -5
 - data/lib/devise-security/models/password_archivable.rb +2 -2
 - data/lib/devise-security/models/password_expirable.rb +5 -1
 - data/lib/devise-security/models/secure_validatable.rb +56 -6
 - data/lib/devise-security/models/session_limitable.rb +10 -1
 - data/lib/devise-security/validators/password_complexity_validator.rb +53 -24
 - data/lib/devise-security/version.rb +1 -1
 - data/lib/devise-security.rb +13 -5
 - data/lib/generators/devise_security/install_generator.rb +3 -3
 - data/lib/generators/templates/{devise-security.rb → devise_security.rb} +6 -1
 - data/test/controllers/test_paranoid_verification_code_controller.rb +68 -0
 - data/test/controllers/test_password_expired_controller.rb +121 -19
 - data/test/controllers/test_security_question_controller.rb +16 -40
 - data/test/dummy/app/assets/config/manifest.js +3 -0
 - data/test/dummy/app/controllers/overrides/paranoid_verification_code_controller.rb +7 -0
 - data/test/dummy/app/controllers/overrides/password_expired_controller.rb +7 -0
 - data/test/dummy/app/controllers/widgets_controller.rb +3 -0
 - data/test/dummy/app/models/application_user_record.rb +2 -1
 - data/test/dummy/app/models/mongoid/confirmable_fields.rb +2 -0
 - data/test/dummy/app/models/mongoid/database_authenticable_fields.rb +4 -3
 - data/test/dummy/app/models/mongoid/expirable_fields.rb +2 -0
 - data/test/dummy/app/models/mongoid/lockable_fields.rb +2 -0
 - data/test/dummy/app/models/mongoid/mappings.rb +4 -2
 - data/test/dummy/app/models/mongoid/omniauthable_fields.rb +2 -0
 - data/test/dummy/app/models/mongoid/paranoid_verification_fields.rb +2 -0
 - data/test/dummy/app/models/mongoid/password_archivable_fields.rb +2 -0
 - data/test/dummy/app/models/mongoid/password_expirable_fields.rb +2 -0
 - data/test/dummy/app/models/mongoid/recoverable_fields.rb +2 -0
 - data/test/dummy/app/models/mongoid/registerable_fields.rb +4 -2
 - data/test/dummy/app/models/mongoid/rememberable_fields.rb +2 -0
 - data/test/dummy/app/models/mongoid/secure_validatable_fields.rb +2 -0
 - data/test/dummy/app/models/mongoid/security_questionable_fields.rb +2 -0
 - data/test/dummy/app/models/mongoid/session_limitable_fields.rb +2 -0
 - data/test/dummy/app/models/mongoid/timeoutable_fields.rb +2 -0
 - data/test/dummy/app/models/mongoid/trackable_fields.rb +2 -0
 - data/test/dummy/app/models/mongoid/validatable_fields.rb +2 -0
 - data/test/dummy/app/models/paranoid_verification_user.rb +26 -0
 - data/test/dummy/app/models/password_expired_user.rb +26 -0
 - data/test/dummy/app/models/user.rb +1 -2
 - data/test/dummy/app/models/widget.rb +1 -3
 - data/test/dummy/app/mongoid/one_user.rb +5 -5
 - data/test/dummy/app/mongoid/user_on_engine.rb +2 -2
 - data/test/dummy/app/mongoid/user_on_main_app.rb +2 -2
 - data/test/dummy/app/mongoid/user_with_validations.rb +3 -3
 - data/test/dummy/app/mongoid/user_without_email.rb +3 -3
 - data/test/dummy/config/application.rb +4 -4
 - data/test/dummy/config/boot.rb +1 -1
 - data/test/dummy/config/environment.rb +1 -1
 - data/test/dummy/config/environments/test.rb +3 -13
 - data/test/dummy/config/initializers/migration_class.rb +1 -8
 - data/test/dummy/config/locales/en.yml +10 -0
 - data/test/dummy/config/mongoid.yml +1 -1
 - data/test/dummy/config/routes.rb +5 -3
 - data/test/dummy/db/migrate/20120508165529_create_tables.rb +3 -3
 - data/test/dummy/lib/shared_expirable_columns.rb +1 -0
 - data/test/dummy/lib/shared_security_questions_fields.rb +1 -0
 - data/test/dummy/lib/shared_user.rb +17 -6
 - data/test/dummy/lib/shared_user_without_email.rb +2 -1
 - data/test/dummy/lib/shared_user_without_omniauth.rb +12 -3
 - data/test/dummy/lib/shared_verification_fields.rb +1 -0
 - data/test/dummy/{app/models/.gitkeep → log/development.log} +0 -0
 - data/test/dummy/log/test.log +101533 -0
 - data/test/integration/test_password_expirable_workflow.rb +53 -0
 - data/test/integration/test_session_limitable_workflow.rb +2 -0
 - data/test/orm/active_record.rb +7 -4
 - data/test/orm/mongoid.rb +2 -1
 - data/test/support/integration_helpers.rb +15 -33
 - data/test/support/mongoid.yml +1 -1
 - data/test/test_compatibility.rb +2 -0
 - data/test/test_complexity_validator.rb +250 -29
 - data/test/test_database_authenticatable_patch.rb +146 -0
 - data/test/test_helper.rb +12 -6
 - data/test/test_install_generator.rb +12 -2
 - data/test/test_paranoid_verification.rb +0 -1
 - data/test/test_password_archivable.rb +34 -11
 - data/test/test_password_expirable.rb +26 -26
 - data/test/test_secure_validatable.rb +292 -50
 - data/test/test_secure_validatable_overrides.rb +185 -0
 - data/test/test_session_limitable.rb +27 -1
 - data/test/tmp/config/initializers/devise_security.rb +49 -0
 - data/test/tmp/config/locales/devise.security_extension.by.yml +49 -0
 - data/test/tmp/config/locales/devise.security_extension.cs.yml +41 -0
 - data/test/tmp/config/locales/devise.security_extension.de.yml +41 -0
 - data/test/tmp/config/locales/devise.security_extension.en.yml +42 -0
 - data/test/tmp/config/locales/devise.security_extension.es.yml +30 -0
 - data/test/tmp/config/locales/devise.security_extension.fa.yml +41 -0
 - data/test/tmp/config/locales/devise.security_extension.fr.yml +30 -0
 - data/test/tmp/config/locales/devise.security_extension.hi.yml +42 -0
 - data/test/tmp/config/locales/devise.security_extension.it.yml +41 -0
 - data/test/tmp/config/locales/devise.security_extension.ja.yml +30 -0
 - data/test/tmp/config/locales/devise.security_extension.nl.yml +41 -0
 - data/test/tmp/config/locales/devise.security_extension.pt.yml +41 -0
 - data/test/tmp/config/locales/devise.security_extension.ru.yml +49 -0
 - data/test/tmp/config/locales/devise.security_extension.tr.yml +18 -0
 - data/test/tmp/config/locales/devise.security_extension.uk.yml +49 -0
 - data/test/tmp/config/locales/devise.security_extension.zh_CN.yml +41 -0
 - data/test/tmp/config/locales/devise.security_extension.zh_TW.yml +41 -0
 - metadata +168 -132
 - data/.codeclimate.yml +0 -63
 - data/.document +0 -5
 - data/.gitignore +0 -43
 - data/.mdlrc +0 -1
 - data/.rubocop.yml +0 -64
 - data/.ruby-version +0 -1
 - data/.travis.yml +0 -39
 - data/Appraisals +0 -35
 - data/Gemfile +0 -10
 - data/Rakefile +0 -27
 - data/devise-security.gemspec +0 -50
 - data/gemfiles/rails_4.2_stable.gemfile +0 -16
 - data/gemfiles/rails_5.0_stable.gemfile +0 -15
 - data/gemfiles/rails_5.1_stable.gemfile +0 -15
 - data/gemfiles/rails_5.2_stable.gemfile +0 -15
 - data/gemfiles/rails_6.0_beta.gemfile +0 -15
 - data/lib/devise-security/orm/active_record.rb +0 -20
 - data/lib/devise-security/schema.rb +0 -66
 - data/test/dummy/app/models/secure_user.rb +0 -9
 
| 
         @@ -6,41 +6,143 @@ class Devise::PasswordExpiredControllerTest < ActionController::TestCase 
     | 
|
| 
       6 
6 
     | 
    
         
             
              include Devise::Test::ControllerHelpers
         
     | 
| 
       7 
7 
     | 
    
         | 
| 
       8 
8 
     | 
    
         
             
              setup do
         
     | 
| 
       9 
     | 
    
         
            -
                @ 
     | 
| 
      
 9 
     | 
    
         
            +
                @controller.class.respond_to :json, :xml
         
     | 
| 
      
 10 
     | 
    
         
            +
                @request.env['devise.mapping'] = Devise.mappings[:user]
         
     | 
| 
       10 
11 
     | 
    
         
             
                @user = User.create!(
         
     | 
| 
       11 
12 
     | 
    
         
             
                  username: 'hello',
         
     | 
| 
       12 
13 
     | 
    
         
             
                  email: 'hello@path.travel',
         
     | 
| 
       13 
14 
     | 
    
         
             
                  password: 'Password4',
         
     | 
| 
       14 
15 
     | 
    
         
             
                  password_changed_at: 4.months.ago,
         
     | 
| 
       15 
     | 
    
         
            -
                  confirmed_at: 5.months.ago
         
     | 
| 
      
 16 
     | 
    
         
            +
                  confirmed_at: 5.months.ago,
         
     | 
| 
       16 
17 
     | 
    
         
             
                )
         
     | 
| 
       17 
18 
     | 
    
         
             
                assert @user.valid?
         
     | 
| 
      
 19 
     | 
    
         
            +
                assert @user.need_change_password?
         
     | 
| 
      
 20 
     | 
    
         
            +
             
     | 
| 
       18 
21 
     | 
    
         
             
                sign_in(@user)
         
     | 
| 
       19 
22 
     | 
    
         
             
              end
         
     | 
| 
       20 
23 
     | 
    
         | 
| 
      
 24 
     | 
    
         
            +
              test 'redirects on show if user not logged in' do
         
     | 
| 
      
 25 
     | 
    
         
            +
                sign_out(@user)
         
     | 
| 
      
 26 
     | 
    
         
            +
                get :show
         
     | 
| 
      
 27 
     | 
    
         
            +
                assert_redirected_to :root
         
     | 
| 
      
 28 
     | 
    
         
            +
              end
         
     | 
| 
      
 29 
     | 
    
         
            +
             
     | 
| 
      
 30 
     | 
    
         
            +
              test 'redirects on show if user does not need password change' do
         
     | 
| 
      
 31 
     | 
    
         
            +
                @user.update(password_changed_at: Time.zone.now)
         
     | 
| 
      
 32 
     | 
    
         
            +
                get :show
         
     | 
| 
      
 33 
     | 
    
         
            +
                assert_redirected_to :root
         
     | 
| 
      
 34 
     | 
    
         
            +
              end
         
     | 
| 
      
 35 
     | 
    
         
            +
             
     | 
| 
       21 
36 
     | 
    
         
             
              test 'should render show' do
         
     | 
| 
       22 
37 
     | 
    
         
             
                get :show
         
     | 
| 
       23 
38 
     | 
    
         
             
                assert_includes @response.body, 'Renew your password'
         
     | 
| 
       24 
39 
     | 
    
         
             
              end
         
     | 
| 
       25 
40 
     | 
    
         | 
| 
       26 
     | 
    
         
            -
              test ' 
     | 
| 
       27 
     | 
    
         
            -
                 
     | 
| 
       28 
     | 
    
         
            -
             
     | 
| 
       29 
     | 
    
         
            -
             
     | 
| 
       30 
     | 
    
         
            -
             
     | 
| 
       31 
     | 
    
         
            -
             
     | 
| 
       32 
     | 
    
         
            -
             
     | 
| 
       33 
     | 
    
         
            -
             
     | 
| 
       34 
     | 
    
         
            -
             
     | 
| 
       35 
     | 
    
         
            -
                 
     | 
| 
       36 
     | 
    
         
            -
             
     | 
| 
       37 
     | 
    
         
            -
             
     | 
| 
       38 
     | 
    
         
            -
             
     | 
| 
       39 
     | 
    
         
            -
             
     | 
| 
       40 
     | 
    
         
            -
             
     | 
| 
      
 41 
     | 
    
         
            +
              test 'redirects on update if user not logged in' do
         
     | 
| 
      
 42 
     | 
    
         
            +
                sign_out(@user)
         
     | 
| 
      
 43 
     | 
    
         
            +
                put :update
         
     | 
| 
      
 44 
     | 
    
         
            +
                assert_redirected_to :root
         
     | 
| 
      
 45 
     | 
    
         
            +
              end
         
     | 
| 
      
 46 
     | 
    
         
            +
             
     | 
| 
      
 47 
     | 
    
         
            +
              test 'redirects on update if user does not need password change' do
         
     | 
| 
      
 48 
     | 
    
         
            +
                @user.update(password_changed_at: Time.zone.now)
         
     | 
| 
      
 49 
     | 
    
         
            +
                put :update
         
     | 
| 
      
 50 
     | 
    
         
            +
                assert_redirected_to :root
         
     | 
| 
      
 51 
     | 
    
         
            +
              end
         
     | 
| 
      
 52 
     | 
    
         
            +
             
     | 
| 
      
 53 
     | 
    
         
            +
              test 'update password with default format' do
         
     | 
| 
      
 54 
     | 
    
         
            +
                put :update,
         
     | 
| 
      
 55 
     | 
    
         
            +
                    params: {
         
     | 
| 
      
 56 
     | 
    
         
            +
                      user: {
         
     | 
| 
      
 57 
     | 
    
         
            +
                        current_password: 'Password4',
         
     | 
| 
      
 58 
     | 
    
         
            +
                        password: 'Password5',
         
     | 
| 
      
 59 
     | 
    
         
            +
                        password_confirmation: 'Password5',
         
     | 
| 
      
 60 
     | 
    
         
            +
                      },
         
     | 
| 
       41 
61 
     | 
    
         
             
                    }
         
     | 
| 
       42 
     | 
    
         
            -
                  }
         
     | 
| 
       43 
     | 
    
         
            -
                end
         
     | 
| 
       44 
62 
     | 
    
         
             
                assert_redirected_to root_path
         
     | 
| 
      
 63 
     | 
    
         
            +
                assert_equal response.media_type, 'text/html'
         
     | 
| 
      
 64 
     | 
    
         
            +
              end
         
     | 
| 
      
 65 
     | 
    
         
            +
             
     | 
| 
      
 66 
     | 
    
         
            +
              test 'password confirmation does not match' do
         
     | 
| 
      
 67 
     | 
    
         
            +
                put :update,
         
     | 
| 
      
 68 
     | 
    
         
            +
                    params: {
         
     | 
| 
      
 69 
     | 
    
         
            +
                      user: {
         
     | 
| 
      
 70 
     | 
    
         
            +
                        current_password: 'Password4',
         
     | 
| 
      
 71 
     | 
    
         
            +
                        password: 'Password5',
         
     | 
| 
      
 72 
     | 
    
         
            +
                        password_confirmation: 'Password6',
         
     | 
| 
      
 73 
     | 
    
         
            +
                      },
         
     | 
| 
      
 74 
     | 
    
         
            +
                    }
         
     | 
| 
      
 75 
     | 
    
         
            +
             
     | 
| 
      
 76 
     | 
    
         
            +
                assert_response :success
         
     | 
| 
      
 77 
     | 
    
         
            +
                assert_template :show
         
     | 
| 
      
 78 
     | 
    
         
            +
                assert_equal response.media_type, 'text/html'
         
     | 
| 
      
 79 
     | 
    
         
            +
                assert_includes(
         
     | 
| 
      
 80 
     | 
    
         
            +
                  response.body,
         
     | 
| 
      
 81 
     | 
    
         
            +
                  'Password confirmation doesn't match Password'
         
     | 
| 
      
 82 
     | 
    
         
            +
                )
         
     | 
| 
      
 83 
     | 
    
         
            +
              end
         
     | 
| 
      
 84 
     | 
    
         
            +
             
     | 
| 
      
 85 
     | 
    
         
            +
              test 'update password using JSON format' do
         
     | 
| 
      
 86 
     | 
    
         
            +
                put :update,
         
     | 
| 
      
 87 
     | 
    
         
            +
                    format: :json,
         
     | 
| 
      
 88 
     | 
    
         
            +
                    params: {
         
     | 
| 
      
 89 
     | 
    
         
            +
                      user: {
         
     | 
| 
      
 90 
     | 
    
         
            +
                        current_password: 'Password4',
         
     | 
| 
      
 91 
     | 
    
         
            +
                        password: 'Password5',
         
     | 
| 
      
 92 
     | 
    
         
            +
                        password_confirmation: 'Password5',
         
     | 
| 
      
 93 
     | 
    
         
            +
                      },
         
     | 
| 
      
 94 
     | 
    
         
            +
                    }
         
     | 
| 
      
 95 
     | 
    
         
            +
                assert_response 204
         
     | 
| 
      
 96 
     | 
    
         
            +
                assert_equal root_url, response.location
         
     | 
| 
      
 97 
     | 
    
         
            +
                assert_nil response.media_type, 'No Content-Type header should be set for No Content response'
         
     | 
| 
      
 98 
     | 
    
         
            +
              end
         
     | 
| 
      
 99 
     | 
    
         
            +
             
     | 
| 
      
 100 
     | 
    
         
            +
              test 'update password using XML format' do
         
     | 
| 
      
 101 
     | 
    
         
            +
                put :update,
         
     | 
| 
      
 102 
     | 
    
         
            +
                    format: :xml,
         
     | 
| 
      
 103 
     | 
    
         
            +
                    params: {
         
     | 
| 
      
 104 
     | 
    
         
            +
                      user: {
         
     | 
| 
      
 105 
     | 
    
         
            +
                        current_password: 'Password4',
         
     | 
| 
      
 106 
     | 
    
         
            +
                        password: 'Password5',
         
     | 
| 
      
 107 
     | 
    
         
            +
                        password_confirmation: 'Password5',
         
     | 
| 
      
 108 
     | 
    
         
            +
                      },
         
     | 
| 
      
 109 
     | 
    
         
            +
                    }
         
     | 
| 
      
 110 
     | 
    
         
            +
                assert_response 204
         
     | 
| 
      
 111 
     | 
    
         
            +
                assert_equal root_url, response.location
         
     | 
| 
      
 112 
     | 
    
         
            +
                assert_nil response.media_type, 'No Content-Type header should be set for No Content response'
         
     | 
| 
      
 113 
     | 
    
         
            +
              end
         
     | 
| 
      
 114 
     | 
    
         
            +
            end
         
     | 
| 
      
 115 
     | 
    
         
            +
             
     | 
| 
      
 116 
     | 
    
         
            +
            class PasswordExpiredCustomRedirectTest < ActionController::TestCase
         
     | 
| 
      
 117 
     | 
    
         
            +
              include Devise::Test::ControllerHelpers
         
     | 
| 
      
 118 
     | 
    
         
            +
              tests Overrides::PasswordExpiredController
         
     | 
| 
      
 119 
     | 
    
         
            +
             
     | 
| 
      
 120 
     | 
    
         
            +
              setup do
         
     | 
| 
      
 121 
     | 
    
         
            +
                @controller.class.respond_to :json, :xml
         
     | 
| 
      
 122 
     | 
    
         
            +
                @request.env['devise.mapping'] = Devise.mappings[:password_expired_user]
         
     | 
| 
      
 123 
     | 
    
         
            +
                @user = PasswordExpiredUser.create!(
         
     | 
| 
      
 124 
     | 
    
         
            +
                  username: 'hello',
         
     | 
| 
      
 125 
     | 
    
         
            +
                  email: 'hello@path.travel',
         
     | 
| 
      
 126 
     | 
    
         
            +
                  password: 'Password4',
         
     | 
| 
      
 127 
     | 
    
         
            +
                  password_changed_at: 4.months.ago,
         
     | 
| 
      
 128 
     | 
    
         
            +
                  confirmed_at: 5.months.ago,
         
     | 
| 
      
 129 
     | 
    
         
            +
                )
         
     | 
| 
      
 130 
     | 
    
         
            +
                assert @user.valid?
         
     | 
| 
      
 131 
     | 
    
         
            +
                assert @user.need_change_password?
         
     | 
| 
      
 132 
     | 
    
         
            +
             
     | 
| 
      
 133 
     | 
    
         
            +
                sign_in(@user)
         
     | 
| 
      
 134 
     | 
    
         
            +
              end
         
     | 
| 
      
 135 
     | 
    
         
            +
             
     | 
| 
      
 136 
     | 
    
         
            +
              test 'update password with custom redirect route' do
         
     | 
| 
      
 137 
     | 
    
         
            +
                put :update,
         
     | 
| 
      
 138 
     | 
    
         
            +
                    params: {
         
     | 
| 
      
 139 
     | 
    
         
            +
                      password_expired_user: {
         
     | 
| 
      
 140 
     | 
    
         
            +
                        current_password: 'Password4',
         
     | 
| 
      
 141 
     | 
    
         
            +
                        password: 'Password5',
         
     | 
| 
      
 142 
     | 
    
         
            +
                        password_confirmation: 'Password5',
         
     | 
| 
      
 143 
     | 
    
         
            +
                      },
         
     | 
| 
      
 144 
     | 
    
         
            +
                    }
         
     | 
| 
      
 145 
     | 
    
         
            +
             
     | 
| 
      
 146 
     | 
    
         
            +
                assert_redirected_to '/cookies'
         
     | 
| 
       45 
147 
     | 
    
         
             
              end
         
     | 
| 
       46 
148 
     | 
    
         
             
            end
         
     | 
| 
         @@ -8,44 +8,28 @@ class TestWithSecurityQuestion < ActionController::TestCase 
     | 
|
| 
       8 
8 
     | 
    
         | 
| 
       9 
9 
     | 
    
         
             
              setup do
         
     | 
| 
       10 
10 
     | 
    
         
             
                @user = SecurityQuestionUser.create!(username: 'hello', email: 'hello@microsoft.com',
         
     | 
| 
       11 
     | 
    
         
            -
             
     | 
| 
      
 11 
     | 
    
         
            +
                                                     password: 'A1234567z!', security_question_answer: 'Right Answer')
         
     | 
| 
       12 
12 
     | 
    
         
             
                @user.lock_access!
         
     | 
| 
       13 
13 
     | 
    
         
             
                assert @user.locked_at.present?
         
     | 
| 
       14 
14 
     | 
    
         
             
                @request.env['devise.mapping'] = Devise.mappings[:security_question_user]
         
     | 
| 
       15 
15 
     | 
    
         
             
              end
         
     | 
| 
       16 
16 
     | 
    
         | 
| 
       17 
17 
     | 
    
         
             
              test 'When security question is enabled, it is inserted correctly' do
         
     | 
| 
       18 
     | 
    
         
            -
                 
     | 
| 
       19 
     | 
    
         
            -
                   
     | 
| 
       20 
     | 
    
         
            -
                     
     | 
| 
       21 
     | 
    
         
            -
             
     | 
| 
       22 
     | 
    
         
            -
             
     | 
| 
       23 
     | 
    
         
            -
                  }
         
     | 
| 
       24 
     | 
    
         
            -
                else
         
     | 
| 
       25 
     | 
    
         
            -
                  post :create, params: {
         
     | 
| 
       26 
     | 
    
         
            -
                    security_question_user: {
         
     | 
| 
       27 
     | 
    
         
            -
                      email: @user.email
         
     | 
| 
       28 
     | 
    
         
            -
                    }, security_question_answer: "wrong answer"
         
     | 
| 
       29 
     | 
    
         
            -
                  }
         
     | 
| 
       30 
     | 
    
         
            -
                end
         
     | 
| 
      
 18 
     | 
    
         
            +
                post :create, params: {
         
     | 
| 
      
 19 
     | 
    
         
            +
                  security_question_user: {
         
     | 
| 
      
 20 
     | 
    
         
            +
                    email: @user.email,
         
     | 
| 
      
 21 
     | 
    
         
            +
                  }, security_question_answer: 'wrong answer'
         
     | 
| 
      
 22 
     | 
    
         
            +
                }
         
     | 
| 
       31 
23 
     | 
    
         
             
                assert_equal I18n.t('devise.invalid_security_question'), flash[:alert]
         
     | 
| 
       32 
24 
     | 
    
         
             
                assert_redirected_to new_security_question_user_unlock_path
         
     | 
| 
       33 
25 
     | 
    
         
             
              end
         
     | 
| 
       34 
26 
     | 
    
         | 
| 
       35 
27 
     | 
    
         
             
              test 'When security_question is valid, it runs as normal' do
         
     | 
| 
       36 
     | 
    
         
            -
                 
     | 
| 
       37 
     | 
    
         
            -
                   
     | 
| 
       38 
     | 
    
         
            -
                     
     | 
| 
       39 
     | 
    
         
            -
             
     | 
| 
       40 
     | 
    
         
            -
             
     | 
| 
       41 
     | 
    
         
            -
                  }
         
     | 
| 
       42 
     | 
    
         
            -
                else
         
     | 
| 
       43 
     | 
    
         
            -
                  post :create, params: {
         
     | 
| 
       44 
     | 
    
         
            -
                    security_question_user: {
         
     | 
| 
       45 
     | 
    
         
            -
                      email: @user.email
         
     | 
| 
       46 
     | 
    
         
            -
                    }, security_question_answer: @user.security_question_answer
         
     | 
| 
       47 
     | 
    
         
            -
                  }
         
     | 
| 
       48 
     | 
    
         
            -
                end
         
     | 
| 
      
 28 
     | 
    
         
            +
                post :create, params: {
         
     | 
| 
      
 29 
     | 
    
         
            +
                  security_question_user: {
         
     | 
| 
      
 30 
     | 
    
         
            +
                    email: @user.email,
         
     | 
| 
      
 31 
     | 
    
         
            +
                  }, security_question_answer: @user.security_question_answer
         
     | 
| 
      
 32 
     | 
    
         
            +
                }
         
     | 
| 
       49 
33 
     | 
    
         | 
| 
       50 
34 
     | 
    
         
             
                assert_equal I18n.t('devise.unlocks.send_instructions'), flash[:notice]
         
     | 
| 
       51 
35 
     | 
    
         
             
                assert_redirected_to new_security_question_user_session_path
         
     | 
| 
         @@ -64,19 +48,11 @@ class TestWithoutSecurityQuestion < ActionController::TestCase 
     | 
|
| 
       64 
48 
     | 
    
         
             
              end
         
     | 
| 
       65 
49 
     | 
    
         | 
| 
       66 
50 
     | 
    
         
             
              test 'When security question is not enabled it is not inserted' do
         
     | 
| 
       67 
     | 
    
         
            -
                 
     | 
| 
       68 
     | 
    
         
            -
                   
     | 
| 
       69 
     | 
    
         
            -
                     
     | 
| 
       70 
     | 
    
         
            -
             
     | 
| 
       71 
     | 
    
         
            -
             
     | 
| 
       72 
     | 
    
         
            -
                  }
         
     | 
| 
       73 
     | 
    
         
            -
                else
         
     | 
| 
       74 
     | 
    
         
            -
                  post :create, params: {
         
     | 
| 
       75 
     | 
    
         
            -
                    user: {
         
     | 
| 
       76 
     | 
    
         
            -
                      email: @user.email
         
     | 
| 
       77 
     | 
    
         
            -
                    }
         
     | 
| 
       78 
     | 
    
         
            -
                  }
         
     | 
| 
       79 
     | 
    
         
            -
                end
         
     | 
| 
      
 51 
     | 
    
         
            +
                post :create, params: {
         
     | 
| 
      
 52 
     | 
    
         
            +
                  user: {
         
     | 
| 
      
 53 
     | 
    
         
            +
                    email: @user.email,
         
     | 
| 
      
 54 
     | 
    
         
            +
                  },
         
     | 
| 
      
 55 
     | 
    
         
            +
                }
         
     | 
| 
       80 
56 
     | 
    
         | 
| 
       81 
57 
     | 
    
         
             
                assert_equal I18n.t('devise.unlocks.send_instructions'), flash[:notice]
         
     | 
| 
       82 
58 
     | 
    
         
             
                assert_redirected_to new_user_session_path
         
     | 
| 
         @@ -1,3 +1,5 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # frozen_string_literal: true
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
       1 
3 
     | 
    
         
             
            module DatabaseAuthenticatableFields
         
     | 
| 
       2 
4 
     | 
    
         
             
              extend ::ActiveSupport::Concern
         
     | 
| 
       3 
5 
     | 
    
         | 
| 
         @@ -6,10 +8,9 @@ module DatabaseAuthenticatableFields 
     | 
|
| 
       6 
8 
     | 
    
         | 
| 
       7 
9 
     | 
    
         
             
                ## Database authenticatable
         
     | 
| 
       8 
10 
     | 
    
         
             
                field :username, type: String
         
     | 
| 
       9 
     | 
    
         
            -
                field :email, type: String, default:  
     | 
| 
       10 
     | 
    
         
            -
                #validates_presence_of :email
         
     | 
| 
      
 11 
     | 
    
         
            +
                field :email, type: String, default: ''
         
     | 
| 
       11 
12 
     | 
    
         | 
| 
       12 
     | 
    
         
            -
                field :encrypted_password, type: String, default:  
     | 
| 
      
 13 
     | 
    
         
            +
                field :encrypted_password, type: String, default: ''
         
     | 
| 
       13 
14 
     | 
    
         
             
                validates_presence_of :encrypted_password
         
     | 
| 
       14 
15 
     | 
    
         | 
| 
       15 
16 
     | 
    
         
             
                include Mongoid::Timestamps
         
     | 
| 
         @@ -1,11 +1,13 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
             
     | 
| 
      
 1 
     | 
    
         
            +
            # frozen_string_literal: true
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            Dir[File.expand_path('*_fields.rb', __dir__)].each { |f| require_relative f }
         
     | 
| 
       2 
4 
     | 
    
         | 
| 
       3 
5 
     | 
    
         
             
            module Mongoid
         
     | 
| 
       4 
6 
     | 
    
         
             
              module Mappings
         
     | 
| 
       5 
7 
     | 
    
         
             
                extend ::ActiveSupport::Concern
         
     | 
| 
       6 
8 
     | 
    
         | 
| 
       7 
9 
     | 
    
         
             
                included do
         
     | 
| 
       8 
     | 
    
         
            -
                   
     | 
| 
      
 10 
     | 
    
         
            +
                  devise_modules.each do |devise_module_name|
         
     | 
| 
       9 
11 
     | 
    
         
             
                    include "#{devise_module_name.to_s.classify}Fields".constantize
         
     | 
| 
       10 
12 
     | 
    
         
             
                  end
         
     | 
| 
       11 
13 
     | 
    
         
             
                end
         
     | 
| 
         @@ -1,3 +1,5 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # frozen_string_literal: true
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
       1 
3 
     | 
    
         
             
            module RegisterableFields
         
     | 
| 
       2 
4 
     | 
    
         
             
              extend ::ActiveSupport::Concern
         
     | 
| 
       3 
5 
     | 
    
         | 
| 
         @@ -5,10 +7,10 @@ module RegisterableFields 
     | 
|
| 
       5 
7 
     | 
    
         
             
                include Mongoid::Document
         
     | 
| 
       6 
8 
     | 
    
         | 
| 
       7 
9 
     | 
    
         
             
                ## Database authenticatable
         
     | 
| 
       8 
     | 
    
         
            -
                field :email, type: String, default:  
     | 
| 
      
 10 
     | 
    
         
            +
                field :email, type: String, default: ''
         
     | 
| 
       9 
11 
     | 
    
         
             
                validates_presence_of :email
         
     | 
| 
       10 
12 
     | 
    
         | 
| 
       11 
     | 
    
         
            -
                field :encrypted_password, type: String, default:  
     | 
| 
      
 13 
     | 
    
         
            +
                field :encrypted_password, type: String, default: ''
         
     | 
| 
       12 
14 
     | 
    
         
             
                validates_presence_of :encrypted_password
         
     | 
| 
       13 
15 
     | 
    
         | 
| 
       14 
16 
     | 
    
         
             
                field :password_changed_at, type: Time
         
     | 
| 
         @@ -0,0 +1,26 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # frozen_string_literal: true
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            class ParanoidVerificationUser < ApplicationUserRecord
         
     | 
| 
      
 4 
     | 
    
         
            +
              devise :database_authenticatable,
         
     | 
| 
      
 5 
     | 
    
         
            +
                     :confirmable,
         
     | 
| 
      
 6 
     | 
    
         
            +
                     :expirable,
         
     | 
| 
      
 7 
     | 
    
         
            +
                     :lockable,
         
     | 
| 
      
 8 
     | 
    
         
            +
                     :omniauthable,
         
     | 
| 
      
 9 
     | 
    
         
            +
                     :paranoid_verification,
         
     | 
| 
      
 10 
     | 
    
         
            +
                     :password_archivable,
         
     | 
| 
      
 11 
     | 
    
         
            +
                     :password_expirable,
         
     | 
| 
      
 12 
     | 
    
         
            +
                     :recoverable,
         
     | 
| 
      
 13 
     | 
    
         
            +
                     :registerable,
         
     | 
| 
      
 14 
     | 
    
         
            +
                     :rememberable,
         
     | 
| 
      
 15 
     | 
    
         
            +
                     :secure_validatable,
         
     | 
| 
      
 16 
     | 
    
         
            +
                     :security_questionable,
         
     | 
| 
      
 17 
     | 
    
         
            +
                     :session_limitable,
         
     | 
| 
      
 18 
     | 
    
         
            +
                     :timeoutable,
         
     | 
| 
      
 19 
     | 
    
         
            +
                     :trackable,
         
     | 
| 
      
 20 
     | 
    
         
            +
                     :validatable
         
     | 
| 
      
 21 
     | 
    
         
            +
             
     | 
| 
      
 22 
     | 
    
         
            +
              if DEVISE_ORM == :mongoid
         
     | 
| 
      
 23 
     | 
    
         
            +
                require './test/dummy/app/models/mongoid/mappings'
         
     | 
| 
      
 24 
     | 
    
         
            +
                include ::Mongoid::Mappings
         
     | 
| 
      
 25 
     | 
    
         
            +
              end
         
     | 
| 
      
 26 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,26 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # frozen_string_literal: true
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            class PasswordExpiredUser < ApplicationUserRecord
         
     | 
| 
      
 4 
     | 
    
         
            +
              devise :database_authenticatable,
         
     | 
| 
      
 5 
     | 
    
         
            +
                     :confirmable,
         
     | 
| 
      
 6 
     | 
    
         
            +
                     :expirable,
         
     | 
| 
      
 7 
     | 
    
         
            +
                     :lockable,
         
     | 
| 
      
 8 
     | 
    
         
            +
                     :omniauthable,
         
     | 
| 
      
 9 
     | 
    
         
            +
                     :paranoid_verification,
         
     | 
| 
      
 10 
     | 
    
         
            +
                     :password_archivable,
         
     | 
| 
      
 11 
     | 
    
         
            +
                     :password_expirable,
         
     | 
| 
      
 12 
     | 
    
         
            +
                     :recoverable,
         
     | 
| 
      
 13 
     | 
    
         
            +
                     :registerable,
         
     | 
| 
      
 14 
     | 
    
         
            +
                     :rememberable,
         
     | 
| 
      
 15 
     | 
    
         
            +
                     :secure_validatable,
         
     | 
| 
      
 16 
     | 
    
         
            +
                     :security_questionable,
         
     | 
| 
      
 17 
     | 
    
         
            +
                     :session_limitable,
         
     | 
| 
      
 18 
     | 
    
         
            +
                     :timeoutable,
         
     | 
| 
      
 19 
     | 
    
         
            +
                     :trackable,
         
     | 
| 
      
 20 
     | 
    
         
            +
                     :validatable
         
     | 
| 
      
 21 
     | 
    
         
            +
             
     | 
| 
      
 22 
     | 
    
         
            +
              if DEVISE_ORM == :mongoid
         
     | 
| 
      
 23 
     | 
    
         
            +
                require './test/dummy/app/models/mongoid/mappings'
         
     | 
| 
      
 24 
     | 
    
         
            +
                include ::Mongoid::Mappings
         
     | 
| 
      
 25 
     | 
    
         
            +
              end
         
     | 
| 
      
 26 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -1,7 +1,6 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            # frozen_string_literal: true
         
     | 
| 
       2 
2 
     | 
    
         | 
| 
       3 
3 
     | 
    
         
             
            class User < ApplicationRecord
         
     | 
| 
       4 
     | 
    
         
            -
             
     | 
| 
       5 
4 
     | 
    
         
             
              devise :database_authenticatable,
         
     | 
| 
       6 
5 
     | 
    
         
             
                     :confirmable,
         
     | 
| 
       7 
6 
     | 
    
         
             
                     :expirable,
         
     | 
| 
         @@ -25,7 +24,7 @@ class User < ApplicationRecord 
     | 
|
| 
       25 
24 
     | 
    
         
             
              if DEVISE_ORM == :mongoid
         
     | 
| 
       26 
25 
     | 
    
         
             
                require './test/dummy/app/models/mongoid/mappings'
         
     | 
| 
       27 
26 
     | 
    
         
             
                include ::Mongoid::Mappings
         
     | 
| 
       28 
     | 
    
         
            -
             
     | 
| 
      
 27 
     | 
    
         
            +
             
     | 
| 
       29 
28 
     | 
    
         
             
                def some_method_calling_mongoid
         
     | 
| 
       30 
29 
     | 
    
         
             
                  Mongoid.logger
         
     | 
| 
       31 
30 
     | 
    
         
             
                end
         
     | 
| 
         @@ -11,16 +11,16 @@ class OneUser 
     | 
|
| 
       11 
11 
     | 
    
         
             
              field :password_changed_at, type: Time
         
     | 
| 
       12 
12 
     | 
    
         
             
              index({ password_changed_at: 1 }, {})
         
     | 
| 
       13 
13 
     | 
    
         | 
| 
       14 
     | 
    
         
            -
               
     | 
| 
       15 
     | 
    
         
            -
               
     | 
| 
       16 
     | 
    
         
            -
               
     | 
| 
      
 14 
     | 
    
         
            +
              field :paranoid_verification_code, type: String
         
     | 
| 
      
 15 
     | 
    
         
            +
              field :paranoid_verified_at, type: Time
         
     | 
| 
      
 16 
     | 
    
         
            +
              field :paranoid_verification_attempt, type: Integer, default: 0
         
     | 
| 
       17 
17 
     | 
    
         | 
| 
       18 
18 
     | 
    
         
             
              field :username, type: String
         
     | 
| 
       19 
19 
     | 
    
         
             
              field :facebook_token, type: String
         
     | 
| 
       20 
20 
     | 
    
         | 
| 
       21 
21 
     | 
    
         
             
              ## Database authenticatable
         
     | 
| 
       22 
     | 
    
         
            -
              field :email,              type: String, default:  
     | 
| 
       23 
     | 
    
         
            -
              field :encrypted_password, type: String, default:  
     | 
| 
      
 22 
     | 
    
         
            +
              field :email,              type: String, default: ''
         
     | 
| 
      
 23 
     | 
    
         
            +
              field :encrypted_password, type: String, default: ''
         
     | 
| 
       24 
24 
     | 
    
         | 
| 
       25 
25 
     | 
    
         
             
              ## Recoverable
         
     | 
| 
       26 
26 
     | 
    
         
             
              field :reset_password_token,   type: String
         
     | 
| 
         @@ -11,8 +11,8 @@ class UserOnEngine 
     | 
|
| 
       11 
11 
     | 
    
         
             
              field :facebook_token, type: String
         
     | 
| 
       12 
12 
     | 
    
         | 
| 
       13 
13 
     | 
    
         
             
              ## Database authenticatable
         
     | 
| 
       14 
     | 
    
         
            -
              field :email, type: String, default:  
     | 
| 
       15 
     | 
    
         
            -
              field :encrypted_password, type: String, default:  
     | 
| 
      
 14 
     | 
    
         
            +
              field :email, type: String, default: ''
         
     | 
| 
      
 15 
     | 
    
         
            +
              field :encrypted_password, type: String, default: ''
         
     | 
| 
       16 
16 
     | 
    
         | 
| 
       17 
17 
     | 
    
         
             
              ## Recoverable
         
     | 
| 
       18 
18 
     | 
    
         
             
              field :reset_password_token, type: String
         
     | 
| 
         @@ -11,8 +11,8 @@ class UserOnMainApp 
     | 
|
| 
       11 
11 
     | 
    
         
             
              field :facebook_token, type: String
         
     | 
| 
       12 
12 
     | 
    
         | 
| 
       13 
13 
     | 
    
         
             
              ## Database authenticatable
         
     | 
| 
       14 
     | 
    
         
            -
              field :email, type: String, default:  
     | 
| 
       15 
     | 
    
         
            -
              field :encrypted_password, type: String, default:  
     | 
| 
      
 14 
     | 
    
         
            +
              field :email, type: String, default: ''
         
     | 
| 
      
 15 
     | 
    
         
            +
              field :encrypted_password, type: String, default: ''
         
     | 
| 
       16 
16 
     | 
    
         | 
| 
       17 
17 
     | 
    
         
             
              ## Recoverable
         
     | 
| 
       18 
18 
     | 
    
         
             
              field :reset_password_token, type: String
         
     | 
| 
         @@ -1,6 +1,6 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            # frozen_string_literal: true
         
     | 
| 
       2 
2 
     | 
    
         | 
| 
       3 
     | 
    
         
            -
            require  
     | 
| 
      
 3 
     | 
    
         
            +
            require 'shared_user'
         
     | 
| 
       4 
4 
     | 
    
         | 
| 
       5 
5 
     | 
    
         
             
            class UserWithValidations
         
     | 
| 
       6 
6 
     | 
    
         
             
              include Mongoid::Document
         
     | 
| 
         @@ -11,8 +11,8 @@ class UserWithValidations 
     | 
|
| 
       11 
11 
     | 
    
         
             
              field :facebook_token, type: String
         
     | 
| 
       12 
12 
     | 
    
         | 
| 
       13 
13 
     | 
    
         
             
              ## Database authenticatable
         
     | 
| 
       14 
     | 
    
         
            -
              field :email, type: String, default:  
     | 
| 
       15 
     | 
    
         
            -
              field :encrypted_password, type: String, default:  
     | 
| 
      
 14 
     | 
    
         
            +
              field :email, type: String, default: ''
         
     | 
| 
      
 15 
     | 
    
         
            +
              field :encrypted_password, type: String, default: ''
         
     | 
| 
       16 
16 
     | 
    
         | 
| 
       17 
17 
     | 
    
         
             
              ## Recoverable
         
     | 
| 
       18 
18 
     | 
    
         
             
              field :reset_password_token, type: String
         
     | 
| 
         @@ -1,6 +1,6 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            # frozen_string_literal: true
         
     | 
| 
       2 
2 
     | 
    
         | 
| 
       3 
     | 
    
         
            -
            require  
     | 
| 
      
 3 
     | 
    
         
            +
            require 'shared_user_without_email'
         
     | 
| 
       4 
4 
     | 
    
         | 
| 
       5 
5 
     | 
    
         
             
            class UserWithoutEmail
         
     | 
| 
       6 
6 
     | 
    
         
             
              include Mongoid::Document
         
     | 
| 
         @@ -11,8 +11,8 @@ class UserWithoutEmail 
     | 
|
| 
       11 
11 
     | 
    
         
             
              field :facebook_token, type: String
         
     | 
| 
       12 
12 
     | 
    
         | 
| 
       13 
13 
     | 
    
         
             
              ## Database authenticatable
         
     | 
| 
       14 
     | 
    
         
            -
              field :email, type: String, default:  
     | 
| 
       15 
     | 
    
         
            -
              field :encrypted_password, type: String, default:  
     | 
| 
      
 14 
     | 
    
         
            +
              field :email, type: String, default: ''
         
     | 
| 
      
 15 
     | 
    
         
            +
              field :encrypted_password, type: String, default: ''
         
     | 
| 
       16 
16 
     | 
    
         | 
| 
       17 
17 
     | 
    
         
             
              ## Recoverable
         
     | 
| 
       18 
18 
     | 
    
         
             
              field :reset_password_token, type: String
         
     | 
| 
         @@ -1,10 +1,10 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            # frozen_string_literal: true
         
     | 
| 
       2 
2 
     | 
    
         | 
| 
       3 
     | 
    
         
            -
            require File.expand_path(' 
     | 
| 
      
 3 
     | 
    
         
            +
            require File.expand_path('boot', __dir__)
         
     | 
| 
       4 
4 
     | 
    
         | 
| 
       5 
5 
     | 
    
         
             
            require 'action_mailer/railtie'
         
     | 
| 
       6 
     | 
    
         
            -
            require  
     | 
| 
       7 
     | 
    
         
            -
            require  
     | 
| 
      
 6 
     | 
    
         
            +
            require 'action_mailer/railtie'
         
     | 
| 
      
 7 
     | 
    
         
            +
            require 'rails/test_unit/railtie'
         
     | 
| 
       8 
8 
     | 
    
         
             
            DEVISE_ORM = ENV.fetch('DEVISE_ORM', 'active_record').to_sym
         
     | 
| 
       9 
9 
     | 
    
         | 
| 
       10 
10 
     | 
    
         
             
            Bundler.require :default, DEVISE_ORM
         
     | 
| 
         @@ -25,6 +25,6 @@ module RailsApp 
     | 
|
| 
       25 
25 
     | 
    
         
             
                config.assets.enabled = true
         
     | 
| 
       26 
26 
     | 
    
         | 
| 
       27 
27 
     | 
    
         
             
                config.assets.version = '1.0'
         
     | 
| 
       28 
     | 
    
         
            -
                config.secret_key_base = ' 
     | 
| 
      
 28 
     | 
    
         
            +
                config.secret_key_base = 'foobar'
         
     | 
| 
       29 
29 
     | 
    
         
             
              end
         
     | 
| 
       30 
30 
     | 
    
         
             
            end
         
     | 
    
        data/test/dummy/config/boot.rb
    CHANGED