authpwn_rails 0.11.0 → 0.11.1
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/app/models/credentials/email.rb +2 -1
- data/authpwn_rails.gemspec +1 -1
- data/lib/authpwn_rails/generators/templates/user.rb +8 -0
- data/lib/authpwn_rails/http_basic.rb +1 -1
- data/lib/authpwn_rails/session_controller.rb +1 -1
- data/lib/authpwn_rails/user_model.rb +14 -0
- data/test/http_basic_controller_test.rb +12 -1
- data/test/session_controller_api_test.rb +24 -15
- data/test/user_test.rb +8 -0
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.11.
|
1
|
+
0.11.1
|
@@ -33,7 +33,8 @@ class Email < ::Credential
|
|
33
33
|
#
|
34
34
|
# Presenting the correct e-mail is almost never sufficient for authentication
|
35
35
|
# purposes. This method will most likely used to kick off an authentication
|
36
|
-
# process, such as in
|
36
|
+
# process, such as in User#authenticate_signin and
|
37
|
+
# Password#authenticate_email.
|
37
38
|
#
|
38
39
|
# Returns the authenticated User instance, or a symbol indicating the reason
|
39
40
|
# why the (potentially valid) password was rejected.
|
data/authpwn_rails.gemspec
CHANGED
@@ -9,6 +9,14 @@ class User < ActiveRecord::Base
|
|
9
9
|
# Convenience Facebook accessors.
|
10
10
|
# include Authpwn::UserExtensions::FacebookFields
|
11
11
|
|
12
|
+
# Change this method to change the way users are looked up when signing in.
|
13
|
+
#
|
14
|
+
# For example, to implement Facebook / Twitter's ability to log in using
|
15
|
+
# either an e-mail address or a username, look up the user by the username,
|
16
|
+
# and pass their e-mail to super.
|
17
|
+
def self.authenticate_signin(email, password)
|
18
|
+
super
|
19
|
+
end
|
12
20
|
|
13
21
|
# Add your extensions to the User class here.
|
14
22
|
end
|
@@ -29,7 +29,7 @@ module HttpBasicControllerInstanceMethods
|
|
29
29
|
def authenticate_using_http_basic
|
30
30
|
return if current_user
|
31
31
|
authenticate_with_http_basic do |email, password|
|
32
|
-
auth =
|
32
|
+
auth = User.authenticate_signin email, password
|
33
33
|
self.current_user = auth unless auth.kind_of? Symbol
|
34
34
|
end
|
35
35
|
end
|
@@ -56,7 +56,7 @@ module SessionController
|
|
56
56
|
|
57
57
|
@redirect_url = params[:redirect_url] || session_url
|
58
58
|
@email = params[:email]
|
59
|
-
auth =
|
59
|
+
auth = User.authenticate_signin @email, params[:password]
|
60
60
|
self.current_user = auth unless auth.kind_of? Symbol
|
61
61
|
|
62
62
|
respond_to do |format|
|
@@ -40,6 +40,20 @@ module UserModel
|
|
40
40
|
def find_by_param(param)
|
41
41
|
where(:exuid => param).first
|
42
42
|
end
|
43
|
+
|
44
|
+
# Authenticates a user given the information on a signup form.
|
45
|
+
#
|
46
|
+
# The method's parameter names are an acknowledgement to the email and
|
47
|
+
# password fields on automatically-generated forms.
|
48
|
+
#
|
49
|
+
# The easiest method of accepting other login information is to override this
|
50
|
+
# method, locate the user's email, and supply it in a call to super.
|
51
|
+
#
|
52
|
+
# Returns an authenticated user, or a symbol indicating the reason why the
|
53
|
+
# authentication failed.
|
54
|
+
def authenticate_signin(email, password)
|
55
|
+
Credentials::Password.authenticate_email email, password
|
56
|
+
end
|
43
57
|
end # module Authpwn::UserModel::ClassMethods
|
44
58
|
|
45
59
|
# Checks if a credential is acceptable for authenticating a user.
|
@@ -46,12 +46,23 @@ class HttpBasicControllerTest < ActionController::TestCase
|
|
46
46
|
end
|
47
47
|
|
48
48
|
test "invalid user credentials in header" do
|
49
|
-
set_http_basic_user @user, '
|
49
|
+
set_http_basic_user @user, 'fail'
|
50
50
|
get :show
|
51
51
|
assert_nil assigns(:current_user)
|
52
52
|
assert_equal 'No user', response.body
|
53
53
|
end
|
54
54
|
|
55
|
+
test "uses User.authenticate_signin" do
|
56
|
+
flexmock(User).should_receive(:authenticate_signin).
|
57
|
+
with('jane@gmail.com', 'fail').and_return @user
|
58
|
+
set_http_basic_user @user, 'fail'
|
59
|
+
get :show
|
60
|
+
assert_equal @user, assigns(:current_user)
|
61
|
+
assert_equal "User: #{ActiveRecord::Fixtures.identify(:jane)}",
|
62
|
+
response.body
|
63
|
+
end
|
64
|
+
|
65
|
+
|
55
66
|
test "reset user credentials in header" do
|
56
67
|
set_http_basic_user @user, 'pa55w0rd'
|
57
68
|
set_http_basic_user nil
|
@@ -118,6 +118,15 @@ class SessionControllerApiTest < ActionController::TestCase
|
|
118
118
|
assert_match(/ blocked/, flash[:alert])
|
119
119
|
end
|
120
120
|
|
121
|
+
test "create uses User.authenticate_signin" do
|
122
|
+
flexmock(User).should_receive(:authenticate_signin).
|
123
|
+
with('em@ail.com', 'fail').and_return @email_credential.user
|
124
|
+
post :create, :email => 'em@ail.com', :password => 'fail'
|
125
|
+
assert_equal @user, assigns(:current_user), 'instance variable'
|
126
|
+
assert_equal @user, session_current_user, 'session'
|
127
|
+
assert_redirected_to session_url
|
128
|
+
end
|
129
|
+
|
121
130
|
test "create by json does not log in with bad password" do
|
122
131
|
post :create, :email => @email_credential.email, :password => 'fail',
|
123
132
|
:format => 'json'
|
@@ -275,8 +284,8 @@ class SessionControllerApiTest < ActionController::TestCase
|
|
275
284
|
:password_confirmation => 'hacks'}
|
276
285
|
assert_redirected_to session_url
|
277
286
|
assert_equal @password_credential, assigns(:credential)
|
278
|
-
assert_equal @user,
|
279
|
-
|
287
|
+
assert_equal @user, User.authenticate_signin(@email_credential.email,
|
288
|
+
'hacks'), 'password not changed'
|
280
289
|
end
|
281
290
|
|
282
291
|
test "change_password rejects bad old password" do
|
@@ -287,8 +296,8 @@ class SessionControllerApiTest < ActionController::TestCase
|
|
287
296
|
assert_response :ok
|
288
297
|
assert_template :password_change
|
289
298
|
assert_equal @password_credential, assigns(:credential)
|
290
|
-
assert_equal @user,
|
291
|
-
|
299
|
+
assert_equal @user, User.authenticate_signin(@email_credential.email,
|
300
|
+
'password'), 'password wrongly changed'
|
292
301
|
end
|
293
302
|
|
294
303
|
test "change_password rejects un-confirmed password" do
|
@@ -299,8 +308,8 @@ class SessionControllerApiTest < ActionController::TestCase
|
|
299
308
|
assert_response :ok
|
300
309
|
assert_template :password_change
|
301
310
|
assert_equal @password_credential, assigns(:credential)
|
302
|
-
assert_equal @user,
|
303
|
-
|
311
|
+
assert_equal @user, User.authenticate_signin( @email_credential.email,
|
312
|
+
'password'), 'password wrongly changed'
|
304
313
|
end
|
305
314
|
|
306
315
|
test "change_password works for password recovery" do
|
@@ -310,8 +319,8 @@ class SessionControllerApiTest < ActionController::TestCase
|
|
310
319
|
:credential => { :password => 'hacks',
|
311
320
|
:password_confirmation => 'hacks'}
|
312
321
|
assert_redirected_to session_url
|
313
|
-
assert_equal @user,
|
314
|
-
|
322
|
+
assert_equal @user, User.authenticate_signin(@email_credential.email,
|
323
|
+
'hacks'), 'password not changed'
|
315
324
|
end
|
316
325
|
|
317
326
|
test "change_password rejects un-confirmed password on recovery" do
|
@@ -341,8 +350,8 @@ class SessionControllerApiTest < ActionController::TestCase
|
|
341
350
|
:credential => { :password => 'hacks',
|
342
351
|
:password_confirmation => 'hacks'}
|
343
352
|
assert_response :ok
|
344
|
-
assert_equal @user,
|
345
|
-
|
353
|
+
assert_equal @user, User.authenticate_signin(@email_credential.email,
|
354
|
+
'hacks'), 'password not changed'
|
346
355
|
end
|
347
356
|
|
348
357
|
test "change_password by json rejects bad old password" do
|
@@ -354,8 +363,8 @@ class SessionControllerApiTest < ActionController::TestCase
|
|
354
363
|
data = ActiveSupport::JSON.decode response.body
|
355
364
|
assert_equal 'invalid', data['error']
|
356
365
|
assert_equal @password_credential, assigns(:credential)
|
357
|
-
assert_equal @user,
|
358
|
-
|
366
|
+
assert_equal @user, User.authenticate_signin(@email_credential.email,
|
367
|
+
'password'), 'password wrongly changed'
|
359
368
|
end
|
360
369
|
|
361
370
|
test "change_password by json rejects un-confirmed password" do
|
@@ -366,8 +375,8 @@ class SessionControllerApiTest < ActionController::TestCase
|
|
366
375
|
assert_response :ok
|
367
376
|
data = ActiveSupport::JSON.decode response.body
|
368
377
|
assert_equal 'invalid', data['error']
|
369
|
-
assert_equal @user,
|
370
|
-
|
378
|
+
assert_equal @user, User.authenticate_signin( @email_credential.email,
|
379
|
+
'password'), 'password wrongly changed'
|
371
380
|
end
|
372
381
|
|
373
382
|
test "change_password by json works for password recovery" do
|
@@ -377,7 +386,7 @@ class SessionControllerApiTest < ActionController::TestCase
|
|
377
386
|
:credential => { :password => 'hacks',
|
378
387
|
:password_confirmation => 'hacks'}
|
379
388
|
assert_response :ok
|
380
|
-
assert_equal @user,
|
389
|
+
assert_equal @user, User.authenticate_signin(
|
381
390
|
@email_credential.email, 'hacks'), 'password not changed'
|
382
391
|
end
|
383
392
|
|
data/test/user_test.rb
CHANGED
@@ -52,4 +52,12 @@ class UserTest < ActiveSupport::TestCase
|
|
52
52
|
assert_equal 1, @user.credentials.length
|
53
53
|
assert_equal 'test@email.com', @user.credentials.first.name
|
54
54
|
end
|
55
|
+
|
56
|
+
test 'authenticate_email' do
|
57
|
+
assert_equal users(:john),
|
58
|
+
User.authenticate_signin('john@gmail.com', 'password')
|
59
|
+
assert_equal :invalid,
|
60
|
+
User.authenticate_signin('john@gmail.com', 'pa55w0rd'),
|
61
|
+
"Jane's password on John's account"
|
62
|
+
end
|
55
63
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: authpwn_rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.11.
|
4
|
+
version: 0.11.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -278,7 +278,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
278
278
|
version: '0'
|
279
279
|
segments:
|
280
280
|
- 0
|
281
|
-
hash:
|
281
|
+
hash: 1446133306816314856
|
282
282
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
283
283
|
none: false
|
284
284
|
requirements:
|