]> projects.mako.cc - selectricity-live/blob - vendor/plugins/login_engine/test/unit/user_test.rb
12fff2d88e493c40c4041021ee36e42c639db883
[selectricity-live] / vendor / plugins / login_engine / test / unit / user_test.rb
1 require File.dirname(__FILE__) + '/../test_helper'
2 class UserTest < Test::Unit::TestCase
3
4   # load the fixture into the developer-specified table using the custom
5   # 'fixture' method.
6   fixture :users, :table_name => LoginEngine.config(:user_table), :class_name => "User"
7  
8   def setup
9     LoginEngine::CONFIG[:salt] = "test-salt"
10   end 
11     
12   def test_auth   
13     assert_equal users(:bob), User.authenticate("bob", "atest")    
14     assert_nil User.authenticate("nonbob", "atest")
15   end
16
17
18   def test_passwordchange
19         
20     users(:longbob).change_password("nonbobpasswd")
21     users(:longbob).save
22     assert_equal users(:longbob), User.authenticate("longbob", "nonbobpasswd")
23     assert_nil User.authenticate("longbob", "alongtest")
24     users(:longbob).change_password("alongtest")
25     users(:longbob).save
26     assert_equal users(:longbob), User.authenticate("longbob", "alongtest")
27     assert_nil User.authenticate("longbob", "nonbobpasswd")
28         
29   end
30   
31   def test_disallowed_passwords
32     
33     u = User.new    
34     u.login = "nonbob"
35     u.email = "bobs@email.com"
36
37     u.change_password("tiny")
38     assert !u.save     
39     assert u.errors.invalid?('password')
40
41     u.change_password("hugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehuge")
42     assert !u.save     
43     assert u.errors.invalid?('password')
44         
45     u.change_password("")
46     assert !u.save    
47     assert u.errors.invalid?('password')
48         
49     u.change_password("bobs_secure_password")
50     assert u.save     
51     assert u.errors.empty?
52         
53   end
54   
55   def test_bad_logins
56
57     u = User.new  
58     u.change_password("bobs_secure_password")
59     u.email = "bobs@email.com"
60
61     u.login = "x"
62     assert !u.save     
63     assert u.errors.invalid?('login')
64     
65     u.login = "hugebobhugebobhugebobhugebobhugebobhugebobhugebobhugebobhugebobhugebobhugebobhugebobhugebobhugebobhugebobhugebobhugebobhugebobhugebobhugebobhugebobhugebobhugebobhugebobhugebobhugebobhug"
66     assert !u.save     
67     assert u.errors.invalid?('login')
68
69     u.login = ""
70     assert !u.save
71     assert u.errors.invalid?('login')
72
73     u.login = "okbob"
74     assert u.save  
75     assert u.errors.empty?
76       
77   end
78
79
80   def test_collision
81     u = User.new
82     u.login = "existingbob"
83     u.change_password("bobs_secure_password")
84     assert !u.save
85   end
86
87
88   def test_create
89     u = User.new
90     u.login = "nonexistingbob"
91     u.change_password("bobs_secure_password")
92     u.email = "bobs@email.com"
93       
94     assert u.save  
95     
96   end
97
98   def test_email_should_be_nominally_valid
99     u = User.new
100     u.login = "email_test"
101     u.change_password("email_test_password")
102
103     assert !u.save
104     assert u.errors.invalid?('email')
105
106     u.email = "invalid_email"
107     assert !u.save
108     assert u.errors.invalid?('email')
109
110     u.email = "valid@email.com"
111     assert u.save
112   end
113
114 end

Benjamin Mako Hill || Want to submit a patch?