sorcery 0.2.1 → 0.4.2

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. data/Gemfile +3 -2
  2. data/Gemfile.lock +13 -11
  3. data/README.rdoc +157 -61
  4. data/Rakefile +4 -4
  5. data/VERSION +1 -1
  6. data/lib/generators/sorcery_migration/sorcery_migration_generator.rb +24 -0
  7. data/lib/generators/sorcery_migration/templates/activity_logging.rb +17 -0
  8. data/lib/generators/sorcery_migration/templates/brute_force_protection.rb +11 -0
  9. data/lib/generators/sorcery_migration/templates/core.rb +16 -0
  10. data/lib/generators/sorcery_migration/templates/external.rb +14 -0
  11. data/lib/generators/sorcery_migration/templates/remember_me.rb +15 -0
  12. data/lib/generators/sorcery_migration/templates/reset_password.rb +13 -0
  13. data/lib/generators/sorcery_migration/templates/user_activation.rb +17 -0
  14. data/lib/sorcery/controller/adapters/sinatra.rb +97 -0
  15. data/lib/sorcery/controller/submodules/external/protocols/oauth1.rb +35 -0
  16. data/lib/sorcery/controller/submodules/external/protocols/oauth2.rb +26 -0
  17. data/lib/sorcery/controller/submodules/{oauth → external}/providers/facebook.rb +24 -6
  18. data/lib/sorcery/controller/submodules/{oauth → external}/providers/twitter.rb +31 -6
  19. data/lib/sorcery/controller/submodules/{oauth.rb → external.rb} +18 -27
  20. data/lib/sorcery/controller/submodules/http_basic_auth.rb +11 -7
  21. data/lib/sorcery/controller.rb +21 -21
  22. data/lib/sorcery/crypto_providers/bcrypt.rb +3 -5
  23. data/lib/sorcery/crypto_providers/common.rb +35 -0
  24. data/lib/sorcery/crypto_providers/md5.rb +3 -23
  25. data/lib/sorcery/crypto_providers/sha1.rb +4 -16
  26. data/lib/sorcery/crypto_providers/sha256.rb +3 -23
  27. data/lib/sorcery/crypto_providers/sha512.rb +3 -23
  28. data/lib/sorcery/engine.rb +4 -0
  29. data/lib/sorcery/initializers/initializer.rb +86 -0
  30. data/lib/sorcery/model/submodules/activity_logging.rb +2 -2
  31. data/lib/sorcery/model/submodules/brute_force_protection.rb +1 -5
  32. data/lib/sorcery/model/submodules/{oauth.rb → external.rb} +3 -3
  33. data/lib/sorcery/model/submodules/reset_password.rb +1 -1
  34. data/lib/sorcery/model.rb +34 -9
  35. data/lib/sorcery/railties/tasks.rake +10 -0
  36. data/lib/sorcery/sinatra.rb +5 -0
  37. data/lib/sorcery/test_helpers/internal/rails.rb +52 -0
  38. data/lib/sorcery/test_helpers/internal/sinatra.rb +122 -0
  39. data/lib/sorcery/test_helpers/internal.rb +55 -0
  40. data/lib/sorcery/test_helpers/rails.rb +16 -0
  41. data/lib/sorcery/test_helpers/sinatra.rb +85 -0
  42. data/lib/sorcery/test_helpers.rb +0 -79
  43. data/lib/sorcery.rb +25 -7
  44. data/sorcery.gemspec +207 -137
  45. data/spec/Gemfile +2 -2
  46. data/spec/Gemfile.lock +20 -12
  47. data/spec/Rakefile +1 -0
  48. data/spec/rails3/.rspec +1 -1
  49. data/spec/rails3/{app_root/Gemfile → Gemfile} +5 -7
  50. data/spec/rails3/{app_root/Gemfile.lock → Gemfile.lock} +20 -23
  51. data/spec/rails3/{app_root/Rakefile → Rakefile} +1 -0
  52. data/spec/rails3/{app_root/app → app}/controllers/application_controller.rb +11 -11
  53. data/spec/rails3/config/database.yml +27 -0
  54. data/spec/rails3/{app_root/spec → spec}/controller_activity_logging_spec.rb +2 -4
  55. data/spec/rails3/{app_root/spec → spec}/controller_brute_force_protection_spec.rb +3 -2
  56. data/spec/rails3/{app_root/spec → spec}/controller_oauth2_spec.rb +25 -22
  57. data/spec/rails3/{app_root/spec → spec}/controller_oauth_spec.rb +24 -19
  58. data/spec/rails3/spec/controller_session_timeout_spec.rb +55 -0
  59. data/spec/rails3/{app_root/spec → spec}/controller_spec.rb +6 -16
  60. data/spec/rails3/spec/spec.opts +2 -0
  61. data/spec/rails3/spec/spec_helper.rb +70 -0
  62. data/spec/rails3/{app_root/spec → spec}/user_activation_spec.rb +7 -13
  63. data/spec/rails3/{app_root/spec → spec}/user_brute_force_protection_spec.rb +2 -30
  64. data/spec/rails3/{app_root/spec → spec}/user_oauth_spec.rb +7 -7
  65. data/spec/rails3/{app_root/spec → spec}/user_remember_me_spec.rb +3 -11
  66. data/spec/rails3/{app_root/spec → spec}/user_reset_password_spec.rb +20 -17
  67. data/spec/rails3/{app_root/spec → spec}/user_spec.rb +21 -11
  68. data/spec/sinatra/Gemfile +12 -0
  69. data/spec/sinatra/Gemfile.lock +134 -0
  70. data/spec/sinatra/Rakefile +11 -0
  71. data/spec/sinatra/authentication.rb +3 -0
  72. data/spec/sinatra/db/migrate/activation/20101224223622_add_activation_to_users.rb +17 -0
  73. data/spec/sinatra/db/migrate/activity_logging/20101224223624_add_activity_logging_to_users.rb +17 -0
  74. data/spec/sinatra/db/migrate/brute_force_protection/20101224223626_add_brute_force_protection_to_users.rb +11 -0
  75. data/spec/sinatra/db/migrate/core/20101224223620_create_users.rb +16 -0
  76. data/spec/sinatra/db/migrate/external/20101224223628_create_authentications.rb +14 -0
  77. data/spec/sinatra/db/migrate/remember_me/20101224223623_add_remember_me_token_to_users.rb +15 -0
  78. data/spec/sinatra/db/migrate/reset_password/20101224223622_add_reset_password_to_users.rb +13 -0
  79. data/spec/sinatra/filters.rb +21 -0
  80. data/spec/sinatra/myapp.rb +133 -0
  81. data/spec/sinatra/sorcery_mailer.rb +25 -0
  82. data/spec/sinatra/spec/controller_activity_logging_spec.rb +85 -0
  83. data/spec/sinatra/spec/controller_brute_force_protection_spec.rb +70 -0
  84. data/spec/sinatra/spec/controller_http_basic_auth_spec.rb +53 -0
  85. data/spec/sinatra/spec/controller_oauth2_spec.rb +120 -0
  86. data/spec/sinatra/spec/controller_oauth_spec.rb +121 -0
  87. data/spec/sinatra/spec/controller_remember_me_spec.rb +64 -0
  88. data/spec/sinatra/spec/controller_session_timeout_spec.rb +57 -0
  89. data/spec/sinatra/spec/controller_spec.rb +120 -0
  90. data/spec/sinatra/spec/spec.opts +2 -0
  91. data/spec/sinatra/spec/spec_helper.rb +46 -0
  92. data/spec/sinatra/user.rb +6 -0
  93. data/spec/sinatra/views/test_login.erb +4 -0
  94. data/spec/sorcery_crypto_providers_spec.rb +5 -4
  95. data/spec/spec.opts +2 -0
  96. data/spec/spec_helper.rb +3 -4
  97. data/spec/untitled folder +18 -0
  98. metadata +217 -139
  99. data/lib/sorcery/controller/submodules/oauth/oauth1.rb +0 -26
  100. data/lib/sorcery/controller/submodules/oauth/oauth2.rb +0 -24
  101. data/spec/rails3/app_root/.rspec +0 -1
  102. data/spec/rails3/app_root/config/database.yml +0 -27
  103. data/spec/rails3/app_root/spec/controller_session_timeout_spec.rb +0 -50
  104. data/spec/rails3/app_root/spec/spec_helper.rb +0 -61
  105. /data/spec/rails3/{app_root/.gitignore → .gitignore} +0 -0
  106. /data/spec/rails3/{app_root/README → README} +0 -0
  107. /data/spec/rails3/{app_root/Rakefile.unused → Rakefile.unused} +0 -0
  108. /data/spec/rails3/{app_root/app → app}/helpers/application_helper.rb +0 -0
  109. /data/spec/rails3/{app_root/app → app}/mailers/sorcery_mailer.rb +0 -0
  110. /data/spec/rails3/{app_root/app → app}/models/authentication.rb +0 -0
  111. /data/spec/rails3/{app_root/app → app}/models/user.rb +0 -0
  112. /data/spec/rails3/{app_root/app → app}/views/layouts/application.html.erb +0 -0
  113. /data/spec/rails3/{app_root/app → app}/views/sorcery_mailer/activation_email.html.erb +0 -0
  114. /data/spec/rails3/{app_root/app → app}/views/sorcery_mailer/activation_email.text.erb +0 -0
  115. /data/spec/rails3/{app_root/app → app}/views/sorcery_mailer/activation_success_email.html.erb +0 -0
  116. /data/spec/rails3/{app_root/app → app}/views/sorcery_mailer/activation_success_email.text.erb +0 -0
  117. /data/spec/rails3/{app_root/app → app}/views/sorcery_mailer/reset_password_email.html.erb +0 -0
  118. /data/spec/rails3/{app_root/app → app}/views/sorcery_mailer/reset_password_email.text.erb +0 -0
  119. /data/spec/rails3/{app_root/config → config}/application.rb +0 -0
  120. /data/spec/rails3/{app_root/config → config}/boot.rb +0 -0
  121. /data/spec/rails3/{app_root/config → config}/environment.rb +0 -0
  122. /data/spec/rails3/{app_root/config → config}/environments/development.rb +0 -0
  123. /data/spec/rails3/{app_root/config → config}/environments/in_memory.rb +0 -0
  124. /data/spec/rails3/{app_root/config → config}/environments/production.rb +0 -0
  125. /data/spec/rails3/{app_root/config → config}/environments/test.rb +0 -0
  126. /data/spec/rails3/{app_root/config → config}/initializers/backtrace_silencers.rb +0 -0
  127. /data/spec/rails3/{app_root/config → config}/initializers/inflections.rb +0 -0
  128. /data/spec/rails3/{app_root/config → config}/initializers/mime_types.rb +0 -0
  129. /data/spec/rails3/{app_root/config → config}/initializers/secret_token.rb +0 -0
  130. /data/spec/rails3/{app_root/config → config}/initializers/session_store.rb +0 -0
  131. /data/spec/rails3/{app_root/config → config}/locales/en.yml +0 -0
  132. /data/spec/rails3/{app_root/config → config}/routes.rb +0 -0
  133. /data/spec/rails3/{app_root/config.ru → config.ru} +0 -0
  134. /data/spec/rails3/{app_root/db → db}/migrate/activation/20101224223622_add_activation_to_users.rb +0 -0
  135. /data/spec/rails3/{app_root/db → db}/migrate/activity_logging/20101224223624_add_activity_logging_to_users.rb +0 -0
  136. /data/spec/rails3/{app_root/db → db}/migrate/brute_force_protection/20101224223626_add_brute_force_protection_to_users.rb +0 -0
  137. /data/spec/rails3/{app_root/db → db}/migrate/core/20101224223620_create_users.rb +0 -0
  138. /data/spec/rails3/{app_root/db/migrate/oauth → db/migrate/external}/20101224223628_create_authentications.rb +0 -0
  139. /data/spec/rails3/{app_root/db → db}/migrate/remember_me/20101224223623_add_remember_me_token_to_users.rb +0 -0
  140. /data/spec/rails3/{app_root/db → db}/migrate/reset_password/20101224223622_add_reset_password_to_users.rb +0 -0
  141. /data/spec/rails3/{app_root/db → db}/schema.rb +0 -0
  142. /data/spec/rails3/{app_root/db → db}/seeds.rb +0 -0
  143. /data/spec/rails3/{app_root/lib → lib}/tasks/.gitkeep +0 -0
  144. /data/spec/rails3/{app_root/public → public}/404.html +0 -0
  145. /data/spec/rails3/{app_root/public → public}/422.html +0 -0
  146. /data/spec/rails3/{app_root/public → public}/500.html +0 -0
  147. /data/spec/rails3/{app_root/public → public}/favicon.ico +0 -0
  148. /data/spec/rails3/{app_root/public → public}/images/rails.png +0 -0
  149. /data/spec/rails3/{app_root/public → public}/index.html +0 -0
  150. /data/spec/rails3/{app_root/public → public}/javascripts/application.js +0 -0
  151. /data/spec/rails3/{app_root/public → public}/javascripts/controls.js +0 -0
  152. /data/spec/rails3/{app_root/public → public}/javascripts/dragdrop.js +0 -0
  153. /data/spec/rails3/{app_root/public → public}/javascripts/effects.js +0 -0
  154. /data/spec/rails3/{app_root/public → public}/javascripts/prototype.js +0 -0
  155. /data/spec/rails3/{app_root/public → public}/javascripts/rails.js +0 -0
  156. /data/spec/rails3/{app_root/public → public}/robots.txt +0 -0
  157. /data/spec/rails3/{app_root/public → public}/stylesheets/.gitkeep +0 -0
  158. /data/spec/rails3/{app_root/script → script}/rails +0 -0
  159. /data/spec/rails3/{app_root/spec → spec}/controller_http_basic_auth_spec.rb +0 -0
  160. /data/spec/rails3/{app_root/spec → spec}/controller_remember_me_spec.rb +0 -0
  161. /data/spec/rails3/{app_root/spec → spec}/spec_helper.orig.rb +0 -0
  162. /data/spec/rails3/{app_root/spec → spec}/user_activity_logging_spec.rb +0 -0
  163. /data/spec/rails3/{app_root/vendor → vendor}/plugins/.gitkeep +0 -0
@@ -57,23 +57,17 @@ describe "User with activation submodule" do
57
57
  sorcery_reload!([:user_activation], :user_activation_mailer => ::SorceryMailer)
58
58
  end
59
59
 
60
- it "should generate an activation code on registration" do
60
+ before(:each) do
61
61
  create_new_user
62
- @user.activation_token.should_not be_nil
63
62
  end
64
63
 
65
64
  it "should initialize user state to 'pending'" do
66
- create_new_user
67
65
  @user.activation_state.should == "pending"
68
66
  end
69
67
 
70
- it "should respond to 'activate!'" do
71
- create_new_user
72
- @user.should respond_to(:activate!)
73
- end
68
+ specify { @user.should respond_to(:activate!) }
74
69
 
75
70
  it "should clear activation code and change state to 'active' on activation" do
76
- create_new_user
77
71
  activation_token = @user.activation_token
78
72
  @user.activate!
79
73
  @user2 = User.find(@user.id) # go to db to make sure it was saved and not just in memory
@@ -89,7 +83,6 @@ describe "User with activation submodule" do
89
83
  end
90
84
 
91
85
  it "subsequent saves do not send activation email" do
92
- create_new_user
93
86
  old_size = ActionMailer::Base.deliveries.size
94
87
  @user.username = "Shauli"
95
88
  @user.save!
@@ -97,14 +90,12 @@ describe "User with activation submodule" do
97
90
  end
98
91
 
99
92
  it "should send the user an activation success email on successful activation" do
100
- create_new_user
101
93
  old_size = ActionMailer::Base.deliveries.size
102
94
  @user.activate!
103
95
  ActionMailer::Base.deliveries.size.should == old_size + 1
104
96
  end
105
97
 
106
98
  it "subsequent saves do not send activation success email" do
107
- create_new_user
108
99
  @user.activate!
109
100
  old_size = ActionMailer::Base.deliveries.size
110
101
  @user.username = "Shauli"
@@ -121,7 +112,6 @@ describe "User with activation submodule" do
121
112
 
122
113
  it "activation success email is optional" do
123
114
  sorcery_model_property_set(:activation_success_email_method_name, nil)
124
- create_new_user
125
115
  old_size = ActionMailer::Base.deliveries.size
126
116
  @user.activate!
127
117
  ActionMailer::Base.deliveries.size.should == old_size
@@ -150,6 +140,10 @@ describe "User with activation submodule" do
150
140
  sorcery_reload!([:user_activation], :user_activation_mailer => ::SorceryMailer)
151
141
  end
152
142
 
143
+ after(:each) do
144
+ Timecop.return
145
+ end
146
+
153
147
  it "load_from_activation_token should return user when token is found" do
154
148
  create_new_user
155
149
  User.load_from_activation_token(@user.activation_token).should == @user
@@ -169,7 +163,7 @@ describe "User with activation submodule" do
169
163
  it "load_from_activation_token should NOT return user when token is found and expired" do
170
164
  sorcery_model_property_set(:activation_token_expiration_period, 0.1)
171
165
  create_new_user
172
- sleep 0.5
166
+ Timecop.travel(Time.now+0.5)
173
167
  User.load_from_activation_token(@user.activation_token).should == nil
174
168
  end
175
169
 
@@ -21,13 +21,8 @@ describe "User with brute_force_protection submodule" do
21
21
  User.sorcery_config.reset!
22
22
  end
23
23
 
24
- it "should respond to 'failed_logins_count'" do
25
- @user.should respond_to(:failed_logins_count)
26
- end
27
-
28
- it "should respond to 'lock_expires_at'" do
29
- @user.should respond_to(:failed_logins_count)
30
- end
24
+ specify { @user.should respond_to(:failed_logins_count) }
25
+ specify { @user.should respond_to(:lock_expires_at) }
31
26
 
32
27
  it "should enable configuration option 'failed_logins_count_attribute_name'" do
33
28
  sorcery_model_property_set(:failed_logins_count_attribute_name, :my_count)
@@ -49,28 +44,5 @@ describe "User with brute_force_protection submodule" do
49
44
  User.sorcery_config.login_lock_time_period.should == 2.hours
50
45
  end
51
46
  end
52
-
53
- # ----------------- PLUGIN ACTIVATED -----------------------
54
- describe User, "when activated with sorcery" do
55
-
56
- before(:all) do
57
- sorcery_reload!([:brute_force_protection])
58
- end
59
-
60
- before(:each) do
61
- User.delete_all
62
- end
63
-
64
- # it "should increment failed_logins_count on a failed login" do
65
- # create_new_user
66
- #
67
- # end
68
- #
69
- # it "should set lock expiry (effectively lock user) when failed_logins_count reaches max within max period" do
70
- # create_new_user
71
- # @user.lock_expires_at.should == Time.now.utc + 30
72
- # end
73
-
74
- end
75
47
 
76
48
  end
@@ -2,23 +2,23 @@ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
2
 
3
3
  describe "User with oauth submodule" do
4
4
  before(:all) do
5
- ActiveRecord::Migrator.migrate("#{Rails.root}/db/migrate/oauth")
5
+ ActiveRecord::Migrator.migrate("#{Rails.root}/db/migrate/external")
6
6
  end
7
7
 
8
8
  after(:all) do
9
- ActiveRecord::Migrator.rollback("#{Rails.root}/db/migrate/oauth")
9
+ ActiveRecord::Migrator.rollback("#{Rails.root}/db/migrate/external")
10
10
  end
11
11
 
12
12
  # ----------------- PLUGIN CONFIGURATION -----------------------
13
13
  describe User, "loaded plugin configuration" do
14
14
 
15
15
  before(:all) do
16
- sorcery_reload!([:oauth])
17
- sorcery_controller_property_set(:oauth_providers, [:twitter])
16
+ sorcery_reload!([:external])
17
+ sorcery_controller_property_set(:external_providers, [:twitter])
18
18
  sorcery_model_property_set(:authentications_class, Authentication)
19
- sorcery_controller_oauth_property_set(:twitter, :key, "eYVNBjBDi33aa9GkA3w")
20
- sorcery_controller_oauth_property_set(:twitter, :secret, "XpbeSdCoaKSmQGSeokz5qcUATClRW5u08QWNfv71N8")
21
- sorcery_controller_oauth_property_set(:twitter, :callback_url, "http://blabla.com")
19
+ sorcery_controller_external_property_set(:twitter, :key, "eYVNBjBDi33aa9GkA3w")
20
+ sorcery_controller_external_property_set(:twitter, :secret, "XpbeSdCoaKSmQGSeokz5qcUATClRW5u08QWNfv71N8")
21
+ sorcery_controller_external_property_set(:twitter, :callback_url, "http://blabla.com")
22
22
  create_new_external_user(:twitter)
23
23
  end
24
24
 
@@ -13,6 +13,7 @@ describe "User with remember_me submodule" do
13
13
  describe User, "loaded plugin configuration" do
14
14
  before(:all) do
15
15
  sorcery_reload!([:remember_me])
16
+ create_new_user
16
17
  end
17
18
 
18
19
  after(:each) do
@@ -29,32 +30,23 @@ describe "User with remember_me submodule" do
29
30
  User.sorcery_config.remember_me_token_expires_at_attribute_name.should equal(:my_expires)
30
31
  end
31
32
 
32
- it "should respond to 'remember_me!'" do
33
- create_new_user
34
- @user.should respond_to(:remember_me!)
35
- end
33
+ specify { @user.should respond_to(:remember_me!) }
36
34
 
37
- it "should respond to 'forget_me!'" do
38
- create_new_user
39
- @user.should respond_to(:forget_me!)
40
- end
35
+ specify { @user.should respond_to(:forget_me!) }
41
36
 
42
37
  it "should generate a new token on 'remember_me!'" do
43
- create_new_user
44
38
  @user.remember_me_token.should be_nil
45
39
  @user.remember_me!
46
40
  @user.remember_me_token.should_not be_nil
47
41
  end
48
42
 
49
43
  it "should set an expiration based on 'remember_me_for' attribute" do
50
- create_new_user
51
44
  sorcery_model_property_set(:remember_me_for, 2 * 60 * 60 * 24)
52
45
  @user.remember_me!
53
46
  @user.remember_me_token_expires_at.to_s.should == (Time.now + 2 * 60 * 60 * 24).utc.to_s
54
47
  end
55
48
 
56
49
  it "should delete the token and expiration on 'forget_me!'" do
57
- create_new_user
58
50
  @user.remember_me!
59
51
  @user.remember_me_token.should_not be_nil
60
52
  @user.forget_me!
@@ -20,21 +20,20 @@ describe "User with reset_password submodule" do
20
20
  User.sorcery_config.reset!
21
21
  end
22
22
 
23
- it "should respond to 'deliver_reset_password_instructions!'" do
24
- create_new_user
25
- @user.should respond_to(:deliver_reset_password_instructions!)
26
- end
27
-
28
- it "should respond to 'reset_password!" do
29
- create_new_user
30
- @user.should respond_to(:reset_password!)
31
- end
32
-
33
- it "should respond to 'load_from_reset_password_token'" do
34
- create_new_user
35
- User.should respond_to(:load_from_reset_password_token)
23
+ context "API" do
24
+ before(:all) do
25
+ create_new_user
26
+ end
27
+
28
+ specify { @user.should respond_to(:deliver_reset_password_instructions!) }
29
+
30
+ specify { @user.should respond_to(:reset_password!) }
31
+
32
+ it "should respond to .load_from_reset_password_token" do
33
+ User.should respond_to(:load_from_reset_password_token)
34
+ end
36
35
  end
37
-
36
+
38
37
  it "should allow configuration option 'reset_password_token_attribute_name'" do
39
38
  sorcery_model_property_set(:reset_password_token_attribute_name, :my_code)
40
39
  User.sorcery_config.reset_password_token_attribute_name.should equal(:my_code)
@@ -76,7 +75,11 @@ describe "User with reset_password submodule" do
76
75
  before(:each) do
77
76
  User.delete_all
78
77
  end
79
-
78
+
79
+ after(:each) do
80
+ Timecop.return
81
+ end
82
+
80
83
  it "load_from_reset_password_token should return user when token is found" do
81
84
  create_new_user
82
85
  @user.deliver_reset_password_instructions!
@@ -100,7 +103,7 @@ describe "User with reset_password submodule" do
100
103
  create_new_user
101
104
  sorcery_model_property_set(:reset_password_expiration_period, 0.1)
102
105
  @user.deliver_reset_password_instructions!
103
- sleep 0.5
106
+ Timecop.travel(Time.now+0.5)
104
107
  User.load_from_reset_password_token(@user.reset_password_token).should == nil
105
108
  end
106
109
 
@@ -164,7 +167,7 @@ describe "User with reset_password submodule" do
164
167
  old_size = ActionMailer::Base.deliveries.size
165
168
  @user.deliver_reset_password_instructions!
166
169
  ActionMailer::Base.deliveries.size.should == old_size + 1
167
- sleep 0.5
170
+ Timecop.travel(Time.now+0.5)
168
171
  @user.deliver_reset_password_instructions!
169
172
  ActionMailer::Base.deliveries.size.should == old_size + 2
170
173
  end
@@ -8,14 +8,11 @@ describe "User with no submodules (core)" do
8
8
 
9
9
  describe User, "when app has plugin loaded" do
10
10
  it "should respond to the plugin activation class method" do
11
- ActiveRecord::Base.should respond_to(:activate_sorcery!)
12
- User.should respond_to(:activate_sorcery!)
11
+ ActiveRecord::Base.should respond_to(:authenticates_with_sorcery!)
13
12
  end
14
13
 
15
- it "plugin activation should yield config to block" do
16
- User.activate_sorcery! do |config|
17
- config.class.should == ::Sorcery::Model::Config
18
- end
14
+ it "User should respond_to .authenticates_with_sorcery!" do
15
+ User.should respond_to(:authenticates_with_sorcery!)
19
16
  end
20
17
  end
21
18
 
@@ -23,7 +20,7 @@ describe "User with no submodules (core)" do
23
20
  describe TestUser, "Testing activated class self-registration" do
24
21
  it "should register itself as user_class if activated" do
25
22
  TestUser.class_eval do
26
- activate_sorcery!
23
+ authenticates_with_sorcery!
27
24
  end
28
25
  ::Sorcery::Controller::Config.user_class.should == TestUser
29
26
  end
@@ -115,8 +112,21 @@ describe "User with no submodules (core)" do
115
112
  User.authenticate(@user.send(User.sorcery_config.username_attribute_name), 'wrong!').should be_false
116
113
  end
117
114
 
118
- it "should respond to the class method encrypt" do
119
- User.should respond_to(:encrypt)
115
+ specify { User.should respond_to(:encrypt) }
116
+
117
+ it "subclass should inherit config if defined so" do
118
+ sorcery_reload!([],{:subclasses_inherit_config => true})
119
+ class Admin < User
120
+ end
121
+ Admin.sorcery_config.should_not be_nil
122
+ Admin.sorcery_config.should == User.sorcery_config
123
+ end
124
+
125
+ it "subclass should not inherit config if not defined so" do
126
+ sorcery_reload!([],{:subclasses_inherit_config => false})
127
+ class Admin2 < User
128
+ end
129
+ Admin2.sorcery_config.should be_nil
120
130
  end
121
131
  end
122
132
 
@@ -286,12 +296,12 @@ describe "User with no submodules (core)" do
286
296
 
287
297
  describe User, "external users" do
288
298
  before(:all) do
289
- ActiveRecord::Migrator.migrate("#{Rails.root}/db/migrate/oauth")
299
+ ActiveRecord::Migrator.migrate("#{Rails.root}/db/migrate/external")
290
300
  sorcery_reload!()
291
301
  end
292
302
 
293
303
  after(:all) do
294
- ActiveRecord::Migrator.rollback("#{Rails.root}/db/migrate/oauth")
304
+ ActiveRecord::Migrator.rollback("#{Rails.root}/db/migrate/external")
295
305
  end
296
306
 
297
307
  before(:each) do
@@ -0,0 +1,12 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gem 'sinatra', '>= 1.2.0'
4
+ gem 'sqlite3-ruby', :require => 'sqlite3'
5
+ gem "sorcery", '>= 0.1.0', :path => '../../'
6
+
7
+ group :development, :test do
8
+ gem "rspec", "~> 2.5.0"
9
+ gem 'ruby-debug19'
10
+ gem 'simplecov', '>= 0.3.8', :require => false # Will install simplecov-html as a dependency
11
+ gem 'timecop'
12
+ end
@@ -0,0 +1,134 @@
1
+ PATH
2
+ remote: ../../
3
+ specs:
4
+ sorcery (0.4.2)
5
+ bcrypt-ruby (~> 2.1.4)
6
+ json (>= 1.5.1)
7
+ oauth (>= 0.4.4)
8
+ oauth (>= 0.4.4)
9
+ oauth2 (>= 0.1.1)
10
+ oauth2 (>= 0.1.1)
11
+ rails (>= 3.0.0)
12
+
13
+ GEM
14
+ remote: http://rubygems.org/
15
+ specs:
16
+ abstract (1.0.0)
17
+ actionmailer (3.0.3)
18
+ actionpack (= 3.0.3)
19
+ mail (~> 2.2.9)
20
+ actionpack (3.0.3)
21
+ activemodel (= 3.0.3)
22
+ activesupport (= 3.0.3)
23
+ builder (~> 2.1.2)
24
+ erubis (~> 2.6.6)
25
+ i18n (~> 0.4)
26
+ rack (~> 1.2.1)
27
+ rack-mount (~> 0.6.13)
28
+ rack-test (~> 0.5.6)
29
+ tzinfo (~> 0.3.23)
30
+ activemodel (3.0.3)
31
+ activesupport (= 3.0.3)
32
+ builder (~> 2.1.2)
33
+ i18n (~> 0.4)
34
+ activerecord (3.0.3)
35
+ activemodel (= 3.0.3)
36
+ activesupport (= 3.0.3)
37
+ arel (~> 2.0.2)
38
+ tzinfo (~> 0.3.23)
39
+ activeresource (3.0.3)
40
+ activemodel (= 3.0.3)
41
+ activesupport (= 3.0.3)
42
+ activesupport (3.0.3)
43
+ addressable (2.2.5)
44
+ archive-tar-minitar (0.5.2)
45
+ arel (2.0.7)
46
+ bcrypt-ruby (2.1.4)
47
+ builder (2.1.2)
48
+ columnize (0.3.2)
49
+ diff-lcs (1.1.2)
50
+ erubis (2.6.6)
51
+ abstract (>= 1.0.0)
52
+ faraday (0.6.1)
53
+ addressable (~> 2.2.4)
54
+ multipart-post (~> 1.1.0)
55
+ rack (< 2, >= 1.1.0)
56
+ i18n (0.5.0)
57
+ json (1.5.1)
58
+ linecache19 (0.5.11)
59
+ ruby_core_source (>= 0.1.4)
60
+ mail (2.2.15)
61
+ activesupport (>= 2.3.6)
62
+ i18n (>= 0.4.0)
63
+ mime-types (~> 1.16)
64
+ treetop (~> 1.4.8)
65
+ mime-types (1.16)
66
+ multi_json (0.0.5)
67
+ multipart-post (1.1.0)
68
+ oauth (0.4.4)
69
+ oauth2 (0.4.0)
70
+ faraday (~> 0.6.0)
71
+ multi_json (~> 0.0.4)
72
+ polyglot (0.3.1)
73
+ rack (1.2.1)
74
+ rack-mount (0.6.14)
75
+ rack (>= 1.0.0)
76
+ rack-test (0.5.7)
77
+ rack (>= 1.0)
78
+ rails (3.0.3)
79
+ actionmailer (= 3.0.3)
80
+ actionpack (= 3.0.3)
81
+ activerecord (= 3.0.3)
82
+ activeresource (= 3.0.3)
83
+ activesupport (= 3.0.3)
84
+ bundler (~> 1.0)
85
+ railties (= 3.0.3)
86
+ railties (3.0.3)
87
+ actionpack (= 3.0.3)
88
+ activesupport (= 3.0.3)
89
+ rake (>= 0.8.7)
90
+ thor (~> 0.14.4)
91
+ rake (0.8.7)
92
+ rspec (2.5.0)
93
+ rspec-core (~> 2.5.0)
94
+ rspec-expectations (~> 2.5.0)
95
+ rspec-mocks (~> 2.5.0)
96
+ rspec-core (2.5.1)
97
+ rspec-expectations (2.5.0)
98
+ diff-lcs (~> 1.1.2)
99
+ rspec-mocks (2.5.0)
100
+ ruby-debug-base19 (0.11.24)
101
+ columnize (>= 0.3.1)
102
+ linecache19 (>= 0.5.11)
103
+ ruby_core_source (>= 0.1.4)
104
+ ruby-debug19 (0.11.6)
105
+ columnize (>= 0.3.1)
106
+ linecache19 (>= 0.5.11)
107
+ ruby-debug-base19 (>= 0.11.19)
108
+ ruby_core_source (0.1.4)
109
+ archive-tar-minitar (>= 0.5.2)
110
+ simplecov (0.3.9)
111
+ simplecov-html (>= 0.3.7)
112
+ simplecov-html (0.3.9)
113
+ sinatra (1.2.0)
114
+ rack (~> 1.1)
115
+ tilt (< 2.0, >= 1.2.2)
116
+ sqlite3-ruby (1.3.2)
117
+ thor (0.14.6)
118
+ tilt (1.2.2)
119
+ timecop (0.3.5)
120
+ treetop (1.4.9)
121
+ polyglot (>= 0.3.1)
122
+ tzinfo (0.3.24)
123
+
124
+ PLATFORMS
125
+ ruby
126
+
127
+ DEPENDENCIES
128
+ rspec (~> 2.5.0)
129
+ ruby-debug19
130
+ simplecov (>= 0.3.8)
131
+ sinatra (>= 1.2.0)
132
+ sorcery (>= 0.1.0)!
133
+ sqlite3-ruby
134
+ timecop
@@ -0,0 +1,11 @@
1
+ require 'rake'
2
+ require 'rspec/core/rake_task'
3
+
4
+ desc 'Default: Run all specs.'
5
+ task :default => :spec
6
+
7
+ desc "Run all specs"
8
+ RSpec::Core::RakeTask.new(:spec) do |t|
9
+ t.pattern = '**/*_spec.rb'
10
+ t.rspec_opts = ["--options #{File.dirname(__FILE__)}/spec/spec.opts"]
11
+ end
@@ -0,0 +1,3 @@
1
+ class Authentication < ActiveRecord::Base
2
+ belongs_to :user
3
+ end
@@ -0,0 +1,17 @@
1
+ class AddActivationToUsers < ActiveRecord::Migration
2
+ def self.up
3
+ add_column :users, :activation_state, :string, :default => nil
4
+ add_column :users, :activation_token, :string, :default => nil
5
+ add_column :users, :activation_token_expires_at, :datetime, :default => nil
6
+
7
+ add_index :users, :activation_token
8
+ end
9
+
10
+ def self.down
11
+ remove_index :users, :activation_token
12
+
13
+ remove_column :users, :activation_token_expires_at
14
+ remove_column :users, :activation_token
15
+ remove_column :users, :activation_state
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ class AddActivityLoggingToUsers < ActiveRecord::Migration
2
+ def self.up
3
+ add_column :users, :last_login_at, :datetime, :default => nil
4
+ add_column :users, :last_logout_at, :datetime, :default => nil
5
+ add_column :users, :last_activity_at, :datetime, :default => nil
6
+
7
+ add_index :users, [:last_logout_at, :last_activity_at]
8
+ end
9
+
10
+ def self.down
11
+ remove_index :users, [:last_logout_at, :last_activity_at]
12
+
13
+ remove_column :users, :last_activity_at
14
+ remove_column :users, :last_logout_at
15
+ remove_column :users, :last_login_at
16
+ end
17
+ end
@@ -0,0 +1,11 @@
1
+ class AddBruteForceProtectionToUsers < ActiveRecord::Migration
2
+ def self.up
3
+ add_column :users, :failed_logins_count, :integer, :default => 0
4
+ add_column :users, :lock_expires_at, :datetime, :default => nil
5
+ end
6
+
7
+ def self.down
8
+ remove_column :users, :lock_expires_at
9
+ remove_column :users, :failed_logins_count
10
+ end
11
+ end
@@ -0,0 +1,16 @@
1
+ class CreateUsers < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :users do |t|
4
+ t.string :username, :null => false
5
+ t.string :email, :default => nil
6
+ t.string :crypted_password, :default => nil
7
+ t.string :salt, :default => nil
8
+
9
+ t.timestamps
10
+ end
11
+ end
12
+
13
+ def self.down
14
+ drop_table :users
15
+ end
16
+ end
@@ -0,0 +1,14 @@
1
+ class CreateAuthentications < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :authentications do |t|
4
+ t.integer :user_id, :null => false
5
+ t.string :provider, :uid, :null => false
6
+
7
+ t.timestamps
8
+ end
9
+ end
10
+
11
+ def self.down
12
+ drop_table :authentications
13
+ end
14
+ end
@@ -0,0 +1,15 @@
1
+ class AddRememberMeTokenToUsers < ActiveRecord::Migration
2
+ def self.up
3
+ add_column :users, :remember_me_token, :string, :default => nil
4
+ add_column :users, :remember_me_token_expires_at, :datetime, :default => nil
5
+
6
+ add_index :users, :remember_me_token
7
+ end
8
+
9
+ def self.down
10
+ remove_index :users, :remember_me_token
11
+
12
+ remove_column :users, :remember_me_token_expires_at
13
+ remove_column :users, :remember_me_token
14
+ end
15
+ end
@@ -0,0 +1,13 @@
1
+ class AddResetPasswordToUsers < ActiveRecord::Migration
2
+ def self.up
3
+ add_column :users, :reset_password_token, :string, :default => nil
4
+ add_column :users, :reset_password_token_expires_at, :datetime, :default => nil
5
+ add_column :users, :reset_password_email_sent_at, :datetime, :default => nil
6
+ end
7
+
8
+ def self.down
9
+ remove_column :users, :reset_password_email_sent_at
10
+ remove_column :users, :reset_password_token_expires_at
11
+ remove_column :users, :reset_password_token
12
+ end
13
+ end
@@ -0,0 +1,21 @@
1
+ # --- before filters
2
+
3
+ ['/test_logout','/some_action','/test_should_be_logged_in'].each do |patt|
4
+ before patt do
5
+ require_login
6
+ end
7
+ end
8
+
9
+ before '/test_http_basic_auth' do
10
+ require_login_from_http_basic
11
+ end
12
+
13
+ # ----- test filters
14
+
15
+ before do
16
+ self.class.sorcery_vars = {}
17
+ end
18
+
19
+ after do
20
+ save_instance_vars
21
+ end