sorcery 0.7.4 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) hide show
  1. data/.travis.yml +3 -0
  2. data/Gemfile +9 -4
  3. data/Gemfile.lock +103 -62
  4. data/README.rdoc +33 -8
  5. data/Rakefile +6 -7
  6. data/VERSION +1 -1
  7. data/lib/generators/sorcery/install_generator.rb +15 -10
  8. data/lib/generators/sorcery/templates/initializer.rb +343 -125
  9. data/lib/generators/sorcery/templates/migration/brute_force_protection.rb +2 -0
  10. data/lib/generators/sorcery/templates/migration/reset_password.rb +1 -1
  11. data/lib/sorcery/controller/submodules/activity_logging.rb +3 -3
  12. data/lib/sorcery/controller/submodules/brute_force_protection.rb +1 -2
  13. data/lib/sorcery/controller/submodules/external/protocols/oauth2.rb +19 -19
  14. data/lib/sorcery/controller/submodules/external/providers/facebook.rb +20 -5
  15. data/lib/sorcery/controller/submodules/external/providers/github.rb +15 -4
  16. data/lib/sorcery/controller/submodules/external/providers/google.rb +90 -0
  17. data/lib/sorcery/controller/submodules/external/providers/linkedin.rb +101 -0
  18. data/lib/sorcery/controller/submodules/external/providers/liveid.rb +91 -0
  19. data/lib/sorcery/controller/submodules/external/providers/twitter.rb +2 -1
  20. data/lib/sorcery/controller/submodules/external/providers/vkontakte.rb +94 -0
  21. data/lib/sorcery/controller/submodules/external.rb +89 -15
  22. data/lib/sorcery/controller/submodules/http_basic_auth.rb +1 -1
  23. data/lib/sorcery/controller/submodules/remember_me.rb +11 -2
  24. data/lib/sorcery/controller.rb +14 -6
  25. data/lib/sorcery/crypto_providers/bcrypt.rb +1 -0
  26. data/lib/sorcery/model/adapters/active_record.rb +21 -1
  27. data/lib/sorcery/model/adapters/mongo_mapper.rb +22 -15
  28. data/lib/sorcery/model/adapters/mongoid.rb +20 -3
  29. data/lib/sorcery/model/submodules/activity_logging.rb +4 -4
  30. data/lib/sorcery/model/submodules/brute_force_protection.rb +46 -15
  31. data/lib/sorcery/model/submodules/remember_me.rb +4 -6
  32. data/lib/sorcery/model/submodules/reset_password.rb +18 -12
  33. data/lib/sorcery/model/submodules/user_activation.rb +15 -8
  34. data/lib/sorcery/model.rb +57 -43
  35. data/lib/sorcery/railties/tasks.rake +2 -0
  36. data/lib/sorcery.rb +5 -1
  37. data/sorcery.gemspec +33 -21
  38. data/spec/Gemfile +1 -1
  39. data/spec/Gemfile.lock +22 -21
  40. data/spec/README.md +8 -8
  41. data/spec/rails3/Gemfile +3 -3
  42. data/spec/rails3/Gemfile.lock +55 -33
  43. data/spec/rails3/app/controllers/application_controller.rb +85 -2
  44. data/spec/rails3/app/mailers/sorcery_mailer.rb +7 -0
  45. data/spec/rails3/app/views/sorcery_mailer/send_unlock_token_email.text.erb +1 -0
  46. data/spec/rails3/config/environments/in_memory.rb +35 -0
  47. data/spec/rails3/db/migrate/brute_force_protection/20101224223626_add_brute_force_protection_to_users.rb +2 -0
  48. data/spec/rails3/spec/controller_activity_logging_spec.rb +10 -0
  49. data/spec/rails3/spec/controller_brute_force_protection_spec.rb +23 -1
  50. data/spec/rails3/spec/controller_oauth2_spec.rb +260 -22
  51. data/spec/rails3/spec/controller_oauth_spec.rb +111 -6
  52. data/spec/rails3/spec/controller_spec.rb +37 -2
  53. data/spec/rails3/spec/integration_spec.rb +15 -15
  54. data/spec/rails3/spec/spec_helper.rb +1 -1
  55. data/spec/rails3_mongo_mapper/Gemfile +2 -1
  56. data/spec/rails3_mongo_mapper/Gemfile.lock +40 -42
  57. data/spec/rails3_mongo_mapper/app/controllers/application_controller.rb +14 -0
  58. data/spec/rails3_mongo_mapper/spec/controller_spec.rb +41 -1
  59. data/spec/rails3_mongoid/Gemfile +1 -0
  60. data/spec/rails3_mongoid/Gemfile.lock +30 -27
  61. data/spec/rails3_mongoid/app/controllers/application_controller.rb +19 -0
  62. data/spec/rails3_mongoid/config/mongoid.yml +1 -1
  63. data/spec/rails3_mongoid/spec/controller_activity_logging_spec.rb +18 -11
  64. data/spec/rails3_mongoid/spec/controller_spec.rb +41 -1
  65. data/spec/shared_examples/controller_oauth2_shared_examples.rb +20 -1
  66. data/spec/shared_examples/controller_oauth_shared_examples.rb +18 -0
  67. data/spec/shared_examples/user_activation_shared_examples.rb +71 -41
  68. data/spec/shared_examples/user_reset_password_shared_examples.rb +80 -27
  69. data/spec/sorcery_crypto_providers_spec.rb +14 -1
  70. metadata +74 -46
@@ -1,12 +1,10 @@
1
1
  PATH
2
2
  remote: ../../
3
3
  specs:
4
- sorcery (0.7.2)
4
+ sorcery (0.7.13)
5
5
  bcrypt-ruby (~> 3.0.0)
6
6
  oauth (~> 0.4.4)
7
- oauth (~> 0.4.4)
8
- oauth2 (~> 0.4.1)
9
- oauth2 (~> 0.4.1)
7
+ oauth2 (~> 0.8.0)
10
8
 
11
9
  GEM
12
10
  remote: http://rubygems.org/
@@ -38,23 +36,24 @@ GEM
38
36
  activemodel (= 3.0.3)
39
37
  activesupport (= 3.0.3)
40
38
  activesupport (3.0.3)
41
- addressable (2.2.6)
42
39
  archive-tar-minitar (0.5.2)
43
40
  arel (2.0.10)
44
41
  bcrypt-ruby (3.0.1)
45
- bson (1.3.1)
46
- bson_ext (1.3.1)
42
+ bson (1.6.0)
43
+ bson_ext (1.6.0)
44
+ bson (= 1.6.0)
47
45
  builder (2.1.2)
48
- coderay (0.9.8)
49
- columnize (0.3.4)
46
+ coderay (1.0.5)
47
+ columnize (0.3.6)
50
48
  diff-lcs (1.1.3)
51
49
  erubis (2.6.6)
52
50
  abstract (>= 1.0.0)
53
- faraday (0.6.1)
54
- addressable (~> 2.2.4)
55
- multipart-post (~> 1.1.0)
56
- rack (>= 1.1.0, < 2)
51
+ faraday (0.8.4)
52
+ multipart-post (~> 1.1)
53
+ httpauth (0.2.0)
57
54
  i18n (0.6.0)
55
+ jwt (0.1.5)
56
+ multi_json (>= 1.0)
58
57
  linecache19 (0.5.12)
59
58
  ruby_core_source (>= 0.1.4)
60
59
  mail (2.2.19)
@@ -62,30 +61,31 @@ GEM
62
61
  i18n (>= 0.4.0)
63
62
  mime-types (~> 1.16)
64
63
  treetop (~> 1.4.8)
65
- method_source (0.6.7)
66
- ruby_parser (>= 2.3.1)
64
+ method_source (0.7.1)
67
65
  mime-types (1.17.2)
68
- mongo (1.3.1)
69
- bson (>= 1.3.1)
70
- mongo_mapper (0.9.2)
66
+ mongo (1.6.0)
67
+ bson (= 1.6.0)
68
+ mongo_mapper (0.11.0)
71
69
  activemodel (~> 3.0)
72
70
  activesupport (~> 3.0)
73
- plucky (~> 0.3.8)
74
- multi_json (1.0.3)
75
- multipart-post (1.1.3)
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)
81
- mongo (~> 1.3)
82
- polyglot (0.3.2)
83
- pry (0.9.7.3)
84
- coderay (~> 0.9.8)
85
- method_source (~> 0.6.7)
86
- ruby_parser (>= 2.3.1)
87
- slop (~> 2.1.0)
88
- rack (1.2.4)
71
+ plucky (~> 0.4.0)
72
+ multi_json (1.1.0)
73
+ multipart-post (1.1.5)
74
+ oauth (0.4.7)
75
+ oauth2 (0.8.0)
76
+ faraday (~> 0.8)
77
+ httpauth (~> 0.1)
78
+ jwt (~> 0.1.4)
79
+ multi_json (~> 1.0)
80
+ rack (~> 1.2)
81
+ plucky (0.4.4)
82
+ mongo (~> 1.5)
83
+ polyglot (0.3.3)
84
+ pry (0.9.8.3)
85
+ coderay (~> 1.0.5)
86
+ method_source (~> 0.7.1)
87
+ slop (>= 2.4.4, < 3)
88
+ rack (1.2.5)
89
89
  rack-mount (0.6.14)
90
90
  rack (>= 1.0.0)
91
91
  rack-test (0.5.7)
@@ -127,27 +127,25 @@ GEM
127
127
  ruby-debug-base19 (>= 0.11.19)
128
128
  ruby_core_source (0.1.5)
129
129
  archive-tar-minitar (>= 0.5.2)
130
- ruby_parser (2.3.1)
131
- sexp_processor (~> 3.0)
132
- sexp_processor (3.0.7)
133
- simplecov (0.5.4)
134
- multi_json (~> 1.0.3)
130
+ simplecov (0.6.1)
131
+ multi_json (~> 1.0)
135
132
  simplecov-html (~> 0.5.3)
136
133
  simplecov-html (0.5.3)
137
- slop (2.1.0)
134
+ slop (2.4.4)
138
135
  thor (0.14.6)
139
136
  timecop (0.3.5)
140
137
  treetop (1.4.10)
141
138
  polyglot
142
139
  polyglot (>= 0.3.1)
143
- tzinfo (0.3.30)
140
+ tzinfo (0.3.31)
144
141
 
145
142
  PLATFORMS
146
143
  ruby
147
144
 
148
145
  DEPENDENCIES
146
+ bcrypt-ruby (~> 3.0.0)
149
147
  bson_ext (~> 1.3)
150
- mongo_mapper
148
+ mongo_mapper (~> 0.11.0)
151
149
  pry
152
150
  rails (= 3.0.3)
153
151
  rspec (~> 2.5.0)
@@ -101,6 +101,20 @@ class ApplicationController < ActionController::Base
101
101
  end
102
102
  end
103
103
 
104
+ def test_create_from_provider_with_block
105
+ provider = params[:provider]
106
+ login_from(provider)
107
+ @user = create_from(provider) do |user|
108
+ # check uniqueness of username
109
+ User.where(:username => user.username).empty?
110
+ end
111
+ if @user
112
+ redirect_to "bla", :notice => "Success!"
113
+ else
114
+ redirect_to "blu", :alert => "Failed!"
115
+ end
116
+ end
117
+
104
118
  protected
105
119
 
106
120
 
@@ -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
@@ -108,6 +141,13 @@ describe ApplicationController do
108
141
  response.should redirect_to("http://test.host/")
109
142
  end
110
143
 
144
+ it "require_login before_filter should not save the url that the user originally wanted upon all non-get http methods" do
145
+ [:post, :put, :delete].each do |m|
146
+ self.send(m, :some_action)
147
+ session[:return_to_url].should be_nil
148
+ end
149
+ end
150
+
111
151
  it "on successful login the user should be redirected to the url he originally wanted" do
112
152
  session[:return_to_url] = "http://test.host/some_action"
113
153
  post :test_return_to, :username => 'gizmo', :password => 'secret'
@@ -127,4 +167,4 @@ describe ApplicationController do
127
167
  end
128
168
  end
129
169
 
130
- end
170
+ end
@@ -1,5 +1,6 @@
1
1
  source 'http://rubygems.org'
2
2
 
3
+ gem 'bcrypt-ruby', '~> 3.0.0'
3
4
  gem 'rails', '3.0.3'
4
5
  gem "sorcery", '>= 0.1.0', :path => '../../'
5
6
  gem "mongoid", "~> 2.0"
@@ -1,12 +1,10 @@
1
1
  PATH
2
2
  remote: ../../
3
3
  specs:
4
- sorcery (0.7.2)
4
+ sorcery (0.7.13)
5
5
  bcrypt-ruby (~> 3.0.0)
6
6
  oauth (~> 0.4.4)
7
- oauth (~> 0.4.4)
8
- oauth2 (~> 0.4.1)
9
- oauth2 (~> 0.4.1)
7
+ oauth2 (~> 0.8.0)
10
8
 
11
9
  GEM
12
10
  remote: http://rubygems.org/
@@ -38,22 +36,23 @@ GEM
38
36
  activemodel (= 3.0.3)
39
37
  activesupport (= 3.0.3)
40
38
  activesupport (3.0.3)
41
- addressable (2.2.6)
42
39
  archive-tar-minitar (0.5.2)
43
40
  arel (2.0.10)
44
41
  bcrypt-ruby (3.0.1)
45
- bson (1.3.1)
46
- bson_ext (1.3.1)
42
+ bson (1.6.0)
43
+ bson_ext (1.6.0)
44
+ bson (= 1.6.0)
47
45
  builder (2.1.2)
48
- columnize (0.3.4)
46
+ columnize (0.3.6)
49
47
  diff-lcs (1.1.3)
50
48
  erubis (2.6.6)
51
49
  abstract (>= 1.0.0)
52
- faraday (0.6.1)
53
- addressable (~> 2.2.4)
54
- multipart-post (~> 1.1.0)
55
- rack (>= 1.1.0, < 2)
50
+ faraday (0.8.4)
51
+ multipart-post (~> 1.1)
52
+ httpauth (0.2.0)
56
53
  i18n (0.6.0)
54
+ jwt (0.1.5)
55
+ multi_json (>= 1.0)
57
56
  linecache19 (0.5.12)
58
57
  ruby_core_source (>= 0.1.4)
59
58
  mail (2.2.19)
@@ -62,20 +61,23 @@ GEM
62
61
  mime-types (~> 1.16)
63
62
  treetop (~> 1.4.8)
64
63
  mime-types (1.17.2)
65
- mongo (1.3.1)
66
- bson (>= 1.3.1)
67
- mongoid (2.2.3)
68
- activemodel (~> 3.0)
64
+ mongo (1.6.0)
65
+ bson (= 1.6.0)
66
+ mongoid (2.2.6)
67
+ activemodel (~> 3.0.0)
69
68
  mongo (~> 1.3)
70
69
  tzinfo (~> 0.3.22)
71
- multi_json (1.0.3)
72
- multipart-post (1.1.3)
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)
78
- rack (1.2.4)
70
+ multi_json (1.1.0)
71
+ multipart-post (1.1.5)
72
+ oauth (0.4.7)
73
+ oauth2 (0.8.0)
74
+ faraday (~> 0.8)
75
+ httpauth (~> 0.1)
76
+ jwt (~> 0.1.4)
77
+ multi_json (~> 1.0)
78
+ rack (~> 1.2)
79
+ polyglot (0.3.3)
80
+ rack (1.2.5)
79
81
  rack-mount (0.6.14)
80
82
  rack (>= 1.0.0)
81
83
  rack-test (0.5.7)
@@ -117,8 +119,8 @@ GEM
117
119
  ruby-debug-base19 (>= 0.11.19)
118
120
  ruby_core_source (0.1.5)
119
121
  archive-tar-minitar (>= 0.5.2)
120
- simplecov (0.5.4)
121
- multi_json (~> 1.0.3)
122
+ simplecov (0.6.1)
123
+ multi_json (~> 1.0)
122
124
  simplecov-html (~> 0.5.3)
123
125
  simplecov-html (0.5.3)
124
126
  thor (0.14.6)
@@ -126,12 +128,13 @@ GEM
126
128
  treetop (1.4.10)
127
129
  polyglot
128
130
  polyglot (>= 0.3.1)
129
- tzinfo (0.3.30)
131
+ tzinfo (0.3.31)
130
132
 
131
133
  PLATFORMS
132
134
  ruby
133
135
 
134
136
  DEPENDENCIES
137
+ bcrypt-ruby (~> 3.0.0)
135
138
  bson_ext (~> 1.3)
136
139
  mongoid (~> 2.0)
137
140
  rails (= 3.0.3)
@@ -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 => ""
@@ -101,6 +106,20 @@ class ApplicationController < ActionController::Base
101
106
  end
102
107
  end
103
108
 
109
+ def test_create_from_provider_with_block
110
+ provider = params[:provider]
111
+ login_from(provider)
112
+ @user = create_from(provider) do |user|
113
+ # check uniqueness of username
114
+ User.where(:username => user.username).empty?
115
+ end
116
+ if @user
117
+ redirect_to "bla", :notice => "Success!"
118
+ else
119
+ redirect_to "blu", :alert => "Failed!"
120
+ end
121
+ end
122
+
104
123
  protected
105
124
 
106
125
 
@@ -4,4 +4,4 @@ development:
4
4
 
5
5
  test:
6
6
  host: localhost
7
- database: app_root_test
7
+ database: app_root_test
@@ -23,28 +23,35 @@ 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.utc
27
27
  login_user
28
28
  @user.last_login_at.should_not be_nil
29
- @user.last_login_at.to_s(:db).should >= now.to_s(:db)
30
- @user.last_login_at.to_s(:db).should <= (now+2).to_s(:db)
29
+ @user.last_login_at.utc.to_s.should >= now.utc.to_s
30
+ @user.last_login_at.utc.to_s.should <= (now.utc+2).to_s
31
31
  end
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.utc
36
36
  logout_user
37
- User.first.last_logout_at.should_not be_nil
38
- User.first.last_logout_at.to_s(:db).should >= now.to_s(:db)
39
- User.first.last_logout_at.to_s(:db).should <= (now+2).to_s(:db)
37
+ User.first.last_logout_at.utc.should_not be_nil
38
+ User.first.last_logout_at.utc.to_s.should >= now.utc.to_s
39
+ User.first.last_logout_at.utc.to_s.should <= (now.utc+2).to_s
40
40
  end
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.utc
45
45
  get :some_action
46
- User.first.last_activity_at.to_s(:db).should >= now.to_s(:db)
47
- User.first.last_activity_at.to_s(:db).should <= (now+2).to_s(:db)
46
+ User.first.last_activity_at.utc.should >= now.utc
47
+ User.first.last_activity_at.utc.should <= (now.utc+2)
48
+ end
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
48
55
  end
49
56
 
50
57
  it "'current_users' should hold the user object when 1 user is logged in" do
@@ -95,4 +102,4 @@ describe ApplicationController do
95
102
  @user.last_activity_at.should be_nil
96
103
  end
97
104
  end
98
- end
105
+ end
@@ -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,7 +69,35 @@ 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
67
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
+
68
101
  it "logout should clear the session" do
69
102
  cookies[:remember_me_token] = nil
70
103
  session[:user_id] = @user.id
@@ -119,6 +152,13 @@ describe ApplicationController do
119
152
  response.should redirect_to("http://test.host/")
120
153
  end
121
154
 
155
+ it "require_login before_filter should not save the url that the user originally wanted upon all non-get http methods" do
156
+ [:post, :put, :delete].each do |m|
157
+ self.send(m, :some_action)
158
+ session[:return_to_url].should be_nil
159
+ end
160
+ end
161
+
122
162
  it "on successful login the user should be redirected to the url he originally wanted" do
123
163
  session[:return_to_url] = "http://test.host/some_action"
124
164
  post :test_return_to, :username => 'gizmo', :password => 'secret'
@@ -138,4 +178,4 @@ describe ApplicationController do
138
178
  end
139
179
  end
140
180
 
141
- end
181
+ end
@@ -32,6 +32,25 @@ shared_examples_for "oauth2_controller" do
32
32
  end.should change(User, :count).by(1)
33
33
  User.first.username.should == "Noam Ben Ari"
34
34
  User.first.created_at.should_not be_nil
35
- end
35
+ end
36
+
37
+ describe "with a block" do
38
+
39
+ before(:each) do
40
+ user = User.new(:username => 'Noam Ben Ari')
41
+ user.save!(:validate => false)
42
+ user.authentications.create(:provider => 'twitter', :uid => '456')
43
+ end
44
+
45
+ it "should not create user" do
46
+ sorcery_model_property_set(:authentications_class, Authentication)
47
+ sorcery_controller_external_property_set(:facebook, :user_info_mapping, {:username => "name"})
48
+ lambda do
49
+ # test_create_from_provider_with_block in controller will check for uniqueness of username
50
+ get :test_create_from_provider_with_block, :provider => "facebook"
51
+ end.should_not change(User, :count)
52
+ end
53
+
54
+ end
36
55
  end
37
56
  end
@@ -33,5 +33,23 @@ shared_examples_for "oauth_controller" do
33
33
  User.first.username.should == "coming soon to sorcery gem: twitter and facebook authentication support."
34
34
  User.first.created_at.should_not be_nil
35
35
  end
36
+
37
+ describe "with a block" do
38
+
39
+ before(:each) do
40
+ user = User.new(:username => 'nbenari')
41
+ user.save!(:validate => false)
42
+ user.authentications.create(:provider => 'github', :uid => '456')
43
+ end
44
+
45
+ it "should not create user" do
46
+ sorcery_model_property_set(:authentications_class, Authentication)
47
+ sorcery_controller_external_property_set(:twitter, :user_info_mapping, {:username => "screen_name"})
48
+ lambda do
49
+ get :test_create_from_provider_with_block, :provider => "twitter"
50
+ end.should_not change(User, :count)
51
+ end
52
+
53
+ end
36
54
  end
37
55
  end