sorcery 0.7.4 → 0.7.6

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.
Files changed (46) hide show
  1. data/Gemfile +1 -1
  2. data/Gemfile.lock +41 -41
  3. data/README.rdoc +1 -1
  4. data/Rakefile +1 -1
  5. data/VERSION +1 -1
  6. data/lib/generators/sorcery/install_generator.rb +6 -3
  7. data/lib/generators/sorcery/templates/initializer.rb +25 -4
  8. data/lib/generators/sorcery/templates/migration/reset_password.rb +1 -1
  9. data/lib/sorcery/controller/submodules/activity_logging.rb +3 -3
  10. data/lib/sorcery/controller/submodules/external/protocols/oauth2.rb +19 -19
  11. data/lib/sorcery/controller/submodules/external/providers/facebook.rb +5 -2
  12. data/lib/sorcery/controller/submodules/external/providers/github.rb +12 -3
  13. data/lib/sorcery/controller/submodules/external/providers/google.rb +90 -0
  14. data/lib/sorcery/controller/submodules/external/providers/liveid.rb +91 -0
  15. data/lib/sorcery/controller/submodules/external/providers/twitter.rb +2 -1
  16. data/lib/sorcery/controller/submodules/external.rb +6 -0
  17. data/lib/sorcery/model/adapters/active_record.rb +16 -1
  18. data/lib/sorcery/model/adapters/mongo_mapper.rb +6 -1
  19. data/lib/sorcery/model/adapters/mongoid.rb +12 -1
  20. data/lib/sorcery/model/submodules/activity_logging.rb +4 -4
  21. data/lib/sorcery/model/submodules/brute_force_protection.rb +5 -5
  22. data/lib/sorcery/model/submodules/reset_password.rb +4 -5
  23. data/lib/sorcery/model/submodules/user_activation.rb +1 -2
  24. data/lib/sorcery/model.rb +17 -4
  25. data/lib/sorcery.rb +2 -0
  26. data/sorcery.gemspec +131 -9
  27. data/spec/Gemfile +1 -1
  28. data/spec/Gemfile.lock +14 -14
  29. data/spec/rails3/Gemfile +2 -3
  30. data/spec/rails3/Gemfile.lock +45 -26
  31. data/spec/rails3/app/controllers/application_controller.rb +31 -2
  32. data/spec/rails3/config/environments/in_memory.rb +35 -0
  33. data/spec/rails3/spec/controller_activity_logging_spec.rb +7 -0
  34. data/spec/rails3/spec/controller_oauth2_spec.rb +111 -11
  35. data/spec/rails3/spec/controller_spec.rb +30 -2
  36. data/spec/rails3/spec/integration_spec.rb +15 -15
  37. data/spec/rails3/spec/spec_helper.rb +1 -1
  38. data/spec/rails3_mongo_mapper/Gemfile.lock +22 -22
  39. data/spec/rails3_mongo_mapper/spec/controller_spec.rb +34 -1
  40. data/spec/rails3_mongoid/Gemfile.lock +18 -18
  41. data/spec/rails3_mongoid/app/controllers/application_controller.rb +5 -0
  42. data/spec/rails3_mongoid/spec/controller_activity_logging_spec.rb +10 -3
  43. data/spec/rails3_mongoid/spec/controller_spec.rb +34 -1
  44. data/spec/shared_examples/user_reset_password_shared_examples.rb +9 -1
  45. data/spec/sorcery_crypto_providers_spec.rb +5 -1
  46. metadata +235 -120
@@ -9,16 +9,21 @@ class ApplicationController < ActionController::Base
9
9
 
10
10
  def index
11
11
  end
12
-
12
+
13
13
  def some_action
14
14
  render :nothing => true
15
15
  end
16
16
 
17
+ def some_action_making_a_non_persisted_change_to_the_user
18
+ current_user.username = "to_be_ignored"
19
+ render :nothing => true
20
+ end
21
+
17
22
  def test_login
18
23
  @user = login(params[:username], params[:password])
19
24
  render :text => ""
20
25
  end
21
-
26
+
22
27
  def test_auto_login
23
28
  @user = User.find(:first)
24
29
  auto_login(@user)
@@ -84,6 +89,14 @@ class ApplicationController < ActionController::Base
84
89
  login_at(:github)
85
90
  end
86
91
 
92
+ def login_at_test4
93
+ login_at(:google)
94
+ end
95
+
96
+ def login_at_test5
97
+ login_at(:liveid)
98
+ end
99
+
87
100
  def test_login_from
88
101
  if @user = login_from(:twitter)
89
102
  redirect_to "bla", :notice => "Success!"
@@ -108,6 +121,22 @@ class ApplicationController < ActionController::Base
108
121
  end
109
122
  end
110
123
 
124
+ def test_login_from4
125
+ if @user = login_from(:google)
126
+ redirect_to "bla", :notice => "Success!"
127
+ else
128
+ redirect_to "blu", :alert => "Failed!"
129
+ end
130
+ end
131
+
132
+ def test_login_from5
133
+ if @user = login_from(:liveid)
134
+ redirect_to "bla", :notice => "Success!"
135
+ else
136
+ redirect_to "blu", :alert => "Failed!"
137
+ end
138
+ end
139
+
111
140
  def test_create_from_provider
112
141
  provider = params[:provider]
113
142
  login_from(provider)
@@ -0,0 +1,35 @@
1
+ AppRoot::Application.configure do
2
+ # Settings specified here will take precedence over those in config/application.rb
3
+
4
+ # The test environment is used exclusively to run your application's
5
+ # test suite. You never need to work with it otherwise. Remember that
6
+ # your test database is "scratch space" for the test suite and is wiped
7
+ # and recreated between test runs. Don't rely on the data there!
8
+ config.cache_classes = true
9
+
10
+ # Log error messages when you accidentally call methods on nil.
11
+ config.whiny_nils = true
12
+
13
+ # Show full error reports and disable caching
14
+ config.consider_all_requests_local = true
15
+ config.action_controller.perform_caching = false
16
+
17
+ # Raise exceptions instead of rendering exception templates
18
+ config.action_dispatch.show_exceptions = false
19
+
20
+ # Disable request forgery protection in test environment
21
+ config.action_controller.allow_forgery_protection = true
22
+
23
+ # Tell Action Mailer not to deliver emails to the real world.
24
+ # The :test delivery method accumulates sent emails in the
25
+ # ActionMailer::Base.deliveries array.
26
+ config.action_mailer.delivery_method = :test
27
+
28
+ # Use SQL instead of Active Record's schema dumper when creating the test database.
29
+ # This is necessary if your schema can't be completely dumped by the schema dumper,
30
+ # like if you have constraints or database-specific column types
31
+ # config.active_record.schema_format = :sql
32
+
33
+ # Print deprecation notices to the stderr
34
+ config.active_support.deprecation = :stderr
35
+ end
@@ -54,6 +54,13 @@ describe ApplicationController do
54
54
  User.first.last_activity_at.to_s(:db).should <= (now+2).to_s(:db)
55
55
  end
56
56
 
57
+ it "should update nothing but activity fields" do
58
+ original_user_name = User.first.username
59
+ login_user
60
+ get :some_action_making_a_non_persisted_change_to_the_user
61
+ User.first.username.should == original_user_name
62
+ end
63
+
57
64
  it "'current_users' should hold the user object when 1 user is logged in" do
58
65
  login_user
59
66
  get :some_action
@@ -2,26 +2,45 @@ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
2
  require File.expand_path(File.dirname(__FILE__) + '/../../shared_examples/controller_oauth2_shared_examples')
3
3
 
4
4
  def stub_all_oauth2_requests!
5
- @client = OAuth2::Client.new("key","secret", :site => "http://myapi.com")
6
- OAuth2::Client.stub!(:new).and_return(@client)
7
- @acc_token = OAuth2::AccessToken.new(@client, "asd", {})
8
- @webby = @client.web_server
9
- OAuth2::Strategy::WebServer.stub!(:new).and_return(@webby)
10
- @webby.stub!(:get_access_token).and_return(@acc_token)
11
- @acc_token.stub!(:get).and_return({"id"=>"123", "name"=>"Noam Ben Ari", "first_name"=>"Noam", "last_name"=>"Ben Ari", "link"=>"http://www.facebook.com/nbenari1", "hometown"=>{"id"=>"110619208966868", "name"=>"Haifa, Israel"}, "location"=>{"id"=>"106906559341067", "name"=>"Pardes Hanah, Hefa, Israel"}, "bio"=>"I'm a new daddy, and enjoying it!", "gender"=>"male", "email"=>"nbenari@gmail.com", "timezone"=>2, "locale"=>"en_US", "languages"=>[{"id"=>"108405449189952", "name"=>"Hebrew"}, {"id"=>"106059522759137", "name"=>"English"}, {"id"=>"112624162082677", "name"=>"Russian"}], "verified"=>true, "updated_time"=>"2011-02-16T20:59:38+0000"}.to_json)
5
+ auth_code = OAuth2::Strategy::AuthCode.any_instance
6
+ access_token = mock(OAuth2::AccessToken)
7
+ access_token.stub(:token_param=)
8
+ access_token.stub(:get).and_return({
9
+ "id"=>"123",
10
+ "name"=>"Noam Ben Ari",
11
+ "first_name"=>"Noam",
12
+ "last_name"=>"Ben Ari",
13
+ "link"=>"http://www.facebook.com/nbenari1",
14
+ "hometown"=>{"id"=>"110619208966868", "name"=>"Haifa, Israel"},
15
+ "location"=>{"id"=>"106906559341067", "name"=>"Pardes Hanah, Hefa, Israel"},
16
+ "bio"=>"I'm a new daddy, and enjoying it!",
17
+ "gender"=>"male",
18
+ "email"=>"nbenari@gmail.com",
19
+ "timezone"=>2,
20
+ "locale"=>"en_US",
21
+ "languages"=>[{"id"=>"108405449189952", "name"=>"Hebrew"}, {"id"=>"106059522759137", "name"=>"English"}, {"id"=>"112624162082677", "name"=>"Russian"}],
22
+ "verified"=>true,
23
+ "updated_time"=>"2011-02-16T20:59:38+0000"}.to_json)
24
+ auth_code.stub(:get_access_token).and_return(access_token)
12
25
  end
13
26
 
14
27
  describe ApplicationController do
15
28
  before(:all) do
16
29
  ActiveRecord::Migrator.migrate("#{Rails.root}/db/migrate/external")
17
30
  sorcery_reload!([:external])
18
- sorcery_controller_property_set(:external_providers, [:facebook, :github])
31
+ sorcery_controller_property_set(:external_providers, [:facebook, :github, :google, :liveid])
19
32
  sorcery_controller_external_property_set(:facebook, :key, "eYVNBjBDi33aa9GkA3w")
20
33
  sorcery_controller_external_property_set(:facebook, :secret, "XpbeSdCoaKSmQGSeokz5qcUATClRW5u08QWNfv71N8")
21
34
  sorcery_controller_external_property_set(:facebook, :callback_url, "http://blabla.com")
22
35
  sorcery_controller_external_property_set(:github, :key, "eYVNBjBDi33aa9GkA3w")
23
36
  sorcery_controller_external_property_set(:github, :secret, "XpbeSdCoaKSmQGSeokz5qcUATClRW5u08QWNfv71N8")
24
37
  sorcery_controller_external_property_set(:github, :callback_url, "http://blabla.com")
38
+ sorcery_controller_external_property_set(:google, :key, "eYVNBjBDi33aa9GkA3w")
39
+ sorcery_controller_external_property_set(:google, :secret, "XpbeSdCoaKSmQGSeokz5qcUATClRW5u08QWNfv71N8")
40
+ sorcery_controller_external_property_set(:google, :callback_url, "http://blabla.com")
41
+ sorcery_controller_external_property_set(:liveid, :key, "eYVNBjBDi33aa9GkA3w")
42
+ sorcery_controller_external_property_set(:liveid, :secret, "XpbeSdCoaKSmQGSeokz5qcUATClRW5u08QWNfv71N8")
43
+ sorcery_controller_external_property_set(:liveid, :callback_url, "http://blabla.com")
25
44
  end
26
45
 
27
46
  after(:all) do
@@ -43,7 +62,7 @@ describe ApplicationController do
43
62
  create_new_user
44
63
  get :login_at_test2
45
64
  response.should be_a_redirect
46
- response.should redirect_to("http://myapi.com/oauth/authorize?client_id=key&redirect_uri=http%3A%2F%2Fblabla.com&scope=email%2Coffline_access&response_type=code")
65
+ 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")
47
66
  end
48
67
 
49
68
  it "'login_from' logins if user exists" do
@@ -65,7 +84,7 @@ describe ApplicationController do
65
84
  create_new_user
66
85
  get :login_at_test3
67
86
  response.should be_a_redirect
68
- response.should redirect_to("http://myapi.com/oauth/authorize?client_id=key&redirect_uri=http%3A%2F%2Fblabla.com&scope=&response_type=code")
87
+ response.should redirect_to("https://github.com/oauth/authorize?response_type=code&client_id=#{::Sorcery::Controller::Config.github.key}&redirect_uri=http%3A%2F%2Fblabla.com&scope=&display=")
69
88
  end
70
89
 
71
90
  it "'login_from' logins if user exists (github)" do
@@ -82,6 +101,50 @@ describe ApplicationController do
82
101
  flash[:alert].should == "Failed!"
83
102
  end
84
103
 
104
+ # provider: google
105
+ it "login_at redirects correctly (google)" do
106
+ create_new_user
107
+ get :login_at_test4
108
+ response.should be_a_redirect
109
+ 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=")
110
+ end
111
+
112
+ it "'login_from' logins if user exists (google)" do
113
+ sorcery_model_property_set(:authentications_class, Authentication)
114
+ create_new_external_user(:google)
115
+ get :test_login_from4
116
+ flash[:notice].should == "Success!"
117
+ end
118
+
119
+ it "'login_from' fails if user doesn't exist (google)" do
120
+ sorcery_model_property_set(:authentications_class, Authentication)
121
+ create_new_user
122
+ get :test_login_from4
123
+ flash[:alert].should == "Failed!"
124
+ end
125
+
126
+ # provider: liveid
127
+ it "login_at redirects correctly (liveid)" do
128
+ create_new_user
129
+ get :login_at_test5
130
+ response.should be_a_redirect
131
+ 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=")
132
+ end
133
+
134
+ it "'login_from' logins if user exists (liveid)" do
135
+ sorcery_model_property_set(:authentications_class, Authentication)
136
+ create_new_external_user(:liveid)
137
+ get :test_login_from5
138
+ flash[:notice].should == "Success!"
139
+ end
140
+
141
+ it "'login_from' fails if user doesn't exist (liveid)" do
142
+ sorcery_model_property_set(:authentications_class, Authentication)
143
+ create_new_user
144
+ get :test_login_from5
145
+ flash[:alert].should == "Failed!"
146
+ end
147
+
85
148
  end
86
149
 
87
150
 
@@ -93,13 +156,20 @@ describe ApplicationController do
93
156
  before(:all) do
94
157
  ActiveRecord::Migrator.migrate("#{Rails.root}/db/migrate/activation")
95
158
  sorcery_reload!([:user_activation,:external], :user_activation_mailer => ::SorceryMailer)
96
- sorcery_controller_property_set(:external_providers, [:facebook, :github])
159
+ sorcery_controller_property_set(:external_providers, [:facebook, :github, :google, :liveid])
97
160
  sorcery_controller_external_property_set(:facebook, :key, "eYVNBjBDi33aa9GkA3w")
98
161
  sorcery_controller_external_property_set(:facebook, :secret, "XpbeSdCoaKSmQGSeokz5qcUATClRW5u08QWNfv71N8")
99
162
  sorcery_controller_external_property_set(:facebook, :callback_url, "http://blabla.com")
100
163
  sorcery_controller_external_property_set(:github, :key, "eYVNBjBDi33aa9GkA3w")
101
164
  sorcery_controller_external_property_set(:github, :secret, "XpbeSdCoaKSmQGSeokz5qcUATClRW5u08QWNfv71N8")
102
165
  sorcery_controller_external_property_set(:github, :callback_url, "http://blabla.com")
166
+ sorcery_controller_external_property_set(:google, :key, "eYVNBjBDi33aa9GkA3w")
167
+ sorcery_controller_external_property_set(:google, :secret, "XpbeSdCoaKSmQGSeokz5qcUATClRW5u08QWNfv71N8")
168
+ sorcery_controller_external_property_set(:google, :callback_url, "http://blabla.com")
169
+ sorcery_controller_external_property_set(:liveid, :key, "eYVNBjBDi33aa9GkA3w")
170
+ sorcery_controller_external_property_set(:liveid, :secret, "XpbeSdCoaKSmQGSeokz5qcUATClRW5u08QWNfv71N8")
171
+ sorcery_controller_external_property_set(:liveid, :callback_url, "http://blabla.com")
172
+
103
173
  end
104
174
 
105
175
  after(:all) do
@@ -138,5 +208,35 @@ describe ApplicationController do
138
208
  @user.activate!
139
209
  ActionMailer::Base.deliveries.size.should == old_size
140
210
  end
211
+
212
+ # provider: google
213
+ it "should not send activation email to external users (google)" do
214
+ old_size = ActionMailer::Base.deliveries.size
215
+ create_new_external_user(:google)
216
+ ActionMailer::Base.deliveries.size.should == old_size
217
+ end
218
+
219
+ it "should not send external users an activation success email (google)" do
220
+ sorcery_model_property_set(:activation_success_email_method_name, nil)
221
+ create_new_external_user(:google)
222
+ old_size = ActionMailer::Base.deliveries.size
223
+ @user.activate!
224
+ ActionMailer::Base.deliveries.size.should == old_size
225
+ end
226
+
227
+ # provider: liveid
228
+ it "should not send activation email to external users (liveid)" do
229
+ old_size = ActionMailer::Base.deliveries.size
230
+ create_new_external_user(:liveid)
231
+ ActionMailer::Base.deliveries.size.should == old_size
232
+ end
233
+
234
+ it "should not send external users an activation success email (liveid)" do
235
+ sorcery_model_property_set(:activation_success_email_method_name, nil)
236
+ create_new_external_user(:liveid)
237
+ old_size = ActionMailer::Base.deliveries.size
238
+ @user.activate!
239
+ ActionMailer::Base.deliveries.size.should == old_size
240
+ end
141
241
  end
142
242
  end
@@ -63,13 +63,41 @@ describe ApplicationController do
63
63
  assigns[:user].should == @user
64
64
  session[:user_id].should == @user.id
65
65
  end
66
-
66
+
67
67
  it "login(username,password) should return nil and not set the session when failure" do
68
68
  get :test_login, :username => 'gizmo', :password => 'opensesame!'
69
69
  assigns[:user].should be_nil
70
70
  session[:user_id].should be_nil
71
71
  end
72
+
73
+ it "login(username,password) should return nil and not set the session when upper case username" do
74
+ get :test_login, :username => 'GIZMO', :password => 'secret'
75
+ assigns[:user].should be_nil
76
+ session[:user_id].should be_nil
77
+ end
72
78
 
79
+ it "login(username,password) should return the user and set the session with user.id when upper case username and config is downcase before authenticating" do
80
+ sorcery_model_property_set(:downcase_username_before_authenticating, true)
81
+ get :test_login, :username => 'GIZMO', :password => 'secret'
82
+ assigns[:user].should == @user
83
+ session[:user_id].should == @user.id
84
+ end
85
+
86
+ it "login(username,password) should return nil and not set the session when user was created with upper case username, config is default, and log in username is lower case" do
87
+ create_new_user({:username => 'GIZMO1', :email => "bla1@bla.com", :password => 'secret1'})
88
+ get :test_login, :username => 'gizmo1', :password => 'secret1'
89
+ assigns[:user].should be_nil
90
+ session[:user_id].should be_nil
91
+ end
92
+
93
+ it "login(username,password) should return the user and set the session with user.id when user was created with upper case username and config is downcase before authenticating" do
94
+ sorcery_model_property_set(:downcase_username_before_authenticating, true)
95
+ create_new_user({:username => 'GIZMO1', :email => "bla1@bla.com", :password => 'secret1'})
96
+ get :test_login, :username => 'gizmo1', :password => 'secret1'
97
+ assigns[:user].should == @user
98
+ session[:user_id].should == @user.id
99
+ end
100
+
73
101
  it "logout should clear the session" do
74
102
  cookies[:remember_me_token] = nil
75
103
  session[:user_id] = @user.id
@@ -139,4 +167,4 @@ describe ApplicationController do
139
167
  end
140
168
  end
141
169
 
142
- end
170
+ end
@@ -1,21 +1,21 @@
1
- # require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
- #
3
- # describe "the login process", :type => :request do
4
- # before(:all) do
5
- # sorcery_reload!
6
- # create_new_user
7
- # end
8
- #
9
- # after(:all) do
10
- # end
11
- #
12
- # it "handles unverified request" do
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "the login process", :type => :request do
4
+ before(:all) do
5
+ sorcery_reload!
6
+ create_new_user
7
+ end
8
+
9
+ after(:all) do
10
+ end
11
+ end
12
+ # it "handles unverified request", :js => true do
13
13
  # visit root_path
14
- # # save_and_open_page
15
- # fill_in 'Username', :with => 'gizmo'
14
+ # #save_and_open_page
15
+ # fill_in 'Username', :with => 'gizmo1'
16
16
  # fill_in 'Password', :with => 'secret'
17
17
  # # <input name="authenticity_token" type="hidden" value="+8M9lXnjnhAW/mAuzwI9Mmy6hM+00qZJa8VMQUg+NmM=">
18
- # #page.execute_script("$$('hidden').value='mezuza'")
18
+ # page.execute_script("$$('hidden').value='mezuza'")
19
19
  # #save_and_open_page
20
20
  # click_button 'Login'
21
21
  # save_and_open_page
@@ -5,7 +5,7 @@ $: << File.join(File.dirname(__FILE__), '..', '..', 'lib' )
5
5
  ENV["RAILS_ENV"] ||= 'in_memory'
6
6
  require File.expand_path("../../config/environment", __FILE__)
7
7
  require 'rspec/rails'
8
- #require 'capybara/rspec'
8
+ require 'capybara/rspec'
9
9
  require 'timecop'
10
10
  # require 'simplecov'
11
11
  # SimpleCov.root File.join(File.dirname(__FILE__), "..", "..", "rails3" )
@@ -1,12 +1,12 @@
1
1
  PATH
2
2
  remote: ../../
3
3
  specs:
4
- sorcery (0.7.2)
4
+ sorcery (0.7.5)
5
5
  bcrypt-ruby (~> 3.0.0)
6
6
  oauth (~> 0.4.4)
7
7
  oauth (~> 0.4.4)
8
- oauth2 (~> 0.4.1)
9
- oauth2 (~> 0.4.1)
8
+ oauth2 (~> 0.5.1)
9
+ oauth2 (~> 0.5.1)
10
10
 
11
11
  GEM
12
12
  remote: http://rubygems.org/
@@ -42,17 +42,17 @@ GEM
42
42
  archive-tar-minitar (0.5.2)
43
43
  arel (2.0.10)
44
44
  bcrypt-ruby (3.0.1)
45
- bson (1.3.1)
46
- bson_ext (1.3.1)
45
+ bson (1.4.0)
46
+ bson_ext (1.4.0)
47
47
  builder (2.1.2)
48
48
  coderay (0.9.8)
49
- columnize (0.3.4)
49
+ columnize (0.3.5)
50
50
  diff-lcs (1.1.3)
51
51
  erubis (2.6.6)
52
52
  abstract (>= 1.0.0)
53
- faraday (0.6.1)
54
- addressable (~> 2.2.4)
55
- multipart-post (~> 1.1.0)
53
+ faraday (0.7.5)
54
+ addressable (~> 2.2.6)
55
+ multipart-post (~> 1.1.3)
56
56
  rack (>= 1.1.0, < 2)
57
57
  i18n (0.6.0)
58
58
  linecache19 (0.5.12)
@@ -65,22 +65,22 @@ GEM
65
65
  method_source (0.6.7)
66
66
  ruby_parser (>= 2.3.1)
67
67
  mime-types (1.17.2)
68
- mongo (1.3.1)
69
- bson (>= 1.3.1)
70
- mongo_mapper (0.9.2)
68
+ mongo (1.4.0)
69
+ bson (= 1.4.0)
70
+ mongo_mapper (0.10.1)
71
71
  activemodel (~> 3.0)
72
72
  activesupport (~> 3.0)
73
- plucky (~> 0.3.8)
73
+ plucky (~> 0.4.0)
74
74
  multi_json (1.0.3)
75
- multipart-post (1.1.3)
75
+ multipart-post (1.1.4)
76
76
  oauth (0.4.5)
77
- oauth2 (0.4.1)
78
- faraday (~> 0.6.1)
79
- multi_json (>= 0.0.5)
80
- plucky (0.3.8)
77
+ oauth2 (0.5.1)
78
+ faraday (~> 0.7.4)
79
+ multi_json (~> 1.0.3)
80
+ plucky (0.4.3)
81
81
  mongo (~> 1.3)
82
- polyglot (0.3.2)
83
- pry (0.9.7.3)
82
+ polyglot (0.3.3)
83
+ pry (0.9.7.4)
84
84
  coderay (~> 0.9.8)
85
85
  method_source (~> 0.6.7)
86
86
  ruby_parser (>= 2.3.1)
@@ -129,7 +129,7 @@ GEM
129
129
  archive-tar-minitar (>= 0.5.2)
130
130
  ruby_parser (2.3.1)
131
131
  sexp_processor (~> 3.0)
132
- sexp_processor (3.0.7)
132
+ sexp_processor (3.0.8)
133
133
  simplecov (0.5.4)
134
134
  multi_json (~> 1.0.3)
135
135
  simplecov-html (~> 0.5.3)
@@ -140,7 +140,7 @@ GEM
140
140
  treetop (1.4.10)
141
141
  polyglot
142
142
  polyglot (>= 0.3.1)
143
- tzinfo (0.3.30)
143
+ tzinfo (0.3.31)
144
144
 
145
145
  PLATFORMS
146
146
  ruby
@@ -30,11 +30,16 @@ describe ApplicationController do
30
30
  before(:all) do
31
31
  sorcery_reload!
32
32
  User.delete_all
33
+ end
34
+
35
+ before(:each) do
33
36
  create_new_user
34
37
  end
35
38
 
36
39
  after(:each) do
37
40
  Sorcery::Controller::Config.reset!
41
+ sorcery_reload!
42
+ User.delete_all
38
43
  sorcery_controller_property_set(:user_class, User)
39
44
  sorcery_model_property_set(:username_attribute_names, [:username, :email])
40
45
  end
@@ -64,6 +69,34 @@ describe ApplicationController do
64
69
  assigns[:user].should be_nil
65
70
  session[:user_id].should be_nil
66
71
  end
72
+
73
+ it "login(username,password) should return nil and not set the session when upper case username" do
74
+ get :test_login, :username => 'GIZMO', :password => 'secret'
75
+ assigns[:user].should be_nil
76
+ session[:user_id].should be_nil
77
+ end
78
+
79
+ it "login(username,password) should return the user and set the session with user.id when upper case username and config is downcase before authenticating" do
80
+ sorcery_model_property_set(:downcase_username_before_authenticating, true)
81
+ get :test_login, :username => 'GIZMO', :password => 'secret'
82
+ assigns[:user].should == @user
83
+ session[:user_id].should == @user.id
84
+ end
85
+
86
+ it "login(username,password) should return nil and not set the session when user was created with upper case username, config is default, and log in username is lower case" do
87
+ create_new_user({:username => 'GIZMO1', :email => "bla1@bla.com", :password => 'secret1'})
88
+ get :test_login, :username => 'gizmo1', :password => 'secret1'
89
+ assigns[:user].should be_nil
90
+ session[:user_id].should be_nil
91
+ end
92
+
93
+ it "login(username,password) should return the user and set the session with user.id when user was created with upper case username and config is downcase before authenticating" do
94
+ sorcery_model_property_set(:downcase_username_before_authenticating, true)
95
+ create_new_user({:username => 'GIZMO1', :email => "bla1@bla.com", :password => 'secret1'})
96
+ get :test_login, :username => 'gizmo1', :password => 'secret1'
97
+ assigns[:user].should == @user
98
+ session[:user_id].should == @user.id
99
+ end
67
100
 
68
101
  it "logout should clear the session" do
69
102
  cookies[:remember_me_token] = nil
@@ -127,4 +160,4 @@ describe ApplicationController do
127
160
  end
128
161
  end
129
162
 
130
- end
163
+ end
@@ -1,12 +1,12 @@
1
1
  PATH
2
2
  remote: ../../
3
3
  specs:
4
- sorcery (0.7.2)
4
+ sorcery (0.7.5)
5
5
  bcrypt-ruby (~> 3.0.0)
6
6
  oauth (~> 0.4.4)
7
7
  oauth (~> 0.4.4)
8
- oauth2 (~> 0.4.1)
9
- oauth2 (~> 0.4.1)
8
+ oauth2 (~> 0.5.1)
9
+ oauth2 (~> 0.5.1)
10
10
 
11
11
  GEM
12
12
  remote: http://rubygems.org/
@@ -42,16 +42,16 @@ GEM
42
42
  archive-tar-minitar (0.5.2)
43
43
  arel (2.0.10)
44
44
  bcrypt-ruby (3.0.1)
45
- bson (1.3.1)
46
- bson_ext (1.3.1)
45
+ bson (1.4.0)
46
+ bson_ext (1.4.0)
47
47
  builder (2.1.2)
48
- columnize (0.3.4)
48
+ columnize (0.3.5)
49
49
  diff-lcs (1.1.3)
50
50
  erubis (2.6.6)
51
51
  abstract (>= 1.0.0)
52
- faraday (0.6.1)
53
- addressable (~> 2.2.4)
54
- multipart-post (~> 1.1.0)
52
+ faraday (0.7.5)
53
+ addressable (~> 2.2.6)
54
+ multipart-post (~> 1.1.3)
55
55
  rack (>= 1.1.0, < 2)
56
56
  i18n (0.6.0)
57
57
  linecache19 (0.5.12)
@@ -62,19 +62,19 @@ GEM
62
62
  mime-types (~> 1.16)
63
63
  treetop (~> 1.4.8)
64
64
  mime-types (1.17.2)
65
- mongo (1.3.1)
66
- bson (>= 1.3.1)
67
- mongoid (2.2.3)
65
+ mongo (1.4.0)
66
+ bson (= 1.4.0)
67
+ mongoid (2.2.4)
68
68
  activemodel (~> 3.0)
69
69
  mongo (~> 1.3)
70
70
  tzinfo (~> 0.3.22)
71
71
  multi_json (1.0.3)
72
- multipart-post (1.1.3)
72
+ multipart-post (1.1.4)
73
73
  oauth (0.4.5)
74
- oauth2 (0.4.1)
75
- faraday (~> 0.6.1)
76
- multi_json (>= 0.0.5)
77
- polyglot (0.3.2)
74
+ oauth2 (0.5.1)
75
+ faraday (~> 0.7.4)
76
+ multi_json (~> 1.0.3)
77
+ polyglot (0.3.3)
78
78
  rack (1.2.4)
79
79
  rack-mount (0.6.14)
80
80
  rack (>= 1.0.0)
@@ -126,7 +126,7 @@ GEM
126
126
  treetop (1.4.10)
127
127
  polyglot
128
128
  polyglot (>= 0.3.1)
129
- tzinfo (0.3.30)
129
+ tzinfo (0.3.31)
130
130
 
131
131
  PLATFORMS
132
132
  ruby
@@ -16,6 +16,11 @@ class ApplicationController < ActionController::Base
16
16
  render :nothing => true
17
17
  end
18
18
 
19
+ def some_action_making_a_non_persisted_change_to_the_user
20
+ current_user.username = "to_be_ignored"
21
+ render :nothing => true
22
+ end
23
+
19
24
  def test_login
20
25
  @user = login(params[:username], params[:password])
21
26
  render :text => ""
@@ -23,7 +23,7 @@ describe ApplicationController do
23
23
  end
24
24
 
25
25
  it "should log login time on login" do
26
- now = Time.now.in_time_zone
26
+ now = Time.now
27
27
  login_user
28
28
  @user.last_login_at.should_not be_nil
29
29
  @user.last_login_at.to_s(:db).should >= now.to_s(:db)
@@ -32,7 +32,7 @@ describe ApplicationController do
32
32
 
33
33
  it "should log logout time on logout" do
34
34
  login_user
35
- now = Time.now.in_time_zone
35
+ now = Time.now
36
36
  logout_user
37
37
  User.first.last_logout_at.should_not be_nil
38
38
  User.first.last_logout_at.to_s(:db).should >= now.to_s(:db)
@@ -41,12 +41,19 @@ describe ApplicationController do
41
41
 
42
42
  it "should log last activity time when logged in" do
43
43
  login_user
44
- now = Time.now.in_time_zone
44
+ now = Time.now
45
45
  get :some_action
46
46
  User.first.last_activity_at.to_s(:db).should >= now.to_s(:db)
47
47
  User.first.last_activity_at.to_s(:db).should <= (now+2).to_s(:db)
48
48
  end
49
49
 
50
+ it "should update nothing but activity fields" do
51
+ original_user_name = User.first.username
52
+ login_user
53
+ get :some_action_making_a_non_persisted_change_to_the_user
54
+ User.first.username.should == original_user_name
55
+ end
56
+
50
57
  it "'current_users' should hold the user object when 1 user is logged in" do
51
58
  login_user
52
59
  get :some_action