authpwn_rails 0.16.0 → 0.16.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/app/models/credentials/email.rb +1 -0
- data/authpwn_rails.gemspec +1 -1
- data/lib/authpwn_rails/generators/templates/credentials.yml +2 -2
- data/lib/authpwn_rails/generators/templates/session_controller_test.rb +9 -8
- data/test/credentials/email_credential_test.rb +19 -6
- data/test/credentials/one_time_token_credential_test.rb +12 -14
- data/test/credentials/password_credential_test.rb +12 -6
- data/test/credentials/token_crendential_test.rb +5 -5
- data/test/session_controller_api_test.rb +30 -30
- data/test/user_test.rb +7 -5
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 55e00431fac95ebeaa4bffd96d5f03a788bc0340
|
4
|
+
data.tar.gz: 80a15431b638ed0798dd0b22735f8ced99770b4c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4bb61cd308147854a0712247e38678c8d311d9ef145973138218e2b4cae76af334597333e79616f517c9b02fcbfc7bfcaf71d9a6dcc87f3a4a8a3c1a18bce1a8
|
7
|
+
data.tar.gz: b9b35f7de8f897de9674242e7311f10e1faa57f8ce7c429388aca357cf9ee0c78fece76711579385f2b0e6a2574f008f61e26c104187093ca0edbca16d0d9408
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.16.
|
1
|
+
0.16.1
|
data/authpwn_rails.gemspec
CHANGED
@@ -35,12 +35,12 @@ john_facebook:
|
|
35
35
|
|
36
36
|
jane_token:
|
37
37
|
user: jane
|
38
|
-
type: Tokens::
|
38
|
+
type: Tokens::OneTime
|
39
39
|
name: 6TXe1vv7BgOw0BkJ1hzUKO6G08fLk4sVfJ3wPDZHS-c
|
40
40
|
|
41
41
|
john_token:
|
42
42
|
user: john
|
43
|
-
type: Tokens::
|
43
|
+
type: Tokens::Base
|
44
44
|
name: YZ-Fo8HX6_NyU6lVZXYi6cMDLV5eAgt35UTF5l8bD6A
|
45
45
|
|
46
46
|
john_email_token:
|
@@ -2,10 +2,9 @@ require 'test_helper'
|
|
2
2
|
|
3
3
|
class SessionControllerTest < ActionController::TestCase
|
4
4
|
setup do
|
5
|
-
@user = users(:
|
6
|
-
@email_credential = credentials(:
|
7
|
-
@password_credential = credentials(:
|
8
|
-
@token_credential = credentials(:john_email_token)
|
5
|
+
@user = users(:jane)
|
6
|
+
@email_credential = credentials(:jane_email)
|
7
|
+
@password_credential = credentials(:jane_password)
|
9
8
|
end
|
10
9
|
|
11
10
|
test "user home page" do
|
@@ -21,7 +20,7 @@ class SessionControllerTest < ActionController::TestCase
|
|
21
20
|
old_token.updated_at = Time.now - 1.year
|
22
21
|
old_token.save!
|
23
22
|
post :create, session: { email: @email_credential.email,
|
24
|
-
password: '
|
23
|
+
password: 'pa55w0rd' }
|
25
24
|
assert_equal @user, session_current_user, 'session'
|
26
25
|
assert_redirected_to session_url
|
27
26
|
assert_nil Tokens::Base.with_code(old_token.code).first,
|
@@ -40,7 +39,7 @@ class SessionControllerTest < ActionController::TestCase
|
|
40
39
|
get :show
|
41
40
|
|
42
41
|
assert_equal User.count, assigns(:user_count)
|
43
|
-
assert_select 'a', 'sign in'
|
42
|
+
assert_select 'a[href="/session/new"]', 'sign in'
|
44
43
|
end
|
45
44
|
|
46
45
|
test "user not logged in with JSON request" do
|
@@ -62,9 +61,11 @@ class SessionControllerTest < ActionController::TestCase
|
|
62
61
|
end
|
63
62
|
|
64
63
|
test "e-mail verification link" do
|
65
|
-
|
64
|
+
token_credential = credentials(:john_email_token)
|
65
|
+
email_credential = credentials(:john_email)
|
66
|
+
get :token, code: token_credential.code
|
66
67
|
assert_redirected_to session_url
|
67
|
-
assert
|
68
|
+
assert email_credential.reload.verified?, 'Email not verified'
|
68
69
|
end
|
69
70
|
|
70
71
|
test "password reset link" do
|
@@ -71,17 +71,30 @@ class EmailCredentialTest < ActiveSupport::TestCase
|
|
71
71
|
end
|
72
72
|
|
73
73
|
test 'authenticate' do
|
74
|
-
assert_equal users(:
|
75
|
-
|
74
|
+
assert_equal users(:jane),
|
75
|
+
Credentials::Email.authenticate('jane@gmail.com')
|
76
|
+
assert_equal :blocked, Credentials::Email.authenticate('john@gmail.com')
|
76
77
|
assert_equal :invalid, Credentials::Email.authenticate('bill@gmail.com')
|
78
|
+
|
79
|
+
john_email = credentials(:john_email)
|
80
|
+
john_email.verified = true
|
81
|
+
john_email.save!
|
82
|
+
assert_equal users(:john),
|
83
|
+
Credentials::Email.authenticate('john@gmail.com')
|
77
84
|
end
|
78
85
|
|
79
86
|
test 'authenticate calls User#auth_bounce_reason' do
|
80
|
-
with_blocked_credential credentials(:
|
81
|
-
assert_equal :reason, Credentials::Email.authenticate('
|
82
|
-
assert_equal
|
83
|
-
Credentials::Email.authenticate('
|
87
|
+
with_blocked_credential credentials(:jane_email), :reason do
|
88
|
+
assert_equal :reason, Credentials::Email.authenticate('jane@gmail.com')
|
89
|
+
assert_equal :blocked,
|
90
|
+
Credentials::Email.authenticate('john@gmail.com')
|
84
91
|
assert_equal :invalid, Credentials::Email.authenticate('bill@gmail.com')
|
92
|
+
|
93
|
+
john_email = credentials(:john_email)
|
94
|
+
john_email.verified = true
|
95
|
+
john_email.save!
|
96
|
+
assert_equal users(:john),
|
97
|
+
Credentials::Email.authenticate('john@gmail.com')
|
85
98
|
end
|
86
99
|
end
|
87
100
|
end
|
@@ -17,7 +17,7 @@ class OneTimeTokenCredentialTest < ActiveSupport::TestCase
|
|
17
17
|
end
|
18
18
|
|
19
19
|
test 'code uniqueness' do
|
20
|
-
@credential.code = credentials(:
|
20
|
+
@credential.code = credentials(:jane_token).code
|
21
21
|
assert !@credential.valid?
|
22
22
|
end
|
23
23
|
|
@@ -27,7 +27,7 @@ class OneTimeTokenCredentialTest < ActiveSupport::TestCase
|
|
27
27
|
end
|
28
28
|
|
29
29
|
test 'spend destroys the token' do
|
30
|
-
credential = credentials(:
|
30
|
+
credential = credentials(:jane_token)
|
31
31
|
assert_equal Tokens::OneTime, credential.class, 'bad setup'
|
32
32
|
|
33
33
|
assert_difference 'Credential.count', -1 do
|
@@ -37,10 +37,10 @@ class OneTimeTokenCredentialTest < ActiveSupport::TestCase
|
|
37
37
|
end
|
38
38
|
|
39
39
|
test 'authenticate spends the token' do
|
40
|
-
|
40
|
+
jane = '6TXe1vv7BgOw0BkJ1hzUKO6G08fLk4sVfJ3wPDZHS-c'
|
41
41
|
bogus = 'AyCMIixa5C7BBqU-XFI7l7IaUFJ4zQZPmcK6oNb3FLo'
|
42
42
|
assert_difference 'Credential.count', -1, 'token spent' do
|
43
|
-
assert_equal users(:
|
43
|
+
assert_equal users(:jane), Tokens::Base.authenticate(jane)
|
44
44
|
end
|
45
45
|
assert_no_difference 'Credential.count', 'token mistakenly spent' do
|
46
46
|
assert_equal :invalid, Tokens::Base.authenticate(bogus)
|
@@ -48,37 +48,35 @@ class OneTimeTokenCredentialTest < ActiveSupport::TestCase
|
|
48
48
|
end
|
49
49
|
|
50
50
|
test 'authenticate calls User#auth_bounce_reason' do
|
51
|
-
john = 'YZ-Fo8HX6_NyU6lVZXYi6cMDLV5eAgt35UTF5l8bD6A'
|
52
51
|
jane = '6TXe1vv7BgOw0BkJ1hzUKO6G08fLk4sVfJ3wPDZHS-c'
|
53
|
-
bogus = 'AyCMIixa5C7BBqU-XFI7l7IaUFJ4zQZPmcK6oNb3FLo'
|
54
52
|
|
55
|
-
with_blocked_credential credentials(:
|
53
|
+
with_blocked_credential credentials(:jane_token), :reason do
|
56
54
|
assert_no_difference 'Credential.count', 'no token spent' do
|
57
|
-
assert_equal :reason, Tokens::Base.authenticate(
|
55
|
+
assert_equal :reason, Tokens::Base.authenticate(jane)
|
58
56
|
end
|
59
57
|
end
|
60
58
|
end
|
61
59
|
|
62
60
|
test 'instance authenticate spends the token' do
|
63
61
|
assert_difference 'Credential.count', -1, 'token spent' do
|
64
|
-
assert_equal users(:
|
62
|
+
assert_equal users(:jane), credentials(:jane_token).authenticate
|
65
63
|
end
|
66
64
|
end
|
67
65
|
|
68
66
|
test 'instance authenticate calls User#auth_bounce_reason' do
|
69
|
-
with_blocked_credential credentials(:
|
67
|
+
with_blocked_credential credentials(:jane_token), :reason do
|
70
68
|
assert_no_difference 'Credential.count', 'token mistakenly spent' do
|
71
|
-
assert_equal :reason, credentials(:
|
69
|
+
assert_equal :reason, credentials(:jane_token).authenticate
|
72
70
|
end
|
73
71
|
end
|
74
72
|
end
|
75
73
|
|
76
74
|
test 'random_for' do
|
77
|
-
token = Tokens::OneTime.random_for users(:
|
75
|
+
token = Tokens::OneTime.random_for users(:jane)
|
78
76
|
assert token.valid?, 'valid token'
|
79
|
-
assert_equal users(:
|
77
|
+
assert_equal users(:jane), token.user
|
80
78
|
assert_equal Tokens::OneTime, token.class
|
81
79
|
assert !token.new_record?, 'saved token'
|
82
|
-
assert_operator users(:
|
80
|
+
assert_operator users(:jane).credentials, :include?, token
|
83
81
|
end
|
84
82
|
end
|
@@ -77,24 +77,30 @@ class PasswordCredentialTest < ActiveSupport::TestCase
|
|
77
77
|
end
|
78
78
|
|
79
79
|
test 'authenticate_email' do
|
80
|
-
assert_equal users(:john),
|
81
|
-
Credentials::Password.authenticate_email('john@gmail.com', 'password')
|
82
|
-
assert_equal :invalid,
|
83
|
-
Credentials::Password.authenticate_email('john@gmail.com', 'pa55w0rd'),
|
84
|
-
"Jane's password on John's account"
|
85
80
|
assert_equal users(:jane),
|
86
81
|
Credentials::Password.authenticate_email('jane@gmail.com', 'pa55w0rd')
|
87
82
|
assert_equal :invalid,
|
88
83
|
Credentials::Password.authenticate_email('jane@gmail.com', 'password'),
|
89
84
|
"John's password on Jane's account"
|
90
85
|
assert_equal :invalid,
|
91
|
-
Credentials::Password.authenticate_email('
|
86
|
+
Credentials::Password.authenticate_email('jane@gmail.com', 'awesome'),
|
92
87
|
'Bogus password'
|
88
|
+
assert_equal :blocked,
|
89
|
+
Credentials::Password.authenticate_email('john@gmail.com', 'password')
|
90
|
+
assert_equal :blocked,
|
91
|
+
Credentials::Password.authenticate_email('john@gmail.com', 'pa55w0rd'),
|
92
|
+
"Jane's password on John's account"
|
93
93
|
assert_equal :invalid,
|
94
94
|
Credentials::Password.authenticate_email('bill@gmail.com', 'pa55w0rd'),
|
95
95
|
'Password authentication on account without password credential'
|
96
96
|
assert_equal :invalid,
|
97
97
|
Credentials::Password.authenticate_email('none@gmail.com', 'pa55w0rd'),
|
98
98
|
'Bogus e-mail'
|
99
|
+
|
100
|
+
john_email = credentials(:john_email)
|
101
|
+
john_email.verified = true
|
102
|
+
john_email.save!
|
103
|
+
assert_equal users(:john),
|
104
|
+
Credentials::Password.authenticate_email('john@gmail.com', 'password')
|
99
105
|
end
|
100
106
|
end
|
@@ -17,7 +17,7 @@ class TokenCredentialTest < ActiveSupport::TestCase
|
|
17
17
|
end
|
18
18
|
|
19
19
|
test 'code uniqueness' do
|
20
|
-
@credential.code = credentials(:
|
20
|
+
@credential.code = credentials(:jane_token).code
|
21
21
|
assert !@credential.valid?
|
22
22
|
end
|
23
23
|
|
@@ -27,7 +27,7 @@ class TokenCredentialTest < ActiveSupport::TestCase
|
|
27
27
|
end
|
28
28
|
|
29
29
|
test 'spend does nothing' do
|
30
|
-
credential = credentials(:
|
30
|
+
credential = credentials(:john_token)
|
31
31
|
assert_equal Tokens::Base, credential.class, 'bad setup'
|
32
32
|
|
33
33
|
assert_no_difference 'Credential.count' do
|
@@ -36,12 +36,12 @@ class TokenCredentialTest < ActiveSupport::TestCase
|
|
36
36
|
end
|
37
37
|
|
38
38
|
test 'random_for' do
|
39
|
-
token = Tokens::Base.random_for users(:
|
39
|
+
token = Tokens::Base.random_for users(:jane)
|
40
40
|
assert token.valid?, 'valid token'
|
41
|
-
assert_equal users(:
|
41
|
+
assert_equal users(:jane), token.user
|
42
42
|
assert_equal Tokens::Base, token.class
|
43
43
|
assert !token.new_record?, 'saved token'
|
44
|
-
assert_operator users(:
|
44
|
+
assert_operator users(:jane).credentials, :include?, token
|
45
45
|
end
|
46
46
|
|
47
47
|
test 'with_code' do
|
@@ -15,10 +15,10 @@ class SessionControllerApiTest < ActionController::TestCase
|
|
15
15
|
tests BareSessionController
|
16
16
|
|
17
17
|
setup do
|
18
|
-
@user = users(:
|
19
|
-
@email_credential = credentials(:
|
20
|
-
@password_credential = credentials(:
|
21
|
-
@token_credential = credentials(:
|
18
|
+
@user = users(:jane)
|
19
|
+
@email_credential = credentials(:jane_email)
|
20
|
+
@password_credential = credentials(:jane_password)
|
21
|
+
@token_credential = credentials(:jane_token)
|
22
22
|
@_auto_purge_sessions = BareSessionController.auto_purge_sessions
|
23
23
|
end
|
24
24
|
|
@@ -81,7 +81,7 @@ class SessionControllerApiTest < ActionController::TestCase
|
|
81
81
|
|
82
82
|
test "create logs in with good account details" do
|
83
83
|
post :create, session: { email: @email_credential.email,
|
84
|
-
password: '
|
84
|
+
password: 'pa55w0rd' }
|
85
85
|
assert_equal @user, assigns(:current_user), 'instance variable'
|
86
86
|
assert_equal @user, session_current_user, 'session'
|
87
87
|
assert_nil flash[:alert], 'no alert'
|
@@ -90,7 +90,7 @@ class SessionControllerApiTest < ActionController::TestCase
|
|
90
90
|
end
|
91
91
|
|
92
92
|
test "create logs in with good raw account details" do
|
93
|
-
post :create, email: @email_credential.email, password: '
|
93
|
+
post :create, email: @email_credential.email, password: 'pa55w0rd'
|
94
94
|
assert_equal @user, assigns(:current_user), 'instance variable'
|
95
95
|
assert_equal @user, session_current_user, 'session'
|
96
96
|
assert_nil flash[:alert], 'no alert'
|
@@ -104,7 +104,7 @@ class SessionControllerApiTest < ActionController::TestCase
|
|
104
104
|
old_token.updated_at = Time.now - 1.year
|
105
105
|
old_token.save!
|
106
106
|
post :create, session: { email: @email_credential.email,
|
107
|
-
password: '
|
107
|
+
password: 'pa55w0rd' }
|
108
108
|
assert_equal @user, session_current_user, 'session'
|
109
109
|
assert_nil Tokens::Base.with_code(old_token.code).first,
|
110
110
|
'old session not purged'
|
@@ -115,14 +115,14 @@ class SessionControllerApiTest < ActionController::TestCase
|
|
115
115
|
old_token = credentials(:jane_session_token)
|
116
116
|
old_token.updated_at = Time.now - 1.year
|
117
117
|
old_token.save!
|
118
|
-
post :create, email: @email_credential.email, password: '
|
118
|
+
post :create, email: @email_credential.email, password: 'pa55w0rd'
|
119
119
|
assert_equal @user, session_current_user, 'session'
|
120
120
|
assert_equal old_token, Tokens::Base.with_code(old_token.code).first,
|
121
121
|
'old session purged'
|
122
122
|
end
|
123
123
|
|
124
124
|
test "create by json logs in with good account details" do
|
125
|
-
post :create, email: @email_credential.email, password: '
|
125
|
+
post :create, email: @email_credential.email, password: 'pa55w0rd',
|
126
126
|
format: 'json'
|
127
127
|
assert_response :ok
|
128
128
|
data = ActiveSupport::JSON.decode response.body
|
@@ -137,7 +137,7 @@ class SessionControllerApiTest < ActionController::TestCase
|
|
137
137
|
old_token = credentials(:jane_session_token)
|
138
138
|
old_token.updated_at = Time.now - 1.year
|
139
139
|
old_token.save!
|
140
|
-
post :create, email: @email_credential.email, password: '
|
140
|
+
post :create, email: @email_credential.email, password: 'pa55w0rd',
|
141
141
|
format: 'json'
|
142
142
|
assert_response :ok
|
143
143
|
assert_equal @user, session_current_user, 'session'
|
@@ -148,7 +148,7 @@ class SessionControllerApiTest < ActionController::TestCase
|
|
148
148
|
test "create redirects properly with good account details" do
|
149
149
|
url = 'http://authpwn.redirect.url'
|
150
150
|
post :create, session: { email: @email_credential.email,
|
151
|
-
password: '
|
151
|
+
password: 'pa55w0rd' }, redirect_url: url
|
152
152
|
assert_redirected_to url
|
153
153
|
assert_nil flash[:alert], 'no alert'
|
154
154
|
assert_nil flash[:auth_redirect_url], 'no redirect URL in flash'
|
@@ -167,7 +167,7 @@ class SessionControllerApiTest < ActionController::TestCase
|
|
167
167
|
@password_credential.updated_at = Time.now - 2.years
|
168
168
|
@password_credential.save!
|
169
169
|
post :create, session: { email: @email_credential.email,
|
170
|
-
password: '
|
170
|
+
password: 'pa55w0rd' }
|
171
171
|
assert_redirected_to new_session_url
|
172
172
|
assert_nil assigns(:current_user), 'instance variable'
|
173
173
|
assert_nil session_current_user, 'session'
|
@@ -189,7 +189,7 @@ class SessionControllerApiTest < ActionController::TestCase
|
|
189
189
|
test "create does not log in blocked accounts" do
|
190
190
|
with_blocked_credential @email_credential do
|
191
191
|
post :create, session: { email: @email_credential.email,
|
192
|
-
password: '
|
192
|
+
password: 'pa55w0rd' }
|
193
193
|
end
|
194
194
|
assert_redirected_to new_session_url
|
195
195
|
assert_nil assigns(:current_user), 'instance variable'
|
@@ -221,7 +221,7 @@ class SessionControllerApiTest < ActionController::TestCase
|
|
221
221
|
test "create by json does not log in with expired password" do
|
222
222
|
@password_credential.updated_at = Time.now - 2.years
|
223
223
|
@password_credential.save!
|
224
|
-
post :create, email: @email_credential.email, password: '
|
224
|
+
post :create, email: @email_credential.email, password: 'pa55w0rd',
|
225
225
|
format: 'json'
|
226
226
|
assert_response :ok
|
227
227
|
data = ActiveSupport::JSON.decode response.body
|
@@ -233,7 +233,7 @@ class SessionControllerApiTest < ActionController::TestCase
|
|
233
233
|
|
234
234
|
test "create by json does not log in blocked accounts" do
|
235
235
|
with_blocked_credential @email_credential do
|
236
|
-
post :create, email: @email_credential.email, password: '
|
236
|
+
post :create, email: @email_credential.email, password: 'pa55w0rd',
|
237
237
|
format: 'json'
|
238
238
|
end
|
239
239
|
assert_response :ok
|
@@ -365,15 +365,15 @@ class SessionControllerApiTest < ActionController::TestCase
|
|
365
365
|
end
|
366
366
|
|
367
367
|
test "change_password bounces without logged in user" do
|
368
|
-
post :change_password, old_password: '
|
368
|
+
post :change_password, old_password: 'pa55w0rd',
|
369
369
|
credential: { password: 'hacks',
|
370
|
-
|
370
|
+
password_confirmation: 'hacks'}
|
371
371
|
assert_response :forbidden
|
372
372
|
end
|
373
373
|
|
374
374
|
test "change_password works with correct input" do
|
375
375
|
set_session_current_user @user
|
376
|
-
post :change_password, old_password: '
|
376
|
+
post :change_password, old_password: 'pa55w0rd',
|
377
377
|
credential: { password: 'hacks', password_confirmation: 'hacks'}
|
378
378
|
assert_redirected_to session_url
|
379
379
|
assert_equal @password_credential, assigns(:credential)
|
@@ -383,7 +383,7 @@ class SessionControllerApiTest < ActionController::TestCase
|
|
383
383
|
|
384
384
|
test "change_password works with correct input and extra form input" do
|
385
385
|
set_session_current_user @user
|
386
|
-
post :change_password, old_password: '
|
386
|
+
post :change_password, old_password: 'pa55w0rd',
|
387
387
|
credential: { password: 'hacks', password_confirmation: 'hacks'},
|
388
388
|
utf8: "\u2713", commit: 'Change password'
|
389
389
|
assert_redirected_to session_url
|
@@ -394,24 +394,24 @@ class SessionControllerApiTest < ActionController::TestCase
|
|
394
394
|
|
395
395
|
test "change_password rejects bad old password" do
|
396
396
|
set_session_current_user @user
|
397
|
-
post :change_password, old_password: '
|
397
|
+
post :change_password, old_password: '_pa55w0rd',
|
398
398
|
credential: { password: 'hacks', password_confirmation: 'hacks'}
|
399
399
|
assert_response :ok
|
400
400
|
assert_template :password_change
|
401
401
|
assert_equal @password_credential, assigns(:credential)
|
402
402
|
assert_equal @user, User.authenticate_signin(@email_credential.email,
|
403
|
-
'
|
403
|
+
'pa55w0rd'), 'password wrongly changed'
|
404
404
|
end
|
405
405
|
|
406
406
|
test "change_password rejects un-confirmed password" do
|
407
407
|
set_session_current_user @user
|
408
|
-
post :change_password, old_password: '
|
408
|
+
post :change_password, old_password: 'pa55w0rd',
|
409
409
|
credential: { password: 'hacks', password_confirmation: 'hacks_'}
|
410
410
|
assert_response :ok
|
411
411
|
assert_template :password_change
|
412
412
|
assert_equal @password_credential, assigns(:credential)
|
413
413
|
assert_equal @user, User.authenticate_signin( @email_credential.email,
|
414
|
-
'
|
414
|
+
'pa55w0rd'), 'password wrongly changed'
|
415
415
|
end
|
416
416
|
|
417
417
|
test "change_password works for password recovery" do
|
@@ -438,7 +438,7 @@ class SessionControllerApiTest < ActionController::TestCase
|
|
438
438
|
end
|
439
439
|
|
440
440
|
test "change_password by json bounces without logged in user" do
|
441
|
-
post :change_password, format: 'json', old_password: '
|
441
|
+
post :change_password, format: 'json', old_password: 'pa55w0rd',
|
442
442
|
credential: { password: 'hacks', password_confirmation: 'hacks'}
|
443
443
|
assert_response :ok
|
444
444
|
data = ActiveSupport::JSON.decode response.body
|
@@ -447,7 +447,7 @@ class SessionControllerApiTest < ActionController::TestCase
|
|
447
447
|
|
448
448
|
test "change_password by json works with correct input" do
|
449
449
|
set_session_current_user @user
|
450
|
-
post :change_password, format: 'json', old_password: '
|
450
|
+
post :change_password, format: 'json', old_password: 'pa55w0rd',
|
451
451
|
credential: { password: 'hacks',
|
452
452
|
password_confirmation: 'hacks'}
|
453
453
|
assert_response :ok
|
@@ -457,25 +457,25 @@ class SessionControllerApiTest < ActionController::TestCase
|
|
457
457
|
|
458
458
|
test "change_password by json rejects bad old password" do
|
459
459
|
set_session_current_user @user
|
460
|
-
post :change_password, format: 'json', old_password: '
|
460
|
+
post :change_password, format: 'json', old_password: '_pa55w0rd',
|
461
461
|
credential: { password: 'hacks', password_confirmation: 'hacks'}
|
462
462
|
assert_response :ok
|
463
463
|
data = ActiveSupport::JSON.decode response.body
|
464
464
|
assert_equal 'invalid', data['error']
|
465
465
|
assert_equal @password_credential, assigns(:credential)
|
466
466
|
assert_equal @user, User.authenticate_signin(@email_credential.email,
|
467
|
-
'
|
467
|
+
'pa55w0rd'), 'password wrongly changed'
|
468
468
|
end
|
469
469
|
|
470
470
|
test "change_password by json rejects un-confirmed password" do
|
471
471
|
set_session_current_user @user
|
472
|
-
post :change_password, format: 'json', old_password: '
|
472
|
+
post :change_password, format: 'json', old_password: 'pa55w0rd',
|
473
473
|
credential: { password: 'hacks', password_confirmation: 'hacks_'}
|
474
474
|
assert_response :ok
|
475
475
|
data = ActiveSupport::JSON.decode response.body
|
476
476
|
assert_equal 'invalid', data['error']
|
477
|
-
assert_equal @user, User.authenticate_signin(
|
478
|
-
'
|
477
|
+
assert_equal @user, User.authenticate_signin(@email_credential.email,
|
478
|
+
'pa55w0rd'), 'password wrongly changed'
|
479
479
|
end
|
480
480
|
|
481
481
|
test "change_password by json works for password recovery" do
|
data/test/user_test.rb
CHANGED
@@ -56,12 +56,14 @@ class UserTest < ActiveSupport::TestCase
|
|
56
56
|
assert_equal nil, User.find_by_param(nil)
|
57
57
|
end
|
58
58
|
|
59
|
-
test '
|
60
|
-
assert_equal users(:
|
61
|
-
User.authenticate_signin('
|
59
|
+
test 'authenticate_signin' do
|
60
|
+
assert_equal users(:jane),
|
61
|
+
User.authenticate_signin('jane@gmail.com', 'pa55w0rd')
|
62
62
|
assert_equal :invalid,
|
63
|
-
User.authenticate_signin('
|
64
|
-
"
|
63
|
+
User.authenticate_signin('jane@gmail.com', 'password'),
|
64
|
+
"John's password on Jane's account"
|
65
|
+
assert_equal :blocked,
|
66
|
+
User.authenticate_signin('john@gmail.com', 'password')
|
65
67
|
end
|
66
68
|
|
67
69
|
test 'autosaves credentials' do
|