sorcery 0.8.5 → 0.8.6
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.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.travis.yml +60 -4
- data/CHANGELOG.md +15 -1
- data/Gemfile +9 -18
- data/Gemfile.rails4 +8 -10
- data/README.md +31 -11
- data/VERSION +1 -1
- data/gemfiles/active_record-rails41.gemfile +6 -0
- data/gemfiles/mongo_mapper-rails41.gemfile +8 -0
- data/gemfiles/mongoid-rails41.gemfile +11 -0
- data/lib/sorcery.rb +20 -28
- data/lib/sorcery/controller.rb +6 -11
- data/lib/sorcery/controller/submodules/external.rb +30 -15
- data/lib/sorcery/controller/submodules/session_timeout.rb +1 -1
- data/lib/sorcery/model.rb +102 -70
- data/lib/sorcery/model/adapters/active_record.rb +7 -2
- data/lib/sorcery/model/adapters/datamapper.rb +123 -0
- data/lib/sorcery/model/adapters/mongo_mapper.rb +8 -4
- data/lib/sorcery/model/adapters/mongoid.rb +6 -6
- data/lib/sorcery/model/submodules/activity_logging.rb +24 -0
- data/lib/sorcery/model/submodules/brute_force_protection.rb +16 -0
- data/lib/sorcery/model/submodules/remember_me.rb +19 -4
- data/lib/sorcery/model/submodules/reset_password.rb +30 -13
- data/lib/sorcery/model/submodules/user_activation.rb +53 -22
- data/lib/sorcery/{controller/submodules/external/protocols → protocols}/certs/ca-bundle.crt +0 -0
- data/lib/sorcery/protocols/oauth.rb +42 -0
- data/lib/sorcery/protocols/oauth2.rb +47 -0
- data/lib/sorcery/providers/base.rb +27 -0
- data/lib/sorcery/providers/facebook.rb +63 -0
- data/lib/sorcery/providers/github.rb +51 -0
- data/lib/sorcery/providers/google.rb +51 -0
- data/lib/sorcery/providers/linkedin.rb +66 -0
- data/lib/sorcery/providers/liveid.rb +53 -0
- data/lib/sorcery/providers/twitter.rb +59 -0
- data/lib/sorcery/providers/vk.rb +61 -0
- data/lib/sorcery/providers/xing.rb +64 -0
- data/lib/sorcery/test_helpers/internal.rb +3 -3
- data/lib/sorcery/test_helpers/internal/rails.rb +14 -3
- data/lib/sorcery/test_helpers/rails.rb +1 -10
- data/lib/sorcery/test_helpers/rails/controller.rb +17 -0
- data/lib/sorcery/test_helpers/rails/integration.rb +26 -0
- data/sorcery.gemspec +14 -18
- data/spec/active_record/controller_activity_logging_spec.rb +5 -116
- data/spec/active_record/controller_brute_force_protection_spec.rb +69 -47
- data/spec/active_record/controller_http_basic_auth_spec.rb +24 -18
- data/spec/active_record/controller_oauth2_spec.rb +112 -187
- data/spec/active_record/controller_oauth_spec.rb +41 -37
- data/spec/active_record/controller_remember_me_spec.rb +39 -38
- data/spec/active_record/controller_session_timeout_spec.rb +31 -16
- data/spec/active_record/controller_spec.rb +4 -178
- data/spec/active_record/integration_spec.rb +1 -1
- data/spec/active_record/user_activation_spec.rb +1 -1
- data/spec/active_record/user_activity_logging_spec.rb +1 -1
- data/spec/active_record/user_brute_force_protection_spec.rb +1 -1
- data/spec/active_record/user_oauth_spec.rb +1 -1
- data/spec/active_record/user_remember_me_spec.rb +1 -1
- data/spec/active_record/user_reset_password_spec.rb +1 -1
- data/spec/active_record/user_spec.rb +7 -8
- data/spec/datamapper/controller_activity_logging_spec.rb +17 -0
- data/spec/datamapper/controller_spec.rb +8 -0
- data/spec/datamapper/user_activation_spec.rb +10 -0
- data/spec/datamapper/user_activity_logging_spec.rb +9 -0
- data/spec/datamapper/user_brute_force_protection_spec.rb +9 -0
- data/spec/datamapper/user_oauth_spec.rb +9 -0
- data/spec/datamapper/user_remember_me_spec.rb +8 -0
- data/spec/datamapper/user_reset_password_spec.rb +8 -0
- data/spec/datamapper/user_spec.rb +27 -0
- data/spec/mongo_mapper/controller_spec.rb +4 -171
- data/spec/mongo_mapper/user_activation_spec.rb +1 -2
- data/spec/mongo_mapper/user_activity_logging_spec.rb +1 -1
- data/spec/mongo_mapper/user_brute_force_protection_spec.rb +1 -1
- data/spec/mongo_mapper/user_oauth_spec.rb +1 -1
- data/spec/mongo_mapper/user_remember_me_spec.rb +1 -1
- data/spec/mongo_mapper/user_reset_password_spec.rb +1 -1
- data/spec/mongo_mapper/user_spec.rb +7 -8
- data/spec/mongoid/controller_activity_logging_spec.rb +4 -99
- data/spec/mongoid/controller_spec.rb +4 -182
- data/spec/mongoid/user_activation_spec.rb +1 -2
- data/spec/mongoid/user_activity_logging_spec.rb +1 -2
- data/spec/mongoid/user_brute_force_protection_spec.rb +1 -2
- data/spec/mongoid/user_oauth_spec.rb +1 -2
- data/spec/mongoid/user_remember_me_spec.rb +1 -2
- data/spec/mongoid/user_reset_password_spec.rb +1 -2
- data/spec/mongoid/user_spec.rb +8 -9
- data/spec/orm/active_record.rb +2 -0
- data/spec/orm/datamapper.rb +34 -0
- data/spec/orm/mongo_mapper.rb +1 -0
- data/spec/orm/mongoid.rb +1 -0
- data/spec/rails_app/app/controllers/sorcery_controller.rb +64 -59
- data/spec/rails_app/app/datamapper/authentication.rb +8 -0
- data/spec/rails_app/app/datamapper/user.rb +7 -0
- data/spec/rails_app/config/routes.rb +18 -13
- data/spec/shared_examples/controller_activity_logging_shared_examples.rb +125 -0
- data/spec/shared_examples/controller_oauth2_shared_examples.rb +32 -36
- data/spec/shared_examples/controller_oauth_shared_examples.rb +19 -26
- data/spec/shared_examples/controller_shared_examples.rb +203 -0
- data/spec/shared_examples/user_activation_shared_examples.rb +107 -90
- data/spec/shared_examples/user_activity_logging_shared_examples.rb +10 -10
- data/spec/shared_examples/user_brute_force_protection_shared_examples.rb +14 -13
- data/spec/shared_examples/user_oauth_shared_examples.rb +23 -15
- data/spec/shared_examples/user_remember_me_shared_examples.rb +32 -23
- data/spec/shared_examples/user_reset_password_shared_examples.rb +136 -115
- data/spec/shared_examples/user_shared_examples.rb +206 -146
- data/spec/sorcery_crypto_providers_spec.rb +28 -28
- data/spec/spec_helper.rb +15 -6
- metadata +83 -127
- data/lib/sorcery/controller/submodules/external/protocols/oauth1.rb +0 -46
- data/lib/sorcery/controller/submodules/external/protocols/oauth2.rb +0 -50
- data/lib/sorcery/controller/submodules/external/providers/base.rb +0 -21
- data/lib/sorcery/controller/submodules/external/providers/facebook.rb +0 -99
- data/lib/sorcery/controller/submodules/external/providers/github.rb +0 -93
- data/lib/sorcery/controller/submodules/external/providers/google.rb +0 -92
- data/lib/sorcery/controller/submodules/external/providers/linkedin.rb +0 -103
- data/lib/sorcery/controller/submodules/external/providers/liveid.rb +0 -93
- data/lib/sorcery/controller/submodules/external/providers/twitter.rb +0 -94
- data/lib/sorcery/controller/submodules/external/providers/vk.rb +0 -101
- data/lib/sorcery/controller/submodules/external/providers/xing.rb +0 -98
- data/lib/sorcery/test_helpers.rb +0 -5
@@ -1,6 +1,5 @@
|
|
1
1
|
shared_examples_for "rails_3_activity_logging_model" do
|
2
|
-
|
3
|
-
describe User, "loaded plugin configuration" do
|
2
|
+
context "loaded plugin configuration" do
|
4
3
|
before(:all) do
|
5
4
|
sorcery_reload!([:activity_logging])
|
6
5
|
end
|
@@ -9,24 +8,25 @@ shared_examples_for "rails_3_activity_logging_model" do
|
|
9
8
|
User.sorcery_config.reset!
|
10
9
|
end
|
11
10
|
|
12
|
-
it "
|
11
|
+
it "allows configuration option 'last_login_at_attribute_name'" do
|
13
12
|
sorcery_model_property_set(:last_login_at_attribute_name, :login_time)
|
14
|
-
|
13
|
+
|
14
|
+
expect(User.sorcery_config.last_login_at_attribute_name).to eq :login_time
|
15
15
|
end
|
16
16
|
|
17
|
-
it "
|
17
|
+
it "allows configuration option 'last_logout_at_attribute_name'" do
|
18
18
|
sorcery_model_property_set(:last_logout_at_attribute_name, :logout_time)
|
19
|
-
User.sorcery_config.last_logout_at_attribute_name.
|
19
|
+
expect(User.sorcery_config.last_logout_at_attribute_name).to eq :logout_time
|
20
20
|
end
|
21
21
|
|
22
|
-
it "
|
22
|
+
it "allows configuration option 'last_activity_at_attribute_name'" do
|
23
23
|
sorcery_model_property_set(:last_activity_at_attribute_name, :activity_time)
|
24
|
-
User.sorcery_config.last_activity_at_attribute_name.
|
24
|
+
expect(User.sorcery_config.last_activity_at_attribute_name).to eq :activity_time
|
25
25
|
end
|
26
26
|
|
27
|
-
it "
|
27
|
+
it "allows configuration option 'last_login_from_ip_adress'" do
|
28
28
|
sorcery_model_property_set(:last_login_from_ip_address_name, :ip_address)
|
29
|
-
User.sorcery_config.last_login_from_ip_address_name.
|
29
|
+
expect(User.sorcery_config.last_login_from_ip_address_name).to eq :ip_address
|
30
30
|
end
|
31
31
|
end
|
32
32
|
end
|
@@ -1,37 +1,38 @@
|
|
1
1
|
shared_examples_for "rails_3_brute_force_protection_model" do
|
2
|
-
|
3
|
-
|
2
|
+
context "loaded plugin configuration" do
|
3
|
+
|
4
|
+
let(:config) { User.sorcery_config }
|
5
|
+
let(:user) { create_new_user }
|
4
6
|
|
5
7
|
before(:all) do
|
6
8
|
sorcery_reload!([:brute_force_protection])
|
7
|
-
create_new_user
|
8
9
|
end
|
9
10
|
|
10
11
|
after(:each) do
|
11
12
|
User.sorcery_config.reset!
|
12
13
|
end
|
13
14
|
|
14
|
-
specify {
|
15
|
-
specify {
|
15
|
+
specify { expect(user).to respond_to(:failed_logins_count) }
|
16
|
+
specify { expect(user).to respond_to(:lock_expires_at) }
|
16
17
|
|
17
|
-
it "
|
18
|
+
it "enables configuration option 'failed_logins_count_attribute_name'" do
|
18
19
|
sorcery_model_property_set(:failed_logins_count_attribute_name, :my_count)
|
19
|
-
|
20
|
+
expect(config.failed_logins_count_attribute_name).to eq :my_count
|
20
21
|
end
|
21
22
|
|
22
|
-
it "
|
23
|
+
it "enables configuration option 'lock_expires_at_attribute_name'" do
|
23
24
|
sorcery_model_property_set(:lock_expires_at_attribute_name, :expires)
|
24
|
-
|
25
|
+
expect(config.lock_expires_at_attribute_name).to eq :expires
|
25
26
|
end
|
26
27
|
|
27
|
-
it "
|
28
|
+
it "enables configuration option 'consecutive_login_retries_amount_allowed'" do
|
28
29
|
sorcery_model_property_set(:consecutive_login_retries_amount_limit, 34)
|
29
|
-
|
30
|
+
expect(config.consecutive_login_retries_amount_limit).to eq 34
|
30
31
|
end
|
31
32
|
|
32
|
-
it "
|
33
|
+
it "enables configuration option 'login_lock_time_period'" do
|
33
34
|
sorcery_model_property_set(:login_lock_time_period, 2.hours)
|
34
|
-
|
35
|
+
expect(config.login_lock_time_period).to eq 2.hours
|
35
36
|
end
|
36
37
|
end
|
37
38
|
end
|
@@ -1,31 +1,39 @@
|
|
1
1
|
shared_examples_for "rails_3_oauth_model" do
|
2
2
|
# ----------------- PLUGIN CONFIGURATION -----------------------
|
3
|
-
|
4
|
-
|
3
|
+
|
4
|
+
let(:external_user) { create_new_external_user :twitter }
|
5
|
+
|
6
|
+
describe "loaded plugin configuration" do
|
7
|
+
|
5
8
|
before(:all) do
|
9
|
+
if defined?(DataMapper) && User.ancestors.include?(DataMapper::Resource)
|
10
|
+
Authentication.all.destroy
|
11
|
+
else
|
12
|
+
Authentication.delete_all
|
13
|
+
end
|
6
14
|
User.delete_all
|
7
|
-
Authentication.delete_all
|
8
15
|
sorcery_reload!([:external])
|
9
16
|
sorcery_controller_property_set(:external_providers, [:twitter])
|
10
17
|
sorcery_model_property_set(:authentications_class, Authentication)
|
11
18
|
sorcery_controller_external_property_set(:twitter, :key, "eYVNBjBDi33aa9GkA3w")
|
12
19
|
sorcery_controller_external_property_set(:twitter, :secret, "XpbeSdCoaKSmQGSeokz5qcUATClRW5u08QWNfv71N8")
|
13
20
|
sorcery_controller_external_property_set(:twitter, :callback_url, "http://blabla.com")
|
14
|
-
create_new_external_user(:twitter)
|
15
21
|
end
|
16
22
|
|
17
|
-
it "
|
18
|
-
User.
|
23
|
+
it "responds to 'load_from_provider'" do
|
24
|
+
expect(User).to respond_to(:load_from_provider)
|
19
25
|
end
|
20
|
-
|
21
|
-
it "'load_from_provider'
|
22
|
-
|
26
|
+
|
27
|
+
it "'load_from_provider' loads user if exists" do
|
28
|
+
external_user
|
29
|
+
expect(User.load_from_provider :twitter, 123).to eq external_user
|
23
30
|
end
|
24
|
-
|
25
|
-
it "'load_from_provider'
|
26
|
-
|
31
|
+
|
32
|
+
it "'load_from_provider' returns nil if user doesn't exist" do
|
33
|
+
external_user
|
34
|
+
expect(User.load_from_provider :twitter, 980342).to be_nil
|
27
35
|
end
|
28
|
-
|
36
|
+
|
29
37
|
end
|
30
|
-
|
31
|
-
end
|
38
|
+
|
39
|
+
end
|
@@ -1,48 +1,57 @@
|
|
1
1
|
shared_examples_for "rails_3_remember_me_model" do
|
2
|
-
|
3
|
-
|
2
|
+
let(:user) { create_new_user }
|
3
|
+
|
4
|
+
describe "loaded plugin configuration" do
|
5
|
+
|
4
6
|
before(:all) do
|
5
7
|
sorcery_reload!([:remember_me])
|
6
|
-
create_new_user
|
7
8
|
end
|
8
9
|
|
9
10
|
after(:each) do
|
10
11
|
User.sorcery_config.reset!
|
11
12
|
end
|
12
13
|
|
13
|
-
it "
|
14
|
+
it "allows configuration option 'remember_me_token_attribute_name'" do
|
14
15
|
sorcery_model_property_set(:remember_me_token_attribute_name, :my_token)
|
15
|
-
|
16
|
+
|
17
|
+
expect(User.sorcery_config.remember_me_token_attribute_name).to eq :my_token
|
16
18
|
end
|
17
19
|
|
18
|
-
it "
|
20
|
+
it "allows configuration option 'remember_me_token_expires_at_attribute_name'" do
|
19
21
|
sorcery_model_property_set(:remember_me_token_expires_at_attribute_name, :my_expires)
|
20
|
-
|
22
|
+
|
23
|
+
expect(User.sorcery_config.remember_me_token_expires_at_attribute_name).to eq :my_expires
|
21
24
|
end
|
22
25
|
|
23
|
-
specify {
|
24
|
-
|
25
|
-
specify {
|
26
|
+
specify { expect(user).to respond_to :remember_me! }
|
27
|
+
|
28
|
+
specify { expect(user).to respond_to :forget_me! }
|
26
29
|
|
27
|
-
it "
|
28
|
-
|
29
|
-
|
30
|
-
|
30
|
+
it "generates a new token on 'remember_me!'" do
|
31
|
+
expect(user.remember_me_token).to be_nil
|
32
|
+
|
33
|
+
user.remember_me!
|
34
|
+
|
35
|
+
expect(user.remember_me_token).not_to be_nil
|
31
36
|
end
|
32
37
|
|
33
38
|
# FIXME: assert on line 37 sometimes fails by a second
|
34
|
-
it "
|
39
|
+
it "sets an expiration based on 'remember_me_for' attribute" do
|
35
40
|
sorcery_model_property_set(:remember_me_for, 2 * 60 * 60 * 24)
|
36
|
-
|
37
|
-
|
41
|
+
user.remember_me!
|
42
|
+
|
43
|
+
expect(user.remember_me_token_expires_at.utc.to_s).to eq (Time.now.in_time_zone + 2 * 60 * 60 * 24).utc.to_s
|
38
44
|
end
|
39
45
|
|
40
|
-
it "
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
+
it "deletes the token and expiration on 'forget_me!'" do
|
47
|
+
user.remember_me!
|
48
|
+
|
49
|
+
expect(user.remember_me_token).not_to be_nil
|
50
|
+
|
51
|
+
user.forget_me!
|
52
|
+
|
53
|
+
expect(user.remember_me_token).to be_nil
|
54
|
+
expect(user.remember_me_token_expires_at).to be_nil
|
46
55
|
end
|
47
56
|
end
|
48
57
|
end
|
@@ -1,6 +1,8 @@
|
|
1
1
|
shared_examples_for "rails_3_reset_password_model" do
|
2
2
|
# ----------------- PLUGIN CONFIGURATION -----------------------
|
3
|
-
|
3
|
+
let(:user) { create_new_user }
|
4
|
+
|
5
|
+
describe "loaded plugin configuration" do
|
4
6
|
|
5
7
|
before(:all) do
|
6
8
|
sorcery_reload!([:reset_password], :reset_password_mailer => ::SorceryMailer)
|
@@ -11,32 +13,32 @@ shared_examples_for "rails_3_reset_password_model" do
|
|
11
13
|
end
|
12
14
|
|
13
15
|
context "API" do
|
14
|
-
before(:all) do
|
15
|
-
create_new_user
|
16
|
-
end
|
17
16
|
|
18
|
-
specify {
|
17
|
+
specify { expect(user).to respond_to :deliver_reset_password_instructions! }
|
19
18
|
|
20
|
-
specify {
|
19
|
+
specify { expect(user).to respond_to :change_password! }
|
21
20
|
|
22
|
-
it "
|
23
|
-
User.
|
21
|
+
it "responds to .load_from_reset_password_token" do
|
22
|
+
expect(User).to respond_to :load_from_reset_password_token
|
24
23
|
end
|
25
24
|
end
|
26
25
|
|
27
|
-
it "
|
26
|
+
it "allows configuration option 'reset_password_token_attribute_name'" do
|
28
27
|
sorcery_model_property_set(:reset_password_token_attribute_name, :my_code)
|
29
|
-
|
28
|
+
|
29
|
+
expect(User.sorcery_config.reset_password_token_attribute_name).to eq :my_code
|
30
30
|
end
|
31
31
|
|
32
|
-
it "
|
32
|
+
it "allows configuration option 'reset_password_mailer'" do
|
33
33
|
sorcery_model_property_set(:reset_password_mailer, TestUser)
|
34
|
-
|
34
|
+
|
35
|
+
expect(User.sorcery_config.reset_password_mailer).to eq TestUser
|
35
36
|
end
|
36
37
|
|
37
|
-
it "
|
38
|
+
it "enables configuration option 'reset_password_mailer_disabled'" do
|
38
39
|
sorcery_model_property_set(:reset_password_mailer_disabled, :my_reset_password_mailer_disabled)
|
39
|
-
|
40
|
+
|
41
|
+
expect(User.sorcery_config.reset_password_mailer_disabled).to eq :my_reset_password_mailer_disabled
|
40
42
|
end
|
41
43
|
|
42
44
|
it "if mailer is nil and mailer is enabled, throw exception!" do
|
@@ -47,29 +49,33 @@ shared_examples_for "rails_3_reset_password_model" do
|
|
47
49
|
expect{sorcery_reload!([:reset_password], :reset_password_mailer_disabled => true)}.to_not raise_error
|
48
50
|
end
|
49
51
|
|
50
|
-
it "
|
52
|
+
it "allows configuration option 'reset_password_email_method_name'" do
|
51
53
|
sorcery_model_property_set(:reset_password_email_method_name, :my_mailer_method)
|
52
|
-
|
54
|
+
|
55
|
+
expect(User.sorcery_config.reset_password_email_method_name).to eq :my_mailer_method
|
53
56
|
end
|
54
57
|
|
55
|
-
it "
|
58
|
+
it "allows configuration option 'reset_password_expiration_period'" do
|
56
59
|
sorcery_model_property_set(:reset_password_expiration_period, 16)
|
57
|
-
|
60
|
+
|
61
|
+
expect(User.sorcery_config.reset_password_expiration_period).to eq 16
|
58
62
|
end
|
59
63
|
|
60
|
-
it "
|
64
|
+
it "allows configuration option 'reset_password_email_sent_at_attribute_name'" do
|
61
65
|
sorcery_model_property_set(:reset_password_email_sent_at_attribute_name, :blabla)
|
62
|
-
|
66
|
+
|
67
|
+
expect(User.sorcery_config.reset_password_email_sent_at_attribute_name).to eq :blabla
|
63
68
|
end
|
64
69
|
|
65
|
-
it "
|
70
|
+
it "allows configuration option 'reset_password_time_between_emails'" do
|
66
71
|
sorcery_model_property_set(:reset_password_time_between_emails, 16)
|
67
|
-
|
72
|
+
|
73
|
+
expect(User.sorcery_config.reset_password_time_between_emails).to eq 16
|
68
74
|
end
|
69
75
|
end
|
70
76
|
|
71
|
-
|
72
|
-
describe
|
77
|
+
|
78
|
+
describe "when activated with sorcery" do
|
73
79
|
|
74
80
|
before(:all) do
|
75
81
|
sorcery_reload!([:reset_password], :reset_password_mailer => ::SorceryMailer)
|
@@ -77,100 +83,109 @@ shared_examples_for "rails_3_reset_password_model" do
|
|
77
83
|
|
78
84
|
before(:each) do
|
79
85
|
User.delete_all
|
86
|
+
user
|
80
87
|
end
|
81
88
|
|
82
89
|
after(:each) do
|
83
90
|
Timecop.return
|
84
91
|
end
|
85
92
|
|
86
|
-
it "load_from_reset_password_token
|
87
|
-
|
88
|
-
|
89
|
-
|
93
|
+
it "load_from_reset_password_token returns user when token is found" do
|
94
|
+
user.deliver_reset_password_instructions!
|
95
|
+
updated_user = defined?(DataMapper) && user.class.ancestors.include?(DataMapper::Resource) ? User.find(user.id) : user
|
96
|
+
|
97
|
+
expect(User.load_from_reset_password_token user.reset_password_token).to eq updated_user
|
90
98
|
end
|
91
99
|
|
92
|
-
it "load_from_reset_password_token
|
93
|
-
|
94
|
-
|
95
|
-
User.load_from_reset_password_token
|
100
|
+
it "load_from_reset_password_token does NOT return user when token is NOT found" do
|
101
|
+
user.deliver_reset_password_instructions!
|
102
|
+
|
103
|
+
expect(User.load_from_reset_password_token "a").to be_nil
|
96
104
|
end
|
97
105
|
|
98
|
-
it "load_from_reset_password_token
|
99
|
-
create_new_user
|
106
|
+
it "load_from_reset_password_token returns user when token is found and not expired" do
|
100
107
|
sorcery_model_property_set(:reset_password_expiration_period, 500)
|
101
|
-
|
102
|
-
User.
|
108
|
+
user.deliver_reset_password_instructions!
|
109
|
+
updated_user = defined?(DataMapper) && user.class.ancestors.include?(DataMapper::Resource) ? User.find(user.id) : user
|
110
|
+
|
111
|
+
expect(User.load_from_reset_password_token user.reset_password_token).to eq updated_user
|
103
112
|
end
|
104
113
|
|
105
|
-
it "load_from_reset_password_token
|
106
|
-
create_new_user
|
114
|
+
it "load_from_reset_password_token does NOT return user when token is found and expired" do
|
107
115
|
sorcery_model_property_set(:reset_password_expiration_period, 0.1)
|
108
|
-
|
116
|
+
user.deliver_reset_password_instructions!
|
109
117
|
Timecop.travel(Time.now.in_time_zone+0.5)
|
110
|
-
|
118
|
+
|
119
|
+
expect(User.load_from_reset_password_token user.reset_password_token).to be_nil
|
111
120
|
end
|
112
121
|
|
113
|
-
it "load_from_reset_password_token
|
114
|
-
create_new_user
|
122
|
+
it "load_from_reset_password_token is always valid if expiration period is nil" do
|
115
123
|
sorcery_model_property_set(:reset_password_expiration_period, nil)
|
116
|
-
|
117
|
-
User.
|
124
|
+
user.deliver_reset_password_instructions!
|
125
|
+
updated_user = defined?(DataMapper) && user.class.ancestors.include?(DataMapper::Resource) ? User.find(user.id) : user
|
126
|
+
|
127
|
+
expect(User.load_from_reset_password_token user.reset_password_token).to eq updated_user
|
118
128
|
end
|
119
129
|
|
120
|
-
it "load_from_reset_password_token
|
121
|
-
User.load_from_reset_password_token
|
122
|
-
User.load_from_reset_password_token
|
130
|
+
it "load_from_reset_password_token returns nil if token is blank" do
|
131
|
+
expect(User.load_from_reset_password_token nil).to be_nil
|
132
|
+
expect(User.load_from_reset_password_token "").to be_nil
|
123
133
|
end
|
124
134
|
|
125
|
-
it "'deliver_reset_password_instructions!'
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
135
|
+
it "'deliver_reset_password_instructions!' generates a reset_password_token" do
|
136
|
+
expect(user.reset_password_token).to be_nil
|
137
|
+
|
138
|
+
user.deliver_reset_password_instructions!
|
139
|
+
|
140
|
+
expect(user.reset_password_token).not_to be_nil
|
130
141
|
end
|
131
142
|
|
132
|
-
it "the reset_password_token
|
133
|
-
create_new_user
|
143
|
+
it "the reset_password_token is random" do
|
134
144
|
sorcery_model_property_set(:reset_password_time_between_emails, 0)
|
135
|
-
|
136
|
-
old_password_code =
|
137
|
-
|
138
|
-
|
145
|
+
user.deliver_reset_password_instructions!
|
146
|
+
old_password_code = user.reset_password_token
|
147
|
+
user.deliver_reset_password_instructions!
|
148
|
+
|
149
|
+
expect(user.reset_password_token).not_to eq old_password_code
|
139
150
|
end
|
140
151
|
|
141
152
|
context "mailer is enabled" do
|
142
|
-
it "
|
143
|
-
create_new_user
|
153
|
+
it "sends an email on reset" do
|
144
154
|
old_size = ActionMailer::Base.deliveries.size
|
145
|
-
|
146
|
-
|
155
|
+
user.deliver_reset_password_instructions!
|
156
|
+
|
157
|
+
expect(ActionMailer::Base.deliveries.size).to eq old_size + 1
|
147
158
|
end
|
148
159
|
|
149
|
-
it "
|
150
|
-
|
151
|
-
|
152
|
-
|
160
|
+
it "calls send_reset_password_email! on reset" do
|
161
|
+
expect(user).to receive(:send_reset_password_email!).once
|
162
|
+
|
163
|
+
user.deliver_reset_password_instructions!
|
153
164
|
end
|
154
165
|
|
155
|
-
it "
|
156
|
-
create_new_user
|
166
|
+
it "does not send an email if time between emails has not passed since last email" do
|
157
167
|
sorcery_model_property_set(:reset_password_time_between_emails, 10000)
|
158
168
|
old_size = ActionMailer::Base.deliveries.size
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
169
|
+
user.deliver_reset_password_instructions!
|
170
|
+
|
171
|
+
expect(ActionMailer::Base.deliveries.size).to eq old_size + 1
|
172
|
+
|
173
|
+
user.deliver_reset_password_instructions!
|
174
|
+
|
175
|
+
expect(ActionMailer::Base.deliveries.size).to eq old_size + 1
|
163
176
|
end
|
164
177
|
|
165
|
-
it "
|
166
|
-
create_new_user
|
178
|
+
it "sends an email if time between emails has passed since last email" do
|
167
179
|
sorcery_model_property_set(:reset_password_time_between_emails, 0.5)
|
168
180
|
old_size = ActionMailer::Base.deliveries.size
|
169
|
-
|
170
|
-
|
181
|
+
user.deliver_reset_password_instructions!
|
182
|
+
|
183
|
+
expect(ActionMailer::Base.deliveries.size).to eq old_size + 1
|
184
|
+
|
171
185
|
Timecop.travel(Time.now.in_time_zone+0.5)
|
172
|
-
|
173
|
-
|
186
|
+
user.deliver_reset_password_instructions!
|
187
|
+
|
188
|
+
expect(ActionMailer::Base.deliveries.size).to eq old_size + 2
|
174
189
|
end
|
175
190
|
end
|
176
191
|
|
@@ -180,62 +195,68 @@ shared_examples_for "rails_3_reset_password_model" do
|
|
180
195
|
sorcery_reload!([:reset_password], :reset_password_mailer_disabled => true, :reset_password_mailer => ::SorceryMailer)
|
181
196
|
end
|
182
197
|
|
183
|
-
it "
|
184
|
-
create_new_user
|
198
|
+
it "sends an email on reset" do
|
185
199
|
old_size = ActionMailer::Base.deliveries.size
|
186
|
-
|
187
|
-
|
200
|
+
user.deliver_reset_password_instructions!
|
201
|
+
|
202
|
+
expect(ActionMailer::Base.deliveries.size).to eq old_size
|
188
203
|
end
|
189
|
-
|
190
|
-
it "
|
191
|
-
|
192
|
-
|
193
|
-
|
204
|
+
|
205
|
+
it "does not call send_reset_password_email! on reset" do
|
206
|
+
expect(user).to receive(:send_reset_password_email!).never
|
207
|
+
|
208
|
+
user.deliver_reset_password_instructions!
|
194
209
|
end
|
195
210
|
|
196
|
-
it "
|
197
|
-
create_new_user
|
211
|
+
it "does not send an email if time between emails has not passed since last email" do
|
198
212
|
sorcery_model_property_set(:reset_password_time_between_emails, 10000)
|
199
213
|
old_size = ActionMailer::Base.deliveries.size
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
214
|
+
user.deliver_reset_password_instructions!
|
215
|
+
|
216
|
+
expect(ActionMailer::Base.deliveries.size).to eq old_size
|
217
|
+
|
218
|
+
user.deliver_reset_password_instructions!
|
219
|
+
|
220
|
+
expect(ActionMailer::Base.deliveries.size).to eq old_size
|
204
221
|
end
|
205
222
|
|
206
|
-
it "
|
207
|
-
create_new_user
|
223
|
+
it "sends an email if time between emails has passed since last email" do
|
208
224
|
sorcery_model_property_set(:reset_password_time_between_emails, 0.5)
|
209
225
|
old_size = ActionMailer::Base.deliveries.size
|
210
|
-
|
211
|
-
|
226
|
+
user.deliver_reset_password_instructions!
|
227
|
+
|
228
|
+
expect(ActionMailer::Base.deliveries.size).to eq old_size
|
229
|
+
|
212
230
|
Timecop.travel(Time.now.in_time_zone+0.5)
|
213
|
-
|
214
|
-
|
231
|
+
user.deliver_reset_password_instructions!
|
232
|
+
|
233
|
+
expect(ActionMailer::Base.deliveries.size).to eq old_size
|
215
234
|
end
|
216
235
|
end
|
217
236
|
|
218
|
-
it "when change_password! is called,
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
237
|
+
it "when change_password! is called, deletes reset_password_token" do
|
238
|
+
user.deliver_reset_password_instructions!
|
239
|
+
|
240
|
+
expect(user.reset_password_token).not_to be_nil
|
241
|
+
|
242
|
+
user.change_password!("blabulsdf")
|
243
|
+
user.save!
|
244
|
+
|
245
|
+
expect(user.reset_password_token).to be_nil
|
225
246
|
end
|
226
247
|
|
227
|
-
it "
|
228
|
-
create_new_user
|
248
|
+
it "returns false if time between emails has not passed since last email" do
|
229
249
|
sorcery_model_property_set(:reset_password_time_between_emails, 10000)
|
230
|
-
|
231
|
-
|
250
|
+
user.deliver_reset_password_instructions!
|
251
|
+
|
252
|
+
expect(user.deliver_reset_password_instructions!).to be false
|
232
253
|
end
|
233
254
|
|
234
|
-
it "
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
Sorcery::CryptoProviders::BCrypt.matches?
|
255
|
+
it "encrypts properly on reset" do
|
256
|
+
user.deliver_reset_password_instructions!
|
257
|
+
user.change_password!("blagu")
|
258
|
+
|
259
|
+
expect(Sorcery::CryptoProviders::BCrypt.matches? user.crypted_password, "blagu", user.salt).to be true
|
239
260
|
end
|
240
261
|
|
241
262
|
end
|