adva_user 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README +114 -0
- data/README.md +29 -0
- data/Rakefile +2 -0
- data/adva_user.gemspec +17 -0
- data/app/controllers/admin/base_account_controller.rb +13 -0
- data/app/controllers/admin/users_controller.rb +95 -0
- data/app/controllers/password_controller.rb +36 -0
- data/app/controllers/session_controller.rb +30 -0
- data/app/helpers/users_helper.rb +27 -0
- data/app/models/account.rb +7 -0
- data/app/models/membership.rb +16 -0
- data/app/models/password_mailer.rb +43 -0
- data/app/models/user.rb +106 -0
- data/app/views/admin/users/_form.html.erb +29 -0
- data/app/views/admin/users/_sidebar.html.erb +8 -0
- data/app/views/admin/users/edit.html.erb +7 -0
- data/app/views/admin/users/index.html.erb +13 -0
- data/app/views/admin/users/new.html.erb +5 -0
- data/app/views/admin/users/show.html.erb +27 -0
- data/app/views/layouts/login.html.erb +24 -0
- data/app/views/password/edit.html.erb +14 -0
- data/app/views/password/new.html.erb +13 -0
- data/app/views/password_mailer/reset_password_email.html.erb +3 -0
- data/app/views/password_mailer/updated_password_email.html.erb +1 -0
- data/app/views/session/new.html.erb +17 -0
- data/config/initializers/menus.rb +25 -0
- data/config/routes.rb +14 -0
- data/db/migrate/20080402000001_create_users_table.rb +33 -0
- data/db/migrate/20080402000005_create_memberships_table.rb +13 -0
- data/db/migrate/20090625124502_create_accounts.rb +13 -0
- data/db/migrate/20090625133231_add_account_to_user.rb +10 -0
- data/lib/action_controller/authenticate_anonymous.rb +70 -0
- data/lib/action_controller/authenticate_user.rb +201 -0
- data/lib/active_record/belongs_to_author.rb +37 -0
- data/lib/adva_user.rb +28 -0
- data/lib/adva_user/version.rb +3 -0
- data/lib/login/helper_integration.rb +11 -0
- data/lib/login/mail_config.rb +39 -0
- data/test/contexts.rb +42 -0
- data/test/fixtures.rb +18 -0
- data/test/functional/admin/users_controller_test.rb +176 -0
- data/test/functional/password_controller_test.rb +96 -0
- data/test/functional/session_controller_test.rb +1 -0
- data/test/functional/user_controller_test.rb +95 -0
- data/test/integration/anonymous_login_test.rb +39 -0
- data/test/integration/edit_user_test.rb +44 -0
- data/test/integration/memberships_test.rb +52 -0
- data/test/integration/user_deletion_test.rb +27 -0
- data/test/integration/user_login_test.rb +53 -0
- data/test/integration/user_login_with_remember_me_test.rb +20 -0
- data/test/integration/user_registration_test.rb +64 -0
- data/test/test_helper.rb +1 -0
- data/test/unit/cells/user_cell_test.rb +13 -0
- data/test/unit/helpers/users_helper_test.rb +52 -0
- data/test/unit/models/account_test.rb +21 -0
- data/test/unit/models/anonymous_test.rb +54 -0
- data/test/unit/models/password_mailer_test.rb +26 -0
- data/test/unit/models/user_mailer_test.rb +16 -0
- data/test/unit/models/user_test.rb +173 -0
- data/vendor/gems/authentication/.gitignore +17 -0
- data/vendor/gems/authentication/Gemfile +4 -0
- data/vendor/gems/authentication/LICENSE +22 -0
- data/vendor/gems/authentication/MIT-LICENSE +38 -0
- data/vendor/gems/authentication/README +39 -0
- data/vendor/gems/authentication/README.md +29 -0
- data/vendor/gems/authentication/RUNNING_UNIT_TESTS +13 -0
- data/vendor/gems/authentication/Rakefile +61 -0
- data/vendor/gems/authentication/authentication.gemspec +17 -0
- data/vendor/gems/authentication/lib/authentication.rb +270 -0
- data/vendor/gems/authentication/lib/authentication/active_record_extensions.rb +11 -0
- data/vendor/gems/authentication/lib/authentication/bogus.rb +13 -0
- data/vendor/gems/authentication/lib/authentication/hash_helper.rb +26 -0
- data/vendor/gems/authentication/lib/authentication/ldap.rb +49 -0
- data/vendor/gems/authentication/lib/authentication/remember_me.rb +52 -0
- data/vendor/gems/authentication/lib/authentication/salted_hash.rb +53 -0
- data/vendor/gems/authentication/lib/authentication/single_token.rb +53 -0
- data/vendor/gems/authentication/lib/authentication/version.rb +3 -0
- data/vendor/gems/authentication/lib/radius/dictionary +207 -0
- data/vendor/gems/authentication/test_backup/abstract_unit.rb +30 -0
- data/vendor/gems/authentication/test_backup/active_record_extension_test.rb +17 -0
- data/vendor/gems/authentication/test_backup/authentication_test.rb +231 -0
- data/vendor/gems/authentication/test_backup/database.yml +12 -0
- data/vendor/gems/authentication/test_backup/fixtures/user.rb +3 -0
- data/vendor/gems/authentication/test_backup/fixtures/users.yml +3 -0
- data/vendor/gems/authentication/test_backup/options_test.rb +100 -0
- data/vendor/gems/authentication/test_backup/remember_me_test.rb +41 -0
- data/vendor/gems/authentication/test_backup/salted_hash_test.rb +38 -0
- data/vendor/gems/authentication/test_backup/schema.rb +10 -0
- data/vendor/gems/authentication/test_backup/single_token_test.rb +44 -0
- data/vendor/gems/authentication/test_backup/test_helper.rb +8 -0
- metadata +157 -0
@@ -0,0 +1,30 @@
|
|
1
|
+
# NOTE: Inherited from acts_as_versioned
|
2
|
+
|
3
|
+
$:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
4
|
+
|
5
|
+
require 'test/unit'
|
6
|
+
require File.expand_path(File.join(File.dirname(__FILE__),
|
7
|
+
'..', '..', '..', '..', 'config', 'environment.rb'))
|
8
|
+
require 'active_record/fixtures'
|
9
|
+
|
10
|
+
config = YAML::load(IO.read(File.join(File.dirname(__FILE__), 'database.yml')))
|
11
|
+
ActiveRecord::Base.logger =
|
12
|
+
Logger.new(File.join(File.dirname(__FILE__), 'debug.log'))
|
13
|
+
ActiveRecord::Base.establish_connection(config[ENV['DB'] || 'sqlite3'])
|
14
|
+
|
15
|
+
load(File.join(File.dirname(__FILE__), 'schema.rb'))
|
16
|
+
|
17
|
+
Test::Unit::TestCase.fixture_path = File.join(File.dirname(__FILE__),'fixtures')
|
18
|
+
$LOAD_PATH.unshift(Test::Unit::TestCase.fixture_path)
|
19
|
+
|
20
|
+
class Test::Unit::TestCase #:nodoc:
|
21
|
+
def create_fixtures(*table_names)
|
22
|
+
if block_given?
|
23
|
+
Fixtures.create_fixtures(Test::Unit::TestCase.fixture_path, table_names) { yield }
|
24
|
+
else
|
25
|
+
Fixtures.create_fixtures(Test::Unit::TestCase.fixture_path, table_names)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
require File.join(File.dirname(__FILE__), 'test_helper.rb')
|
30
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require File.join(File.dirname(__FILE__), 'abstract_unit')
|
3
|
+
|
4
|
+
# Test minor enhancements to ActiveRecord
|
5
|
+
class ActiveRecordExtensionTest < Test::Unit::TestCase
|
6
|
+
def test_column_includes
|
7
|
+
assert ColumnTest.includes_all_columns?(:foo, :bar)
|
8
|
+
assert !ColumnTest.includes_all_columns?(:foo, :boo)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
class ColumnTest < ActiveRecord::Base
|
13
|
+
# Fake the column names
|
14
|
+
def self.column_names
|
15
|
+
%w(id name foo bar baz)
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,231 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require File.join(File.dirname(__FILE__), 'abstract_unit')
|
3
|
+
|
4
|
+
# Will test the various dispatch methods mixed into the user model to enable
|
5
|
+
# use of the various authentication and token modules. The main goal of this
|
6
|
+
# test case is not to test the actual authentication but the process of
|
7
|
+
# dispatching the methods to the various classes that implement the actual
|
8
|
+
# authentication.
|
9
|
+
class AuthenticationTest < Test::Unit::TestCase
|
10
|
+
fixtures :users
|
11
|
+
|
12
|
+
def teardown
|
13
|
+
(RecordedUser.authentication_modules + RecordedUser.token_modules).each do |mod|
|
14
|
+
mod.cleanup
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_create_user_without_token_or_password
|
19
|
+
assert_nothing_raised { User.create! :first_name => 'John', :last_name => 'Doe' }
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_authentication_first_success
|
23
|
+
first = RecordedUser.authentication_modules.first
|
24
|
+
first.send_back :authenticate, true
|
25
|
+
|
26
|
+
jack_with_test_password
|
27
|
+
assert @jack.authenticate('test')
|
28
|
+
|
29
|
+
jack_test_auth_message first
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_authentication_first_fail_later_success
|
33
|
+
first = RecordedUser.authentication_modules.first
|
34
|
+
first.send_back :authenticate, false
|
35
|
+
last = RecordedUser.authentication_modules.last
|
36
|
+
last.send_back :authenticate, true
|
37
|
+
|
38
|
+
jack_with_test_password
|
39
|
+
assert @jack.authenticate('test')
|
40
|
+
|
41
|
+
jack_test_auth_message first, last
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_authentication_no_success
|
45
|
+
first = RecordedUser.authentication_modules.first
|
46
|
+
first.send_back :authenticate, false
|
47
|
+
last = RecordedUser.authentication_modules.last
|
48
|
+
last.send_back :authenticate, false
|
49
|
+
|
50
|
+
jack_with_test_password
|
51
|
+
assert !@jack.authenticate('test')
|
52
|
+
|
53
|
+
jack_test_auth_message first, last
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_authentication_with_token
|
57
|
+
first = RecordedUser.token_modules.first
|
58
|
+
first.send_back :authenticate, true
|
59
|
+
|
60
|
+
tok = jack_token
|
61
|
+
assert @jack.authenticate(tok)
|
62
|
+
|
63
|
+
jack_test_token_message tok, first
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_authentication_with_token_first_fail_later_success
|
67
|
+
first = RecordedUser.token_modules.first
|
68
|
+
first.send_back :authenticate, false
|
69
|
+
last = RecordedUser.token_modules.last
|
70
|
+
last.send_back :authenticate, true
|
71
|
+
|
72
|
+
tok = jack_token
|
73
|
+
assert @jack.authenticate(tok)
|
74
|
+
|
75
|
+
jack_test_token_message tok, first, last
|
76
|
+
end
|
77
|
+
|
78
|
+
def test_authentication_with_token_no_success
|
79
|
+
first = RecordedUser.token_modules.first
|
80
|
+
first.send_back :authenticate, false
|
81
|
+
last = RecordedUser.token_modules.last
|
82
|
+
last.send_back :authenticate, false
|
83
|
+
|
84
|
+
tok = jack_token
|
85
|
+
assert_nil tok
|
86
|
+
assert !@jack.authenticate(tok)
|
87
|
+
|
88
|
+
jack_test_token_message tok, first, last
|
89
|
+
end
|
90
|
+
|
91
|
+
def test_assign_token_first_success
|
92
|
+
first = RecordedUser.token_modules.first
|
93
|
+
first.send_back :assign_token, 'test_token'
|
94
|
+
|
95
|
+
tok = jack_token
|
96
|
+
assert_equal 'test_token', tok
|
97
|
+
jack_test_assign_tok_message first
|
98
|
+
end
|
99
|
+
|
100
|
+
def test_assign_token_first_fail_later_success
|
101
|
+
first = RecordedUser.token_modules.first
|
102
|
+
first.send_back :assign_token, nil
|
103
|
+
last = RecordedUser.token_modules.last
|
104
|
+
last.send_back :assign_token, 'last_token'
|
105
|
+
|
106
|
+
tok = jack_token
|
107
|
+
assert_equal 'last_token', tok
|
108
|
+
jack_test_assign_tok_message first, last
|
109
|
+
end
|
110
|
+
|
111
|
+
def test_assign_token_no_success
|
112
|
+
first = RecordedUser.token_modules.first
|
113
|
+
first.send_back :assign_token, nil
|
114
|
+
last = RecordedUser.token_modules.last
|
115
|
+
last.send_back :assign_token, nil
|
116
|
+
|
117
|
+
tok = jack_token
|
118
|
+
assert_nil tok
|
119
|
+
jack_test_assign_tok_message first, last
|
120
|
+
end
|
121
|
+
|
122
|
+
def test_assign_password
|
123
|
+
first = RecordedUser.authentication_modules.first
|
124
|
+
last = RecordedUser.authentication_modules.last
|
125
|
+
|
126
|
+
jane = RecordedUser.new :first_name => 'Jane', :last_name => 'Doe'
|
127
|
+
jane.password = 'testing'
|
128
|
+
jane.save!
|
129
|
+
jane.reload
|
130
|
+
|
131
|
+
[first, last].each do |auth|
|
132
|
+
message = auth.last_message
|
133
|
+
|
134
|
+
assert_equal :assign_password, message.first
|
135
|
+
assert_equal jane, message[1]
|
136
|
+
assert_equal 'testing', message[2]
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
def test_blank_password_does_not_overwrite
|
141
|
+
jenny = User.new :first_name => 'Jenny'
|
142
|
+
jenny.password = 'test'
|
143
|
+
jenny.save!
|
144
|
+
jenny.reload
|
145
|
+
jenny.password = ""
|
146
|
+
jenny.save!
|
147
|
+
jenny.reload
|
148
|
+
assert jenny.authenticate('test')
|
149
|
+
end
|
150
|
+
|
151
|
+
private
|
152
|
+
|
153
|
+
def jack_with_test_password
|
154
|
+
@jack = RecordedUser.new :first_name => 'Jack'
|
155
|
+
@jack.password = 'test'
|
156
|
+
@jack.save!
|
157
|
+
@jack.reload
|
158
|
+
end
|
159
|
+
|
160
|
+
def jack_token
|
161
|
+
@jack = RecordedUser.new :first_name => 'Jack'
|
162
|
+
tok = @jack.assign_token 'test'
|
163
|
+
@jack.save!
|
164
|
+
@jack.reload
|
165
|
+
tok
|
166
|
+
end
|
167
|
+
|
168
|
+
def jack_test_auth_message(*auths)
|
169
|
+
auths.each do |auth|
|
170
|
+
message = auth.last_message
|
171
|
+
assert_equal :authenticate, message.first
|
172
|
+
assert_equal @jack, message[1]
|
173
|
+
assert_equal 'test', message[2]
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
def jack_test_token_message(token, *toks)
|
178
|
+
toks.each do |tok|
|
179
|
+
message = tok.last_message
|
180
|
+
assert_equal :authenticate, message.first
|
181
|
+
assert_equal @jack, message[1]
|
182
|
+
assert_equal token, message[2]
|
183
|
+
end
|
184
|
+
end
|
185
|
+
|
186
|
+
def jack_test_assign_tok_message(*toks)
|
187
|
+
toks.each do |tok|
|
188
|
+
message = tok.last_message
|
189
|
+
assert_equal :assign_token, message.first
|
190
|
+
assert_equal @jack, message[1]
|
191
|
+
assert_equal 3.days.from_now.to_date, message[3].to_date
|
192
|
+
end
|
193
|
+
end
|
194
|
+
end
|
195
|
+
|
196
|
+
# Utility class that will record everything passed in so we can test the
|
197
|
+
# receipt of the various messages with the various arguments. This class is
|
198
|
+
# working both as a cryptor and tokener.
|
199
|
+
class AuthRecorder
|
200
|
+
def initialize(*args)
|
201
|
+
@record = []
|
202
|
+
@returns = {}
|
203
|
+
end
|
204
|
+
def method_missing(meth, *args)
|
205
|
+
@record << [meth, *args]
|
206
|
+
@returns[meth]
|
207
|
+
end
|
208
|
+
def send_back(meth, ret)
|
209
|
+
@returns[meth] = ret
|
210
|
+
end
|
211
|
+
def last_message
|
212
|
+
@record.last
|
213
|
+
end
|
214
|
+
def cleanup
|
215
|
+
@record = []
|
216
|
+
@returns = {}
|
217
|
+
end
|
218
|
+
def assign_token(*args)
|
219
|
+
method_missing :assign_token, *args
|
220
|
+
end
|
221
|
+
def assign_password(*args)
|
222
|
+
method_missing :assign_password, *args
|
223
|
+
end
|
224
|
+
end
|
225
|
+
|
226
|
+
# Class configured to use a few AuthRecorders
|
227
|
+
class RecordedUser < User
|
228
|
+
acts_as_authenticated_user \
|
229
|
+
:authenticate_with => ['AuthRecorder']*2,
|
230
|
+
:token_with => ['AuthRecorder']*2
|
231
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
sqlite:
|
2
|
+
:adapter: sqlite
|
3
|
+
:dbfile: authentication_plugin_test.sqlite.db
|
4
|
+
sqlite3:
|
5
|
+
:adapter: sqlite3
|
6
|
+
:dbfile: authentication_plugin_test.sqlite3.db
|
7
|
+
mysql:
|
8
|
+
:adapter: mysql
|
9
|
+
:host: localhost
|
10
|
+
:username: rails
|
11
|
+
:password:
|
12
|
+
:database: authentication_plugin_test
|
@@ -0,0 +1,100 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require File.join(File.dirname(__FILE__), 'abstract_unit')
|
3
|
+
|
4
|
+
# The goal of this test case is to ensure that the options processing of the
|
5
|
+
# macro function are being handled properly.
|
6
|
+
class OptionsTest < Test::Unit::TestCase
|
7
|
+
|
8
|
+
def test_no_args
|
9
|
+
auth_mods = UserNoArgs.authentication_modules
|
10
|
+
token_mods = UserNoArgs.token_modules
|
11
|
+
|
12
|
+
assert_equal 1, auth_mods.size
|
13
|
+
assert_equal 2, token_mods.size
|
14
|
+
|
15
|
+
assert_instance_of Authentication::SaltedHash, auth_mods.first
|
16
|
+
assert_instance_of Authentication::RememberMe, token_mods.first
|
17
|
+
assert_instance_of Authentication::SingleToken, token_mods.last
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_with_auth_mod
|
21
|
+
auth_mods = UserWithAuthMod.authentication_modules
|
22
|
+
assert_equal 1, auth_mods.size
|
23
|
+
assert_instance_of BasicAuthMod, auth_mods.first
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_with_token_mod
|
27
|
+
token_mods = UserWithTokenMod.token_modules
|
28
|
+
assert_equal 1, token_mods.size
|
29
|
+
assert_instance_of BasicTokenMod, token_mods.first
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_multiple_mods
|
33
|
+
auth_mods = UserWithMultipleMods.authentication_modules
|
34
|
+
assert_equal 2, auth_mods.size
|
35
|
+
assert_instance_of BasicAuthMod, auth_mods.first
|
36
|
+
assert_instance_of Authentication::SaltedHash, auth_mods.last
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_mods_with_args
|
40
|
+
auth_mods = UserWithArgMod.authentication_modules
|
41
|
+
assert_equal 1, auth_mods.size
|
42
|
+
assert_instance_of ArgAuthMod, auth_mods.first
|
43
|
+
assert_equal 1, auth_mods.first.args.size
|
44
|
+
assert_equal 'test', auth_mods.first.args.first[:server]
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_multiple_mods_with_args
|
48
|
+
auth_mods = UserWithMultipleArgs.authentication_modules
|
49
|
+
assert_equal 2, auth_mods.size
|
50
|
+
assert_instance_of ArgAuthMod, auth_mods.first
|
51
|
+
assert_instance_of AnotherArgAuthMod, auth_mods.last
|
52
|
+
assert_equal 1, auth_mods.first.args.size
|
53
|
+
assert_equal 'test', auth_mods.first.args.first[:server]
|
54
|
+
assert_equal 'testing', auth_mods.last.args.first[:server]
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
class UserNoArgs < ActiveRecord::Base
|
59
|
+
acts_as_authenticated_user
|
60
|
+
end
|
61
|
+
|
62
|
+
class BasicAuthMod
|
63
|
+
end
|
64
|
+
|
65
|
+
class UserWithAuthMod < ActiveRecord::Base
|
66
|
+
acts_as_authenticated_user :authenticate_with => 'BasicAuthMod'
|
67
|
+
end
|
68
|
+
|
69
|
+
class BasicTokenMod
|
70
|
+
end
|
71
|
+
|
72
|
+
class UserWithTokenMod < ActiveRecord::Base
|
73
|
+
acts_as_authenticated_user :token_with => 'BasicTokenMod'
|
74
|
+
end
|
75
|
+
|
76
|
+
class UserWithMultipleMods < ActiveRecord::Base
|
77
|
+
acts_as_authenticated_user :authenticate_with =>
|
78
|
+
['BasicAuthMod', 'Authentication::SaltedHash']
|
79
|
+
end
|
80
|
+
|
81
|
+
class ArgAuthMod
|
82
|
+
def initialize(*args)
|
83
|
+
self.args = args
|
84
|
+
end
|
85
|
+
attr_accessor :args
|
86
|
+
end
|
87
|
+
class AnotherArgAuthMod < ArgAuthMod
|
88
|
+
end
|
89
|
+
|
90
|
+
class UserWithArgMod < ActiveRecord::Base
|
91
|
+
acts_as_authenticated_user :authenticate_with =>
|
92
|
+
{'ArgAuthMod' => {:server => 'test'}}
|
93
|
+
end
|
94
|
+
|
95
|
+
class UserWithMultipleArgs < ActiveRecord::Base
|
96
|
+
acts_as_authenticated_user :authenticate_with => [
|
97
|
+
{'ArgAuthMod' => {:server => 'test'}},
|
98
|
+
{'AnotherArgAuthMod' => {:server => 'testing'}}
|
99
|
+
]
|
100
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require File.join(File.dirname(__FILE__), 'abstract_unit')
|
3
|
+
|
4
|
+
# Tests RememberMe to see if it can allocate remember me tokens and
|
5
|
+
# validate those tokens correctly. This is very similar to single
|
6
|
+
# token except that it stores in a different field and will not care
|
7
|
+
# about expiration
|
8
|
+
class RememberMe < Test::Unit::TestCase
|
9
|
+
include Authentication::HashHelper
|
10
|
+
fixtures :users
|
11
|
+
|
12
|
+
def setup
|
13
|
+
@tokener = Authentication::RememberMe.new
|
14
|
+
|
15
|
+
@joe = users(:joe)
|
16
|
+
@key = @tokener.assign_token @joe, 'remember me'
|
17
|
+
@joe.save!
|
18
|
+
@joe.reload
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_assign_remember_me
|
22
|
+
assert_equal hash_string(@key), @joe.remember_me
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_authenticate
|
26
|
+
assert @tokener.authenticate(@joe, @key)
|
27
|
+
assert !@tokener.authenticate(@joe, "invalid key")
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_expiration_does_not_matter
|
31
|
+
expired_key = @tokener.assign_token @joe, 'remember me', 1.day.ago
|
32
|
+
@joe.save!
|
33
|
+
@joe.reload
|
34
|
+
|
35
|
+
assert @tokener.authenticate(@joe, expired_key)
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_non_remember_me
|
39
|
+
assert_nil @tokener.assign_token(@joe, 'invalid', 3.days.from_now)
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require File.join(File.dirname(__FILE__), 'abstract_unit')
|
3
|
+
|
4
|
+
# Tests SaltedHash class to ensure it can authenticate and assign
|
5
|
+
# passwords correctly
|
6
|
+
class SaltedHashTest < Test::Unit::TestCase
|
7
|
+
fixtures :users
|
8
|
+
|
9
|
+
def setup
|
10
|
+
@password = "foobazzle"
|
11
|
+
@crypter = Authentication::SaltedHash.new
|
12
|
+
|
13
|
+
@joe = users(:joe)
|
14
|
+
@crypter.assign_password @joe, @password
|
15
|
+
@joe.save!
|
16
|
+
@joe.reload
|
17
|
+
end
|
18
|
+
|
19
|
+
# We are basically just going to test that it gets assigned. We can
|
20
|
+
# really only test if it was assigned the right value when we test
|
21
|
+
# authenticate
|
22
|
+
def test_assign_password
|
23
|
+
assert_not_nil @joe.password_salt
|
24
|
+
assert_not_nil @joe.password_hash
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_authenticate
|
28
|
+
assert @crypter.authenticate(@joe, @password)
|
29
|
+
assert !@crypter.authenticate(@joe, "false password")
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_model_validation
|
33
|
+
class << User; alias_method :backup_column_names, :column_names end
|
34
|
+
def User.column_names; %w(id name password) end
|
35
|
+
assert !@crypter.authenticate(@joe, @password)
|
36
|
+
class << User; alias_method :column_names, :backup_column_names end
|
37
|
+
end
|
38
|
+
end
|