sorcery 0.7.12 → 0.7.13

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 (35) hide show
  1. data/Gemfile +5 -4
  2. data/Gemfile.lock +8 -7
  3. data/README.rdoc +5 -1
  4. data/VERSION +1 -1
  5. data/lib/generators/sorcery/templates/initializer.rb +5 -13
  6. data/lib/sorcery/controller.rb +6 -3
  7. data/lib/sorcery/controller/submodules/brute_force_protection.rb +1 -2
  8. data/lib/sorcery/controller/submodules/external.rb +80 -14
  9. data/lib/sorcery/crypto_providers/bcrypt.rb +1 -0
  10. data/lib/sorcery/model/adapters/active_record.rb +9 -4
  11. data/lib/sorcery/model/adapters/mongo_mapper.rb +16 -14
  12. data/lib/sorcery/model/adapters/mongoid.rb +10 -4
  13. data/lib/sorcery/model/submodules/brute_force_protection.rb +8 -8
  14. data/lib/sorcery/model/submodules/remember_me.rb +4 -6
  15. data/lib/sorcery/model/submodules/reset_password.rb +4 -4
  16. data/lib/sorcery/railties/tasks.rake +2 -0
  17. data/sorcery.gemspec +9 -6
  18. data/spec/Gemfile +1 -1
  19. data/spec/Gemfile.lock +7 -10
  20. data/spec/rails3/Gemfile.lock +7 -9
  21. data/spec/rails3/app/controllers/application_controller.rb +14 -0
  22. data/spec/rails3/spec/controller_activity_logging_spec.rb +3 -0
  23. data/spec/rails3/spec/controller_oauth2_spec.rb +125 -21
  24. data/spec/rails3/spec/controller_oauth_spec.rb +102 -6
  25. data/spec/rails3/spec/controller_spec.rb +7 -0
  26. data/spec/rails3_mongo_mapper/Gemfile.lock +7 -10
  27. data/spec/rails3_mongo_mapper/app/controllers/application_controller.rb +14 -0
  28. data/spec/rails3_mongo_mapper/spec/controller_spec.rb +7 -0
  29. data/spec/rails3_mongoid/Gemfile.lock +7 -10
  30. data/spec/rails3_mongoid/app/controllers/application_controller.rb +14 -0
  31. data/spec/rails3_mongoid/spec/controller_spec.rb +7 -0
  32. data/spec/shared_examples/controller_oauth2_shared_examples.rb +20 -1
  33. data/spec/shared_examples/controller_oauth_shared_examples.rb +18 -0
  34. data/spec/sorcery_crypto_providers_spec.rb +9 -0
  35. metadata +139 -123
@@ -72,7 +72,7 @@ module Sorcery
72
72
  config = sorcery_config
73
73
  return if !unlocked?
74
74
  self.increment(config.failed_logins_count_attribute_name)
75
- self.save!(:validate => false)
75
+ self.update_many_attributes(config.failed_logins_count_attribute_name => self.send(config.failed_logins_count_attribute_name))
76
76
  self.lock! if self.send(config.failed_logins_count_attribute_name) >= config.consecutive_login_retries_amount_limit
77
77
  end
78
78
 
@@ -81,23 +81,23 @@ module Sorcery
81
81
  # /!\
82
82
  def unlock!
83
83
  config = sorcery_config
84
- self.send(:"#{config.lock_expires_at_attribute_name}=", nil)
85
- self.send(:"#{config.failed_logins_count_attribute_name}=", 0)
86
- self.send(:"#{config.unlock_token_attribute_name}=", nil) unless config.unlock_token_mailer_disabled or config.unlock_token_mailer.nil?
87
- self.save!(:validate => false)
84
+ attributes = {config.lock_expires_at_attribute_name => nil,
85
+ config.failed_logins_count_attribute_name => 0}
86
+ attributes[config.unlock_token_attribute_name] = nil unless config.unlock_token_mailer_disabled or config.unlock_token_mailer.nil?
87
+ self.update_many_attributes(attributes)
88
88
  end
89
89
 
90
90
  protected
91
91
 
92
92
  def lock!
93
93
  config = sorcery_config
94
- self.send(:"#{config.lock_expires_at_attribute_name}=", Time.now.in_time_zone + config.login_lock_time_period)
94
+ attributes = {config.lock_expires_at_attribute_name => Time.now.in_time_zone + config.login_lock_time_period}
95
95
 
96
96
  unless config.unlock_token_mailer_disabled || config.unlock_token_mailer.nil?
97
- self.send(:"#{config.unlock_token_attribute_name}=", TemporaryToken.generate_random_token)
97
+ attributes[config.unlock_token_attribute_name] = TemporaryToken.generate_random_token
98
98
  send_unlock_token_email!
99
99
  end
100
- self.save!(:validate => false)
100
+ self.update_many_attributes(attributes)
101
101
  end
102
102
 
103
103
  def unlocked?
@@ -49,17 +49,15 @@ module Sorcery
49
49
  # You shouldn't really use this one yourself - it's called by the controller's 'remember_me!' method.
50
50
  def remember_me!
51
51
  config = sorcery_config
52
- self.send(:"#{config.remember_me_token_attribute_name}=", TemporaryToken.generate_random_token)
53
- self.send(:"#{config.remember_me_token_expires_at_attribute_name}=", Time.now.in_time_zone + config.remember_me_for)
54
- self.save!(:validate => false)
52
+ self.update_many_attributes(config.remember_me_token_attribute_name => TemporaryToken.generate_random_token,
53
+ config.remember_me_token_expires_at_attribute_name => Time.now.in_time_zone + config.remember_me_for)
55
54
  end
56
55
 
57
56
  # You shouldn't really use this one yourself - it's called by the controller's 'forget_me!' method.
58
57
  def forget_me!
59
58
  config = sorcery_config
60
- self.send(:"#{config.remember_me_token_attribute_name}=", nil)
61
- self.send(:"#{config.remember_me_token_expires_at_attribute_name}=", nil)
62
- self.save!(:validate => false)
59
+ self.update_many_attributes(config.remember_me_token_attribute_name => nil,
60
+ config.remember_me_token_expires_at_attribute_name => nil)
63
61
  end
64
62
  end
65
63
  end
@@ -96,11 +96,11 @@ module Sorcery
96
96
  config = sorcery_config
97
97
  # hammering protection
98
98
  return false if config.reset_password_time_between_emails && self.send(config.reset_password_email_sent_at_attribute_name) && self.send(config.reset_password_email_sent_at_attribute_name) > config.reset_password_time_between_emails.ago.utc
99
- self.send(:"#{config.reset_password_token_attribute_name}=", TemporaryToken.generate_random_token)
100
- self.send(:"#{config.reset_password_token_expires_at_attribute_name}=", Time.now.in_time_zone + config.reset_password_expiration_period) if config.reset_password_expiration_period
101
- self.send(:"#{config.reset_password_email_sent_at_attribute_name}=", Time.now.in_time_zone)
99
+ attributes = {config.reset_password_token_attribute_name => TemporaryToken.generate_random_token,
100
+ config.reset_password_email_sent_at_attribute_name => Time.now.in_time_zone}
101
+ attributes[config.reset_password_token_expires_at_attribute_name] = Time.now.in_time_zone + config.reset_password_expiration_period if config.reset_password_expiration_period
102
102
  self.class.transaction do
103
- self.save!(:validate => false)
103
+ self.update_many_attributes(attributes)
104
104
  generic_send_email(:reset_password_email_method_name, :reset_password_mailer) unless config.reset_password_mailer_disabled
105
105
  end
106
106
  end
@@ -3,6 +3,8 @@ require 'fileutils'
3
3
  namespace :sorcery do
4
4
  desc "Adds sorcery's initializer file"
5
5
  task :bootstrap do
6
+ warn "This task is obsolete.\nUse \"rails g sorcery:install\" now.\nSee README for more information."
7
+
6
8
  src = File.join(File.dirname(__FILE__), '..', 'initializers', 'initializer.rb')
7
9
  target = File.join(Rails.root, "config", "initializers", "sorcery.rb")
8
10
  FileUtils.cp(src, target)
data/sorcery.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "sorcery"
8
- s.version = "0.7.12"
8
+ s.version = "0.7.13"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Noam Ben Ari"]
12
- s.date = "2012-05-06"
12
+ s.date = "2012-07-22"
13
13
  s.description = "Provides common authentication needs such as signing in/out, activating by email and resetting password."
14
14
  s.email = "nbenari@gmail.com"
15
15
  s.extra_rdoc_files = [
@@ -302,7 +302,7 @@ Gem::Specification.new do |s|
302
302
  s.homepage = "http://github.com/NoamB/sorcery"
303
303
  s.licenses = ["MIT"]
304
304
  s.require_paths = ["lib"]
305
- s.rubygems_version = "1.8.10"
305
+ s.rubygems_version = "1.8.21"
306
306
  s.summary = "Magical authentication for Rails 3 applications"
307
307
 
308
308
  if s.respond_to? :specification_version then
@@ -310,8 +310,9 @@ Gem::Specification.new do |s|
310
310
 
311
311
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
312
312
  s.add_runtime_dependency(%q<oauth>, ["~> 0.4.4"])
313
- s.add_runtime_dependency(%q<oauth2>, ["~> 0.5.1"])
313
+ s.add_runtime_dependency(%q<oauth2>, ["~> 0.6.0"])
314
314
  s.add_runtime_dependency(%q<bcrypt-ruby>, ["~> 3.0.0"])
315
+ s.add_development_dependency(%q<abstract>, [">= 1.0.0"])
315
316
  s.add_development_dependency(%q<rails>, [">= 3.0.0"])
316
317
  s.add_development_dependency(%q<json>, [">= 1.5.1"])
317
318
  s.add_development_dependency(%q<rspec>, ["~> 2.5.0"])
@@ -328,8 +329,9 @@ Gem::Specification.new do |s|
328
329
  s.add_development_dependency(%q<mongoid>, ["~> 2.4.4"])
329
330
  else
330
331
  s.add_dependency(%q<oauth>, ["~> 0.4.4"])
331
- s.add_dependency(%q<oauth2>, ["~> 0.5.1"])
332
+ s.add_dependency(%q<oauth2>, ["~> 0.6.0"])
332
333
  s.add_dependency(%q<bcrypt-ruby>, ["~> 3.0.0"])
334
+ s.add_dependency(%q<abstract>, [">= 1.0.0"])
333
335
  s.add_dependency(%q<rails>, [">= 3.0.0"])
334
336
  s.add_dependency(%q<json>, [">= 1.5.1"])
335
337
  s.add_dependency(%q<rspec>, ["~> 2.5.0"])
@@ -347,8 +349,9 @@ Gem::Specification.new do |s|
347
349
  end
348
350
  else
349
351
  s.add_dependency(%q<oauth>, ["~> 0.4.4"])
350
- s.add_dependency(%q<oauth2>, ["~> 0.5.1"])
352
+ s.add_dependency(%q<oauth2>, ["~> 0.6.0"])
351
353
  s.add_dependency(%q<bcrypt-ruby>, ["~> 3.0.0"])
354
+ s.add_dependency(%q<abstract>, [">= 1.0.0"])
352
355
  s.add_dependency(%q<rails>, [">= 3.0.0"])
353
356
  s.add_dependency(%q<json>, [">= 1.5.1"])
354
357
  s.add_dependency(%q<rspec>, ["~> 2.5.0"])
data/spec/Gemfile CHANGED
@@ -4,7 +4,7 @@ gem "rails", '3.0.3'
4
4
  gem 'bcrypt-ruby', :require => 'bcrypt'
5
5
  gem "sorcery", '>= 0.1.0', :path => '../'
6
6
  gem 'oauth', "~> 0.4.4"
7
- gem 'oauth2', "~> 0.5.1"
7
+ gem 'oauth2', "~> 0.6.0"
8
8
  group :development do
9
9
  gem "rspec", "~> 2.5.0"
10
10
  gem 'ruby-debug19'
data/spec/Gemfile.lock CHANGED
@@ -1,12 +1,10 @@
1
1
  PATH
2
2
  remote: ../
3
3
  specs:
4
- sorcery (0.7.10)
4
+ sorcery (0.7.13)
5
5
  bcrypt-ruby (~> 3.0.0)
6
- bundler (>= 1.1.0)
7
6
  oauth (~> 0.4.4)
8
- oauth2 (~> 0.5.1)
9
- sorcery
7
+ oauth2 (~> 0.6.0)
10
8
 
11
9
  GEM
12
10
  remote: http://rubygems.org/
@@ -38,7 +36,6 @@ GEM
38
36
  activemodel (= 3.0.3)
39
37
  activesupport (= 3.0.3)
40
38
  activesupport (3.0.3)
41
- addressable (2.2.7)
42
39
  archive-tar-minitar (0.5.2)
43
40
  arel (2.0.10)
44
41
  bcrypt-ruby (3.0.1)
@@ -47,10 +44,9 @@ GEM
47
44
  diff-lcs (1.1.3)
48
45
  erubis (2.6.6)
49
46
  abstract (>= 1.0.0)
50
- faraday (0.7.6)
51
- addressable (~> 2.2)
47
+ faraday (0.8.1)
52
48
  multipart-post (~> 1.1)
53
- rack (~> 1.1)
49
+ httpauth (0.1)
54
50
  i18n (0.6.0)
55
51
  linecache19 (0.5.12)
56
52
  ruby_core_source (>= 0.1.4)
@@ -63,8 +59,9 @@ GEM
63
59
  multi_json (1.1.0)
64
60
  multipart-post (1.1.5)
65
61
  oauth (0.4.5)
66
- oauth2 (0.5.2)
62
+ oauth2 (0.6.0)
67
63
  faraday (~> 0.7)
64
+ httpauth (~> 0.1)
68
65
  multi_json (~> 1.0)
69
66
  polyglot (0.3.3)
70
67
  rack (1.2.5)
@@ -120,7 +117,7 @@ PLATFORMS
120
117
  DEPENDENCIES
121
118
  bcrypt-ruby
122
119
  oauth (~> 0.4.4)
123
- oauth2 (~> 0.5.1)
120
+ oauth2 (~> 0.6.0)
124
121
  rails (= 3.0.3)
125
122
  rspec (~> 2.5.0)
126
123
  ruby-debug19
@@ -1,12 +1,10 @@
1
1
  PATH
2
2
  remote: ../../
3
3
  specs:
4
- sorcery (0.7.10)
4
+ sorcery (0.7.13)
5
5
  bcrypt-ruby (~> 3.0.0)
6
- bundler (>= 1.1.0)
7
6
  oauth (~> 0.4.4)
8
- oauth2 (~> 0.5.1)
9
- sorcery
7
+ oauth2 (~> 0.6.0)
10
8
 
11
9
  GEM
12
10
  remote: http://rubygems.org/
@@ -56,11 +54,10 @@ GEM
56
54
  diff-lcs (1.1.3)
57
55
  erubis (2.6.6)
58
56
  abstract (>= 1.0.0)
59
- faraday (0.7.6)
60
- addressable (~> 2.2)
57
+ faraday (0.8.1)
61
58
  multipart-post (~> 1.1)
62
- rack (~> 1.1)
63
59
  ffi (1.0.11)
60
+ httpauth (0.1)
64
61
  i18n (0.6.0)
65
62
  launchy (2.0.5)
66
63
  addressable (~> 2.2.6)
@@ -75,9 +72,10 @@ GEM
75
72
  multi_json (1.1.0)
76
73
  multipart-post (1.1.5)
77
74
  nokogiri (1.5.0)
78
- oauth (0.4.5)
79
- oauth2 (0.5.2)
75
+ oauth (0.4.6)
76
+ oauth2 (0.6.0)
80
77
  faraday (~> 0.7)
78
+ httpauth (~> 0.1)
81
79
  multi_json (~> 1.0)
82
80
  polyglot (0.3.3)
83
81
  rack (1.2.5)
@@ -186,6 +186,20 @@ class ApplicationController < ActionController::Base
186
186
  redirect_to "blu", :alert => "Failed!"
187
187
  end
188
188
  end
189
+
190
+ def test_create_from_provider_with_block
191
+ provider = params[:provider]
192
+ login_from(provider)
193
+ @user = create_from(provider) do |user|
194
+ # check uniqueness of username
195
+ User.where(:username => user.username).empty?
196
+ end
197
+ if @user
198
+ redirect_to "bla", :notice => "Success!"
199
+ else
200
+ redirect_to "blu", :alert => "Failed!"
201
+ end
202
+ end
189
203
 
190
204
  protected
191
205
 
@@ -7,6 +7,9 @@ describe ApplicationController do
7
7
 
8
8
  after(:all) do
9
9
  ActiveRecord::Migrator.rollback("#{Rails.root}/db/migrate/activity_logging")
10
+ sorcery_controller_property_set(:register_login_time, true)
11
+ sorcery_controller_property_set(:register_logout_time, true)
12
+ sorcery_controller_property_set(:register_last_activity_time, true)
10
13
  end
11
14
 
12
15
  # ----------------- ACTIVITY LOGGING -----------------------
@@ -26,23 +26,27 @@ def stub_all_oauth2_requests!
26
26
  auth_code.stub(:get_token).and_return(access_token)
27
27
  end
28
28
 
29
+ def set_external_property
30
+ sorcery_controller_property_set(:external_providers, [:facebook, :github, :google, :liveid])
31
+ sorcery_controller_external_property_set(:facebook, :key, "eYVNBjBDi33aa9GkA3w")
32
+ sorcery_controller_external_property_set(:facebook, :secret, "XpbeSdCoaKSmQGSeokz5qcUATClRW5u08QWNfv71N8")
33
+ sorcery_controller_external_property_set(:facebook, :callback_url, "http://blabla.com")
34
+ sorcery_controller_external_property_set(:github, :key, "eYVNBjBDi33aa9GkA3w")
35
+ sorcery_controller_external_property_set(:github, :secret, "XpbeSdCoaKSmQGSeokz5qcUATClRW5u08QWNfv71N8")
36
+ sorcery_controller_external_property_set(:github, :callback_url, "http://blabla.com")
37
+ sorcery_controller_external_property_set(:google, :key, "eYVNBjBDi33aa9GkA3w")
38
+ sorcery_controller_external_property_set(:google, :secret, "XpbeSdCoaKSmQGSeokz5qcUATClRW5u08QWNfv71N8")
39
+ sorcery_controller_external_property_set(:google, :callback_url, "http://blabla.com")
40
+ sorcery_controller_external_property_set(:liveid, :key, "eYVNBjBDi33aa9GkA3w")
41
+ sorcery_controller_external_property_set(:liveid, :secret, "XpbeSdCoaKSmQGSeokz5qcUATClRW5u08QWNfv71N8")
42
+ sorcery_controller_external_property_set(:liveid, :callback_url, "http://blabla.com")
43
+ end
44
+
29
45
  describe ApplicationController do
30
46
  before(:all) do
31
47
  ActiveRecord::Migrator.migrate("#{Rails.root}/db/migrate/external")
32
48
  sorcery_reload!([:external])
33
- sorcery_controller_property_set(:external_providers, [:facebook, :github, :google, :liveid])
34
- sorcery_controller_external_property_set(:facebook, :key, "eYVNBjBDi33aa9GkA3w")
35
- sorcery_controller_external_property_set(:facebook, :secret, "XpbeSdCoaKSmQGSeokz5qcUATClRW5u08QWNfv71N8")
36
- sorcery_controller_external_property_set(:facebook, :callback_url, "http://blabla.com")
37
- sorcery_controller_external_property_set(:github, :key, "eYVNBjBDi33aa9GkA3w")
38
- sorcery_controller_external_property_set(:github, :secret, "XpbeSdCoaKSmQGSeokz5qcUATClRW5u08QWNfv71N8")
39
- sorcery_controller_external_property_set(:github, :callback_url, "http://blabla.com")
40
- sorcery_controller_external_property_set(:google, :key, "eYVNBjBDi33aa9GkA3w")
41
- sorcery_controller_external_property_set(:google, :secret, "XpbeSdCoaKSmQGSeokz5qcUATClRW5u08QWNfv71N8")
42
- sorcery_controller_external_property_set(:google, :callback_url, "http://blabla.com")
43
- sorcery_controller_external_property_set(:liveid, :key, "eYVNBjBDi33aa9GkA3w")
44
- sorcery_controller_external_property_set(:liveid, :secret, "XpbeSdCoaKSmQGSeokz5qcUATClRW5u08QWNfv71N8")
45
- sorcery_controller_external_property_set(:liveid, :callback_url, "http://blabla.com")
49
+ set_external_property
46
50
  end
47
51
 
48
52
  after(:all) do
@@ -60,13 +64,30 @@ describe ApplicationController do
60
64
  Authentication.delete_all
61
65
  end
62
66
 
63
- it "login_at redirects correctly" do
64
- create_new_user
65
- get :login_at_test2
66
- response.should be_a_redirect
67
- 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")
67
+ context "when callback_url begin with /" do
68
+ before do
69
+ sorcery_controller_external_property_set(:facebook, :callback_url, "/oauth/twitter/callback")
70
+ end
71
+ it "login_at redirects correctly" do
72
+ create_new_user
73
+ get :login_at_test2
74
+ response.should be_a_redirect
75
+ 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")
76
+ end
77
+ after do
78
+ sorcery_controller_external_property_set(:facebook, :callback_url, "http://blabla.com")
79
+ end
68
80
  end
69
81
 
82
+ context "when callback_url begin with http://" do
83
+ it "login_at redirects correctly" do
84
+ create_new_user
85
+ get :login_at_test2
86
+ response.should be_a_redirect
87
+ 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")
88
+ end
89
+ end
90
+
70
91
  it "'login_from' logins if user exists" do
71
92
  sorcery_model_property_set(:authentications_class, Authentication)
72
93
  create_new_external_user(:facebook)
@@ -94,7 +115,7 @@ describe ApplicationController do
94
115
  create_new_user
95
116
  get :login_at_test3
96
117
  response.should be_a_redirect
97
- 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=")
118
+ 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")
98
119
  end
99
120
 
100
121
  it "'login_from' logins if user exists (github)" do
@@ -124,7 +145,7 @@ describe ApplicationController do
124
145
  create_new_user
125
146
  get :login_at_test4
126
147
  response.should be_a_redirect
127
- 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%20https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.profile&display=")
148
+ 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")
128
149
  end
129
150
 
130
151
  it "'login_from' logins if user exists (google)" do
@@ -154,7 +175,7 @@ describe ApplicationController do
154
175
  create_new_user
155
176
  get :login_at_test5
156
177
  response.should be_a_redirect
157
- 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%20wl.emails%20wl.offline_access&display=")
178
+ 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")
158
179
  end
159
180
 
160
181
  it "'login_from' logins if user exists (liveid)" do
@@ -273,4 +294,87 @@ describe ApplicationController do
273
294
  ActionMailer::Base.deliveries.size.should == old_size
274
295
  end
275
296
  end
297
+
298
+ describe ApplicationController, "OAuth with user activation features" do
299
+ before(:all) do
300
+ ActiveRecord::Migrator.migrate("#{Rails.root}/db/migrate/external")
301
+ ActiveRecord::Migrator.migrate("#{Rails.root}/db/migrate/activity_logging")
302
+ sorcery_reload!([:activity_logging, :external])
303
+ end
304
+
305
+ after(:all) do
306
+ ActiveRecord::Migrator.rollback("#{Rails.root}/db/migrate/external")
307
+ ActiveRecord::Migrator.rollback("#{Rails.root}/db/migrate/activity_logging")
308
+ end
309
+
310
+ %w(facebook github google liveid).each.with_index(2) do |provider, index|
311
+ context "when #{provider}" do
312
+ before(:each) do
313
+ User.delete_all
314
+ Authentication.delete_all
315
+ sorcery_controller_property_set(:register_login_time, true)
316
+ stub_all_oauth2_requests!
317
+ sorcery_model_property_set(:authentications_class, Authentication)
318
+ create_new_external_user(provider.to_sym)
319
+ end
320
+
321
+ it "should register login time" do
322
+ now = Time.now.in_time_zone
323
+ get "test_login_from#{index}".to_sym
324
+ User.last.last_login_at.should_not be_nil
325
+ User.last.last_login_at.to_s(:db).should >= now.to_s(:db)
326
+ User.last.last_login_at.to_s(:db).should <= (now+2).to_s(:db)
327
+ end
328
+
329
+ it "should not register login time if configured so" do
330
+ sorcery_controller_property_set(:register_login_time, false)
331
+ now = Time.now.in_time_zone
332
+ get "test_login_from#{index}".to_sym
333
+ User.last.last_login_at.should be_nil
334
+ end
335
+ end
336
+ end
337
+ end
338
+
339
+ describe ApplicationController, "OAuth with session timeout features" do
340
+ before(:all) do
341
+ ActiveRecord::Migrator.migrate("#{Rails.root}/db/migrate/external")
342
+ sorcery_reload!([:session_timeout, :external])
343
+ end
344
+
345
+ after(:all) do
346
+ ActiveRecord::Migrator.rollback("#{Rails.root}/db/migrate/external")
347
+ end
348
+
349
+ %w(facebook github google liveid).each.with_index(2) do |provider, index|
350
+ context "when #{provider}" do
351
+ before(:each) do
352
+ User.delete_all
353
+ Authentication.delete_all
354
+ sorcery_model_property_set(:authentications_class, Authentication)
355
+ sorcery_controller_property_set(:session_timeout,0.5)
356
+ stub_all_oauth2_requests!
357
+ create_new_external_user(provider.to_sym)
358
+ end
359
+
360
+ after(:each) do
361
+ Timecop.return
362
+ end
363
+
364
+ it "should not reset session before session timeout" do
365
+ get "test_login_from#{index}".to_sym
366
+ session[:user_id].should_not be_nil
367
+ flash[:notice].should == "Success!"
368
+ end
369
+
370
+ it "should reset session after session timeout" do
371
+ get "test_login_from#{index}".to_sym
372
+ Timecop.travel(Time.now.in_time_zone+0.6)
373
+ get :test_should_be_logged_in
374
+ session[:user_id].should be_nil
375
+ response.should be_a_redirect
376
+ end
377
+ end
378
+ end
379
+ end
276
380
  end