sorcery 0.9.0 → 0.10.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.
- checksums.yaml +4 -4
- data/.travis.yml +29 -104
- data/CHANGELOG.md +22 -1
- data/Gemfile +2 -16
- data/README.md +124 -271
- data/Rakefile +2 -2
- data/gemfiles/{mongoid-rails40.gemfile → active_record-rails42.gemfile} +1 -3
- data/lib/generators/sorcery/helpers.rb +4 -4
- data/lib/generators/sorcery/install_generator.rb +25 -19
- data/lib/generators/sorcery/templates/initializer.rb +29 -53
- data/lib/generators/sorcery/templates/migration/activity_logging.rb +2 -2
- data/lib/generators/sorcery/templates/migration/brute_force_protection.rb +1 -1
- data/lib/generators/sorcery/templates/migration/core.rb +3 -3
- data/lib/generators/sorcery/templates/migration/external.rb +3 -3
- data/lib/generators/sorcery/templates/migration/remember_me.rb +2 -2
- data/lib/generators/sorcery/templates/migration/reset_password.rb +2 -2
- data/lib/generators/sorcery/templates/migration/user_activation.rb +2 -2
- data/lib/sorcery/adapters/active_record_adapter.rb +7 -18
- data/lib/sorcery/controller/config.rb +20 -18
- data/lib/sorcery/controller/submodules/activity_logging.rb +7 -15
- data/lib/sorcery/controller/submodules/brute_force_protection.rb +1 -2
- data/lib/sorcery/controller/submodules/external.rb +23 -15
- data/lib/sorcery/controller/submodules/http_basic_auth.rb +16 -19
- data/lib/sorcery/controller/submodules/remember_me.rb +15 -10
- data/lib/sorcery/controller/submodules/session_timeout.rb +7 -8
- data/lib/sorcery/controller.rb +19 -21
- data/lib/sorcery/crypto_providers/aes256.rb +15 -15
- data/lib/sorcery/crypto_providers/bcrypt.rb +19 -21
- data/lib/sorcery/crypto_providers/common.rb +1 -1
- data/lib/sorcery/crypto_providers/md5.rb +5 -5
- data/lib/sorcery/crypto_providers/sha1.rb +5 -5
- data/lib/sorcery/crypto_providers/sha256.rb +2 -2
- data/lib/sorcery/crypto_providers/sha512.rb +3 -3
- data/lib/sorcery/engine.rb +3 -8
- data/lib/sorcery/model/config.rb +64 -49
- data/lib/sorcery/model/submodules/activity_logging.rb +31 -12
- data/lib/sorcery/model/submodules/brute_force_protection.rb +23 -23
- data/lib/sorcery/model/submodules/external.rb +3 -7
- data/lib/sorcery/model/submodules/remember_me.rb +19 -7
- data/lib/sorcery/model/submodules/reset_password.rb +32 -36
- data/lib/sorcery/model/submodules/user_activation.rb +38 -50
- data/lib/sorcery/model/temporary_token.rb +2 -2
- data/lib/sorcery/model.rb +27 -31
- data/lib/sorcery/protocols/oauth.rb +3 -9
- data/lib/sorcery/protocols/oauth2.rb +0 -2
- data/lib/sorcery/providers/base.rb +4 -4
- data/lib/sorcery/providers/facebook.rb +17 -9
- data/lib/sorcery/providers/github.rb +12 -5
- data/lib/sorcery/providers/google.rb +3 -5
- data/lib/sorcery/providers/heroku.rb +6 -8
- data/lib/sorcery/providers/jira.rb +12 -17
- data/lib/sorcery/providers/linkedin.rb +6 -8
- data/lib/sorcery/providers/liveid.rb +4 -7
- data/lib/sorcery/providers/paypal.rb +60 -0
- data/lib/sorcery/providers/salesforce.rb +3 -5
- data/lib/sorcery/providers/slack.rb +45 -0
- data/lib/sorcery/providers/twitter.rb +4 -6
- data/lib/sorcery/providers/vk.rb +3 -5
- data/lib/sorcery/providers/wechat.rb +79 -0
- data/lib/sorcery/providers/xing.rb +8 -11
- data/lib/sorcery/test_helpers/internal/rails.rb +16 -8
- data/lib/sorcery/test_helpers/internal.rb +10 -10
- data/lib/sorcery/test_helpers/rails/controller.rb +1 -1
- data/lib/sorcery/test_helpers/rails/integration.rb +5 -6
- data/lib/sorcery/version.rb +1 -1
- data/lib/sorcery.rb +0 -28
- data/sorcery.gemspec +25 -27
- data/spec/active_record/user_activation_spec.rb +2 -3
- data/spec/active_record/user_activity_logging_spec.rb +2 -4
- data/spec/active_record/user_brute_force_protection_spec.rb +3 -4
- data/spec/active_record/user_oauth_spec.rb +3 -4
- data/spec/active_record/user_remember_me_spec.rb +3 -4
- data/spec/active_record/user_reset_password_spec.rb +2 -3
- data/spec/active_record/user_spec.rb +7 -7
- data/spec/controllers/controller_activity_logging_spec.rb +13 -24
- data/spec/controllers/controller_brute_force_protection_spec.rb +6 -8
- data/spec/controllers/controller_http_basic_auth_spec.rb +19 -20
- data/spec/controllers/controller_oauth2_spec.rb +142 -102
- data/spec/controllers/controller_oauth_spec.rb +86 -66
- data/spec/controllers/controller_remember_me_spec.rb +35 -30
- data/spec/controllers/controller_session_timeout_spec.rb +14 -15
- data/spec/controllers/controller_spec.rb +77 -111
- data/spec/orm/active_record.rb +1 -1
- data/spec/rails_app/app/active_record/authentication.rb +1 -1
- data/spec/rails_app/app/active_record/user.rb +2 -2
- data/spec/rails_app/app/controllers/sorcery_controller.rb +89 -24
- data/spec/rails_app/app/mailers/sorcery_mailer.rb +16 -17
- data/spec/rails_app/config/application.rb +7 -7
- data/spec/rails_app/config/boot.rb +1 -1
- data/spec/rails_app/config/environments/test.rb +1 -1
- data/spec/rails_app/config/initializers/compatible_legacy_migration.rb +11 -0
- data/spec/rails_app/config/initializers/session_store.rb +3 -3
- data/spec/rails_app/config/routes.rb +11 -1
- data/spec/rails_app/config.ru +1 -1
- data/spec/rails_app/db/migrate/activation/20101224223622_add_activation_to_users.rb +4 -4
- data/spec/rails_app/db/migrate/activity_logging/20101224223624_add_activity_logging_to_users.rb +8 -8
- data/spec/rails_app/db/migrate/brute_force_protection/20101224223626_add_brute_force_protection_to_users.rb +5 -5
- data/spec/rails_app/db/migrate/core/20101224223620_create_users.rb +5 -5
- data/spec/rails_app/db/migrate/external/20101224223628_create_authentications_and_user_providers.rb +3 -3
- data/spec/rails_app/db/migrate/remember_me/20101224223623_add_remember_me_token_to_users.rb +6 -6
- data/spec/rails_app/db/migrate/reset_password/20101224223622_add_reset_password_to_users.rb +5 -5
- data/spec/shared_examples/user_activation_shared_examples.rb +99 -58
- data/spec/shared_examples/user_activity_logging_shared_examples.rb +47 -41
- data/spec/shared_examples/user_brute_force_protection_shared_examples.rb +19 -24
- data/spec/shared_examples/user_oauth_shared_examples.rb +7 -10
- data/spec/shared_examples/user_remember_me_shared_examples.rb +90 -21
- data/spec/shared_examples/user_reset_password_shared_examples.rb +52 -54
- data/spec/shared_examples/user_shared_examples.rb +226 -116
- data/spec/sorcery_crypto_providers_spec.rb +63 -76
- data/spec/spec_helper.rb +17 -13
- metadata +28 -82
- data/gemfiles/mongo_mapper-rails40.gemfile +0 -9
- data/gemfiles/mongo_mapper-rails41.gemfile +0 -9
- data/gemfiles/mongoid-rails41.gemfile +0 -9
- data/gemfiles/mongoid3-rails32.gemfile +0 -9
- data/lib/sorcery/adapters/data_mapper_adapter.rb +0 -176
- data/lib/sorcery/adapters/mongo_mapper_adapter.rb +0 -110
- data/lib/sorcery/adapters/mongoid_adapter.rb +0 -97
- data/lib/sorcery/railties/tasks.rake +0 -6
- data/spec/data_mapper/user_activation_spec.rb +0 -10
- data/spec/data_mapper/user_activity_logging_spec.rb +0 -14
- data/spec/data_mapper/user_brute_force_protection_spec.rb +0 -9
- data/spec/data_mapper/user_oauth_spec.rb +0 -9
- data/spec/data_mapper/user_remember_me_spec.rb +0 -8
- data/spec/data_mapper/user_reset_password_spec.rb +0 -8
- data/spec/data_mapper/user_spec.rb +0 -27
- data/spec/mongo_mapper/user_activation_spec.rb +0 -9
- data/spec/mongo_mapper/user_activity_logging_spec.rb +0 -8
- data/spec/mongo_mapper/user_brute_force_protection_spec.rb +0 -8
- data/spec/mongo_mapper/user_oauth_spec.rb +0 -8
- data/spec/mongo_mapper/user_remember_me_spec.rb +0 -8
- data/spec/mongo_mapper/user_reset_password_spec.rb +0 -8
- data/spec/mongo_mapper/user_spec.rb +0 -37
- data/spec/mongoid/user_activation_spec.rb +0 -9
- data/spec/mongoid/user_activity_logging_spec.rb +0 -8
- data/spec/mongoid/user_brute_force_protection_spec.rb +0 -8
- data/spec/mongoid/user_oauth_spec.rb +0 -8
- data/spec/mongoid/user_remember_me_spec.rb +0 -8
- data/spec/mongoid/user_reset_password_spec.rb +0 -8
- data/spec/mongoid/user_spec.rb +0 -51
- data/spec/orm/data_mapper.rb +0 -48
- data/spec/orm/mongo_mapper.rb +0 -10
- data/spec/orm/mongoid.rb +0 -22
- data/spec/rails_app/app/data_mapper/authentication.rb +0 -8
- data/spec/rails_app/app/data_mapper/user.rb +0 -7
- data/spec/rails_app/app/mongo_mapper/authentication.rb +0 -6
- data/spec/rails_app/app/mongo_mapper/user.rb +0 -7
- data/spec/rails_app/app/mongoid/authentication.rb +0 -7
- data/spec/rails_app/app/mongoid/user.rb +0 -7
- data/spec/rails_app/log/development.log +0 -1791
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
shared_examples_for
|
|
2
|
-
|
|
1
|
+
shared_examples_for 'rails_3_core_model' do
|
|
3
2
|
let(:user) { create_new_user }
|
|
4
3
|
let(:crypted_password) { user.send User.sorcery_config.crypted_password_attribute_name }
|
|
5
4
|
|
|
6
|
-
describe
|
|
7
|
-
|
|
5
|
+
describe 'loaded plugin configuration' do
|
|
8
6
|
after(:each) { User.sorcery_config.reset! }
|
|
9
7
|
|
|
10
8
|
it "enables configuration option 'username_attribute_names'" do
|
|
@@ -57,7 +55,7 @@ shared_examples_for "rails_3_core_model" do
|
|
|
57
55
|
end
|
|
58
56
|
|
|
59
57
|
it "enables configuration option 'salt_join_token'" do
|
|
60
|
-
salt_join_token =
|
|
58
|
+
salt_join_token = '--%%*&-'
|
|
61
59
|
sorcery_model_property_set(:salt_join_token, salt_join_token)
|
|
62
60
|
|
|
63
61
|
expect(User.sorcery_config.salt_join_token).to eq salt_join_token
|
|
@@ -70,88 +68,126 @@ shared_examples_for "rails_3_core_model" do
|
|
|
70
68
|
expect(User.sorcery_config.stretches).to eq stretches
|
|
71
69
|
end
|
|
72
70
|
|
|
71
|
+
it "enables configuration option 'deliver_later_enabled" do
|
|
72
|
+
sorcery_model_property_set(:email_delivery_method, :deliver_later)
|
|
73
|
+
expect(User.sorcery_config.email_delivery_method).to eq :deliver_later
|
|
74
|
+
end
|
|
75
|
+
|
|
73
76
|
it 'respond to username=' do
|
|
74
77
|
expect(User.new).to respond_to(:username=)
|
|
75
78
|
end
|
|
76
79
|
end
|
|
77
80
|
|
|
78
|
-
describe
|
|
81
|
+
describe 'when activated with sorcery' do
|
|
79
82
|
before(:all) { sorcery_reload! }
|
|
80
83
|
before(:each) { User.sorcery_adapter.delete_all }
|
|
81
84
|
|
|
82
|
-
it
|
|
85
|
+
it 'does not add authenticate method to base class', active_record: true do
|
|
83
86
|
expect(ActiveRecord::Base).not_to respond_to(:authenticate) if defined?(ActiveRecord)
|
|
84
87
|
end
|
|
85
88
|
|
|
86
|
-
it
|
|
89
|
+
it 'responds to class method authenticate' do
|
|
87
90
|
expect(User).to respond_to :authenticate
|
|
88
91
|
end
|
|
89
92
|
|
|
90
|
-
|
|
91
|
-
|
|
93
|
+
describe '#authenticate' do
|
|
94
|
+
it 'returns user if credentials are good' do
|
|
95
|
+
expect(User.authenticate(user.email, 'secret')).to eq user
|
|
96
|
+
end
|
|
92
97
|
|
|
93
|
-
|
|
94
|
-
|
|
98
|
+
it 'returns nil if credentials are bad' do
|
|
99
|
+
expect(User.authenticate(user.email, 'wrong!')).to be nil
|
|
100
|
+
end
|
|
95
101
|
|
|
96
|
-
|
|
97
|
-
|
|
102
|
+
context 'downcasing username' do
|
|
103
|
+
after do
|
|
104
|
+
sorcery_reload!
|
|
105
|
+
end
|
|
98
106
|
|
|
99
|
-
|
|
100
|
-
|
|
107
|
+
context 'when downcasing set to false' do
|
|
108
|
+
before do
|
|
109
|
+
sorcery_model_property_set(:downcase_username_before_authenticating, false)
|
|
110
|
+
end
|
|
101
111
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
end
|
|
112
|
+
it 'does not find user with wrongly capitalized username' do
|
|
113
|
+
expect(User.authenticate(user.email.capitalize, 'secret')).to be_nil
|
|
114
|
+
end
|
|
106
115
|
|
|
107
|
-
|
|
108
|
-
|
|
116
|
+
it 'finds user with correctly capitalized username' do
|
|
117
|
+
expect(User.authenticate(user.email, 'secret')).to eq user
|
|
118
|
+
end
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
context 'when downcasing set to true' do
|
|
122
|
+
before do
|
|
123
|
+
sorcery_model_property_set(:downcase_username_before_authenticating, true)
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
it 'does not find user with wrongly capitalized username' do
|
|
127
|
+
expect(User.authenticate(user.email.capitalize, 'secret')).to eq user
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
it 'finds user with correctly capitalized username' do
|
|
131
|
+
expect(User.authenticate(user.email, 'secret')).to eq user
|
|
132
|
+
end
|
|
133
|
+
end
|
|
109
134
|
end
|
|
110
135
|
|
|
111
|
-
|
|
112
|
-
|
|
136
|
+
context 'and model implements active_for_authentication?' do
|
|
137
|
+
it 'authenticates returns user if active_for_authentication? returns true' do
|
|
138
|
+
allow_any_instance_of(User).to receive(:active_for_authentication?) { true }
|
|
139
|
+
|
|
140
|
+
expect(User.authenticate(user.email, 'secret')).to eq user
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
it 'authenticate returns nil if active_for_authentication? returns false' do
|
|
144
|
+
allow_any_instance_of(User).to receive(:active_for_authentication?) { false }
|
|
145
|
+
|
|
146
|
+
expect(User.authenticate(user.email, 'secret')).to be_nil
|
|
147
|
+
end
|
|
113
148
|
end
|
|
114
149
|
end
|
|
115
150
|
|
|
116
151
|
specify { expect(User).to respond_to(:encrypt) }
|
|
117
152
|
|
|
118
|
-
it
|
|
119
|
-
sorcery_reload!([],
|
|
153
|
+
it 'subclass inherits config if defined so' do
|
|
154
|
+
sorcery_reload!([], subclasses_inherit_config: true)
|
|
120
155
|
class Admin < User; end
|
|
121
156
|
|
|
122
157
|
expect(Admin.sorcery_config).not_to be_nil
|
|
123
158
|
expect(Admin.sorcery_config).to eq User.sorcery_config
|
|
124
159
|
end
|
|
125
160
|
|
|
126
|
-
it
|
|
127
|
-
sorcery_reload!([],
|
|
161
|
+
it 'subclass does not inherit config if not defined so' do
|
|
162
|
+
sorcery_reload!([], subclasses_inherit_config: false)
|
|
128
163
|
class Admin2 < User; end
|
|
129
164
|
|
|
130
165
|
expect(Admin2.sorcery_config).to be_nil
|
|
131
166
|
end
|
|
132
167
|
end
|
|
133
168
|
|
|
134
|
-
|
|
135
|
-
describe "registration" do
|
|
136
|
-
|
|
169
|
+
describe 'registration' do
|
|
137
170
|
before(:all) { sorcery_reload! }
|
|
138
171
|
before(:each) { User.sorcery_adapter.delete_all }
|
|
139
172
|
|
|
140
|
-
it
|
|
173
|
+
it 'by default, encryption_provider is not nil' do
|
|
141
174
|
expect(User.sorcery_config.encryption_provider).not_to be_nil
|
|
142
175
|
end
|
|
143
176
|
|
|
144
|
-
it
|
|
145
|
-
expect(
|
|
177
|
+
it 'encrypts password when a new user is saved' do
|
|
178
|
+
expect(
|
|
179
|
+
User.sorcery_config.encryption_provider.matches?(crypted_password, 'secret', user.salt)
|
|
180
|
+
).to be true
|
|
146
181
|
end
|
|
147
182
|
|
|
148
|
-
it
|
|
183
|
+
it 'clears the virtual password field if the encryption process worked' do
|
|
149
184
|
expect(user.password).to be_nil
|
|
150
185
|
end
|
|
151
186
|
|
|
152
|
-
it
|
|
187
|
+
it 'does not clear the virtual password field if save failed due to validity' do
|
|
153
188
|
User.class_eval do
|
|
154
|
-
validates_format_of :email, :
|
|
189
|
+
validates_format_of :email, with: /\A(.)+@(.)+\Z/,
|
|
190
|
+
if: proc { |r| r.email }, message: 'is invalid'
|
|
155
191
|
end
|
|
156
192
|
|
|
157
193
|
user.password = 'blupush'
|
|
@@ -161,7 +197,7 @@ shared_examples_for "rails_3_core_model" do
|
|
|
161
197
|
expect(user.password).not_to be_nil
|
|
162
198
|
end
|
|
163
199
|
|
|
164
|
-
it
|
|
200
|
+
it 'does not clear the virtual password field if save failed due to exception' do
|
|
165
201
|
user.password = '4blupush'
|
|
166
202
|
user.username = nil
|
|
167
203
|
|
|
@@ -175,21 +211,25 @@ shared_examples_for "rails_3_core_model" do
|
|
|
175
211
|
expect(user.password).not_to be_nil
|
|
176
212
|
end
|
|
177
213
|
|
|
178
|
-
it
|
|
179
|
-
user.email =
|
|
214
|
+
it 'does not encrypt the password twice when a user is updated' do
|
|
215
|
+
user.email = 'blup@bla.com'
|
|
180
216
|
user.save
|
|
181
217
|
|
|
182
|
-
expect(
|
|
218
|
+
expect(
|
|
219
|
+
User.sorcery_config.encryption_provider.matches?(crypted_password, 'secret', user.salt)
|
|
220
|
+
).to be true
|
|
183
221
|
end
|
|
184
222
|
|
|
185
|
-
it
|
|
223
|
+
it 'replaces the crypted_password in case a new password is set' do
|
|
186
224
|
user.password = 'new_secret'
|
|
187
225
|
user.save
|
|
188
226
|
|
|
189
|
-
expect(
|
|
227
|
+
expect(
|
|
228
|
+
User.sorcery_config.encryption_provider.matches?(crypted_password, 'secret', user.salt)
|
|
229
|
+
).to be false
|
|
190
230
|
end
|
|
191
231
|
|
|
192
|
-
describe
|
|
232
|
+
describe 'when user has password_confirmation_defined' do
|
|
193
233
|
before(:all) do
|
|
194
234
|
update_model { attr_accessor :password_confirmation }
|
|
195
235
|
end
|
|
@@ -199,17 +239,25 @@ shared_examples_for "rails_3_core_model" do
|
|
|
199
239
|
User.send(:remove_method, :password_confirmation=)
|
|
200
240
|
end
|
|
201
241
|
|
|
202
|
-
it
|
|
203
|
-
user = create_new_user(
|
|
242
|
+
it 'clears the virtual password field if the encryption process worked' do
|
|
243
|
+
user = create_new_user(
|
|
244
|
+
username: 'u',
|
|
245
|
+
password: 'secret', password_confirmation: 'secret',
|
|
246
|
+
email: 'email@example.com'
|
|
247
|
+
)
|
|
204
248
|
|
|
205
249
|
expect(user.password_confirmation).to be_nil
|
|
206
250
|
end
|
|
207
251
|
|
|
208
|
-
it
|
|
252
|
+
it 'does not clear the virtual password field if save failed due to validity' do
|
|
209
253
|
User.class_eval do
|
|
210
|
-
validates_format_of :email, :
|
|
254
|
+
validates_format_of :email, with: /\A(.)+@(.)+\Z/
|
|
211
255
|
end
|
|
212
|
-
user = build_new_user(
|
|
256
|
+
user = build_new_user(
|
|
257
|
+
username: 'u',
|
|
258
|
+
password: 'secret', password_confirmation: 'secret',
|
|
259
|
+
email: 'asd'
|
|
260
|
+
)
|
|
213
261
|
user.save
|
|
214
262
|
|
|
215
263
|
expect(user.password_confirmation).not_to be_nil
|
|
@@ -217,25 +265,89 @@ shared_examples_for "rails_3_core_model" do
|
|
|
217
265
|
end
|
|
218
266
|
end
|
|
219
267
|
|
|
220
|
-
describe
|
|
221
|
-
|
|
222
|
-
|
|
268
|
+
describe 'password validation' do
|
|
269
|
+
let(:user_with_pass) do
|
|
270
|
+
create_new_user(username: 'foo_bar', email: 'foo@bar.com', password: 'foobar')
|
|
271
|
+
end
|
|
223
272
|
|
|
224
273
|
specify { expect(user_with_pass).to respond_to :valid_password? }
|
|
225
|
-
|
|
226
|
-
it
|
|
227
|
-
expect(user_with_pass.valid_password?(
|
|
274
|
+
|
|
275
|
+
it 'returns true if password is correct' do
|
|
276
|
+
expect(user_with_pass.valid_password?('foobar')).to be true
|
|
228
277
|
end
|
|
229
|
-
|
|
230
|
-
it
|
|
231
|
-
expect(user_with_pass.valid_password?(
|
|
278
|
+
|
|
279
|
+
it 'returns false if password is incorrect' do
|
|
280
|
+
expect(user_with_pass.valid_password?('foobug')).to be false
|
|
232
281
|
end
|
|
233
282
|
end
|
|
234
283
|
|
|
235
|
-
describe
|
|
284
|
+
describe 'generic send email' do
|
|
236
285
|
before(:all) do
|
|
237
|
-
|
|
238
|
-
|
|
286
|
+
ActiveRecord::Migrator.migrate("#{Rails.root}/db/migrate/activation")
|
|
287
|
+
User.reset_column_information
|
|
288
|
+
end
|
|
289
|
+
|
|
290
|
+
after(:all) do
|
|
291
|
+
ActiveRecord::Migrator.rollback("#{Rails.root}/db/migrate/activation")
|
|
292
|
+
end
|
|
293
|
+
|
|
294
|
+
before do
|
|
295
|
+
@mail = double('mail')
|
|
296
|
+
allow(::SorceryMailer).to receive(:activation_success_email).and_return(@mail)
|
|
297
|
+
end
|
|
298
|
+
|
|
299
|
+
it 'use deliver_later' do
|
|
300
|
+
sorcery_reload!(
|
|
301
|
+
[
|
|
302
|
+
:user_activation, :user_activation_mailer,
|
|
303
|
+
:activation_needed_email_method_name, :email_delivery_method
|
|
304
|
+
],
|
|
305
|
+
user_activation_mailer: SorceryMailer,
|
|
306
|
+
activation_needed_email_method_name: nil,
|
|
307
|
+
email_delivery_method: :deliver_later
|
|
308
|
+
)
|
|
309
|
+
|
|
310
|
+
expect(@mail).to receive(:deliver_later).once
|
|
311
|
+
user.activate!
|
|
312
|
+
end
|
|
313
|
+
|
|
314
|
+
describe 'email_delivery_method is default' do
|
|
315
|
+
it 'use deliver_now if rails version 4.2+' do
|
|
316
|
+
allow(Rails).to receive(:version).and_return('4.2.0')
|
|
317
|
+
sorcery_reload!(
|
|
318
|
+
[
|
|
319
|
+
:user_activation, :user_activation_mailer,
|
|
320
|
+
:activation_needed_email_method_name
|
|
321
|
+
],
|
|
322
|
+
user_activation_mailer: SorceryMailer,
|
|
323
|
+
activation_needed_email_method_name: nil
|
|
324
|
+
)
|
|
325
|
+
|
|
326
|
+
expect(@mail).to receive(:deliver_now).once
|
|
327
|
+
user.activate!
|
|
328
|
+
end
|
|
329
|
+
|
|
330
|
+
it 'use deliver if rails version < 4.2' do
|
|
331
|
+
allow(Rails).to receive(:version).and_return('4.1.0')
|
|
332
|
+
sorcery_reload!(
|
|
333
|
+
[
|
|
334
|
+
:user_activation, :user_activation_mailer,
|
|
335
|
+
:activation_needed_email_method_name
|
|
336
|
+
],
|
|
337
|
+
user_activation_mailer: SorceryMailer,
|
|
338
|
+
activation_needed_email_method_name: nil
|
|
339
|
+
)
|
|
340
|
+
|
|
341
|
+
expect(@mail).to receive(:deliver).once
|
|
342
|
+
user.activate!
|
|
343
|
+
end
|
|
344
|
+
end
|
|
345
|
+
end
|
|
346
|
+
|
|
347
|
+
describe 'special encryption cases' do
|
|
348
|
+
before(:all) do
|
|
349
|
+
sorcery_reload!
|
|
350
|
+
@text = 'Some Text!'
|
|
239
351
|
end
|
|
240
352
|
|
|
241
353
|
before(:each) do
|
|
@@ -246,20 +358,20 @@ shared_examples_for "rails_3_core_model" do
|
|
|
246
358
|
User.sorcery_config.reset!
|
|
247
359
|
end
|
|
248
360
|
|
|
249
|
-
it
|
|
361
|
+
it 'works with no password encryption' do
|
|
250
362
|
sorcery_model_property_set(:encryption_algorithm, :none)
|
|
251
363
|
username = user.send(User.sorcery_config.username_attribute_names.first)
|
|
252
364
|
|
|
253
|
-
expect(User.authenticate
|
|
365
|
+
expect(User.authenticate(username, 'secret')).to be_truthy
|
|
254
366
|
end
|
|
255
367
|
|
|
256
|
-
it
|
|
368
|
+
it 'works with custom password encryption' do
|
|
257
369
|
class MyCrypto
|
|
258
370
|
def self.encrypt(*tokens)
|
|
259
|
-
tokens.flatten.join('').
|
|
371
|
+
tokens.flatten.join('').tr('e', 'A')
|
|
260
372
|
end
|
|
261
373
|
|
|
262
|
-
def self.matches?(crypted
|
|
374
|
+
def self.matches?(crypted, *tokens)
|
|
263
375
|
crypted == encrypt(*tokens)
|
|
264
376
|
end
|
|
265
377
|
end
|
|
@@ -268,87 +380,87 @@ shared_examples_for "rails_3_core_model" do
|
|
|
268
380
|
|
|
269
381
|
username = user.send(User.sorcery_config.username_attribute_names.first)
|
|
270
382
|
|
|
271
|
-
expect(User.authenticate
|
|
383
|
+
expect(User.authenticate(username, 'secret')).to be_truthy
|
|
272
384
|
end
|
|
273
385
|
|
|
274
|
-
it
|
|
386
|
+
it 'if encryption algo is aes256, it sets key to crypto provider' do
|
|
275
387
|
sorcery_model_property_set(:encryption_algorithm, :aes256)
|
|
276
388
|
sorcery_model_property_set(:encryption_key, nil)
|
|
277
389
|
|
|
278
390
|
expect { User.encrypt @text }.to raise_error(ArgumentError)
|
|
279
391
|
|
|
280
|
-
sorcery_model_property_set(:encryption_key,
|
|
392
|
+
sorcery_model_property_set(:encryption_key, 'asd234dfs423fddsmndsflktsdf32343')
|
|
281
393
|
|
|
282
394
|
expect { User.encrypt @text }.not_to raise_error
|
|
283
395
|
end
|
|
284
396
|
|
|
285
|
-
it
|
|
397
|
+
it 'if encryption algo is aes256, it sets key to crypto provider, even if attributes are set in reverse' do
|
|
286
398
|
sorcery_model_property_set(:encryption_key, nil)
|
|
287
399
|
sorcery_model_property_set(:encryption_algorithm, :none)
|
|
288
|
-
sorcery_model_property_set(:encryption_key,
|
|
400
|
+
sorcery_model_property_set(:encryption_key, 'asd234dfs423fddsmndsflktsdf32343')
|
|
289
401
|
sorcery_model_property_set(:encryption_algorithm, :aes256)
|
|
290
402
|
|
|
291
403
|
expect { User.encrypt @text }.not_to raise_error
|
|
292
404
|
end
|
|
293
405
|
|
|
294
|
-
it
|
|
406
|
+
it 'if encryption algo is md5 it works' do
|
|
295
407
|
sorcery_model_property_set(:encryption_algorithm, :md5)
|
|
296
408
|
|
|
297
|
-
expect(User.encrypt
|
|
409
|
+
expect(User.encrypt(@text)).to eq Sorcery::CryptoProviders::MD5.encrypt(@text)
|
|
298
410
|
end
|
|
299
411
|
|
|
300
|
-
it
|
|
412
|
+
it 'if encryption algo is sha1 it works' do
|
|
301
413
|
sorcery_model_property_set(:encryption_algorithm, :sha1)
|
|
302
414
|
|
|
303
|
-
expect(User.encrypt
|
|
415
|
+
expect(User.encrypt(@text)).to eq Sorcery::CryptoProviders::SHA1.encrypt(@text)
|
|
304
416
|
end
|
|
305
417
|
|
|
306
|
-
it
|
|
418
|
+
it 'if encryption algo is sha256 it works' do
|
|
307
419
|
sorcery_model_property_set(:encryption_algorithm, :sha256)
|
|
308
420
|
|
|
309
|
-
expect(User.encrypt
|
|
421
|
+
expect(User.encrypt(@text)).to eq Sorcery::CryptoProviders::SHA256.encrypt(@text)
|
|
310
422
|
end
|
|
311
423
|
|
|
312
|
-
it
|
|
424
|
+
it 'if encryption algo is sha512 it works' do
|
|
313
425
|
sorcery_model_property_set(:encryption_algorithm, :sha512)
|
|
314
426
|
|
|
315
|
-
expect(User.encrypt
|
|
427
|
+
expect(User.encrypt(@text)).to eq Sorcery::CryptoProviders::SHA512.encrypt(@text)
|
|
316
428
|
end
|
|
317
429
|
|
|
318
|
-
it
|
|
430
|
+
it 'salt is random for each user and saved in db' do
|
|
319
431
|
sorcery_model_property_set(:salt_attribute_name, :salt)
|
|
320
432
|
|
|
321
433
|
expect(user.salt).not_to be_nil
|
|
322
434
|
end
|
|
323
435
|
|
|
324
|
-
it
|
|
436
|
+
it 'if salt is set uses it to encrypt' do
|
|
325
437
|
sorcery_model_property_set(:salt_attribute_name, :salt)
|
|
326
438
|
sorcery_model_property_set(:encryption_algorithm, :sha512)
|
|
327
439
|
|
|
328
440
|
expect(user.crypted_password).not_to eq Sorcery::CryptoProviders::SHA512.encrypt('secret')
|
|
329
|
-
expect(user.crypted_password).to eq Sorcery::CryptoProviders::SHA512.encrypt('secret',user.salt)
|
|
441
|
+
expect(user.crypted_password).to eq Sorcery::CryptoProviders::SHA512.encrypt('secret', user.salt)
|
|
330
442
|
end
|
|
331
443
|
|
|
332
|
-
it
|
|
444
|
+
it 'if salt_join_token is set uses it to encrypt' do
|
|
333
445
|
sorcery_model_property_set(:salt_attribute_name, :salt)
|
|
334
|
-
sorcery_model_property_set(:salt_join_token,
|
|
446
|
+
sorcery_model_property_set(:salt_join_token, '-@=>')
|
|
335
447
|
sorcery_model_property_set(:encryption_algorithm, :sha512)
|
|
336
448
|
|
|
337
449
|
expect(user.crypted_password).not_to eq Sorcery::CryptoProviders::SHA512.encrypt('secret')
|
|
338
450
|
|
|
339
|
-
Sorcery::CryptoProviders::SHA512.join_token =
|
|
451
|
+
Sorcery::CryptoProviders::SHA512.join_token = ''
|
|
340
452
|
|
|
341
|
-
expect(user.crypted_password).not_to eq Sorcery::CryptoProviders::SHA512.encrypt('secret',user.salt)
|
|
453
|
+
expect(user.crypted_password).not_to eq Sorcery::CryptoProviders::SHA512.encrypt('secret', user.salt)
|
|
342
454
|
|
|
343
455
|
Sorcery::CryptoProviders::SHA512.join_token = User.sorcery_config.salt_join_token
|
|
344
456
|
|
|
345
|
-
expect(user.crypted_password).to eq Sorcery::CryptoProviders::SHA512.encrypt('secret',user.salt)
|
|
457
|
+
expect(user.crypted_password).to eq Sorcery::CryptoProviders::SHA512.encrypt('secret', user.salt)
|
|
346
458
|
end
|
|
347
459
|
end
|
|
348
460
|
|
|
349
|
-
describe
|
|
461
|
+
describe 'ORM adapter' do
|
|
350
462
|
before(:all) do
|
|
351
|
-
sorcery_reload!
|
|
463
|
+
sorcery_reload!
|
|
352
464
|
User.sorcery_adapter.delete_all
|
|
353
465
|
end
|
|
354
466
|
|
|
@@ -359,26 +471,25 @@ shared_examples_for "rails_3_core_model" do
|
|
|
359
471
|
User.sorcery_config.reset!
|
|
360
472
|
end
|
|
361
473
|
|
|
362
|
-
|
|
363
|
-
it "find_by_username works as expected" do
|
|
474
|
+
it 'find_by_username works as expected' do
|
|
364
475
|
sorcery_model_property_set(:username_attribute_names, [:username])
|
|
365
476
|
|
|
366
|
-
expect(User.sorcery_adapter.find_by_username
|
|
477
|
+
expect(User.sorcery_adapter.find_by_username('gizmo')).to eq user
|
|
367
478
|
end
|
|
368
479
|
|
|
369
|
-
it
|
|
480
|
+
it 'find_by_username works as expected with multiple username attributes' do
|
|
370
481
|
sorcery_model_property_set(:username_attribute_names, [:username, :email])
|
|
371
482
|
|
|
372
|
-
expect(User.sorcery_adapter.find_by_username
|
|
483
|
+
expect(User.sorcery_adapter.find_by_username('gizmo')).to eq user
|
|
373
484
|
end
|
|
374
485
|
|
|
375
|
-
it
|
|
376
|
-
expect(User.sorcery_adapter.find_by_email
|
|
486
|
+
it 'find_by_email works as expected' do
|
|
487
|
+
expect(User.sorcery_adapter.find_by_email('bla@bla.com')).to eq user
|
|
377
488
|
end
|
|
378
489
|
end
|
|
379
490
|
end
|
|
380
491
|
|
|
381
|
-
shared_examples_for
|
|
492
|
+
shared_examples_for 'external_user' do
|
|
382
493
|
let(:user) { create_new_user }
|
|
383
494
|
let(:external_user) { create_new_external_user :twitter }
|
|
384
495
|
|
|
@@ -390,16 +501,15 @@ shared_examples_for "external_user" do
|
|
|
390
501
|
expect(user).to respond_to(:external?)
|
|
391
502
|
end
|
|
392
503
|
|
|
393
|
-
it
|
|
504
|
+
it 'external? is false for regular users' do
|
|
394
505
|
expect(user.external?).to be false
|
|
395
506
|
end
|
|
396
507
|
|
|
397
|
-
it
|
|
508
|
+
it 'external? is true for external users' do
|
|
398
509
|
expect(external_user.external?).to be true
|
|
399
510
|
end
|
|
400
511
|
|
|
401
|
-
describe
|
|
402
|
-
|
|
512
|
+
describe '.create_from_provider' do
|
|
403
513
|
before(:all) do
|
|
404
514
|
if SORCERY_ORM == :active_record
|
|
405
515
|
ActiveRecord::Migrator.migrate("#{Rails.root}/db/migrate/external")
|
|
@@ -418,24 +528,26 @@ shared_examples_for "external_user" do
|
|
|
418
528
|
it 'supports nested attributes' do
|
|
419
529
|
sorcery_model_property_set(:authentications_class, Authentication)
|
|
420
530
|
|
|
421
|
-
expect
|
|
531
|
+
expect do
|
|
532
|
+
User.create_from_provider('facebook', '123', username: 'Noam Ben Ari')
|
|
533
|
+
end.to change { User.count }.by(1)
|
|
534
|
+
|
|
422
535
|
expect(User.first.username).to eq 'Noam Ben Ari'
|
|
423
536
|
end
|
|
424
537
|
|
|
425
538
|
context 'with block' do
|
|
426
539
|
it 'create user when block return true' do
|
|
427
|
-
expect
|
|
428
|
-
User.create_from_provider('facebook', '123',
|
|
429
|
-
|
|
540
|
+
expect do
|
|
541
|
+
User.create_from_provider('facebook', '123', username: 'Noam Ben Ari') { true }
|
|
542
|
+
end.to change { User.count }.by(1)
|
|
430
543
|
end
|
|
431
544
|
|
|
432
545
|
it 'does not create user when block return false' do
|
|
433
|
-
expect
|
|
434
|
-
User.create_from_provider('facebook', '123',
|
|
435
|
-
|
|
546
|
+
expect do
|
|
547
|
+
User.create_from_provider('facebook', '123', username: 'Noam Ben Ari') { false }
|
|
548
|
+
end.not_to change { User.count }
|
|
436
549
|
end
|
|
437
550
|
end
|
|
438
|
-
|
|
439
551
|
end
|
|
440
552
|
|
|
441
553
|
describe 'activation' do
|
|
@@ -445,13 +557,13 @@ shared_examples_for "external_user" do
|
|
|
445
557
|
ActiveRecord::Migrator.migrate("#{Rails.root}/db/migrate/activation")
|
|
446
558
|
end
|
|
447
559
|
|
|
448
|
-
sorcery_reload!([:user_activation
|
|
560
|
+
sorcery_reload!([:user_activation, :external], user_activation_mailer: ::SorceryMailer)
|
|
449
561
|
end
|
|
450
562
|
|
|
451
563
|
after(:all) do
|
|
452
564
|
if SORCERY_ORM == :active_record
|
|
453
|
-
ActiveRecord::Migrator.rollback("#{Rails.root}/db/migrate/activation")
|
|
454
565
|
ActiveRecord::Migrator.rollback("#{Rails.root}/db/migrate/external")
|
|
566
|
+
ActiveRecord::Migrator.rollback("#{Rails.root}/db/migrate/activation")
|
|
455
567
|
end
|
|
456
568
|
end
|
|
457
569
|
|
|
@@ -459,16 +571,15 @@ shared_examples_for "external_user" do
|
|
|
459
571
|
User.sorcery_adapter.delete_all
|
|
460
572
|
end
|
|
461
573
|
|
|
462
|
-
[:facebook, :github, :google, :liveid].each do |provider|
|
|
463
|
-
|
|
464
|
-
it "does not send activation email to external users" do
|
|
574
|
+
[:facebook, :github, :google, :liveid, :slack].each do |provider|
|
|
575
|
+
it 'does not send activation email to external users' do
|
|
465
576
|
old_size = ActionMailer::Base.deliveries.size
|
|
466
577
|
create_new_external_user(provider)
|
|
467
578
|
|
|
468
579
|
expect(ActionMailer::Base.deliveries.size).to eq old_size
|
|
469
580
|
end
|
|
470
581
|
|
|
471
|
-
it
|
|
582
|
+
it 'does not send external users an activation success email' do
|
|
472
583
|
sorcery_model_property_set(:activation_success_email_method_name, nil)
|
|
473
584
|
create_new_external_user(provider)
|
|
474
585
|
old_size = ActionMailer::Base.deliveries.size
|
|
@@ -477,6 +588,5 @@ shared_examples_for "external_user" do
|
|
|
477
588
|
expect(ActionMailer::Base.deliveries.size).to eq old_size
|
|
478
589
|
end
|
|
479
590
|
end
|
|
480
|
-
|
|
481
591
|
end
|
|
482
592
|
end
|