sorcery 0.4.2 → 0.5.0
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.
- data/Gemfile +5 -2
- data/Gemfile.lock +12 -0
- data/README.rdoc +12 -7
- data/VERSION +1 -1
- data/lib/sorcery/controller/submodules/brute_force_protection.rb +1 -1
- data/lib/sorcery/crypto_providers/common.rb +2 -2
- data/lib/sorcery/engine.rb +0 -4
- data/lib/sorcery/initializers/initializer.rb +1 -0
- data/lib/sorcery/model/adapters/active_record.rb +28 -0
- data/lib/sorcery/model/adapters/mongoid.rb +59 -0
- data/lib/sorcery/model/submodules/activity_logging.rb +12 -3
- data/lib/sorcery/model/submodules/brute_force_protection.rb +6 -1
- data/lib/sorcery/model/submodules/external.rb +1 -0
- data/lib/sorcery/model/submodules/remember_me.rb +15 -1
- data/lib/sorcery/model/submodules/reset_password.rb +10 -3
- data/lib/sorcery/model/submodules/user_activation.rb +11 -1
- data/lib/sorcery/model/temporary_token.rb +1 -1
- data/lib/sorcery/model.rb +15 -7
- data/lib/sorcery/sinatra.rb +0 -1
- data/lib/sorcery/test_helpers/internal/sinatra.rb +6 -54
- data/lib/sorcery/test_helpers/internal.rb +2 -1
- data/lib/sorcery/test_helpers/sinatra.rb +4 -1
- data/lib/sorcery.rb +22 -1
- data/sorcery.gemspec +107 -10
- data/spec/Gemfile.lock +1 -1
- data/spec/rails3/Gemfile.lock +5 -5
- data/spec/rails3/spec/user_reset_password_spec.rb +2 -2
- data/spec/rails3/spec/user_spec.rb +0 -1
- data/spec/rails3_mongoid/.gitignore +4 -0
- data/spec/rails3_mongoid/.rspec +1 -0
- data/spec/rails3_mongoid/Gemfile +14 -0
- data/spec/rails3_mongoid/Gemfile.lock +146 -0
- data/spec/rails3_mongoid/Rakefile +11 -0
- data/spec/rails3_mongoid/app/controllers/application_controller.rb +108 -0
- data/spec/rails3_mongoid/app/helpers/application_helper.rb +2 -0
- data/spec/rails3_mongoid/app/mailers/sorcery_mailer.rb +25 -0
- data/spec/rails3_mongoid/app/models/authentication.rb +7 -0
- data/spec/rails3_mongoid/app/models/user.rb +5 -0
- data/spec/rails3_mongoid/app/views/layouts/application.html.erb +14 -0
- data/spec/rails3_mongoid/app/views/sorcery_mailer/activation_email.html.erb +17 -0
- data/spec/rails3_mongoid/app/views/sorcery_mailer/activation_email.text.erb +9 -0
- data/spec/rails3_mongoid/app/views/sorcery_mailer/activation_success_email.html.erb +17 -0
- data/spec/rails3_mongoid/app/views/sorcery_mailer/activation_success_email.text.erb +9 -0
- data/spec/rails3_mongoid/app/views/sorcery_mailer/reset_password_email.html.erb +16 -0
- data/spec/rails3_mongoid/app/views/sorcery_mailer/reset_password_email.text.erb +8 -0
- data/spec/rails3_mongoid/config/application.rb +51 -0
- data/spec/rails3_mongoid/config/boot.rb +13 -0
- data/spec/rails3_mongoid/config/environment.rb +5 -0
- data/spec/rails3_mongoid/config/environments/development.rb +26 -0
- data/spec/rails3_mongoid/config/environments/in_memory.rb +0 -0
- data/spec/rails3_mongoid/config/environments/production.rb +49 -0
- data/spec/rails3_mongoid/config/environments/test.rb +35 -0
- data/spec/rails3_mongoid/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/rails3_mongoid/config/initializers/inflections.rb +10 -0
- data/spec/rails3_mongoid/config/initializers/mime_types.rb +5 -0
- data/spec/rails3_mongoid/config/initializers/secret_token.rb +7 -0
- data/spec/rails3_mongoid/config/initializers/session_store.rb +8 -0
- data/spec/rails3_mongoid/config/locales/en.yml +5 -0
- data/spec/rails3_mongoid/config/mongoid.yml +7 -0
- data/spec/rails3_mongoid/config/routes.rb +59 -0
- data/spec/rails3_mongoid/config.ru +4 -0
- data/spec/rails3_mongoid/db/schema.rb +23 -0
- data/spec/rails3_mongoid/db/seeds.rb +7 -0
- data/spec/rails3_mongoid/lib/tasks/.gitkeep +0 -0
- data/spec/rails3_mongoid/public/404.html +26 -0
- data/spec/rails3_mongoid/public/422.html +26 -0
- data/spec/rails3_mongoid/public/500.html +26 -0
- data/spec/rails3_mongoid/public/favicon.ico +0 -0
- data/spec/rails3_mongoid/public/images/rails.png +0 -0
- data/spec/rails3_mongoid/public/javascripts/application.js +2 -0
- data/spec/rails3_mongoid/public/javascripts/controls.js +965 -0
- data/spec/rails3_mongoid/public/javascripts/dragdrop.js +974 -0
- data/spec/rails3_mongoid/public/javascripts/effects.js +1123 -0
- data/spec/rails3_mongoid/public/javascripts/prototype.js +6001 -0
- data/spec/rails3_mongoid/public/javascripts/rails.js +175 -0
- data/spec/rails3_mongoid/public/robots.txt +5 -0
- data/spec/rails3_mongoid/public/stylesheets/.gitkeep +0 -0
- data/spec/rails3_mongoid/script/rails +6 -0
- data/spec/rails3_mongoid/spec/spec.opts +2 -0
- data/spec/rails3_mongoid/spec/spec_helper.orig.rb +27 -0
- data/spec/rails3_mongoid/spec/spec_helper.rb +55 -0
- data/spec/rails3_mongoid/spec/user_activation_spec.rb +178 -0
- data/spec/rails3_mongoid/spec/user_activity_logging_spec.rb +31 -0
- data/spec/rails3_mongoid/spec/user_brute_force_protection_spec.rb +41 -0
- data/spec/rails3_mongoid/spec/user_oauth_spec.rb +34 -0
- data/spec/rails3_mongoid/spec/user_remember_me_spec.rb +51 -0
- data/spec/rails3_mongoid/spec/user_reset_password_spec.rb +174 -0
- data/spec/rails3_mongoid/spec/user_spec.rb +329 -0
- data/spec/rails3_mongoid/vendor/plugins/.gitkeep +0 -0
- data/spec/sinatra/Gemfile.lock +5 -5
- data/spec/sinatra/spec/spec_helper.rb +0 -1
- metadata +150 -37
- data/spec/untitled folder +0 -18
@@ -0,0 +1,174 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe "User with reset_password submodule" do
|
4
|
+
|
5
|
+
# ----------------- PLUGIN CONFIGURATION -----------------------
|
6
|
+
describe User, "loaded plugin configuration" do
|
7
|
+
|
8
|
+
before(:all) do
|
9
|
+
sorcery_reload!([:reset_password], :reset_password_mailer => ::SorceryMailer)
|
10
|
+
end
|
11
|
+
|
12
|
+
after(:each) do
|
13
|
+
User.sorcery_config.reset!
|
14
|
+
end
|
15
|
+
|
16
|
+
context "API" do
|
17
|
+
before(:all) do
|
18
|
+
create_new_user
|
19
|
+
end
|
20
|
+
|
21
|
+
specify { @user.should respond_to(:deliver_reset_password_instructions!) }
|
22
|
+
|
23
|
+
specify { @user.should respond_to(:reset_password!) }
|
24
|
+
|
25
|
+
it "should respond to .load_from_reset_password_token" do
|
26
|
+
User.should respond_to(:load_from_reset_password_token)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should allow configuration option 'reset_password_token_attribute_name'" do
|
31
|
+
sorcery_model_property_set(:reset_password_token_attribute_name, :my_code)
|
32
|
+
User.sorcery_config.reset_password_token_attribute_name.should equal(:my_code)
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should allow configuration option 'reset_password_mailer'" do
|
36
|
+
sorcery_model_property_set(:reset_password_mailer, TestUser)
|
37
|
+
User.sorcery_config.reset_password_mailer.should equal(TestUser)
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should allow configuration option 'reset_password_email_method_name'" do
|
41
|
+
sorcery_model_property_set(:reset_password_email_method_name, :my_mailer_method)
|
42
|
+
User.sorcery_config.reset_password_email_method_name.should equal(:my_mailer_method)
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should allow configuration option 'reset_password_expiration_period'" do
|
46
|
+
sorcery_model_property_set(:reset_password_expiration_period, 16)
|
47
|
+
User.sorcery_config.reset_password_expiration_period.should equal(16)
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should allow configuration option 'reset_password_email_sent_at_attribute_name'" do
|
51
|
+
sorcery_model_property_set(:reset_password_email_sent_at_attribute_name, :blabla)
|
52
|
+
User.sorcery_config.reset_password_email_sent_at_attribute_name.should equal(:blabla)
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should allow configuration option 'reset_password_time_between_emails'" do
|
56
|
+
sorcery_model_property_set(:reset_password_time_between_emails, 16)
|
57
|
+
User.sorcery_config.reset_password_time_between_emails.should equal(16)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
# ----------------- PLUGIN ACTIVATED -----------------------
|
62
|
+
describe User, "when activated with sorcery" do
|
63
|
+
|
64
|
+
before(:all) do
|
65
|
+
sorcery_reload!([:reset_password], :reset_password_mailer => ::SorceryMailer)
|
66
|
+
end
|
67
|
+
|
68
|
+
before(:each) do
|
69
|
+
User.delete_all
|
70
|
+
end
|
71
|
+
|
72
|
+
after(:each) do
|
73
|
+
Timecop.return
|
74
|
+
end
|
75
|
+
|
76
|
+
it "load_from_reset_password_token should return user when token is found" do
|
77
|
+
create_new_user
|
78
|
+
@user.deliver_reset_password_instructions!
|
79
|
+
User.load_from_reset_password_token(@user.reset_password_token).should == @user
|
80
|
+
end
|
81
|
+
|
82
|
+
it "load_from_reset_password_token should NOT return user when token is NOT found" do
|
83
|
+
create_new_user
|
84
|
+
@user.deliver_reset_password_instructions!
|
85
|
+
User.load_from_reset_password_token("a").should == nil
|
86
|
+
end
|
87
|
+
|
88
|
+
it "load_from_reset_password_token should return user when token is found and not expired" do
|
89
|
+
create_new_user
|
90
|
+
sorcery_model_property_set(:reset_password_expiration_period, 500)
|
91
|
+
@user.deliver_reset_password_instructions!
|
92
|
+
User.load_from_reset_password_token(@user.reset_password_token).should == @user
|
93
|
+
end
|
94
|
+
|
95
|
+
it "load_from_reset_password_token should NOT return user when token is found and expired" do
|
96
|
+
create_new_user
|
97
|
+
sorcery_model_property_set(:reset_password_expiration_period, 0.1)
|
98
|
+
@user.deliver_reset_password_instructions!
|
99
|
+
Timecop.travel(Time.now+0.5)
|
100
|
+
User.load_from_reset_password_token(@user.reset_password_token).should == nil
|
101
|
+
end
|
102
|
+
|
103
|
+
it "load_from_reset_password_token should always be valid if expiration period is nil" do
|
104
|
+
create_new_user
|
105
|
+
sorcery_model_property_set(:reset_password_expiration_period, nil)
|
106
|
+
@user.deliver_reset_password_instructions!
|
107
|
+
User.load_from_reset_password_token(@user.reset_password_token).should == @user
|
108
|
+
end
|
109
|
+
|
110
|
+
it "load_from_reset_password_token should return nil if token is blank" do
|
111
|
+
User.load_from_reset_password_token(nil).should == nil
|
112
|
+
User.load_from_reset_password_token("").should == nil
|
113
|
+
end
|
114
|
+
|
115
|
+
it "'deliver_reset_password_instructions!' should generate a reset_password_token" do
|
116
|
+
create_new_user
|
117
|
+
@user.reset_password_token.should be_nil
|
118
|
+
@user.deliver_reset_password_instructions!
|
119
|
+
@user.reset_password_token.should_not be_nil
|
120
|
+
end
|
121
|
+
|
122
|
+
it "the reset_password_token should be random" do
|
123
|
+
create_new_user
|
124
|
+
sorcery_model_property_set(:reset_password_time_between_emails, 0)
|
125
|
+
@user.deliver_reset_password_instructions!
|
126
|
+
old_password_code = @user.reset_password_token
|
127
|
+
@user.deliver_reset_password_instructions!
|
128
|
+
@user.reset_password_token.should_not == old_password_code
|
129
|
+
end
|
130
|
+
|
131
|
+
it "should send an email on reset" do
|
132
|
+
create_new_user
|
133
|
+
old_size = ActionMailer::Base.deliveries.size
|
134
|
+
@user.deliver_reset_password_instructions!
|
135
|
+
ActionMailer::Base.deliveries.size.should == old_size + 1
|
136
|
+
end
|
137
|
+
|
138
|
+
it "when reset_password! is called, should delete reset_password_token" do
|
139
|
+
create_new_user
|
140
|
+
@user.deliver_reset_password_instructions!
|
141
|
+
@user.reset_password_token.should_not be_nil
|
142
|
+
@user.change_password!("blabulsdf")
|
143
|
+
@user.save!
|
144
|
+
@user.reset_password_token.should be_nil
|
145
|
+
end
|
146
|
+
|
147
|
+
it "should not send an email if time between emails has not passed since last email" do
|
148
|
+
create_new_user
|
149
|
+
sorcery_model_property_set(:reset_password_time_between_emails, 10000)
|
150
|
+
old_size = ActionMailer::Base.deliveries.size
|
151
|
+
@user.deliver_reset_password_instructions!
|
152
|
+
ActionMailer::Base.deliveries.size.should == old_size + 1
|
153
|
+
@user.deliver_reset_password_instructions!
|
154
|
+
ActionMailer::Base.deliveries.size.should == old_size + 1
|
155
|
+
end
|
156
|
+
|
157
|
+
it "should send an email if time between emails has passed since last email" do
|
158
|
+
create_new_user
|
159
|
+
sorcery_model_property_set(:reset_password_time_between_emails, 0.5)
|
160
|
+
old_size = ActionMailer::Base.deliveries.size
|
161
|
+
@user.deliver_reset_password_instructions!
|
162
|
+
ActionMailer::Base.deliveries.size.should == old_size + 1
|
163
|
+
Timecop.travel(Time.now+0.5)
|
164
|
+
@user.deliver_reset_password_instructions!
|
165
|
+
ActionMailer::Base.deliveries.size.should == old_size + 2
|
166
|
+
end
|
167
|
+
|
168
|
+
it "if mailer is nil on activation, throw exception!" do
|
169
|
+
expect{sorcery_reload!([:reset_password])}.to raise_error(ArgumentError)
|
170
|
+
end
|
171
|
+
|
172
|
+
end
|
173
|
+
|
174
|
+
end
|
@@ -0,0 +1,329 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
require File.expand_path(File.dirname(__FILE__) + '/../app/mailers/sorcery_mailer')
|
3
|
+
|
4
|
+
describe "User with no submodules (core)" do
|
5
|
+
before(:all) do
|
6
|
+
sorcery_reload!
|
7
|
+
end
|
8
|
+
|
9
|
+
describe User, "when app has plugin loaded" do
|
10
|
+
it "User should respond_to .authenticates_with_sorcery!" do
|
11
|
+
User.should respond_to(:authenticates_with_sorcery!)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
# ----------------- PLUGIN ACTIVATION -----------------------
|
16
|
+
describe TestUser, "Testing activated class self-registration" do
|
17
|
+
it "should register itself as user_class if activated" do
|
18
|
+
TestUser.class_eval do
|
19
|
+
authenticates_with_sorcery!
|
20
|
+
end
|
21
|
+
::Sorcery::Controller::Config.user_class.should == TestUser
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
# ----------------- PLUGIN CONFIGURATION -----------------------
|
26
|
+
describe User, "loaded plugin configuration" do
|
27
|
+
after(:each) do
|
28
|
+
User.sorcery_config.reset!
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should enable configuration option 'username_attribute_name'" do
|
32
|
+
sorcery_model_property_set(:username_attribute_name, :email)
|
33
|
+
User.sorcery_config.username_attribute_name.should equal(:email)
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should enable configuration option 'password_attribute_name'" do
|
37
|
+
sorcery_model_property_set(:password_attribute_name, :mypassword)
|
38
|
+
User.sorcery_config.password_attribute_name.should equal(:mypassword)
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should enable configuration option 'email_attribute_name'" do
|
42
|
+
sorcery_model_property_set(:email_attribute_name, :my_email)
|
43
|
+
User.sorcery_config.email_attribute_name.should equal(:my_email)
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should enable configuration option 'crypted_password_attribute_name'" do
|
47
|
+
sorcery_model_property_set(:crypted_password_attribute_name, :password)
|
48
|
+
User.sorcery_config.crypted_password_attribute_name.should equal(:password)
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should enable configuration option 'salt_attribute_name'" do
|
52
|
+
sorcery_model_property_set(:salt_attribute_name, :my_salt)
|
53
|
+
User.sorcery_config.salt_attribute_name.should equal(:my_salt)
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should enable configuration option 'encryption_algorithm'" do
|
57
|
+
sorcery_model_property_set(:encryption_algorithm, :none)
|
58
|
+
User.sorcery_config.encryption_algorithm.should equal(:none)
|
59
|
+
end
|
60
|
+
|
61
|
+
it "should enable configuration option 'encryption_key'" do
|
62
|
+
sorcery_model_property_set(:encryption_key, 'asdadas424234242')
|
63
|
+
User.sorcery_config.encryption_key.should == 'asdadas424234242'
|
64
|
+
end
|
65
|
+
|
66
|
+
it "should enable configuration option 'custom_encryption_provider'" do
|
67
|
+
sorcery_model_property_set(:encryption_algorithm, :custom)
|
68
|
+
sorcery_model_property_set(:custom_encryption_provider, Array)
|
69
|
+
User.sorcery_config.custom_encryption_provider.should equal(Array)
|
70
|
+
end
|
71
|
+
|
72
|
+
it "should enable configuration option 'salt_join_token'" do
|
73
|
+
salt_join_token = "--%%*&-"
|
74
|
+
sorcery_model_property_set(:salt_join_token, salt_join_token)
|
75
|
+
User.sorcery_config.salt_join_token.should equal(salt_join_token)
|
76
|
+
end
|
77
|
+
|
78
|
+
it "should enable configuration option 'stretches'" do
|
79
|
+
stretches = 15
|
80
|
+
sorcery_model_property_set(:stretches, stretches)
|
81
|
+
User.sorcery_config.stretches.should equal(stretches)
|
82
|
+
end
|
83
|
+
|
84
|
+
end
|
85
|
+
|
86
|
+
# ----------------- PLUGIN ACTIVATED -----------------------
|
87
|
+
describe User, "when activated with sorcery" do
|
88
|
+
before(:all) do
|
89
|
+
sorcery_reload!()
|
90
|
+
end
|
91
|
+
|
92
|
+
before(:each) do
|
93
|
+
User.delete_all
|
94
|
+
end
|
95
|
+
|
96
|
+
it "should respond to class method authenticate" do
|
97
|
+
User.should respond_to(:authenticate)
|
98
|
+
end
|
99
|
+
|
100
|
+
it "authenticate should return true if credentials are good" do
|
101
|
+
create_new_user
|
102
|
+
User.authenticate(@user.send(User.sorcery_config.username_attribute_name), 'secret').should be_true
|
103
|
+
end
|
104
|
+
|
105
|
+
it "authenticate should return false if credentials are bad" do
|
106
|
+
create_new_user
|
107
|
+
User.authenticate(@user.send(User.sorcery_config.username_attribute_name), 'wrong!').should be_false
|
108
|
+
end
|
109
|
+
|
110
|
+
specify { User.should respond_to(:encrypt) }
|
111
|
+
|
112
|
+
it "subclass should inherit config if defined so" do
|
113
|
+
sorcery_reload!([],{:subclasses_inherit_config => true})
|
114
|
+
class Admin < User
|
115
|
+
end
|
116
|
+
Admin.sorcery_config.should_not be_nil
|
117
|
+
Admin.sorcery_config.should == User.sorcery_config
|
118
|
+
end
|
119
|
+
|
120
|
+
it "subclass should not inherit config if not defined so" do
|
121
|
+
sorcery_reload!([],{:subclasses_inherit_config => false})
|
122
|
+
class Admin2 < User
|
123
|
+
end
|
124
|
+
Admin2.sorcery_config.should be_nil
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
# ----------------- REGISTRATION -----------------------
|
129
|
+
describe User, "registration" do
|
130
|
+
|
131
|
+
before(:all) do
|
132
|
+
sorcery_reload!()
|
133
|
+
end
|
134
|
+
|
135
|
+
before(:each) do
|
136
|
+
User.delete_all
|
137
|
+
end
|
138
|
+
|
139
|
+
it "by default, encryption_provider should not be nil" do
|
140
|
+
User.sorcery_config.encryption_provider.should_not be_nil
|
141
|
+
end
|
142
|
+
|
143
|
+
it "should encrypt password when a new user is saved" do
|
144
|
+
create_new_user
|
145
|
+
User.sorcery_config.encryption_provider.matches?(@user.send(User.sorcery_config.crypted_password_attribute_name),'secret',@user.salt).should be_true
|
146
|
+
end
|
147
|
+
|
148
|
+
it "should clear the virtual password field if the encryption process worked" do
|
149
|
+
create_new_user
|
150
|
+
@user.password.should be_nil
|
151
|
+
end
|
152
|
+
|
153
|
+
it "should not clear the virtual password field if save failed due to validity" do
|
154
|
+
create_new_user
|
155
|
+
User.class_eval do
|
156
|
+
validates_format_of :email, :with => /^(.)+@(.)+$/, :if => Proc.new {|r| r.email}, :message => "is invalid"
|
157
|
+
end
|
158
|
+
@user.password = 'blupush'
|
159
|
+
@user.email = 'asd'
|
160
|
+
@user.save
|
161
|
+
@user.password.should_not be_nil
|
162
|
+
end
|
163
|
+
|
164
|
+
it "should not clear the virtual password field if save failed due to exception" do
|
165
|
+
create_new_user
|
166
|
+
@user.password = '4blupush'
|
167
|
+
@user.username = nil
|
168
|
+
User.class_eval do
|
169
|
+
validates_presence_of :username
|
170
|
+
end
|
171
|
+
begin
|
172
|
+
@user.save! # triggers validation exception since username field is required.
|
173
|
+
rescue
|
174
|
+
end
|
175
|
+
@user.password.should_not be_nil
|
176
|
+
end
|
177
|
+
|
178
|
+
it "should not encrypt the password twice when a user is updated" do
|
179
|
+
create_new_user
|
180
|
+
@user.email = "blup@bla.com"
|
181
|
+
@user.save!
|
182
|
+
User.sorcery_config.encryption_provider.matches?(@user.send(User.sorcery_config.crypted_password_attribute_name),'secret',@user.salt).should be_true
|
183
|
+
end
|
184
|
+
|
185
|
+
it "should replace the crypted_password in case a new password is set" do
|
186
|
+
create_new_user
|
187
|
+
@user.password = 'new_secret'
|
188
|
+
@user.save!
|
189
|
+
User.sorcery_config.encryption_provider.matches?(@user.send(User.sorcery_config.crypted_password_attribute_name),'secret',@user.salt).should be_false
|
190
|
+
end
|
191
|
+
|
192
|
+
end
|
193
|
+
|
194
|
+
# ----------------- PASSWORD ENCRYPTION -----------------------
|
195
|
+
describe User, "special encryption cases" do
|
196
|
+
before(:all) do
|
197
|
+
|
198
|
+
@text = "Some Text!"
|
199
|
+
end
|
200
|
+
|
201
|
+
before(:each) do
|
202
|
+
User.delete_all
|
203
|
+
sorcery_reload!()
|
204
|
+
end
|
205
|
+
|
206
|
+
after(:each) do
|
207
|
+
User.sorcery_config.reset!
|
208
|
+
end
|
209
|
+
|
210
|
+
it "should work with no password encryption" do
|
211
|
+
sorcery_model_property_set(:encryption_algorithm, :none)
|
212
|
+
create_new_user
|
213
|
+
User.authenticate(@user.send(User.sorcery_config.username_attribute_name), 'secret').should be_true
|
214
|
+
end
|
215
|
+
|
216
|
+
it "should work with custom password encryption" do
|
217
|
+
class MyCrypto
|
218
|
+
def self.encrypt(*tokens)
|
219
|
+
tokens.flatten.compact.join('').gsub(/e/,'A')
|
220
|
+
end
|
221
|
+
|
222
|
+
def self.matches?(crypted,*tokens)
|
223
|
+
crypted == encrypt(*tokens)
|
224
|
+
end
|
225
|
+
end
|
226
|
+
sorcery_model_property_set(:encryption_algorithm, :custom)
|
227
|
+
sorcery_model_property_set(:custom_encryption_provider, MyCrypto)
|
228
|
+
create_new_user
|
229
|
+
User.authenticate(@user.send(User.sorcery_config.username_attribute_name), 'secret').should be_true
|
230
|
+
end
|
231
|
+
|
232
|
+
it "if encryption algo is aes256, it should set key to crypto provider" do
|
233
|
+
sorcery_model_property_set(:encryption_algorithm, :aes256)
|
234
|
+
sorcery_model_property_set(:encryption_key, nil)
|
235
|
+
expect{User.encrypt(@text)}.to raise_error(ArgumentError)
|
236
|
+
sorcery_model_property_set(:encryption_key, "asd234dfs423fddsmndsflktsdf32343")
|
237
|
+
expect{User.encrypt(@text)}.to_not raise_error(ArgumentError)
|
238
|
+
end
|
239
|
+
|
240
|
+
it "if encryption algo is aes256, it should set key to crypto provider, even if attributes are set in reverse" do
|
241
|
+
sorcery_model_property_set(:encryption_key, nil)
|
242
|
+
sorcery_model_property_set(:encryption_algorithm, :none)
|
243
|
+
sorcery_model_property_set(:encryption_key, "asd234dfs423fddsmndsflktsdf32343")
|
244
|
+
sorcery_model_property_set(:encryption_algorithm, :aes256)
|
245
|
+
expect{User.encrypt(@text)}.to_not raise_error(ArgumentError)
|
246
|
+
end
|
247
|
+
|
248
|
+
it "if encryption algo is md5 it should work" do
|
249
|
+
sorcery_model_property_set(:encryption_algorithm, :md5)
|
250
|
+
User.encrypt(@text).should == Sorcery::CryptoProviders::MD5.encrypt(@text)
|
251
|
+
end
|
252
|
+
|
253
|
+
it "if encryption algo is sha1 it should work" do
|
254
|
+
sorcery_model_property_set(:encryption_algorithm, :sha1)
|
255
|
+
User.encrypt(@text).should == Sorcery::CryptoProviders::SHA1.encrypt(@text)
|
256
|
+
end
|
257
|
+
|
258
|
+
it "if encryption algo is sha256 it should work" do
|
259
|
+
sorcery_model_property_set(:encryption_algorithm, :sha256)
|
260
|
+
User.encrypt(@text).should == Sorcery::CryptoProviders::SHA256.encrypt(@text)
|
261
|
+
end
|
262
|
+
|
263
|
+
it "if encryption algo is sha512 it should work" do
|
264
|
+
sorcery_model_property_set(:encryption_algorithm, :sha512)
|
265
|
+
User.encrypt(@text).should == Sorcery::CryptoProviders::SHA512.encrypt(@text)
|
266
|
+
end
|
267
|
+
|
268
|
+
it "salt should be random for each user and saved in db" do
|
269
|
+
sorcery_model_property_set(:salt_attribute_name, :salt)
|
270
|
+
create_new_user
|
271
|
+
@user.salt.should_not be_nil
|
272
|
+
end
|
273
|
+
|
274
|
+
it "if salt is set should use it to encrypt" do
|
275
|
+
sorcery_model_property_set(:salt_attribute_name, :salt)
|
276
|
+
sorcery_model_property_set(:encryption_algorithm, :sha512)
|
277
|
+
create_new_user
|
278
|
+
@user.crypted_password.should_not == Sorcery::CryptoProviders::SHA512.encrypt('secret')
|
279
|
+
@user.crypted_password.should == Sorcery::CryptoProviders::SHA512.encrypt('secret',@user.salt)
|
280
|
+
end
|
281
|
+
|
282
|
+
it "if salt_join_token is set should use it to encrypt" do
|
283
|
+
sorcery_model_property_set(:salt_attribute_name, :salt)
|
284
|
+
sorcery_model_property_set(:salt_join_token, "-@=>")
|
285
|
+
sorcery_model_property_set(:encryption_algorithm, :sha512)
|
286
|
+
create_new_user
|
287
|
+
@user.crypted_password.should_not == Sorcery::CryptoProviders::SHA512.encrypt('secret')
|
288
|
+
Sorcery::CryptoProviders::SHA512.join_token = ""
|
289
|
+
@user.crypted_password.should_not == Sorcery::CryptoProviders::SHA512.encrypt('secret')
|
290
|
+
Sorcery::CryptoProviders::SHA512.join_token = User.sorcery_config.salt_join_token
|
291
|
+
@user.crypted_password.should == Sorcery::CryptoProviders::SHA512.encrypt('secret',@user.salt)
|
292
|
+
end
|
293
|
+
|
294
|
+
end
|
295
|
+
|
296
|
+
describe User, "external users" do
|
297
|
+
|
298
|
+
before(:each) do
|
299
|
+
User.delete_all
|
300
|
+
end
|
301
|
+
|
302
|
+
it "should respond to 'external?'" do
|
303
|
+
create_new_user
|
304
|
+
@user.should respond_to(:external?)
|
305
|
+
end
|
306
|
+
|
307
|
+
it "external? should be false for regular users" do
|
308
|
+
create_new_user
|
309
|
+
@user.external?.should be_false
|
310
|
+
end
|
311
|
+
|
312
|
+
it "external? should be true for external users" do
|
313
|
+
create_new_external_user(:twitter)
|
314
|
+
@user.external?.should be_true
|
315
|
+
end
|
316
|
+
end
|
317
|
+
|
318
|
+
describe User, "when inherited" do
|
319
|
+
it "should inherit mongoid fields" do
|
320
|
+
User.class_eval do
|
321
|
+
field :blabla
|
322
|
+
end
|
323
|
+
class SubUser < User
|
324
|
+
end
|
325
|
+
|
326
|
+
SubUser.fields.should include("blabla")
|
327
|
+
end
|
328
|
+
end
|
329
|
+
end
|
File without changes
|
data/spec/sinatra/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: ../../
|
3
3
|
specs:
|
4
|
-
sorcery (0.
|
4
|
+
sorcery (0.5.0)
|
5
5
|
bcrypt-ruby (~> 2.1.4)
|
6
6
|
json (>= 1.5.1)
|
7
7
|
oauth (>= 0.4.4)
|
@@ -63,12 +63,12 @@ GEM
|
|
63
63
|
mime-types (~> 1.16)
|
64
64
|
treetop (~> 1.4.8)
|
65
65
|
mime-types (1.16)
|
66
|
-
multi_json (
|
66
|
+
multi_json (1.0.1)
|
67
67
|
multipart-post (1.1.0)
|
68
68
|
oauth (0.4.4)
|
69
|
-
oauth2 (0.4.
|
70
|
-
faraday (~> 0.6.
|
71
|
-
multi_json (
|
69
|
+
oauth2 (0.4.1)
|
70
|
+
faraday (~> 0.6.1)
|
71
|
+
multi_json (>= 0.0.5)
|
72
72
|
polyglot (0.3.1)
|
73
73
|
rack (1.2.1)
|
74
74
|
rack-mount (0.6.14)
|
@@ -20,7 +20,6 @@ end
|
|
20
20
|
|
21
21
|
Rspec.configure do |config|
|
22
22
|
config.send(:include, RSpecMixinExample)
|
23
|
-
config.send(:include, ::Sorcery::TestHelpers::Sinatra)
|
24
23
|
config.send(:include, ::Sorcery::TestHelpers::Internal)
|
25
24
|
config.send(:include, ::Sorcery::TestHelpers::Internal::Sinatra)
|
26
25
|
config.before(:suite) do
|