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.

Files changed (119) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.travis.yml +60 -4
  4. data/CHANGELOG.md +15 -1
  5. data/Gemfile +9 -18
  6. data/Gemfile.rails4 +8 -10
  7. data/README.md +31 -11
  8. data/VERSION +1 -1
  9. data/gemfiles/active_record-rails41.gemfile +6 -0
  10. data/gemfiles/mongo_mapper-rails41.gemfile +8 -0
  11. data/gemfiles/mongoid-rails41.gemfile +11 -0
  12. data/lib/sorcery.rb +20 -28
  13. data/lib/sorcery/controller.rb +6 -11
  14. data/lib/sorcery/controller/submodules/external.rb +30 -15
  15. data/lib/sorcery/controller/submodules/session_timeout.rb +1 -1
  16. data/lib/sorcery/model.rb +102 -70
  17. data/lib/sorcery/model/adapters/active_record.rb +7 -2
  18. data/lib/sorcery/model/adapters/datamapper.rb +123 -0
  19. data/lib/sorcery/model/adapters/mongo_mapper.rb +8 -4
  20. data/lib/sorcery/model/adapters/mongoid.rb +6 -6
  21. data/lib/sorcery/model/submodules/activity_logging.rb +24 -0
  22. data/lib/sorcery/model/submodules/brute_force_protection.rb +16 -0
  23. data/lib/sorcery/model/submodules/remember_me.rb +19 -4
  24. data/lib/sorcery/model/submodules/reset_password.rb +30 -13
  25. data/lib/sorcery/model/submodules/user_activation.rb +53 -22
  26. data/lib/sorcery/{controller/submodules/external/protocols → protocols}/certs/ca-bundle.crt +0 -0
  27. data/lib/sorcery/protocols/oauth.rb +42 -0
  28. data/lib/sorcery/protocols/oauth2.rb +47 -0
  29. data/lib/sorcery/providers/base.rb +27 -0
  30. data/lib/sorcery/providers/facebook.rb +63 -0
  31. data/lib/sorcery/providers/github.rb +51 -0
  32. data/lib/sorcery/providers/google.rb +51 -0
  33. data/lib/sorcery/providers/linkedin.rb +66 -0
  34. data/lib/sorcery/providers/liveid.rb +53 -0
  35. data/lib/sorcery/providers/twitter.rb +59 -0
  36. data/lib/sorcery/providers/vk.rb +61 -0
  37. data/lib/sorcery/providers/xing.rb +64 -0
  38. data/lib/sorcery/test_helpers/internal.rb +3 -3
  39. data/lib/sorcery/test_helpers/internal/rails.rb +14 -3
  40. data/lib/sorcery/test_helpers/rails.rb +1 -10
  41. data/lib/sorcery/test_helpers/rails/controller.rb +17 -0
  42. data/lib/sorcery/test_helpers/rails/integration.rb +26 -0
  43. data/sorcery.gemspec +14 -18
  44. data/spec/active_record/controller_activity_logging_spec.rb +5 -116
  45. data/spec/active_record/controller_brute_force_protection_spec.rb +69 -47
  46. data/spec/active_record/controller_http_basic_auth_spec.rb +24 -18
  47. data/spec/active_record/controller_oauth2_spec.rb +112 -187
  48. data/spec/active_record/controller_oauth_spec.rb +41 -37
  49. data/spec/active_record/controller_remember_me_spec.rb +39 -38
  50. data/spec/active_record/controller_session_timeout_spec.rb +31 -16
  51. data/spec/active_record/controller_spec.rb +4 -178
  52. data/spec/active_record/integration_spec.rb +1 -1
  53. data/spec/active_record/user_activation_spec.rb +1 -1
  54. data/spec/active_record/user_activity_logging_spec.rb +1 -1
  55. data/spec/active_record/user_brute_force_protection_spec.rb +1 -1
  56. data/spec/active_record/user_oauth_spec.rb +1 -1
  57. data/spec/active_record/user_remember_me_spec.rb +1 -1
  58. data/spec/active_record/user_reset_password_spec.rb +1 -1
  59. data/spec/active_record/user_spec.rb +7 -8
  60. data/spec/datamapper/controller_activity_logging_spec.rb +17 -0
  61. data/spec/datamapper/controller_spec.rb +8 -0
  62. data/spec/datamapper/user_activation_spec.rb +10 -0
  63. data/spec/datamapper/user_activity_logging_spec.rb +9 -0
  64. data/spec/datamapper/user_brute_force_protection_spec.rb +9 -0
  65. data/spec/datamapper/user_oauth_spec.rb +9 -0
  66. data/spec/datamapper/user_remember_me_spec.rb +8 -0
  67. data/spec/datamapper/user_reset_password_spec.rb +8 -0
  68. data/spec/datamapper/user_spec.rb +27 -0
  69. data/spec/mongo_mapper/controller_spec.rb +4 -171
  70. data/spec/mongo_mapper/user_activation_spec.rb +1 -2
  71. data/spec/mongo_mapper/user_activity_logging_spec.rb +1 -1
  72. data/spec/mongo_mapper/user_brute_force_protection_spec.rb +1 -1
  73. data/spec/mongo_mapper/user_oauth_spec.rb +1 -1
  74. data/spec/mongo_mapper/user_remember_me_spec.rb +1 -1
  75. data/spec/mongo_mapper/user_reset_password_spec.rb +1 -1
  76. data/spec/mongo_mapper/user_spec.rb +7 -8
  77. data/spec/mongoid/controller_activity_logging_spec.rb +4 -99
  78. data/spec/mongoid/controller_spec.rb +4 -182
  79. data/spec/mongoid/user_activation_spec.rb +1 -2
  80. data/spec/mongoid/user_activity_logging_spec.rb +1 -2
  81. data/spec/mongoid/user_brute_force_protection_spec.rb +1 -2
  82. data/spec/mongoid/user_oauth_spec.rb +1 -2
  83. data/spec/mongoid/user_remember_me_spec.rb +1 -2
  84. data/spec/mongoid/user_reset_password_spec.rb +1 -2
  85. data/spec/mongoid/user_spec.rb +8 -9
  86. data/spec/orm/active_record.rb +2 -0
  87. data/spec/orm/datamapper.rb +34 -0
  88. data/spec/orm/mongo_mapper.rb +1 -0
  89. data/spec/orm/mongoid.rb +1 -0
  90. data/spec/rails_app/app/controllers/sorcery_controller.rb +64 -59
  91. data/spec/rails_app/app/datamapper/authentication.rb +8 -0
  92. data/spec/rails_app/app/datamapper/user.rb +7 -0
  93. data/spec/rails_app/config/routes.rb +18 -13
  94. data/spec/shared_examples/controller_activity_logging_shared_examples.rb +125 -0
  95. data/spec/shared_examples/controller_oauth2_shared_examples.rb +32 -36
  96. data/spec/shared_examples/controller_oauth_shared_examples.rb +19 -26
  97. data/spec/shared_examples/controller_shared_examples.rb +203 -0
  98. data/spec/shared_examples/user_activation_shared_examples.rb +107 -90
  99. data/spec/shared_examples/user_activity_logging_shared_examples.rb +10 -10
  100. data/spec/shared_examples/user_brute_force_protection_shared_examples.rb +14 -13
  101. data/spec/shared_examples/user_oauth_shared_examples.rb +23 -15
  102. data/spec/shared_examples/user_remember_me_shared_examples.rb +32 -23
  103. data/spec/shared_examples/user_reset_password_shared_examples.rb +136 -115
  104. data/spec/shared_examples/user_shared_examples.rb +206 -146
  105. data/spec/sorcery_crypto_providers_spec.rb +28 -28
  106. data/spec/spec_helper.rb +15 -6
  107. metadata +83 -127
  108. data/lib/sorcery/controller/submodules/external/protocols/oauth1.rb +0 -46
  109. data/lib/sorcery/controller/submodules/external/protocols/oauth2.rb +0 -50
  110. data/lib/sorcery/controller/submodules/external/providers/base.rb +0 -21
  111. data/lib/sorcery/controller/submodules/external/providers/facebook.rb +0 -99
  112. data/lib/sorcery/controller/submodules/external/providers/github.rb +0 -93
  113. data/lib/sorcery/controller/submodules/external/providers/google.rb +0 -92
  114. data/lib/sorcery/controller/submodules/external/providers/linkedin.rb +0 -103
  115. data/lib/sorcery/controller/submodules/external/providers/liveid.rb +0 -93
  116. data/lib/sorcery/controller/submodules/external/providers/twitter.rb +0 -94
  117. data/lib/sorcery/controller/submodules/external/providers/vk.rb +0 -101
  118. data/lib/sorcery/controller/submodules/external/providers/xing.rb +0 -98
  119. 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
- it "should enable configuration option 'username_attribute_names'" do
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
- User.sorcery_config.username_attribute_names.should == [:email]
12
+
13
+ expect(User.sorcery_config.username_attribute_names).to eq [:email]
10
14
  end
11
15
 
12
- it "should enable configuration option 'password_attribute_name'" do
16
+ it "enables configuration option 'password_attribute_name'" do
13
17
  sorcery_model_property_set(:password_attribute_name, :mypassword)
14
- User.sorcery_config.password_attribute_name.should equal(:mypassword)
18
+
19
+ expect(User.sorcery_config.password_attribute_name).to eq :mypassword
15
20
  end
16
21
 
17
- it "should enable configuration option 'email_attribute_name'" do
22
+ it "enables configuration option 'email_attribute_name'" do
18
23
  sorcery_model_property_set(:email_attribute_name, :my_email)
19
- User.sorcery_config.email_attribute_name.should equal(:my_email)
24
+
25
+ expect(User.sorcery_config.email_attribute_name).to eq :my_email
20
26
  end
21
27
 
22
- it "should enable configuration option 'crypted_password_attribute_name'" do
28
+ it "enables configuration option 'crypted_password_attribute_name'" do
23
29
  sorcery_model_property_set(:crypted_password_attribute_name, :password)
24
- User.sorcery_config.crypted_password_attribute_name.should equal(:password)
30
+
31
+ expect(User.sorcery_config.crypted_password_attribute_name).to eq :password
25
32
  end
26
33
 
27
- it "should enable configuration option 'salt_attribute_name'" do
34
+ it "enables configuration option 'salt_attribute_name'" do
28
35
  sorcery_model_property_set(:salt_attribute_name, :my_salt)
29
- User.sorcery_config.salt_attribute_name.should equal(:my_salt)
36
+
37
+ expect(User.sorcery_config.salt_attribute_name).to eq :my_salt
30
38
  end
31
39
 
32
- it "should enable configuration option 'encryption_algorithm'" do
40
+ it "enables configuration option 'encryption_algorithm'" do
33
41
  sorcery_model_property_set(:encryption_algorithm, :none)
34
- User.sorcery_config.encryption_algorithm.should equal(:none)
42
+
43
+ expect(User.sorcery_config.encryption_algorithm).to eq :none
35
44
  end
36
45
 
37
- it "should enable configuration option 'encryption_key'" do
46
+ it "enables configuration option 'encryption_key'" do
38
47
  sorcery_model_property_set(:encryption_key, 'asdadas424234242')
39
- User.sorcery_config.encryption_key.should == 'asdadas424234242'
48
+
49
+ expect(User.sorcery_config.encryption_key).to eq 'asdadas424234242'
40
50
  end
41
51
 
42
- it "should enable configuration option 'custom_encryption_provider'" do
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
- User.sorcery_config.custom_encryption_provider.should equal(Array)
55
+
56
+ expect(User.sorcery_config.custom_encryption_provider).to eq Array
46
57
  end
47
58
 
48
- it "should enable configuration option 'salt_join_token'" do
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
- User.sorcery_config.salt_join_token.should equal(salt_join_token)
62
+
63
+ expect(User.sorcery_config.salt_join_token).to eq salt_join_token
52
64
  end
53
65
 
54
- it "should enable configuration option 'stretches'" do
66
+ it "enables configuration option 'stretches'" do
55
67
  stretches = 15
56
68
  sorcery_model_property_set(:stretches, stretches)
57
- User.sorcery_config.stretches.should equal(stretches)
69
+
70
+ expect(User.sorcery_config.stretches).to eq stretches
58
71
  end
59
72
  end
60
73
 
61
- # ----------------- PLUGIN ACTIVATED -----------------------
62
- describe User, "when activated with sorcery" do
63
- before(:all) do
64
- sorcery_reload!
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
- before(:each) do
68
- User.delete_all
82
+ it "responds to class method authenticate" do
83
+ expect(User).to respond_to :authenticate
69
84
  end
70
85
 
71
- it "should respond to class method authenticate" do
72
- ActiveRecord::Base.should_not respond_to(:authenticate) if defined?(ActiveRecord)
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
- it "authenticate should return true if credentials are good" do
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 should return false if credentials are bad" do
82
- create_new_user
83
- User.authenticate(@user.send(User.sorcery_config.username_attribute_names.first), 'wrong!').should be_false
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 be_false
108
+ expect(User.authenticate(nil, 'wrong!')).to be_falsy
97
109
  end
98
110
  end
99
111
 
100
- specify { User.should respond_to(:encrypt) }
112
+ specify { expect(User).to respond_to(:encrypt) }
101
113
 
102
- it "subclass should inherit config if defined so" do
114
+ it "subclass inherits config if defined so" do
103
115
  sorcery_reload!([],{:subclasses_inherit_config => true})
104
- class Admin < User
105
- end
106
- Admin.sorcery_config.should_not be_nil
107
- Admin.sorcery_config.should == User.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 should not inherit config if not defined so" do
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
- end
114
- Admin2.sorcery_config.should be_nil
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
- before(:all) do
122
- sorcery_reload!()
123
- end
131
+ describe "registration" do
124
132
 
125
- before(:each) do
126
- User.delete_all
127
- end
133
+ before(:all) { sorcery_reload! }
134
+ before(:each) { User.delete_all }
128
135
 
129
- it "by default, encryption_provider should not be nil" do
130
- User.sorcery_config.encryption_provider.should_not be_nil
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 "should encrypt password when a new user is saved" do
134
- create_new_user
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 "should clear the virtual password field if the encryption process worked" do
139
- create_new_user
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 "should not clear the virtual password field if save failed due to validity" do
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
- @user.password = 'blupush'
149
- @user.email = 'asd'
150
- @user.save
151
- @user.password.should_not be_nil
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 "should not clear the virtual password field if save failed due to exception" do
155
- create_new_user
156
- @user.password = '4blupush'
157
- @user.username = nil
158
- User.class_eval do
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
- @user.save! # triggers validation exception since username field is required.
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
- @user.password.should_not be_nil
173
+
174
+ expect(user.password).not_to be_nil
166
175
  end
167
176
 
168
- it "should not encrypt the password twice when a user is updated" do
169
- create_new_user
170
- @user.email = "blup@bla.com"
171
- @user.save!
172
- User.sorcery_config.encryption_provider.matches?(@user.send(User.sorcery_config.crypted_password_attribute_name),'secret',@user.salt).should be_true
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 "should replace the crypted_password in case a new password is set" do
176
- create_new_user
177
- @user.password = 'new_secret'
178
- @user.save!
179
- User.sorcery_config.encryption_provider.matches?(@user.send(User.sorcery_config.crypted_password_attribute_name),'secret',@user.salt).should be_false
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
- # ----------------- PASSWORD ENCRYPTION -----------------------
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 "should work with no password encryption" do
244
+ it "works with no password encryption" do
200
245
  sorcery_model_property_set(:encryption_algorithm, :none)
201
- create_new_user
202
- User.authenticate(@user.send(User.sorcery_config.username_attribute_names.first), 'secret').should be_true
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 "should work with custom password encryption" do
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
- create_new_user
218
- User.authenticate(@user.send(User.sorcery_config.username_attribute_names.first), 'secret').should be_true
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 should set key to crypto provider" do
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
- expect{User.encrypt(@text)}.to raise_error(ArgumentError)
272
+
273
+ expect { User.encrypt @text }.to raise_error(ArgumentError)
274
+
225
275
  sorcery_model_property_set(:encryption_key, "asd234dfs423fddsmndsflktsdf32343")
226
- expect{User.encrypt(@text)}.to_not raise_error
276
+
277
+ expect { User.encrypt @text }.not_to raise_error
227
278
  end
228
279
 
229
- it "if encryption algo is aes256, it should set key to crypto provider, even if attributes are set in reverse" do
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
- expect{User.encrypt(@text)}.to_not raise_error
285
+
286
+ expect { User.encrypt @text }.not_to raise_error
235
287
  end
236
288
 
237
- it "if encryption algo is md5 it should work" do
289
+ it "if encryption algo is md5 it works" do
238
290
  sorcery_model_property_set(:encryption_algorithm, :md5)
239
- User.encrypt(@text).should == Sorcery::CryptoProviders::MD5.encrypt(@text)
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 should work" do
295
+ it "if encryption algo is sha1 it works" do
243
296
  sorcery_model_property_set(:encryption_algorithm, :sha1)
244
- User.encrypt(@text).should == Sorcery::CryptoProviders::SHA1.encrypt(@text)
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 should work" do
301
+ it "if encryption algo is sha256 it works" do
248
302
  sorcery_model_property_set(:encryption_algorithm, :sha256)
249
- User.encrypt(@text).should == Sorcery::CryptoProviders::SHA256.encrypt(@text)
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 should work" do
307
+ it "if encryption algo is sha512 it works" do
253
308
  sorcery_model_property_set(:encryption_algorithm, :sha512)
254
- User.encrypt(@text).should == Sorcery::CryptoProviders::SHA512.encrypt(@text)
309
+
310
+ expect(User.encrypt @text).to eq Sorcery::CryptoProviders::SHA512.encrypt(@text)
255
311
  end
256
312
 
257
- it "salt should be random for each user and saved in db" do
313
+ it "salt is random for each user and saved in db" do
258
314
  sorcery_model_property_set(:salt_attribute_name, :salt)
259
- create_new_user
260
- @user.salt.should_not be_nil
315
+
316
+ expect(user.salt).not_to be_nil
261
317
  end
262
318
 
263
- it "if salt is set should use it to encrypt" do
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
- create_new_user
267
- @user.crypted_password.should_not == Sorcery::CryptoProviders::SHA512.encrypt('secret')
268
- @user.crypted_password.should == Sorcery::CryptoProviders::SHA512.encrypt('secret',@user.salt)
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 should use it to encrypt" do
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
- create_new_user
276
- @user.crypted_password.should_not == Sorcery::CryptoProviders::SHA512.encrypt('secret')
331
+
332
+ expect(user.crypted_password).not_to eq Sorcery::CryptoProviders::SHA512.encrypt('secret')
333
+
277
334
  Sorcery::CryptoProviders::SHA512.join_token = ""
278
- @user.crypted_password.should_not == Sorcery::CryptoProviders::SHA512.encrypt('secret',@user.salt)
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 User, "ORM adapter" do
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) do
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
- it "find_by_username should work as expected" do
357
+
358
+ it "find_by_username works as expected" do
301
359
  sorcery_model_property_set(:username_attribute_names, [:username])
302
- User.find_by_username("gizmo").should == @user
360
+
361
+ expect(User.find_by_username "gizmo").to eq user
303
362
  end
304
363
 
305
- it "find_by_username should work as expected with multiple username attributes" do
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
- User.find_by_username("gizmo").should == @user
366
+
367
+ expect(User.find_by_username "gizmo").to eq user
308
368
  end
309
369
 
310
- it "find_by_email should work as expected" do
311
- User.find_by_email("bla@bla.com").should == @user
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 "should respond to 'external?'" do
322
- create_new_user
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? should be false for regular users" do
327
- create_new_user
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? should be true for external users" do
332
- create_new_external_user(:twitter)
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