Mercurial > hg > soundsoftware-site
comparison test/unit/user_test.rb @ 245:051f544170fe
* Update to SVN trunk revision 4993
author | Chris Cannam |
---|---|
date | Thu, 03 Mar 2011 11:42:28 +0000 |
parents | 0579821a129a |
children | cbce1fd3b1b7 |
comparison
equal
deleted
inserted
replaced
244:8972b600f4fb | 245:051f544170fe |
---|---|
359 assert user.save | 359 assert user.save |
360 | 360 |
361 user = User.try_to_login("admin", "hello") | 361 user = User.try_to_login("admin", "hello") |
362 assert_kind_of User, user | 362 assert_kind_of User, user |
363 assert_equal "admin", user.login | 363 assert_equal "admin", user.login |
364 assert_equal User.hash_password("hello"), user.hashed_password | |
365 end | 364 end |
366 | 365 |
367 def test_name_format | 366 def test_name_format |
368 assert_equal 'Smith, John', @jsmith.name(:lastname_coma_firstname) | 367 assert_equal 'Smith, John', @jsmith.name(:lastname_coma_firstname) |
369 Setting.user_format = :firstname_lastname | 368 Setting.user_format = :firstname_lastname |
379 @jsmith.status = User::STATUS_LOCKED | 378 @jsmith.status = User::STATUS_LOCKED |
380 assert @jsmith.save | 379 assert @jsmith.save |
381 | 380 |
382 user = User.try_to_login("jsmith", "jsmith") | 381 user = User.try_to_login("jsmith", "jsmith") |
383 assert_equal nil, user | 382 assert_equal nil, user |
383 end | |
384 | |
385 context ".try_to_login" do | |
386 context "with good credentials" do | |
387 should "return the user" do | |
388 user = User.try_to_login("admin", "admin") | |
389 assert_kind_of User, user | |
390 assert_equal "admin", user.login | |
391 end | |
392 end | |
393 | |
394 context "with wrong credentials" do | |
395 should "return nil" do | |
396 assert_nil User.try_to_login("admin", "foo") | |
397 end | |
398 end | |
384 end | 399 end |
385 | 400 |
386 if ldap_configured? | 401 if ldap_configured? |
387 context "#try_to_login using LDAP" do | 402 context "#try_to_login using LDAP" do |
388 context "with failed connection to the LDAP server" do | 403 context "with failed connection to the LDAP server" do |
725 | 740 |
726 context "other events" do | 741 context "other events" do |
727 should 'be added and tested' | 742 should 'be added and tested' |
728 end | 743 end |
729 end | 744 end |
745 | |
746 def test_salt_unsalted_passwords | |
747 # Restore a user with an unsalted password | |
748 user = User.find(1) | |
749 user.salt = nil | |
750 user.hashed_password = User.hash_password("unsalted") | |
751 user.save! | |
752 | |
753 User.salt_unsalted_passwords! | |
754 | |
755 user.reload | |
756 # Salt added | |
757 assert !user.salt.blank? | |
758 # Password still valid | |
759 assert user.check_password?("unsalted") | |
760 assert_equal user, User.try_to_login(user.login, "unsalted") | |
761 end | |
730 | 762 |
731 if Object.const_defined?(:OpenID) | 763 if Object.const_defined?(:OpenID) |
732 | 764 |
733 def test_setting_identity_url | 765 def test_setting_identity_url |
734 normalized_open_id_url = 'http://example.com/' | 766 normalized_open_id_url = 'http://example.com/' |