sorcery 0.8.5 → 0.8.6
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of sorcery might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.travis.yml +60 -4
- data/CHANGELOG.md +15 -1
- data/Gemfile +9 -18
- data/Gemfile.rails4 +8 -10
- data/README.md +31 -11
- data/VERSION +1 -1
- data/gemfiles/active_record-rails41.gemfile +6 -0
- data/gemfiles/mongo_mapper-rails41.gemfile +8 -0
- data/gemfiles/mongoid-rails41.gemfile +11 -0
- data/lib/sorcery.rb +20 -28
- data/lib/sorcery/controller.rb +6 -11
- data/lib/sorcery/controller/submodules/external.rb +30 -15
- data/lib/sorcery/controller/submodules/session_timeout.rb +1 -1
- data/lib/sorcery/model.rb +102 -70
- data/lib/sorcery/model/adapters/active_record.rb +7 -2
- data/lib/sorcery/model/adapters/datamapper.rb +123 -0
- data/lib/sorcery/model/adapters/mongo_mapper.rb +8 -4
- data/lib/sorcery/model/adapters/mongoid.rb +6 -6
- data/lib/sorcery/model/submodules/activity_logging.rb +24 -0
- data/lib/sorcery/model/submodules/brute_force_protection.rb +16 -0
- data/lib/sorcery/model/submodules/remember_me.rb +19 -4
- data/lib/sorcery/model/submodules/reset_password.rb +30 -13
- data/lib/sorcery/model/submodules/user_activation.rb +53 -22
- data/lib/sorcery/{controller/submodules/external/protocols → protocols}/certs/ca-bundle.crt +0 -0
- data/lib/sorcery/protocols/oauth.rb +42 -0
- data/lib/sorcery/protocols/oauth2.rb +47 -0
- data/lib/sorcery/providers/base.rb +27 -0
- data/lib/sorcery/providers/facebook.rb +63 -0
- data/lib/sorcery/providers/github.rb +51 -0
- data/lib/sorcery/providers/google.rb +51 -0
- data/lib/sorcery/providers/linkedin.rb +66 -0
- data/lib/sorcery/providers/liveid.rb +53 -0
- data/lib/sorcery/providers/twitter.rb +59 -0
- data/lib/sorcery/providers/vk.rb +61 -0
- data/lib/sorcery/providers/xing.rb +64 -0
- data/lib/sorcery/test_helpers/internal.rb +3 -3
- data/lib/sorcery/test_helpers/internal/rails.rb +14 -3
- data/lib/sorcery/test_helpers/rails.rb +1 -10
- data/lib/sorcery/test_helpers/rails/controller.rb +17 -0
- data/lib/sorcery/test_helpers/rails/integration.rb +26 -0
- data/sorcery.gemspec +14 -18
- data/spec/active_record/controller_activity_logging_spec.rb +5 -116
- data/spec/active_record/controller_brute_force_protection_spec.rb +69 -47
- data/spec/active_record/controller_http_basic_auth_spec.rb +24 -18
- data/spec/active_record/controller_oauth2_spec.rb +112 -187
- data/spec/active_record/controller_oauth_spec.rb +41 -37
- data/spec/active_record/controller_remember_me_spec.rb +39 -38
- data/spec/active_record/controller_session_timeout_spec.rb +31 -16
- data/spec/active_record/controller_spec.rb +4 -178
- data/spec/active_record/integration_spec.rb +1 -1
- data/spec/active_record/user_activation_spec.rb +1 -1
- data/spec/active_record/user_activity_logging_spec.rb +1 -1
- data/spec/active_record/user_brute_force_protection_spec.rb +1 -1
- data/spec/active_record/user_oauth_spec.rb +1 -1
- data/spec/active_record/user_remember_me_spec.rb +1 -1
- data/spec/active_record/user_reset_password_spec.rb +1 -1
- data/spec/active_record/user_spec.rb +7 -8
- data/spec/datamapper/controller_activity_logging_spec.rb +17 -0
- data/spec/datamapper/controller_spec.rb +8 -0
- data/spec/datamapper/user_activation_spec.rb +10 -0
- data/spec/datamapper/user_activity_logging_spec.rb +9 -0
- data/spec/datamapper/user_brute_force_protection_spec.rb +9 -0
- data/spec/datamapper/user_oauth_spec.rb +9 -0
- data/spec/datamapper/user_remember_me_spec.rb +8 -0
- data/spec/datamapper/user_reset_password_spec.rb +8 -0
- data/spec/datamapper/user_spec.rb +27 -0
- data/spec/mongo_mapper/controller_spec.rb +4 -171
- data/spec/mongo_mapper/user_activation_spec.rb +1 -2
- data/spec/mongo_mapper/user_activity_logging_spec.rb +1 -1
- data/spec/mongo_mapper/user_brute_force_protection_spec.rb +1 -1
- data/spec/mongo_mapper/user_oauth_spec.rb +1 -1
- data/spec/mongo_mapper/user_remember_me_spec.rb +1 -1
- data/spec/mongo_mapper/user_reset_password_spec.rb +1 -1
- data/spec/mongo_mapper/user_spec.rb +7 -8
- data/spec/mongoid/controller_activity_logging_spec.rb +4 -99
- data/spec/mongoid/controller_spec.rb +4 -182
- data/spec/mongoid/user_activation_spec.rb +1 -2
- data/spec/mongoid/user_activity_logging_spec.rb +1 -2
- data/spec/mongoid/user_brute_force_protection_spec.rb +1 -2
- data/spec/mongoid/user_oauth_spec.rb +1 -2
- data/spec/mongoid/user_remember_me_spec.rb +1 -2
- data/spec/mongoid/user_reset_password_spec.rb +1 -2
- data/spec/mongoid/user_spec.rb +8 -9
- data/spec/orm/active_record.rb +2 -0
- data/spec/orm/datamapper.rb +34 -0
- data/spec/orm/mongo_mapper.rb +1 -0
- data/spec/orm/mongoid.rb +1 -0
- data/spec/rails_app/app/controllers/sorcery_controller.rb +64 -59
- data/spec/rails_app/app/datamapper/authentication.rb +8 -0
- data/spec/rails_app/app/datamapper/user.rb +7 -0
- data/spec/rails_app/config/routes.rb +18 -13
- data/spec/shared_examples/controller_activity_logging_shared_examples.rb +125 -0
- data/spec/shared_examples/controller_oauth2_shared_examples.rb +32 -36
- data/spec/shared_examples/controller_oauth_shared_examples.rb +19 -26
- data/spec/shared_examples/controller_shared_examples.rb +203 -0
- data/spec/shared_examples/user_activation_shared_examples.rb +107 -90
- data/spec/shared_examples/user_activity_logging_shared_examples.rb +10 -10
- data/spec/shared_examples/user_brute_force_protection_shared_examples.rb +14 -13
- data/spec/shared_examples/user_oauth_shared_examples.rb +23 -15
- data/spec/shared_examples/user_remember_me_shared_examples.rb +32 -23
- data/spec/shared_examples/user_reset_password_shared_examples.rb +136 -115
- data/spec/shared_examples/user_shared_examples.rb +206 -146
- data/spec/sorcery_crypto_providers_spec.rb +28 -28
- data/spec/spec_helper.rb +15 -6
- metadata +83 -127
- data/lib/sorcery/controller/submodules/external/protocols/oauth1.rb +0 -46
- data/lib/sorcery/controller/submodules/external/protocols/oauth2.rb +0 -50
- data/lib/sorcery/controller/submodules/external/providers/base.rb +0 -21
- data/lib/sorcery/controller/submodules/external/providers/facebook.rb +0 -99
- data/lib/sorcery/controller/submodules/external/providers/github.rb +0 -93
- data/lib/sorcery/controller/submodules/external/providers/google.rb +0 -92
- data/lib/sorcery/controller/submodules/external/providers/linkedin.rb +0 -103
- data/lib/sorcery/controller/submodules/external/providers/liveid.rb +0 -93
- data/lib/sorcery/controller/submodules/external/providers/twitter.rb +0 -94
- data/lib/sorcery/controller/submodules/external/providers/vk.rb +0 -101
- data/lib/sorcery/controller/submodules/external/providers/xing.rb +0 -98
- data/lib/sorcery/test_helpers.rb +0 -5
@@ -1,14 +1,15 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe SorceryController do
|
3
|
+
describe SorceryController, :active_record => true do
|
4
|
+
|
5
|
+
let!(:user) { create_new_user }
|
4
6
|
|
5
7
|
# ----------------- HTTP BASIC AUTH -----------------------
|
6
|
-
describe
|
8
|
+
describe "with http basic auth features" do
|
7
9
|
before(:all) do
|
8
10
|
sorcery_reload!([:http_basic_auth])
|
9
11
|
|
10
12
|
sorcery_controller_property_set(:controller_to_realm_map, {"sorcery" => "sorcery"})
|
11
|
-
create_new_user
|
12
13
|
end
|
13
14
|
|
14
15
|
after(:each) do
|
@@ -17,43 +18,48 @@ describe SorceryController do
|
|
17
18
|
|
18
19
|
it "requests basic authentication when before_filter is used" do
|
19
20
|
get :test_http_basic_auth
|
20
|
-
|
21
|
+
|
22
|
+
expect(response.code).to eq "401"
|
21
23
|
end
|
22
24
|
|
23
25
|
it "authenticates from http basic if credentials are sent" do
|
24
26
|
# dirty hack for rails 4
|
25
|
-
|
27
|
+
allow(subject).to receive(:register_last_activity_time_to_db)
|
26
28
|
|
27
|
-
@request.env["HTTP_AUTHORIZATION"] = "Basic " + Base64::encode64("#{
|
29
|
+
@request.env["HTTP_AUTHORIZATION"] = "Basic " + Base64::encode64("#{user.email}:secret")
|
28
30
|
get :test_http_basic_auth, nil, :http_authentication_used => true
|
29
|
-
|
31
|
+
|
32
|
+
expect(response).to be_a_success
|
30
33
|
end
|
31
34
|
|
32
35
|
it "fails authentication if credentials are wrong" do
|
33
|
-
@request.env["HTTP_AUTHORIZATION"] = "Basic " + Base64::encode64("#{
|
36
|
+
@request.env["HTTP_AUTHORIZATION"] = "Basic " + Base64::encode64("#{user.email}:wrong!")
|
34
37
|
get :test_http_basic_auth, nil, :http_authentication_used => true
|
35
|
-
|
38
|
+
|
39
|
+
expect(response).to redirect_to root_url
|
36
40
|
end
|
37
41
|
|
38
|
-
it "
|
42
|
+
it "allows configuration option 'controller_to_realm_map'" do
|
39
43
|
sorcery_controller_property_set(:controller_to_realm_map, {"1" => "2"})
|
40
|
-
|
44
|
+
|
45
|
+
expect(Sorcery::Controller::Config.controller_to_realm_map).to eq({"1" => "2"})
|
41
46
|
end
|
42
47
|
|
43
|
-
it "
|
48
|
+
it "displays the correct realm name configured for the controller" do
|
44
49
|
sorcery_controller_property_set(:controller_to_realm_map, {"sorcery" => "Salad"})
|
45
|
-
|
46
50
|
get :test_http_basic_auth
|
47
|
-
|
51
|
+
|
52
|
+
expect(response.headers["WWW-Authenticate"]).to eq "Basic realm=\"Salad\""
|
48
53
|
end
|
49
54
|
|
50
|
-
it "
|
55
|
+
it "signs in the user's session on successful login" do
|
51
56
|
# dirty hack for rails 4
|
52
|
-
|
57
|
+
allow(controller).to receive(:register_last_activity_time_to_db)
|
53
58
|
|
54
|
-
@request.env["HTTP_AUTHORIZATION"] = "Basic " + Base64::encode64("#{
|
59
|
+
@request.env["HTTP_AUTHORIZATION"] = "Basic " + Base64::encode64("#{user.email}:secret")
|
55
60
|
get :test_http_basic_auth, nil, :http_authentication_used => true
|
56
|
-
|
61
|
+
|
62
|
+
expect(session[:user_id]).to be User.find_by_email(user.email).id
|
57
63
|
end
|
58
64
|
end
|
59
65
|
end
|
@@ -2,7 +2,7 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
require 'shared_examples/controller_oauth2_shared_examples'
|
4
4
|
|
5
|
-
describe SorceryController do
|
5
|
+
describe SorceryController, :active_record => true do
|
6
6
|
before(:all) do
|
7
7
|
ActiveRecord::Migrator.migrate("#{Rails.root}/db/migrate/external")
|
8
8
|
User.reset_column_information
|
@@ -14,8 +14,11 @@ describe SorceryController do
|
|
14
14
|
after(:all) do
|
15
15
|
ActiveRecord::Migrator.rollback("#{Rails.root}/db/migrate/external")
|
16
16
|
end
|
17
|
+
|
18
|
+
it_behaves_like "oauth2_controller"
|
19
|
+
|
17
20
|
# ----------------- OAuth -----------------------
|
18
|
-
|
21
|
+
context "with OAuth features" do
|
19
22
|
|
20
23
|
before(:each) do
|
21
24
|
stub_all_oauth2_requests!
|
@@ -32,15 +35,15 @@ describe SorceryController do
|
|
32
35
|
end
|
33
36
|
it "login_at redirects correctly" do
|
34
37
|
create_new_user
|
35
|
-
get :
|
36
|
-
response.
|
37
|
-
response.
|
38
|
+
get :login_at_test_facebook
|
39
|
+
expect(response).to be_a_redirect
|
40
|
+
expect(response).to redirect_to("https://graph.facebook.com/oauth/authorize?client_id=#{::Sorcery::Controller::Config.facebook.key}&display=page&redirect_uri=http%3A%2F%2Ftest.host%2Foauth%2Ftwitter%2Fcallback&response_type=code&scope=email%2Coffline_access&state=")
|
38
41
|
end
|
39
42
|
it "logins with state" do
|
40
43
|
create_new_user
|
41
44
|
get :login_at_test_with_state
|
42
|
-
response.
|
43
|
-
response.
|
45
|
+
expect(response).to be_a_redirect
|
46
|
+
expect(response).to redirect_to("https://graph.facebook.com/oauth/authorize?client_id=#{::Sorcery::Controller::Config.facebook.key}&display=page&redirect_uri=http%3A%2F%2Ftest.host%2Foauth%2Ftwitter%2Fcallback&response_type=code&scope=email%2Coffline_access&state=bla")
|
44
47
|
end
|
45
48
|
after do
|
46
49
|
sorcery_controller_external_property_set(:facebook, :callback_url, "http://blabla.com")
|
@@ -60,148 +63,83 @@ describe SorceryController do
|
|
60
63
|
=end
|
61
64
|
it "'login_from' logins if user exists" do
|
62
65
|
# dirty hack for rails 4
|
63
|
-
|
66
|
+
allow(subject).to receive(:register_last_activity_time_to_db)
|
64
67
|
|
65
68
|
sorcery_model_property_set(:authentications_class, Authentication)
|
66
69
|
create_new_external_user(:facebook)
|
67
|
-
get :
|
68
|
-
|
70
|
+
get :test_login_from_facebook
|
71
|
+
|
72
|
+
expect(flash[:notice]).to eq "Success!"
|
69
73
|
end
|
70
74
|
|
71
75
|
it "'login_from' fails if user doesn't exist" do
|
72
76
|
sorcery_model_property_set(:authentications_class, Authentication)
|
73
77
|
create_new_user
|
74
|
-
get :
|
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
|
78
|
+
get :test_login_from_facebook
|
88
79
|
|
89
|
-
|
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")
|
80
|
+
expect(flash[:alert]).to eq "Failed!"
|
95
81
|
end
|
96
82
|
|
97
|
-
it "
|
83
|
+
it "on successful login_from the user is redirected to the url he originally wanted" do
|
98
84
|
# dirty hack for rails 4
|
99
|
-
|
85
|
+
allow(subject).to receive(:register_last_activity_time_to_db)
|
100
86
|
|
101
87
|
sorcery_model_property_set(:authentications_class, Authentication)
|
102
|
-
create_new_external_user(:
|
103
|
-
get :
|
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)
|
88
|
+
create_new_external_user(:facebook)
|
89
|
+
get :test_return_to_with_external_facebook, {}, :return_to_url => "fuu"
|
117
90
|
|
118
|
-
|
119
|
-
|
120
|
-
get :test_return_to_with_external3, {}, :return_to_url => "fuu"
|
121
|
-
response.should redirect_to("fuu")
|
122
|
-
flash[:notice].should == "Success!"
|
91
|
+
expect(response).to redirect_to("fuu")
|
92
|
+
expect(flash[:notice]).to eq "Success!"
|
123
93
|
end
|
124
94
|
|
125
|
-
|
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
|
95
|
+
[:github, :google, :liveid].each do |provider|
|
132
96
|
|
133
|
-
|
134
|
-
# dirty hack for rails 4
|
135
|
-
@controller.stub(:register_last_activity_time_to_db)
|
97
|
+
describe "with #{provider}" do
|
136
98
|
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
flash[:notice].should == "Success!"
|
141
|
-
end
|
99
|
+
it "login_at redirects correctly" do
|
100
|
+
create_new_user
|
101
|
+
get :"login_at_test_#{provider}"
|
142
102
|
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
get :test_login_from4
|
147
|
-
flash[:alert].should == "Failed!"
|
148
|
-
end
|
103
|
+
expect(response).to be_a_redirect
|
104
|
+
expect(response).to redirect_to(provider_url provider)
|
105
|
+
end
|
149
106
|
|
150
|
-
|
151
|
-
|
152
|
-
|
107
|
+
it "'login_from' logins if user exists" do
|
108
|
+
# dirty hack for rails 4
|
109
|
+
allow(subject).to receive(:register_last_activity_time_to_db)
|
153
110
|
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
response.should redirect_to("fuu")
|
158
|
-
flash[:notice].should == "Success!"
|
159
|
-
end
|
111
|
+
sorcery_model_property_set(:authentications_class, Authentication)
|
112
|
+
create_new_external_user(provider)
|
113
|
+
get :"test_login_from_#{provider}"
|
160
114
|
|
161
|
-
|
162
|
-
|
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
|
115
|
+
expect(flash[:notice]).to eq "Success!"
|
116
|
+
end
|
168
117
|
|
169
|
-
|
170
|
-
|
171
|
-
|
118
|
+
it "'login_from' fails if user doesn't exist" do
|
119
|
+
sorcery_model_property_set(:authentications_class, Authentication)
|
120
|
+
create_new_user
|
121
|
+
get :"test_login_from_#{provider}"
|
172
122
|
|
173
|
-
|
174
|
-
|
175
|
-
get :test_login_from5
|
176
|
-
flash[:notice].should == "Success!"
|
177
|
-
end
|
123
|
+
expect(flash[:alert]).to eq "Failed!"
|
124
|
+
end
|
178
125
|
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
get :test_login_from5
|
183
|
-
flash[:alert].should == "Failed!"
|
184
|
-
end
|
126
|
+
it "on successful login_from the user is redirected to the url he originally wanted (github)" do
|
127
|
+
# dirty hack for rails 4
|
128
|
+
allow(subject).to receive(:register_last_activity_time_to_db)
|
185
129
|
|
186
|
-
|
187
|
-
|
188
|
-
|
130
|
+
sorcery_model_property_set(:authentications_class, Authentication)
|
131
|
+
create_new_external_user(provider)
|
132
|
+
get :"test_return_to_with_external_#{provider}", {}, :return_to_url => "fuu"
|
189
133
|
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
flash[:notice].should == "Success!"
|
134
|
+
expect(response).to redirect_to "fuu"
|
135
|
+
expect(flash[:notice]).to eq "Success!"
|
136
|
+
end
|
137
|
+
end
|
195
138
|
end
|
196
139
|
|
197
140
|
end
|
198
141
|
|
199
|
-
|
200
|
-
describe SorceryController do
|
201
|
-
it_behaves_like "oauth2_controller"
|
202
|
-
end
|
203
|
-
|
204
|
-
describe SorceryController, "OAuth with User Activation features" do
|
142
|
+
describe "OAuth with User Activation features" do
|
205
143
|
before(:all) do
|
206
144
|
ActiveRecord::Migrator.migrate("#{Rails.root}/db/migrate/activation")
|
207
145
|
sorcery_reload!([:user_activation,:external], :user_activation_mailer => ::SorceryMailer)
|
@@ -229,67 +167,42 @@ describe SorceryController do
|
|
229
167
|
User.delete_all
|
230
168
|
end
|
231
169
|
|
232
|
-
it "
|
170
|
+
it "does not send activation email to external users" do
|
233
171
|
old_size = ActionMailer::Base.deliveries.size
|
234
172
|
create_new_external_user(:facebook)
|
235
|
-
|
173
|
+
|
174
|
+
expect(ActionMailer::Base.deliveries.size).to eq old_size
|
236
175
|
end
|
237
176
|
|
238
|
-
it "
|
177
|
+
it "does not send external users an activation success email" do
|
239
178
|
sorcery_model_property_set(:activation_success_email_method_name, nil)
|
240
179
|
create_new_external_user(:facebook)
|
241
180
|
old_size = ActionMailer::Base.deliveries.size
|
242
181
|
@user.activate!
|
243
|
-
ActionMailer::Base.deliveries.size.should == old_size
|
244
|
-
end
|
245
182
|
|
246
|
-
|
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
|
183
|
+
expect(ActionMailer::Base.deliveries.size).to eq old_size
|
251
184
|
end
|
252
185
|
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
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
|
186
|
+
# provider: github
|
187
|
+
[:github, :google, :liveid].each do |provider|
|
188
|
+
it "does not send activation email to external users (github)" do
|
189
|
+
old_size = ActionMailer::Base.deliveries.size
|
190
|
+
create_new_external_user provider
|
191
|
+
expect(ActionMailer::Base.deliveries.size).to eq old_size
|
192
|
+
end
|
275
193
|
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
end
|
194
|
+
it "does not send external users an activation success email (github)" do
|
195
|
+
sorcery_model_property_set(:activation_success_email_method_name, nil)
|
196
|
+
create_new_external_user provider
|
197
|
+
old_size = ActionMailer::Base.deliveries.size
|
198
|
+
@user.activate!
|
282
199
|
|
283
|
-
|
284
|
-
|
285
|
-
create_new_external_user(:liveid)
|
286
|
-
old_size = ActionMailer::Base.deliveries.size
|
287
|
-
@user.activate!
|
288
|
-
ActionMailer::Base.deliveries.size.should == old_size
|
200
|
+
expect(ActionMailer::Base.deliveries.size).to eq old_size
|
201
|
+
end
|
289
202
|
end
|
290
203
|
end
|
291
204
|
|
292
|
-
describe
|
205
|
+
describe "OAuth with user activation features" do
|
293
206
|
before(:all) do
|
294
207
|
ActiveRecord::Migrator.migrate("#{Rails.root}/db/migrate/external")
|
295
208
|
ActiveRecord::Migrator.migrate("#{Rails.root}/db/migrate/activity_logging")
|
@@ -302,7 +215,7 @@ describe SorceryController do
|
|
302
215
|
ActiveRecord::Migrator.rollback("#{Rails.root}/db/migrate/activity_logging")
|
303
216
|
end
|
304
217
|
|
305
|
-
%w(facebook github google liveid).each
|
218
|
+
%w(facebook github google liveid).each do |provider|
|
306
219
|
context "when #{provider}" do
|
307
220
|
before(:each) do
|
308
221
|
User.delete_all
|
@@ -313,25 +226,27 @@ describe SorceryController do
|
|
313
226
|
create_new_external_user(provider.to_sym)
|
314
227
|
end
|
315
228
|
|
316
|
-
it "
|
229
|
+
it "registers login time" do
|
317
230
|
now = Time.now.in_time_zone
|
318
|
-
get "
|
319
|
-
|
320
|
-
User.last.last_login_at
|
321
|
-
User.last.last_login_at.to_s(:db).
|
231
|
+
get "test_login_from_#{provider}".to_sym
|
232
|
+
|
233
|
+
expect(User.last.last_login_at).not_to be_nil
|
234
|
+
expect(User.last.last_login_at.to_s(:db)).to be >= now.to_s(:db)
|
235
|
+
expect(User.last.last_login_at.to_s(:db)).to be <= (now+2).to_s(:db)
|
322
236
|
end
|
323
237
|
|
324
|
-
it "
|
238
|
+
it "does not register login time if configured so" do
|
325
239
|
sorcery_controller_property_set(:register_login_time, false)
|
326
240
|
now = Time.now.in_time_zone
|
327
|
-
get "
|
328
|
-
|
241
|
+
get "test_login_from_#{provider}".to_sym
|
242
|
+
|
243
|
+
expect(User.last.last_login_at).to be_nil
|
329
244
|
end
|
330
245
|
end
|
331
246
|
end
|
332
247
|
end
|
333
248
|
|
334
|
-
describe
|
249
|
+
describe "OAuth with session timeout features" do
|
335
250
|
before(:all) do
|
336
251
|
ActiveRecord::Migrator.migrate("#{Rails.root}/db/migrate/external")
|
337
252
|
User.reset_column_information
|
@@ -342,7 +257,7 @@ describe SorceryController do
|
|
342
257
|
ActiveRecord::Migrator.rollback("#{Rails.root}/db/migrate/external")
|
343
258
|
end
|
344
259
|
|
345
|
-
%w(facebook github google liveid).each
|
260
|
+
%w(facebook github google liveid).each do |provider|
|
346
261
|
context "when #{provider}" do
|
347
262
|
before(:each) do
|
348
263
|
User.delete_all
|
@@ -357,29 +272,30 @@ describe SorceryController do
|
|
357
272
|
Timecop.return
|
358
273
|
end
|
359
274
|
|
360
|
-
it "
|
361
|
-
get "
|
362
|
-
|
363
|
-
|
275
|
+
it "does not reset session before session timeout" do
|
276
|
+
get "test_login_from_#{provider}".to_sym
|
277
|
+
|
278
|
+
expect(session[:user_id]).not_to be_nil
|
279
|
+
expect(flash[:notice]).to eq "Success!"
|
364
280
|
end
|
365
281
|
|
366
|
-
it "
|
367
|
-
get "
|
282
|
+
it "resets session after session timeout" do
|
283
|
+
get "test_login_from_#{provider}".to_sym
|
368
284
|
Timecop.travel(Time.now.in_time_zone+0.6)
|
369
285
|
get :test_should_be_logged_in
|
370
|
-
|
371
|
-
|
286
|
+
|
287
|
+
expect(session[:user_id]).to be_nil
|
288
|
+
expect(response).to be_a_redirect
|
372
289
|
end
|
373
290
|
end
|
374
291
|
end
|
375
292
|
end
|
376
293
|
|
377
294
|
def stub_all_oauth2_requests!
|
378
|
-
auth_code = OAuth2::Strategy::AuthCode.any_instance
|
379
295
|
access_token = double(OAuth2::AccessToken)
|
380
|
-
access_token.
|
296
|
+
allow(access_token).to receive(:token_param=)
|
381
297
|
response = double(OAuth2::Response)
|
382
|
-
response.
|
298
|
+
allow(response).to receive(:body) { {
|
383
299
|
"id"=>"123",
|
384
300
|
"name"=>"Noam Ben Ari",
|
385
301
|
"first_name"=>"Noam",
|
@@ -394,9 +310,9 @@ describe SorceryController do
|
|
394
310
|
"locale"=>"en_US",
|
395
311
|
"languages"=>[{"id"=>"108405449189952", "name"=>"Hebrew"}, {"id"=>"106059522759137", "name"=>"English"}, {"id"=>"112624162082677", "name"=>"Russian"}],
|
396
312
|
"verified"=>true,
|
397
|
-
"updated_time"=>"2011-02-16T20:59:38+0000"}.to_json
|
398
|
-
access_token.
|
399
|
-
|
313
|
+
"updated_time"=>"2011-02-16T20:59:38+0000"}.to_json }
|
314
|
+
allow(access_token).to receive(:get) { response }
|
315
|
+
allow_any_instance_of(OAuth2::Strategy::AuthCode).to receive(:get_token) { access_token }
|
400
316
|
end
|
401
317
|
|
402
318
|
def set_external_property
|
@@ -414,4 +330,13 @@ describe SorceryController do
|
|
414
330
|
sorcery_controller_external_property_set(:liveid, :secret, "XpbeSdCoaKSmQGSeokz5qcUATClRW5u08QWNfv71N8")
|
415
331
|
sorcery_controller_external_property_set(:liveid, :callback_url, "http://blabla.com")
|
416
332
|
end
|
333
|
+
|
334
|
+
def provider_url(provider)
|
335
|
+
{
|
336
|
+
github: "https://github.com/login/oauth/authorize?client_id=#{::Sorcery::Controller::Config.github.key}&display=&redirect_uri=http%3A%2F%2Fblabla.com&response_type=code&scope=&state=",
|
337
|
+
google: "https://accounts.google.com/o/oauth2/auth?client_id=#{::Sorcery::Controller::Config.google.key}&display=&redirect_uri=http%3A%2F%2Fblabla.com&response_type=code&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.profile&state=",
|
338
|
+
liveid: "https://oauth.live.com/authorize?client_id=#{::Sorcery::Controller::Config.liveid.key}&display=&redirect_uri=http%3A%2F%2Fblabla.com&response_type=code&scope=wl.basic+wl.emails+wl.offline_access&state="
|
339
|
+
}[provider]
|
340
|
+
end
|
341
|
+
|
417
342
|
end
|