1 require File.dirname(__FILE__) + '/../test_helper'
2 class UserTest < Test::Unit::TestCase
4 # load the fixture into the developer-specified table using the custom
6 fixture :users, :table_name => LoginEngine.config(:user_table), :class_name => "User"
9 LoginEngine::CONFIG[:salt] = "test-salt"
13 assert_equal users(:bob), User.authenticate("bob", "atest")
14 assert_nil User.authenticate("nonbob", "atest")
18 def test_passwordchange
20 users(:longbob).change_password("nonbobpasswd")
22 assert_equal users(:longbob), User.authenticate("longbob", "nonbobpasswd")
23 assert_nil User.authenticate("longbob", "alongtest")
24 users(:longbob).change_password("alongtest")
26 assert_equal users(:longbob), User.authenticate("longbob", "alongtest")
27 assert_nil User.authenticate("longbob", "nonbobpasswd")
31 def test_disallowed_passwords
35 u.email = "bobs@email.com"
37 u.change_password("tiny")
39 assert u.errors.invalid?('password')
41 u.change_password("hugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehuge")
43 assert u.errors.invalid?('password')
47 assert u.errors.invalid?('password')
49 u.change_password("bobs_secure_password")
51 assert u.errors.empty?
58 u.change_password("bobs_secure_password")
59 u.email = "bobs@email.com"
63 assert u.errors.invalid?('login')
65 u.login = "hugebobhugebobhugebobhugebobhugebobhugebobhugebobhugebobhugebobhugebobhugebobhugebobhugebobhugebobhugebobhugebobhugebobhugebobhugebobhugebobhugebobhugebobhugebobhugebobhugebobhugebobhug"
67 assert u.errors.invalid?('login')
71 assert u.errors.invalid?('login')
75 assert u.errors.empty?
82 u.login = "existingbob"
83 u.change_password("bobs_secure_password")
90 u.login = "nonexistingbob"
91 u.change_password("bobs_secure_password")
92 u.email = "bobs@email.com"
98 def test_email_should_be_nominally_valid
100 u.login = "email_test"
101 u.change_password("email_test_password")
104 assert u.errors.invalid?('email')
106 u.email = "invalid_email"
108 assert u.errors.invalid?('email')
110 u.email = "valid@email.com"