multi_auth 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README +11 -0
- data/app/controllers/auth/name_controller.rb +31 -0
- data/app/controllers/credentials/email_controller.rb +3 -3
- data/app/controllers/credentials/name_controller.rb +93 -0
- data/app/controllers/credentials_controller.rb +6 -4
- data/app/models/name_credential.rb +63 -0
- data/app/models/name_credential_edit_form.rb +40 -0
- data/app/models/name_login_form.rb +14 -0
- data/app/models/{email_password_edit_form.rb → password_edit_form.rb} +5 -13
- data/app/views/auth/name/index.html.erb +89 -0
- data/app/views/credentials/index.html.erb +46 -0
- data/app/views/credentials/name/delete.html.erb +19 -0
- data/app/views/credentials/name/edit_password.html.erb +27 -0
- data/app/views/credentials/name/new.html.erb +32 -0
- data/config/routes.rb +8 -0
- data/db/development.sqlite3 +0 -0
- data/db/schema.rb +13 -1
- data/db/test.sqlite3 +0 -0
- data/generators/multi_auth_migration/templates/migration.rb +13 -0
- data/generators/multi_auth_migration/templates/upgrade_migration.rb +19 -0
- data/generators/multi_auth_migration/upgrade_multi_auth_tables_generator.rb +11 -0
- data/lib/multi_auth.rb +1 -0
- data/lib/multi_auth/active_record.rb +1 -0
- data/locale/ja/LC_MESSAGES/multi_auth.mo +0 -0
- data/po/ja/multi_auth.po +357 -259
- data/po/multi_auth.pot +309 -215
- data/test/functional/auth/name_controller_test.rb +77 -0
- data/test/functional/credentials/email_controller_test.rb +3 -4
- data/test/functional/credentials/name_controller_test.rb +292 -0
- data/test/unit/name_credential_edit_form_test.rb +151 -0
- data/test/unit/name_credential_test.rb +173 -0
- data/test/unit/name_login_form_test.rb +68 -0
- data/test/unit/{email_password_edit_form_test.rb → password_edit_form_test.rb} +7 -6
- metadata +22 -6
@@ -0,0 +1,77 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class Auth::NameControllerTest < ActionController::TestCase
|
4
|
+
def setup
|
5
|
+
@login_form = NameLoginForm.new
|
6
|
+
end
|
7
|
+
|
8
|
+
test "toutes" do
|
9
|
+
base = { :controller => "auth/name" }
|
10
|
+
|
11
|
+
assert_routing("/auth/name", base.merge(:action => "index"))
|
12
|
+
assert_routing("/auth/name/login", base.merge(:action => "login"))
|
13
|
+
end
|
14
|
+
|
15
|
+
test "GET index" do
|
16
|
+
session_login(users(:yuya))
|
17
|
+
|
18
|
+
get :index
|
19
|
+
|
20
|
+
assert_response(:success)
|
21
|
+
assert_template("index")
|
22
|
+
assert_flash_empty
|
23
|
+
assert_not_logged_in
|
24
|
+
|
25
|
+
assert_equal(NameLoginForm.new.attributes, assigns(:login_form).attributes)
|
26
|
+
end
|
27
|
+
|
28
|
+
test "POST login" do
|
29
|
+
session_login(users(:shinya))
|
30
|
+
|
31
|
+
time = Time.local(2010, 1, 1)
|
32
|
+
@login_form.attributes = {
|
33
|
+
:name => name_credentials(:nayutaya).name,
|
34
|
+
:password => "nayutaya",
|
35
|
+
}
|
36
|
+
assert_equal(true, @login_form.valid?)
|
37
|
+
|
38
|
+
Kagemusha::DateTime.at(time) {
|
39
|
+
post :login, :login_form => @login_form.attributes
|
40
|
+
}
|
41
|
+
|
42
|
+
assert_response(:redirect)
|
43
|
+
assert_redirected_to(:controller => "/auth", :action => "logged_in")
|
44
|
+
assert_flash_empty
|
45
|
+
assert_logged_in(users(:yuya))
|
46
|
+
|
47
|
+
assert_equal(
|
48
|
+
@login_form.attributes,
|
49
|
+
assigns(:login_form).attributes)
|
50
|
+
|
51
|
+
assert_equal(name_credentials(:nayutaya), assigns(:name_credential))
|
52
|
+
assert_equal(time, assigns(:name_credential).loggedin_at)
|
53
|
+
end
|
54
|
+
|
55
|
+
test "POST login, invalid form" do
|
56
|
+
session_login(users(:shinya))
|
57
|
+
|
58
|
+
assert_equal(false, @login_form.valid?)
|
59
|
+
|
60
|
+
post :login, :login_form => @login_form.attributes
|
61
|
+
|
62
|
+
assert_response(:success)
|
63
|
+
assert_template("index")
|
64
|
+
assert_flash_error
|
65
|
+
assert_not_logged_in
|
66
|
+
|
67
|
+
assert_equal(nil, assigns(:login_form).password)
|
68
|
+
assert_equal(nil, assigns(:email_credential))
|
69
|
+
end
|
70
|
+
|
71
|
+
test "GET login, abnormal, method not allowed" do
|
72
|
+
get :login
|
73
|
+
|
74
|
+
assert_response(405)
|
75
|
+
assert_template(nil)
|
76
|
+
end
|
77
|
+
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
1
2
|
|
2
3
|
require 'test_helper'
|
3
4
|
|
@@ -13,7 +14,7 @@ class Credentials::EmailControllerTest < ActionController::TestCase
|
|
13
14
|
:password => "password",
|
14
15
|
:password_confirmation => "password")
|
15
16
|
|
16
|
-
@password_edit_form =
|
17
|
+
@password_edit_form = PasswordEditForm.new(
|
17
18
|
:password => "password",
|
18
19
|
:password_confirmation => "password")
|
19
20
|
|
@@ -165,9 +166,7 @@ class Credentials::EmailControllerTest < ActionController::TestCase
|
|
165
166
|
|
166
167
|
assert_equal(@yuya_gmail, assigns(:email_credential))
|
167
168
|
|
168
|
-
assert_equal(
|
169
|
-
EmailPasswordEditForm.new.attributes,
|
170
|
-
assigns(:edit_form).attributes)
|
169
|
+
assert_equal(PasswordEditForm.new.attributes, assigns(:edit_form).attributes)
|
171
170
|
end
|
172
171
|
|
173
172
|
test "GET edit_password, abnormal, no login" do
|
@@ -0,0 +1,292 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'test_helper'
|
3
|
+
|
4
|
+
class Credentials::NameControllerTest < ActionController::TestCase
|
5
|
+
def setup
|
6
|
+
@yuya = users(:yuya)
|
7
|
+
@nayutaya = name_credentials(:nayutaya)
|
8
|
+
@risa_risa = name_credentials(:risa_risa)
|
9
|
+
|
10
|
+
@edit_form = NameCredentialEditForm.new(
|
11
|
+
:name => "name",
|
12
|
+
:password => "password",
|
13
|
+
:password_confirmation => "password")
|
14
|
+
|
15
|
+
@password_edit_form = PasswordEditForm.new(
|
16
|
+
:password => "password",
|
17
|
+
:password_confirmation => "password")
|
18
|
+
|
19
|
+
session_login(@yuya)
|
20
|
+
end
|
21
|
+
|
22
|
+
test "routes" do
|
23
|
+
base = {:controller => "credentials/name"}
|
24
|
+
|
25
|
+
assert_routing("/credentials/name/new", base.merge(:action => "new"))
|
26
|
+
assert_routing("/credentials/name/create", base.merge(:action => "create"))
|
27
|
+
|
28
|
+
assert_routing("/credential/name/1234567890/edit_password", base.merge(:action => "edit_password", :name_credential_id => "1234567890"))
|
29
|
+
assert_routing("/credential/name/1234567890/update_password", base.merge(:action => "update_password", :name_credential_id => "1234567890"))
|
30
|
+
assert_routing("/credential/name/1234567890/delete", base.merge(:action => "delete", :name_credential_id => "1234567890"))
|
31
|
+
assert_routing("/credential/name/1234567890/destroy", base.merge(:action => "destroy", :name_credential_id => "1234567890"))
|
32
|
+
end
|
33
|
+
|
34
|
+
test "GET new" do
|
35
|
+
get :new
|
36
|
+
|
37
|
+
assert_response(:success)
|
38
|
+
assert_template("new")
|
39
|
+
assert_flash_empty
|
40
|
+
assert_logged_in(@yuya)
|
41
|
+
|
42
|
+
assert_equal(
|
43
|
+
NameCredentialEditForm.new.attributes,
|
44
|
+
assigns(:edit_form).attributes)
|
45
|
+
end
|
46
|
+
|
47
|
+
test "GET new, abnormal, no login" do
|
48
|
+
session_logout
|
49
|
+
|
50
|
+
get :new
|
51
|
+
|
52
|
+
assert_response(:redirect)
|
53
|
+
assert_redirected_to(root_path)
|
54
|
+
assert_flash_error
|
55
|
+
end
|
56
|
+
|
57
|
+
test "POST create" do
|
58
|
+
assert_equal(true, @edit_form.valid?)
|
59
|
+
|
60
|
+
assert_difference("NameCredential.count", +1) {
|
61
|
+
post :create, :edit_form => @edit_form.attributes
|
62
|
+
}
|
63
|
+
|
64
|
+
assert_response(:redirect)
|
65
|
+
assert_redirected_to(:controller => "/credentials", :action => "index")
|
66
|
+
assert_flash_notice
|
67
|
+
assert_logged_in(@yuya)
|
68
|
+
assert_equal(@edit_form.attributes, assigns(:edit_form).attributes)
|
69
|
+
assigns(:name_credential).reload
|
70
|
+
assert_equal(@yuya.id, assigns(:name_credential).user_id)
|
71
|
+
assert_equal(@edit_form.name, assigns(:name_credential).name)
|
72
|
+
assert_equal(true, NameCredential.compare_hashed_password(@edit_form.password, assigns(:name_credential).hashed_password))
|
73
|
+
end
|
74
|
+
|
75
|
+
test "POST create, invalid form" do
|
76
|
+
@edit_form.name = nil
|
77
|
+
assert_equal(false, @edit_form.valid?)
|
78
|
+
|
79
|
+
assert_difference("NameCredential.count", 0) {
|
80
|
+
post :create, :edit_form => @edit_form.attributes
|
81
|
+
}
|
82
|
+
|
83
|
+
assert_response(:success)
|
84
|
+
assert_template("new")
|
85
|
+
assert_flash_error
|
86
|
+
|
87
|
+
assert_equal(nil, assigns(:edit_form).password)
|
88
|
+
assert_equal(nil, assigns(:edit_form).password_confirmation)
|
89
|
+
end
|
90
|
+
|
91
|
+
test "GET create, abnormal, method not allowed" do
|
92
|
+
get :create
|
93
|
+
|
94
|
+
assert_response(405)
|
95
|
+
assert_template(nil)
|
96
|
+
end
|
97
|
+
|
98
|
+
test "POST create, abnormal, no login" do
|
99
|
+
session_logout
|
100
|
+
|
101
|
+
post :create
|
102
|
+
|
103
|
+
assert_response(:redirect)
|
104
|
+
assert_redirected_to(root_path)
|
105
|
+
assert_flash_error
|
106
|
+
end
|
107
|
+
|
108
|
+
test "GET edit_password" do
|
109
|
+
get :edit_password, :name_credential_id => @nayutaya.id
|
110
|
+
|
111
|
+
assert_response(:success)
|
112
|
+
assert_template("edit_password")
|
113
|
+
assert_flash_empty
|
114
|
+
assert_logged_in(@yuya)
|
115
|
+
|
116
|
+
assert_equal(@nayutaya, assigns(:name_credential))
|
117
|
+
|
118
|
+
assert_equal(PasswordEditForm.new.attributes, assigns(:edit_form).attributes)
|
119
|
+
end
|
120
|
+
|
121
|
+
test "GET edit_password, abnormal, no login" do
|
122
|
+
session_logout
|
123
|
+
|
124
|
+
get :edit_password, :name_credential_id => @nayutaya.id
|
125
|
+
|
126
|
+
assert_response(:redirect)
|
127
|
+
assert_redirected_to(root_path)
|
128
|
+
assert_flash_error
|
129
|
+
end
|
130
|
+
|
131
|
+
test "GET edit_password, abnormal, invalid name credential id" do
|
132
|
+
get :edit_password, :name_credential_id => "0"
|
133
|
+
|
134
|
+
assert_response(:redirect)
|
135
|
+
assert_redirected_to(root_path)
|
136
|
+
assert_flash_error
|
137
|
+
end
|
138
|
+
|
139
|
+
test "GET edit_password, abnormal, other's name credential" do
|
140
|
+
get :edit_password, :name_credential_id => @risa_risa.id
|
141
|
+
|
142
|
+
assert_response(:redirect)
|
143
|
+
assert_redirected_to(root_path)
|
144
|
+
assert_flash_error
|
145
|
+
end
|
146
|
+
|
147
|
+
test "POST update_password" do
|
148
|
+
assert_equal(true, @password_edit_form.valid?)
|
149
|
+
|
150
|
+
post :update_password, :name_credential_id => @nayutaya.id, :edit_form => @password_edit_form.attributes
|
151
|
+
|
152
|
+
assert_response(:redirect)
|
153
|
+
assert_redirected_to(:controller => "/credentials", :action => "index")
|
154
|
+
assert_flash_notice
|
155
|
+
assert_logged_in(@yuya)
|
156
|
+
|
157
|
+
assert_equal(@nayutaya, assigns(:name_credential))
|
158
|
+
|
159
|
+
assert_equal(
|
160
|
+
@password_edit_form.attributes,
|
161
|
+
assigns(:edit_form).attributes)
|
162
|
+
|
163
|
+
assigns(:name_credential).reload
|
164
|
+
assert_equal(
|
165
|
+
true,
|
166
|
+
NameCredential.compare_hashed_password(@password_edit_form.password, assigns(:name_credential).hashed_password))
|
167
|
+
end
|
168
|
+
|
169
|
+
test "POST update_password, invalid form" do
|
170
|
+
@password_edit_form.password = "x"
|
171
|
+
assert_equal(false, @password_edit_form.valid?)
|
172
|
+
|
173
|
+
post :update_password, :name_credential_id => @nayutaya.id, :edit_form => @password_edit_form.attributes
|
174
|
+
|
175
|
+
assert_response(:success)
|
176
|
+
assert_template("edit_password")
|
177
|
+
assert_flash_error
|
178
|
+
|
179
|
+
assert_equal(nil, assigns(:edit_form).password)
|
180
|
+
assert_equal(nil, assigns(:edit_form).password_confirmation)
|
181
|
+
end
|
182
|
+
|
183
|
+
test "GET update_password, abnormal, method not allowed" do
|
184
|
+
get :update_password, :name_credential_id => @nayutaya.id
|
185
|
+
|
186
|
+
assert_response(405)
|
187
|
+
assert_template(nil)
|
188
|
+
end
|
189
|
+
|
190
|
+
test "POST update_password, abnormal, no login" do
|
191
|
+
session_logout
|
192
|
+
|
193
|
+
post :update_password, :name_credential_id => @nayutaya.id
|
194
|
+
|
195
|
+
assert_response(:redirect)
|
196
|
+
assert_redirected_to(root_path)
|
197
|
+
assert_flash_error
|
198
|
+
end
|
199
|
+
|
200
|
+
test "POST update_password, abnormal, invalid name credential id" do
|
201
|
+
post :update_password, :name_credential_id => "0"
|
202
|
+
|
203
|
+
assert_response(:redirect)
|
204
|
+
assert_redirected_to(root_path)
|
205
|
+
assert_flash_error
|
206
|
+
end
|
207
|
+
|
208
|
+
test "GET delete" do
|
209
|
+
get :delete, :name_credential_id => @nayutaya.id
|
210
|
+
|
211
|
+
assert_response(:success)
|
212
|
+
assert_template("delete")
|
213
|
+
assert_flash_empty
|
214
|
+
assert_logged_in(@yuya)
|
215
|
+
|
216
|
+
assert_equal(@nayutaya, assigns(:name_credential))
|
217
|
+
end
|
218
|
+
|
219
|
+
test "GET delete, abnormal, no login" do
|
220
|
+
session_logout
|
221
|
+
|
222
|
+
get :delete, :name_credential_id => @nayutaya.id
|
223
|
+
|
224
|
+
assert_response(:redirect)
|
225
|
+
assert_redirected_to(root_path)
|
226
|
+
assert_flash_error
|
227
|
+
end
|
228
|
+
|
229
|
+
test "GET delete, abnormal, invalid name credential id" do
|
230
|
+
get :delete, :name_credential_id => "0"
|
231
|
+
|
232
|
+
assert_response(:redirect)
|
233
|
+
assert_redirected_to(root_path)
|
234
|
+
assert_flash_error
|
235
|
+
end
|
236
|
+
|
237
|
+
test "GET delete, abnormal, other's name credential" do
|
238
|
+
get :delete, :name_credential_id => @risa_risa.id
|
239
|
+
|
240
|
+
assert_response(:redirect)
|
241
|
+
assert_redirected_to(root_path)
|
242
|
+
assert_flash_error
|
243
|
+
end
|
244
|
+
|
245
|
+
test "POST destroy" do
|
246
|
+
assert_difference("NameCredential.count", -1) {
|
247
|
+
post :destroy, :name_credential_id => @nayutaya.id
|
248
|
+
}
|
249
|
+
|
250
|
+
assert_response(:redirect)
|
251
|
+
assert_redirected_to(:controller => "/credentials", :action => "index")
|
252
|
+
assert_flash_notice
|
253
|
+
assert_logged_in(@yuya)
|
254
|
+
|
255
|
+
assert_equal(@nayutaya, assigns(:name_credential))
|
256
|
+
|
257
|
+
assert_equal(nil, NameCredential.find_by_id(@nayutaya.id))
|
258
|
+
end
|
259
|
+
|
260
|
+
test "GET destroy, abnormal, method not allowed" do
|
261
|
+
get :destroy, :name_credential_id => @nayutaya.id
|
262
|
+
|
263
|
+
assert_response(405)
|
264
|
+
assert_template(nil)
|
265
|
+
end
|
266
|
+
|
267
|
+
test "POST destroy, abnormal, no login" do
|
268
|
+
session_logout
|
269
|
+
|
270
|
+
post :destroy, :name_credential_id => @nayutaya.id
|
271
|
+
|
272
|
+
assert_response(:redirect)
|
273
|
+
assert_redirected_to(root_path)
|
274
|
+
assert_flash_error
|
275
|
+
end
|
276
|
+
|
277
|
+
test "POST destroy, abnormal, invalid name credential id" do
|
278
|
+
post :destroy, :name_credential_id => "0"
|
279
|
+
|
280
|
+
assert_response(:redirect)
|
281
|
+
assert_redirected_to(root_path)
|
282
|
+
assert_flash_error
|
283
|
+
end
|
284
|
+
|
285
|
+
test "POST destroy, abnormal, other's name credential" do
|
286
|
+
post :destroy, :name_credential_id => @risa_risa.id
|
287
|
+
|
288
|
+
assert_response(:redirect)
|
289
|
+
assert_redirected_to(root_path)
|
290
|
+
assert_flash_error
|
291
|
+
end
|
292
|
+
end
|
@@ -0,0 +1,151 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'test_helper'
|
3
|
+
|
4
|
+
class NameCredentialEditFormTest < ActiveSupport::TestCase
|
5
|
+
def setup
|
6
|
+
@klass = NameCredentialEditForm
|
7
|
+
@form = @klass.new
|
8
|
+
@basic = @klass.new(:name => "name",
|
9
|
+
:password => "password", :password_confirmation => "password")
|
10
|
+
end
|
11
|
+
|
12
|
+
#
|
13
|
+
# 基底クラス
|
14
|
+
#
|
15
|
+
|
16
|
+
test "superclass" do
|
17
|
+
assert_equal(ActiveForm, @klass.superclass)
|
18
|
+
end
|
19
|
+
|
20
|
+
#
|
21
|
+
# カラム
|
22
|
+
#
|
23
|
+
|
24
|
+
test "columns" do
|
25
|
+
[
|
26
|
+
[:name, nil, "str", "str"],
|
27
|
+
[:password, nil, "str", "str"],
|
28
|
+
[:password_confirmation, nil, "str", "str"],
|
29
|
+
].each { |name, default, set_value, get_value|
|
30
|
+
form = @klass.new
|
31
|
+
assert_equal(default, form.__send__(name))
|
32
|
+
form.__send__("#{name}=", set_value)
|
33
|
+
assert_equal(get_value, form.__send__(name))
|
34
|
+
}
|
35
|
+
end
|
36
|
+
|
37
|
+
#
|
38
|
+
# 検証
|
39
|
+
#
|
40
|
+
|
41
|
+
test "basic is valid" do
|
42
|
+
assert_equal(true, @basic.valid?)
|
43
|
+
end
|
44
|
+
|
45
|
+
test "validates_presence_of :name" do
|
46
|
+
@basic.name = nil
|
47
|
+
assert_equal(false, @basic.valid?)
|
48
|
+
end
|
49
|
+
|
50
|
+
test "validates_presence_of :password" do
|
51
|
+
@basic.password = nil
|
52
|
+
assert_equal(false, @basic.valid?)
|
53
|
+
end
|
54
|
+
|
55
|
+
test "validates_presence_of :password_confirmation" do
|
56
|
+
@basic.password_confirmation = nil
|
57
|
+
assert_equal(false, @basic.valid?)
|
58
|
+
end
|
59
|
+
|
60
|
+
test "validates_length_of :name" do
|
61
|
+
[
|
62
|
+
["a" * 13, 13, true ],
|
63
|
+
["a" * 200, 200, true ],
|
64
|
+
["a" * 201, 201, false],
|
65
|
+
].each { |value, length, expected|
|
66
|
+
assert_equal(length, value.size)
|
67
|
+
@basic.name = value
|
68
|
+
assert_equal(expected, @basic.valid?)
|
69
|
+
}
|
70
|
+
end
|
71
|
+
|
72
|
+
test "validates_length_of :password" do
|
73
|
+
[
|
74
|
+
["a" * 3, false],
|
75
|
+
["a" * 4, true ],
|
76
|
+
["a" * 20, true ],
|
77
|
+
["a" * 21, false],
|
78
|
+
].each { |value, expected|
|
79
|
+
@basic.password = value
|
80
|
+
@basic.password_confirmation = value
|
81
|
+
assert_equal(expected, @basic.valid?)
|
82
|
+
}
|
83
|
+
end
|
84
|
+
|
85
|
+
test "validates_format_of :password" do
|
86
|
+
valid_chars = (0x21..0x7E).map { |c| c.chr }.join
|
87
|
+
|
88
|
+
[
|
89
|
+
[valid_chars.slice!(0, 20), true ],
|
90
|
+
[valid_chars.slice!(0, 20), true ],
|
91
|
+
[valid_chars.slice!(0, 20), true ],
|
92
|
+
[valid_chars.slice!(0, 20), true ],
|
93
|
+
[valid_chars.slice!(0, 20), true ],
|
94
|
+
["aaaa", true ],
|
95
|
+
["aaa ", false],
|
96
|
+
["日本語", false],
|
97
|
+
].each { |value, expected|
|
98
|
+
@basic.password = value
|
99
|
+
@basic.password_confirmation = value
|
100
|
+
assert_equal(expected, @basic.valid?)
|
101
|
+
}
|
102
|
+
|
103
|
+
assert_equal(true, valid_chars.empty?)
|
104
|
+
end
|
105
|
+
|
106
|
+
test "validates_each, password" do
|
107
|
+
@basic.password = "aaaa"
|
108
|
+
@basic.password_confirmation = "aaaa"
|
109
|
+
assert_equal(true, @basic.valid?)
|
110
|
+
|
111
|
+
@basic.password = "aaaa"
|
112
|
+
@basic.password_confirmation = "AAAA"
|
113
|
+
assert_equal(false, @basic.valid?)
|
114
|
+
end
|
115
|
+
#
|
116
|
+
# インスタンスメソッド
|
117
|
+
#
|
118
|
+
|
119
|
+
test "masked_password" do
|
120
|
+
@form.password = nil
|
121
|
+
assert_equal("", @form.masked_password)
|
122
|
+
|
123
|
+
@form.password = "a"
|
124
|
+
assert_equal("*", @form.masked_password)
|
125
|
+
|
126
|
+
@form.password = "abc"
|
127
|
+
assert_equal("***", @form.masked_password)
|
128
|
+
end
|
129
|
+
|
130
|
+
test "to_name_credential_hash, empty" do
|
131
|
+
hash = @form.to_name_credential_hash
|
132
|
+
assert_equal(
|
133
|
+
[:name, :hashed_password].map(&:to_s).sort,
|
134
|
+
hash.keys.map(&:to_s).sort)
|
135
|
+
assert_equal(nil, hash[:name])
|
136
|
+
assert_equal(true, NameCredential.compare_hashed_password("", hash[:hashed_password]))
|
137
|
+
end
|
138
|
+
|
139
|
+
test "to_name_credential_hash, full" do
|
140
|
+
@form.attributes = {
|
141
|
+
:name => "foo@example.com",
|
142
|
+
:password => "foo",
|
143
|
+
}
|
144
|
+
hash = @form.to_name_credential_hash
|
145
|
+
assert_equal(
|
146
|
+
[:name, :hashed_password].map(&:to_s).sort,
|
147
|
+
hash.keys.map(&:to_s).sort)
|
148
|
+
assert_equal(@form.name, hash[:name])
|
149
|
+
assert_equal(true, NameCredential.compare_hashed_password(@form.password, hash[:hashed_password]))
|
150
|
+
end
|
151
|
+
end
|