mirror of
https://github.com/TracksApp/tracks.git
synced 2026-02-04 06:51:48 +01:00
* Introduce Tracks::Config class to wrap environment.rb config settings * Remove unused admin and index actions from user_controller * Introduce flash partial and standardize on symbol keys for the flash hash * Replace usages of render_partial with render :partial Two new authentication options! These probably need documentation... * Introduce LDAP authentication option (see configuration in environment.rb.tmpl). Thanks to Jeremy Evans for creating the SimpleLdapAuthenticator plugin. Note: the ldap auth integration test is likely to be fragile. Works for me on OS X with openldap, but your mileage may vary. * Introduce Open ID authentication option (see configuration in environment.rb.tmpl and http://openid.net for more info). Thanks to East Media for the Open ID Consumer Plugin. In environment.rb, you can enable any combination of the three auth options. If you have more than one selected, users can opt between them via their preferences pages. To play with the Open ID auth, you can get an identity at pip.verisignlabs.com. Note that there are some new migrations to support the new authentication options, so don't forget to rake migrate! git-svn-id: http://www.rousette.org.uk/svn/tracks-repos/trunk@334 a4c988fc-2ded-0310-b66e-134b36920a42
138 lines
4.4 KiB
Ruby
138 lines
4.4 KiB
Ruby
require File.dirname(__FILE__) + '/../test_helper'
|
|
|
|
class UserTest < Test::Unit::TestCase
|
|
fixtures :users
|
|
|
|
def setup
|
|
assert_equal "test", ENV['RAILS_ENV']
|
|
assert_equal "change-me", Tracks::Config.salt
|
|
@admin_user = User.find(1)
|
|
@other_user = User.find(2)
|
|
end
|
|
|
|
# Test an admin user model
|
|
#
|
|
def test_admin
|
|
assert_kind_of User, @admin_user
|
|
assert_equal 1, @admin_user.id
|
|
assert_equal "admin", @admin_user.login
|
|
assert_equal "#{Digest::SHA1.hexdigest("#{Tracks::Config.salt}--abracadabra--")}", @admin_user.password
|
|
assert_not_nil @admin_user.word
|
|
assert @admin_user.is_admin
|
|
end
|
|
|
|
# Test a non-admin user model
|
|
def test_non_admin
|
|
assert_kind_of User, @other_user
|
|
assert_equal 2, @other_user.id
|
|
assert_equal "jane", @other_user.login
|
|
assert_equal "#{Digest::SHA1.hexdigest("#{Tracks::Config.salt}--sesame--")}", @other_user.password
|
|
assert_not_nil @other_user.word
|
|
assert @other_user.is_admin == false || @other_user.is_admin == 0
|
|
end
|
|
|
|
# ============================================
|
|
# Validations
|
|
# ============================================
|
|
|
|
# Test a password shorter than 5 characters
|
|
#
|
|
def test_validate_short_password
|
|
assert_equal "#{Digest::SHA1.hexdigest("#{Tracks::Config.salt}--sesame--")}", @other_user.password
|
|
@other_user.password = "four"
|
|
assert !@other_user.save
|
|
assert_equal 1, @other_user.errors.count
|
|
assert_equal "is too short (minimum is 5 characters)", @other_user.errors.on(:password)
|
|
end
|
|
|
|
# Test a password longer than 40 characters
|
|
#
|
|
def test_validate_long_password
|
|
assert_equal "#{Digest::SHA1.hexdigest("#{Tracks::Config.salt}--sesame--")}", @other_user.password
|
|
@other_user.password = generate_random_string(41)
|
|
assert !@other_user.save
|
|
assert_equal 1, @other_user.errors.count
|
|
assert_equal "is too long (maximum is 40 characters)", @other_user.errors.on(:password)
|
|
end
|
|
|
|
# Test that correct length password is valid
|
|
#
|
|
def test_validate_correct_length_password
|
|
assert_equal "#{Digest::SHA1.hexdigest("#{Tracks::Config.salt}--sesame--")}", @other_user.password
|
|
@other_user.password = generate_random_string(6)
|
|
assert @other_user.save
|
|
end
|
|
|
|
# Test a missing password
|
|
#
|
|
def test_validate_missing_password
|
|
assert_equal 2, @other_user.id
|
|
@other_user.password = ""
|
|
assert !@other_user.save
|
|
assert_equal 2, @other_user.errors.count
|
|
assert_equal ["is too short (minimum is 5 characters)", "can't be blank"], @other_user.errors.on(:password)
|
|
end
|
|
|
|
# Test a login shorter than 3 characters
|
|
#
|
|
def test_validate_short_login
|
|
assert_equal "jane", @other_user.login
|
|
@other_user.login = "ba"
|
|
assert !@other_user.save
|
|
assert_equal 1, @other_user.errors.count
|
|
assert_equal "is too short (minimum is 3 characters)", @other_user.errors.on(:login)
|
|
end
|
|
|
|
# Test a login longer than 80 characters
|
|
#
|
|
def test_validate_long_login
|
|
assert_equal "jane", @other_user.login
|
|
@other_user.login = generate_random_string(81)
|
|
assert !@other_user.save
|
|
assert_equal 1, @other_user.errors.count
|
|
assert_equal "is too long (maximum is 80 characters)", @other_user.errors.on(:login)
|
|
end
|
|
|
|
# Test that correct length login is valid
|
|
#
|
|
def test_validate_correct_length_login
|
|
assert_equal "jane", @other_user.login
|
|
@other_user.login = generate_random_string(6)
|
|
assert @other_user.save
|
|
end
|
|
|
|
# Test a missing login
|
|
#
|
|
def test_validate_missing_login
|
|
assert_equal 2, @other_user.id
|
|
@other_user.login = ""
|
|
assert !@other_user.save
|
|
assert_equal 2, @other_user.errors.count
|
|
assert_equal ["is too short (minimum is 3 characters)", "can't be blank"], @other_user.errors.on(:login)
|
|
end
|
|
|
|
def test_display_name_with_first_and_last_name_set
|
|
@other_user.first_name = "Jane"
|
|
@other_user.last_name = "Doe"
|
|
assert_equal "Jane Doe", @other_user.display_name
|
|
end
|
|
|
|
def test_display_name_with_first_name_set
|
|
@other_user.first_name = "Jane"
|
|
@other_user.last_name = nil
|
|
assert_equal "Jane", @other_user.display_name
|
|
end
|
|
|
|
def test_display_name_with_last_name_set
|
|
@other_user.first_name = nil
|
|
@other_user.last_name = "Doe"
|
|
assert_equal "Doe", @other_user.display_name
|
|
end
|
|
|
|
def test_display_name_with_neither_first_nor_last_name_set
|
|
@other_user.first_name = nil
|
|
@other_user.last_name = nil
|
|
assert_equal @other_user.login, @other_user.display_name
|
|
end
|
|
|
|
end
|