sorcery 0.5.21 → 0.5.30
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of sorcery might be problematic. Click here for more details.
- data/README.rdoc +1 -1
- data/VERSION +1 -1
- data/lib/sorcery/controller.rb +5 -3
- data/lib/sorcery/controller/submodules/activity_logging.rb +10 -6
- data/lib/sorcery/controller/submodules/brute_force_protection.rb +6 -3
- data/lib/sorcery/controller/submodules/http_basic_auth.rb +10 -5
- data/lib/sorcery/controller/submodules/remember_me.rb +13 -4
- data/lib/sorcery/controller/submodules/session_timeout.rb +3 -1
- data/lib/sorcery/crypto_providers/aes256.rb +8 -5
- data/lib/sorcery/crypto_providers/bcrypt.rb +12 -6
- data/lib/sorcery/crypto_providers/sha256.rb +2 -1
- data/lib/sorcery/crypto_providers/sha512.rb +2 -1
- data/lib/sorcery/initializers/initializer.rb +125 -36
- data/lib/sorcery/model.rb +28 -15
- data/lib/sorcery/model/adapters/active_record.rb +2 -2
- data/lib/sorcery/model/adapters/mongoid.rb +2 -2
- data/lib/sorcery/model/submodules/activity_logging.rb +7 -6
- data/lib/sorcery/model/submodules/brute_force_protection.rb +10 -6
- data/lib/sorcery/model/submodules/external.rb +4 -2
- data/lib/sorcery/model/submodules/remember_me.rb +4 -3
- data/lib/sorcery/model/submodules/reset_password.rb +16 -8
- data/lib/sorcery/model/submodules/user_activation.rb +23 -10
- data/lib/sorcery/model/temporary_token.rb +3 -2
- data/lib/sorcery/test_helpers/internal.rb +2 -1
- data/lib/sorcery/test_helpers/internal/rails.rb +5 -1
- data/sorcery.gemspec +16 -2
- data/spec/Gemfile.lock +1 -1
- data/spec/rails3/Gemfile.lock +1 -1
- data/spec/rails3/spec/user_activation_spec.rb +2 -168
- data/spec/rails3/spec/user_activity_logging_spec.rb +2 -30
- data/spec/rails3/spec/user_brute_force_protection_spec.rb +2 -35
- data/spec/rails3/spec/user_oauth_spec.rb +2 -26
- data/spec/rails3/spec/user_remember_me_spec.rb +2 -45
- data/spec/rails3/spec/user_reset_password_spec.rb +3 -168
- data/spec/rails3/spec/user_spec.rb +3 -283
- data/spec/rails3_mongoid/Gemfile.lock +1 -1
- data/spec/rails3_mongoid/app/models/authentication.rb +3 -3
- data/spec/rails3_mongoid/spec/user_activation_spec.rb +2 -171
- data/spec/rails3_mongoid/spec/user_activity_logging_spec.rb +2 -25
- data/spec/rails3_mongoid/spec/user_brute_force_protection_spec.rb +2 -35
- data/spec/rails3_mongoid/spec/user_oauth_spec.rb +2 -28
- data/spec/rails3_mongoid/spec/user_remember_me_spec.rb +2 -45
- data/spec/rails3_mongoid/spec/user_reset_password_spec.rb +2 -176
- data/spec/rails3_mongoid/spec/user_spec.rb +3 -285
- data/spec/shared_examples/user_activation_shared_examples.rb +173 -0
- data/spec/shared_examples/user_activity_logging_shared_examples.rb +27 -0
- data/spec/shared_examples/user_brute_force_protection_shared_examples.rb +37 -0
- data/spec/shared_examples/user_oauth_shared_examples.rb +30 -0
- data/spec/shared_examples/user_remember_me_shared_examples.rb +47 -0
- data/spec/shared_examples/user_reset_password_shared_examples.rb +177 -0
- data/spec/shared_examples/user_shared_examples.rb +292 -0
- data/spec/sinatra/Gemfile.lock +1 -1
- data/spec/sinatra_modular/Gemfile.lock +1 -1
- metadata +16 -2
@@ -1,7 +1,7 @@
|
|
1
1
|
class Authentication
|
2
2
|
include Mongoid::Document
|
3
|
-
field :user_id, type
|
4
|
-
field :provider, type
|
5
|
-
field :uid, type
|
3
|
+
field :user_id, :type => Integer
|
4
|
+
field :provider, :type => String
|
5
|
+
field :uid, :type => Integer
|
6
6
|
belongs_to :user
|
7
7
|
end
|
@@ -1,178 +1,9 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
2
|
require File.expand_path(File.dirname(__FILE__) + '/../app/mailers/sorcery_mailer')
|
3
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../shared_examples/user_activation_shared_examples')
|
3
4
|
|
4
5
|
describe "User with activation submodule" do
|
5
6
|
|
6
|
-
|
7
|
-
describe User, "loaded plugin configuration" do
|
8
|
-
before(:all) do
|
9
|
-
sorcery_reload!([:user_activation], :user_activation_mailer => ::SorceryMailer)
|
10
|
-
end
|
11
|
-
|
12
|
-
after(:each) do
|
13
|
-
User.sorcery_config.reset!
|
14
|
-
sorcery_reload!([:user_activation], :user_activation_mailer => ::SorceryMailer)
|
15
|
-
end
|
16
|
-
|
17
|
-
it "should enable configuration option 'activation_state_attribute_name'" do
|
18
|
-
sorcery_model_property_set(:activation_state_attribute_name, :status)
|
19
|
-
User.sorcery_config.activation_state_attribute_name.should equal(:status)
|
20
|
-
end
|
21
|
-
|
22
|
-
it "should enable configuration option 'activation_token_attribute_name'" do
|
23
|
-
sorcery_model_property_set(:activation_token_attribute_name, :code)
|
24
|
-
User.sorcery_config.activation_token_attribute_name.should equal(:code)
|
25
|
-
end
|
26
|
-
|
27
|
-
it "should enable configuration option 'user_activation_mailer'" do
|
28
|
-
sorcery_model_property_set(:user_activation_mailer, TestMailer)
|
29
|
-
User.sorcery_config.user_activation_mailer.should equal(TestMailer)
|
30
|
-
end
|
31
|
-
|
32
|
-
it "should enable configuration option 'activation_needed_email_method_name'" do
|
33
|
-
sorcery_model_property_set(:activation_needed_email_method_name, :my_activation_email)
|
34
|
-
User.sorcery_config.activation_needed_email_method_name.should equal(:my_activation_email)
|
35
|
-
end
|
36
|
-
|
37
|
-
it "should enable configuration option 'activation_success_email_method_name'" do
|
38
|
-
sorcery_model_property_set(:activation_success_email_method_name, :my_activation_email)
|
39
|
-
User.sorcery_config.activation_success_email_method_name.should equal(:my_activation_email)
|
40
|
-
end
|
41
|
-
|
42
|
-
it "if mailer is nil on activation, throw exception!" do
|
43
|
-
expect{sorcery_reload!([:user_activation])}.to raise_error(ArgumentError)
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
# ----------------- ACTIVATION PROCESS -----------------------
|
48
|
-
describe User, "activation process" do
|
49
|
-
before(:all) do
|
50
|
-
sorcery_reload!([:user_activation], :user_activation_mailer => ::SorceryMailer)
|
51
|
-
end
|
52
|
-
|
53
|
-
before(:each) do
|
54
|
-
create_new_user
|
55
|
-
end
|
56
|
-
|
57
|
-
it "should initialize user state to 'pending'" do
|
58
|
-
@user.activation_state.should == "pending"
|
59
|
-
end
|
60
|
-
|
61
|
-
specify { @user.should respond_to(:activate!) }
|
62
|
-
|
63
|
-
it "should clear activation code and change state to 'active' on activation" do
|
64
|
-
activation_token = @user.activation_token
|
65
|
-
@user.activate!
|
66
|
-
@user2 = User.find(@user.id) # go to db to make sure it was saved and not just in memory
|
67
|
-
@user2.activation_token.should be_nil
|
68
|
-
@user2.activation_state.should == "active"
|
69
|
-
User.find_by_activation_token(activation_token).should be_nil
|
70
|
-
end
|
71
|
-
|
72
|
-
it "should send the user an activation email" do
|
73
|
-
old_size = ActionMailer::Base.deliveries.size
|
74
|
-
create_new_user
|
75
|
-
ActionMailer::Base.deliveries.size.should == old_size + 1
|
76
|
-
end
|
77
|
-
|
78
|
-
it "subsequent saves do not send activation email" do
|
79
|
-
old_size = ActionMailer::Base.deliveries.size
|
80
|
-
@user.username = "Shauli"
|
81
|
-
@user.save!
|
82
|
-
ActionMailer::Base.deliveries.size.should == old_size
|
83
|
-
end
|
84
|
-
|
85
|
-
it "should send the user an activation success email on successful activation" do
|
86
|
-
old_size = ActionMailer::Base.deliveries.size
|
87
|
-
@user.activate!
|
88
|
-
ActionMailer::Base.deliveries.size.should == old_size + 1
|
89
|
-
end
|
90
|
-
|
91
|
-
it "subsequent saves do not send activation success email" do
|
92
|
-
@user.activate!
|
93
|
-
old_size = ActionMailer::Base.deliveries.size
|
94
|
-
@user.username = "Shauli"
|
95
|
-
@user.save!
|
96
|
-
ActionMailer::Base.deliveries.size.should == old_size
|
97
|
-
end
|
98
|
-
|
99
|
-
it "activation needed email is optional" do
|
100
|
-
sorcery_model_property_set(:activation_needed_email_method_name, nil)
|
101
|
-
old_size = ActionMailer::Base.deliveries.size
|
102
|
-
create_new_user
|
103
|
-
ActionMailer::Base.deliveries.size.should == old_size
|
104
|
-
end
|
105
|
-
|
106
|
-
it "activation success email is optional" do
|
107
|
-
sorcery_model_property_set(:activation_success_email_method_name, nil)
|
108
|
-
old_size = ActionMailer::Base.deliveries.size
|
109
|
-
@user.activate!
|
110
|
-
ActionMailer::Base.deliveries.size.should == old_size
|
111
|
-
end
|
112
|
-
end
|
113
|
-
|
114
|
-
describe User, "prevent non-active login feature" do
|
115
|
-
before(:all) do
|
116
|
-
sorcery_reload!([:user_activation], :user_activation_mailer => ::SorceryMailer)
|
117
|
-
end
|
118
|
-
|
119
|
-
before(:each) do
|
120
|
-
User.delete_all
|
121
|
-
create_new_user
|
122
|
-
end
|
123
|
-
|
124
|
-
it "should not allow a non-active user to authenticate" do
|
125
|
-
User.authenticate(@user.username,'secret').should be_false
|
126
|
-
end
|
127
|
-
|
128
|
-
it "should allow a non-active user to authenticate if configured so" do
|
129
|
-
sorcery_model_property_set(:prevent_non_active_users_to_login, false)
|
130
|
-
User.authenticate(@user.username,'secret').should be_true
|
131
|
-
end
|
132
|
-
end
|
133
|
-
|
134
|
-
describe User, "load_from_activation_token" do
|
135
|
-
before(:all) do
|
136
|
-
sorcery_reload!([:user_activation], :user_activation_mailer => ::SorceryMailer)
|
137
|
-
end
|
138
|
-
|
139
|
-
after(:each) do
|
140
|
-
Timecop.return
|
141
|
-
end
|
142
|
-
|
143
|
-
it "load_from_activation_token should return user when token is found" do
|
144
|
-
create_new_user
|
145
|
-
User.load_from_activation_token(@user.activation_token).should == @user
|
146
|
-
end
|
147
|
-
|
148
|
-
it "load_from_activation_token should NOT return user when token is NOT found" do
|
149
|
-
create_new_user
|
150
|
-
User.load_from_activation_token("a").should == nil
|
151
|
-
end
|
152
|
-
|
153
|
-
it "load_from_activation_token should return user when token is found and not expired" do
|
154
|
-
sorcery_model_property_set(:activation_token_expiration_period, 500)
|
155
|
-
create_new_user
|
156
|
-
User.load_from_activation_token(@user.activation_token).should == @user
|
157
|
-
end
|
158
|
-
|
159
|
-
it "load_from_activation_token should NOT return user when token is found and expired" do
|
160
|
-
sorcery_model_property_set(:activation_token_expiration_period, 0.1)
|
161
|
-
create_new_user
|
162
|
-
Timecop.travel(Time.now+0.5)
|
163
|
-
User.load_from_activation_token(@user.activation_token).should == nil
|
164
|
-
end
|
165
|
-
|
166
|
-
it "load_from_activation_token should return nil if token is blank" do
|
167
|
-
User.load_from_activation_token(nil).should == nil
|
168
|
-
User.load_from_activation_token("").should == nil
|
169
|
-
end
|
170
|
-
|
171
|
-
it "load_from_activation_token should always be valid if expiration period is nil" do
|
172
|
-
sorcery_model_property_set(:activation_token_expiration_period, nil)
|
173
|
-
create_new_user
|
174
|
-
User.load_from_activation_token(@user.activation_token).should == @user
|
175
|
-
end
|
176
|
-
end
|
7
|
+
it_behaves_like "rails_3_activation_model"
|
177
8
|
|
178
9
|
end
|
@@ -1,31 +1,8 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../shared_examples/user_activity_logging_shared_examples')
|
2
3
|
|
3
4
|
describe "User with activity logging submodule" do
|
4
5
|
|
5
|
-
|
6
|
-
describe User, "loaded plugin configuration" do
|
7
|
-
before(:all) do
|
8
|
-
sorcery_reload!([:activity_logging])
|
9
|
-
end
|
10
|
-
|
11
|
-
after(:each) do
|
12
|
-
User.sorcery_config.reset!
|
13
|
-
end
|
14
|
-
|
15
|
-
it "should allow configuration option 'last_login_at_attribute_name'" do
|
16
|
-
sorcery_model_property_set(:last_login_at_attribute_name, :login_time)
|
17
|
-
User.sorcery_config.last_login_at_attribute_name.should equal(:login_time)
|
18
|
-
end
|
19
|
-
|
20
|
-
it "should allow configuration option 'last_logout_at_attribute_name'" do
|
21
|
-
sorcery_model_property_set(:last_logout_at_attribute_name, :logout_time)
|
22
|
-
User.sorcery_config.last_logout_at_attribute_name.should equal(:logout_time)
|
23
|
-
end
|
24
|
-
|
25
|
-
it "should allow configuration option 'last_activity_at_attribute_name'" do
|
26
|
-
sorcery_model_property_set(:last_activity_at_attribute_name, :activity_time)
|
27
|
-
User.sorcery_config.last_activity_at_attribute_name.should equal(:activity_time)
|
28
|
-
end
|
29
|
-
end
|
6
|
+
it_behaves_like "rails_3_activity_logging_model"
|
30
7
|
|
31
8
|
end
|
@@ -1,41 +1,8 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../shared_examples/user_brute_force_protection_shared_examples')
|
2
3
|
|
3
4
|
describe "User with brute_force_protection submodule" do
|
4
5
|
|
5
|
-
|
6
|
-
describe User, "loaded plugin configuration" do
|
7
|
-
|
8
|
-
before(:all) do
|
9
|
-
sorcery_reload!([:brute_force_protection])
|
10
|
-
create_new_user
|
11
|
-
end
|
12
|
-
|
13
|
-
after(:each) do
|
14
|
-
User.sorcery_config.reset!
|
15
|
-
end
|
16
|
-
|
17
|
-
specify { @user.should respond_to(:failed_logins_count) }
|
18
|
-
specify { @user.should respond_to(:lock_expires_at) }
|
19
|
-
|
20
|
-
it "should enable configuration option 'failed_logins_count_attribute_name'" do
|
21
|
-
sorcery_model_property_set(:failed_logins_count_attribute_name, :my_count)
|
22
|
-
User.sorcery_config.failed_logins_count_attribute_name.should equal(:my_count)
|
23
|
-
end
|
24
|
-
|
25
|
-
it "should enable configuration option 'lock_expires_at_attribute_name'" do
|
26
|
-
sorcery_model_property_set(:lock_expires_at_attribute_name, :expires)
|
27
|
-
User.sorcery_config.lock_expires_at_attribute_name.should equal(:expires)
|
28
|
-
end
|
29
|
-
|
30
|
-
it "should enable configuration option 'consecutive_login_retries_amount_allowed'" do
|
31
|
-
sorcery_model_property_set(:consecutive_login_retries_amount_limit, 34)
|
32
|
-
User.sorcery_config.consecutive_login_retries_amount_limit.should equal(34)
|
33
|
-
end
|
34
|
-
|
35
|
-
it "should enable configuration option 'login_lock_time_period'" do
|
36
|
-
sorcery_model_property_set(:login_lock_time_period, 2.hours)
|
37
|
-
User.sorcery_config.login_lock_time_period.should == 2.hours
|
38
|
-
end
|
39
|
-
end
|
6
|
+
it_behaves_like "rails_3_brute_force_protection_model"
|
40
7
|
|
41
8
|
end
|
@@ -1,34 +1,8 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../shared_examples/user_oauth_shared_examples')
|
2
3
|
|
3
4
|
describe "User with oauth submodule" do
|
4
5
|
|
5
|
-
|
6
|
-
describe User, "loaded plugin configuration" do
|
7
|
-
|
8
|
-
before(:all) do
|
9
|
-
User.delete_all
|
10
|
-
Authentication.delete_all
|
11
|
-
sorcery_reload!([:external])
|
12
|
-
sorcery_controller_property_set(:external_providers, [:twitter])
|
13
|
-
sorcery_model_property_set(:authentications_class, Authentication)
|
14
|
-
sorcery_controller_external_property_set(:twitter, :key, "eYVNBjBDi33aa9GkA3w")
|
15
|
-
sorcery_controller_external_property_set(:twitter, :secret, "XpbeSdCoaKSmQGSeokz5qcUATClRW5u08QWNfv71N8")
|
16
|
-
sorcery_controller_external_property_set(:twitter, :callback_url, "http://blabla.com")
|
17
|
-
create_new_external_user(:twitter)
|
18
|
-
end
|
19
|
-
|
20
|
-
it "should respond to 'load_from_provider'" do
|
21
|
-
User.should respond_to(:load_from_provider)
|
22
|
-
end
|
23
|
-
|
24
|
-
it "'load_from_provider' should load user if exists" do
|
25
|
-
User.load_from_provider(:twitter,123).should == @user
|
26
|
-
end
|
27
|
-
|
28
|
-
it "'load_from_provider' should return nil if user doesn't exist" do
|
29
|
-
User.load_from_provider(:twitter,980342).should be_nil
|
30
|
-
end
|
31
|
-
|
32
|
-
end
|
6
|
+
it_behaves_like "rails_3_oauth_model"
|
33
7
|
|
34
8
|
end
|
@@ -1,51 +1,8 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../shared_examples/user_remember_me_shared_examples')
|
2
3
|
|
3
4
|
describe "User with remember_me submodule" do
|
4
5
|
|
5
|
-
|
6
|
-
describe User, "loaded plugin configuration" do
|
7
|
-
before(:all) do
|
8
|
-
sorcery_reload!([:remember_me])
|
9
|
-
create_new_user
|
10
|
-
end
|
11
|
-
|
12
|
-
after(:each) do
|
13
|
-
User.sorcery_config.reset!
|
14
|
-
end
|
15
|
-
|
16
|
-
it "should allow configuration option 'remember_me_token_attribute_name'" do
|
17
|
-
sorcery_model_property_set(:remember_me_token_attribute_name, :my_token)
|
18
|
-
User.sorcery_config.remember_me_token_attribute_name.should equal(:my_token)
|
19
|
-
end
|
20
|
-
|
21
|
-
it "should allow configuration option 'remember_me_token_expires_at_attribute_name'" do
|
22
|
-
sorcery_model_property_set(:remember_me_token_expires_at_attribute_name, :my_expires)
|
23
|
-
User.sorcery_config.remember_me_token_expires_at_attribute_name.should equal(:my_expires)
|
24
|
-
end
|
25
|
-
|
26
|
-
specify { @user.should respond_to(:remember_me!) }
|
27
|
-
|
28
|
-
specify { @user.should respond_to(:forget_me!) }
|
29
|
-
|
30
|
-
it "should generate a new token on 'remember_me!'" do
|
31
|
-
@user.remember_me_token.should be_nil
|
32
|
-
@user.remember_me!
|
33
|
-
@user.remember_me_token.should_not be_nil
|
34
|
-
end
|
35
|
-
|
36
|
-
it "should set an expiration based on 'remember_me_for' attribute" do
|
37
|
-
sorcery_model_property_set(:remember_me_for, 2 * 60 * 60 * 24)
|
38
|
-
@user.remember_me!
|
39
|
-
@user.remember_me_token_expires_at.utc.to_s.should == (Time.now + 2 * 60 * 60 * 24).utc.to_s
|
40
|
-
end
|
41
|
-
|
42
|
-
it "should delete the token and expiration on 'forget_me!'" do
|
43
|
-
@user.remember_me!
|
44
|
-
@user.remember_me_token.should_not be_nil
|
45
|
-
@user.forget_me!
|
46
|
-
@user.remember_me_token.should be_nil
|
47
|
-
@user.remember_me_token_expires_at.should be_nil
|
48
|
-
end
|
49
|
-
end
|
6
|
+
it_behaves_like "rails_3_remember_me_model"
|
50
7
|
|
51
8
|
end
|
@@ -1,182 +1,8 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../shared_examples/user_reset_password_shared_examples')
|
2
3
|
|
3
4
|
describe "User with reset_password submodule" do
|
4
5
|
|
5
|
-
|
6
|
-
describe User, "loaded plugin configuration" do
|
7
|
-
|
8
|
-
before(:all) do
|
9
|
-
sorcery_reload!([:reset_password], :reset_password_mailer => ::SorceryMailer)
|
10
|
-
end
|
11
|
-
|
12
|
-
after(:each) do
|
13
|
-
User.sorcery_config.reset!
|
14
|
-
end
|
15
|
-
|
16
|
-
context "API" do
|
17
|
-
before(:all) do
|
18
|
-
create_new_user
|
19
|
-
end
|
20
|
-
|
21
|
-
specify { @user.should respond_to(:deliver_reset_password_instructions!) }
|
22
|
-
|
23
|
-
specify { @user.should respond_to(:change_password!) }
|
24
|
-
|
25
|
-
it "should respond to .load_from_reset_password_token" do
|
26
|
-
User.should respond_to(:load_from_reset_password_token)
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
it "should allow configuration option 'reset_password_token_attribute_name'" do
|
31
|
-
sorcery_model_property_set(:reset_password_token_attribute_name, :my_code)
|
32
|
-
User.sorcery_config.reset_password_token_attribute_name.should equal(:my_code)
|
33
|
-
end
|
34
|
-
|
35
|
-
it "should allow configuration option 'reset_password_mailer'" do
|
36
|
-
sorcery_model_property_set(:reset_password_mailer, TestUser)
|
37
|
-
User.sorcery_config.reset_password_mailer.should equal(TestUser)
|
38
|
-
end
|
39
|
-
|
40
|
-
it "should allow configuration option 'reset_password_email_method_name'" do
|
41
|
-
sorcery_model_property_set(:reset_password_email_method_name, :my_mailer_method)
|
42
|
-
User.sorcery_config.reset_password_email_method_name.should equal(:my_mailer_method)
|
43
|
-
end
|
44
|
-
|
45
|
-
it "should allow configuration option 'reset_password_expiration_period'" do
|
46
|
-
sorcery_model_property_set(:reset_password_expiration_period, 16)
|
47
|
-
User.sorcery_config.reset_password_expiration_period.should equal(16)
|
48
|
-
end
|
49
|
-
|
50
|
-
it "should allow configuration option 'reset_password_email_sent_at_attribute_name'" do
|
51
|
-
sorcery_model_property_set(:reset_password_email_sent_at_attribute_name, :blabla)
|
52
|
-
User.sorcery_config.reset_password_email_sent_at_attribute_name.should equal(:blabla)
|
53
|
-
end
|
54
|
-
|
55
|
-
it "should allow configuration option 'reset_password_time_between_emails'" do
|
56
|
-
sorcery_model_property_set(:reset_password_time_between_emails, 16)
|
57
|
-
User.sorcery_config.reset_password_time_between_emails.should equal(16)
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
# ----------------- PLUGIN ACTIVATED -----------------------
|
62
|
-
describe User, "when activated with sorcery" do
|
63
|
-
|
64
|
-
before(:all) do
|
65
|
-
sorcery_reload!([:reset_password], :reset_password_mailer => ::SorceryMailer)
|
66
|
-
end
|
67
|
-
|
68
|
-
before(:each) do
|
69
|
-
User.delete_all
|
70
|
-
end
|
71
|
-
|
72
|
-
after(:each) do
|
73
|
-
Timecop.return
|
74
|
-
end
|
75
|
-
|
76
|
-
it "load_from_reset_password_token should return user when token is found" do
|
77
|
-
create_new_user
|
78
|
-
@user.deliver_reset_password_instructions!
|
79
|
-
User.load_from_reset_password_token(@user.reset_password_token).should == @user
|
80
|
-
end
|
81
|
-
|
82
|
-
it "load_from_reset_password_token should NOT return user when token is NOT found" do
|
83
|
-
create_new_user
|
84
|
-
@user.deliver_reset_password_instructions!
|
85
|
-
User.load_from_reset_password_token("a").should == nil
|
86
|
-
end
|
87
|
-
|
88
|
-
it "load_from_reset_password_token should return user when token is found and not expired" do
|
89
|
-
create_new_user
|
90
|
-
sorcery_model_property_set(:reset_password_expiration_period, 500)
|
91
|
-
@user.deliver_reset_password_instructions!
|
92
|
-
User.load_from_reset_password_token(@user.reset_password_token).should == @user
|
93
|
-
end
|
94
|
-
|
95
|
-
it "load_from_reset_password_token should NOT return user when token is found and expired" do
|
96
|
-
create_new_user
|
97
|
-
sorcery_model_property_set(:reset_password_expiration_period, 0.1)
|
98
|
-
@user.deliver_reset_password_instructions!
|
99
|
-
Timecop.travel(Time.now+0.5)
|
100
|
-
User.load_from_reset_password_token(@user.reset_password_token).should == nil
|
101
|
-
end
|
102
|
-
|
103
|
-
it "load_from_reset_password_token should always be valid if expiration period is nil" do
|
104
|
-
create_new_user
|
105
|
-
sorcery_model_property_set(:reset_password_expiration_period, nil)
|
106
|
-
@user.deliver_reset_password_instructions!
|
107
|
-
User.load_from_reset_password_token(@user.reset_password_token).should == @user
|
108
|
-
end
|
109
|
-
|
110
|
-
it "load_from_reset_password_token should return nil if token is blank" do
|
111
|
-
User.load_from_reset_password_token(nil).should == nil
|
112
|
-
User.load_from_reset_password_token("").should == nil
|
113
|
-
end
|
114
|
-
|
115
|
-
it "'deliver_reset_password_instructions!' should generate a reset_password_token" do
|
116
|
-
create_new_user
|
117
|
-
@user.reset_password_token.should be_nil
|
118
|
-
@user.deliver_reset_password_instructions!
|
119
|
-
@user.reset_password_token.should_not be_nil
|
120
|
-
end
|
121
|
-
|
122
|
-
it "the reset_password_token should be random" do
|
123
|
-
create_new_user
|
124
|
-
sorcery_model_property_set(:reset_password_time_between_emails, 0)
|
125
|
-
@user.deliver_reset_password_instructions!
|
126
|
-
old_password_code = @user.reset_password_token
|
127
|
-
@user.deliver_reset_password_instructions!
|
128
|
-
@user.reset_password_token.should_not == old_password_code
|
129
|
-
end
|
130
|
-
|
131
|
-
it "should send an email on reset" do
|
132
|
-
create_new_user
|
133
|
-
old_size = ActionMailer::Base.deliveries.size
|
134
|
-
@user.deliver_reset_password_instructions!
|
135
|
-
ActionMailer::Base.deliveries.size.should == old_size + 1
|
136
|
-
end
|
137
|
-
|
138
|
-
it "when change_password! is called, should delete reset_password_token" do
|
139
|
-
create_new_user
|
140
|
-
@user.deliver_reset_password_instructions!
|
141
|
-
@user.reset_password_token.should_not be_nil
|
142
|
-
@user.change_password!("blabulsdf")
|
143
|
-
@user.save!
|
144
|
-
@user.reset_password_token.should be_nil
|
145
|
-
end
|
146
|
-
|
147
|
-
it "should not send an email if time between emails has not passed since last email" do
|
148
|
-
create_new_user
|
149
|
-
sorcery_model_property_set(:reset_password_time_between_emails, 10000)
|
150
|
-
old_size = ActionMailer::Base.deliveries.size
|
151
|
-
@user.deliver_reset_password_instructions!
|
152
|
-
ActionMailer::Base.deliveries.size.should == old_size + 1
|
153
|
-
@user.deliver_reset_password_instructions!
|
154
|
-
ActionMailer::Base.deliveries.size.should == old_size + 1
|
155
|
-
end
|
156
|
-
|
157
|
-
it "should send an email if time between emails has passed since last email" do
|
158
|
-
create_new_user
|
159
|
-
sorcery_model_property_set(:reset_password_time_between_emails, 0.5)
|
160
|
-
old_size = ActionMailer::Base.deliveries.size
|
161
|
-
@user.deliver_reset_password_instructions!
|
162
|
-
ActionMailer::Base.deliveries.size.should == old_size + 1
|
163
|
-
Timecop.travel(Time.now+0.5)
|
164
|
-
@user.deliver_reset_password_instructions!
|
165
|
-
ActionMailer::Base.deliveries.size.should == old_size + 2
|
166
|
-
end
|
167
|
-
|
168
|
-
it "should encrypt properly on reset" do
|
169
|
-
create_new_user
|
170
|
-
@user.deliver_reset_password_instructions!
|
171
|
-
@user.change_password!("blagu")
|
172
|
-
Sorcery::CryptoProviders::BCrypt.matches?(@user.crypted_password,"blagu",@user.salt).should be_true
|
173
|
-
end
|
174
|
-
|
175
|
-
it "if mailer is nil on activation, throw exception!" do
|
176
|
-
expect{sorcery_reload!([:reset_password])}.to raise_error(ArgumentError)
|
177
|
-
end
|
178
|
-
|
179
|
-
|
180
|
-
end
|
6
|
+
it_behaves_like "rails_3_reset_password_model"
|
181
7
|
|
182
8
|
end
|