]> git.openstreetmap.org Git - rails.git/blob - test/unit/password_hash_test.rb
Replace the country table with a static XML countries file
[rails.git] / test / unit / password_hash_test.rb
1 require File.dirname(__FILE__) + '/../test_helper'
2
3 class PasswordHashTest < ActiveSupport::TestCase
4   def test_md5_without_salt
5     assert_equal true, PasswordHash.check("5f4dcc3b5aa765d61d8327deb882cf99", nil, "password")
6     assert_equal false, PasswordHash.check("5f4dcc3b5aa765d61d8327deb882cf99", nil, "wrong")
7     assert_equal true, PasswordHash.upgrade?("5f4dcc3b5aa765d61d8327deb882cf99", nil)
8   end
9
10   def test_md5_with_salt
11     assert_equal true, PasswordHash.check("67a1e09bb1f83f5007dc119c14d663aa", "salt", "password")
12     assert_equal false, PasswordHash.check("67a1e09bb1f83f5007dc119c14d663aa", "salt", "wrong")
13     assert_equal false, PasswordHash.check("67a1e09bb1f83f5007dc119c14d663aa", "wrong", "password")
14     assert_equal true, PasswordHash.upgrade?("67a1e09bb1f83f5007dc119c14d663aa", "salt")
15   end
16
17   def test_default
18     hash1, salt1 = PasswordHash.create("password")
19     hash2, salt2 = PasswordHash.create("password")
20     assert_not_equal hash1, hash2
21     assert_not_equal salt1, salt2
22     assert_equal true, PasswordHash.check(hash1, salt1, "password")
23     assert_equal false, PasswordHash.check(hash1, salt1, "wrong")
24     assert_equal true, PasswordHash.check(hash2, salt2, "password")
25     assert_equal false, PasswordHash.check(hash2, salt2, "wrong")
26     assert_equal false, PasswordHash.upgrade?(hash1, salt1)
27     assert_equal false, PasswordHash.upgrade?(hash2, salt2)
28   end
29 end