sorcery 0.1.4 → 0.2.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.
Potentially problematic release.
This version of sorcery might be problematic. Click here for more details.
- data/Gemfile +4 -2
- data/Gemfile.lock +16 -13
- data/README.rdoc +28 -27
- data/Rakefile +5 -0
- data/VERSION +1 -1
- data/lib/sorcery.rb +12 -0
- data/lib/sorcery/controller.rb +29 -17
- data/lib/sorcery/controller/submodules/activity_logging.rb +20 -7
- data/lib/sorcery/controller/submodules/brute_force_protection.rb +9 -2
- data/lib/sorcery/controller/submodules/http_basic_auth.rb +8 -3
- data/lib/sorcery/controller/submodules/oauth.rb +95 -0
- data/lib/sorcery/controller/submodules/oauth/oauth1.rb +25 -0
- data/lib/sorcery/controller/submodules/oauth/oauth2.rb +23 -0
- data/lib/sorcery/controller/submodules/oauth/providers/facebook.rb +64 -0
- data/lib/sorcery/controller/submodules/oauth/providers/twitter.rb +61 -0
- data/lib/sorcery/controller/submodules/remember_me.rb +14 -5
- data/lib/sorcery/controller/submodules/session_timeout.rb +6 -1
- data/lib/sorcery/engine.rb +9 -2
- data/lib/sorcery/model.rb +10 -3
- data/lib/sorcery/model/submodules/activity_logging.rb +12 -7
- data/lib/sorcery/model/submodules/brute_force_protection.rb +11 -4
- data/lib/sorcery/model/submodules/oauth.rb +53 -0
- data/lib/sorcery/model/submodules/remember_me.rb +5 -3
- data/lib/sorcery/model/submodules/reset_password.rb +16 -13
- data/lib/sorcery/model/submodules/user_activation.rb +38 -19
- data/lib/sorcery/model/temporary_token.rb +22 -0
- data/lib/sorcery/test_helpers.rb +84 -0
- data/sorcery.gemspec +69 -40
- data/spec/Gemfile +3 -2
- data/spec/Gemfile.lock +15 -2
- data/spec/rails3/app_root/.rspec +1 -0
- data/spec/rails3/{Gemfile → app_root/Gemfile} +5 -3
- data/spec/rails3/{Gemfile.lock → app_root/Gemfile.lock} +25 -2
- data/spec/rails3/{Rakefile → app_root/Rakefile} +0 -0
- data/spec/rails3/app_root/app/controllers/application_controller.rb +42 -1
- data/spec/rails3/app_root/app/models/authentication.rb +3 -0
- data/spec/rails3/app_root/app/models/user.rb +4 -1
- data/spec/rails3/app_root/config/application.rb +1 -3
- data/spec/rails3/app_root/config/routes.rb +1 -10
- data/spec/rails3/app_root/db/migrate/activation/20101224223622_add_activation_to_users.rb +6 -4
- data/spec/rails3/app_root/db/migrate/core/20101224223620_create_users.rb +4 -4
- data/spec/rails3/app_root/db/migrate/oauth/20101224223628_create_authentications.rb +14 -0
- data/spec/rails3/{controller_activity_logging_spec.rb → app_root/spec/controller_activity_logging_spec.rb} +13 -13
- data/spec/rails3/{controller_brute_force_protection_spec.rb → app_root/spec/controller_brute_force_protection_spec.rb} +16 -6
- data/spec/rails3/{controller_http_basic_auth_spec.rb → app_root/spec/controller_http_basic_auth_spec.rb} +3 -3
- data/spec/rails3/app_root/spec/controller_oauth2_spec.rb +117 -0
- data/spec/rails3/app_root/spec/controller_oauth_spec.rb +117 -0
- data/spec/rails3/{controller_remember_me_spec.rb → app_root/spec/controller_remember_me_spec.rb} +4 -4
- data/spec/rails3/{controller_session_timeout_spec.rb → app_root/spec/controller_session_timeout_spec.rb} +4 -4
- data/spec/rails3/{controller_spec.rb → app_root/spec/controller_spec.rb} +20 -13
- data/spec/rails3/app_root/spec/spec_helper.orig.rb +27 -0
- data/spec/rails3/app_root/spec/spec_helper.rb +61 -0
- data/spec/rails3/{user_activation_spec.rb → app_root/spec/user_activation_spec.rb} +60 -20
- data/spec/rails3/{user_activity_logging_spec.rb → app_root/spec/user_activity_logging_spec.rb} +4 -4
- data/spec/rails3/{user_brute_force_protection_spec.rb → app_root/spec/user_brute_force_protection_spec.rb} +7 -7
- data/spec/rails3/app_root/spec/user_oauth_spec.rb +39 -0
- data/spec/rails3/{user_remember_me_spec.rb → app_root/spec/user_remember_me_spec.rb} +4 -4
- data/spec/rails3/{user_reset_password_spec.rb → app_root/spec/user_reset_password_spec.rb} +21 -41
- data/spec/rails3/{user_spec.rb → app_root/spec/user_spec.rb} +68 -38
- metadata +127 -58
- data/spec/rails3/app_root/test/fixtures/users.yml +0 -9
- data/spec/rails3/app_root/test/performance/browsing_test.rb +0 -9
- data/spec/rails3/app_root/test/test_helper.rb +0 -13
- data/spec/rails3/app_root/test/unit/user_test.rb +0 -8
- data/spec/rails3/spec_helper.rb +0 -135
@@ -0,0 +1,39 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe "User with oauth submodule" do
|
4
|
+
before(:all) do
|
5
|
+
ActiveRecord::Migrator.migrate("#{Rails.root}/db/migrate/oauth")
|
6
|
+
end
|
7
|
+
|
8
|
+
after(:all) do
|
9
|
+
ActiveRecord::Migrator.rollback("#{Rails.root}/db/migrate/oauth")
|
10
|
+
end
|
11
|
+
|
12
|
+
# ----------------- PLUGIN CONFIGURATION -----------------------
|
13
|
+
describe User, "loaded plugin configuration" do
|
14
|
+
|
15
|
+
before(:all) do
|
16
|
+
sorcery_reload!([:oauth])
|
17
|
+
sorcery_controller_property_set(:oauth_providers, [:twitter])
|
18
|
+
sorcery_model_property_set(:authentications_class, Authentication)
|
19
|
+
sorcery_controller_oauth_property_set(:twitter, :key, "eYVNBjBDi33aa9GkA3w")
|
20
|
+
sorcery_controller_oauth_property_set(:twitter, :secret, "XpbeSdCoaKSmQGSeokz5qcUATClRW5u08QWNfv71N8")
|
21
|
+
sorcery_controller_oauth_property_set(:twitter, :callback_url, "http://blabla.com")
|
22
|
+
create_new_external_user(:twitter)
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should respond to 'load_from_provider'" do
|
26
|
+
User.should respond_to(:load_from_provider)
|
27
|
+
end
|
28
|
+
|
29
|
+
it "'load_from_provider' should load user if exists" do
|
30
|
+
User.load_from_provider(:twitter,123).should == @user
|
31
|
+
end
|
32
|
+
|
33
|
+
it "'load_from_provider' should return nil if user doesn't exist" do
|
34
|
+
User.load_from_provider(:twitter,980342).should be_nil
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
@@ -12,7 +12,7 @@ describe "User with remember_me submodule" do
|
|
12
12
|
# ----------------- PLUGIN CONFIGURATION -----------------------
|
13
13
|
describe User, "loaded plugin configuration" do
|
14
14
|
before(:all) do
|
15
|
-
|
15
|
+
sorcery_reload!([:remember_me])
|
16
16
|
end
|
17
17
|
|
18
18
|
after(:each) do
|
@@ -20,12 +20,12 @@ describe "User with remember_me submodule" do
|
|
20
20
|
end
|
21
21
|
|
22
22
|
it "should allow configuration option 'remember_me_token_attribute_name'" do
|
23
|
-
|
23
|
+
sorcery_model_property_set(:remember_me_token_attribute_name, :my_token)
|
24
24
|
User.sorcery_config.remember_me_token_attribute_name.should equal(:my_token)
|
25
25
|
end
|
26
26
|
|
27
27
|
it "should allow configuration option 'remember_me_token_expires_at_attribute_name'" do
|
28
|
-
|
28
|
+
sorcery_model_property_set(:remember_me_token_expires_at_attribute_name, :my_expires)
|
29
29
|
User.sorcery_config.remember_me_token_expires_at_attribute_name.should equal(:my_expires)
|
30
30
|
end
|
31
31
|
|
@@ -48,7 +48,7 @@ describe "User with remember_me submodule" do
|
|
48
48
|
|
49
49
|
it "should set an expiration based on 'remember_me_for' attribute" do
|
50
50
|
create_new_user
|
51
|
-
|
51
|
+
sorcery_model_property_set(:remember_me_for, 2 * 60 * 60 * 24)
|
52
52
|
@user.remember_me!
|
53
53
|
@user.remember_me_token_expires_at.to_s.should == (Time.now + 2 * 60 * 60 * 24).utc.to_s
|
54
54
|
end
|
@@ -13,7 +13,7 @@ describe "User with reset_password submodule" do
|
|
13
13
|
describe User, "loaded plugin configuration" do
|
14
14
|
|
15
15
|
before(:all) do
|
16
|
-
|
16
|
+
sorcery_reload!([:reset_password], :reset_password_mailer => ::SorceryMailer)
|
17
17
|
end
|
18
18
|
|
19
19
|
after(:each) do
|
@@ -25,11 +25,6 @@ describe "User with reset_password submodule" do
|
|
25
25
|
@user.should respond_to(:deliver_reset_password_instructions!)
|
26
26
|
end
|
27
27
|
|
28
|
-
it "should respond to 'reset_password_token_valid?'" do
|
29
|
-
create_new_user
|
30
|
-
@user.should respond_to(:reset_password_token_valid?)
|
31
|
-
end
|
32
|
-
|
33
28
|
it "should respond to 'reset_password!" do
|
34
29
|
create_new_user
|
35
30
|
@user.should respond_to(:reset_password!)
|
@@ -41,32 +36,32 @@ describe "User with reset_password submodule" do
|
|
41
36
|
end
|
42
37
|
|
43
38
|
it "should allow configuration option 'reset_password_token_attribute_name'" do
|
44
|
-
|
39
|
+
sorcery_model_property_set(:reset_password_token_attribute_name, :my_code)
|
45
40
|
User.sorcery_config.reset_password_token_attribute_name.should equal(:my_code)
|
46
41
|
end
|
47
42
|
|
48
43
|
it "should allow configuration option 'reset_password_mailer'" do
|
49
|
-
|
44
|
+
sorcery_model_property_set(:reset_password_mailer, TestUser)
|
50
45
|
User.sorcery_config.reset_password_mailer.should equal(TestUser)
|
51
46
|
end
|
52
47
|
|
53
48
|
it "should allow configuration option 'reset_password_email_method_name'" do
|
54
|
-
|
49
|
+
sorcery_model_property_set(:reset_password_email_method_name, :my_mailer_method)
|
55
50
|
User.sorcery_config.reset_password_email_method_name.should equal(:my_mailer_method)
|
56
51
|
end
|
57
52
|
|
58
53
|
it "should allow configuration option 'reset_password_expiration_period'" do
|
59
|
-
|
54
|
+
sorcery_model_property_set(:reset_password_expiration_period, 16)
|
60
55
|
User.sorcery_config.reset_password_expiration_period.should equal(16)
|
61
56
|
end
|
62
57
|
|
63
58
|
it "should allow configuration option 'reset_password_email_sent_at_attribute_name'" do
|
64
|
-
|
59
|
+
sorcery_model_property_set(:reset_password_email_sent_at_attribute_name, :blabla)
|
65
60
|
User.sorcery_config.reset_password_email_sent_at_attribute_name.should equal(:blabla)
|
66
61
|
end
|
67
62
|
|
68
63
|
it "should allow configuration option 'reset_password_time_between_emails'" do
|
69
|
-
|
64
|
+
sorcery_model_property_set(:reset_password_time_between_emails, 16)
|
70
65
|
User.sorcery_config.reset_password_time_between_emails.should equal(16)
|
71
66
|
end
|
72
67
|
end
|
@@ -75,7 +70,7 @@ describe "User with reset_password submodule" do
|
|
75
70
|
describe User, "when activated with sorcery" do
|
76
71
|
|
77
72
|
before(:all) do
|
78
|
-
|
73
|
+
sorcery_reload!([:reset_password], :reset_password_mailer => ::SorceryMailer)
|
79
74
|
end
|
80
75
|
|
81
76
|
before(:each) do
|
@@ -96,19 +91,26 @@ describe "User with reset_password submodule" do
|
|
96
91
|
|
97
92
|
it "load_from_reset_password_token should return user when token is found and not expired" do
|
98
93
|
create_new_user
|
99
|
-
|
94
|
+
sorcery_model_property_set(:reset_password_expiration_period, 500)
|
100
95
|
@user.deliver_reset_password_instructions!
|
101
96
|
User.load_from_reset_password_token(@user.reset_password_token).should == @user
|
102
97
|
end
|
103
98
|
|
104
99
|
it "load_from_reset_password_token should NOT return user when token is found and expired" do
|
105
100
|
create_new_user
|
106
|
-
|
101
|
+
sorcery_model_property_set(:reset_password_expiration_period, 0.1)
|
107
102
|
@user.deliver_reset_password_instructions!
|
108
103
|
sleep 0.5
|
109
104
|
User.load_from_reset_password_token(@user.reset_password_token).should == nil
|
110
105
|
end
|
111
106
|
|
107
|
+
it "load_from_reset_password_token should always be valid if expiration period is nil" do
|
108
|
+
create_new_user
|
109
|
+
sorcery_model_property_set(:reset_password_expiration_period, nil)
|
110
|
+
@user.deliver_reset_password_instructions!
|
111
|
+
User.load_from_reset_password_token(@user.reset_password_token).should == @user
|
112
|
+
end
|
113
|
+
|
112
114
|
it "load_from_reset_password_token should return nil if token is blank" do
|
113
115
|
User.load_from_reset_password_token(nil).should == nil
|
114
116
|
User.load_from_reset_password_token("").should == nil
|
@@ -123,7 +125,7 @@ describe "User with reset_password submodule" do
|
|
123
125
|
|
124
126
|
it "the reset_password_token should be random" do
|
125
127
|
create_new_user
|
126
|
-
|
128
|
+
sorcery_model_property_set(:reset_password_time_between_emails, 0)
|
127
129
|
@user.deliver_reset_password_instructions!
|
128
130
|
old_password_code = @user.reset_password_token
|
129
131
|
@user.deliver_reset_password_instructions!
|
@@ -146,31 +148,9 @@ describe "User with reset_password submodule" do
|
|
146
148
|
@user.reset_password_token.should be_nil
|
147
149
|
end
|
148
150
|
|
149
|
-
it "code isn't valid if expiration passed" do
|
150
|
-
create_new_user
|
151
|
-
plugin_set_model_config_property(:reset_password_expiration_period, 0.1)
|
152
|
-
@user.deliver_reset_password_instructions!
|
153
|
-
sleep 0.5
|
154
|
-
@user.reset_password_token_valid?.should == false
|
155
|
-
end
|
156
|
-
|
157
|
-
it "code is valid if it's the same code and expiration period did not pass" do
|
158
|
-
create_new_user
|
159
|
-
plugin_set_model_config_property(:reset_password_expiration_period, 300)
|
160
|
-
@user.deliver_reset_password_instructions!
|
161
|
-
@user.reset_password_token_valid?.should == true
|
162
|
-
end
|
163
|
-
|
164
|
-
it "code is valid if it's the same code and expiration period is nil" do
|
165
|
-
create_new_user
|
166
|
-
plugin_set_model_config_property(:reset_password_expiration_period, nil)
|
167
|
-
@user.deliver_reset_password_instructions!
|
168
|
-
@user.reset_password_token_valid?.should == true
|
169
|
-
end
|
170
|
-
|
171
151
|
it "should not send an email if time between emails has not passed since last email" do
|
172
152
|
create_new_user
|
173
|
-
|
153
|
+
sorcery_model_property_set(:reset_password_time_between_emails, 10000)
|
174
154
|
old_size = ActionMailer::Base.deliveries.size
|
175
155
|
@user.deliver_reset_password_instructions!
|
176
156
|
ActionMailer::Base.deliveries.size.should == old_size + 1
|
@@ -180,7 +160,7 @@ describe "User with reset_password submodule" do
|
|
180
160
|
|
181
161
|
it "should send an email if time between emails has passed since last email" do
|
182
162
|
create_new_user
|
183
|
-
|
163
|
+
sorcery_model_property_set(:reset_password_time_between_emails, 0.5)
|
184
164
|
old_size = ActionMailer::Base.deliveries.size
|
185
165
|
@user.deliver_reset_password_instructions!
|
186
166
|
ActionMailer::Base.deliveries.size.should == old_size + 1
|
@@ -190,7 +170,7 @@ describe "User with reset_password submodule" do
|
|
190
170
|
end
|
191
171
|
|
192
172
|
it "if mailer is nil on activation, throw exception!" do
|
193
|
-
expect{
|
173
|
+
expect{sorcery_reload!([:reset_password])}.to raise_error(ArgumentError)
|
194
174
|
end
|
195
175
|
|
196
176
|
end
|
@@ -1,9 +1,9 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
-
require File.expand_path(File.dirname(__FILE__) + '
|
2
|
+
require File.expand_path(File.dirname(__FILE__) + '/../app/mailers/sorcery_mailer')
|
3
3
|
|
4
4
|
describe "User with no submodules (core)" do
|
5
5
|
before(:all) do
|
6
|
-
|
6
|
+
sorcery_reload!
|
7
7
|
end
|
8
8
|
|
9
9
|
describe User, "when app has plugin loaded" do
|
@@ -36,55 +36,55 @@ describe "User with no submodules (core)" do
|
|
36
36
|
end
|
37
37
|
|
38
38
|
it "should enable configuration option 'username_attribute_name'" do
|
39
|
-
|
39
|
+
sorcery_model_property_set(:username_attribute_name, :email)
|
40
40
|
User.sorcery_config.username_attribute_name.should equal(:email)
|
41
41
|
end
|
42
42
|
|
43
43
|
it "should enable configuration option 'password_attribute_name'" do
|
44
|
-
|
44
|
+
sorcery_model_property_set(:password_attribute_name, :mypassword)
|
45
45
|
User.sorcery_config.password_attribute_name.should equal(:mypassword)
|
46
46
|
end
|
47
47
|
|
48
48
|
it "should enable configuration option 'email_attribute_name'" do
|
49
|
-
|
49
|
+
sorcery_model_property_set(:email_attribute_name, :my_email)
|
50
50
|
User.sorcery_config.email_attribute_name.should equal(:my_email)
|
51
51
|
end
|
52
52
|
|
53
53
|
it "should enable configuration option 'crypted_password_attribute_name'" do
|
54
|
-
|
54
|
+
sorcery_model_property_set(:crypted_password_attribute_name, :password)
|
55
55
|
User.sorcery_config.crypted_password_attribute_name.should equal(:password)
|
56
56
|
end
|
57
57
|
|
58
58
|
it "should enable configuration option 'salt_attribute_name'" do
|
59
|
-
|
59
|
+
sorcery_model_property_set(:salt_attribute_name, :my_salt)
|
60
60
|
User.sorcery_config.salt_attribute_name.should equal(:my_salt)
|
61
61
|
end
|
62
62
|
|
63
63
|
it "should enable configuration option 'encryption_algorithm'" do
|
64
|
-
|
64
|
+
sorcery_model_property_set(:encryption_algorithm, :none)
|
65
65
|
User.sorcery_config.encryption_algorithm.should equal(:none)
|
66
66
|
end
|
67
67
|
|
68
68
|
it "should enable configuration option 'encryption_key'" do
|
69
|
-
|
69
|
+
sorcery_model_property_set(:encryption_key, 'asdadas424234242')
|
70
70
|
User.sorcery_config.encryption_key.should == 'asdadas424234242'
|
71
71
|
end
|
72
72
|
|
73
73
|
it "should enable configuration option 'custom_encryption_provider'" do
|
74
|
-
|
75
|
-
|
74
|
+
sorcery_model_property_set(:encryption_algorithm, :custom)
|
75
|
+
sorcery_model_property_set(:custom_encryption_provider, Array)
|
76
76
|
User.sorcery_config.custom_encryption_provider.should equal(Array)
|
77
77
|
end
|
78
78
|
|
79
79
|
it "should enable configuration option 'salt_join_token'" do
|
80
80
|
salt_join_token = "--%%*&-"
|
81
|
-
|
81
|
+
sorcery_model_property_set(:salt_join_token, salt_join_token)
|
82
82
|
User.sorcery_config.salt_join_token.should equal(salt_join_token)
|
83
83
|
end
|
84
84
|
|
85
85
|
it "should enable configuration option 'stretches'" do
|
86
86
|
stretches = 15
|
87
|
-
|
87
|
+
sorcery_model_property_set(:stretches, stretches)
|
88
88
|
User.sorcery_config.stretches.should equal(stretches)
|
89
89
|
end
|
90
90
|
|
@@ -93,7 +93,7 @@ describe "User with no submodules (core)" do
|
|
93
93
|
# ----------------- PLUGIN ACTIVATED -----------------------
|
94
94
|
describe User, "when activated with sorcery" do
|
95
95
|
before(:all) do
|
96
|
-
|
96
|
+
sorcery_reload!()
|
97
97
|
end
|
98
98
|
|
99
99
|
before(:each) do
|
@@ -124,7 +124,7 @@ describe "User with no submodules (core)" do
|
|
124
124
|
describe User, "registration" do
|
125
125
|
|
126
126
|
before(:all) do
|
127
|
-
|
127
|
+
sorcery_reload!()
|
128
128
|
end
|
129
129
|
|
130
130
|
before(:each) do
|
@@ -159,9 +159,9 @@ describe "User with no submodules (core)" do
|
|
159
159
|
it "should not clear the virtual password field if save failed due to exception" do
|
160
160
|
create_new_user
|
161
161
|
@user.password = 'blupush'
|
162
|
-
@user.
|
162
|
+
@user.username = nil
|
163
163
|
begin
|
164
|
-
@user.save # triggers SQL exception since
|
164
|
+
@user.save # triggers SQL exception since username field is defined not null.
|
165
165
|
rescue
|
166
166
|
end
|
167
167
|
@user.password.should_not be_nil
|
@@ -186,7 +186,7 @@ describe "User with no submodules (core)" do
|
|
186
186
|
# ----------------- PASSWORD ENCRYPTION -----------------------
|
187
187
|
describe User, "special encryption cases" do
|
188
188
|
before(:all) do
|
189
|
-
|
189
|
+
sorcery_reload!()
|
190
190
|
@text = "Some Text!"
|
191
191
|
end
|
192
192
|
|
@@ -199,7 +199,7 @@ describe "User with no submodules (core)" do
|
|
199
199
|
end
|
200
200
|
|
201
201
|
it "should work with no password encryption" do
|
202
|
-
|
202
|
+
sorcery_model_property_set(:encryption_algorithm, :none)
|
203
203
|
create_new_user
|
204
204
|
User.authenticate(@user.send(User.sorcery_config.username_attribute_name), 'secret').should be_true
|
205
205
|
end
|
@@ -214,66 +214,66 @@ describe "User with no submodules (core)" do
|
|
214
214
|
crypted = encrypt(*tokens)
|
215
215
|
end
|
216
216
|
end
|
217
|
-
|
218
|
-
|
217
|
+
sorcery_model_property_set(:encryption_algorithm, :custom)
|
218
|
+
sorcery_model_property_set(:custom_encryption_provider, MyCrypto)
|
219
219
|
create_new_user
|
220
220
|
User.authenticate(@user.send(User.sorcery_config.username_attribute_name), 'secret').should be_true
|
221
221
|
end
|
222
222
|
|
223
223
|
it "if encryption algo is aes256, it should set key to crypto provider" do
|
224
|
-
|
225
|
-
|
224
|
+
sorcery_model_property_set(:encryption_algorithm, :aes256)
|
225
|
+
sorcery_model_property_set(:encryption_key, nil)
|
226
226
|
expect{User.encrypt(@text)}.to raise_error(ArgumentError)
|
227
|
-
|
227
|
+
sorcery_model_property_set(:encryption_key, "asd234dfs423fddsmndsflktsdf32343")
|
228
228
|
expect{User.encrypt(@text)}.to_not raise_error(ArgumentError)
|
229
229
|
end
|
230
230
|
|
231
231
|
it "if encryption algo is aes256, it should set key to crypto provider, even if attributes are set in reverse" do
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
232
|
+
sorcery_model_property_set(:encryption_key, nil)
|
233
|
+
sorcery_model_property_set(:encryption_algorithm, :none)
|
234
|
+
sorcery_model_property_set(:encryption_key, "asd234dfs423fddsmndsflktsdf32343")
|
235
|
+
sorcery_model_property_set(:encryption_algorithm, :aes256)
|
236
236
|
expect{User.encrypt(@text)}.to_not raise_error(ArgumentError)
|
237
237
|
end
|
238
238
|
|
239
239
|
it "if encryption algo is md5 it should work" do
|
240
|
-
|
240
|
+
sorcery_model_property_set(:encryption_algorithm, :md5)
|
241
241
|
User.encrypt(@text).should == Sorcery::CryptoProviders::MD5.encrypt(@text)
|
242
242
|
end
|
243
243
|
|
244
244
|
it "if encryption algo is sha1 it should work" do
|
245
|
-
|
245
|
+
sorcery_model_property_set(:encryption_algorithm, :sha1)
|
246
246
|
User.encrypt(@text).should == Sorcery::CryptoProviders::SHA1.encrypt(@text)
|
247
247
|
end
|
248
248
|
|
249
249
|
it "if encryption algo is sha256 it should work" do
|
250
|
-
|
250
|
+
sorcery_model_property_set(:encryption_algorithm, :sha256)
|
251
251
|
User.encrypt(@text).should == Sorcery::CryptoProviders::SHA256.encrypt(@text)
|
252
252
|
end
|
253
253
|
|
254
254
|
it "if encryption algo is sha512 it should work" do
|
255
|
-
|
255
|
+
sorcery_model_property_set(:encryption_algorithm, :sha512)
|
256
256
|
User.encrypt(@text).should == Sorcery::CryptoProviders::SHA512.encrypt(@text)
|
257
257
|
end
|
258
258
|
|
259
259
|
it "salt should be random for each user and saved in db" do
|
260
|
-
|
260
|
+
sorcery_model_property_set(:salt_attribute_name, :salt)
|
261
261
|
create_new_user
|
262
262
|
@user.salt.should_not be_nil
|
263
263
|
end
|
264
264
|
|
265
265
|
it "if salt is set should use it to encrypt" do
|
266
|
-
|
267
|
-
|
266
|
+
sorcery_model_property_set(:salt_attribute_name, :salt)
|
267
|
+
sorcery_model_property_set(:encryption_algorithm, :sha512)
|
268
268
|
create_new_user
|
269
269
|
@user.crypted_password.should_not == Sorcery::CryptoProviders::SHA512.encrypt('secret')
|
270
270
|
@user.crypted_password.should == Sorcery::CryptoProviders::SHA512.encrypt('secret',@user.salt)
|
271
271
|
end
|
272
272
|
|
273
273
|
it "if salt_join_token is set should use it to encrypt" do
|
274
|
-
|
275
|
-
|
276
|
-
|
274
|
+
sorcery_model_property_set(:salt_attribute_name, :salt)
|
275
|
+
sorcery_model_property_set(:salt_join_token, "-@=>")
|
276
|
+
sorcery_model_property_set(:encryption_algorithm, :sha512)
|
277
277
|
create_new_user
|
278
278
|
@user.crypted_password.should_not == Sorcery::CryptoProviders::SHA512.encrypt('secret')
|
279
279
|
Sorcery::CryptoProviders::SHA512.join_token = ""
|
@@ -283,5 +283,35 @@ describe "User with no submodules (core)" do
|
|
283
283
|
end
|
284
284
|
|
285
285
|
end
|
286
|
+
|
287
|
+
describe User, "external users" do
|
288
|
+
before(:all) do
|
289
|
+
ActiveRecord::Migrator.migrate("#{Rails.root}/db/migrate/oauth")
|
290
|
+
sorcery_reload!()
|
291
|
+
end
|
292
|
+
|
293
|
+
after(:all) do
|
294
|
+
ActiveRecord::Migrator.rollback("#{Rails.root}/db/migrate/oauth")
|
295
|
+
end
|
296
|
+
|
297
|
+
before(:each) do
|
298
|
+
User.delete_all
|
299
|
+
end
|
300
|
+
|
301
|
+
it "should respond to 'external?'" do
|
302
|
+
create_new_user
|
303
|
+
@user.should respond_to(:external?)
|
304
|
+
end
|
305
|
+
|
306
|
+
it "external? should be false for regular users" do
|
307
|
+
create_new_user
|
308
|
+
@user.external?.should be_false
|
309
|
+
end
|
310
|
+
|
311
|
+
it "external? should be true for external users" do
|
312
|
+
create_new_external_user(:twitter)
|
313
|
+
@user.external?.should be_true
|
314
|
+
end
|
315
|
+
end
|
286
316
|
|
287
317
|
end
|