goma 0.0.1.beta → 0.0.1.gamma
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +1 -0
- data/Gemfile.lock +9 -1
- data/README.md +18 -15
- data/goma.gemspec +16 -0
- data/lib/generators/goma/erb/templates/confirmation/new.html.erb +2 -2
- data/lib/generators/goma/erb/templates/password/new.html.erb +2 -2
- data/lib/generators/goma/erb/templates/session/new.html.erb +3 -3
- data/lib/generators/goma/erb/templates/unlock/new.html.erb +2 -2
- data/lib/generators/goma/helpers/helpers.rb +5 -0
- data/lib/generators/goma/install/templates/goma.rb +38 -22
- data/lib/generators/goma/mailer/erb/templates/activation_needed_email.html.erb +1 -1
- data/lib/generators/goma/mailer/erb/templates/activation_needed_email.text.erb +1 -1
- data/lib/generators/goma/mailer/erb/templates/email_confirmation_needed_email.html.erb +1 -1
- data/lib/generators/goma/mailer/erb/templates/email_confirmation_needed_email.text.erb +1 -1
- data/lib/generators/goma/mailer/templates/mailer.rb +1 -1
- data/lib/generators/goma/model/active_record_generator.rb +11 -0
- data/lib/generators/goma/model/oauth/active_record_generator.rb +10 -1
- data/lib/generators/goma/model/oauth/templates/model.rb +5 -0
- data/lib/generators/goma/resource_route/resource_route_generator.rb +10 -12
- data/lib/generators/goma/scaffold_controller/templates/confirmation_controller.rb +5 -5
- data/lib/generators/goma/scaffold_controller/templates/oauth_controller.rb +1 -1
- data/lib/generators/goma/scaffold_controller/templates/password_controller.rb +2 -2
- data/lib/generators/goma/scaffold_controller/templates/session_controller.rb +2 -2
- data/lib/generators/goma/scaffold_controller/templates/unlock_controller.rb +1 -1
- data/lib/generators/goma/scaffold_controller/templates/user_controller.rb +6 -1
- data/lib/goma/config.rb +16 -19
- data/lib/goma/models/confirmable.rb +1 -1
- data/lib/goma/models/rememberable.rb +2 -2
- data/lib/goma/railtie.rb +0 -9
- data/lib/goma/version.rb +1 -1
- data/test/controllers/confirmations_controller_test.rb +14 -0
- data/test/controllers/lockable_controller_test.rb +8 -8
- data/test/controllers/sessions_controller_test.rb +8 -8
- data/test/controllers/users_controller_test.rb +2 -13
- data/test/fabricators/users_fabricator.rb +2 -2
- data/test/integration/{authenticatable_test.rb → authenticatable_integration_test.rb} +4 -4
- data/test/integration/omniauthable_integration_test.rb +26 -0
- data/test/integration/{rememberable_test.rb → rememberable_integration_test.rb} +7 -7
- data/test/integration/{routes_test.rb → routes_integration_test.rb} +8 -8
- data/test/integration/{timeoutable_test.rb → timeoutable_integration_test.rb} +3 -3
- data/test/integration/{trackable_test.rb → trackable_integration_test.rb} +3 -3
- data/test/models/confirmable_test.rb +1 -1
- data/test/models/validatable_test.rb +7 -7
- data/test/rails_app/app/assets/javascripts/{sessions.js → confirmations.js} +0 -0
- data/test/rails_app/app/assets/stylesheets/authentications.css +4 -0
- data/test/rails_app/app/assets/stylesheets/confirmations.css +4 -0
- data/test/rails_app/app/assets/stylesheets/passwords.css +4 -0
- data/test/rails_app/app/assets/stylesheets/unlocks.css +4 -0
- data/test/rails_app/app/controllers/authentications_controller.rb +15 -0
- data/test/rails_app/app/controllers/confirmations_controller.rb +52 -0
- data/test/rails_app/app/controllers/passwords_controller.rb +41 -0
- data/test/rails_app/app/controllers/sessions_controller.rb +13 -5
- data/test/rails_app/app/controllers/unlocks_controller.rb +32 -0
- data/test/rails_app/app/controllers/users_controller.rb +32 -15
- data/test/rails_app/app/helpers/authentications_helper.rb +2 -0
- data/test/rails_app/app/helpers/confirmations_helper.rb +2 -0
- data/test/rails_app/app/helpers/passwords_helper.rb +2 -0
- data/test/rails_app/app/helpers/unlocks_helper.rb +2 -0
- data/test/rails_app/app/mailers/user_mailer.rb +33 -20
- data/test/rails_app/app/views/confirmations/new.html.erb +12 -0
- data/test/rails_app/app/views/passwords/edit.html.erb +27 -0
- data/test/rails_app/app/views/passwords/new.html.erb +11 -0
- data/test/rails_app/app/views/sessions/new.html.erb +13 -5
- data/test/rails_app/app/views/unlocks/new.html.erb +11 -0
- data/test/rails_app/app/views/user_mailer/activation_needed_email.text.erb +5 -2
- data/test/rails_app/app/views/user_mailer/activation_success_email.text.erb +7 -2
- data/test/rails_app/app/views/user_mailer/email_confirmation_needed_email.text.erb +5 -2
- data/test/rails_app/app/views/user_mailer/email_confirmation_success_email.text.erb +4 -2
- data/test/rails_app/app/views/user_mailer/reset_password_email.text.erb +10 -0
- data/test/rails_app/app/views/user_mailer/unlock_token_email.text.erb +10 -0
- data/test/rails_app/app/views/users/_form.html.erb +33 -0
- data/test/rails_app/app/views/users/edit.html.erb +6 -2
- data/test/rails_app/app/views/users/index.html.erb +25 -2
- data/test/rails_app/app/views/users/new.html.erb +5 -2
- data/test/rails_app/app/views/users/show.html.erb +4 -2
- data/test/rails_app/config/environments/test.rb +2 -0
- data/test/rails_app/config/initializers/goma.rb +43 -29
- data/test/rails_app/config/initializers/omniauth.rb +4 -0
- data/test/rails_app/config/routes.rb +20 -5
- data/test/rails_app/db/migrate/20140512081308_create_users.rb +44 -0
- data/test/rails_app/db/migrate/{20140326043644_create_authentications.rb → 20140512081309_create_authentications.rb} +1 -0
- data/test/rails_app/db/schema.rb +9 -5
- data/test/test_helper.rb +10 -0
- metadata +72 -24
- data/test/rails_app/app/views/user_mailer/unlock_email.text.erb +0 -0
- data/test/rails_app/db/migrate/20131205013904_goma_create_users.rb +0 -46
data/lib/goma/config.rb
CHANGED
@@ -42,27 +42,31 @@ module Goma
|
|
42
42
|
include Goma::Configurable
|
43
43
|
config_accessor(:default_mailer_name) { 'UserMailer' }
|
44
44
|
config_accessor(:mailer_sender)
|
45
|
-
config_accessor(:authentication_keys) { [:email] }
|
46
|
-
config_accessor(:email_regexp) { /\A[^@]+@[^@]+\z/ }
|
47
|
-
config_accessor(:password_length) { 6..128 }
|
48
|
-
config_accessor(:case_insensitive_keys) { [:email] }
|
49
|
-
config_accessor(:strip_whitespace_keys) { [:email] }
|
50
45
|
config_accessor(:clean_up_csrf_token_on_authentication) { true }
|
51
46
|
config_accessor(:secret_key)
|
52
|
-
config_accessor(:encryptor) { :bcrypt }
|
53
|
-
config_accessor(:stretches) { 10 }
|
54
|
-
config_accessor(:pepper)
|
55
47
|
config_accessor(:serialization_method) { :goma }
|
56
48
|
config_accessor(:scopes) { [:user] }
|
57
49
|
config_accessor(:default_scope) { :user }
|
58
|
-
config_accessor(:modules) { [
|
50
|
+
config_accessor(:modules) { [] }
|
59
51
|
config_accessor(:save_return_to_url) { true }
|
60
52
|
config_accessor(:not_authenticated_action) { :not_authenticated }
|
61
53
|
|
54
|
+
|
55
|
+
# Password authenticatable
|
56
|
+
config_accessor(:authentication_keys) { [:email] }
|
57
|
+
config_accessor(:case_insensitive_keys) { [:email] }
|
58
|
+
config_accessor(:strip_whitespace_keys) { [:email] }
|
59
|
+
config_accessor(:encryptor) { :bcrypt }
|
60
|
+
config_accessor(:pepper)
|
61
|
+
config_accessor(:stretches) { 10 }
|
62
62
|
config_accessor(:email_attribute_name) { :email }
|
63
63
|
config_accessor(:password_attribute_name) { :password }
|
64
64
|
config_accessor(:encrypted_password_attribute_name) { :encrypted_password }
|
65
65
|
|
66
|
+
# Validatable
|
67
|
+
config_accessor(:password_length) { 8..128 }
|
68
|
+
config_accessor(:email_regexp) { /\A[^@]+@[^@]+\z/ }
|
69
|
+
|
66
70
|
# Confirmable
|
67
71
|
config_accessor(:activation_mailer_name) { nil }
|
68
72
|
config_accessor(:email_confirmation_mailer_name) { nil }
|
@@ -86,7 +90,7 @@ module Goma
|
|
86
90
|
config_accessor(:remember_for) { 2.weeks }
|
87
91
|
config_accessor(:extend_remember_period) { false }
|
88
92
|
config_accessor(:rememberable_options) { {} }
|
89
|
-
config_accessor(:remember_token_attribute_name) {
|
93
|
+
config_accessor(:remember_token_attribute_name) { nil }
|
90
94
|
config_accessor(:remember_created_at_attribute_name) { :remember_created_at }
|
91
95
|
|
92
96
|
# Timeoutable
|
@@ -96,17 +100,17 @@ module Goma
|
|
96
100
|
|
97
101
|
# Lockable
|
98
102
|
config_accessor(:unlock_token_mailer_name) { nil }
|
99
|
-
config_accessor(:unlock_token_email_method_name) { :
|
103
|
+
config_accessor(:unlock_token_email_method_name) { :unlock_token_email }
|
100
104
|
config_accessor(:lock_strategy) { :failed_attempts }
|
101
105
|
config_accessor(:unlock_keys) { :email }
|
102
106
|
config_accessor(:unlock_strategies) { [:email, :time] }
|
103
107
|
config_accessor(:maximum_attempts) { 20 }
|
104
108
|
config_accessor(:failed_attempts_attribute_name) { :failed_attempts }
|
105
109
|
config_accessor(:locked_at_attribute_name) { :locked_at }
|
110
|
+
config_accessor(:unlock_in) { 1.hour }
|
106
111
|
config_accessor(:unlock_token_attribute_name) { :unlock_token }
|
107
112
|
config_accessor(:unlock_token_sent_at_attribute_name) { :unlock_token_sent_at }
|
108
113
|
config_accessor(:unlock_token_to_send_attribute_name) { :raw_unlock_token }
|
109
|
-
config_accessor(:unlock_in) { 1.hour }
|
110
114
|
|
111
115
|
# Recoverable
|
112
116
|
config_accessor(:reset_password_mailer_name) { nil }
|
@@ -125,17 +129,10 @@ module Goma
|
|
125
129
|
config_accessor(:last_login_ip_attribute_name) { :last_login_ip }
|
126
130
|
|
127
131
|
# Omniauthable
|
128
|
-
config_accessor(:oauth_providers) { {} }
|
129
132
|
config_accessor(:oauth_authentication_class_name) { 'Authentication' }
|
130
133
|
config_accessor(:oauth_provider_attribute_name) { :provider }
|
131
134
|
config_accessor(:oauth_uid_attribute_name) { :uid }
|
132
|
-
def omniauth(provider, app_id=nil, app_secret=nil)
|
133
|
-
oauth_providers[provider] = {key: app_id, secret: app_secret}
|
134
|
-
end
|
135
135
|
|
136
|
-
# TODO
|
137
|
-
config_accessor(:salt_attribute_name) { nil }
|
138
|
-
config_accessor(:salt_join_token) { '' }
|
139
136
|
|
140
137
|
self.instance_methods(false).grep(/attribute_name$/).each do |conf_name|
|
141
138
|
name = conf_name.to_s[0...-15]
|
@@ -82,7 +82,7 @@ module Goma
|
|
82
82
|
end
|
83
83
|
|
84
84
|
def send_activation_needed_email?
|
85
|
-
goma_config.activation_needed_email_method_name && !@skip_activation_needed_email
|
85
|
+
!activated? && goma_config.activation_needed_email_method_name && !@skip_activation_needed_email
|
86
86
|
end
|
87
87
|
|
88
88
|
def send_activation_success_email?
|
@@ -28,13 +28,13 @@ module Goma
|
|
28
28
|
|
29
29
|
def forget_me!
|
30
30
|
return unless persisted?
|
31
|
-
send(goma_config.remember_token_setter, nil)
|
31
|
+
send(goma_config.remember_token_setter, nil) if goma_config.remember_token_attribute_name
|
32
32
|
send(goma_config.remember_created_at_setter, nil)
|
33
33
|
save(validate: false)
|
34
34
|
end
|
35
35
|
|
36
36
|
def rememberable_value
|
37
|
-
if
|
37
|
+
if goma_config.remember_token_attribute_name
|
38
38
|
send(goma_config.remember_token_getter)
|
39
39
|
elsif salt = authenticatable_salt
|
40
40
|
salt
|
data/lib/goma/railtie.rb
CHANGED
@@ -89,15 +89,6 @@ module Goma
|
|
89
89
|
Goma::Encryptors.const_get(Goma.config.encryptor.to_s.classify)
|
90
90
|
end
|
91
91
|
|
92
|
-
if Goma.config.modules.include?(:omniauthable)
|
93
|
-
config.app_middleware.use ::OmniAuth::Builder do
|
94
|
-
Goma.config.oauth_providers.each do |service, oauth|
|
95
|
-
provider(service) and next if service.to_sym == :developer
|
96
|
-
provider service, oauth[:key], oauth[:secret]
|
97
|
-
end
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
101
92
|
require 'goma/routes'
|
102
93
|
end
|
103
94
|
end
|
data/lib/goma/version.rb
CHANGED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class ConfirmationsControllerTest < ActionController::TestCase
|
4
|
+
test 'should activate user' do
|
5
|
+
user = User.new(username: 'foo', email: 'foo@example.com', password: 'password', password_confirmation: 'password')
|
6
|
+
user.save!
|
7
|
+
|
8
|
+
get :show, id: user.raw_confirmation_token
|
9
|
+
assert_redirected_to new_session_url
|
10
|
+
assert flash[:notice]
|
11
|
+
user.reload
|
12
|
+
assert user.activated?
|
13
|
+
end
|
14
|
+
end
|
@@ -14,10 +14,10 @@ class LockableControllerTest < ActionController::TestCase
|
|
14
14
|
|
15
15
|
should 'be reset failed_attempts when user logs in successfully' do
|
16
16
|
assert_equal 0, @user.failed_attempts
|
17
|
-
2.times{ post :create, {username_or_email: @user.email, password: '
|
17
|
+
2.times{ post :create, {username_or_email: @user.email, password: 'wrongpass'} }
|
18
18
|
assert_equal 2, @user.reload.failed_attempts
|
19
19
|
|
20
|
-
post :create, {username_or_email: @user.email, password: '
|
20
|
+
post :create, {username_or_email: @user.email, password: 'password'}
|
21
21
|
assert_equal 0, @user.reload.failed_attempts
|
22
22
|
end
|
23
23
|
|
@@ -33,13 +33,13 @@ class LockableControllerTest < ActionController::TestCase
|
|
33
33
|
should 'be locked when number of login attemps exceeds config.maximum_attempts' do
|
34
34
|
assert_no_difference 'ActionMailer::Base.deliveries.count' do
|
35
35
|
5.times do
|
36
|
-
post :create, {username_or_email: @user.email, password: '
|
36
|
+
post :create, {username_or_email: @user.email, password: 'wrongpass'}
|
37
37
|
end
|
38
38
|
end
|
39
39
|
refute @user.reload.access_locked?
|
40
40
|
|
41
41
|
assert_difference 'ActionMailer::Base.deliveries.count', 1 do
|
42
|
-
post :create, {username_or_email: @user.email, password: '
|
42
|
+
post :create, {username_or_email: @user.email, password: 'wrongpass'}
|
43
43
|
end
|
44
44
|
assert @user.reload.access_locked?
|
45
45
|
end
|
@@ -47,7 +47,7 @@ class LockableControllerTest < ActionController::TestCase
|
|
47
47
|
|
48
48
|
should 'not be unlocked after config.unlock_in time' do
|
49
49
|
6.times do
|
50
|
-
post :create, {username_or_email: @user.email, password: '
|
50
|
+
post :create, {username_or_email: @user.email, password: 'wrongpass'}
|
51
51
|
end
|
52
52
|
assert @user.reload.access_locked?
|
53
53
|
|
@@ -70,20 +70,20 @@ class LockableControllerTest < ActionController::TestCase
|
|
70
70
|
should 'be locked without sending email' do
|
71
71
|
assert_no_difference 'ActionMailer::Base.deliveries.count' do
|
72
72
|
5.times do
|
73
|
-
post :create, {username_or_email: @user.email, password: '
|
73
|
+
post :create, {username_or_email: @user.email, password: 'wrongpass'}
|
74
74
|
end
|
75
75
|
end
|
76
76
|
refute @user.reload.access_locked?
|
77
77
|
|
78
78
|
assert_no_difference 'ActionMailer::Base.deliveries.count' do
|
79
|
-
post :create, {username_or_email: @user.email, password: '
|
79
|
+
post :create, {username_or_email: @user.email, password: 'wrongpass'}
|
80
80
|
end
|
81
81
|
assert @user.reload.access_locked?
|
82
82
|
end
|
83
83
|
|
84
84
|
should 'be unlocked after config.unlock_in time' do
|
85
85
|
6.times do
|
86
|
-
post :create, {username_or_email: @user.email, password: '
|
86
|
+
post :create, {username_or_email: @user.email, password: 'wrongpass'}
|
87
87
|
end
|
88
88
|
assert @user.reload.access_locked?
|
89
89
|
|
@@ -7,21 +7,21 @@ class SessionsControllerTest < ActionController::TestCase
|
|
7
7
|
end
|
8
8
|
|
9
9
|
test 'should login with email' do
|
10
|
-
post :create, {username_or_email: @user.email, password: '
|
10
|
+
post :create, {username_or_email: @user.email, password: 'password'}
|
11
11
|
assert_redirected_to root_url
|
12
12
|
assert flash[:notice]
|
13
13
|
assert_equal @user, current_user
|
14
14
|
end
|
15
15
|
|
16
16
|
test 'should login with username' do
|
17
|
-
post :create, {username_or_email: @user.username, password: '
|
17
|
+
post :create, {username_or_email: @user.username, password: 'password'}
|
18
18
|
assert_redirected_to root_url
|
19
19
|
assert flash[:notice]
|
20
20
|
assert_equal @user, current_user
|
21
21
|
end
|
22
22
|
|
23
23
|
test 'should not login with incorrect password' do
|
24
|
-
post :create, {username_or_email: @user.email, password: '
|
24
|
+
post :create, {username_or_email: @user.email, password: 'wrongpass'}
|
25
25
|
assert_nil current_user
|
26
26
|
assert_response :success
|
27
27
|
assert_template :new
|
@@ -30,7 +30,7 @@ class SessionsControllerTest < ActionController::TestCase
|
|
30
30
|
|
31
31
|
test 'should login with case-insensitive key case-insensitively' do
|
32
32
|
assert :email.in? @user.goma_config.case_insensitive_keys
|
33
|
-
post :create, {username_or_email: @user.email.upcase, password: '
|
33
|
+
post :create, {username_or_email: @user.email.upcase, password: 'password'}
|
34
34
|
assert_redirected_to root_url
|
35
35
|
assert flash[:notice]
|
36
36
|
assert_equal @user, current_user
|
@@ -38,7 +38,7 @@ class SessionsControllerTest < ActionController::TestCase
|
|
38
38
|
|
39
39
|
test 'should login with strip-whitespace key whitespace-strippingly' do
|
40
40
|
assert :email.in? @user.goma_config.strip_whitespace_keys
|
41
|
-
post :create, {username_or_email: " " + @user.email + ' ', password: '
|
41
|
+
post :create, {username_or_email: " " + @user.email + ' ', password: 'password'}
|
42
42
|
assert_redirected_to root_url
|
43
43
|
assert flash[:notice]
|
44
44
|
assert_equal @user, current_user
|
@@ -46,7 +46,7 @@ class SessionsControllerTest < ActionController::TestCase
|
|
46
46
|
|
47
47
|
test 'should not login with non case-insensitive key case-insensitively' do
|
48
48
|
refute :username.in? @user.goma_config.case_insensitive_keys
|
49
|
-
post :create, {username_or_email: @user.username.upcase, password: '
|
49
|
+
post :create, {username_or_email: @user.username.upcase, password: 'password'}
|
50
50
|
assert_nil current_user
|
51
51
|
assert_response :success
|
52
52
|
assert_template :new
|
@@ -55,7 +55,7 @@ class SessionsControllerTest < ActionController::TestCase
|
|
55
55
|
|
56
56
|
test 'should not login with non strip-whitespace key whitespace-strippingly' do
|
57
57
|
refute :username.in? @user.goma_config.strip_whitespace_keys
|
58
|
-
post :create, {username_or_email: " " + @user.username + ' ', password: '
|
58
|
+
post :create, {username_or_email: " " + @user.username + ' ', password: 'password'}
|
59
59
|
assert_nil current_user
|
60
60
|
assert_response :success
|
61
61
|
assert_template :new
|
@@ -64,7 +64,7 @@ class SessionsControllerTest < ActionController::TestCase
|
|
64
64
|
|
65
65
|
test 'should raise exception when login! with incorrect password' do
|
66
66
|
assert_raise Goma::InvalidIdOrPassword do
|
67
|
-
@controller.login!(@user.email, '
|
67
|
+
@controller.login!(@user.email, 'wrongpass')
|
68
68
|
end
|
69
69
|
end
|
70
70
|
|
@@ -4,20 +4,9 @@ class UsersControllerTest < ActionController::TestCase
|
|
4
4
|
# This test might not be needed
|
5
5
|
test 'should create user' do
|
6
6
|
assert_difference 'User.count', 1 do
|
7
|
-
post :create, {user: {username: 'foo', email: 'foo@example.com', password: '
|
7
|
+
post :create, {user: {username: 'foo', email: 'foo@example.com', password: 'password', password_confirmation: 'password'}}
|
8
8
|
end
|
9
|
-
assert_redirected_to
|
9
|
+
assert_redirected_to new_session_url
|
10
10
|
assert flash[:notice]
|
11
11
|
end
|
12
|
-
|
13
|
-
test 'should activate user' do
|
14
|
-
user = User.new(username: 'foo', email: 'foo@example.com', password: 'secret', password_confirmation: 'secret')
|
15
|
-
user.save!
|
16
|
-
|
17
|
-
get :activate, id: user.raw_confirmation_token
|
18
|
-
assert_redirected_to root_url
|
19
|
-
assert flash[:notice]
|
20
|
-
user.reload
|
21
|
-
assert user.activated?
|
22
|
-
end
|
23
12
|
end
|
@@ -1,8 +1,8 @@
|
|
1
1
|
Fabricator(:user) do
|
2
2
|
username { sequence(:username) { |i| "user#{i}" } }
|
3
3
|
email { sequence(:email) { |i| "user#{i}@example.com" } }
|
4
|
-
password '
|
5
|
-
password_confirmation '
|
4
|
+
password 'password'
|
5
|
+
password_confirmation 'password'
|
6
6
|
activated_at Time.new.utc
|
7
7
|
end
|
8
8
|
|
@@ -1,26 +1,26 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
|
-
class
|
3
|
+
class AuthenticatableSessionIntegrationTest < ActionDispatch::IntegrationTest
|
4
4
|
def setup
|
5
5
|
@user = Fabricate(:user)
|
6
6
|
end
|
7
7
|
|
8
8
|
test 'should login' do
|
9
|
-
post 'session', username_or_email: @user.email, password: '
|
9
|
+
post 'session', username_or_email: @user.email, password: 'password'
|
10
10
|
assert_equal @user, request.env['warden'].user(:user)
|
11
11
|
end
|
12
12
|
|
13
13
|
test 'should redirect back correctly' do
|
14
14
|
get 'secret/index'
|
15
15
|
assert_redirected_to root_url
|
16
|
-
post 'session', username_or_email: @user.email, password: '
|
16
|
+
post 'session', username_or_email: @user.email, password: 'password'
|
17
17
|
assert_redirected_to secret_index_url
|
18
18
|
end
|
19
19
|
|
20
20
|
test 'should redirect back url with parameters correctly' do
|
21
21
|
get 'secret/index?page=100'
|
22
22
|
assert_redirected_to root_url
|
23
|
-
post 'session', username_or_email: @user.email, password: '
|
23
|
+
post 'session', username_or_email: @user.email, password: 'password'
|
24
24
|
assert_redirected_to '/secret/index?page=100'
|
25
25
|
end
|
26
26
|
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class OmniauthableIntegrationTest < ActionDispatch::IntegrationTest
|
4
|
+
def setup
|
5
|
+
OmniAuth.config.mock_auth[:twitter] = OmniAuth::AuthHash.new({
|
6
|
+
provider: 'twitter',
|
7
|
+
uid: '1234567'
|
8
|
+
})
|
9
|
+
end
|
10
|
+
|
11
|
+
test 'should create user with omniauth' do
|
12
|
+
get '/auth/twitter'
|
13
|
+
assert_redirected_to '/auth/twitter/callback'
|
14
|
+
|
15
|
+
assert_no_difference 'ActionMailer::Base.deliveries.count' do
|
16
|
+
assert_difference ['User.count', 'Authentication.count'], 1 do
|
17
|
+
follow_redirect!
|
18
|
+
end
|
19
|
+
end
|
20
|
+
assert_redirected_to root_url
|
21
|
+
|
22
|
+
assert current_user
|
23
|
+
assert_equal 'twitter', current_user.authentications.first.provider
|
24
|
+
assert_equal '1234567', current_user.authentications.first.uid
|
25
|
+
end
|
26
|
+
end
|
@@ -1,12 +1,12 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
|
-
class
|
3
|
+
class RememberableIntegrationTest < ActionDispatch::IntegrationTest
|
4
4
|
def setup
|
5
5
|
@user = Fabricate(:user)
|
6
6
|
end
|
7
7
|
|
8
8
|
test 'should not remember when remember_me is not set' do
|
9
|
-
post 'session', username_or_email: @user.email, password: '
|
9
|
+
post 'session', username_or_email: @user.email, password: 'password'
|
10
10
|
assert @user, request.env['warden'].user(:user)
|
11
11
|
|
12
12
|
Timecop.freeze 30.minutes.from_now
|
@@ -19,7 +19,7 @@ class RememberableTest < ActionDispatch::IntegrationTest
|
|
19
19
|
test 'should remember' do
|
20
20
|
swap ApplicationController, allow_forgery_protection: true do
|
21
21
|
get 'session/new'
|
22
|
-
post 'session', username_or_email: @user.email, password: '
|
22
|
+
post 'session', username_or_email: @user.email, password: 'password', remember_me: '1', authenticity_token: session['_csrf_token']
|
23
23
|
|
24
24
|
@user.reload
|
25
25
|
assert @user, request.env['warden'].user(:user)
|
@@ -38,7 +38,7 @@ class RememberableTest < ActionDispatch::IntegrationTest
|
|
38
38
|
swap ApplicationController, allow_forgery_protection: true do
|
39
39
|
get 'session/new'
|
40
40
|
assert_raise ActionController::InvalidAuthenticityToken do
|
41
|
-
post 'session', username_or_email: @user.email, password: '
|
41
|
+
post 'session', username_or_email: @user.email, password: 'password', remember_me: '1'
|
42
42
|
end
|
43
43
|
|
44
44
|
refute request.env['warden'].user(:user)
|
@@ -51,7 +51,7 @@ class RememberableTest < ActionDispatch::IntegrationTest
|
|
51
51
|
swap ApplicationController, allow_forgery_protection: true do
|
52
52
|
get 'session/new'
|
53
53
|
assert_raise ActionController::InvalidAuthenticityToken do
|
54
|
-
post 'session', username_or_email: @user.email, password: '
|
54
|
+
post 'session', username_or_email: @user.email, password: 'password', remember_me: '1', authenticity_token: 'wrong'
|
55
55
|
end
|
56
56
|
|
57
57
|
refute request.env['warden'].user(:user)
|
@@ -63,7 +63,7 @@ class RememberableTest < ActionDispatch::IntegrationTest
|
|
63
63
|
test 'should login with remember cookie' do
|
64
64
|
swap ApplicationController, allow_forgery_protection: true do
|
65
65
|
get 'session/new'
|
66
|
-
post 'session', username_or_email: @user.email, password: '
|
66
|
+
post 'session', username_or_email: @user.email, password: 'password', remember_me: '1', authenticity_token: session['_csrf_token']
|
67
67
|
|
68
68
|
reset!
|
69
69
|
|
@@ -81,7 +81,7 @@ class RememberableTest < ActionDispatch::IntegrationTest
|
|
81
81
|
test 'should forget when logout' do
|
82
82
|
swap ApplicationController, allow_forgery_protection: true do
|
83
83
|
get 'session/new'
|
84
|
-
post 'session', username_or_email: @user.email, password: '
|
84
|
+
post 'session', username_or_email: @user.email, password: 'password', remember_me: '1', authenticity_token: session['_csrf_token']
|
85
85
|
assert @user, request.env['warden'].user(:user)
|
86
86
|
|
87
87
|
delete 'session', authenticity_token: session['_csrf_token']
|
@@ -1,8 +1,8 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
|
-
class
|
3
|
+
class RoutesIntegrationTest < ActionDispatch::IntegrationTest
|
4
4
|
def setup
|
5
|
-
@user = Fabricate(:user, password: '
|
5
|
+
@user = Fabricate(:user, password: 'password')
|
6
6
|
end
|
7
7
|
|
8
8
|
test 'constraints user_logged_in? should work correctly' do
|
@@ -10,7 +10,7 @@ class RoutesTest < ActionDispatch::IntegrationTest
|
|
10
10
|
assert_response 200
|
11
11
|
assert_instance_of HomeController, @controller
|
12
12
|
assert_equal 'a_page_for_visitors', @controller.action_name
|
13
|
-
post 'session', username_or_email: @user.email, password: '
|
13
|
+
post 'session', username_or_email: @user.email, password: 'password'
|
14
14
|
get 'a_page'
|
15
15
|
assert_response 200
|
16
16
|
assert_instance_of HomeController, @controller
|
@@ -18,7 +18,7 @@ class RoutesTest < ActionDispatch::IntegrationTest
|
|
18
18
|
end
|
19
19
|
|
20
20
|
test 'constraints current_user{|u|... should work correctly' do
|
21
|
-
post 'session', username_or_email: @user.email, password: '
|
21
|
+
post 'session', username_or_email: @user.email, password: 'password'
|
22
22
|
|
23
23
|
assert_raise ActionController::RoutingError do
|
24
24
|
get 'a_path_constraints_current_user_with_arity_block'
|
@@ -33,7 +33,7 @@ class RoutesTest < ActionDispatch::IntegrationTest
|
|
33
33
|
end
|
34
34
|
|
35
35
|
test 'constraints current_user{... should work correctly' do
|
36
|
-
post 'session', username_or_email: @user.email, password: '
|
36
|
+
post 'session', username_or_email: @user.email, password: 'password'
|
37
37
|
|
38
38
|
assert_raise ActionController::RoutingError do
|
39
39
|
get 'a_path_constraints_current_user_with_no_arity_block'
|
@@ -56,7 +56,7 @@ class RoutesTest < ActionDispatch::IntegrationTest
|
|
56
56
|
should 'work correctly with constraints user_logged_in?' do
|
57
57
|
swap ApplicationController, allow_forgery_protection: true do
|
58
58
|
get 'session/new'
|
59
|
-
post 'session', username_or_email: @user.email, password: '
|
59
|
+
post 'session', username_or_email: @user.email, password: 'password', remember_me: '1', authenticity_token: session['_csrf_token']
|
60
60
|
reset!
|
61
61
|
|
62
62
|
get 'a_page'
|
@@ -81,7 +81,7 @@ class RoutesTest < ActionDispatch::IntegrationTest
|
|
81
81
|
end
|
82
82
|
|
83
83
|
get 'session/new'
|
84
|
-
post 'session', username_or_email: @user.email, password: '
|
84
|
+
post 'session', username_or_email: @user.email, password: 'password', remember_me: '1', authenticity_token: session['_csrf_token']
|
85
85
|
reset!
|
86
86
|
|
87
87
|
@user.reload
|
@@ -101,7 +101,7 @@ class RoutesTest < ActionDispatch::IntegrationTest
|
|
101
101
|
end
|
102
102
|
|
103
103
|
get 'session/new'
|
104
|
-
post 'session', username_or_email: @user.email, password: '
|
104
|
+
post 'session', username_or_email: @user.email, password: 'password', remember_me: '1', authenticity_token: session['_csrf_token']
|
105
105
|
reset!
|
106
106
|
|
107
107
|
@user.reload
|
@@ -1,9 +1,9 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
|
-
class
|
3
|
+
class TimeoutableIntegrationTest < ActionDispatch::IntegrationTest
|
4
4
|
def setup
|
5
5
|
@user = Fabricate(:user)
|
6
|
-
post 'session', username_or_email: @user.email, password: '
|
6
|
+
post 'session', username_or_email: @user.email, password: 'password'
|
7
7
|
end
|
8
8
|
|
9
9
|
test "should set goma.last_request_at immediately after login" do
|
@@ -107,7 +107,7 @@ end
|
|
107
107
|
# # Goma.config.validate_session_even_in_not_login_area = false
|
108
108
|
# # reinclude_timeout_module
|
109
109
|
# @user = Fabricate(:user)
|
110
|
-
# post 'session', username_or_email: @user.email, password: '
|
110
|
+
# post 'session', username_or_email: @user.email, password: 'password'
|
111
111
|
# end
|
112
112
|
# #
|
113
113
|
# # def teardown
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
|
-
class
|
3
|
+
class TrackableIntegrationTest < ActionDispatch::IntegrationTest
|
4
4
|
def setup
|
5
5
|
@user = Fabricate(:user)
|
6
6
|
end
|
@@ -14,7 +14,7 @@ class TrackableTest < ActionDispatch::IntegrationTest
|
|
14
14
|
|
15
15
|
Timecop.freeze 10.minutes.from_now
|
16
16
|
@login_at = Time.now.utc
|
17
|
-
post 'session', username_or_email: @user.email, password: '
|
17
|
+
post 'session', username_or_email: @user.email, password: 'password'
|
18
18
|
|
19
19
|
Timecop.travel 10.minutes.from_now
|
20
20
|
|
@@ -40,7 +40,7 @@ class TrackableTest < ActionDispatch::IntegrationTest
|
|
40
40
|
|
41
41
|
Timecop.freeze 10.minutes.from_now
|
42
42
|
@second_login_at = Time.now.utc
|
43
|
-
post 'session', {username_or_email: @user.email, password: '
|
43
|
+
post 'session', {username_or_email: @user.email, password: 'password'}, {'REMOTE_ADDR' => '192.168.1.10'}
|
44
44
|
|
45
45
|
Timecop.travel 10.minutes.from_now
|
46
46
|
|
@@ -3,7 +3,7 @@ require "test_helper"
|
|
3
3
|
class ConfirmableTest < ActiveSupport::TestCase
|
4
4
|
context "A newly created user" do
|
5
5
|
setup do
|
6
|
-
@user = User.new(username: 'foo', email: 'foo@example.com', password: '
|
6
|
+
@user = User.new(username: 'foo', email: 'foo@example.com', password: 'password')
|
7
7
|
end
|
8
8
|
|
9
9
|
should "not be activated" do
|
@@ -7,43 +7,43 @@ class ValidatableTest < ActiveSupport::TestCase
|
|
7
7
|
|
8
8
|
test 'should pass all the validations with valid data' do
|
9
9
|
assert_difference 'User.count', 1 do
|
10
|
-
User.create!(username: 'bar', email: 'bar@example.com', password: '
|
10
|
+
User.create!(username: 'bar', email: 'bar@example.com', password: 'password', password_confirmation: 'password')
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
14
|
test 'should validates_presence_of :username' do
|
15
15
|
assert_raise ActiveRecord::RecordInvalid do
|
16
|
-
user = User.create!(username: nil, email: 'bar@example.com', password: '
|
16
|
+
user = User.create!(username: nil, email: 'bar@example.com', password: 'password', password_confirmation: 'password')
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
20
|
test 'should validates_uniqueness_of :username' do
|
21
21
|
assert_raise ActiveRecord::RecordInvalid do
|
22
|
-
user = User.create!(username: 'foo', email: 'bar@example.com', password: '
|
22
|
+
user = User.create!(username: 'foo', email: 'bar@example.com', password: 'password', password_confirmation: 'password')
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
26
26
|
test 'should validates_presence_of :email' do
|
27
27
|
assert_raise ActiveRecord::RecordInvalid do
|
28
|
-
user = User.create!(username: 'foo', email: nil, password: '
|
28
|
+
user = User.create!(username: 'foo', email: nil, password: 'password', password_confirmation: 'password')
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
32
|
test 'should validates_uniqueness_of :email' do
|
33
33
|
assert_raise ActiveRecord::RecordInvalid do
|
34
|
-
user = User.create!(username: 'bar', email: 'foo@example.com', password: '
|
34
|
+
user = User.create!(username: 'bar', email: 'foo@example.com', password: 'password', password_confirmation: 'password')
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
38
38
|
test 'should validates_format_of :email' do
|
39
39
|
assert_raise ActiveRecord::RecordInvalid do
|
40
|
-
user = User.create!(username: 'bar', email: 'bar.example.com', password: '
|
40
|
+
user = User.create!(username: 'bar', email: 'bar.example.com', password: 'password', password_confirmation: 'password')
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
44
44
|
test 'should validates_length_of :password with too short password' do
|
45
45
|
assert_raise ActiveRecord::RecordInvalid do
|
46
|
-
user = User.create!(username: 'bar', email: 'bar@example.com', password: 's' *
|
46
|
+
user = User.create!(username: 'bar', email: 'bar@example.com', password: 's' * 7, password_confirmation: 's' * 7)
|
47
47
|
end
|
48
48
|
end
|
49
49
|
|
File without changes
|