sorcery 0.8.5 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +3 -1
- data/.travis.yml +122 -5
- data/CHANGELOG.md +37 -1
- data/Gemfile +10 -18
- data/README.md +159 -88
- data/gemfiles/active_record-rails40.gemfile +7 -0
- data/gemfiles/active_record-rails41.gemfile +7 -0
- data/gemfiles/mongo_mapper-rails40.gemfile +9 -0
- data/gemfiles/mongo_mapper-rails41.gemfile +9 -0
- data/gemfiles/mongoid-rails40.gemfile +9 -0
- data/gemfiles/mongoid-rails41.gemfile +9 -0
- data/gemfiles/mongoid3-rails32.gemfile +9 -0
- data/lib/generators/sorcery/USAGE +1 -1
- data/lib/generators/sorcery/install_generator.rb +19 -5
- data/lib/generators/sorcery/templates/initializer.rb +34 -9
- data/lib/generators/sorcery/templates/migration/brute_force_protection.rb +3 -1
- data/lib/generators/sorcery/templates/migration/core.rb +2 -2
- data/lib/generators/sorcery/templates/migration/external.rb +3 -1
- data/lib/sorcery/adapters/active_record_adapter.rb +120 -0
- data/lib/sorcery/adapters/base_adapter.rb +30 -0
- data/lib/sorcery/adapters/data_mapper_adapter.rb +176 -0
- data/lib/sorcery/adapters/mongo_mapper_adapter.rb +110 -0
- data/lib/sorcery/adapters/mongoid_adapter.rb +97 -0
- data/lib/sorcery/controller/config.rb +65 -0
- data/lib/sorcery/controller/submodules/activity_logging.rb +16 -21
- data/lib/sorcery/controller/submodules/brute_force_protection.rb +6 -6
- data/lib/sorcery/controller/submodules/external.rb +35 -40
- data/lib/sorcery/controller/submodules/remember_me.rb +4 -4
- data/lib/sorcery/controller/submodules/session_timeout.rb +10 -6
- data/lib/sorcery/controller.rb +10 -74
- data/lib/sorcery/model/config.rb +96 -0
- data/lib/sorcery/model/submodules/activity_logging.rb +30 -13
- data/lib/sorcery/model/submodules/brute_force_protection.rb +21 -21
- data/lib/sorcery/model/submodules/external.rb +53 -9
- data/lib/sorcery/model/submodules/remember_me.rb +15 -19
- data/lib/sorcery/model/submodules/reset_password.rb +33 -34
- data/lib/sorcery/model/submodules/user_activation.rb +36 -47
- data/lib/sorcery/model/temporary_token.rb +4 -4
- data/lib/sorcery/model.rb +73 -173
- data/lib/sorcery/protocols/oauth.rb +42 -0
- data/lib/sorcery/protocols/oauth2.rb +47 -0
- data/lib/sorcery/providers/base.rb +38 -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/heroku.rb +57 -0
- data/lib/sorcery/providers/jira.rb +77 -0
- data/lib/sorcery/providers/linkedin.rb +66 -0
- data/lib/sorcery/providers/liveid.rb +53 -0
- data/lib/sorcery/providers/salesforce.rb +50 -0
- data/lib/sorcery/providers/twitter.rb +59 -0
- data/lib/sorcery/providers/vk.rb +63 -0
- data/lib/sorcery/providers/xing.rb +64 -0
- data/lib/sorcery/test_helpers/internal/rails.rb +14 -3
- data/lib/sorcery/test_helpers/internal.rb +7 -3
- data/lib/sorcery/test_helpers/rails/controller.rb +21 -0
- data/lib/sorcery/test_helpers/rails/integration.rb +26 -0
- data/lib/sorcery/version.rb +3 -0
- data/lib/sorcery.rb +82 -58
- data/sorcery.gemspec +19 -19
- data/spec/active_record/user_activation_spec.rb +1 -1
- data/spec/active_record/user_activity_logging_spec.rb +10 -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/controllers/controller_activity_logging_spec.rb +124 -0
- data/spec/controllers/controller_brute_force_protection_spec.rb +43 -0
- data/spec/controllers/controller_http_basic_auth_spec.rb +68 -0
- data/spec/controllers/controller_oauth2_spec.rb +414 -0
- data/spec/controllers/controller_oauth_spec.rb +240 -0
- data/spec/controllers/controller_remember_me_spec.rb +117 -0
- data/spec/controllers/controller_session_timeout_spec.rb +80 -0
- data/spec/controllers/controller_spec.rb +218 -0
- data/spec/data_mapper/user_activation_spec.rb +10 -0
- data/spec/data_mapper/user_activity_logging_spec.rb +14 -0
- data/spec/data_mapper/user_brute_force_protection_spec.rb +9 -0
- data/spec/data_mapper/user_oauth_spec.rb +9 -0
- data/spec/data_mapper/user_remember_me_spec.rb +8 -0
- data/spec/data_mapper/user_reset_password_spec.rb +8 -0
- data/spec/data_mapper/user_spec.rb +27 -0
- 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/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 +21 -9
- data/spec/orm/active_record.rb +14 -0
- data/spec/orm/data_mapper.rb +48 -0
- data/spec/orm/mongo_mapper.rb +1 -1
- data/spec/orm/mongoid.rb +5 -0
- data/spec/rails_app/app/controllers/sorcery_controller.rb +125 -59
- data/spec/rails_app/app/data_mapper/authentication.rb +8 -0
- data/spec/rails_app/app/data_mapper/user.rb +7 -0
- data/spec/rails_app/app/mongo_mapper/user.rb +2 -0
- data/spec/rails_app/config/routes.rb +27 -13
- data/spec/rails_app/db/migrate/core/20101224223620_create_users.rb +2 -2
- data/spec/shared_examples/user_activation_shared_examples.rb +108 -91
- data/spec/shared_examples/user_activity_logging_shared_examples.rb +83 -15
- data/spec/shared_examples/user_brute_force_protection_shared_examples.rb +140 -21
- data/spec/shared_examples/user_oauth_shared_examples.rb +21 -16
- data/spec/shared_examples/user_remember_me_shared_examples.rb +36 -24
- data/spec/shared_examples/user_reset_password_shared_examples.rb +138 -117
- data/spec/shared_examples/user_shared_examples.rb +297 -150
- data/spec/sorcery_crypto_providers_spec.rb +28 -28
- data/spec/spec_helper.rb +12 -18
- metadata +99 -165
- data/Gemfile.rails4 +0 -24
- data/VERSION +0 -1
- 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/model/adapters/active_record.rb +0 -49
- data/lib/sorcery/model/adapters/mongo_mapper.rb +0 -56
- data/lib/sorcery/model/adapters/mongoid.rb +0 -88
- data/lib/sorcery/test_helpers/rails.rb +0 -16
- data/lib/sorcery/test_helpers.rb +0 -5
- data/spec/active_record/controller_activity_logging_spec.rb +0 -140
- data/spec/active_record/controller_brute_force_protection_spec.rb +0 -136
- data/spec/active_record/controller_http_basic_auth_spec.rb +0 -59
- data/spec/active_record/controller_oauth2_spec.rb +0 -417
- data/spec/active_record/controller_oauth_spec.rb +0 -212
- data/spec/active_record/controller_remember_me_spec.rb +0 -96
- data/spec/active_record/controller_session_timeout_spec.rb +0 -55
- data/spec/active_record/controller_spec.rb +0 -182
- data/spec/active_record/integration_spec.rb +0 -23
- data/spec/mongo_mapper/controller_spec.rb +0 -175
- data/spec/mongoid/controller_activity_logging_spec.rb +0 -111
- data/spec/mongoid/controller_spec.rb +0 -186
- data/spec/rails_app/public/404.html +0 -26
- data/spec/rails_app/public/422.html +0 -26
- data/spec/rails_app/public/500.html +0 -26
- data/spec/rails_app/public/favicon.ico +0 -0
- data/spec/rails_app/public/images/rails.png +0 -0
- data/spec/rails_app/public/javascripts/application.js +0 -2
- data/spec/rails_app/public/javascripts/controls.js +0 -965
- data/spec/rails_app/public/javascripts/dragdrop.js +0 -974
- data/spec/rails_app/public/javascripts/effects.js +0 -1123
- data/spec/rails_app/public/javascripts/prototype.js +0 -6001
- data/spec/rails_app/public/javascripts/rails.js +0 -175
- data/spec/rails_app/public/robots.txt +0 -5
- data/spec/rails_app/public/stylesheets/.gitkeep +0 -0
- data/spec/shared_examples/controller_oauth2_shared_examples.rb +0 -56
- data/spec/shared_examples/controller_oauth_shared_examples.rb +0 -69
- /data/lib/sorcery/{controller/submodules/external/protocols → protocols}/certs/ca-bundle.crt +0 -0
|
@@ -1,417 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
|
|
3
|
-
require 'shared_examples/controller_oauth2_shared_examples'
|
|
4
|
-
|
|
5
|
-
describe SorceryController do
|
|
6
|
-
before(:all) do
|
|
7
|
-
ActiveRecord::Migrator.migrate("#{Rails.root}/db/migrate/external")
|
|
8
|
-
User.reset_column_information
|
|
9
|
-
|
|
10
|
-
sorcery_reload!([:external])
|
|
11
|
-
set_external_property
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
after(:all) do
|
|
15
|
-
ActiveRecord::Migrator.rollback("#{Rails.root}/db/migrate/external")
|
|
16
|
-
end
|
|
17
|
-
# ----------------- OAuth -----------------------
|
|
18
|
-
describe SorceryController, "with OAuth features" do
|
|
19
|
-
|
|
20
|
-
before(:each) do
|
|
21
|
-
stub_all_oauth2_requests!
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
after(:each) do
|
|
25
|
-
User.delete_all
|
|
26
|
-
Authentication.delete_all
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
context "when callback_url begin with /" do
|
|
30
|
-
before do
|
|
31
|
-
sorcery_controller_external_property_set(:facebook, :callback_url, "/oauth/twitter/callback")
|
|
32
|
-
end
|
|
33
|
-
it "login_at redirects correctly" do
|
|
34
|
-
create_new_user
|
|
35
|
-
get :login_at_test2
|
|
36
|
-
response.should be_a_redirect
|
|
37
|
-
response.should redirect_to("https://graph.facebook.com/oauth/authorize?response_type=code&client_id=#{::Sorcery::Controller::Config.facebook.key}&redirect_uri=http%3A%2F%2Ftest.host%2Foauth%2Ftwitter%2Fcallback&scope=email%2Coffline_access&display=page&state")
|
|
38
|
-
end
|
|
39
|
-
it "logins with state" do
|
|
40
|
-
create_new_user
|
|
41
|
-
get :login_at_test_with_state
|
|
42
|
-
response.should be_a_redirect
|
|
43
|
-
response.should redirect_to("https://graph.facebook.com/oauth/authorize?response_type=code&client_id=#{::Sorcery::Controller::Config.facebook.key}&redirect_uri=http%3A%2F%2Ftest.host%2Foauth%2Ftwitter%2Fcallback&scope=email%2Coffline_access&display=page&state=bla")
|
|
44
|
-
end
|
|
45
|
-
after do
|
|
46
|
-
sorcery_controller_external_property_set(:facebook, :callback_url, "http://blabla.com")
|
|
47
|
-
end
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
#this test can never pass because of the previous test (the callback url can't change anymore)
|
|
51
|
-
=begin
|
|
52
|
-
context "when callback_url begin with http://" do
|
|
53
|
-
it "login_at redirects correctly" do
|
|
54
|
-
create_new_user
|
|
55
|
-
get :login_at_test2
|
|
56
|
-
response.should be_a_redirect
|
|
57
|
-
response.should redirect_to("https://graph.facebook.com/oauth/authorize?response_type=code&client_id=#{::Sorcery::Controller::Config.facebook.key}&redirect_uri=http%3A%2F%2Fblabla.com&scope=email%2Coffline_access&display=page&state")
|
|
58
|
-
end
|
|
59
|
-
end
|
|
60
|
-
=end
|
|
61
|
-
it "'login_from' logins if user exists" do
|
|
62
|
-
# dirty hack for rails 4
|
|
63
|
-
@controller.stub(:register_last_activity_time_to_db)
|
|
64
|
-
|
|
65
|
-
sorcery_model_property_set(:authentications_class, Authentication)
|
|
66
|
-
create_new_external_user(:facebook)
|
|
67
|
-
get :test_login_from2
|
|
68
|
-
flash[:notice].should == "Success!"
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
it "'login_from' fails if user doesn't exist" do
|
|
72
|
-
sorcery_model_property_set(:authentications_class, Authentication)
|
|
73
|
-
create_new_user
|
|
74
|
-
get :test_login_from2
|
|
75
|
-
flash[:alert].should == "Failed!"
|
|
76
|
-
end
|
|
77
|
-
|
|
78
|
-
it "on successful login_from the user should be redirected to the url he originally wanted" do
|
|
79
|
-
# dirty hack for rails 4
|
|
80
|
-
@controller.stub(:register_last_activity_time_to_db)
|
|
81
|
-
|
|
82
|
-
sorcery_model_property_set(:authentications_class, Authentication)
|
|
83
|
-
create_new_external_user(:facebook)
|
|
84
|
-
get :test_return_to_with_external2, {}, :return_to_url => "fuu"
|
|
85
|
-
response.should redirect_to("fuu")
|
|
86
|
-
flash[:notice].should == "Success!"
|
|
87
|
-
end
|
|
88
|
-
|
|
89
|
-
# provider: github
|
|
90
|
-
it "login_at redirects correctly (github)" do
|
|
91
|
-
create_new_user
|
|
92
|
-
get :login_at_test3
|
|
93
|
-
response.should be_a_redirect
|
|
94
|
-
response.should redirect_to("https://github.com/login/oauth/authorize?response_type=code&client_id=#{::Sorcery::Controller::Config.github.key}&redirect_uri=http%3A%2F%2Fblabla.com&scope&display&state")
|
|
95
|
-
end
|
|
96
|
-
|
|
97
|
-
it "'login_from' logins if user exists (github)" do
|
|
98
|
-
# dirty hack for rails 4
|
|
99
|
-
@controller.stub(:register_last_activity_time_to_db)
|
|
100
|
-
|
|
101
|
-
sorcery_model_property_set(:authentications_class, Authentication)
|
|
102
|
-
create_new_external_user(:github)
|
|
103
|
-
get :test_login_from3
|
|
104
|
-
flash[:notice].should == "Success!"
|
|
105
|
-
end
|
|
106
|
-
|
|
107
|
-
it "'login_from' fails if user doesn't exist (github)" do
|
|
108
|
-
sorcery_model_property_set(:authentications_class, Authentication)
|
|
109
|
-
create_new_user
|
|
110
|
-
get :test_login_from3
|
|
111
|
-
flash[:alert].should == "Failed!"
|
|
112
|
-
end
|
|
113
|
-
|
|
114
|
-
it "on successful login_from the user should be redirected to the url he originally wanted (github)" do
|
|
115
|
-
# dirty hack for rails 4
|
|
116
|
-
@controller.stub(:register_last_activity_time_to_db)
|
|
117
|
-
|
|
118
|
-
sorcery_model_property_set(:authentications_class, Authentication)
|
|
119
|
-
create_new_external_user(:github)
|
|
120
|
-
get :test_return_to_with_external3, {}, :return_to_url => "fuu"
|
|
121
|
-
response.should redirect_to("fuu")
|
|
122
|
-
flash[:notice].should == "Success!"
|
|
123
|
-
end
|
|
124
|
-
|
|
125
|
-
# provider: google
|
|
126
|
-
it "login_at redirects correctly (google)" do
|
|
127
|
-
create_new_user
|
|
128
|
-
get :login_at_test4
|
|
129
|
-
response.should be_a_redirect
|
|
130
|
-
response.should redirect_to("https://accounts.google.com/o/oauth2/auth?response_type=code&client_id=#{::Sorcery::Controller::Config.google.key}&redirect_uri=http%3A%2F%2Fblabla.com&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.profile&display&state")
|
|
131
|
-
end
|
|
132
|
-
|
|
133
|
-
it "'login_from' logins if user exists (google)" do
|
|
134
|
-
# dirty hack for rails 4
|
|
135
|
-
@controller.stub(:register_last_activity_time_to_db)
|
|
136
|
-
|
|
137
|
-
sorcery_model_property_set(:authentications_class, Authentication)
|
|
138
|
-
create_new_external_user(:google)
|
|
139
|
-
get :test_login_from4
|
|
140
|
-
flash[:notice].should == "Success!"
|
|
141
|
-
end
|
|
142
|
-
|
|
143
|
-
it "'login_from' fails if user doesn't exist (google)" do
|
|
144
|
-
sorcery_model_property_set(:authentications_class, Authentication)
|
|
145
|
-
create_new_user
|
|
146
|
-
get :test_login_from4
|
|
147
|
-
flash[:alert].should == "Failed!"
|
|
148
|
-
end
|
|
149
|
-
|
|
150
|
-
it "on successful login_from the user should be redirected to the url he originally wanted (google)" do
|
|
151
|
-
# dirty hack for rails 4
|
|
152
|
-
@controller.stub(:register_last_activity_time_to_db)
|
|
153
|
-
|
|
154
|
-
sorcery_model_property_set(:authentications_class, Authentication)
|
|
155
|
-
create_new_external_user(:google)
|
|
156
|
-
get :test_return_to_with_external4, {}, :return_to_url => "fuu"
|
|
157
|
-
response.should redirect_to("fuu")
|
|
158
|
-
flash[:notice].should == "Success!"
|
|
159
|
-
end
|
|
160
|
-
|
|
161
|
-
# provider: liveid
|
|
162
|
-
it "login_at redirects correctly (liveid)" do
|
|
163
|
-
create_new_user
|
|
164
|
-
get :login_at_test5
|
|
165
|
-
response.should be_a_redirect
|
|
166
|
-
response.should redirect_to("https://oauth.live.com/authorize?response_type=code&client_id=#{::Sorcery::Controller::Config.liveid.key}&redirect_uri=http%3A%2F%2Fblabla.com&scope=wl.basic+wl.emails+wl.offline_access&display&state")
|
|
167
|
-
end
|
|
168
|
-
|
|
169
|
-
it "'login_from' logins if user exists (liveid)" do
|
|
170
|
-
# dirty hack for rails 4
|
|
171
|
-
@controller.stub(:register_last_activity_time_to_db)
|
|
172
|
-
|
|
173
|
-
sorcery_model_property_set(:authentications_class, Authentication)
|
|
174
|
-
create_new_external_user(:liveid)
|
|
175
|
-
get :test_login_from5
|
|
176
|
-
flash[:notice].should == "Success!"
|
|
177
|
-
end
|
|
178
|
-
|
|
179
|
-
it "'login_from' fails if user doesn't exist (liveid)" do
|
|
180
|
-
sorcery_model_property_set(:authentications_class, Authentication)
|
|
181
|
-
create_new_user
|
|
182
|
-
get :test_login_from5
|
|
183
|
-
flash[:alert].should == "Failed!"
|
|
184
|
-
end
|
|
185
|
-
|
|
186
|
-
it "on successful login_from the user should be redirected to the url he originally wanted (liveid)" do
|
|
187
|
-
# dirty hack for rails 4
|
|
188
|
-
@controller.stub(:register_last_activity_time_to_db)
|
|
189
|
-
|
|
190
|
-
sorcery_model_property_set(:authentications_class, Authentication)
|
|
191
|
-
create_new_external_user(:liveid)
|
|
192
|
-
get :test_return_to_with_external5, {}, :return_to_url => "fuu"
|
|
193
|
-
response.should redirect_to("fuu")
|
|
194
|
-
flash[:notice].should == "Success!"
|
|
195
|
-
end
|
|
196
|
-
|
|
197
|
-
end
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
describe SorceryController do
|
|
201
|
-
it_behaves_like "oauth2_controller"
|
|
202
|
-
end
|
|
203
|
-
|
|
204
|
-
describe SorceryController, "OAuth with User Activation features" do
|
|
205
|
-
before(:all) do
|
|
206
|
-
ActiveRecord::Migrator.migrate("#{Rails.root}/db/migrate/activation")
|
|
207
|
-
sorcery_reload!([:user_activation,:external], :user_activation_mailer => ::SorceryMailer)
|
|
208
|
-
sorcery_controller_property_set(:external_providers, [:facebook, :github, :google, :liveid])
|
|
209
|
-
sorcery_controller_external_property_set(:facebook, :key, "eYVNBjBDi33aa9GkA3w")
|
|
210
|
-
sorcery_controller_external_property_set(:facebook, :secret, "XpbeSdCoaKSmQGSeokz5qcUATClRW5u08QWNfv71N8")
|
|
211
|
-
sorcery_controller_external_property_set(:facebook, :callback_url, "http://blabla.com")
|
|
212
|
-
sorcery_controller_external_property_set(:github, :key, "eYVNBjBDi33aa9GkA3w")
|
|
213
|
-
sorcery_controller_external_property_set(:github, :secret, "XpbeSdCoaKSmQGSeokz5qcUATClRW5u08QWNfv71N8")
|
|
214
|
-
sorcery_controller_external_property_set(:github, :callback_url, "http://blabla.com")
|
|
215
|
-
sorcery_controller_external_property_set(:google, :key, "eYVNBjBDi33aa9GkA3w")
|
|
216
|
-
sorcery_controller_external_property_set(:google, :secret, "XpbeSdCoaKSmQGSeokz5qcUATClRW5u08QWNfv71N8")
|
|
217
|
-
sorcery_controller_external_property_set(:google, :callback_url, "http://blabla.com")
|
|
218
|
-
sorcery_controller_external_property_set(:liveid, :key, "eYVNBjBDi33aa9GkA3w")
|
|
219
|
-
sorcery_controller_external_property_set(:liveid, :secret, "XpbeSdCoaKSmQGSeokz5qcUATClRW5u08QWNfv71N8")
|
|
220
|
-
sorcery_controller_external_property_set(:liveid, :callback_url, "http://blabla.com")
|
|
221
|
-
|
|
222
|
-
end
|
|
223
|
-
|
|
224
|
-
after(:all) do
|
|
225
|
-
ActiveRecord::Migrator.rollback("#{Rails.root}/db/migrate/activation")
|
|
226
|
-
end
|
|
227
|
-
|
|
228
|
-
after(:each) do
|
|
229
|
-
User.delete_all
|
|
230
|
-
end
|
|
231
|
-
|
|
232
|
-
it "should not send activation email to external users" do
|
|
233
|
-
old_size = ActionMailer::Base.deliveries.size
|
|
234
|
-
create_new_external_user(:facebook)
|
|
235
|
-
ActionMailer::Base.deliveries.size.should == old_size
|
|
236
|
-
end
|
|
237
|
-
|
|
238
|
-
it "should not send external users an activation success email" do
|
|
239
|
-
sorcery_model_property_set(:activation_success_email_method_name, nil)
|
|
240
|
-
create_new_external_user(:facebook)
|
|
241
|
-
old_size = ActionMailer::Base.deliveries.size
|
|
242
|
-
@user.activate!
|
|
243
|
-
ActionMailer::Base.deliveries.size.should == old_size
|
|
244
|
-
end
|
|
245
|
-
|
|
246
|
-
# provider: github
|
|
247
|
-
it "should not send activation email to external users (github)" do
|
|
248
|
-
old_size = ActionMailer::Base.deliveries.size
|
|
249
|
-
create_new_external_user(:github)
|
|
250
|
-
ActionMailer::Base.deliveries.size.should == old_size
|
|
251
|
-
end
|
|
252
|
-
|
|
253
|
-
it "should not send external users an activation success email (github)" do
|
|
254
|
-
sorcery_model_property_set(:activation_success_email_method_name, nil)
|
|
255
|
-
create_new_external_user(:github)
|
|
256
|
-
old_size = ActionMailer::Base.deliveries.size
|
|
257
|
-
@user.activate!
|
|
258
|
-
ActionMailer::Base.deliveries.size.should == old_size
|
|
259
|
-
end
|
|
260
|
-
|
|
261
|
-
# provider: google
|
|
262
|
-
it "should not send activation email to external users (google)" do
|
|
263
|
-
old_size = ActionMailer::Base.deliveries.size
|
|
264
|
-
create_new_external_user(:google)
|
|
265
|
-
ActionMailer::Base.deliveries.size.should == old_size
|
|
266
|
-
end
|
|
267
|
-
|
|
268
|
-
it "should not send external users an activation success email (google)" do
|
|
269
|
-
sorcery_model_property_set(:activation_success_email_method_name, nil)
|
|
270
|
-
create_new_external_user(:google)
|
|
271
|
-
old_size = ActionMailer::Base.deliveries.size
|
|
272
|
-
@user.activate!
|
|
273
|
-
ActionMailer::Base.deliveries.size.should == old_size
|
|
274
|
-
end
|
|
275
|
-
|
|
276
|
-
# provider: liveid
|
|
277
|
-
it "should not send activation email to external users (liveid)" do
|
|
278
|
-
old_size = ActionMailer::Base.deliveries.size
|
|
279
|
-
create_new_external_user(:liveid)
|
|
280
|
-
ActionMailer::Base.deliveries.size.should == old_size
|
|
281
|
-
end
|
|
282
|
-
|
|
283
|
-
it "should not send external users an activation success email (liveid)" do
|
|
284
|
-
sorcery_model_property_set(:activation_success_email_method_name, nil)
|
|
285
|
-
create_new_external_user(:liveid)
|
|
286
|
-
old_size = ActionMailer::Base.deliveries.size
|
|
287
|
-
@user.activate!
|
|
288
|
-
ActionMailer::Base.deliveries.size.should == old_size
|
|
289
|
-
end
|
|
290
|
-
end
|
|
291
|
-
|
|
292
|
-
describe SorceryController, "OAuth with user activation features" do
|
|
293
|
-
before(:all) do
|
|
294
|
-
ActiveRecord::Migrator.migrate("#{Rails.root}/db/migrate/external")
|
|
295
|
-
ActiveRecord::Migrator.migrate("#{Rails.root}/db/migrate/activity_logging")
|
|
296
|
-
User.reset_column_information
|
|
297
|
-
sorcery_reload!([:activity_logging, :external])
|
|
298
|
-
end
|
|
299
|
-
|
|
300
|
-
after(:all) do
|
|
301
|
-
ActiveRecord::Migrator.rollback("#{Rails.root}/db/migrate/external")
|
|
302
|
-
ActiveRecord::Migrator.rollback("#{Rails.root}/db/migrate/activity_logging")
|
|
303
|
-
end
|
|
304
|
-
|
|
305
|
-
%w(facebook github google liveid).each.with_index(2) do |provider, index|
|
|
306
|
-
context "when #{provider}" do
|
|
307
|
-
before(:each) do
|
|
308
|
-
User.delete_all
|
|
309
|
-
Authentication.delete_all
|
|
310
|
-
sorcery_controller_property_set(:register_login_time, true)
|
|
311
|
-
stub_all_oauth2_requests!
|
|
312
|
-
sorcery_model_property_set(:authentications_class, Authentication)
|
|
313
|
-
create_new_external_user(provider.to_sym)
|
|
314
|
-
end
|
|
315
|
-
|
|
316
|
-
it "should register login time" do
|
|
317
|
-
now = Time.now.in_time_zone
|
|
318
|
-
get "test_login_from#{index}".to_sym
|
|
319
|
-
User.last.last_login_at.should_not be_nil
|
|
320
|
-
User.last.last_login_at.to_s(:db).should >= now.to_s(:db)
|
|
321
|
-
User.last.last_login_at.to_s(:db).should <= (now+2).to_s(:db)
|
|
322
|
-
end
|
|
323
|
-
|
|
324
|
-
it "should not register login time if configured so" do
|
|
325
|
-
sorcery_controller_property_set(:register_login_time, false)
|
|
326
|
-
now = Time.now.in_time_zone
|
|
327
|
-
get "test_login_from#{index}".to_sym
|
|
328
|
-
User.last.last_login_at.should be_nil
|
|
329
|
-
end
|
|
330
|
-
end
|
|
331
|
-
end
|
|
332
|
-
end
|
|
333
|
-
|
|
334
|
-
describe SorceryController, "OAuth with session timeout features" do
|
|
335
|
-
before(:all) do
|
|
336
|
-
ActiveRecord::Migrator.migrate("#{Rails.root}/db/migrate/external")
|
|
337
|
-
User.reset_column_information
|
|
338
|
-
sorcery_reload!([:session_timeout, :external])
|
|
339
|
-
end
|
|
340
|
-
|
|
341
|
-
after(:all) do
|
|
342
|
-
ActiveRecord::Migrator.rollback("#{Rails.root}/db/migrate/external")
|
|
343
|
-
end
|
|
344
|
-
|
|
345
|
-
%w(facebook github google liveid).each.with_index(2) do |provider, index|
|
|
346
|
-
context "when #{provider}" do
|
|
347
|
-
before(:each) do
|
|
348
|
-
User.delete_all
|
|
349
|
-
Authentication.delete_all
|
|
350
|
-
sorcery_model_property_set(:authentications_class, Authentication)
|
|
351
|
-
sorcery_controller_property_set(:session_timeout,0.5)
|
|
352
|
-
stub_all_oauth2_requests!
|
|
353
|
-
create_new_external_user(provider.to_sym)
|
|
354
|
-
end
|
|
355
|
-
|
|
356
|
-
after(:each) do
|
|
357
|
-
Timecop.return
|
|
358
|
-
end
|
|
359
|
-
|
|
360
|
-
it "should not reset session before session timeout" do
|
|
361
|
-
get "test_login_from#{index}".to_sym
|
|
362
|
-
session[:user_id].should_not be_nil
|
|
363
|
-
flash[:notice].should == "Success!"
|
|
364
|
-
end
|
|
365
|
-
|
|
366
|
-
it "should reset session after session timeout" do
|
|
367
|
-
get "test_login_from#{index}".to_sym
|
|
368
|
-
Timecop.travel(Time.now.in_time_zone+0.6)
|
|
369
|
-
get :test_should_be_logged_in
|
|
370
|
-
session[:user_id].should be_nil
|
|
371
|
-
response.should be_a_redirect
|
|
372
|
-
end
|
|
373
|
-
end
|
|
374
|
-
end
|
|
375
|
-
end
|
|
376
|
-
|
|
377
|
-
def stub_all_oauth2_requests!
|
|
378
|
-
auth_code = OAuth2::Strategy::AuthCode.any_instance
|
|
379
|
-
access_token = double(OAuth2::AccessToken)
|
|
380
|
-
access_token.stub(:token_param=)
|
|
381
|
-
response = double(OAuth2::Response)
|
|
382
|
-
response.stub(:body).and_return({
|
|
383
|
-
"id"=>"123",
|
|
384
|
-
"name"=>"Noam Ben Ari",
|
|
385
|
-
"first_name"=>"Noam",
|
|
386
|
-
"last_name"=>"Ben Ari",
|
|
387
|
-
"link"=>"http://www.facebook.com/nbenari1",
|
|
388
|
-
"hometown"=>{"id"=>"110619208966868", "name"=>"Haifa, Israel"},
|
|
389
|
-
"location"=>{"id"=>"106906559341067", "name"=>"Pardes Hanah, Hefa, Israel"},
|
|
390
|
-
"bio"=>"I'm a new daddy, and enjoying it!",
|
|
391
|
-
"gender"=>"male",
|
|
392
|
-
"email"=>"nbenari@gmail.com",
|
|
393
|
-
"timezone"=>2,
|
|
394
|
-
"locale"=>"en_US",
|
|
395
|
-
"languages"=>[{"id"=>"108405449189952", "name"=>"Hebrew"}, {"id"=>"106059522759137", "name"=>"English"}, {"id"=>"112624162082677", "name"=>"Russian"}],
|
|
396
|
-
"verified"=>true,
|
|
397
|
-
"updated_time"=>"2011-02-16T20:59:38+0000"}.to_json)
|
|
398
|
-
access_token.stub(:get).and_return(response)
|
|
399
|
-
auth_code.stub(:get_token).and_return(access_token)
|
|
400
|
-
end
|
|
401
|
-
|
|
402
|
-
def set_external_property
|
|
403
|
-
sorcery_controller_property_set(:external_providers, [:facebook, :github, :google, :liveid])
|
|
404
|
-
sorcery_controller_external_property_set(:facebook, :key, "eYVNBjBDi33aa9GkA3w")
|
|
405
|
-
sorcery_controller_external_property_set(:facebook, :secret, "XpbeSdCoaKSmQGSeokz5qcUATClRW5u08QWNfv71N8")
|
|
406
|
-
sorcery_controller_external_property_set(:facebook, :callback_url, "http://blabla.com")
|
|
407
|
-
sorcery_controller_external_property_set(:github, :key, "eYVNBjBDi33aa9GkA3w")
|
|
408
|
-
sorcery_controller_external_property_set(:github, :secret, "XpbeSdCoaKSmQGSeokz5qcUATClRW5u08QWNfv71N8")
|
|
409
|
-
sorcery_controller_external_property_set(:github, :callback_url, "http://blabla.com")
|
|
410
|
-
sorcery_controller_external_property_set(:google, :key, "eYVNBjBDi33aa9GkA3w")
|
|
411
|
-
sorcery_controller_external_property_set(:google, :secret, "XpbeSdCoaKSmQGSeokz5qcUATClRW5u08QWNfv71N8")
|
|
412
|
-
sorcery_controller_external_property_set(:google, :callback_url, "http://blabla.com")
|
|
413
|
-
sorcery_controller_external_property_set(:liveid, :key, "eYVNBjBDi33aa9GkA3w")
|
|
414
|
-
sorcery_controller_external_property_set(:liveid, :secret, "XpbeSdCoaKSmQGSeokz5qcUATClRW5u08QWNfv71N8")
|
|
415
|
-
sorcery_controller_external_property_set(:liveid, :callback_url, "http://blabla.com")
|
|
416
|
-
end
|
|
417
|
-
end
|
|
@@ -1,212 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
|
|
3
|
-
require 'shared_examples/controller_oauth_shared_examples'
|
|
4
|
-
require 'ostruct'
|
|
5
|
-
|
|
6
|
-
def stub_all_oauth_requests!
|
|
7
|
-
@consumer = OAuth::Consumer.new("key","secret", :site => "http://myapi.com")
|
|
8
|
-
OAuth::Consumer.stub(:new).and_return(@consumer)
|
|
9
|
-
|
|
10
|
-
@req_token = OAuth::RequestToken.new(@consumer)
|
|
11
|
-
@consumer.stub(:get_request_token).and_return(@req_token)
|
|
12
|
-
@acc_token = OAuth::AccessToken.new(@consumer)
|
|
13
|
-
@req_token.stub(:get_access_token).and_return(@acc_token)
|
|
14
|
-
session[:request_token] = @req_token.token
|
|
15
|
-
session[:request_token_secret] = @req_token.secret
|
|
16
|
-
OAuth::RequestToken.stub(:new).and_return(@req_token)
|
|
17
|
-
response = OpenStruct.new()
|
|
18
|
-
response.body = {"following"=>false, "listed_count"=>0, "profile_link_color"=>"0084B4", "profile_image_url"=>"http://a1.twimg.com/profile_images/536178575/noamb_normal.jpg", "description"=>"Programmer/Heavy Metal Fan/New Father", "status"=>{"text"=>"coming soon to sorcery gem: twitter and facebook authentication support.", "truncated"=>false, "favorited"=>false, "source"=>"web", "geo"=>nil, "in_reply_to_screen_name"=>nil, "in_reply_to_user_id"=>nil, "in_reply_to_status_id_str"=>nil, "created_at"=>"Sun Mar 06 23:01:12 +0000 2011", "contributors"=>nil, "place"=>nil, "retweeted"=>false, "in_reply_to_status_id"=>nil, "in_reply_to_user_id_str"=>nil, "coordinates"=>nil, "retweet_count"=>0, "id"=>44533012284706816, "id_str"=>"44533012284706816"}, "show_all_inline_media"=>false, "geo_enabled"=>true, "profile_sidebar_border_color"=>"a8c7f7", "url"=>nil, "followers_count"=>10, "screen_name"=>"nbenari", "profile_use_background_image"=>true, "location"=>"Israel", "statuses_count"=>25, "profile_background_color"=>"022330", "lang"=>"en", "verified"=>false, "notifications"=>false, "profile_background_image_url"=>"http://a3.twimg.com/profile_background_images/104087198/04042010339.jpg", "favourites_count"=>5, "created_at"=>"Fri Nov 20 21:58:19 +0000 2009", "is_translator"=>false, "contributors_enabled"=>false, "protected"=>false, "follow_request_sent"=>false, "time_zone"=>"Greenland", "profile_text_color"=>"333333", "name"=>"Noam Ben Ari", "friends_count"=>10, "profile_sidebar_fill_color"=>"C0DFEC", "id"=>123, "id_str"=>"91434812", "profile_background_tile"=>false, "utc_offset"=>-10800}.to_json
|
|
19
|
-
@acc_token.stub(:get).and_return(response)
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
describe SorceryController do
|
|
23
|
-
before(:all) do
|
|
24
|
-
ActiveRecord::Migrator.migrate("#{Rails.root}/db/migrate/external")
|
|
25
|
-
User.reset_column_information
|
|
26
|
-
|
|
27
|
-
sorcery_reload!([:external])
|
|
28
|
-
sorcery_controller_property_set(:external_providers, [:twitter])
|
|
29
|
-
sorcery_controller_external_property_set(:twitter, :key, "eYVNBjBDi33aa9GkA3w")
|
|
30
|
-
sorcery_controller_external_property_set(:twitter, :secret, "XpbeSdCoaKSmQGSeokz5qcUATClRW5u08QWNfv71N8")
|
|
31
|
-
sorcery_controller_external_property_set(:twitter, :callback_url, "http://blabla.com")
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
after(:all) do
|
|
35
|
-
ActiveRecord::Migrator.rollback("#{Rails.root}/db/migrate/external")
|
|
36
|
-
end
|
|
37
|
-
# ----------------- OAuth -----------------------
|
|
38
|
-
describe SorceryController, "'using external API to login'" do
|
|
39
|
-
|
|
40
|
-
before(:each) do
|
|
41
|
-
stub_all_oauth_requests!
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
after(:each) do
|
|
45
|
-
User.delete_all
|
|
46
|
-
Authentication.delete_all
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
context "when callback_url begin with /" do
|
|
50
|
-
before do
|
|
51
|
-
sorcery_controller_external_property_set(:twitter, :callback_url, "/oauth/twitter/callback")
|
|
52
|
-
end
|
|
53
|
-
it "login_at redirects correctly" do
|
|
54
|
-
create_new_user
|
|
55
|
-
get :login_at_test
|
|
56
|
-
response.should be_a_redirect
|
|
57
|
-
response.should redirect_to("http://myapi.com/oauth/authorize?oauth_callback=http%3A%2F%2Ftest.host%2Foauth%2Ftwitter%2Fcallback&oauth_token=")
|
|
58
|
-
end
|
|
59
|
-
after do
|
|
60
|
-
sorcery_controller_external_property_set(:twitter, :callback_url, "http://blabla.com")
|
|
61
|
-
end
|
|
62
|
-
end
|
|
63
|
-
|
|
64
|
-
context "when callback_url begin with http://" do
|
|
65
|
-
it "login_at redirects correctly", pending: true do
|
|
66
|
-
create_new_user
|
|
67
|
-
get :login_at_test
|
|
68
|
-
response.should be_a_redirect
|
|
69
|
-
response.should redirect_to("http://myapi.com/oauth/authorize?oauth_callback=http%3A%2F%2Fblabla.com&oauth_token=")
|
|
70
|
-
end
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
it "logins if user exists" do
|
|
74
|
-
sorcery_model_property_set(:authentications_class, Authentication)
|
|
75
|
-
create_new_external_user(:twitter)
|
|
76
|
-
get :test_login_from, :oauth_verifier => "blablaRERASDFcxvSDFA"
|
|
77
|
-
flash[:notice].should == "Success!"
|
|
78
|
-
end
|
|
79
|
-
|
|
80
|
-
it "'login_from' fails if user doesn't exist" do
|
|
81
|
-
sorcery_model_property_set(:authentications_class, Authentication)
|
|
82
|
-
create_new_user
|
|
83
|
-
get :test_login_from, :oauth_verifier => "blablaRERASDFcxvSDFA"
|
|
84
|
-
flash[:alert].should == "Failed!"
|
|
85
|
-
end
|
|
86
|
-
|
|
87
|
-
it "on successful 'login_from' the user should be redirected to the url he originally wanted" do
|
|
88
|
-
sorcery_model_property_set(:authentications_class, Authentication)
|
|
89
|
-
create_new_external_user(:twitter)
|
|
90
|
-
get :test_return_to_with_external, {}, :return_to_url => "fuu"
|
|
91
|
-
response.should redirect_to("fuu")
|
|
92
|
-
flash[:notice].should == "Success!"
|
|
93
|
-
end
|
|
94
|
-
|
|
95
|
-
end
|
|
96
|
-
|
|
97
|
-
describe SorceryController do
|
|
98
|
-
it_behaves_like "oauth_controller"
|
|
99
|
-
end
|
|
100
|
-
|
|
101
|
-
describe SorceryController, "using OAuth with User Activation features" do
|
|
102
|
-
before(:all) do
|
|
103
|
-
ActiveRecord::Migrator.migrate("#{Rails.root}/db/migrate/activation")
|
|
104
|
-
sorcery_reload!([:user_activation,:external], :user_activation_mailer => ::SorceryMailer)
|
|
105
|
-
end
|
|
106
|
-
|
|
107
|
-
after(:all) do
|
|
108
|
-
ActiveRecord::Migrator.rollback("#{Rails.root}/db/migrate/activation")
|
|
109
|
-
end
|
|
110
|
-
|
|
111
|
-
after(:each) do
|
|
112
|
-
User.delete_all
|
|
113
|
-
Authentication.delete_all
|
|
114
|
-
end
|
|
115
|
-
|
|
116
|
-
it "should not send activation email to external users" do
|
|
117
|
-
old_size = ActionMailer::Base.deliveries.size
|
|
118
|
-
create_new_external_user(:twitter)
|
|
119
|
-
ActionMailer::Base.deliveries.size.should == old_size
|
|
120
|
-
end
|
|
121
|
-
|
|
122
|
-
it "should not send external users an activation success email" do
|
|
123
|
-
sorcery_model_property_set(:activation_success_email_method_name, nil)
|
|
124
|
-
create_new_external_user(:twitter)
|
|
125
|
-
old_size = ActionMailer::Base.deliveries.size
|
|
126
|
-
@user.activate!
|
|
127
|
-
ActionMailer::Base.deliveries.size.should == old_size
|
|
128
|
-
end
|
|
129
|
-
end
|
|
130
|
-
|
|
131
|
-
describe SorceryController, "OAuth with user activation features" do
|
|
132
|
-
before(:all) do
|
|
133
|
-
ActiveRecord::Migrator.migrate("#{Rails.root}/db/migrate/external")
|
|
134
|
-
ActiveRecord::Migrator.migrate("#{Rails.root}/db/migrate/activity_logging")
|
|
135
|
-
User.reset_column_information
|
|
136
|
-
sorcery_reload!([:activity_logging, :external])
|
|
137
|
-
end
|
|
138
|
-
|
|
139
|
-
after(:all) do
|
|
140
|
-
ActiveRecord::Migrator.rollback("#{Rails.root}/db/migrate/external")
|
|
141
|
-
ActiveRecord::Migrator.rollback("#{Rails.root}/db/migrate/activity_logging")
|
|
142
|
-
User.reset_column_information
|
|
143
|
-
end
|
|
144
|
-
|
|
145
|
-
context "when twitter" do
|
|
146
|
-
before(:each) do
|
|
147
|
-
User.delete_all
|
|
148
|
-
Authentication.delete_all
|
|
149
|
-
sorcery_controller_property_set(:register_login_time, true)
|
|
150
|
-
stub_all_oauth_requests!
|
|
151
|
-
sorcery_model_property_set(:authentications_class, Authentication)
|
|
152
|
-
create_new_external_user(:twitter)
|
|
153
|
-
end
|
|
154
|
-
|
|
155
|
-
it "should register login time" do
|
|
156
|
-
now = Time.now.in_time_zone
|
|
157
|
-
get :test_login_from
|
|
158
|
-
User.last.last_login_at.should_not be_nil
|
|
159
|
-
User.last.last_login_at.to_s(:db).should >= now.to_s(:db)
|
|
160
|
-
User.last.last_login_at.to_s(:db).should <= (now+2).to_s(:db)
|
|
161
|
-
end
|
|
162
|
-
|
|
163
|
-
it "should not register login time if configured so" do
|
|
164
|
-
sorcery_controller_property_set(:register_login_time, false)
|
|
165
|
-
now = Time.now.in_time_zone
|
|
166
|
-
get :test_login_from
|
|
167
|
-
User.last.last_login_at.should be_nil
|
|
168
|
-
end
|
|
169
|
-
end
|
|
170
|
-
end
|
|
171
|
-
|
|
172
|
-
describe SorceryController, "OAuth with session timeout features" do
|
|
173
|
-
before(:all) do
|
|
174
|
-
ActiveRecord::Migrator.migrate("#{Rails.root}/db/migrate/external")
|
|
175
|
-
User.reset_column_information
|
|
176
|
-
sorcery_reload!([:session_timeout, :external])
|
|
177
|
-
end
|
|
178
|
-
|
|
179
|
-
after(:all) do
|
|
180
|
-
ActiveRecord::Migrator.rollback("#{Rails.root}/db/migrate/external")
|
|
181
|
-
end
|
|
182
|
-
|
|
183
|
-
context "when twitter" do
|
|
184
|
-
before(:each) do
|
|
185
|
-
User.delete_all
|
|
186
|
-
Authentication.delete_all
|
|
187
|
-
sorcery_model_property_set(:authentications_class, Authentication)
|
|
188
|
-
sorcery_controller_property_set(:session_timeout,0.5)
|
|
189
|
-
stub_all_oauth_requests!
|
|
190
|
-
create_new_external_user(:twitter)
|
|
191
|
-
end
|
|
192
|
-
|
|
193
|
-
after(:each) do
|
|
194
|
-
Timecop.return
|
|
195
|
-
end
|
|
196
|
-
|
|
197
|
-
it "should not reset session before session timeout" do
|
|
198
|
-
get :test_login_from
|
|
199
|
-
session[:user_id].should_not be_nil
|
|
200
|
-
flash[:notice].should == "Success!"
|
|
201
|
-
end
|
|
202
|
-
|
|
203
|
-
it "should reset session after session timeout" do
|
|
204
|
-
get :test_login_from
|
|
205
|
-
Timecop.travel(Time.now.in_time_zone+0.6)
|
|
206
|
-
get :test_should_be_logged_in
|
|
207
|
-
session[:user_id].should be_nil
|
|
208
|
-
response.should be_a_redirect
|
|
209
|
-
end
|
|
210
|
-
end
|
|
211
|
-
end
|
|
212
|
-
end
|