sorcery 0.8.5 → 0.9.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 (163) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +3 -1
  3. data/.travis.yml +122 -5
  4. data/CHANGELOG.md +37 -1
  5. data/Gemfile +10 -18
  6. data/README.md +159 -88
  7. data/gemfiles/active_record-rails40.gemfile +7 -0
  8. data/gemfiles/active_record-rails41.gemfile +7 -0
  9. data/gemfiles/mongo_mapper-rails40.gemfile +9 -0
  10. data/gemfiles/mongo_mapper-rails41.gemfile +9 -0
  11. data/gemfiles/mongoid-rails40.gemfile +9 -0
  12. data/gemfiles/mongoid-rails41.gemfile +9 -0
  13. data/gemfiles/mongoid3-rails32.gemfile +9 -0
  14. data/lib/generators/sorcery/USAGE +1 -1
  15. data/lib/generators/sorcery/install_generator.rb +19 -5
  16. data/lib/generators/sorcery/templates/initializer.rb +34 -9
  17. data/lib/generators/sorcery/templates/migration/brute_force_protection.rb +3 -1
  18. data/lib/generators/sorcery/templates/migration/core.rb +2 -2
  19. data/lib/generators/sorcery/templates/migration/external.rb +3 -1
  20. data/lib/sorcery/adapters/active_record_adapter.rb +120 -0
  21. data/lib/sorcery/adapters/base_adapter.rb +30 -0
  22. data/lib/sorcery/adapters/data_mapper_adapter.rb +176 -0
  23. data/lib/sorcery/adapters/mongo_mapper_adapter.rb +110 -0
  24. data/lib/sorcery/adapters/mongoid_adapter.rb +97 -0
  25. data/lib/sorcery/controller/config.rb +65 -0
  26. data/lib/sorcery/controller/submodules/activity_logging.rb +16 -21
  27. data/lib/sorcery/controller/submodules/brute_force_protection.rb +6 -6
  28. data/lib/sorcery/controller/submodules/external.rb +35 -40
  29. data/lib/sorcery/controller/submodules/remember_me.rb +4 -4
  30. data/lib/sorcery/controller/submodules/session_timeout.rb +10 -6
  31. data/lib/sorcery/controller.rb +10 -74
  32. data/lib/sorcery/model/config.rb +96 -0
  33. data/lib/sorcery/model/submodules/activity_logging.rb +30 -13
  34. data/lib/sorcery/model/submodules/brute_force_protection.rb +21 -21
  35. data/lib/sorcery/model/submodules/external.rb +53 -9
  36. data/lib/sorcery/model/submodules/remember_me.rb +15 -19
  37. data/lib/sorcery/model/submodules/reset_password.rb +33 -34
  38. data/lib/sorcery/model/submodules/user_activation.rb +36 -47
  39. data/lib/sorcery/model/temporary_token.rb +4 -4
  40. data/lib/sorcery/model.rb +73 -173
  41. data/lib/sorcery/protocols/oauth.rb +42 -0
  42. data/lib/sorcery/protocols/oauth2.rb +47 -0
  43. data/lib/sorcery/providers/base.rb +38 -0
  44. data/lib/sorcery/providers/facebook.rb +63 -0
  45. data/lib/sorcery/providers/github.rb +51 -0
  46. data/lib/sorcery/providers/google.rb +51 -0
  47. data/lib/sorcery/providers/heroku.rb +57 -0
  48. data/lib/sorcery/providers/jira.rb +77 -0
  49. data/lib/sorcery/providers/linkedin.rb +66 -0
  50. data/lib/sorcery/providers/liveid.rb +53 -0
  51. data/lib/sorcery/providers/salesforce.rb +50 -0
  52. data/lib/sorcery/providers/twitter.rb +59 -0
  53. data/lib/sorcery/providers/vk.rb +63 -0
  54. data/lib/sorcery/providers/xing.rb +64 -0
  55. data/lib/sorcery/test_helpers/internal/rails.rb +14 -3
  56. data/lib/sorcery/test_helpers/internal.rb +7 -3
  57. data/lib/sorcery/test_helpers/rails/controller.rb +21 -0
  58. data/lib/sorcery/test_helpers/rails/integration.rb +26 -0
  59. data/lib/sorcery/version.rb +3 -0
  60. data/lib/sorcery.rb +82 -58
  61. data/sorcery.gemspec +19 -19
  62. data/spec/active_record/user_activation_spec.rb +1 -1
  63. data/spec/active_record/user_activity_logging_spec.rb +10 -1
  64. data/spec/active_record/user_brute_force_protection_spec.rb +1 -1
  65. data/spec/active_record/user_oauth_spec.rb +1 -1
  66. data/spec/active_record/user_remember_me_spec.rb +1 -1
  67. data/spec/active_record/user_reset_password_spec.rb +1 -1
  68. data/spec/active_record/user_spec.rb +7 -8
  69. data/spec/controllers/controller_activity_logging_spec.rb +124 -0
  70. data/spec/controllers/controller_brute_force_protection_spec.rb +43 -0
  71. data/spec/controllers/controller_http_basic_auth_spec.rb +68 -0
  72. data/spec/controllers/controller_oauth2_spec.rb +414 -0
  73. data/spec/controllers/controller_oauth_spec.rb +240 -0
  74. data/spec/controllers/controller_remember_me_spec.rb +117 -0
  75. data/spec/controllers/controller_session_timeout_spec.rb +80 -0
  76. data/spec/controllers/controller_spec.rb +218 -0
  77. data/spec/data_mapper/user_activation_spec.rb +10 -0
  78. data/spec/data_mapper/user_activity_logging_spec.rb +14 -0
  79. data/spec/data_mapper/user_brute_force_protection_spec.rb +9 -0
  80. data/spec/data_mapper/user_oauth_spec.rb +9 -0
  81. data/spec/data_mapper/user_remember_me_spec.rb +8 -0
  82. data/spec/data_mapper/user_reset_password_spec.rb +8 -0
  83. data/spec/data_mapper/user_spec.rb +27 -0
  84. data/spec/mongo_mapper/user_activation_spec.rb +1 -2
  85. data/spec/mongo_mapper/user_activity_logging_spec.rb +1 -1
  86. data/spec/mongo_mapper/user_brute_force_protection_spec.rb +1 -1
  87. data/spec/mongo_mapper/user_oauth_spec.rb +1 -1
  88. data/spec/mongo_mapper/user_remember_me_spec.rb +1 -1
  89. data/spec/mongo_mapper/user_reset_password_spec.rb +1 -1
  90. data/spec/mongo_mapper/user_spec.rb +7 -8
  91. data/spec/mongoid/user_activation_spec.rb +1 -2
  92. data/spec/mongoid/user_activity_logging_spec.rb +1 -2
  93. data/spec/mongoid/user_brute_force_protection_spec.rb +1 -2
  94. data/spec/mongoid/user_oauth_spec.rb +1 -2
  95. data/spec/mongoid/user_remember_me_spec.rb +1 -2
  96. data/spec/mongoid/user_reset_password_spec.rb +1 -2
  97. data/spec/mongoid/user_spec.rb +21 -9
  98. data/spec/orm/active_record.rb +14 -0
  99. data/spec/orm/data_mapper.rb +48 -0
  100. data/spec/orm/mongo_mapper.rb +1 -1
  101. data/spec/orm/mongoid.rb +5 -0
  102. data/spec/rails_app/app/controllers/sorcery_controller.rb +125 -59
  103. data/spec/rails_app/app/data_mapper/authentication.rb +8 -0
  104. data/spec/rails_app/app/data_mapper/user.rb +7 -0
  105. data/spec/rails_app/app/mongo_mapper/user.rb +2 -0
  106. data/spec/rails_app/config/routes.rb +27 -13
  107. data/spec/rails_app/db/migrate/core/20101224223620_create_users.rb +2 -2
  108. data/spec/shared_examples/user_activation_shared_examples.rb +108 -91
  109. data/spec/shared_examples/user_activity_logging_shared_examples.rb +83 -15
  110. data/spec/shared_examples/user_brute_force_protection_shared_examples.rb +140 -21
  111. data/spec/shared_examples/user_oauth_shared_examples.rb +21 -16
  112. data/spec/shared_examples/user_remember_me_shared_examples.rb +36 -24
  113. data/spec/shared_examples/user_reset_password_shared_examples.rb +138 -117
  114. data/spec/shared_examples/user_shared_examples.rb +297 -150
  115. data/spec/sorcery_crypto_providers_spec.rb +28 -28
  116. data/spec/spec_helper.rb +12 -18
  117. metadata +99 -165
  118. data/Gemfile.rails4 +0 -24
  119. data/VERSION +0 -1
  120. data/lib/sorcery/controller/submodules/external/protocols/oauth1.rb +0 -46
  121. data/lib/sorcery/controller/submodules/external/protocols/oauth2.rb +0 -50
  122. data/lib/sorcery/controller/submodules/external/providers/base.rb +0 -21
  123. data/lib/sorcery/controller/submodules/external/providers/facebook.rb +0 -99
  124. data/lib/sorcery/controller/submodules/external/providers/github.rb +0 -93
  125. data/lib/sorcery/controller/submodules/external/providers/google.rb +0 -92
  126. data/lib/sorcery/controller/submodules/external/providers/linkedin.rb +0 -103
  127. data/lib/sorcery/controller/submodules/external/providers/liveid.rb +0 -93
  128. data/lib/sorcery/controller/submodules/external/providers/twitter.rb +0 -94
  129. data/lib/sorcery/controller/submodules/external/providers/vk.rb +0 -101
  130. data/lib/sorcery/controller/submodules/external/providers/xing.rb +0 -98
  131. data/lib/sorcery/model/adapters/active_record.rb +0 -49
  132. data/lib/sorcery/model/adapters/mongo_mapper.rb +0 -56
  133. data/lib/sorcery/model/adapters/mongoid.rb +0 -88
  134. data/lib/sorcery/test_helpers/rails.rb +0 -16
  135. data/lib/sorcery/test_helpers.rb +0 -5
  136. data/spec/active_record/controller_activity_logging_spec.rb +0 -140
  137. data/spec/active_record/controller_brute_force_protection_spec.rb +0 -136
  138. data/spec/active_record/controller_http_basic_auth_spec.rb +0 -59
  139. data/spec/active_record/controller_oauth2_spec.rb +0 -417
  140. data/spec/active_record/controller_oauth_spec.rb +0 -212
  141. data/spec/active_record/controller_remember_me_spec.rb +0 -96
  142. data/spec/active_record/controller_session_timeout_spec.rb +0 -55
  143. data/spec/active_record/controller_spec.rb +0 -182
  144. data/spec/active_record/integration_spec.rb +0 -23
  145. data/spec/mongo_mapper/controller_spec.rb +0 -175
  146. data/spec/mongoid/controller_activity_logging_spec.rb +0 -111
  147. data/spec/mongoid/controller_spec.rb +0 -186
  148. data/spec/rails_app/public/404.html +0 -26
  149. data/spec/rails_app/public/422.html +0 -26
  150. data/spec/rails_app/public/500.html +0 -26
  151. data/spec/rails_app/public/favicon.ico +0 -0
  152. data/spec/rails_app/public/images/rails.png +0 -0
  153. data/spec/rails_app/public/javascripts/application.js +0 -2
  154. data/spec/rails_app/public/javascripts/controls.js +0 -965
  155. data/spec/rails_app/public/javascripts/dragdrop.js +0 -974
  156. data/spec/rails_app/public/javascripts/effects.js +0 -1123
  157. data/spec/rails_app/public/javascripts/prototype.js +0 -6001
  158. data/spec/rails_app/public/javascripts/rails.js +0 -175
  159. data/spec/rails_app/public/robots.txt +0 -5
  160. data/spec/rails_app/public/stylesheets/.gitkeep +0 -0
  161. data/spec/shared_examples/controller_oauth2_shared_examples.rb +0 -56
  162. data/spec/shared_examples/controller_oauth_shared_examples.rb +0 -69
  163. /data/lib/sorcery/{controller/submodules/external/protocols → protocols}/certs/ca-bundle.crt +0 -0
@@ -1,186 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe SorceryController do
4
-
5
- # ----------------- PLUGIN CONFIGURATION -----------------------
6
- describe SorceryController, "plugin configuration" do
7
- before(:all) do
8
- sorcery_reload!
9
- end
10
-
11
- after(:each) do
12
- Sorcery::Controller::Config.reset!
13
- sorcery_reload!
14
- end
15
-
16
- it "should enable configuration option 'user_class'" do
17
- sorcery_controller_property_set(:user_class, "TestUser")
18
- Sorcery::Controller::Config.user_class.should == "TestUser"
19
- end
20
-
21
- it "should enable configuration option 'not_authenticated_action'" do
22
- sorcery_controller_property_set(:not_authenticated_action, :my_action)
23
- Sorcery::Controller::Config.not_authenticated_action.should equal(:my_action)
24
- end
25
-
26
- end
27
-
28
- # ----------------- PLUGIN ACTIVATED -----------------------
29
- describe SorceryController, "when activated with sorcery" do
30
- before(:all) do
31
- sorcery_reload!
32
- User.delete_all
33
- end
34
-
35
- before(:each) do
36
- create_new_user
37
- end
38
-
39
- after(:each) do
40
- Sorcery::Controller::Config.reset!
41
- sorcery_reload!
42
- User.delete_all
43
- sorcery_controller_property_set(:user_class, User)
44
- sorcery_model_property_set(:username_attribute_names, [:username, :email])
45
- end
46
-
47
- specify { should respond_to(:login) }
48
-
49
- specify { should respond_to(:logout) }
50
-
51
- specify { should respond_to(:logged_in?) }
52
-
53
- specify { should respond_to(:current_user) }
54
-
55
- it "login(username,password) should return the user when success and set the session with user.id" do
56
- get :test_login, :email => 'bla@bla.com', :password => 'secret'
57
- assigns[:user].should == @user
58
- session[:user_id].should == @user.id
59
- end
60
-
61
- it "login(email,password) should return the user when success and set the session with user.id" do
62
- get :test_login, :email => 'bla@bla.com', :password => 'secret'
63
- assigns[:user].should == @user
64
- session[:user_id].should == @user.id
65
- end
66
-
67
- it "login(username,password) should return nil and not set the session when failure" do
68
- get :test_login, :email => 'bla@bla.com', :password => 'opensesame!'
69
- assigns[:user].should be_nil
70
- session[:user_id].should be_nil
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, :email => 'BLA@BLA.com', :password => 'secret'
75
- assigns[:user].should be_nil
76
- session[:user_id].should be_nil
77
- end
78
-
79
- it "login(email,password) should return the user when success and set the session with the _csrf_token" do
80
- get :test_login, :email => 'bla@bla.com', :password => 'secret'
81
- session[:_csrf_token].should_not be_nil
82
- end
83
-
84
- 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
85
- sorcery_model_property_set(:downcase_username_before_authenticating, true)
86
- get :test_login, :email => 'bla@bla.com', :password => 'secret'
87
- assigns[:user].should == @user
88
- session[:user_id].should == @user.id
89
- end
90
-
91
- 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
92
- create_new_user({:username => 'GIZMO1', :email => "BLA1@BLA.com", :password => 'secret1'})
93
- get :test_login, :email => 'bla1@bla.com', :password => 'secret1'
94
- assigns[:user].should be_nil
95
- session[:user_id].should be_nil
96
- end
97
-
98
- 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
99
- sorcery_model_property_set(:downcase_username_before_authenticating, true)
100
- create_new_user({:username => 'GIZMO1', :email => "bla1@bla.com", :password => 'secret1'})
101
- get :test_login, :email => 'bla1@bla.com', :password => 'secret1'
102
- assigns[:user].should == @user
103
- session[:user_id].should == @user.id
104
- end
105
-
106
- it "logout should clear the session" do
107
- cookies[:remember_me_token] = nil
108
- session[:user_id] = @user.id
109
- get :test_logout
110
- session[:user_id].should be_nil
111
- end
112
-
113
- it "logged_in? should return true if logged in" do
114
- session[:user_id] = @user.id
115
- subject.logged_in?.should be_true
116
- end
117
-
118
- it "logged_in? should return false if not logged in" do
119
- session[:user_id] = nil
120
- subject.logged_in?.should be_false
121
- end
122
-
123
- it "current_user should return the user instance if logged in" do
124
- create_new_user
125
- session[:user_id] = @user.id
126
- subject.current_user.should == @user
127
- end
128
-
129
- it "current_user should return false if not logged in" do
130
- session[:user_id] = nil
131
- subject.current_user.should == false
132
- end
133
-
134
- specify { should respond_to(:require_login) }
135
-
136
- it "should call the configured 'not_authenticated_action' when session[:user_id] isn't found" do
137
- # If someone passes in a bogus user_id than no big deal, but if a user is deleted
138
- # and there is still an active session out there for him this causes problems.
139
- user = User.create(:email => 'test@example.com', :password => 'password')
140
- session[:user_id] = user.id
141
- user.destroy
142
- sorcery_controller_property_set(:not_authenticated_action, :test_not_authenticated_action)
143
- get :test_logout
144
- response.body.should == "test_not_authenticated_action"
145
- end
146
-
147
- it "should call the configured 'not_authenticated_action' when authenticate before_filter fails" do
148
- session[:user_id] = nil
149
- sorcery_controller_property_set(:not_authenticated_action, :test_not_authenticated_action)
150
- get :test_logout
151
- response.body.should == "test_not_authenticated_action"
152
- end
153
-
154
- it "require_login before_filter should save the url that the user originally wanted" do
155
- get :some_action
156
- session[:return_to_url].should == "http://test.host/some_action"
157
- response.should redirect_to("http://test.host/")
158
- end
159
-
160
- it "require_login before_filter should not save the url that the user originally wanted upon all non-get http methods" do
161
- [:post, :put, :delete].each do |m|
162
- self.send(m, :some_action)
163
- session[:return_to_url].should be_nil
164
- end
165
- end
166
-
167
- it "on successful login the user should be redirected to the url he originally wanted" do
168
- session[:return_to_url] = "http://test.host/some_action"
169
- post :test_return_to, :username => 'gizmo', :password => 'secret'
170
- response.should redirect_to("http://test.host/some_action")
171
- flash[:notice].should == "haha!"
172
- end
173
-
174
-
175
- # --- login_user(user) ---
176
- specify { should respond_to(:auto_login) }
177
-
178
- it "auto_login(user) should login a user instance" do
179
- create_new_user
180
- session[:user_id] = nil
181
- subject.auto_login(@user)
182
- subject.logged_in?.should be_true
183
- end
184
- end
185
-
186
- end
@@ -1,26 +0,0 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <title>The page you were looking for doesn't exist (404)</title>
5
- <style type="text/css">
6
- body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
7
- div.dialog {
8
- width: 25em;
9
- padding: 0 4em;
10
- margin: 4em auto 0 auto;
11
- border: 1px solid #ccc;
12
- border-right-color: #999;
13
- border-bottom-color: #999;
14
- }
15
- h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
16
- </style>
17
- </head>
18
-
19
- <body>
20
- <!-- This file lives in public/404.html -->
21
- <div class="dialog">
22
- <h1>The page you were looking for doesn't exist.</h1>
23
- <p>You may have mistyped the address or the page may have moved.</p>
24
- </div>
25
- </body>
26
- </html>
@@ -1,26 +0,0 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <title>The change you wanted was rejected (422)</title>
5
- <style type="text/css">
6
- body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
7
- div.dialog {
8
- width: 25em;
9
- padding: 0 4em;
10
- margin: 4em auto 0 auto;
11
- border: 1px solid #ccc;
12
- border-right-color: #999;
13
- border-bottom-color: #999;
14
- }
15
- h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
16
- </style>
17
- </head>
18
-
19
- <body>
20
- <!-- This file lives in public/422.html -->
21
- <div class="dialog">
22
- <h1>The change you wanted was rejected.</h1>
23
- <p>Maybe you tried to change something you didn't have access to.</p>
24
- </div>
25
- </body>
26
- </html>
@@ -1,26 +0,0 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <title>We're sorry, but something went wrong (500)</title>
5
- <style type="text/css">
6
- body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
7
- div.dialog {
8
- width: 25em;
9
- padding: 0 4em;
10
- margin: 4em auto 0 auto;
11
- border: 1px solid #ccc;
12
- border-right-color: #999;
13
- border-bottom-color: #999;
14
- }
15
- h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
16
- </style>
17
- </head>
18
-
19
- <body>
20
- <!-- This file lives in public/500.html -->
21
- <div class="dialog">
22
- <h1>We're sorry, but something went wrong.</h1>
23
- <p>We've been notified about this issue and we'll take a look at it shortly.</p>
24
- </div>
25
- </body>
26
- </html>
File without changes
Binary file
@@ -1,2 +0,0 @@
1
- // Place your application-specific JavaScript functions and classes here
2
- // This file is automatically included by javascript_include_tag :defaults