Sha256: 4d1d5677c23871265f3454d23699cdfe4a038613f5552c1bc3dcc9c21f7f9687

Contents?: true

Size: 1.4 KB

Versions: 62

Compression:

Stored size: 1.4 KB

Contents

require 'test_helper'

module Workarea
  class User
    class RecentPasswordTest < TestCase
      def test_clean
        user = create_user
        passwords = []

        (Workarea.config.password_history_length + 1).times do
          passwords << RecentPassword.create!(
            user: user,
            password: SecureRandom.hex
          )
        end

        RecentPassword.clean(user)

        assert_equal(
          Workarea.config.password_history_length,
          user.recent_passwords.length
        )

        assert_raise(Mongoid::Errors::DocumentNotFound) { passwords.last.reload }
      end

      def test_save_password_digest
        password = 'Password!1'
        cost = if ActiveModel::SecurePassword.min_cost
                 BCrypt::Engine::MIN_COST
               else
                 BCrypt::Engine.cost
               end
        password_digest = BCrypt::Password.create(password, cost: cost).to_s
        user = User.new(
          email: 'admin@othersite.com',
          password_digest: password_digest
        )

        assert_nil(user.password)
        refute_nil(user.password_digest)
        assert_equal(password_digest, user.password_digest)
        assert(user.save!)
        refute_empty(user.recent_passwords)
        refute_nil(user.recent_passwords.first.password_digest)
        assert_equal(password_digest, user.recent_passwords.first.password_digest)
      end
    end
  end
end

Version data entries

62 entries across 62 versions & 1 rubygems

Version Path
workarea-core-3.4.27 test/models/workarea/user/recent_password_test.rb
workarea-core-3.5.4 test/models/workarea/user/recent_password_test.rb
workarea-core-3.4.26 test/models/workarea/user/recent_password_test.rb
workarea-core-3.5.3 test/models/workarea/user/recent_password_test.rb
workarea-core-3.4.25 test/models/workarea/user/recent_password_test.rb
workarea-core-3.5.2 test/models/workarea/user/recent_password_test.rb
workarea-core-3.4.24 test/models/workarea/user/recent_password_test.rb
workarea-core-3.5.1 test/models/workarea/user/recent_password_test.rb
workarea-core-3.4.23 test/models/workarea/user/recent_password_test.rb
workarea-core-3.4.22 test/models/workarea/user/recent_password_test.rb
workarea-core-3.5.0 test/models/workarea/user/recent_password_test.rb
workarea-core-3.4.21 test/models/workarea/user/recent_password_test.rb
workarea-core-3.5.0.beta.1 test/models/workarea/user/recent_password_test.rb
workarea-core-3.4.20 test/models/workarea/user/recent_password_test.rb
workarea-core-3.4.19 test/models/workarea/user/recent_password_test.rb
workarea-core-3.4.18 test/models/workarea/user/recent_password_test.rb
workarea-core-3.4.17 test/models/workarea/user/recent_password_test.rb
workarea-core-3.4.16 test/models/workarea/user/recent_password_test.rb
workarea-core-3.4.15 test/models/workarea/user/recent_password_test.rb
workarea-core-3.4.14 test/models/workarea/user/recent_password_test.rb