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,86 +1,98 @@
|
|
1
1
|
shared_examples_for "rails_3_core_model" do
|
2
|
-
describe User, "loaded plugin configuration" do
|
3
|
-
after(:each) do
|
4
|
-
User.sorcery_config.reset!
|
5
|
-
end
|
6
2
|
|
7
|
-
|
3
|
+
let(:user) { create_new_user }
|
4
|
+
let(:crypted_password) { user.send User.sorcery_config.crypted_password_attribute_name }
|
5
|
+
|
6
|
+
describe "loaded plugin configuration" do
|
7
|
+
|
8
|
+
after(:each) { User.sorcery_config.reset! }
|
9
|
+
|
10
|
+
it "enables configuration option 'username_attribute_names'" do
|
8
11
|
sorcery_model_property_set(:username_attribute_names, :email)
|
9
|
-
|
12
|
+
|
13
|
+
expect(User.sorcery_config.username_attribute_names).to eq [:email]
|
10
14
|
end
|
11
15
|
|
12
|
-
it "
|
16
|
+
it "enables configuration option 'password_attribute_name'" do
|
13
17
|
sorcery_model_property_set(:password_attribute_name, :mypassword)
|
14
|
-
|
18
|
+
|
19
|
+
expect(User.sorcery_config.password_attribute_name).to eq :mypassword
|
15
20
|
end
|
16
21
|
|
17
|
-
it "
|
22
|
+
it "enables configuration option 'email_attribute_name'" do
|
18
23
|
sorcery_model_property_set(:email_attribute_name, :my_email)
|
19
|
-
|
24
|
+
|
25
|
+
expect(User.sorcery_config.email_attribute_name).to eq :my_email
|
20
26
|
end
|
21
27
|
|
22
|
-
it "
|
28
|
+
it "enables configuration option 'crypted_password_attribute_name'" do
|
23
29
|
sorcery_model_property_set(:crypted_password_attribute_name, :password)
|
24
|
-
|
30
|
+
|
31
|
+
expect(User.sorcery_config.crypted_password_attribute_name).to eq :password
|
25
32
|
end
|
26
33
|
|
27
|
-
it "
|
34
|
+
it "enables configuration option 'salt_attribute_name'" do
|
28
35
|
sorcery_model_property_set(:salt_attribute_name, :my_salt)
|
29
|
-
|
36
|
+
|
37
|
+
expect(User.sorcery_config.salt_attribute_name).to eq :my_salt
|
30
38
|
end
|
31
39
|
|
32
|
-
it "
|
40
|
+
it "enables configuration option 'encryption_algorithm'" do
|
33
41
|
sorcery_model_property_set(:encryption_algorithm, :none)
|
34
|
-
|
42
|
+
|
43
|
+
expect(User.sorcery_config.encryption_algorithm).to eq :none
|
35
44
|
end
|
36
45
|
|
37
|
-
it "
|
46
|
+
it "enables configuration option 'encryption_key'" do
|
38
47
|
sorcery_model_property_set(:encryption_key, 'asdadas424234242')
|
39
|
-
|
48
|
+
|
49
|
+
expect(User.sorcery_config.encryption_key).to eq 'asdadas424234242'
|
40
50
|
end
|
41
51
|
|
42
|
-
it "
|
52
|
+
it "enables configuration option 'custom_encryption_provider'" do
|
43
53
|
sorcery_model_property_set(:encryption_algorithm, :custom)
|
44
54
|
sorcery_model_property_set(:custom_encryption_provider, Array)
|
45
|
-
|
55
|
+
|
56
|
+
expect(User.sorcery_config.custom_encryption_provider).to eq Array
|
46
57
|
end
|
47
58
|
|
48
|
-
it "
|
59
|
+
it "enables configuration option 'salt_join_token'" do
|
49
60
|
salt_join_token = "--%%*&-"
|
50
61
|
sorcery_model_property_set(:salt_join_token, salt_join_token)
|
51
|
-
|
62
|
+
|
63
|
+
expect(User.sorcery_config.salt_join_token).to eq salt_join_token
|
52
64
|
end
|
53
65
|
|
54
|
-
it "
|
66
|
+
it "enables configuration option 'stretches'" do
|
55
67
|
stretches = 15
|
56
68
|
sorcery_model_property_set(:stretches, stretches)
|
57
|
-
|
69
|
+
|
70
|
+
expect(User.sorcery_config.stretches).to eq stretches
|
58
71
|
end
|
59
72
|
end
|
60
73
|
|
61
|
-
|
62
|
-
|
63
|
-
before(:
|
64
|
-
|
74
|
+
describe "when activated with sorcery" do
|
75
|
+
before(:all) { sorcery_reload! }
|
76
|
+
before(:each) { User.delete_all }
|
77
|
+
|
78
|
+
it "does not add authenticate method to base class", active_record: true do
|
79
|
+
expect(ActiveRecord::Base).not_to respond_to(:authenticate) if defined?(ActiveRecord)
|
65
80
|
end
|
66
81
|
|
67
|
-
|
68
|
-
User.
|
82
|
+
it "responds to class method authenticate" do
|
83
|
+
expect(User).to respond_to :authenticate
|
69
84
|
end
|
70
85
|
|
71
|
-
it "
|
72
|
-
|
73
|
-
User.should respond_to(:authenticate)
|
74
|
-
end
|
86
|
+
it "authenticate returns true if credentials are good" do
|
87
|
+
username = user.send(User.sorcery_config.username_attribute_names.first)
|
75
88
|
|
76
|
-
|
77
|
-
create_new_user
|
78
|
-
User.authenticate(@user.send(User.sorcery_config.username_attribute_names.first), 'secret').should be_true
|
89
|
+
expect(User.authenticate username, 'secret').to be_truthy
|
79
90
|
end
|
80
91
|
|
81
|
-
it "authenticate
|
82
|
-
|
83
|
-
|
92
|
+
it "authenticate returns nil if credentials are bad" do
|
93
|
+
username = user.send(User.sorcery_config.username_attribute_names.first)
|
94
|
+
|
95
|
+
expect(User.authenticate username, 'wrong!').to be nil
|
84
96
|
end
|
85
97
|
|
86
98
|
context "with empty credentials" do
|
@@ -93,96 +105,129 @@ shared_examples_for "rails_3_core_model" do
|
|
93
105
|
end
|
94
106
|
|
95
107
|
it "don't downcase empty credentials" do
|
96
|
-
expect(User.authenticate(nil, 'wrong!')).to
|
108
|
+
expect(User.authenticate(nil, 'wrong!')).to be_falsy
|
97
109
|
end
|
98
110
|
end
|
99
111
|
|
100
|
-
specify { User.
|
112
|
+
specify { expect(User).to respond_to(:encrypt) }
|
101
113
|
|
102
|
-
it "subclass
|
114
|
+
it "subclass inherits config if defined so" do
|
103
115
|
sorcery_reload!([],{:subclasses_inherit_config => true})
|
104
|
-
class Admin < User
|
105
|
-
|
106
|
-
Admin.sorcery_config.
|
107
|
-
Admin.sorcery_config.
|
116
|
+
class Admin < User; end
|
117
|
+
|
118
|
+
expect(Admin.sorcery_config).not_to be_nil
|
119
|
+
expect(Admin.sorcery_config).to eq User.sorcery_config
|
108
120
|
end
|
109
121
|
|
110
|
-
it "subclass
|
122
|
+
it "subclass does not inherit config if not defined so" do
|
111
123
|
sorcery_reload!([],{:subclasses_inherit_config => false})
|
112
|
-
class Admin2 < User
|
113
|
-
|
114
|
-
Admin2.sorcery_config.
|
124
|
+
class Admin2 < User; end
|
125
|
+
|
126
|
+
expect(Admin2.sorcery_config).to be_nil
|
115
127
|
end
|
116
128
|
end
|
117
129
|
|
118
|
-
# ----------------- REGISTRATION -----------------------
|
119
|
-
describe User, "registration" do
|
120
130
|
|
121
|
-
|
122
|
-
sorcery_reload!()
|
123
|
-
end
|
131
|
+
describe "registration" do
|
124
132
|
|
125
|
-
before(:
|
126
|
-
|
127
|
-
end
|
133
|
+
before(:all) { sorcery_reload! }
|
134
|
+
before(:each) { User.delete_all }
|
128
135
|
|
129
|
-
it "by default, encryption_provider
|
130
|
-
User.sorcery_config.encryption_provider.
|
136
|
+
it "by default, encryption_provider is not nil" do
|
137
|
+
expect(User.sorcery_config.encryption_provider).not_to be_nil
|
131
138
|
end
|
132
139
|
|
133
|
-
it "
|
134
|
-
|
135
|
-
User.sorcery_config.encryption_provider.matches?(@user.send(User.sorcery_config.crypted_password_attribute_name),'secret',@user.salt).should be_true
|
140
|
+
it "encrypts password when a new user is saved" do
|
141
|
+
expect(User.sorcery_config.encryption_provider.matches? crypted_password, 'secret', user.salt).to be true
|
136
142
|
end
|
137
143
|
|
138
|
-
it "
|
139
|
-
|
140
|
-
@user.password.should be_nil
|
144
|
+
it "clears the virtual password field if the encryption process worked" do
|
145
|
+
expect(user.password).to be_nil
|
141
146
|
end
|
142
147
|
|
143
|
-
it "
|
144
|
-
create_new_user
|
148
|
+
it "does not clear the virtual password field if save failed due to validity" do
|
145
149
|
User.class_eval do
|
146
150
|
validates_format_of :email, :with => /\A(.)+@(.)+\Z/, :if => Proc.new {|r| r.email}, :message => "is invalid"
|
147
151
|
end
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
+
|
153
|
+
user.password = 'blupush'
|
154
|
+
user.email = 'asd'
|
155
|
+
user.save
|
156
|
+
|
157
|
+
expect(user.password).not_to be_nil
|
152
158
|
end
|
153
159
|
|
154
|
-
it "
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
User.class_eval
|
159
|
-
validates_presence_of :username
|
160
|
-
end
|
160
|
+
it "does not clear the virtual password field if save failed due to exception" do
|
161
|
+
user.password = '4blupush'
|
162
|
+
user.username = nil
|
163
|
+
|
164
|
+
User.class_eval { validates_presence_of :username }
|
161
165
|
begin
|
162
|
-
|
166
|
+
if defined?(DataMapper) && user.class.ancestors.include?(DataMapper::Resource)
|
167
|
+
user.save
|
168
|
+
else
|
169
|
+
user.save! # triggers validation exception since username field is required.
|
170
|
+
end
|
163
171
|
rescue
|
164
172
|
end
|
165
|
-
|
173
|
+
|
174
|
+
expect(user.password).not_to be_nil
|
166
175
|
end
|
167
176
|
|
168
|
-
it "
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
177
|
+
it "does not encrypt the password twice when a user is updated" do
|
178
|
+
user.email = "blup@bla.com"
|
179
|
+
if defined?(DataMapper) && user.class.ancestors.include?(DataMapper::Resource)
|
180
|
+
user.save
|
181
|
+
else
|
182
|
+
user.save!
|
183
|
+
end
|
184
|
+
|
185
|
+
expect(User.sorcery_config.encryption_provider.matches? crypted_password, 'secret', user.salt).to be true
|
173
186
|
end
|
174
187
|
|
175
|
-
it "
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
188
|
+
it "replaces the crypted_password in case a new password is set" do
|
189
|
+
user.password = 'new_secret'
|
190
|
+
if defined?(DataMapper) && user.class.ancestors.include?(DataMapper::Resource)
|
191
|
+
user.save
|
192
|
+
else
|
193
|
+
user.save!
|
194
|
+
end
|
195
|
+
|
196
|
+
expect(User.sorcery_config.encryption_provider.matches? crypted_password, 'secret', user.salt).to be false
|
180
197
|
end
|
181
198
|
|
199
|
+
describe "when user has password_confirmation_defined" do
|
200
|
+
before(:all) do
|
201
|
+
User.class_eval { attr_accessor :password_confirmation }
|
202
|
+
if defined?(DataMapper)
|
203
|
+
DataMapper.finalize
|
204
|
+
end
|
205
|
+
end
|
206
|
+
|
207
|
+
after(:all) do
|
208
|
+
User.send(:remove_method, :password_confirmation)
|
209
|
+
User.send(:remove_method, :password_confirmation=)
|
210
|
+
end
|
211
|
+
|
212
|
+
it "clears the virtual password field if the encryption process worked" do
|
213
|
+
user = create_new_user(username: "u", password: "secret", password_confirmation: "secret", email: "email@example.com")
|
214
|
+
|
215
|
+
expect(user.password_confirmation).to be_nil
|
216
|
+
end
|
217
|
+
|
218
|
+
it "does not clear the virtual password field if save failed due to validity" do
|
219
|
+
User.class_eval do
|
220
|
+
validates_format_of :email, :with => /\A(.)+@(.)+\Z/
|
221
|
+
end
|
222
|
+
user = build_new_user(username: "u", password: "secret", password_confirmation: "secret", email: "asd")
|
223
|
+
user.save
|
224
|
+
|
225
|
+
expect(user.password_confirmation).not_to be_nil
|
226
|
+
end
|
227
|
+
end
|
182
228
|
end
|
183
229
|
|
184
|
-
|
185
|
-
describe User, "special encryption cases" do
|
230
|
+
describe "special encryption cases" do
|
186
231
|
before(:all) do
|
187
232
|
sorcery_reload!()
|
188
233
|
@text = "Some Text!"
|
@@ -196,13 +241,14 @@ shared_examples_for "rails_3_core_model" do
|
|
196
241
|
User.sorcery_config.reset!
|
197
242
|
end
|
198
243
|
|
199
|
-
it "
|
244
|
+
it "works with no password encryption" do
|
200
245
|
sorcery_model_property_set(:encryption_algorithm, :none)
|
201
|
-
|
202
|
-
|
246
|
+
username = user.send(User.sorcery_config.username_attribute_names.first)
|
247
|
+
|
248
|
+
expect(User.authenticate username, 'secret').to be_truthy
|
203
249
|
end
|
204
250
|
|
205
|
-
it "
|
251
|
+
it "works with custom password encryption" do
|
206
252
|
class MyCrypto
|
207
253
|
def self.encrypt(*tokens)
|
208
254
|
tokens.flatten.join('').gsub(/e/,'A')
|
@@ -214,122 +260,136 @@ shared_examples_for "rails_3_core_model" do
|
|
214
260
|
end
|
215
261
|
sorcery_model_property_set(:encryption_algorithm, :custom)
|
216
262
|
sorcery_model_property_set(:custom_encryption_provider, MyCrypto)
|
217
|
-
|
218
|
-
|
263
|
+
|
264
|
+
username = user.send(User.sorcery_config.username_attribute_names.first)
|
265
|
+
|
266
|
+
expect(User.authenticate username, 'secret').to be_truthy
|
219
267
|
end
|
220
268
|
|
221
|
-
it "if encryption algo is aes256, it
|
269
|
+
it "if encryption algo is aes256, it sets key to crypto provider" do
|
222
270
|
sorcery_model_property_set(:encryption_algorithm, :aes256)
|
223
271
|
sorcery_model_property_set(:encryption_key, nil)
|
224
|
-
|
272
|
+
|
273
|
+
expect { User.encrypt @text }.to raise_error(ArgumentError)
|
274
|
+
|
225
275
|
sorcery_model_property_set(:encryption_key, "asd234dfs423fddsmndsflktsdf32343")
|
226
|
-
|
276
|
+
|
277
|
+
expect { User.encrypt @text }.not_to raise_error
|
227
278
|
end
|
228
279
|
|
229
|
-
it "if encryption algo is aes256, it
|
280
|
+
it "if encryption algo is aes256, it sets key to crypto provider, even if attributes are set in reverse" do
|
230
281
|
sorcery_model_property_set(:encryption_key, nil)
|
231
282
|
sorcery_model_property_set(:encryption_algorithm, :none)
|
232
283
|
sorcery_model_property_set(:encryption_key, "asd234dfs423fddsmndsflktsdf32343")
|
233
284
|
sorcery_model_property_set(:encryption_algorithm, :aes256)
|
234
|
-
|
285
|
+
|
286
|
+
expect { User.encrypt @text }.not_to raise_error
|
235
287
|
end
|
236
288
|
|
237
|
-
it "if encryption algo is md5 it
|
289
|
+
it "if encryption algo is md5 it works" do
|
238
290
|
sorcery_model_property_set(:encryption_algorithm, :md5)
|
239
|
-
|
291
|
+
|
292
|
+
expect(User.encrypt @text).to eq Sorcery::CryptoProviders::MD5.encrypt(@text)
|
240
293
|
end
|
241
294
|
|
242
|
-
it "if encryption algo is sha1 it
|
295
|
+
it "if encryption algo is sha1 it works" do
|
243
296
|
sorcery_model_property_set(:encryption_algorithm, :sha1)
|
244
|
-
|
297
|
+
|
298
|
+
expect(User.encrypt @text).to eq Sorcery::CryptoProviders::SHA1.encrypt(@text)
|
245
299
|
end
|
246
300
|
|
247
|
-
it "if encryption algo is sha256 it
|
301
|
+
it "if encryption algo is sha256 it works" do
|
248
302
|
sorcery_model_property_set(:encryption_algorithm, :sha256)
|
249
|
-
|
303
|
+
|
304
|
+
expect(User.encrypt @text).to eq Sorcery::CryptoProviders::SHA256.encrypt(@text)
|
250
305
|
end
|
251
306
|
|
252
|
-
it "if encryption algo is sha512 it
|
307
|
+
it "if encryption algo is sha512 it works" do
|
253
308
|
sorcery_model_property_set(:encryption_algorithm, :sha512)
|
254
|
-
|
309
|
+
|
310
|
+
expect(User.encrypt @text).to eq Sorcery::CryptoProviders::SHA512.encrypt(@text)
|
255
311
|
end
|
256
312
|
|
257
|
-
it "salt
|
313
|
+
it "salt is random for each user and saved in db" do
|
258
314
|
sorcery_model_property_set(:salt_attribute_name, :salt)
|
259
|
-
|
260
|
-
|
315
|
+
|
316
|
+
expect(user.salt).not_to be_nil
|
261
317
|
end
|
262
318
|
|
263
|
-
it "if salt is set
|
319
|
+
it "if salt is set uses it to encrypt" do
|
264
320
|
sorcery_model_property_set(:salt_attribute_name, :salt)
|
265
321
|
sorcery_model_property_set(:encryption_algorithm, :sha512)
|
266
|
-
|
267
|
-
|
268
|
-
|
322
|
+
|
323
|
+
expect(user.crypted_password).not_to eq Sorcery::CryptoProviders::SHA512.encrypt('secret')
|
324
|
+
expect(user.crypted_password).to eq Sorcery::CryptoProviders::SHA512.encrypt('secret',user.salt)
|
269
325
|
end
|
270
326
|
|
271
|
-
it "if salt_join_token is set
|
327
|
+
it "if salt_join_token is set uses it to encrypt" do
|
272
328
|
sorcery_model_property_set(:salt_attribute_name, :salt)
|
273
329
|
sorcery_model_property_set(:salt_join_token, "-@=>")
|
274
330
|
sorcery_model_property_set(:encryption_algorithm, :sha512)
|
275
|
-
|
276
|
-
|
331
|
+
|
332
|
+
expect(user.crypted_password).not_to eq Sorcery::CryptoProviders::SHA512.encrypt('secret')
|
333
|
+
|
277
334
|
Sorcery::CryptoProviders::SHA512.join_token = ""
|
278
|
-
|
335
|
+
|
336
|
+
expect(user.crypted_password).not_to eq Sorcery::CryptoProviders::SHA512.encrypt('secret',user.salt)
|
337
|
+
|
279
338
|
Sorcery::CryptoProviders::SHA512.join_token = User.sorcery_config.salt_join_token
|
280
|
-
@user.crypted_password.should == Sorcery::CryptoProviders::SHA512.encrypt('secret',@user.salt)
|
281
|
-
end
|
282
339
|
|
340
|
+
expect(user.crypted_password).to eq Sorcery::CryptoProviders::SHA512.encrypt('secret',user.salt)
|
341
|
+
end
|
283
342
|
end
|
284
343
|
|
285
|
-
describe
|
344
|
+
describe "ORM adapter" do
|
286
345
|
before(:all) do
|
287
346
|
sorcery_reload!()
|
288
347
|
User.delete_all
|
289
348
|
end
|
290
349
|
|
291
|
-
before(:each)
|
292
|
-
create_new_user
|
293
|
-
end
|
350
|
+
before(:each) { user }
|
294
351
|
|
295
352
|
after(:each) do
|
296
353
|
User.delete_all
|
297
354
|
User.sorcery_config.reset!
|
298
355
|
end
|
299
356
|
|
300
|
-
|
357
|
+
|
358
|
+
it "find_by_username works as expected" do
|
301
359
|
sorcery_model_property_set(:username_attribute_names, [:username])
|
302
|
-
|
360
|
+
|
361
|
+
expect(User.find_by_username "gizmo").to eq user
|
303
362
|
end
|
304
363
|
|
305
|
-
it "find_by_username
|
364
|
+
it "find_by_username works as expected with multiple username attributes" do
|
306
365
|
sorcery_model_property_set(:username_attribute_names, [:username, :email])
|
307
|
-
|
366
|
+
|
367
|
+
expect(User.find_by_username "gizmo").to eq user
|
308
368
|
end
|
309
369
|
|
310
|
-
it "find_by_email
|
311
|
-
User.find_by_email
|
370
|
+
it "find_by_email works as expected" do
|
371
|
+
expect(User.find_by_email "bla@bla.com").to eq user
|
312
372
|
end
|
313
373
|
end
|
314
374
|
end
|
315
375
|
|
316
376
|
shared_examples_for "external_user" do
|
377
|
+
let(:user) { create_new_user }
|
378
|
+
let(:external_user) { create_new_external_user :twitter }
|
379
|
+
|
317
380
|
before(:each) do
|
318
381
|
User.delete_all
|
319
382
|
end
|
320
383
|
|
321
|
-
it "
|
322
|
-
|
323
|
-
@user.should respond_to(:external?)
|
384
|
+
it "responds to 'external?'" do
|
385
|
+
expect(user).to respond_to(:external?)
|
324
386
|
end
|
325
387
|
|
326
|
-
it "external?
|
327
|
-
|
328
|
-
@user.external?.should be_false
|
388
|
+
it "external? is false for regular users" do
|
389
|
+
expect(user.external?).to be false
|
329
390
|
end
|
330
391
|
|
331
|
-
it "external?
|
332
|
-
|
333
|
-
@user.external?.should be_true
|
392
|
+
it "external? is true for external users" do
|
393
|
+
expect(external_user.external?).to be true
|
334
394
|
end
|
335
|
-
end
|
395
|
+
end
|