devise 1.0.11 → 1.1.0
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.
- data/CHANGELOG.rdoc +59 -13
- data/Gemfile +23 -0
- data/Gemfile.lock +118 -0
- data/README.rdoc +116 -77
- data/Rakefile +4 -2
- data/TODO +3 -2
- data/app/controllers/{confirmations_controller.rb → devise/confirmations_controller.rb} +1 -1
- data/app/controllers/{passwords_controller.rb → devise/passwords_controller.rb} +1 -1
- data/app/controllers/{registrations_controller.rb → devise/registrations_controller.rb} +12 -8
- data/app/controllers/devise/sessions_controller.rb +23 -0
- data/app/controllers/{unlocks_controller.rb → devise/unlocks_controller.rb} +1 -8
- data/app/helpers/devise_helper.rb +17 -0
- data/app/mailers/devise/mailer.rb +71 -0
- data/app/views/devise/confirmations/new.html.erb +12 -0
- data/app/views/devise/passwords/edit.html.erb +16 -0
- data/app/views/devise/passwords/new.html.erb +12 -0
- data/app/views/devise/registrations/edit.html.erb +25 -0
- data/app/views/devise/registrations/new.html.erb +18 -0
- data/app/views/devise/sessions/new.html.erb +17 -0
- data/app/views/devise/shared/_links.erb +19 -0
- data/app/views/devise/unlocks/new.html.erb +12 -0
- data/{lib/devise → config}/locales/en.yml +16 -12
- data/lib/devise/controllers/helpers.rb +57 -52
- data/lib/devise/controllers/internal_helpers.rb +19 -50
- data/lib/devise/controllers/scoped_views.rb +35 -0
- data/lib/devise/controllers/url_helpers.rb +1 -1
- data/lib/devise/encryptors/authlogic_sha512.rb +0 -2
- data/lib/devise/encryptors/base.rb +1 -1
- data/lib/devise/encryptors/bcrypt.rb +2 -4
- data/lib/devise/encryptors/clearance_sha1.rb +0 -2
- data/lib/devise/encryptors/sha1.rb +6 -8
- data/lib/devise/encryptors/sha512.rb +6 -8
- data/lib/devise/failure_app.rb +76 -41
- data/lib/devise/hooks/activatable.rb +6 -10
- data/lib/devise/hooks/forgetable.rb +11 -0
- data/lib/devise/hooks/rememberable.rb +40 -30
- data/lib/devise/hooks/timeoutable.rb +7 -3
- data/lib/devise/hooks/trackable.rb +5 -14
- data/lib/devise/mapping.rb +35 -62
- data/lib/devise/models/authenticatable.rb +126 -0
- data/lib/devise/models/confirmable.rb +19 -22
- data/lib/devise/models/database_authenticatable.rb +26 -60
- data/lib/devise/models/lockable.rb +43 -28
- data/lib/devise/models/recoverable.rb +11 -10
- data/lib/devise/models/rememberable.rb +56 -26
- data/lib/devise/models/timeoutable.rb +1 -3
- data/lib/devise/models/token_authenticatable.rb +14 -43
- data/lib/devise/models/trackable.rb +14 -0
- data/lib/devise/models/validatable.rb +16 -2
- data/lib/devise/models.rb +16 -53
- data/lib/devise/modules.rb +23 -0
- data/lib/devise/orm/active_record.rb +10 -15
- data/lib/devise/orm/mongoid.rb +29 -0
- data/lib/devise/path_checker.rb +18 -0
- data/lib/devise/rails/routes.rb +232 -117
- data/lib/devise/rails/warden_compat.rb +17 -41
- data/lib/devise/rails.rb +64 -9
- data/lib/devise/schema.rb +47 -23
- data/lib/devise/strategies/authenticatable.rb +123 -0
- data/lib/devise/strategies/base.rb +2 -3
- data/lib/devise/strategies/database_authenticatable.rb +7 -22
- data/lib/devise/strategies/rememberable.rb +21 -7
- data/lib/devise/strategies/token_authenticatable.rb +31 -19
- data/lib/devise/test_helpers.rb +6 -6
- data/lib/devise/version.rb +1 -1
- data/lib/devise.rb +174 -157
- data/lib/generators/active_record/devise_generator.rb +28 -0
- data/{generators/devise → lib/generators/active_record}/templates/migration.rb +9 -3
- data/lib/generators/devise/devise_generator.rb +17 -0
- data/lib/generators/devise/install_generator.rb +24 -0
- data/lib/generators/devise/orm_helpers.rb +23 -0
- data/{generators/devise_install → lib/generators/devise}/templates/README +9 -7
- data/lib/generators/devise/templates/devise.rb +142 -0
- data/lib/generators/devise/views_generator.rb +63 -0
- data/lib/generators/devise_install_generator.rb +4 -0
- data/lib/generators/devise_views_generator.rb +4 -0
- data/lib/generators/mongoid/devise_generator.rb +17 -0
- data/test/controllers/helpers_test.rb +48 -19
- data/test/controllers/internal_helpers_test.rb +12 -16
- data/test/controllers/url_helpers_test.rb +21 -10
- data/test/devise_test.rb +16 -25
- data/test/encryptors_test.rb +2 -3
- data/test/failure_app_test.rb +106 -27
- data/test/integration/authenticatable_test.rb +135 -131
- data/test/integration/confirmable_test.rb +22 -15
- data/test/integration/database_authenticatable_test.rb +38 -0
- data/test/integration/http_authenticatable_test.rb +9 -12
- data/test/integration/lockable_test.rb +22 -15
- data/test/integration/recoverable_test.rb +6 -6
- data/test/integration/registerable_test.rb +42 -33
- data/test/integration/rememberable_test.rb +84 -22
- data/test/integration/timeoutable_test.rb +16 -4
- data/test/integration/token_authenticatable_test.rb +45 -12
- data/test/integration/trackable_test.rb +1 -1
- data/test/mailers/confirmation_instructions_test.rb +11 -17
- data/test/mailers/reset_password_instructions_test.rb +7 -7
- data/test/mailers/unlock_instructions_test.rb +7 -7
- data/test/mapping_test.rb +22 -95
- data/test/models/confirmable_test.rb +12 -19
- data/test/models/{authenticatable_test.rb → database_authenticatable_test.rb} +24 -56
- data/test/models/lockable_test.rb +32 -46
- data/test/models/recoverable_test.rb +7 -7
- data/test/models/rememberable_test.rb +118 -35
- data/test/models/timeoutable_test.rb +1 -1
- data/test/models/token_authenticatable_test.rb +5 -19
- data/test/models/trackable_test.rb +1 -1
- data/test/models/validatable_test.rb +20 -27
- data/test/models_test.rb +12 -5
- data/test/orm/active_record.rb +1 -23
- data/test/orm/mongoid.rb +10 -0
- data/test/rails_app/app/active_record/admin.rb +1 -5
- data/test/rails_app/app/active_record/shim.rb +2 -0
- data/test/rails_app/app/active_record/user.rb +3 -3
- data/test/rails_app/app/controllers/application_controller.rb +2 -5
- data/test/rails_app/app/controllers/home_controller.rb +3 -0
- data/test/rails_app/app/controllers/publisher/registrations_controller.rb +2 -0
- data/test/rails_app/app/controllers/publisher/sessions_controller.rb +2 -0
- data/test/rails_app/app/controllers/sessions_controller.rb +6 -0
- data/test/rails_app/app/controllers/users_controller.rb +7 -5
- data/test/rails_app/app/mongoid/admin.rb +6 -0
- data/test/rails_app/app/mongoid/shim.rb +16 -0
- data/test/rails_app/app/mongoid/user.rb +10 -0
- data/test/rails_app/config/application.rb +35 -0
- data/test/rails_app/config/boot.rb +10 -107
- data/test/rails_app/config/environment.rb +4 -41
- data/test/rails_app/config/environments/development.rb +15 -13
- data/test/rails_app/config/environments/production.rb +25 -20
- data/test/rails_app/config/environments/test.rb +33 -28
- data/test/rails_app/config/initializers/backtrace_silencers.rb +7 -0
- data/test/rails_app/config/initializers/devise.rb +95 -38
- data/test/rails_app/config/initializers/secret_token.rb +2 -0
- data/test/rails_app/config/routes.rb +47 -25
- data/test/rails_app/db/migrate/20100401102949_create_tables.rb +27 -0
- data/test/rails_app/db/schema.rb +86 -0
- data/test/routes_test.rb +62 -47
- data/test/support/{assertions_helper.rb → assertions.rb} +2 -15
- data/test/support/{tests_helper.rb → helpers.rb} +18 -3
- data/test/support/{integration_tests_helper.rb → integration.rb} +24 -7
- data/test/support/webrat/integrations/rails.rb +32 -0
- data/test/test_helper.rb +11 -11
- data/test/test_helpers_test.rb +30 -15
- metadata +107 -66
- data/app/controllers/sessions_controller.rb +0 -42
- data/app/models/devise_mailer.rb +0 -68
- data/app/views/confirmations/new.html.erb +0 -12
- data/app/views/passwords/edit.html.erb +0 -16
- data/app/views/passwords/new.html.erb +0 -12
- data/app/views/registrations/edit.html.erb +0 -25
- data/app/views/registrations/new.html.erb +0 -17
- data/app/views/sessions/new.html.erb +0 -17
- data/app/views/shared/_devise_links.erb +0 -19
- data/app/views/unlocks/new.html.erb +0 -12
- data/generators/devise/USAGE +0 -5
- data/generators/devise/devise_generator.rb +0 -15
- data/generators/devise/lib/route_devise.rb +0 -32
- data/generators/devise/templates/model.rb +0 -9
- data/generators/devise_install/USAGE +0 -3
- data/generators/devise_install/devise_install_generator.rb +0 -15
- data/generators/devise_install/templates/devise.rb +0 -105
- data/generators/devise_views/USAGE +0 -3
- data/generators/devise_views/devise_views_generator.rb +0 -21
- data/lib/devise/models/activatable.rb +0 -16
- data/lib/devise/models/http_authenticatable.rb +0 -23
- data/lib/devise/orm/data_mapper.rb +0 -83
- data/lib/devise/orm/mongo_mapper.rb +0 -52
- data/lib/devise/strategies/http_authenticatable.rb +0 -59
- data/rails/init.rb +0 -2
- data/test/integration/rack_middleware_test.rb +0 -47
- data/test/orm/mongo_mapper.rb +0 -20
- data/test/rails_app/app/mongo_mapper/admin.rb +0 -13
- data/test/rails_app/app/mongo_mapper/user.rb +0 -14
- data/test/rails_app/config/initializers/new_rails_defaults.rb +0 -24
- data/test/rails_app/config/initializers/session_store.rb +0 -15
- /data/app/views/{devise_mailer → devise/mailer}/confirmation_instructions.html.erb +0 -0
- /data/app/views/{devise_mailer → devise/mailer}/reset_password_instructions.html.erb +0 -0
- /data/app/views/{devise_mailer → devise/mailer}/unlock_instructions.html.erb +0 -0
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
require '
|
|
1
|
+
require 'test_helper'
|
|
2
2
|
|
|
3
3
|
class HttpAuthenticationTest < ActionController::IntegrationTest
|
|
4
4
|
|
|
5
5
|
test 'sign in should authenticate with http' do
|
|
6
6
|
sign_in_as_new_user_with_http
|
|
7
7
|
assert_response :success
|
|
8
|
-
|
|
9
|
-
assert_contain 'Welcome'
|
|
8
|
+
assert_match '<email>user@test.com</email>', response.body
|
|
10
9
|
assert warden.authenticated?(:user)
|
|
11
10
|
end
|
|
12
11
|
|
|
@@ -17,11 +16,10 @@ class HttpAuthenticationTest < ActionController::IntegrationTest
|
|
|
17
16
|
end
|
|
18
17
|
|
|
19
18
|
test 'uses the request format as response content type' do
|
|
20
|
-
sign_in_as_new_user_with_http("unknown"
|
|
19
|
+
sign_in_as_new_user_with_http("unknown")
|
|
21
20
|
assert_equal 401, status
|
|
22
|
-
assert_equal "application/xml", headers["Content-Type"]
|
|
23
|
-
|
|
24
|
-
# assert response.body.include?("<error>HTTP Basic: Access denied.</error>")
|
|
21
|
+
assert_equal "application/xml; charset=utf-8", headers["Content-Type"]
|
|
22
|
+
assert_match "<error>Invalid email or password.</error>", response.body
|
|
25
23
|
end
|
|
26
24
|
|
|
27
25
|
test 'returns a custom response with www-authenticate and chosen realm' do
|
|
@@ -34,19 +32,18 @@ class HttpAuthenticationTest < ActionController::IntegrationTest
|
|
|
34
32
|
|
|
35
33
|
test 'sign in should authenticate with http even with specific authentication keys' do
|
|
36
34
|
swap Devise, :authentication_keys => [:username] do
|
|
37
|
-
sign_in_as_new_user_with_http
|
|
35
|
+
sign_in_as_new_user_with_http("usertest")
|
|
38
36
|
assert_response :success
|
|
39
|
-
|
|
40
|
-
assert_contain 'Welcome'
|
|
37
|
+
assert_match '<email>user@test.com</email>', response.body
|
|
41
38
|
assert warden.authenticated?(:user)
|
|
42
39
|
end
|
|
43
40
|
end
|
|
44
41
|
|
|
45
42
|
private
|
|
46
43
|
|
|
47
|
-
def sign_in_as_new_user_with_http(username="user@test.com", password="123456"
|
|
44
|
+
def sign_in_as_new_user_with_http(username="user@test.com", password="123456")
|
|
48
45
|
user = create_user
|
|
49
|
-
get users_path(:format =>
|
|
46
|
+
get users_path(:format => :xml), {}, "HTTP_AUTHORIZATION" => "Basic #{ActiveSupport::Base64.encode64("#{username}:#{password}")}"
|
|
50
47
|
user
|
|
51
48
|
end
|
|
52
49
|
end
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
require '
|
|
1
|
+
require 'test_helper'
|
|
2
2
|
|
|
3
3
|
class LockTest < ActionController::IntegrationTest
|
|
4
4
|
|
|
@@ -11,7 +11,7 @@ class LockTest < ActionController::IntegrationTest
|
|
|
11
11
|
ActionMailer::Base.deliveries.clear
|
|
12
12
|
|
|
13
13
|
visit new_user_session_path
|
|
14
|
-
click_link
|
|
14
|
+
click_link "Didn't receive unlock instructions?"
|
|
15
15
|
|
|
16
16
|
fill_in 'email', :with => user.email
|
|
17
17
|
click_button 'Resend unlock instructions'
|
|
@@ -26,7 +26,7 @@ class LockTest < ActionController::IntegrationTest
|
|
|
26
26
|
ActionMailer::Base.deliveries.clear
|
|
27
27
|
|
|
28
28
|
visit new_user_session_path
|
|
29
|
-
click_link
|
|
29
|
+
click_link "Didn't receive unlock instructions?"
|
|
30
30
|
|
|
31
31
|
fill_in 'email', :with => user.email
|
|
32
32
|
click_button 'Resend unlock instructions'
|
|
@@ -37,21 +37,26 @@ class LockTest < ActionController::IntegrationTest
|
|
|
37
37
|
end
|
|
38
38
|
|
|
39
39
|
test 'unlocked pages should not be available if email strategy is disabled' do
|
|
40
|
-
visit
|
|
41
|
-
|
|
40
|
+
visit "/admins/sign_in"
|
|
41
|
+
|
|
42
|
+
assert_raise Webrat::NotFoundError do
|
|
43
|
+
click_link "Didn't receive unlock instructions?"
|
|
44
|
+
end
|
|
42
45
|
|
|
43
|
-
|
|
44
|
-
visit
|
|
45
|
-
assert_response :not_found
|
|
46
|
+
assert_raise NameError do
|
|
47
|
+
visit new_admin_unlock_path
|
|
46
48
|
end
|
|
49
|
+
|
|
50
|
+
visit "/admins/unlock/new"
|
|
51
|
+
assert_response :not_found
|
|
47
52
|
end
|
|
48
53
|
|
|
49
54
|
test 'user with invalid unlock token should not be able to unlock an account' do
|
|
50
55
|
visit_user_unlock_with_token('invalid_token')
|
|
51
56
|
|
|
52
57
|
assert_response :success
|
|
53
|
-
|
|
54
|
-
assert_have_selector '#
|
|
58
|
+
assert_current_url '/users/unlock?unlock_token=invalid_token'
|
|
59
|
+
assert_have_selector '#error_explanation'
|
|
55
60
|
assert_contain /Unlock token(.*)invalid/
|
|
56
61
|
end
|
|
57
62
|
|
|
@@ -61,7 +66,7 @@ class LockTest < ActionController::IntegrationTest
|
|
|
61
66
|
|
|
62
67
|
visit_user_unlock_with_token(user.unlock_token)
|
|
63
68
|
|
|
64
|
-
|
|
69
|
+
assert_current_url '/'
|
|
65
70
|
assert_contain 'Your account was successfully unlocked.'
|
|
66
71
|
|
|
67
72
|
assert_not user.reload.access_locked?
|
|
@@ -82,19 +87,21 @@ class LockTest < ActionController::IntegrationTest
|
|
|
82
87
|
|
|
83
88
|
test "user should not send a new e-mail if already locked" do
|
|
84
89
|
user = create_user(:locked => true)
|
|
85
|
-
user.
|
|
90
|
+
user.failed_attempts = User.maximum_attempts + 1
|
|
91
|
+
user.save!
|
|
92
|
+
|
|
86
93
|
ActionMailer::Base.deliveries.clear
|
|
87
94
|
|
|
88
95
|
sign_in_as_user(:password => "invalid")
|
|
89
|
-
assert_contain '
|
|
96
|
+
assert_contain 'Your account is locked.'
|
|
90
97
|
assert ActionMailer::Base.deliveries.empty?
|
|
91
98
|
end
|
|
92
99
|
|
|
93
100
|
test 'error message is configurable by resource name' do
|
|
94
101
|
store_translations :en, :devise => {
|
|
95
|
-
:
|
|
102
|
+
:failure => { :user => { :locked => "You are locked!" } }
|
|
96
103
|
} do
|
|
97
|
-
|
|
104
|
+
user = sign_in_as_user(:locked => true)
|
|
98
105
|
assert_contain 'You are locked!'
|
|
99
106
|
end
|
|
100
107
|
end
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
require '
|
|
1
|
+
require 'test_helper'
|
|
2
2
|
|
|
3
3
|
class PasswordTest < ActionController::IntegrationTest
|
|
4
4
|
|
|
5
5
|
def visit_new_password_path
|
|
6
6
|
visit new_user_session_path
|
|
7
|
-
click_link 'Forgot password?'
|
|
7
|
+
click_link 'Forgot your password?'
|
|
8
8
|
end
|
|
9
9
|
|
|
10
10
|
def request_forgot_password(&block)
|
|
@@ -77,7 +77,7 @@ class PasswordTest < ActionController::IntegrationTest
|
|
|
77
77
|
|
|
78
78
|
assert_response :success
|
|
79
79
|
assert_template 'passwords/edit'
|
|
80
|
-
assert_have_selector '#
|
|
80
|
+
assert_have_selector '#error_explanation'
|
|
81
81
|
assert_contain /Reset password token(.*)invalid/
|
|
82
82
|
assert_not user.reload.valid_password?('987654321')
|
|
83
83
|
end
|
|
@@ -91,7 +91,7 @@ class PasswordTest < ActionController::IntegrationTest
|
|
|
91
91
|
|
|
92
92
|
assert_response :success
|
|
93
93
|
assert_template 'passwords/edit'
|
|
94
|
-
assert_have_selector '#
|
|
94
|
+
assert_have_selector '#error_explanation'
|
|
95
95
|
assert_contain 'Password doesn\'t match confirmation'
|
|
96
96
|
assert_not user.reload.valid_password?('987654321')
|
|
97
97
|
end
|
|
@@ -113,7 +113,7 @@ class PasswordTest < ActionController::IntegrationTest
|
|
|
113
113
|
fill_in 'Password confirmation', :with => 'other_password'
|
|
114
114
|
end
|
|
115
115
|
assert_response :success
|
|
116
|
-
assert_have_selector '#
|
|
116
|
+
assert_have_selector '#error_explanation'
|
|
117
117
|
assert_not user.reload.valid_password?('987654321')
|
|
118
118
|
|
|
119
119
|
reset_password :reset_password_token => user.reload.reset_password_token, :visit => false
|
|
@@ -134,7 +134,7 @@ class PasswordTest < ActionController::IntegrationTest
|
|
|
134
134
|
request_forgot_password
|
|
135
135
|
reset_password :reset_password_token => user.reload.reset_password_token
|
|
136
136
|
|
|
137
|
-
|
|
137
|
+
assert_equal new_user_session_path, @request.path
|
|
138
138
|
assert !warden.authenticated?(:user)
|
|
139
139
|
end
|
|
140
140
|
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
require '
|
|
1
|
+
require 'test_helper'
|
|
2
2
|
|
|
3
3
|
class RegistrationTest < ActionController::IntegrationTest
|
|
4
4
|
|
|
5
5
|
test 'a guest admin should be able to sign in successfully' do
|
|
6
|
-
|
|
6
|
+
get new_admin_session_path
|
|
7
7
|
click_link 'Sign up'
|
|
8
8
|
|
|
9
9
|
assert_template 'registrations/new'
|
|
@@ -16,38 +16,31 @@ class RegistrationTest < ActionController::IntegrationTest
|
|
|
16
16
|
assert_contain 'You have signed up successfully.'
|
|
17
17
|
assert warden.authenticated?(:admin)
|
|
18
18
|
|
|
19
|
-
admin = Admin.last
|
|
19
|
+
admin = Admin.last :order => "id"
|
|
20
20
|
assert_equal admin.email, 'new_user@test.com'
|
|
21
21
|
end
|
|
22
22
|
|
|
23
23
|
test 'a guest user should be able to sign up successfully and be blocked by confirmation' do
|
|
24
|
-
|
|
24
|
+
get new_user_registration_path
|
|
25
25
|
|
|
26
26
|
fill_in 'email', :with => 'new_user@test.com'
|
|
27
27
|
fill_in 'password', :with => 'new_user123'
|
|
28
28
|
fill_in 'password confirmation', :with => 'new_user123'
|
|
29
29
|
click_button 'Sign up'
|
|
30
30
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
# For some reason flash is not being set correctly, so instead of getting the
|
|
34
|
-
# "signed_up" message we get the unconfirmed one. Seems to be an issue with
|
|
35
|
-
# the internal redirect by the hook and the tests.
|
|
36
|
-
# follow_redirect!
|
|
37
|
-
# assert_contain 'You have signed up successfully.'
|
|
38
|
-
# assert_not_contain 'confirm your account'
|
|
39
|
-
|
|
40
|
-
follow_redirect!
|
|
31
|
+
assert_contain 'You have signed up successfully'
|
|
41
32
|
assert_contain 'Sign in'
|
|
33
|
+
assert_not_contain 'You have to confirm your account before continuing'
|
|
34
|
+
|
|
42
35
|
assert_not warden.authenticated?(:user)
|
|
43
36
|
|
|
44
|
-
user = User.last
|
|
37
|
+
user = User.last :order => "id"
|
|
45
38
|
assert_equal user.email, 'new_user@test.com'
|
|
46
39
|
assert_not user.confirmed?
|
|
47
40
|
end
|
|
48
41
|
|
|
49
42
|
test 'a guest user cannot sign up with invalid information' do
|
|
50
|
-
|
|
43
|
+
get new_user_registration_path
|
|
51
44
|
|
|
52
45
|
fill_in 'email', :with => 'invalid_email'
|
|
53
46
|
fill_in 'password', :with => 'new_user123'
|
|
@@ -55,7 +48,7 @@ class RegistrationTest < ActionController::IntegrationTest
|
|
|
55
48
|
click_button 'Sign up'
|
|
56
49
|
|
|
57
50
|
assert_template 'registrations/new'
|
|
58
|
-
assert_have_selector '#
|
|
51
|
+
assert_have_selector '#error_explanation'
|
|
59
52
|
assert_contain "Email is invalid"
|
|
60
53
|
assert_contain "Password doesn't match confirmation"
|
|
61
54
|
assert_nil User.first
|
|
@@ -65,55 +58,71 @@ class RegistrationTest < ActionController::IntegrationTest
|
|
|
65
58
|
|
|
66
59
|
test 'a guest should not sign up with email/password that already exists' do
|
|
67
60
|
user = create_user
|
|
68
|
-
|
|
61
|
+
get new_user_registration_path
|
|
69
62
|
|
|
70
63
|
fill_in 'email', :with => 'user@test.com'
|
|
71
64
|
fill_in 'password', :with => '123456'
|
|
72
65
|
fill_in 'password confirmation', :with => '123456'
|
|
73
66
|
click_button 'Sign up'
|
|
74
67
|
|
|
75
|
-
|
|
76
|
-
assert_contain
|
|
68
|
+
assert_current_url '/users'
|
|
69
|
+
assert_contain(/Email .* already .* taken/)
|
|
77
70
|
|
|
78
71
|
assert_not warden.authenticated?(:user)
|
|
79
72
|
end
|
|
80
73
|
|
|
81
74
|
test 'a guest should not be able to change account' do
|
|
82
|
-
|
|
75
|
+
get edit_user_registration_path
|
|
76
|
+
assert_redirected_to new_user_session_path
|
|
83
77
|
follow_redirect!
|
|
84
|
-
|
|
78
|
+
assert_contain 'You need to sign in or sign up before continuing.'
|
|
85
79
|
end
|
|
86
80
|
|
|
87
81
|
test 'a signed in user should not be able to access sign up' do
|
|
88
82
|
sign_in_as_user
|
|
89
|
-
|
|
90
|
-
|
|
83
|
+
get new_user_registration_path
|
|
84
|
+
assert_redirected_to root_path
|
|
91
85
|
end
|
|
92
86
|
|
|
93
87
|
test 'a signed in user should be able to edit his account' do
|
|
94
88
|
sign_in_as_user
|
|
95
|
-
|
|
89
|
+
get edit_user_registration_path
|
|
96
90
|
|
|
97
91
|
fill_in 'email', :with => 'user.new@email.com'
|
|
98
92
|
fill_in 'current password', :with => '123456'
|
|
99
93
|
click_button 'Update'
|
|
100
94
|
|
|
101
|
-
|
|
95
|
+
assert_current_url '/'
|
|
102
96
|
assert_contain 'You updated your account successfully.'
|
|
103
97
|
|
|
104
98
|
assert_equal "user.new@email.com", User.first.email
|
|
105
99
|
end
|
|
106
100
|
|
|
101
|
+
test 'a signed in user should not change his current user with invalid password' do
|
|
102
|
+
sign_in_as_user
|
|
103
|
+
get edit_user_registration_path
|
|
104
|
+
|
|
105
|
+
fill_in 'email', :with => 'user.new@email.com'
|
|
106
|
+
fill_in 'current password', :with => 'invalid'
|
|
107
|
+
click_button 'Update'
|
|
108
|
+
|
|
109
|
+
assert_template 'registrations/edit'
|
|
110
|
+
assert_contain 'user@test.com'
|
|
111
|
+
assert_have_selector 'form input[value="user.new@email.com"]'
|
|
112
|
+
|
|
113
|
+
assert_equal "user@test.com", User.first.email
|
|
114
|
+
end
|
|
115
|
+
|
|
107
116
|
test 'a signed in user should be able to edit his password' do
|
|
108
117
|
sign_in_as_user
|
|
109
|
-
|
|
118
|
+
get edit_user_registration_path
|
|
110
119
|
|
|
111
120
|
fill_in 'password', :with => 'pas123'
|
|
112
121
|
fill_in 'password confirmation', :with => 'pas123'
|
|
113
122
|
fill_in 'current password', :with => '123456'
|
|
114
123
|
click_button 'Update'
|
|
115
124
|
|
|
116
|
-
|
|
125
|
+
assert_current_url '/'
|
|
117
126
|
assert_contain 'You updated your account successfully.'
|
|
118
127
|
|
|
119
128
|
assert User.first.valid_password?('pas123')
|
|
@@ -122,23 +131,23 @@ class RegistrationTest < ActionController::IntegrationTest
|
|
|
122
131
|
test 'a signed in user should not be able to edit his password with invalid confirmation' do
|
|
123
132
|
sign_in_as_user
|
|
124
133
|
get edit_user_registration_path
|
|
125
|
-
|
|
134
|
+
|
|
126
135
|
fill_in 'password', :with => 'pas123'
|
|
127
136
|
fill_in 'password confirmation', :with => ''
|
|
128
137
|
fill_in 'current password', :with => '123456'
|
|
129
138
|
click_button 'Update'
|
|
130
|
-
|
|
139
|
+
|
|
131
140
|
assert_contain "Password doesn't match confirmation"
|
|
132
141
|
assert_not User.first.valid_password?('pas123')
|
|
133
142
|
end
|
|
134
143
|
|
|
135
144
|
test 'a signed in user should be able to cancel his account' do
|
|
136
145
|
sign_in_as_user
|
|
137
|
-
|
|
146
|
+
get edit_user_registration_path
|
|
138
147
|
|
|
139
|
-
click_link "Cancel my account"
|
|
148
|
+
click_link "Cancel my account", :method => :delete
|
|
140
149
|
assert_contain "Bye! Your account was successfully cancelled. We hope to see you again soon."
|
|
141
150
|
|
|
142
151
|
assert User.all.empty?
|
|
143
152
|
end
|
|
144
|
-
end
|
|
153
|
+
end
|
|
@@ -1,23 +1,51 @@
|
|
|
1
|
-
require '
|
|
1
|
+
require 'test_helper'
|
|
2
2
|
|
|
3
3
|
class RememberMeTest < ActionController::IntegrationTest
|
|
4
4
|
|
|
5
5
|
def create_user_and_remember(add_to_token='')
|
|
6
|
-
Devise.remember_for = 1
|
|
7
6
|
user = create_user
|
|
8
7
|
user.remember_me!
|
|
9
|
-
|
|
8
|
+
raw_cookie = User.serialize_into_cookie(user).tap { |a| a.last << add_to_token }
|
|
9
|
+
cookies['remember_user_token'] = generate_signed_cookie(raw_cookie)
|
|
10
10
|
user
|
|
11
11
|
end
|
|
12
12
|
|
|
13
|
+
def generate_signed_cookie(raw_cookie)
|
|
14
|
+
request = ActionDispatch::TestRequest.new
|
|
15
|
+
request.cookie_jar.signed['raw_cookie'] = raw_cookie
|
|
16
|
+
request.cookie_jar['raw_cookie']
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def signed_cookie(key)
|
|
20
|
+
controller.send(:cookies).signed[key]
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def cookie_expires(key)
|
|
24
|
+
cookie = response.headers["Set-Cookie"].split("\n").grep(/^#{key}/).first
|
|
25
|
+
cookie.split(";").map(&:strip).grep(/^expires=/)
|
|
26
|
+
Time.parse($')
|
|
27
|
+
end
|
|
28
|
+
|
|
13
29
|
test 'do not remember the user if he has not checked remember me option' do
|
|
14
30
|
user = sign_in_as_user
|
|
31
|
+
assert_nil request.cookies["remember_user_cookie"]
|
|
15
32
|
assert_nil user.reload.remember_token
|
|
16
33
|
end
|
|
17
34
|
|
|
18
35
|
test 'generate remember token after sign in' do
|
|
19
36
|
user = sign_in_as_user :remember_me => true
|
|
20
|
-
|
|
37
|
+
assert request.cookies["remember_user_token"]
|
|
38
|
+
assert user.reload.remember_token
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
test 'generate remember token after sign in setting cookie domain' do
|
|
42
|
+
# We test this by asserting the cookie is not sent after the redirect
|
|
43
|
+
# since we changed the domain. This is the only difference with the
|
|
44
|
+
# previous test.
|
|
45
|
+
swap User, :cookie_domain => "omg.somewhere.com" do
|
|
46
|
+
user = sign_in_as_user :remember_me => true
|
|
47
|
+
assert_nil request.cookies["remember_user_token"]
|
|
48
|
+
end
|
|
21
49
|
end
|
|
22
50
|
|
|
23
51
|
test 'remember the user before sign in' do
|
|
@@ -28,7 +56,51 @@ class RememberMeTest < ActionController::IntegrationTest
|
|
|
28
56
|
assert warden.user(:user) == user
|
|
29
57
|
end
|
|
30
58
|
|
|
31
|
-
test 'does not remember
|
|
59
|
+
test 'does not extend remember period through sign in' do
|
|
60
|
+
swap Devise, :extend_remember_period => true, :remember_for => 1.year do
|
|
61
|
+
user = create_user
|
|
62
|
+
user.remember_me!
|
|
63
|
+
|
|
64
|
+
user.remember_created_at = old = 10.days.ago
|
|
65
|
+
user.save
|
|
66
|
+
|
|
67
|
+
sign_in_as_user :remember_me => true
|
|
68
|
+
user.reload
|
|
69
|
+
|
|
70
|
+
assert warden.user(:user) == user
|
|
71
|
+
assert_equal old.to_i, user.remember_created_at.to_i
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
test 'if both extend_remember_period and remember_across_browsers are true, sends the same token with a new expire date' do
|
|
76
|
+
swap Devise, :remember_across_browsers => true, :extend_remember_period => true, :remember_for => 1.year do
|
|
77
|
+
user = create_user_and_remember
|
|
78
|
+
token = user.remember_token
|
|
79
|
+
|
|
80
|
+
user.remember_created_at = old = 10.minutes.ago
|
|
81
|
+
user.save!
|
|
82
|
+
|
|
83
|
+
get users_path
|
|
84
|
+
assert (cookie_expires("remember_user_token") - 1.year) > (old + 5.minutes)
|
|
85
|
+
assert_equal token, signed_cookie("remember_user_token").last
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
test 'if both extend_remember_period and remember_across_browsers are false, sends a new token with old expire date' do
|
|
90
|
+
swap Devise, :remember_across_browsers => false, :extend_remember_period => false, :remember_for => 1.year do
|
|
91
|
+
user = create_user_and_remember
|
|
92
|
+
token = user.remember_token
|
|
93
|
+
|
|
94
|
+
user.remember_created_at = old = 10.minutes.ago
|
|
95
|
+
user.save!
|
|
96
|
+
|
|
97
|
+
get users_path
|
|
98
|
+
assert (cookie_expires("remember_user_token") - 1.year) < (old + 5.minutes)
|
|
99
|
+
assert_not_equal token, signed_cookie("remember_user_token").last
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
test 'do not remember other scopes' do
|
|
32
104
|
user = create_user_and_remember
|
|
33
105
|
get root_path
|
|
34
106
|
assert_response :success
|
|
@@ -39,16 +111,17 @@ class RememberMeTest < ActionController::IntegrationTest
|
|
|
39
111
|
test 'do not remember with invalid token' do
|
|
40
112
|
user = create_user_and_remember('add')
|
|
41
113
|
get users_path
|
|
42
|
-
assert_response :success
|
|
43
114
|
assert_not warden.authenticated?(:user)
|
|
115
|
+
assert_redirected_to new_user_session_path
|
|
44
116
|
end
|
|
45
117
|
|
|
46
|
-
test 'do not remember with token
|
|
118
|
+
test 'do not remember with expired token' do
|
|
47
119
|
user = create_user_and_remember
|
|
48
|
-
Devise
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
120
|
+
swap Devise, :remember_for => 0 do
|
|
121
|
+
get users_path
|
|
122
|
+
assert_not warden.authenticated?(:user)
|
|
123
|
+
assert_redirected_to new_user_session_path
|
|
124
|
+
end
|
|
52
125
|
end
|
|
53
126
|
|
|
54
127
|
test 'forget the user before sign out' do
|
|
@@ -67,16 +140,5 @@ class RememberMeTest < ActionController::IntegrationTest
|
|
|
67
140
|
get destroy_user_session_path
|
|
68
141
|
get users_path
|
|
69
142
|
assert_not warden.authenticated?(:user)
|
|
70
|
-
assert_equal cookies['remember_user_token'], ''
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
test 'cookies are destroyed on unverified requests' do
|
|
74
|
-
swap HomeController, :allow_forgery_protection => true do
|
|
75
|
-
user = create_user_and_remember
|
|
76
|
-
get users_path
|
|
77
|
-
assert warden.authenticated?(:user)
|
|
78
|
-
post root_path, :authenticity_token => 'INVALID'
|
|
79
|
-
assert_not warden.authenticated?(:user)
|
|
80
|
-
end
|
|
81
143
|
end
|
|
82
144
|
end
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
require '
|
|
1
|
+
require 'test_helper'
|
|
2
2
|
|
|
3
3
|
class SessionTimeoutTest < ActionController::IntegrationTest
|
|
4
4
|
|
|
@@ -32,10 +32,22 @@ class SessionTimeoutTest < ActionController::IntegrationTest
|
|
|
32
32
|
assert_not_nil last_request_at
|
|
33
33
|
|
|
34
34
|
get users_path
|
|
35
|
-
assert_redirected_to new_user_session_path
|
|
35
|
+
assert_redirected_to new_user_session_path
|
|
36
36
|
assert_not warden.authenticated?(:user)
|
|
37
37
|
end
|
|
38
38
|
|
|
39
|
+
test 'time out is not triggered on sign out' do
|
|
40
|
+
user = sign_in_as_user
|
|
41
|
+
get expire_user_path(user)
|
|
42
|
+
|
|
43
|
+
get destroy_user_session_path
|
|
44
|
+
assert_response :redirect
|
|
45
|
+
assert_redirected_to root_path
|
|
46
|
+
|
|
47
|
+
follow_redirect!
|
|
48
|
+
assert_contain 'Signed out successfully'
|
|
49
|
+
end
|
|
50
|
+
|
|
39
51
|
test 'user configured timeout limit' do
|
|
40
52
|
swap Devise, :timeout_in => 8.minutes do
|
|
41
53
|
user = sign_in_as_user
|
|
@@ -47,14 +59,14 @@ class SessionTimeoutTest < ActionController::IntegrationTest
|
|
|
47
59
|
|
|
48
60
|
get expire_user_path(user)
|
|
49
61
|
get users_path
|
|
50
|
-
assert_redirected_to new_user_session_path
|
|
62
|
+
assert_redirected_to new_user_session_path
|
|
51
63
|
assert_not warden.authenticated?(:user)
|
|
52
64
|
end
|
|
53
65
|
end
|
|
54
66
|
|
|
55
67
|
test 'error message with i18n' do
|
|
56
68
|
store_translations :en, :devise => {
|
|
57
|
-
:
|
|
69
|
+
:failure => { :user => { :timeout => 'Session expired!' } }
|
|
58
70
|
} do
|
|
59
71
|
user = sign_in_as_user
|
|
60
72
|
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
require '
|
|
1
|
+
require 'test_helper'
|
|
2
2
|
|
|
3
3
|
class TokenAuthenticationTest < ActionController::IntegrationTest
|
|
4
4
|
|
|
5
|
-
test '
|
|
5
|
+
test 'authenticate with valid authentication token key and value through params' do
|
|
6
6
|
swap Devise, :token_authentication_key => :secret_token do
|
|
7
|
-
sign_in_as_new_user_with_token
|
|
7
|
+
sign_in_as_new_user_with_token
|
|
8
8
|
|
|
9
9
|
assert_response :success
|
|
10
10
|
assert_template 'users/index'
|
|
@@ -13,11 +13,40 @@ class TokenAuthenticationTest < ActionController::IntegrationTest
|
|
|
13
13
|
end
|
|
14
14
|
end
|
|
15
15
|
|
|
16
|
-
test '
|
|
16
|
+
test 'authenticate with valid authentication token key and value through http' do
|
|
17
|
+
swap Devise, :token_authentication_key => :secret_token do
|
|
18
|
+
sign_in_as_new_user_with_token(:http_auth => true)
|
|
19
|
+
|
|
20
|
+
assert_response :success
|
|
21
|
+
assert_match '<email>user@test.com</email>', response.body
|
|
22
|
+
assert warden.authenticated?(:user)
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
test 'does authenticate with valid authentication token key and value through params if not configured' do
|
|
27
|
+
swap Devise, :token_authentication_key => :secret_token, :params_authenticatable => [:database] do
|
|
28
|
+
sign_in_as_new_user_with_token
|
|
29
|
+
|
|
30
|
+
assert_contain 'You need to sign in or sign up before continuing'
|
|
31
|
+
assert_contain 'Sign in'
|
|
32
|
+
assert_not warden.authenticated?(:user)
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
test 'does authenticate with valid authentication token key and value through http if not configured' do
|
|
37
|
+
swap Devise, :token_authentication_key => :secret_token, :http_authenticatable => [:database] do
|
|
38
|
+
sign_in_as_new_user_with_token(:http_auth => true)
|
|
39
|
+
|
|
40
|
+
assert_response 401
|
|
41
|
+
assert_contain 'Invalid email or password.'
|
|
42
|
+
assert_not warden.authenticated?(:user)
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
test 'does not authenticate with improper authentication token key' do
|
|
17
47
|
swap Devise, :token_authentication_key => :donald_duck_token do
|
|
18
48
|
sign_in_as_new_user_with_token(:auth_token_key => :secret_token)
|
|
19
|
-
|
|
20
|
-
follow_redirect!
|
|
49
|
+
assert_equal new_user_session_path, @request.path
|
|
21
50
|
|
|
22
51
|
assert_contain 'You need to sign in or sign up before continuing'
|
|
23
52
|
assert_contain 'Sign in'
|
|
@@ -25,13 +54,11 @@ class TokenAuthenticationTest < ActionController::IntegrationTest
|
|
|
25
54
|
end
|
|
26
55
|
end
|
|
27
56
|
|
|
28
|
-
test '
|
|
29
|
-
store_translations :en, :devise => {:
|
|
57
|
+
test 'does not authenticate with improper authentication token value' do
|
|
58
|
+
store_translations :en, :devise => {:failure => {:invalid_token => 'LOL, that was not a single character correct.'}} do
|
|
30
59
|
sign_in_as_new_user_with_token(:auth_token => '*** INVALID TOKEN ***')
|
|
31
|
-
|
|
32
|
-
follow_redirect!
|
|
60
|
+
assert_equal new_user_session_path, @request.path
|
|
33
61
|
|
|
34
|
-
assert_response :success
|
|
35
62
|
assert_contain 'LOL, that was not a single character correct.'
|
|
36
63
|
assert_contain 'Sign in'
|
|
37
64
|
assert_not warden.authenticated?(:user)
|
|
@@ -48,7 +75,13 @@ class TokenAuthenticationTest < ActionController::IntegrationTest
|
|
|
48
75
|
user.authentication_token = VALID_AUTHENTICATION_TOKEN
|
|
49
76
|
user.save
|
|
50
77
|
|
|
51
|
-
|
|
78
|
+
if options[:http_auth]
|
|
79
|
+
header = "Basic #{ActiveSupport::Base64.encode64("#{VALID_AUTHENTICATION_TOKEN}:X")}"
|
|
80
|
+
get users_path(:format => :xml), {}, "HTTP_AUTHORIZATION" => header
|
|
81
|
+
else
|
|
82
|
+
visit users_path(options[:auth_token_key].to_sym => options[:auth_token])
|
|
83
|
+
end
|
|
84
|
+
|
|
52
85
|
user
|
|
53
86
|
end
|
|
54
87
|
|