sorcery 0.7.6 → 0.8.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/.travis.yml +3 -0
- data/Gemfile +9 -4
- data/Gemfile.lock +99 -58
- data/README.rdoc +33 -8
- data/Rakefile +6 -7
- data/VERSION +1 -1
- data/lib/generators/sorcery/install_generator.rb +9 -7
- data/lib/generators/sorcery/templates/initializer.rb +324 -127
- data/lib/generators/sorcery/templates/migration/brute_force_protection.rb +2 -0
- data/lib/sorcery/controller/submodules/brute_force_protection.rb +1 -2
- data/lib/sorcery/controller/submodules/external/protocols/oauth2.rb +2 -2
- data/lib/sorcery/controller/submodules/external/providers/facebook.rb +16 -4
- data/lib/sorcery/controller/submodules/external/providers/github.rb +6 -4
- data/lib/sorcery/controller/submodules/external/providers/google.rb +4 -4
- data/lib/sorcery/controller/submodules/external/providers/linkedin.rb +101 -0
- data/lib/sorcery/controller/submodules/external/providers/liveid.rb +1 -1
- data/lib/sorcery/controller/submodules/external/providers/vkontakte.rb +94 -0
- data/lib/sorcery/controller/submodules/external.rb +83 -15
- data/lib/sorcery/controller/submodules/http_basic_auth.rb +1 -1
- data/lib/sorcery/controller/submodules/remember_me.rb +11 -2
- data/lib/sorcery/controller.rb +14 -6
- data/lib/sorcery/crypto_providers/bcrypt.rb +1 -0
- data/lib/sorcery/model/adapters/active_record.rb +9 -4
- data/lib/sorcery/model/adapters/mongo_mapper.rb +16 -14
- data/lib/sorcery/model/adapters/mongoid.rb +12 -6
- data/lib/sorcery/model/submodules/brute_force_protection.rb +44 -13
- data/lib/sorcery/model/submodules/remember_me.rb +4 -6
- data/lib/sorcery/model/submodules/reset_password.rb +14 -7
- data/lib/sorcery/model/submodules/user_activation.rb +14 -6
- data/lib/sorcery/model.rb +40 -39
- data/lib/sorcery/railties/tasks.rake +2 -0
- data/lib/sorcery.rb +3 -1
- data/sorcery.gemspec +31 -141
- data/spec/Gemfile +1 -1
- data/spec/Gemfile.lock +20 -19
- data/spec/README.md +8 -8
- data/spec/rails3/Gemfile +1 -0
- data/spec/rails3/Gemfile.lock +27 -24
- data/spec/rails3/app/controllers/application_controller.rb +54 -0
- data/spec/rails3/app/mailers/sorcery_mailer.rb +7 -0
- data/spec/rails3/app/views/sorcery_mailer/send_unlock_token_email.text.erb +1 -0
- data/spec/rails3/db/migrate/brute_force_protection/20101224223626_add_brute_force_protection_to_users.rb +2 -0
- data/spec/rails3/spec/controller_activity_logging_spec.rb +3 -0
- data/spec/rails3/spec/controller_brute_force_protection_spec.rb +23 -1
- data/spec/rails3/spec/controller_oauth2_spec.rb +162 -24
- data/spec/rails3/spec/controller_oauth_spec.rb +111 -6
- data/spec/rails3/spec/controller_spec.rb +7 -0
- data/spec/rails3_mongo_mapper/Gemfile +2 -1
- data/spec/rails3_mongo_mapper/Gemfile.lock +37 -39
- data/spec/rails3_mongo_mapper/app/controllers/application_controller.rb +14 -0
- data/spec/rails3_mongo_mapper/spec/controller_spec.rb +7 -0
- data/spec/rails3_mongoid/Gemfile +1 -0
- data/spec/rails3_mongoid/Gemfile.lock +28 -25
- data/spec/rails3_mongoid/app/controllers/application_controller.rb +14 -0
- data/spec/rails3_mongoid/config/mongoid.yml +1 -1
- data/spec/rails3_mongoid/spec/controller_activity_logging_spec.rb +11 -11
- data/spec/rails3_mongoid/spec/controller_spec.rb +7 -0
- data/spec/shared_examples/controller_oauth2_shared_examples.rb +20 -1
- data/spec/shared_examples/controller_oauth_shared_examples.rb +18 -0
- data/spec/shared_examples/user_activation_shared_examples.rb +71 -41
- data/spec/shared_examples/user_reset_password_shared_examples.rb +76 -31
- data/spec/sorcery_crypto_providers_spec.rb +9 -0
- metadata +159 -246
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: ../../
|
|
3
3
|
specs:
|
|
4
|
-
sorcery (0.7.
|
|
4
|
+
sorcery (0.7.13)
|
|
5
5
|
bcrypt-ruby (~> 3.0.0)
|
|
6
6
|
oauth (~> 0.4.4)
|
|
7
|
-
|
|
8
|
-
oauth2 (~> 0.5.1)
|
|
9
|
-
oauth2 (~> 0.5.1)
|
|
7
|
+
oauth2 (~> 0.8.0)
|
|
10
8
|
|
|
11
9
|
GEM
|
|
12
10
|
remote: http://rubygems.org/
|
|
@@ -38,22 +36,23 @@ GEM
|
|
|
38
36
|
activemodel (= 3.0.3)
|
|
39
37
|
activesupport (= 3.0.3)
|
|
40
38
|
activesupport (3.0.3)
|
|
41
|
-
addressable (2.2.6)
|
|
42
39
|
archive-tar-minitar (0.5.2)
|
|
43
40
|
arel (2.0.10)
|
|
44
41
|
bcrypt-ruby (3.0.1)
|
|
45
|
-
bson (1.
|
|
46
|
-
bson_ext (1.
|
|
42
|
+
bson (1.6.0)
|
|
43
|
+
bson_ext (1.6.0)
|
|
44
|
+
bson (= 1.6.0)
|
|
47
45
|
builder (2.1.2)
|
|
48
|
-
columnize (0.3.
|
|
46
|
+
columnize (0.3.6)
|
|
49
47
|
diff-lcs (1.1.3)
|
|
50
48
|
erubis (2.6.6)
|
|
51
49
|
abstract (>= 1.0.0)
|
|
52
|
-
faraday (0.
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
rack (>= 1.1.0, < 2)
|
|
50
|
+
faraday (0.8.4)
|
|
51
|
+
multipart-post (~> 1.1)
|
|
52
|
+
httpauth (0.2.0)
|
|
56
53
|
i18n (0.6.0)
|
|
54
|
+
jwt (0.1.5)
|
|
55
|
+
multi_json (>= 1.0)
|
|
57
56
|
linecache19 (0.5.12)
|
|
58
57
|
ruby_core_source (>= 0.1.4)
|
|
59
58
|
mail (2.2.19)
|
|
@@ -62,20 +61,23 @@ GEM
|
|
|
62
61
|
mime-types (~> 1.16)
|
|
63
62
|
treetop (~> 1.4.8)
|
|
64
63
|
mime-types (1.17.2)
|
|
65
|
-
mongo (1.
|
|
66
|
-
bson (= 1.
|
|
67
|
-
mongoid (2.2.
|
|
68
|
-
activemodel (~> 3.0)
|
|
64
|
+
mongo (1.6.0)
|
|
65
|
+
bson (= 1.6.0)
|
|
66
|
+
mongoid (2.2.6)
|
|
67
|
+
activemodel (~> 3.0.0)
|
|
69
68
|
mongo (~> 1.3)
|
|
70
69
|
tzinfo (~> 0.3.22)
|
|
71
|
-
multi_json (1.0
|
|
72
|
-
multipart-post (1.1.
|
|
73
|
-
oauth (0.4.
|
|
74
|
-
oauth2 (0.
|
|
75
|
-
faraday (~> 0.
|
|
76
|
-
|
|
70
|
+
multi_json (1.1.0)
|
|
71
|
+
multipart-post (1.1.5)
|
|
72
|
+
oauth (0.4.7)
|
|
73
|
+
oauth2 (0.8.0)
|
|
74
|
+
faraday (~> 0.8)
|
|
75
|
+
httpauth (~> 0.1)
|
|
76
|
+
jwt (~> 0.1.4)
|
|
77
|
+
multi_json (~> 1.0)
|
|
78
|
+
rack (~> 1.2)
|
|
77
79
|
polyglot (0.3.3)
|
|
78
|
-
rack (1.2.
|
|
80
|
+
rack (1.2.5)
|
|
79
81
|
rack-mount (0.6.14)
|
|
80
82
|
rack (>= 1.0.0)
|
|
81
83
|
rack-test (0.5.7)
|
|
@@ -117,8 +119,8 @@ GEM
|
|
|
117
119
|
ruby-debug-base19 (>= 0.11.19)
|
|
118
120
|
ruby_core_source (0.1.5)
|
|
119
121
|
archive-tar-minitar (>= 0.5.2)
|
|
120
|
-
simplecov (0.
|
|
121
|
-
multi_json (~> 1.0
|
|
122
|
+
simplecov (0.6.1)
|
|
123
|
+
multi_json (~> 1.0)
|
|
122
124
|
simplecov-html (~> 0.5.3)
|
|
123
125
|
simplecov-html (0.5.3)
|
|
124
126
|
thor (0.14.6)
|
|
@@ -132,6 +134,7 @@ PLATFORMS
|
|
|
132
134
|
ruby
|
|
133
135
|
|
|
134
136
|
DEPENDENCIES
|
|
137
|
+
bcrypt-ruby (~> 3.0.0)
|
|
135
138
|
bson_ext (~> 1.3)
|
|
136
139
|
mongoid (~> 2.0)
|
|
137
140
|
rails (= 3.0.3)
|
|
@@ -106,6 +106,20 @@ class ApplicationController < ActionController::Base
|
|
|
106
106
|
end
|
|
107
107
|
end
|
|
108
108
|
|
|
109
|
+
def test_create_from_provider_with_block
|
|
110
|
+
provider = params[:provider]
|
|
111
|
+
login_from(provider)
|
|
112
|
+
@user = create_from(provider) do |user|
|
|
113
|
+
# check uniqueness of username
|
|
114
|
+
User.where(:username => user.username).empty?
|
|
115
|
+
end
|
|
116
|
+
if @user
|
|
117
|
+
redirect_to "bla", :notice => "Success!"
|
|
118
|
+
else
|
|
119
|
+
redirect_to "blu", :alert => "Failed!"
|
|
120
|
+
end
|
|
121
|
+
end
|
|
122
|
+
|
|
109
123
|
protected
|
|
110
124
|
|
|
111
125
|
|
|
@@ -23,28 +23,28 @@ describe ApplicationController do
|
|
|
23
23
|
end
|
|
24
24
|
|
|
25
25
|
it "should log login time on login" do
|
|
26
|
-
now = Time.now
|
|
26
|
+
now = Time.now.utc
|
|
27
27
|
login_user
|
|
28
28
|
@user.last_login_at.should_not be_nil
|
|
29
|
-
@user.last_login_at.to_s
|
|
30
|
-
@user.last_login_at.to_s
|
|
29
|
+
@user.last_login_at.utc.to_s.should >= now.utc.to_s
|
|
30
|
+
@user.last_login_at.utc.to_s.should <= (now.utc+2).to_s
|
|
31
31
|
end
|
|
32
32
|
|
|
33
33
|
it "should log logout time on logout" do
|
|
34
34
|
login_user
|
|
35
|
-
now = Time.now
|
|
35
|
+
now = Time.now.utc
|
|
36
36
|
logout_user
|
|
37
|
-
User.first.last_logout_at.should_not be_nil
|
|
38
|
-
User.first.last_logout_at.to_s
|
|
39
|
-
User.first.last_logout_at.to_s
|
|
37
|
+
User.first.last_logout_at.utc.should_not be_nil
|
|
38
|
+
User.first.last_logout_at.utc.to_s.should >= now.utc.to_s
|
|
39
|
+
User.first.last_logout_at.utc.to_s.should <= (now.utc+2).to_s
|
|
40
40
|
end
|
|
41
41
|
|
|
42
42
|
it "should log last activity time when logged in" do
|
|
43
43
|
login_user
|
|
44
|
-
now = Time.now
|
|
44
|
+
now = Time.now.utc
|
|
45
45
|
get :some_action
|
|
46
|
-
User.first.last_activity_at.
|
|
47
|
-
User.first.last_activity_at.
|
|
46
|
+
User.first.last_activity_at.utc.should >= now.utc
|
|
47
|
+
User.first.last_activity_at.utc.should <= (now.utc+2)
|
|
48
48
|
end
|
|
49
49
|
|
|
50
50
|
it "should update nothing but activity fields" do
|
|
@@ -102,4 +102,4 @@ describe ApplicationController do
|
|
|
102
102
|
@user.last_activity_at.should be_nil
|
|
103
103
|
end
|
|
104
104
|
end
|
|
105
|
-
end
|
|
105
|
+
end
|
|
@@ -152,6 +152,13 @@ describe ApplicationController do
|
|
|
152
152
|
response.should redirect_to("http://test.host/")
|
|
153
153
|
end
|
|
154
154
|
|
|
155
|
+
it "require_login before_filter should not save the url that the user originally wanted upon all non-get http methods" do
|
|
156
|
+
[:post, :put, :delete].each do |m|
|
|
157
|
+
self.send(m, :some_action)
|
|
158
|
+
session[:return_to_url].should be_nil
|
|
159
|
+
end
|
|
160
|
+
end
|
|
161
|
+
|
|
155
162
|
it "on successful login the user should be redirected to the url he originally wanted" do
|
|
156
163
|
session[:return_to_url] = "http://test.host/some_action"
|
|
157
164
|
post :test_return_to, :username => 'gizmo', :password => 'secret'
|
|
@@ -32,6 +32,25 @@ shared_examples_for "oauth2_controller" do
|
|
|
32
32
|
end.should change(User, :count).by(1)
|
|
33
33
|
User.first.username.should == "Noam Ben Ari"
|
|
34
34
|
User.first.created_at.should_not be_nil
|
|
35
|
-
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
describe "with a block" do
|
|
38
|
+
|
|
39
|
+
before(:each) do
|
|
40
|
+
user = User.new(:username => 'Noam Ben Ari')
|
|
41
|
+
user.save!(:validate => false)
|
|
42
|
+
user.authentications.create(:provider => 'twitter', :uid => '456')
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
it "should not create user" do
|
|
46
|
+
sorcery_model_property_set(:authentications_class, Authentication)
|
|
47
|
+
sorcery_controller_external_property_set(:facebook, :user_info_mapping, {:username => "name"})
|
|
48
|
+
lambda do
|
|
49
|
+
# test_create_from_provider_with_block in controller will check for uniqueness of username
|
|
50
|
+
get :test_create_from_provider_with_block, :provider => "facebook"
|
|
51
|
+
end.should_not change(User, :count)
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
end
|
|
36
55
|
end
|
|
37
56
|
end
|
|
@@ -33,5 +33,23 @@ shared_examples_for "oauth_controller" do
|
|
|
33
33
|
User.first.username.should == "coming soon to sorcery gem: twitter and facebook authentication support."
|
|
34
34
|
User.first.created_at.should_not be_nil
|
|
35
35
|
end
|
|
36
|
+
|
|
37
|
+
describe "with a block" do
|
|
38
|
+
|
|
39
|
+
before(:each) do
|
|
40
|
+
user = User.new(:username => 'nbenari')
|
|
41
|
+
user.save!(:validate => false)
|
|
42
|
+
user.authentications.create(:provider => 'github', :uid => '456')
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
it "should not create user" do
|
|
46
|
+
sorcery_model_property_set(:authentications_class, Authentication)
|
|
47
|
+
sorcery_controller_external_property_set(:twitter, :user_info_mapping, {:username => "screen_name"})
|
|
48
|
+
lambda do
|
|
49
|
+
get :test_create_from_provider_with_block, :provider => "twitter"
|
|
50
|
+
end.should_not change(User, :count)
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
end
|
|
36
54
|
end
|
|
37
55
|
end
|
|
@@ -34,9 +34,18 @@ shared_examples_for "rails_3_activation_model" do
|
|
|
34
34
|
sorcery_model_property_set(:activation_success_email_method_name, :my_activation_email)
|
|
35
35
|
User.sorcery_config.activation_success_email_method_name.should equal(:my_activation_email)
|
|
36
36
|
end
|
|
37
|
+
|
|
38
|
+
it "should enable configuration option 'activation_mailer_disabled'" do
|
|
39
|
+
sorcery_model_property_set(:activation_mailer_disabled, :my_activation_mailer_disabled)
|
|
40
|
+
User.sorcery_config.activation_mailer_disabled.should equal(:my_activation_mailer_disabled)
|
|
41
|
+
end
|
|
37
42
|
|
|
38
|
-
it "if mailer is nil
|
|
39
|
-
expect{sorcery_reload!([:user_activation])}.to raise_error(ArgumentError)
|
|
43
|
+
it "if mailer is nil and mailer is enabled, throw exception!" do
|
|
44
|
+
expect{sorcery_reload!([:user_activation], :activation_mailer_disabled => false)}.to raise_error(ArgumentError)
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
it "if mailer is disabled and mailer is nil, do NOT throw exception" do
|
|
48
|
+
expect{sorcery_reload!([:user_activation], :activation_mailer_disabled => true)}.to_not raise_error
|
|
40
49
|
end
|
|
41
50
|
end
|
|
42
51
|
|
|
@@ -64,46 +73,67 @@ shared_examples_for "rails_3_activation_model" do
|
|
|
64
73
|
@user2.activation_state.should == "active"
|
|
65
74
|
User.find_by_activation_token(activation_token).should be_nil
|
|
66
75
|
end
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
context "mailer is enabled" do
|
|
79
|
+
it "should send the user an activation email" do
|
|
80
|
+
old_size = ActionMailer::Base.deliveries.size
|
|
81
|
+
create_new_user
|
|
82
|
+
ActionMailer::Base.deliveries.size.should == old_size + 1
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
it "subsequent saves do not send activation email" do
|
|
86
|
+
old_size = ActionMailer::Base.deliveries.size
|
|
87
|
+
@user.username = "Shauli"
|
|
88
|
+
@user.save!
|
|
89
|
+
ActionMailer::Base.deliveries.size.should == old_size
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
it "should send the user an activation success email on successful activation" do
|
|
93
|
+
old_size = ActionMailer::Base.deliveries.size
|
|
94
|
+
@user.activate!
|
|
95
|
+
ActionMailer::Base.deliveries.size.should == old_size + 1
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
it "subsequent saves do not send activation success email" do
|
|
99
|
+
@user.activate!
|
|
100
|
+
old_size = ActionMailer::Base.deliveries.size
|
|
101
|
+
@user.username = "Shauli"
|
|
102
|
+
@user.save!
|
|
103
|
+
ActionMailer::Base.deliveries.size.should == old_size
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
it "activation needed email is optional" do
|
|
107
|
+
sorcery_model_property_set(:activation_needed_email_method_name, nil)
|
|
108
|
+
old_size = ActionMailer::Base.deliveries.size
|
|
109
|
+
create_new_user
|
|
110
|
+
ActionMailer::Base.deliveries.size.should == old_size
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
it "activation success email is optional" do
|
|
114
|
+
sorcery_model_property_set(:activation_success_email_method_name, nil)
|
|
115
|
+
old_size = ActionMailer::Base.deliveries.size
|
|
116
|
+
@user.activate!
|
|
117
|
+
ActionMailer::Base.deliveries.size.should == old_size
|
|
118
|
+
end
|
|
100
119
|
end
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
120
|
+
|
|
121
|
+
context "mailer has been disabled" do
|
|
122
|
+
before(:each) do
|
|
123
|
+
sorcery_reload!([:user_activation], :activation_mailer_disabled => true, :user_activation_mailer => ::SorceryMailer)
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
it "should not send the user an activation email" do
|
|
127
|
+
old_size = ActionMailer::Base.deliveries.size
|
|
128
|
+
create_new_user
|
|
129
|
+
ActionMailer::Base.deliveries.size.should == old_size
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
it "should not send the user an activation success email on successful activation" do
|
|
133
|
+
old_size = ActionMailer::Base.deliveries.size
|
|
134
|
+
@user.activate!
|
|
135
|
+
ActionMailer::Base.deliveries.size.should == old_size
|
|
136
|
+
end
|
|
107
137
|
end
|
|
108
138
|
end
|
|
109
139
|
|
|
@@ -33,7 +33,20 @@ shared_examples_for "rails_3_reset_password_model" do
|
|
|
33
33
|
sorcery_model_property_set(:reset_password_mailer, TestUser)
|
|
34
34
|
User.sorcery_config.reset_password_mailer.should equal(TestUser)
|
|
35
35
|
end
|
|
36
|
+
|
|
37
|
+
it "should enable configuration option 'reset_password_mailer_disabled'" do
|
|
38
|
+
sorcery_model_property_set(:reset_password_mailer_disabled, :my_reset_password_mailer_disabled)
|
|
39
|
+
User.sorcery_config.reset_password_mailer_disabled.should equal(:my_reset_password_mailer_disabled)
|
|
40
|
+
end
|
|
36
41
|
|
|
42
|
+
it "if mailer is nil and mailer is enabled, throw exception!" do
|
|
43
|
+
expect{sorcery_reload!([:reset_password], :reset_password_mailer_disabled => false)}.to raise_error(ArgumentError)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
it "if mailer is disabled and mailer is nil, do NOT throw exception" do
|
|
47
|
+
expect{sorcery_reload!([:reset_password], :reset_password_mailer_disabled => true)}.to_not raise_error
|
|
48
|
+
end
|
|
49
|
+
|
|
37
50
|
it "should allow configuration option 'reset_password_email_method_name'" do
|
|
38
51
|
sorcery_model_property_set(:reset_password_email_method_name, :my_mailer_method)
|
|
39
52
|
User.sorcery_config.reset_password_email_method_name.should equal(:my_mailer_method)
|
|
@@ -125,11 +138,69 @@ shared_examples_for "rails_3_reset_password_model" do
|
|
|
125
138
|
@user.reset_password_token.should_not == old_password_code
|
|
126
139
|
end
|
|
127
140
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
141
|
+
context "mailer is enabled" do
|
|
142
|
+
it "should send an email on reset" do
|
|
143
|
+
create_new_user
|
|
144
|
+
old_size = ActionMailer::Base.deliveries.size
|
|
145
|
+
@user.deliver_reset_password_instructions!
|
|
146
|
+
ActionMailer::Base.deliveries.size.should == old_size + 1
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
it "should not send an email if time between emails has not passed since last email" do
|
|
150
|
+
create_new_user
|
|
151
|
+
sorcery_model_property_set(:reset_password_time_between_emails, 10000)
|
|
152
|
+
old_size = ActionMailer::Base.deliveries.size
|
|
153
|
+
@user.deliver_reset_password_instructions!
|
|
154
|
+
ActionMailer::Base.deliveries.size.should == old_size + 1
|
|
155
|
+
@user.deliver_reset_password_instructions!
|
|
156
|
+
ActionMailer::Base.deliveries.size.should == old_size + 1
|
|
157
|
+
end
|
|
158
|
+
|
|
159
|
+
it "should send an email if time between emails has passed since last email" do
|
|
160
|
+
create_new_user
|
|
161
|
+
sorcery_model_property_set(:reset_password_time_between_emails, 0.5)
|
|
162
|
+
old_size = ActionMailer::Base.deliveries.size
|
|
163
|
+
@user.deliver_reset_password_instructions!
|
|
164
|
+
ActionMailer::Base.deliveries.size.should == old_size + 1
|
|
165
|
+
Timecop.travel(Time.now.in_time_zone+0.5)
|
|
166
|
+
@user.deliver_reset_password_instructions!
|
|
167
|
+
ActionMailer::Base.deliveries.size.should == old_size + 2
|
|
168
|
+
end
|
|
169
|
+
end
|
|
170
|
+
|
|
171
|
+
context "mailer is disabled" do
|
|
172
|
+
|
|
173
|
+
before(:all) do
|
|
174
|
+
sorcery_reload!([:reset_password], :reset_password_mailer_disabled => true, :reset_password_mailer => ::SorceryMailer)
|
|
175
|
+
end
|
|
176
|
+
|
|
177
|
+
it "should send an email on reset" do
|
|
178
|
+
create_new_user
|
|
179
|
+
old_size = ActionMailer::Base.deliveries.size
|
|
180
|
+
@user.deliver_reset_password_instructions!
|
|
181
|
+
ActionMailer::Base.deliveries.size.should == old_size
|
|
182
|
+
end
|
|
183
|
+
|
|
184
|
+
it "should not send an email if time between emails has not passed since last email" do
|
|
185
|
+
create_new_user
|
|
186
|
+
sorcery_model_property_set(:reset_password_time_between_emails, 10000)
|
|
187
|
+
old_size = ActionMailer::Base.deliveries.size
|
|
188
|
+
@user.deliver_reset_password_instructions!
|
|
189
|
+
ActionMailer::Base.deliveries.size.should == old_size
|
|
190
|
+
@user.deliver_reset_password_instructions!
|
|
191
|
+
ActionMailer::Base.deliveries.size.should == old_size
|
|
192
|
+
end
|
|
193
|
+
|
|
194
|
+
it "should send an email if time between emails has passed since last email" do
|
|
195
|
+
create_new_user
|
|
196
|
+
sorcery_model_property_set(:reset_password_time_between_emails, 0.5)
|
|
197
|
+
old_size = ActionMailer::Base.deliveries.size
|
|
198
|
+
@user.deliver_reset_password_instructions!
|
|
199
|
+
ActionMailer::Base.deliveries.size.should == old_size
|
|
200
|
+
Timecop.travel(Time.now.in_time_zone+0.5)
|
|
201
|
+
@user.deliver_reset_password_instructions!
|
|
202
|
+
ActionMailer::Base.deliveries.size.should == old_size
|
|
203
|
+
end
|
|
133
204
|
end
|
|
134
205
|
|
|
135
206
|
it "when change_password! is called, should delete reset_password_token" do
|
|
@@ -140,35 +211,13 @@ shared_examples_for "rails_3_reset_password_model" do
|
|
|
140
211
|
@user.save!
|
|
141
212
|
@user.reset_password_token.should be_nil
|
|
142
213
|
end
|
|
143
|
-
|
|
144
|
-
it "should not send an email if time between emails has not passed since last email" do
|
|
145
|
-
create_new_user
|
|
146
|
-
sorcery_model_property_set(:reset_password_time_between_emails, 10000)
|
|
147
|
-
old_size = ActionMailer::Base.deliveries.size
|
|
148
|
-
@user.deliver_reset_password_instructions!
|
|
149
|
-
ActionMailer::Base.deliveries.size.should == old_size + 1
|
|
150
|
-
@user.deliver_reset_password_instructions!
|
|
151
|
-
ActionMailer::Base.deliveries.size.should == old_size + 1
|
|
152
|
-
end
|
|
153
214
|
|
|
154
215
|
it "should return false if time between emails has not passed since last email" do
|
|
155
216
|
create_new_user
|
|
156
217
|
sorcery_model_property_set(:reset_password_time_between_emails, 10000)
|
|
157
|
-
old_size = ActionMailer::Base.deliveries.size
|
|
158
218
|
@user.deliver_reset_password_instructions!
|
|
159
219
|
@user.deliver_reset_password_instructions!.should == false
|
|
160
220
|
end
|
|
161
|
-
|
|
162
|
-
it "should send an email if time between emails has passed since last email" do
|
|
163
|
-
create_new_user
|
|
164
|
-
sorcery_model_property_set(:reset_password_time_between_emails, 0.5)
|
|
165
|
-
old_size = ActionMailer::Base.deliveries.size
|
|
166
|
-
@user.deliver_reset_password_instructions!
|
|
167
|
-
ActionMailer::Base.deliveries.size.should == old_size + 1
|
|
168
|
-
Timecop.travel(Time.now.in_time_zone+0.5)
|
|
169
|
-
@user.deliver_reset_password_instructions!
|
|
170
|
-
ActionMailer::Base.deliveries.size.should == old_size + 2
|
|
171
|
-
end
|
|
172
221
|
|
|
173
222
|
it "should encrypt properly on reset" do
|
|
174
223
|
create_new_user
|
|
@@ -177,9 +226,5 @@ shared_examples_for "rails_3_reset_password_model" do
|
|
|
177
226
|
Sorcery::CryptoProviders::BCrypt.matches?(@user.crypted_password,"blagu",@user.salt).should be_true
|
|
178
227
|
end
|
|
179
228
|
|
|
180
|
-
it "if mailer is nil on activation, throw exception!" do
|
|
181
|
-
expect{sorcery_reload!([:reset_password])}.to raise_error(ArgumentError)
|
|
182
|
-
end
|
|
183
|
-
|
|
184
229
|
end
|
|
185
230
|
end
|
|
@@ -181,6 +181,15 @@ describe "Crypto Providers wrappers" do
|
|
|
181
181
|
it "matches? returns false when no match" do
|
|
182
182
|
Sorcery::CryptoProviders::BCrypt.matches?(@digest, 'Some Dude').should be_false
|
|
183
183
|
end
|
|
184
|
+
|
|
185
|
+
it "respond_to?(:stretches) returns true" do
|
|
186
|
+
Sorcery::CryptoProviders::BCrypt.respond_to?(:stretches).should be_true
|
|
187
|
+
end
|
|
188
|
+
|
|
189
|
+
it "sets cost when stretches is set" do
|
|
190
|
+
Sorcery::CryptoProviders::BCrypt.stretches = 4
|
|
191
|
+
Sorcery::CryptoProviders::BCrypt.cost.should == 4
|
|
192
|
+
end
|
|
184
193
|
|
|
185
194
|
end
|
|
186
195
|
|