sorcery 0.3.1 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of sorcery might be problematic. Click here for more details.

Files changed (131) hide show
  1. data/Gemfile +3 -2
  2. data/Gemfile.lock +13 -11
  3. data/README.rdoc +89 -61
  4. data/Rakefile +4 -4
  5. data/VERSION +1 -1
  6. data/lib/generators/sorcery_migration/templates/core.rb +2 -2
  7. data/lib/sorcery.rb +1 -0
  8. data/lib/sorcery/controller.rb +16 -18
  9. data/lib/sorcery/controller/submodules/http_basic_auth.rb +1 -1
  10. data/lib/sorcery/crypto_providers/bcrypt.rb +1 -1
  11. data/lib/sorcery/crypto_providers/common.rb +35 -0
  12. data/lib/sorcery/crypto_providers/md5.rb +3 -23
  13. data/lib/sorcery/crypto_providers/sha1.rb +4 -16
  14. data/lib/sorcery/crypto_providers/sha256.rb +3 -23
  15. data/lib/sorcery/crypto_providers/sha512.rb +3 -23
  16. data/lib/sorcery/engine.rb +4 -0
  17. data/lib/sorcery/initializers/initializer.rb +86 -0
  18. data/lib/sorcery/model.rb +4 -2
  19. data/lib/sorcery/railties/tasks.rake +10 -0
  20. data/lib/sorcery/sinatra.rb +0 -9
  21. data/lib/sorcery/test_helpers.rb +12 -0
  22. data/lib/sorcery/test_helpers/rails.rb +6 -9
  23. data/lib/sorcery/test_helpers/sinatra.rb +6 -9
  24. data/sorcery.gemspec +137 -146
  25. data/spec/Gemfile +2 -2
  26. data/spec/Gemfile.lock +10 -10
  27. data/spec/Rakefile +1 -0
  28. data/spec/rails3/{app_root/.gitignore → .gitignore} +0 -0
  29. data/spec/rails3/.rspec +1 -1
  30. data/spec/rails3/{app_root/Gemfile → Gemfile} +4 -4
  31. data/spec/rails3/{app_root/Gemfile.lock → Gemfile.lock} +20 -20
  32. data/spec/rails3/{app_root/README → README} +0 -0
  33. data/spec/rails3/{app_root/Rakefile → Rakefile} +1 -0
  34. data/spec/rails3/{app_root/Rakefile.unused → Rakefile.unused} +0 -0
  35. data/spec/rails3/{app_root/app → app}/controllers/application_controller.rb +0 -0
  36. data/spec/rails3/{app_root/app → app}/helpers/application_helper.rb +0 -0
  37. data/spec/rails3/{app_root/app → app}/mailers/sorcery_mailer.rb +0 -0
  38. data/spec/rails3/{app_root/app → app}/models/authentication.rb +0 -0
  39. data/spec/rails3/{app_root/app → app}/models/user.rb +0 -0
  40. data/spec/rails3/{app_root/app → app}/views/layouts/application.html.erb +0 -0
  41. data/spec/rails3/{app_root/app → app}/views/sorcery_mailer/activation_email.html.erb +0 -0
  42. data/spec/rails3/{app_root/app → app}/views/sorcery_mailer/activation_email.text.erb +0 -0
  43. data/spec/rails3/{app_root/app → app}/views/sorcery_mailer/activation_success_email.html.erb +0 -0
  44. data/spec/rails3/{app_root/app → app}/views/sorcery_mailer/activation_success_email.text.erb +0 -0
  45. data/spec/rails3/{app_root/app → app}/views/sorcery_mailer/reset_password_email.html.erb +0 -0
  46. data/spec/rails3/{app_root/app → app}/views/sorcery_mailer/reset_password_email.text.erb +0 -0
  47. data/spec/rails3/{app_root/config.ru → config.ru} +0 -0
  48. data/spec/rails3/{app_root/config → config}/application.rb +0 -0
  49. data/spec/rails3/{app_root/config → config}/boot.rb +0 -0
  50. data/spec/rails3/config/database.yml +27 -0
  51. data/spec/rails3/{app_root/config → config}/environment.rb +0 -0
  52. data/spec/rails3/{app_root/config → config}/environments/development.rb +0 -0
  53. data/spec/rails3/{app_root/config → config}/environments/in_memory.rb +0 -0
  54. data/spec/rails3/{app_root/config → config}/environments/production.rb +0 -0
  55. data/spec/rails3/{app_root/config → config}/environments/test.rb +0 -0
  56. data/spec/rails3/{app_root/config → config}/initializers/backtrace_silencers.rb +0 -0
  57. data/spec/rails3/{app_root/config → config}/initializers/inflections.rb +0 -0
  58. data/spec/rails3/{app_root/config → config}/initializers/mime_types.rb +0 -0
  59. data/spec/rails3/{app_root/config → config}/initializers/secret_token.rb +0 -0
  60. data/spec/rails3/{app_root/config → config}/initializers/session_store.rb +0 -0
  61. data/spec/rails3/{app_root/config → config}/locales/en.yml +0 -0
  62. data/spec/rails3/{app_root/config → config}/routes.rb +0 -0
  63. data/spec/rails3/{app_root/db → db}/migrate/activation/20101224223622_add_activation_to_users.rb +0 -0
  64. data/spec/rails3/{app_root/db → db}/migrate/activity_logging/20101224223624_add_activity_logging_to_users.rb +0 -0
  65. data/spec/rails3/{app_root/db → db}/migrate/brute_force_protection/20101224223626_add_brute_force_protection_to_users.rb +0 -0
  66. data/spec/rails3/{app_root/db → db}/migrate/core/20101224223620_create_users.rb +0 -0
  67. data/spec/rails3/{app_root/db → db}/migrate/external/20101224223628_create_authentications.rb +0 -0
  68. data/spec/rails3/{app_root/db → db}/migrate/remember_me/20101224223623_add_remember_me_token_to_users.rb +0 -0
  69. data/spec/rails3/{app_root/db → db}/migrate/reset_password/20101224223622_add_reset_password_to_users.rb +0 -0
  70. data/spec/rails3/{app_root/db → db}/schema.rb +0 -0
  71. data/spec/rails3/{app_root/db → db}/seeds.rb +0 -0
  72. data/spec/rails3/{app_root/lib → lib}/tasks/.gitkeep +0 -0
  73. data/spec/rails3/{app_root/public → public}/404.html +0 -0
  74. data/spec/rails3/{app_root/public → public}/422.html +0 -0
  75. data/spec/rails3/{app_root/public → public}/500.html +0 -0
  76. data/spec/rails3/{app_root/public → public}/favicon.ico +0 -0
  77. data/spec/rails3/{app_root/public → public}/images/rails.png +0 -0
  78. data/spec/rails3/{app_root/public → public}/index.html +0 -0
  79. data/spec/rails3/{app_root/public → public}/javascripts/application.js +0 -0
  80. data/spec/rails3/{app_root/public → public}/javascripts/controls.js +0 -0
  81. data/spec/rails3/{app_root/public → public}/javascripts/dragdrop.js +0 -0
  82. data/spec/rails3/{app_root/public → public}/javascripts/effects.js +0 -0
  83. data/spec/rails3/{app_root/public → public}/javascripts/prototype.js +0 -0
  84. data/spec/rails3/{app_root/public → public}/javascripts/rails.js +0 -0
  85. data/spec/rails3/{app_root/public → public}/robots.txt +0 -0
  86. data/spec/rails3/{app_root/public → public}/stylesheets/.gitkeep +0 -0
  87. data/spec/rails3/{app_root/script → script}/rails +0 -0
  88. data/spec/rails3/{app_root/spec → spec}/controller_activity_logging_spec.rb +0 -0
  89. data/spec/rails3/{app_root/spec → spec}/controller_brute_force_protection_spec.rb +3 -2
  90. data/spec/rails3/{app_root/spec → spec}/controller_http_basic_auth_spec.rb +0 -0
  91. data/spec/rails3/{app_root/spec → spec}/controller_oauth2_spec.rb +10 -9
  92. data/spec/rails3/{app_root/spec → spec}/controller_oauth_spec.rb +5 -5
  93. data/spec/rails3/{app_root/spec → spec}/controller_remember_me_spec.rb +0 -0
  94. data/spec/rails3/{app_root/spec → spec}/controller_session_timeout_spec.rb +8 -4
  95. data/spec/rails3/{app_root/spec → spec}/controller_spec.rb +0 -0
  96. data/spec/rails3/spec/spec.opts +2 -0
  97. data/spec/rails3/{app_root/spec → spec}/spec_helper.orig.rb +0 -0
  98. data/spec/rails3/spec/spec_helper.rb +70 -0
  99. data/spec/rails3/{app_root/spec → spec}/user_activation_spec.rb +5 -1
  100. data/spec/rails3/{app_root/spec → spec}/user_activity_logging_spec.rb +0 -0
  101. data/spec/rails3/{app_root/spec → spec}/user_brute_force_protection_spec.rb +0 -0
  102. data/spec/rails3/{app_root/spec → spec}/user_oauth_spec.rb +3 -3
  103. data/spec/rails3/{app_root/spec → spec}/user_remember_me_spec.rb +0 -0
  104. data/spec/rails3/{app_root/spec → spec}/user_reset_password_spec.rb +7 -3
  105. data/spec/rails3/{app_root/spec → spec}/user_spec.rb +3 -9
  106. data/spec/rails3/{app_root/vendor → vendor}/plugins/.gitkeep +0 -0
  107. data/spec/sinatra/Gemfile +3 -3
  108. data/spec/sinatra/Gemfile.lock +17 -17
  109. data/spec/sinatra/Rakefile +1 -0
  110. data/spec/sinatra/spec/controller_brute_force_protection_spec.rb +3 -2
  111. data/spec/sinatra/spec/controller_oauth2_spec.rb +10 -9
  112. data/spec/sinatra/spec/controller_oauth_spec.rb +5 -5
  113. data/spec/sinatra/spec/controller_session_timeout_spec.rb +8 -4
  114. data/spec/sinatra/spec/spec.opts +2 -4
  115. data/spec/sinatra/spec/spec_helper.rb +2 -1
  116. data/spec/sorcery_crypto_providers_spec.rb +5 -4
  117. data/spec/spec.opts +2 -0
  118. data/spec/spec_helper.rb +3 -4
  119. metadata +148 -149
  120. data/lib/sorcery/controller/submodules/email.rb +0 -44
  121. data/lib/sorcery/controller/submodules/oauth.rb +0 -95
  122. data/spec/rails3/app_root/.rspec +0 -1
  123. data/spec/rails3/app_root/config/database.yml +0 -27
  124. data/spec/rails3/app_root/spec/spec_helper.rb +0 -62
  125. data/spec/sinatra/spec/user_activation_spec.rb +0 -188
  126. data/spec/sinatra/spec/user_activity_logging_spec.rb +0 -36
  127. data/spec/sinatra/spec/user_brute_force_protection_spec.rb +0 -76
  128. data/spec/sinatra/spec/user_oauth_spec.rb +0 -39
  129. data/spec/sinatra/spec/user_remember_me_spec.rb +0 -66
  130. data/spec/sinatra/spec/user_reset_password_spec.rb +0 -178
  131. data/spec/sinatra/spec/user_spec.rb +0 -317
@@ -1,76 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
-
3
- describe "User with brute_force_protection submodule" do
4
- before(:all) do
5
- ActiveRecord::Migrator.migrate("#{APP_ROOT}/db/migrate/brute_force_protection")
6
- end
7
-
8
- after(:all) do
9
- ActiveRecord::Migrator.rollback("#{APP_ROOT}/db/migrate/brute_force_protection")
10
- end
11
-
12
- # ----------------- PLUGIN CONFIGURATION -----------------------
13
- describe User, "loaded plugin configuration" do
14
-
15
- before(:all) do
16
- sorcery_reload!([:brute_force_protection])
17
- create_new_user
18
- end
19
-
20
- after(:each) do
21
- User.sorcery_config.reset!
22
- end
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
31
-
32
- it "should enable configuration option 'failed_logins_count_attribute_name'" do
33
- sorcery_model_property_set(:failed_logins_count_attribute_name, :my_count)
34
- User.sorcery_config.failed_logins_count_attribute_name.should equal(:my_count)
35
- end
36
-
37
- it "should enable configuration option 'lock_expires_at_attribute_name'" do
38
- sorcery_model_property_set(:lock_expires_at_attribute_name, :expires)
39
- User.sorcery_config.lock_expires_at_attribute_name.should equal(:expires)
40
- end
41
-
42
- it "should enable configuration option 'consecutive_login_retries_amount_allowed'" do
43
- sorcery_model_property_set(:consecutive_login_retries_amount_limit, 34)
44
- User.sorcery_config.consecutive_login_retries_amount_limit.should equal(34)
45
- end
46
-
47
- it "should enable configuration option 'login_lock_time_period'" do
48
- sorcery_model_property_set(:login_lock_time_period, 2.hours)
49
- User.sorcery_config.login_lock_time_period.should == 2.hours
50
- end
51
- 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
-
76
- end
@@ -1,39 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
-
3
- describe "User with oauth submodule" do
4
- before(:all) do
5
- ActiveRecord::Migrator.migrate("#{APP_ROOT}/db/migrate/external")
6
- end
7
-
8
- after(:all) do
9
- ActiveRecord::Migrator.rollback("#{APP_ROOT}/db/migrate/external")
10
- end
11
-
12
- # ----------------- PLUGIN CONFIGURATION -----------------------
13
- describe User, "loaded plugin configuration" do
14
-
15
- before(:all) do
16
- sorcery_reload!([:external])
17
- sorcery_controller_property_set(:external_providers, [:twitter])
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")
22
- create_new_external_user(:twitter)
23
- end
24
-
25
- it "should respond to 'load_from_provider'" do
26
- User.should respond_to(:load_from_provider)
27
- end
28
-
29
- it "'load_from_provider' should load user if exists" do
30
- User.load_from_provider(:twitter,123).should == @user
31
- end
32
-
33
- it "'load_from_provider' should return nil if user doesn't exist" do
34
- User.load_from_provider(:twitter,980342).should be_nil
35
- end
36
-
37
- end
38
-
39
- end
@@ -1,66 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
-
3
- describe "User with remember_me submodule" do
4
- before(:all) do
5
- ActiveRecord::Migrator.migrate("#{APP_ROOT}/db/migrate/remember_me")
6
- end
7
-
8
- after(:all) do
9
- ActiveRecord::Migrator.rollback("#{APP_ROOT}/db/migrate/remember_me")
10
- end
11
-
12
- # ----------------- PLUGIN CONFIGURATION -----------------------
13
- describe User, "loaded plugin configuration" do
14
- before(:all) do
15
- sorcery_reload!([:remember_me])
16
- end
17
-
18
- after(:each) do
19
- User.sorcery_config.reset!
20
- end
21
-
22
- it "should allow configuration option 'remember_me_token_attribute_name'" do
23
- sorcery_model_property_set(:remember_me_token_attribute_name, :my_token)
24
- User.sorcery_config.remember_me_token_attribute_name.should equal(:my_token)
25
- end
26
-
27
- it "should allow configuration option 'remember_me_token_expires_at_attribute_name'" do
28
- sorcery_model_property_set(:remember_me_token_expires_at_attribute_name, :my_expires)
29
- User.sorcery_config.remember_me_token_expires_at_attribute_name.should equal(:my_expires)
30
- end
31
-
32
- it "should respond to 'remember_me!'" do
33
- create_new_user
34
- @user.should respond_to(:remember_me!)
35
- end
36
-
37
- it "should respond to 'forget_me!'" do
38
- create_new_user
39
- @user.should respond_to(:forget_me!)
40
- end
41
-
42
- it "should generate a new token on 'remember_me!'" do
43
- create_new_user
44
- @user.remember_me_token.should be_nil
45
- @user.remember_me!
46
- @user.remember_me_token.should_not be_nil
47
- end
48
-
49
- it "should set an expiration based on 'remember_me_for' attribute" do
50
- create_new_user
51
- sorcery_model_property_set(:remember_me_for, 2 * 60 * 60 * 24)
52
- @user.remember_me!
53
- @user.remember_me_token_expires_at.to_s.should == (Time.now + 2 * 60 * 60 * 24).to_s
54
- end
55
-
56
- it "should delete the token and expiration on 'forget_me!'" do
57
- create_new_user
58
- @user.remember_me!
59
- @user.remember_me_token.should_not be_nil
60
- @user.forget_me!
61
- @user.remember_me_token.should be_nil
62
- @user.remember_me_token_expires_at.should be_nil
63
- end
64
- end
65
-
66
- end
@@ -1,178 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
-
3
- describe "User with reset_password submodule" do
4
- before(:all) do
5
- ActiveRecord::Migrator.migrate("#{APP_ROOT}/db/migrate/reset_password")
6
- end
7
-
8
- after(:all) do
9
- ActiveRecord::Migrator.rollback("#{APP_ROOT}/db/migrate/reset_password")
10
- end
11
-
12
- # ----------------- PLUGIN CONFIGURATION -----------------------
13
- describe User, "loaded plugin configuration" do
14
-
15
- before(:all) do
16
- sorcery_reload!([:reset_password], :reset_password_mailer => ::SorceryMailer)
17
- end
18
-
19
- after(:each) do
20
- User.sorcery_config.reset!
21
- end
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)
36
- end
37
-
38
- it "should allow configuration option 'reset_password_token_attribute_name'" do
39
- sorcery_model_property_set(:reset_password_token_attribute_name, :my_code)
40
- User.sorcery_config.reset_password_token_attribute_name.should equal(:my_code)
41
- end
42
-
43
- it "should allow configuration option 'reset_password_mailer'" do
44
- sorcery_model_property_set(:reset_password_mailer, TestUser)
45
- User.sorcery_config.reset_password_mailer.should equal(TestUser)
46
- end
47
-
48
- it "should allow configuration option 'reset_password_email_method_name'" do
49
- sorcery_model_property_set(:reset_password_email_method_name, :my_mailer_method)
50
- User.sorcery_config.reset_password_email_method_name.should equal(:my_mailer_method)
51
- end
52
-
53
- it "should allow configuration option 'reset_password_expiration_period'" do
54
- sorcery_model_property_set(:reset_password_expiration_period, 16)
55
- User.sorcery_config.reset_password_expiration_period.should equal(16)
56
- end
57
-
58
- it "should allow configuration option 'reset_password_email_sent_at_attribute_name'" do
59
- sorcery_model_property_set(:reset_password_email_sent_at_attribute_name, :blabla)
60
- User.sorcery_config.reset_password_email_sent_at_attribute_name.should equal(:blabla)
61
- end
62
-
63
- it "should allow configuration option 'reset_password_time_between_emails'" do
64
- sorcery_model_property_set(:reset_password_time_between_emails, 16)
65
- User.sorcery_config.reset_password_time_between_emails.should equal(16)
66
- end
67
- end
68
-
69
- # ----------------- PLUGIN ACTIVATED -----------------------
70
- describe User, "when activated with sorcery" do
71
-
72
- before(:all) do
73
- sorcery_reload!([:reset_password], :reset_password_mailer => ::SorceryMailer)
74
- end
75
-
76
- before(:each) do
77
- User.delete_all
78
- end
79
-
80
- it "load_from_reset_password_token should return user when token is found" do
81
- create_new_user
82
- @user.deliver_reset_password_instructions!
83
- User.load_from_reset_password_token(@user.reset_password_token).should == @user
84
- end
85
-
86
- it "load_from_reset_password_token should NOT return user when token is NOT found" do
87
- create_new_user
88
- @user.deliver_reset_password_instructions!
89
- User.load_from_reset_password_token("a").should == nil
90
- end
91
-
92
- it "load_from_reset_password_token should return user when token is found and not expired" do
93
- create_new_user
94
- sorcery_model_property_set(:reset_password_expiration_period, 500)
95
- @user.deliver_reset_password_instructions!
96
- User.load_from_reset_password_token(@user.reset_password_token).should == @user
97
- end
98
-
99
- it "load_from_reset_password_token should NOT return user when token is found and expired" do
100
- create_new_user
101
- sorcery_model_property_set(:reset_password_expiration_period, 0.1)
102
- @user.deliver_reset_password_instructions!
103
- sleep 0.5
104
- User.load_from_reset_password_token(@user.reset_password_token).should == nil
105
- end
106
-
107
- it "load_from_reset_password_token should always be valid if expiration period is nil" do
108
- create_new_user
109
- sorcery_model_property_set(:reset_password_expiration_period, nil)
110
- @user.deliver_reset_password_instructions!
111
- User.load_from_reset_password_token(@user.reset_password_token).should == @user
112
- end
113
-
114
- it "load_from_reset_password_token should return nil if token is blank" do
115
- User.load_from_reset_password_token(nil).should == nil
116
- User.load_from_reset_password_token("").should == nil
117
- end
118
-
119
- it "'deliver_reset_password_instructions!' should generate a reset_password_token" do
120
- create_new_user
121
- @user.reset_password_token.should be_nil
122
- @user.deliver_reset_password_instructions!
123
- @user.reset_password_token.should_not be_nil
124
- end
125
-
126
- it "the reset_password_token should be random" do
127
- create_new_user
128
- sorcery_model_property_set(:reset_password_time_between_emails, 0)
129
- @user.deliver_reset_password_instructions!
130
- old_password_code = @user.reset_password_token
131
- @user.deliver_reset_password_instructions!
132
- @user.reset_password_token.should_not == old_password_code
133
- end
134
-
135
- it "should send an email on reset" do
136
- create_new_user
137
- old_size = ActionMailer::Base.deliveries.size
138
- @user.deliver_reset_password_instructions!
139
- ActionMailer::Base.deliveries.size.should == old_size + 1
140
- end
141
-
142
- it "when reset_password! is called, should delete reset_password_token" do
143
- create_new_user
144
- @user.deliver_reset_password_instructions!
145
- @user.reset_password_token.should_not be_nil
146
- @user.reset_password!(:password => "blabulsdf")
147
- @user.save!
148
- @user.reset_password_token.should be_nil
149
- end
150
-
151
- it "should not send an email if time between emails has not passed since last email" do
152
- create_new_user
153
- sorcery_model_property_set(:reset_password_time_between_emails, 10000)
154
- old_size = ActionMailer::Base.deliveries.size
155
- @user.deliver_reset_password_instructions!
156
- ActionMailer::Base.deliveries.size.should == old_size + 1
157
- @user.deliver_reset_password_instructions!
158
- ActionMailer::Base.deliveries.size.should == old_size + 1
159
- end
160
-
161
- it "should send an email if time between emails has passed since last email" do
162
- create_new_user
163
- sorcery_model_property_set(:reset_password_time_between_emails, 0.5)
164
- old_size = ActionMailer::Base.deliveries.size
165
- @user.deliver_reset_password_instructions!
166
- ActionMailer::Base.deliveries.size.should == old_size + 1
167
- sleep 0.5
168
- @user.deliver_reset_password_instructions!
169
- ActionMailer::Base.deliveries.size.should == old_size + 2
170
- end
171
-
172
- it "if mailer is nil on activation, throw exception!" do
173
- expect{sorcery_reload!([:reset_password])}.to raise_error(ArgumentError)
174
- end
175
-
176
- end
177
-
178
- end
@@ -1,317 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
- require File.expand_path(File.dirname(__FILE__) + '/../sorcery_mailer')
3
-
4
- describe "User with no submodules (core)" do
5
- before(:all) do
6
- sorcery_reload!
7
- end
8
-
9
- describe User, "when app has plugin loaded" do
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!)
13
- end
14
-
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
19
- end
20
- end
21
-
22
- # ----------------- PLUGIN ACTIVATION -----------------------
23
- describe TestUser, "Testing activated class self-registration" do
24
- it "should register itself as user_class if activated" do
25
- TestUser.class_eval do
26
- activate_sorcery!
27
- end
28
- ::Sorcery::Controller::Config.user_class.should == TestUser
29
- end
30
- end
31
-
32
- # ----------------- PLUGIN CONFIGURATION -----------------------
33
- describe User, "loaded plugin configuration" do
34
- after(:each) do
35
- User.sorcery_config.reset!
36
- end
37
-
38
- it "should enable configuration option 'username_attribute_name'" do
39
- sorcery_model_property_set(:username_attribute_name, :email)
40
- User.sorcery_config.username_attribute_name.should equal(:email)
41
- end
42
-
43
- it "should enable configuration option 'password_attribute_name'" do
44
- sorcery_model_property_set(:password_attribute_name, :mypassword)
45
- User.sorcery_config.password_attribute_name.should equal(:mypassword)
46
- end
47
-
48
- it "should enable configuration option 'email_attribute_name'" do
49
- sorcery_model_property_set(:email_attribute_name, :my_email)
50
- User.sorcery_config.email_attribute_name.should equal(:my_email)
51
- end
52
-
53
- it "should enable configuration option 'crypted_password_attribute_name'" do
54
- sorcery_model_property_set(:crypted_password_attribute_name, :password)
55
- User.sorcery_config.crypted_password_attribute_name.should equal(:password)
56
- end
57
-
58
- it "should enable configuration option 'salt_attribute_name'" do
59
- sorcery_model_property_set(:salt_attribute_name, :my_salt)
60
- User.sorcery_config.salt_attribute_name.should equal(:my_salt)
61
- end
62
-
63
- it "should enable configuration option 'encryption_algorithm'" do
64
- sorcery_model_property_set(:encryption_algorithm, :none)
65
- User.sorcery_config.encryption_algorithm.should equal(:none)
66
- end
67
-
68
- it "should enable configuration option 'encryption_key'" do
69
- sorcery_model_property_set(:encryption_key, 'asdadas424234242')
70
- User.sorcery_config.encryption_key.should == 'asdadas424234242'
71
- end
72
-
73
- it "should enable configuration option 'custom_encryption_provider'" do
74
- sorcery_model_property_set(:encryption_algorithm, :custom)
75
- sorcery_model_property_set(:custom_encryption_provider, Array)
76
- User.sorcery_config.custom_encryption_provider.should equal(Array)
77
- end
78
-
79
- it "should enable configuration option 'salt_join_token'" do
80
- salt_join_token = "--%%*&-"
81
- sorcery_model_property_set(:salt_join_token, salt_join_token)
82
- User.sorcery_config.salt_join_token.should equal(salt_join_token)
83
- end
84
-
85
- it "should enable configuration option 'stretches'" do
86
- stretches = 15
87
- sorcery_model_property_set(:stretches, stretches)
88
- User.sorcery_config.stretches.should equal(stretches)
89
- end
90
-
91
- end
92
-
93
- # ----------------- PLUGIN ACTIVATED -----------------------
94
- describe User, "when activated with sorcery" do
95
- before(:all) do
96
- sorcery_reload!()
97
- end
98
-
99
- before(:each) do
100
- User.delete_all
101
- end
102
-
103
- it "should respond to class method authenticate" do
104
- ActiveRecord::Base.should_not respond_to(:authenticate)
105
- User.should respond_to(:authenticate)
106
- end
107
-
108
- it "authenticate should return true if credentials are good" do
109
- create_new_user
110
- User.authenticate(@user.send(User.sorcery_config.username_attribute_name), 'secret').should be_true
111
- end
112
-
113
- it "authenticate should return false if credentials are bad" do
114
- create_new_user
115
- User.authenticate(@user.send(User.sorcery_config.username_attribute_name), 'wrong!').should be_false
116
- end
117
-
118
- it "should respond to the class method encrypt" do
119
- User.should respond_to(:encrypt)
120
- end
121
- end
122
-
123
- # ----------------- REGISTRATION -----------------------
124
- describe User, "registration" do
125
-
126
- before(:all) do
127
- sorcery_reload!()
128
- end
129
-
130
- before(:each) do
131
- User.delete_all
132
- end
133
-
134
- it "by default, encryption_provider should not be nil" do
135
- User.sorcery_config.encryption_provider.should_not be_nil
136
- end
137
-
138
- it "should encrypt password when a new user is saved" do
139
- create_new_user
140
- User.sorcery_config.encryption_provider.matches?(@user.send(User.sorcery_config.crypted_password_attribute_name),'secret',@user.salt).should be_true
141
- end
142
-
143
- it "should clear the virtual password field if the encryption process worked" do
144
- create_new_user
145
- @user.password.should be_nil
146
- end
147
-
148
- it "should not clear the virtual password field if save failed due to validity" do
149
- create_new_user
150
- User.class_eval do
151
- validates_format_of :email, :with => /^(.)+@(.)+$/, :if => Proc.new {|r| r.email}, :message => "is invalid"
152
- end
153
- @user.password = 'blupush'
154
- @user.email = 'asd'
155
- @user.save
156
- @user.password.should_not be_nil
157
- end
158
-
159
- it "should not clear the virtual password field if save failed due to exception" do
160
- create_new_user
161
- @user.password = 'blupush'
162
- @user.username = nil
163
- begin
164
- @user.save # triggers SQL exception since username field is defined not null.
165
- rescue
166
- end
167
- @user.password.should_not be_nil
168
- end
169
-
170
- it "should not encrypt the password twice when a user is updated" do
171
- create_new_user
172
- @user.email = "blup@bla.com"
173
- @user.save!
174
- User.sorcery_config.encryption_provider.matches?(@user.send(User.sorcery_config.crypted_password_attribute_name),'secret',@user.salt).should be_true
175
- end
176
-
177
- it "should replace the crypted_password in case a new password is set" do
178
- create_new_user
179
- @user.password = 'new_secret'
180
- @user.save!
181
- User.sorcery_config.encryption_provider.matches?(@user.send(User.sorcery_config.crypted_password_attribute_name),'secret',@user.salt).should be_false
182
- end
183
-
184
- end
185
-
186
- # ----------------- PASSWORD ENCRYPTION -----------------------
187
- describe User, "special encryption cases" do
188
- before(:all) do
189
- sorcery_reload!()
190
- @text = "Some Text!"
191
- end
192
-
193
- before(:each) do
194
- User.delete_all
195
- end
196
-
197
- after(:each) do
198
- User.sorcery_config.reset!
199
- end
200
-
201
- it "should work with no password encryption" do
202
- sorcery_model_property_set(:encryption_algorithm, :none)
203
- create_new_user
204
- User.authenticate(@user.send(User.sorcery_config.username_attribute_name), 'secret').should be_true
205
- end
206
-
207
- it "should work with custom password encryption" do
208
- class MyCrypto
209
- def self.encrypt(*tokens)
210
- tokens.flatten.join('').gsub(/e/,'A')
211
- end
212
-
213
- def self.matches?(crypted,*tokens)
214
- crypted = encrypt(*tokens)
215
- end
216
- end
217
- sorcery_model_property_set(:encryption_algorithm, :custom)
218
- sorcery_model_property_set(:custom_encryption_provider, MyCrypto)
219
- create_new_user
220
- User.authenticate(@user.send(User.sorcery_config.username_attribute_name), 'secret').should be_true
221
- end
222
-
223
- it "if encryption algo is aes256, it should set key to crypto provider" do
224
- sorcery_model_property_set(:encryption_algorithm, :aes256)
225
- sorcery_model_property_set(:encryption_key, nil)
226
- expect{User.encrypt(@text)}.to raise_error(ArgumentError)
227
- sorcery_model_property_set(:encryption_key, "asd234dfs423fddsmndsflktsdf32343")
228
- expect{User.encrypt(@text)}.to_not raise_error(ArgumentError)
229
- end
230
-
231
- it "if encryption algo is aes256, it should set key to crypto provider, even if attributes are set in reverse" do
232
- sorcery_model_property_set(:encryption_key, nil)
233
- sorcery_model_property_set(:encryption_algorithm, :none)
234
- sorcery_model_property_set(:encryption_key, "asd234dfs423fddsmndsflktsdf32343")
235
- sorcery_model_property_set(:encryption_algorithm, :aes256)
236
- expect{User.encrypt(@text)}.to_not raise_error(ArgumentError)
237
- end
238
-
239
- it "if encryption algo is md5 it should work" do
240
- sorcery_model_property_set(:encryption_algorithm, :md5)
241
- User.encrypt(@text).should == Sorcery::CryptoProviders::MD5.encrypt(@text)
242
- end
243
-
244
- it "if encryption algo is sha1 it should work" do
245
- sorcery_model_property_set(:encryption_algorithm, :sha1)
246
- User.encrypt(@text).should == Sorcery::CryptoProviders::SHA1.encrypt(@text)
247
- end
248
-
249
- it "if encryption algo is sha256 it should work" do
250
- sorcery_model_property_set(:encryption_algorithm, :sha256)
251
- User.encrypt(@text).should == Sorcery::CryptoProviders::SHA256.encrypt(@text)
252
- end
253
-
254
- it "if encryption algo is sha512 it should work" do
255
- sorcery_model_property_set(:encryption_algorithm, :sha512)
256
- User.encrypt(@text).should == Sorcery::CryptoProviders::SHA512.encrypt(@text)
257
- end
258
-
259
- it "salt should be random for each user and saved in db" do
260
- sorcery_model_property_set(:salt_attribute_name, :salt)
261
- create_new_user
262
- @user.salt.should_not be_nil
263
- end
264
-
265
- it "if salt is set should use it to encrypt" do
266
- sorcery_model_property_set(:salt_attribute_name, :salt)
267
- sorcery_model_property_set(:encryption_algorithm, :sha512)
268
- create_new_user
269
- @user.crypted_password.should_not == Sorcery::CryptoProviders::SHA512.encrypt('secret')
270
- @user.crypted_password.should == Sorcery::CryptoProviders::SHA512.encrypt('secret',@user.salt)
271
- end
272
-
273
- it "if salt_join_token is set should use it to encrypt" do
274
- sorcery_model_property_set(:salt_attribute_name, :salt)
275
- sorcery_model_property_set(:salt_join_token, "-@=>")
276
- sorcery_model_property_set(:encryption_algorithm, :sha512)
277
- create_new_user
278
- @user.crypted_password.should_not == Sorcery::CryptoProviders::SHA512.encrypt('secret')
279
- Sorcery::CryptoProviders::SHA512.join_token = ""
280
- @user.crypted_password.should_not == Sorcery::CryptoProviders::SHA512.encrypt('secret',@user.salt)
281
- Sorcery::CryptoProviders::SHA512.join_token = User.sorcery_config.salt_join_token
282
- @user.crypted_password.should == Sorcery::CryptoProviders::SHA512.encrypt('secret',@user.salt)
283
- end
284
-
285
- end
286
-
287
- describe User, "external users" do
288
- before(:all) do
289
- ActiveRecord::Migrator.migrate("#{APP_ROOT}/db/migrate/external")
290
- sorcery_reload!()
291
- end
292
-
293
- after(:all) do
294
- ActiveRecord::Migrator.rollback("#{APP_ROOT}/db/migrate/external")
295
- end
296
-
297
- before(:each) do
298
- User.delete_all
299
- end
300
-
301
- it "should respond to 'external?'" do
302
- create_new_user
303
- @user.should respond_to(:external?)
304
- end
305
-
306
- it "external? should be false for regular users" do
307
- create_new_user
308
- @user.external?.should be_false
309
- end
310
-
311
- it "external? should be true for external users" do
312
- create_new_external_user(:twitter)
313
- @user.external?.should be_true
314
- end
315
- end
316
-
317
- end