parlement 0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +709 -0
- data/COPYING +223 -0
- data/README +20 -0
- data/Rakefile +136 -0
- data/app/controllers/account_controller.rb +181 -0
- data/app/controllers/application.rb +30 -0
- data/app/controllers/elt_controller.rb +83 -0
- data/app/helpers/account_helper.rb +2 -0
- data/app/helpers/application_helper.rb +4 -0
- data/app/helpers/elt_helper.rb +37 -0
- data/app/helpers/live_tree.rb +238 -0
- data/app/helpers/mailman.rb +96 -0
- data/app/models/attachment.rb +4 -0
- data/app/models/elt.rb +17 -0
- data/app/models/mail.rb +4 -0
- data/app/models/notifier.rb +13 -0
- data/app/models/person.rb +9 -0
- data/app/models/user.rb +7 -0
- data/app/models/user_notify.rb +75 -0
- data/app/views/account/_help.rhtml +23 -0
- data/app/views/account/_login.rhtml +57 -0
- data/app/views/account/_show.rhtml +31 -0
- data/app/views/account/logout.rhtml +10 -0
- data/app/views/account/signup.rhtml +17 -0
- data/app/views/account/welcome.rhtml +13 -0
- data/app/views/elt/_elt.rhtml +105 -0
- data/app/views/elt/_form.rhtml +31 -0
- data/app/views/elt/_list.rhtml +28 -0
- data/app/views/elt/new.rhtml +102 -0
- data/app/views/elt/rss.rxml +31 -0
- data/app/views/elt/show.rhtml +46 -0
- data/app/views/elt/show_tree.rhtml +8 -0
- data/app/views/layouts/scaffold.rhtml +13 -0
- data/app/views/layouts/top.rhtml +45 -0
- data/app/views/notifier/changeEmail.rhtml +10 -0
- data/config/boot.rb +17 -0
- data/config/database.yml +82 -0
- data/config/environment.rb +92 -0
- data/config/environments/development.rb +17 -0
- data/config/environments/production.rb +17 -0
- data/config/environments/test.rb +17 -0
- data/config/environments/user_environment.rb +1 -0
- data/config/routes.rb +28 -0
- data/db/ROOT/CV.txt +166 -0
- data/db/ROOT/IP.txt +3 -0
- data/db/ROOT/parleR.txt +3 -0
- data/db/ROOT/parlement/security.txt +34 -0
- data/db/ROOT/parlement/test.txt +4 -0
- data/db/ROOT/parlement.txt +51 -0
- data/db/ROOT/perso.txt +215 -0
- data/db/schema.sql +127 -0
- data/lib/data_import.rb +54 -0
- data/lib/file_column.rb +263 -0
- data/lib/file_column_helper.rb +45 -0
- data/lib/localization.rb +88 -0
- data/lib/localizer.rb +88 -0
- data/lib/login_system.rb +87 -0
- data/lib/rails_file_column.rb +19 -0
- data/lib/user_system.rb +101 -0
- data/public/404.html +8 -0
- data/public/500.html +8 -0
- data/public/dispatch.cgi +10 -0
- data/public/dispatch.fcgi +24 -0
- data/public/dispatch.rb +10 -0
- data/public/engine_files/README +5 -0
- data/public/engine_files/login_engine/stylesheets/login_engine.css +81 -0
- data/public/favicon.ico +0 -0
- data/public/favicon.png +0 -0
- data/public/images/live_tree_branch_collapsed_icon.gif +0 -0
- data/public/images/live_tree_branch_expanded_icon.gif +0 -0
- data/public/images/live_tree_leaf_icon.gif +0 -0
- data/public/images/live_tree_loading_spinner.gif +0 -0
- data/public/images/webfeed.gif +0 -0
- data/public/javascripts/controls.js +721 -0
- data/public/javascripts/dragdrop.js +519 -0
- data/public/javascripts/effects.js +992 -0
- data/public/javascripts/live_tree.js +749 -0
- data/public/javascripts/prototype.js +1726 -0
- data/public/javascripts/scriptaculous.js +47 -0
- data/public/javascripts/slider.js +258 -0
- data/public/oldREADME +190 -0
- data/public/oldindex.html +78 -0
- data/public/robots.txt +1 -0
- data/public/stylesheets/default.css +238 -0
- data/public/stylesheets/live_tree.css +62 -0
- data/public/stylesheets/scaffold.css +74 -0
- data/script/about +3 -0
- data/script/benchmarker +19 -0
- data/script/breakpointer +3 -0
- data/script/console +3 -0
- data/script/create_db +7 -0
- data/script/destroy +3 -0
- data/script/generate +3 -0
- data/script/performance/benchmarker +3 -0
- data/script/performance/profiler +3 -0
- data/script/plugin +3 -0
- data/script/process/reaper +3 -0
- data/script/process/spawner +3 -0
- data/script/process/spinner +3 -0
- data/script/profiler +34 -0
- data/script/runner +3 -0
- data/script/server +3 -0
- data/test/fixtures/attachments.yml +10 -0
- data/test/fixtures/elts.yml +15 -0
- data/test/fixtures/mails.yml +7 -0
- data/test/fixtures/people.yml +49 -0
- data/test/fixtures/users.yml +41 -0
- data/test/functional/account_controller_test.rb +239 -0
- data/test/functional/elt_controller_test.rb +18 -0
- data/test/mocks/test/time.rb +17 -0
- data/test/mocks/test/user_notify.rb +16 -0
- data/test/test_helper.rb +28 -0
- data/test/unit/attachment_test.rb +14 -0
- data/test/unit/elt_test.rb +14 -0
- data/test/unit/mail_test.rb +14 -0
- data/test/unit/notifier_test.rb +31 -0
- data/test/unit/person_test.rb +24 -0
- data/test/unit/user_test.rb +94 -0
- data/vendor/plugins/engines/CHANGELOG +7 -0
- data/vendor/plugins/engines/README +128 -0
- data/vendor/plugins/engines/init.rb +33 -0
- data/vendor/plugins/engines/lib/action_mailer_extensions.rb +160 -0
- data/vendor/plugins/engines/lib/action_view_extensions.rb +130 -0
- data/vendor/plugins/engines/lib/dependencies_extensions.rb +56 -0
- data/vendor/plugins/engines/lib/engines.rb +292 -0
- data/vendor/plugins/engines/lib/ruby_extensions.rb +127 -0
- data/vendor/plugins/engines/lib/testing_extensions.rb +33 -0
- data/vendor/plugins/engines/test/ruby_extensions_test.rb +94 -0
- data/vendor/plugins/login_engine/README +258 -0
- data/vendor/plugins/login_engine/app/controllers/user_controller.rb +248 -0
- data/vendor/plugins/login_engine/app/helpers/user_helper.rb +88 -0
- data/vendor/plugins/login_engine/app/models/user.rb +7 -0
- data/vendor/plugins/login_engine/app/models/user_notify.rb +75 -0
- data/vendor/plugins/login_engine/app/views/user/_edit.rhtml +11 -0
- data/vendor/plugins/login_engine/app/views/user/_password.rhtml +9 -0
- data/vendor/plugins/login_engine/app/views/user/change_password.rhtml +17 -0
- data/vendor/plugins/login_engine/app/views/user/edit.rhtml +23 -0
- data/vendor/plugins/login_engine/app/views/user/forgot_password.rhtml +18 -0
- data/vendor/plugins/login_engine/app/views/user/home.rhtml +7 -0
- data/vendor/plugins/login_engine/app/views/user/login.rhtml +17 -0
- data/vendor/plugins/login_engine/app/views/user/logout.rhtml +8 -0
- data/vendor/plugins/login_engine/app/views/user/signup.rhtml +17 -0
- data/vendor/plugins/login_engine/app/views/user_notify/change_password.rhtml +10 -0
- data/vendor/plugins/login_engine/app/views/user_notify/delete.rhtml +5 -0
- data/vendor/plugins/login_engine/app/views/user_notify/forgot_password.rhtml +11 -0
- data/vendor/plugins/login_engine/app/views/user_notify/pending_delete.rhtml +9 -0
- data/vendor/plugins/login_engine/app/views/user_notify/signup.rhtml +12 -0
- data/vendor/plugins/login_engine/db/schema.rb +25 -0
- data/vendor/plugins/login_engine/init_engine.rb +10 -0
- data/vendor/plugins/login_engine/lib/login_engine/authenticated_system.rb +107 -0
- data/vendor/plugins/login_engine/lib/login_engine/authenticated_user.rb +149 -0
- data/vendor/plugins/login_engine/lib/login_engine.rb +58 -0
- data/vendor/plugins/login_engine/public/stylesheets/login_engine.css +81 -0
- data/vendor/plugins/login_engine/tasks/tasks.rake +4 -0
- data/vendor/plugins/login_engine/test/fixtures/templates/users.yml +41 -0
- data/vendor/plugins/login_engine/test/fixtures/users.yml +41 -0
- data/vendor/plugins/login_engine/test/functional/user_controller_test.rb +533 -0
- data/vendor/plugins/login_engine/test/mocks/mail.rb +14 -0
- data/vendor/plugins/login_engine/test/mocks/time.rb +19 -0
- data/vendor/plugins/login_engine/test/test_helper.rb +15 -0
- data/vendor/plugins/login_engine/test/unit/user_test.rb +94 -0
- metadata +276 -0
@@ -0,0 +1,533 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../test_helper'
|
2
|
+
require_dependency 'user_controller'
|
3
|
+
require 'breakpoint'
|
4
|
+
|
5
|
+
|
6
|
+
# Raise errors beyond the default web-based presentation
|
7
|
+
class UserController; def rescue_action(e) raise e end; end
|
8
|
+
|
9
|
+
class UserControllerTest < Test::Unit::TestCase
|
10
|
+
|
11
|
+
fixtures LoginEngine.config(:user_table).to_sym
|
12
|
+
|
13
|
+
def setup
|
14
|
+
|
15
|
+
LoginEngine::CONFIG[:salt] = "test-salt"
|
16
|
+
|
17
|
+
@controller = UserController.new
|
18
|
+
@request, @response = ActionController::TestRequest.new, ActionController::TestResponse.new
|
19
|
+
@request.host = "localhost"
|
20
|
+
end
|
21
|
+
|
22
|
+
|
23
|
+
|
24
|
+
#==========================================================================
|
25
|
+
#
|
26
|
+
# Login/Logout
|
27
|
+
#
|
28
|
+
#==========================================================================
|
29
|
+
|
30
|
+
def test_home_without_login
|
31
|
+
get :home
|
32
|
+
assert_redirected_to :action => "login"
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_invalid_login
|
36
|
+
post :login, :user => { :login => "bob", :password => "wrong_password" }
|
37
|
+
assert_response :success
|
38
|
+
|
39
|
+
assert_session_has_no :user
|
40
|
+
assert_template "login"
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_login
|
44
|
+
@request.session['return-to'] = "/bogus/location"
|
45
|
+
|
46
|
+
post :login, :user => { :login => "bob", :password => "atest" }
|
47
|
+
|
48
|
+
assert_response 302 # redirect
|
49
|
+
assert_session_has :user
|
50
|
+
assert_equal fixture_object(LoginEngine.config(:user_table).to_sym, :bob), session[:user]
|
51
|
+
|
52
|
+
assert_redirect_url "http://#{@request.host}/bogus/location"
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_login_logoff
|
56
|
+
|
57
|
+
post :login, :user => { :login => "bob", :password => "atest" }
|
58
|
+
assert_session_has :user
|
59
|
+
|
60
|
+
get :logout
|
61
|
+
assert_session_has_no :user
|
62
|
+
|
63
|
+
end
|
64
|
+
|
65
|
+
|
66
|
+
#==========================================================================
|
67
|
+
#
|
68
|
+
# Signup
|
69
|
+
#
|
70
|
+
#==========================================================================
|
71
|
+
|
72
|
+
def test_signup
|
73
|
+
LoginEngine::CONFIG[:use_email_notification] = true
|
74
|
+
|
75
|
+
ActionMailer::Base.deliveries = []
|
76
|
+
|
77
|
+
@request.session['return-to'] = "/bogus/location"
|
78
|
+
|
79
|
+
assert_equal 5, User.count
|
80
|
+
post :signup, :user => { :login => "newbob", :password => "newpassword", :password_confirmation => "newpassword", :email => "newbob@test.com" }
|
81
|
+
assert_session_has_no :user
|
82
|
+
|
83
|
+
assert_redirect_url(@controller.url_for(:action => "login"))
|
84
|
+
assert_equal 1, ActionMailer::Base.deliveries.size
|
85
|
+
mail = ActionMailer::Base.deliveries[0]
|
86
|
+
assert_equal "newbob@test.com", mail.to_addrs[0].to_s
|
87
|
+
assert_match /login:\s+\w+\n/, mail.encoded
|
88
|
+
assert_match /password:\s+\w+\n/, mail.encoded
|
89
|
+
mail.encoded =~ /key=(.*?)"/
|
90
|
+
key = $1
|
91
|
+
|
92
|
+
user = User.find_by_email("newbob@test.com")
|
93
|
+
assert_not_nil user
|
94
|
+
assert_equal 0, user.verified
|
95
|
+
|
96
|
+
# First past the expiration.
|
97
|
+
Time.advance_by_days = 1
|
98
|
+
get :home, :user=> { "id" => "#{user.id}" }, "key" => "#{key}"
|
99
|
+
Time.advance_by_days = 0
|
100
|
+
user = User.find_by_email("newbob@test.com")
|
101
|
+
assert_equal 0, user.verified
|
102
|
+
|
103
|
+
# Then a bogus key.
|
104
|
+
get :home, :user=> { "id" => "#{user.id}" }, "key" => "boguskey"
|
105
|
+
user = User.find_by_email("newbob@test.com")
|
106
|
+
assert_equal 0, user.verified
|
107
|
+
|
108
|
+
# Now the real one.
|
109
|
+
get :home, :user=> { "id" => "#{user.id}" }, "key" => "#{key}"
|
110
|
+
user = User.find_by_email("newbob@test.com")
|
111
|
+
assert_equal 1, user.verified
|
112
|
+
|
113
|
+
post :login, :user => { :login => "newbob", :password => "newpassword" }
|
114
|
+
assert_session_has :user
|
115
|
+
get :logout
|
116
|
+
|
117
|
+
end
|
118
|
+
|
119
|
+
def test_signup_bad_password
|
120
|
+
LoginEngine::CONFIG[:use_email_notification] = true
|
121
|
+
ActionMailer::Base.deliveries = []
|
122
|
+
|
123
|
+
@request.session['return-to'] = "/bogus/location"
|
124
|
+
post :signup, :user => { :login => "newbob", :password => "bad", :password_confirmation => "bad", :email => "newbob@test.com" }
|
125
|
+
assert_session_has_no :user
|
126
|
+
assert_invalid_column_on_record "user", "password"
|
127
|
+
assert_success
|
128
|
+
assert_equal 0, ActionMailer::Base.deliveries.size
|
129
|
+
end
|
130
|
+
|
131
|
+
def test_signup_bad_email
|
132
|
+
LoginEngine::CONFIG[:use_email_notification] = true
|
133
|
+
ActionMailer::Base.deliveries = []
|
134
|
+
|
135
|
+
@request.session['return-to'] = "/bogus/location"
|
136
|
+
|
137
|
+
ActionMailer::Base.inject_one_error = true
|
138
|
+
post :signup, :user => { :login => "newbob", :password => "newpassword", :password_confirmation => "newpassword", :email => "newbob@test.com" }
|
139
|
+
assert_session_has_no :user
|
140
|
+
assert_equal 0, ActionMailer::Base.deliveries.size
|
141
|
+
end
|
142
|
+
|
143
|
+
def test_signup_without_email
|
144
|
+
LoginEngine::CONFIG[:use_email_notification] = false
|
145
|
+
|
146
|
+
@request.session['return-to'] = "/bogus/location"
|
147
|
+
|
148
|
+
post :signup, :user => { :login => "newbob", :password => "newpassword", :password_confirmation => "newpassword", :email => "newbob@test.com" }
|
149
|
+
|
150
|
+
assert_redirect_url(@controller.url_for(:action => "login"))
|
151
|
+
assert_session_has_no :user
|
152
|
+
assert_match /Signup successful/, flash[:notice]
|
153
|
+
|
154
|
+
assert_not_nil User.find_by_login("newbob")
|
155
|
+
|
156
|
+
user = User.find_by_email("newbob@test.com")
|
157
|
+
assert_not_nil user
|
158
|
+
|
159
|
+
post :login, :user => { :login => "newbob", :password => "newpassword" }
|
160
|
+
assert_session_has :user
|
161
|
+
get :logout
|
162
|
+
end
|
163
|
+
|
164
|
+
def test_signup_bad_details
|
165
|
+
@request.session['return-to'] = "/bogus/location"
|
166
|
+
|
167
|
+
# mismatched password
|
168
|
+
post :signup, :user => { :login => "newbob", :password => "newpassword", :password_confirmation => "wrong" }
|
169
|
+
assert_invalid_column_on_record "user", "password"
|
170
|
+
assert_success
|
171
|
+
|
172
|
+
# login not long enough
|
173
|
+
post :signup, :user => { :login => "yo", :password => "newpassword", :password_confirmation => "newpassword" }
|
174
|
+
assert_invalid_column_on_record "user", "login"
|
175
|
+
assert_success
|
176
|
+
|
177
|
+
# both
|
178
|
+
post :signup, :user => { :login => "yo", :password => "newpassword", :password_confirmation => "wrong" }
|
179
|
+
assert_invalid_column_on_record "user", ["login", "password"]
|
180
|
+
assert_success
|
181
|
+
|
182
|
+
# existing user
|
183
|
+
post :signup, :user => { :login => "bob", :password => "doesnt_matter", :password_confirmation => "doesnt_matter" }
|
184
|
+
assert_invalid_column_on_record "user", "login"
|
185
|
+
assert_success
|
186
|
+
|
187
|
+
# existing email
|
188
|
+
post :signup, :user => { :login => "newbob", :email => "longbob@test.com", :password => "doesnt_matter", :password_confirmation => "doesnt_matter" }
|
189
|
+
assert_invalid_column_on_record "user", "email"
|
190
|
+
assert_success
|
191
|
+
|
192
|
+
end
|
193
|
+
|
194
|
+
|
195
|
+
#==========================================================================
|
196
|
+
#
|
197
|
+
# Edit
|
198
|
+
#
|
199
|
+
#==========================================================================
|
200
|
+
|
201
|
+
def test_edit
|
202
|
+
post :login, :user => { :login => "bob", :password => "atest" }
|
203
|
+
assert_session_has :user
|
204
|
+
|
205
|
+
post :edit, :user => { "firstname" => "Bob", "form" => "edit" }
|
206
|
+
assert_equal @response.session[:user].firstname, "Bob"
|
207
|
+
|
208
|
+
post :edit, :user => { "firstname" => "", "form" => "edit" }
|
209
|
+
assert_equal @response.session[:user].firstname, ""
|
210
|
+
|
211
|
+
get :logout
|
212
|
+
end
|
213
|
+
|
214
|
+
|
215
|
+
|
216
|
+
#==========================================================================
|
217
|
+
#
|
218
|
+
# Delete
|
219
|
+
#
|
220
|
+
#==========================================================================
|
221
|
+
|
222
|
+
def test_delete
|
223
|
+
LoginEngine::CONFIG[:use_email_notification] = true
|
224
|
+
# Immediate delete
|
225
|
+
post :login, :user => { :login => "deletebob1", :password => "alongtest" }
|
226
|
+
assert_session_has :user
|
227
|
+
|
228
|
+
LoginEngine.config :delayed_delete, false, :force
|
229
|
+
post :delete
|
230
|
+
assert_equal 1, ActionMailer::Base.deliveries.size
|
231
|
+
assert_session_has_no :user
|
232
|
+
|
233
|
+
# try and login in again, we should fail.
|
234
|
+
post :login, :user => { :login => "deletebob1", :password => "alongtest" }
|
235
|
+
assert_session_has_no :user
|
236
|
+
assert_template_has "login"
|
237
|
+
|
238
|
+
|
239
|
+
# Now try delayed delete
|
240
|
+
ActionMailer::Base.deliveries = []
|
241
|
+
|
242
|
+
post :login, :user => { :login => "deletebob2", :password => "alongtest" }
|
243
|
+
assert_session_has :user
|
244
|
+
|
245
|
+
LoginEngine.config :delayed_delete, true, :force
|
246
|
+
post :delete
|
247
|
+
assert_equal 1, ActionMailer::Base.deliveries.size
|
248
|
+
mail = ActionMailer::Base.deliveries[0]
|
249
|
+
mail.encoded =~ /user\[id\]=(.*?)&key=(.*?)"/
|
250
|
+
id = $1
|
251
|
+
key = $2
|
252
|
+
|
253
|
+
post :restore_deleted, :user => { "id" => "#{id}" }, "key" => "badkey"
|
254
|
+
assert_session_has_no :user
|
255
|
+
|
256
|
+
# Advance the time past the delete date
|
257
|
+
Time.advance_by_days = LoginEngine.config :delayed_delete_days
|
258
|
+
post :restore_deleted, :user => { "id" => "#{id}" }, "key" => "#{key}"
|
259
|
+
assert_session_has_no :user
|
260
|
+
Time.advance_by_days = 0
|
261
|
+
|
262
|
+
post :restore_deleted, :user => { "id" => "#{id}" }, "key" => "#{key}"
|
263
|
+
assert_session_has :user
|
264
|
+
end
|
265
|
+
|
266
|
+
def test_delete_without_email
|
267
|
+
LoginEngine::CONFIG[:use_email_notification] = false
|
268
|
+
ActionMailer::Base.deliveries = []
|
269
|
+
|
270
|
+
# Immediate delete
|
271
|
+
post :login, :user => { :login => "deletebob1", :password => "alongtest" }
|
272
|
+
assert_session_has :user
|
273
|
+
|
274
|
+
LoginEngine.config :delayed_delete, false, :force
|
275
|
+
post :delete
|
276
|
+
assert_session_has_no :user
|
277
|
+
assert_nil User.find_by_login("deletebob1")
|
278
|
+
|
279
|
+
# try and login in again, we should fail.
|
280
|
+
post :login, :user => { :login => "deletebob1", :password => "alongtest" }
|
281
|
+
assert_session_has_no :user
|
282
|
+
assert_template_has "login"
|
283
|
+
|
284
|
+
|
285
|
+
# Now try delayed delete
|
286
|
+
ActionMailer::Base.deliveries = []
|
287
|
+
|
288
|
+
post :login, :user => { :login => "deletebob2", :password => "alongtest" }
|
289
|
+
assert_session_has :user
|
290
|
+
|
291
|
+
# delayed delete is not really relevant currently without email.
|
292
|
+
LoginEngine.config :delayed_delete, true, :force
|
293
|
+
post :delete
|
294
|
+
assert_equal 1, User.find_by_login("deletebob2").deleted
|
295
|
+
end
|
296
|
+
|
297
|
+
|
298
|
+
|
299
|
+
#==========================================================================
|
300
|
+
#
|
301
|
+
# Change Password
|
302
|
+
#
|
303
|
+
#==========================================================================
|
304
|
+
|
305
|
+
def test_change_valid_password
|
306
|
+
|
307
|
+
LoginEngine::CONFIG[:use_email_notification] = true
|
308
|
+
|
309
|
+
ActionMailer::Base.deliveries = []
|
310
|
+
|
311
|
+
post :login, :user => { :login => "bob", :password => "atest" }
|
312
|
+
assert_session_has :user
|
313
|
+
|
314
|
+
post :change_password, :user => { :password => "changed_password", :password_confirmation => "changed_password" }
|
315
|
+
|
316
|
+
assert_equal 1, ActionMailer::Base.deliveries.size
|
317
|
+
mail = ActionMailer::Base.deliveries[0]
|
318
|
+
assert_equal "bob@test.com", mail.to_addrs[0].to_s
|
319
|
+
assert_match /login:\s+\w+\n/, mail.encoded
|
320
|
+
assert_match /password:\s+\w+\n/, mail.encoded
|
321
|
+
|
322
|
+
post :login, :user => { :login => "bob", :password => "changed_password" }
|
323
|
+
assert_session_has :user
|
324
|
+
post :change_password, :user => { :password => "atest", :password_confirmation => "atest" }
|
325
|
+
get :logout
|
326
|
+
|
327
|
+
post :login, :user => { :login => "bob", :password => "atest" }
|
328
|
+
assert_session_has :user
|
329
|
+
|
330
|
+
get :logout
|
331
|
+
end
|
332
|
+
|
333
|
+
def test_change_valid_password_without_email
|
334
|
+
|
335
|
+
LoginEngine::CONFIG[:use_email_notification] = false
|
336
|
+
|
337
|
+
ActionMailer::Base.deliveries = []
|
338
|
+
|
339
|
+
post :login, :user => { :login => "bob", :password => "atest" }
|
340
|
+
assert_session_has :user
|
341
|
+
|
342
|
+
post :change_password, :user => { :password => "changed_password", :password_confirmation => "changed_password" }
|
343
|
+
|
344
|
+
assert_success
|
345
|
+
|
346
|
+
post :login, :user => { :login => "bob", :password => "changed_password" }
|
347
|
+
assert_session_has :user
|
348
|
+
post :change_password, :user => { :password => "atest", :password_confirmation => "atest" }
|
349
|
+
get :logout
|
350
|
+
|
351
|
+
post :login, :user => { :login => "bob", :password => "atest" }
|
352
|
+
assert_session_has :user
|
353
|
+
|
354
|
+
get :logout
|
355
|
+
end
|
356
|
+
|
357
|
+
def test_change_short_password
|
358
|
+
LoginEngine::CONFIG[:use_email_notification] = true
|
359
|
+
ActionMailer::Base.deliveries = []
|
360
|
+
|
361
|
+
post :login, :user => { :login => "bob", :password => "atest" }
|
362
|
+
assert_session_has :user
|
363
|
+
|
364
|
+
post :change_password, :user => { :password => "bad", :password_confirmation => "bad" }
|
365
|
+
assert_invalid_column_on_record "user", "password"
|
366
|
+
assert_success
|
367
|
+
assert_equal 0, ActionMailer::Base.deliveries.size
|
368
|
+
|
369
|
+
post :login, :user => { :login => "bob", :password => "atest" }
|
370
|
+
assert_session_has :user
|
371
|
+
|
372
|
+
get :logout
|
373
|
+
end
|
374
|
+
|
375
|
+
def test_change_short_password_without_email
|
376
|
+
LoginEngine::CONFIG[:use_email_notification] = false
|
377
|
+
post :login, :user => { :login => "bob", :password => "atest" }
|
378
|
+
assert_session_has :user
|
379
|
+
|
380
|
+
post :change_password, :user => { :password => "bad", :password_confirmation => "bad" }
|
381
|
+
assert_invalid_column_on_record "user", "password"
|
382
|
+
assert_success
|
383
|
+
|
384
|
+
post :login, :user => { :login => "bob", :password => "atest" }
|
385
|
+
assert_session_has :user
|
386
|
+
|
387
|
+
get :logout
|
388
|
+
end
|
389
|
+
|
390
|
+
|
391
|
+
def test_change_password_with_bad_email
|
392
|
+
LoginEngine::CONFIG[:use_email_notification] = true
|
393
|
+
ActionMailer::Base.deliveries = []
|
394
|
+
|
395
|
+
# log in
|
396
|
+
post :login, :user => { :login => "bob", :password => "atest" }
|
397
|
+
assert_session_has :user
|
398
|
+
|
399
|
+
# change the password, but the email delivery will fail
|
400
|
+
ActionMailer::Base.inject_one_error = true
|
401
|
+
post :change_password, :user => { :password => "changed_password", :password_confirmation => "changed_password" }
|
402
|
+
assert_equal 0, ActionMailer::Base.deliveries.size
|
403
|
+
assert_match /Password could not be changed/, flash[:warning]
|
404
|
+
|
405
|
+
# logout
|
406
|
+
get :logout
|
407
|
+
assert_session_has_no :user
|
408
|
+
|
409
|
+
# ensure we can log in with our original password
|
410
|
+
# TODO: WHY DOES THIS FAIL!! It looks like the transaction stuff in UserController#change_password isn't actually rolling back changes.
|
411
|
+
post :login, :user => { :login => "bob", :password => "atest" }
|
412
|
+
assert_session_has :user
|
413
|
+
|
414
|
+
get :logout
|
415
|
+
end
|
416
|
+
|
417
|
+
|
418
|
+
|
419
|
+
|
420
|
+
#==========================================================================
|
421
|
+
#
|
422
|
+
# Forgot Password
|
423
|
+
#
|
424
|
+
#==========================================================================
|
425
|
+
|
426
|
+
def test_forgot_password
|
427
|
+
LoginEngine::CONFIG[:use_email_notification] = true
|
428
|
+
|
429
|
+
do_forgot_password(false, false, false)
|
430
|
+
do_forgot_password(false, false, true)
|
431
|
+
do_forgot_password(true, false, false)
|
432
|
+
do_forgot_password(false, true, false)
|
433
|
+
end
|
434
|
+
|
435
|
+
def do_forgot_password(bad_address, bad_email, logged_in)
|
436
|
+
ActionMailer::Base.deliveries = []
|
437
|
+
|
438
|
+
if logged_in
|
439
|
+
post :login, :user => { :login => "bob", :password => "atest" }
|
440
|
+
assert_session_has :user
|
441
|
+
end
|
442
|
+
|
443
|
+
@request.session['return-to'] = "/bogus/location"
|
444
|
+
if not bad_address and not bad_email
|
445
|
+
post :forgot_password, :user => { :email => "bob@test.com" }
|
446
|
+
password = "anewpassword"
|
447
|
+
if logged_in
|
448
|
+
assert_equal 0, ActionMailer::Base.deliveries.size
|
449
|
+
assert_redirect_url(@controller.url_for(:action => "change_password"))
|
450
|
+
post :change_password, :user => { :password => "#{password}", :password_confirmation => "#{password}" }
|
451
|
+
else
|
452
|
+
assert_equal 1, ActionMailer::Base.deliveries.size
|
453
|
+
mail = ActionMailer::Base.deliveries[0]
|
454
|
+
assert_equal "bob@test.com", mail.to_addrs[0].to_s
|
455
|
+
mail.encoded =~ /user\[id\]=(.*?)&key=(.*?)"/
|
456
|
+
id = $1
|
457
|
+
key = $2
|
458
|
+
post :change_password, :user => { :password => "#{password}", :password_confirmation => "#{password}", :id => "#{id}" }, :key => "#{key}"
|
459
|
+
assert_session_has :user
|
460
|
+
get :logout
|
461
|
+
end
|
462
|
+
elsif bad_address
|
463
|
+
post :forgot_password, :user => { :email => "bademail@test.com" }
|
464
|
+
assert_equal 0, ActionMailer::Base.deliveries.size
|
465
|
+
elsif bad_email
|
466
|
+
ActionMailer::Base.inject_one_error = true
|
467
|
+
post :forgot_password, :user => { :email => "bob@test.com" }
|
468
|
+
assert_equal 0, ActionMailer::Base.deliveries.size
|
469
|
+
else
|
470
|
+
# Invalid test case
|
471
|
+
assert false
|
472
|
+
end
|
473
|
+
|
474
|
+
if not bad_address and not bad_email
|
475
|
+
if logged_in
|
476
|
+
get :logout
|
477
|
+
else
|
478
|
+
assert_redirect_url(@controller.url_for(:action => "login"))
|
479
|
+
end
|
480
|
+
post :login, :user => { :login => "bob", :password => "#{password}" }
|
481
|
+
else
|
482
|
+
# Okay, make sure the database did not get changed
|
483
|
+
if logged_in
|
484
|
+
get :logout
|
485
|
+
end
|
486
|
+
post :login, :user => { :login => "bob", :password => "atest" }
|
487
|
+
end
|
488
|
+
|
489
|
+
assert_session_has :user
|
490
|
+
|
491
|
+
# Put the old settings back
|
492
|
+
if not bad_address and not bad_email
|
493
|
+
post :change_password, :user => { :password => "atest", :password_confirmation => "atest" }
|
494
|
+
end
|
495
|
+
|
496
|
+
get :logout
|
497
|
+
end
|
498
|
+
|
499
|
+
def test_forgot_password_without_email_and_logged_in
|
500
|
+
LoginEngine::CONFIG[:use_email_notification] = false
|
501
|
+
|
502
|
+
post :login, :user => { :login => "bob", :password => "atest" }
|
503
|
+
assert_session_has :user
|
504
|
+
|
505
|
+
@request.session['return-to'] = "/bogus/location"
|
506
|
+
post :forgot_password, :user => { :email => "bob@test.com" }
|
507
|
+
password = "anewpassword"
|
508
|
+
assert_redirect_url(@controller.url_for(:action => "change_password"))
|
509
|
+
post :change_password, :user => { :password => "#{password}", :password_confirmation => "#{password}" }
|
510
|
+
|
511
|
+
get :logout
|
512
|
+
|
513
|
+
post :login, :user => { :login => "bob", :password => "#{password}" }
|
514
|
+
|
515
|
+
assert_session_has :user
|
516
|
+
|
517
|
+
get :logout
|
518
|
+
end
|
519
|
+
|
520
|
+
def forgot_password_without_email_and_not_logged_in
|
521
|
+
LoginEngine::CONFIG[:use_email_notification] = false
|
522
|
+
|
523
|
+
@request.session['return-to'] = "/bogus/location"
|
524
|
+
post :forgot_password, :user => { :email => "bob@test.com" }
|
525
|
+
password = "anewpassword"
|
526
|
+
|
527
|
+
# wothout email, you can't retrieve your forgotten password...
|
528
|
+
assert_match /Please contact the system admin/, flash[:message]
|
529
|
+
assert_session_has_no :user
|
530
|
+
|
531
|
+
assert_redirect_url "http://#{@request.host}/bogus/location"
|
532
|
+
end
|
533
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
ActionMailer::Base.class_eval {
|
2
|
+
@@inject_one_error = false
|
3
|
+
cattr_accessor :inject_one_error
|
4
|
+
|
5
|
+
private
|
6
|
+
def perform_delivery_test(mail)
|
7
|
+
if inject_one_error
|
8
|
+
ActionMailer::Base::inject_one_error = false
|
9
|
+
raise "Failed to send email" if raise_delivery_errors
|
10
|
+
else
|
11
|
+
deliveries << mail
|
12
|
+
end
|
13
|
+
end
|
14
|
+
}
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'time'
|
2
|
+
|
3
|
+
Time.class_eval {
|
4
|
+
if !respond_to? :now_old # somehow this is getting defined many times.
|
5
|
+
@@advance_by_days = 0
|
6
|
+
cattr_accessor :advance_by_days
|
7
|
+
|
8
|
+
class << Time
|
9
|
+
alias now_old now
|
10
|
+
def now
|
11
|
+
if Time.advance_by_days != 0
|
12
|
+
return Time.at(now_old.to_i + Time.advance_by_days * 60 * 60 * 24 + 1)
|
13
|
+
else
|
14
|
+
now_old
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
}
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../../../../test/test_helper' # the default rails helper
|
2
|
+
|
3
|
+
require File.dirname(__FILE__) + '/mocks/time'
|
4
|
+
require File.dirname(__FILE__) + '/mocks/mail'
|
5
|
+
|
6
|
+
# TODO: Add check for database-specific sql files instead
|
7
|
+
load(File.dirname(__FILE__) + "/../db/schema.rb")
|
8
|
+
|
9
|
+
# set up the fixtures location
|
10
|
+
Test::Unit::TestCase.fixture_path = File.dirname(__FILE__) + "/fixtures/"
|
11
|
+
$LOAD_PATH.unshift(Test::Unit::TestCase.fixture_path)
|
12
|
+
|
13
|
+
|
14
|
+
# declare mappings between your fixtures templates and the actual table names used.
|
15
|
+
Test::Unit::TestCase.set_fixtures_table(:users, LoginEngine.config(:user_table))
|
@@ -0,0 +1,94 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../test_helper'
|
2
|
+
|
3
|
+
class UserTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
fixtures LoginEngine.config(:user_table).to_sym
|
6
|
+
|
7
|
+
def setup
|
8
|
+
LoginEngine::CONFIG[:salt] = "test-salt"
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_auth
|
12
|
+
assert_equal fixture_object(LoginEngine.config(:user_table), :bob), User.authenticate("bob", "atest")
|
13
|
+
assert_nil User.authenticate("nonbob", "atest")
|
14
|
+
end
|
15
|
+
|
16
|
+
|
17
|
+
def test_passwordchange
|
18
|
+
|
19
|
+
fixture_object(LoginEngine.config(:user_table), :longbob).change_password("nonbobpasswd")
|
20
|
+
fixture_object(LoginEngine.config(:user_table), :longbob).save
|
21
|
+
assert_equal fixture_object(LoginEngine.config(:user_table), :longbob), User.authenticate("longbob", "nonbobpasswd")
|
22
|
+
assert_nil User.authenticate("longbob", "alongtest")
|
23
|
+
fixture_object(LoginEngine.config(:user_table), :longbob).change_password("alongtest")
|
24
|
+
fixture_object(LoginEngine.config(:user_table), :longbob).save
|
25
|
+
assert_equal fixture_object(LoginEngine.config(:user_table), :longbob), User.authenticate("longbob", "alongtest")
|
26
|
+
assert_nil User.authenticate("longbob", "nonbobpasswd")
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_disallowed_passwords
|
31
|
+
|
32
|
+
u = User.new
|
33
|
+
u.login = "nonbob"
|
34
|
+
|
35
|
+
u.change_password("tiny")
|
36
|
+
assert !u.save
|
37
|
+
assert u.errors.invalid?('password')
|
38
|
+
|
39
|
+
u.change_password("hugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehuge")
|
40
|
+
assert !u.save
|
41
|
+
assert u.errors.invalid?('password')
|
42
|
+
|
43
|
+
u.change_password("")
|
44
|
+
assert !u.save
|
45
|
+
assert u.errors.invalid?('password')
|
46
|
+
|
47
|
+
u.change_password("bobs_secure_password")
|
48
|
+
assert u.save
|
49
|
+
assert u.errors.empty?
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_bad_logins
|
54
|
+
|
55
|
+
u = User.new
|
56
|
+
u.change_password("bobs_secure_password")
|
57
|
+
|
58
|
+
u.login = "x"
|
59
|
+
assert !u.save
|
60
|
+
assert u.errors.invalid?('login')
|
61
|
+
|
62
|
+
u.login = "hugebobhugebobhugebobhugebobhugebobhugebobhugebobhugebobhugebobhugebobhugebobhugebobhugebobhugebobhugebobhugebobhugebobhugebobhugebobhugebobhugebobhugebobhugebobhugebobhugebobhugebobhug"
|
63
|
+
assert !u.save
|
64
|
+
assert u.errors.invalid?('login')
|
65
|
+
|
66
|
+
u.login = ""
|
67
|
+
assert !u.save
|
68
|
+
assert u.errors.invalid?('login')
|
69
|
+
|
70
|
+
u.login = "okbob"
|
71
|
+
assert u.save
|
72
|
+
assert u.errors.empty?
|
73
|
+
|
74
|
+
end
|
75
|
+
|
76
|
+
|
77
|
+
def test_collision
|
78
|
+
u = User.new
|
79
|
+
u.login = "existingbob"
|
80
|
+
u.change_password("bobs_secure_password")
|
81
|
+
assert !u.save
|
82
|
+
end
|
83
|
+
|
84
|
+
|
85
|
+
def test_create
|
86
|
+
u = User.new
|
87
|
+
u.login = "nonexistingbob"
|
88
|
+
u.change_password("bobs_secure_password")
|
89
|
+
|
90
|
+
assert u.save
|
91
|
+
|
92
|
+
end
|
93
|
+
|
94
|
+
end
|