sorcery 0.8.5 → 0.8.6

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of sorcery might be problematic. Click here for more details.

Files changed (119) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.travis.yml +60 -4
  4. data/CHANGELOG.md +15 -1
  5. data/Gemfile +9 -18
  6. data/Gemfile.rails4 +8 -10
  7. data/README.md +31 -11
  8. data/VERSION +1 -1
  9. data/gemfiles/active_record-rails41.gemfile +6 -0
  10. data/gemfiles/mongo_mapper-rails41.gemfile +8 -0
  11. data/gemfiles/mongoid-rails41.gemfile +11 -0
  12. data/lib/sorcery.rb +20 -28
  13. data/lib/sorcery/controller.rb +6 -11
  14. data/lib/sorcery/controller/submodules/external.rb +30 -15
  15. data/lib/sorcery/controller/submodules/session_timeout.rb +1 -1
  16. data/lib/sorcery/model.rb +102 -70
  17. data/lib/sorcery/model/adapters/active_record.rb +7 -2
  18. data/lib/sorcery/model/adapters/datamapper.rb +123 -0
  19. data/lib/sorcery/model/adapters/mongo_mapper.rb +8 -4
  20. data/lib/sorcery/model/adapters/mongoid.rb +6 -6
  21. data/lib/sorcery/model/submodules/activity_logging.rb +24 -0
  22. data/lib/sorcery/model/submodules/brute_force_protection.rb +16 -0
  23. data/lib/sorcery/model/submodules/remember_me.rb +19 -4
  24. data/lib/sorcery/model/submodules/reset_password.rb +30 -13
  25. data/lib/sorcery/model/submodules/user_activation.rb +53 -22
  26. data/lib/sorcery/{controller/submodules/external/protocols → protocols}/certs/ca-bundle.crt +0 -0
  27. data/lib/sorcery/protocols/oauth.rb +42 -0
  28. data/lib/sorcery/protocols/oauth2.rb +47 -0
  29. data/lib/sorcery/providers/base.rb +27 -0
  30. data/lib/sorcery/providers/facebook.rb +63 -0
  31. data/lib/sorcery/providers/github.rb +51 -0
  32. data/lib/sorcery/providers/google.rb +51 -0
  33. data/lib/sorcery/providers/linkedin.rb +66 -0
  34. data/lib/sorcery/providers/liveid.rb +53 -0
  35. data/lib/sorcery/providers/twitter.rb +59 -0
  36. data/lib/sorcery/providers/vk.rb +61 -0
  37. data/lib/sorcery/providers/xing.rb +64 -0
  38. data/lib/sorcery/test_helpers/internal.rb +3 -3
  39. data/lib/sorcery/test_helpers/internal/rails.rb +14 -3
  40. data/lib/sorcery/test_helpers/rails.rb +1 -10
  41. data/lib/sorcery/test_helpers/rails/controller.rb +17 -0
  42. data/lib/sorcery/test_helpers/rails/integration.rb +26 -0
  43. data/sorcery.gemspec +14 -18
  44. data/spec/active_record/controller_activity_logging_spec.rb +5 -116
  45. data/spec/active_record/controller_brute_force_protection_spec.rb +69 -47
  46. data/spec/active_record/controller_http_basic_auth_spec.rb +24 -18
  47. data/spec/active_record/controller_oauth2_spec.rb +112 -187
  48. data/spec/active_record/controller_oauth_spec.rb +41 -37
  49. data/spec/active_record/controller_remember_me_spec.rb +39 -38
  50. data/spec/active_record/controller_session_timeout_spec.rb +31 -16
  51. data/spec/active_record/controller_spec.rb +4 -178
  52. data/spec/active_record/integration_spec.rb +1 -1
  53. data/spec/active_record/user_activation_spec.rb +1 -1
  54. data/spec/active_record/user_activity_logging_spec.rb +1 -1
  55. data/spec/active_record/user_brute_force_protection_spec.rb +1 -1
  56. data/spec/active_record/user_oauth_spec.rb +1 -1
  57. data/spec/active_record/user_remember_me_spec.rb +1 -1
  58. data/spec/active_record/user_reset_password_spec.rb +1 -1
  59. data/spec/active_record/user_spec.rb +7 -8
  60. data/spec/datamapper/controller_activity_logging_spec.rb +17 -0
  61. data/spec/datamapper/controller_spec.rb +8 -0
  62. data/spec/datamapper/user_activation_spec.rb +10 -0
  63. data/spec/datamapper/user_activity_logging_spec.rb +9 -0
  64. data/spec/datamapper/user_brute_force_protection_spec.rb +9 -0
  65. data/spec/datamapper/user_oauth_spec.rb +9 -0
  66. data/spec/datamapper/user_remember_me_spec.rb +8 -0
  67. data/spec/datamapper/user_reset_password_spec.rb +8 -0
  68. data/spec/datamapper/user_spec.rb +27 -0
  69. data/spec/mongo_mapper/controller_spec.rb +4 -171
  70. data/spec/mongo_mapper/user_activation_spec.rb +1 -2
  71. data/spec/mongo_mapper/user_activity_logging_spec.rb +1 -1
  72. data/spec/mongo_mapper/user_brute_force_protection_spec.rb +1 -1
  73. data/spec/mongo_mapper/user_oauth_spec.rb +1 -1
  74. data/spec/mongo_mapper/user_remember_me_spec.rb +1 -1
  75. data/spec/mongo_mapper/user_reset_password_spec.rb +1 -1
  76. data/spec/mongo_mapper/user_spec.rb +7 -8
  77. data/spec/mongoid/controller_activity_logging_spec.rb +4 -99
  78. data/spec/mongoid/controller_spec.rb +4 -182
  79. data/spec/mongoid/user_activation_spec.rb +1 -2
  80. data/spec/mongoid/user_activity_logging_spec.rb +1 -2
  81. data/spec/mongoid/user_brute_force_protection_spec.rb +1 -2
  82. data/spec/mongoid/user_oauth_spec.rb +1 -2
  83. data/spec/mongoid/user_remember_me_spec.rb +1 -2
  84. data/spec/mongoid/user_reset_password_spec.rb +1 -2
  85. data/spec/mongoid/user_spec.rb +8 -9
  86. data/spec/orm/active_record.rb +2 -0
  87. data/spec/orm/datamapper.rb +34 -0
  88. data/spec/orm/mongo_mapper.rb +1 -0
  89. data/spec/orm/mongoid.rb +1 -0
  90. data/spec/rails_app/app/controllers/sorcery_controller.rb +64 -59
  91. data/spec/rails_app/app/datamapper/authentication.rb +8 -0
  92. data/spec/rails_app/app/datamapper/user.rb +7 -0
  93. data/spec/rails_app/config/routes.rb +18 -13
  94. data/spec/shared_examples/controller_activity_logging_shared_examples.rb +125 -0
  95. data/spec/shared_examples/controller_oauth2_shared_examples.rb +32 -36
  96. data/spec/shared_examples/controller_oauth_shared_examples.rb +19 -26
  97. data/spec/shared_examples/controller_shared_examples.rb +203 -0
  98. data/spec/shared_examples/user_activation_shared_examples.rb +107 -90
  99. data/spec/shared_examples/user_activity_logging_shared_examples.rb +10 -10
  100. data/spec/shared_examples/user_brute_force_protection_shared_examples.rb +14 -13
  101. data/spec/shared_examples/user_oauth_shared_examples.rb +23 -15
  102. data/spec/shared_examples/user_remember_me_shared_examples.rb +32 -23
  103. data/spec/shared_examples/user_reset_password_shared_examples.rb +136 -115
  104. data/spec/shared_examples/user_shared_examples.rb +206 -146
  105. data/spec/sorcery_crypto_providers_spec.rb +28 -28
  106. data/spec/spec_helper.rb +15 -6
  107. metadata +83 -127
  108. data/lib/sorcery/controller/submodules/external/protocols/oauth1.rb +0 -46
  109. data/lib/sorcery/controller/submodules/external/protocols/oauth2.rb +0 -50
  110. data/lib/sorcery/controller/submodules/external/providers/base.rb +0 -21
  111. data/lib/sorcery/controller/submodules/external/providers/facebook.rb +0 -99
  112. data/lib/sorcery/controller/submodules/external/providers/github.rb +0 -93
  113. data/lib/sorcery/controller/submodules/external/providers/google.rb +0 -92
  114. data/lib/sorcery/controller/submodules/external/providers/linkedin.rb +0 -103
  115. data/lib/sorcery/controller/submodules/external/providers/liveid.rb +0 -93
  116. data/lib/sorcery/controller/submodules/external/providers/twitter.rb +0 -94
  117. data/lib/sorcery/controller/submodules/external/providers/vk.rb +0 -101
  118. data/lib/sorcery/controller/submodules/external/providers/xing.rb +0 -98
  119. data/lib/sorcery/test_helpers.rb +0 -5
@@ -1,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 SorceryController, "with http basic auth features" do
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
- response.code.should == "401"
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
- @controller.stub(:register_last_activity_time_to_db)
27
+ allow(subject).to receive(:register_last_activity_time_to_db)
26
28
 
27
- @request.env["HTTP_AUTHORIZATION"] = "Basic " + Base64::encode64("#{@user.email}:secret")
29
+ @request.env["HTTP_AUTHORIZATION"] = "Basic " + Base64::encode64("#{user.email}:secret")
28
30
  get :test_http_basic_auth, nil, :http_authentication_used => true
29
- response.should be_a_success
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("#{@user.email}:wrong!")
36
+ @request.env["HTTP_AUTHORIZATION"] = "Basic " + Base64::encode64("#{user.email}:wrong!")
34
37
  get :test_http_basic_auth, nil, :http_authentication_used => true
35
- response.code.should redirect_to root_url
38
+
39
+ expect(response).to redirect_to root_url
36
40
  end
37
41
 
38
- it "should allow configuration option 'controller_to_realm_map'" do
42
+ it "allows configuration option 'controller_to_realm_map'" do
39
43
  sorcery_controller_property_set(:controller_to_realm_map, {"1" => "2"})
40
- Sorcery::Controller::Config.controller_to_realm_map.should == {"1" => "2"}
44
+
45
+ expect(Sorcery::Controller::Config.controller_to_realm_map).to eq({"1" => "2"})
41
46
  end
42
47
 
43
- it "should display the correct realm name configured for the controller" do
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
- response.headers["WWW-Authenticate"].should == "Basic realm=\"Salad\""
51
+
52
+ expect(response.headers["WWW-Authenticate"]).to eq "Basic realm=\"Salad\""
48
53
  end
49
54
 
50
- it "should sign in the user's session on successful login" do
55
+ it "signs in the user's session on successful login" do
51
56
  # dirty hack for rails 4
52
- @controller.stub(:register_last_activity_time_to_db)
57
+ allow(controller).to receive(:register_last_activity_time_to_db)
53
58
 
54
- @request.env["HTTP_AUTHORIZATION"] = "Basic " + Base64::encode64("#{@user.email}:secret")
59
+ @request.env["HTTP_AUTHORIZATION"] = "Basic " + Base64::encode64("#{user.email}:secret")
55
60
  get :test_http_basic_auth, nil, :http_authentication_used => true
56
- session[:user_id].should == User.find_by_email(@user.email).id
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
- describe SorceryController, "with OAuth features" do
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 :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
+ 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.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")
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
- @controller.stub(:register_last_activity_time_to_db)
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 :test_login_from2
68
- flash[:notice].should == "Success!"
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 :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
78
+ get :test_login_from_facebook
88
79
 
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")
80
+ expect(flash[:alert]).to eq "Failed!"
95
81
  end
96
82
 
97
- it "'login_from' logins if user exists (github)" do
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
- @controller.stub(:register_last_activity_time_to_db)
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(: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)
88
+ create_new_external_user(:facebook)
89
+ get :test_return_to_with_external_facebook, {}, :return_to_url => "fuu"
117
90
 
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!"
91
+ expect(response).to redirect_to("fuu")
92
+ expect(flash[:notice]).to eq "Success!"
123
93
  end
124
94
 
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
95
+ [:github, :google, :liveid].each do |provider|
132
96
 
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)
97
+ describe "with #{provider}" do
136
98
 
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
99
+ it "login_at redirects correctly" do
100
+ create_new_user
101
+ get :"login_at_test_#{provider}"
142
102
 
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
103
+ expect(response).to be_a_redirect
104
+ expect(response).to redirect_to(provider_url provider)
105
+ end
149
106
 
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)
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
- 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
111
+ sorcery_model_property_set(:authentications_class, Authentication)
112
+ create_new_external_user(provider)
113
+ get :"test_login_from_#{provider}"
160
114
 
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
115
+ expect(flash[:notice]).to eq "Success!"
116
+ end
168
117
 
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)
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
- 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
123
+ expect(flash[:alert]).to eq "Failed!"
124
+ end
178
125
 
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
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
- 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)
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
- 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!"
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 "should not send activation email to external users" do
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
- ActionMailer::Base.deliveries.size.should == old_size
173
+
174
+ expect(ActionMailer::Base.deliveries.size).to eq old_size
236
175
  end
237
176
 
238
- it "should not send external users an activation success email" do
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
- # 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
183
+ expect(ActionMailer::Base.deliveries.size).to eq old_size
251
184
  end
252
185
 
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
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
- # 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
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
- 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
200
+ expect(ActionMailer::Base.deliveries.size).to eq old_size
201
+ end
289
202
  end
290
203
  end
291
204
 
292
- describe SorceryController, "OAuth with user activation features" do
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.with_index(2) do |provider, index|
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 "should register login time" do
229
+ it "registers login time" do
317
230
  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)
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 "should not register login time if configured so" do
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 "test_login_from#{index}".to_sym
328
- User.last.last_login_at.should be_nil
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 SorceryController, "OAuth with session timeout features" do
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.with_index(2) do |provider, index|
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 "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!"
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 "should reset session after session timeout" do
367
- get "test_login_from#{index}".to_sym
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
- session[:user_id].should be_nil
371
- response.should be_a_redirect
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.stub(:token_param=)
296
+ allow(access_token).to receive(:token_param=)
381
297
  response = double(OAuth2::Response)
382
- response.stub(:body).and_return({
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.stub(:get).and_return(response)
399
- auth_code.stub(:get_token).and_return(access_token)
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