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,44 +0,0 @@
1
- # module Sorcery
2
- # module Controller
3
- # module Submodules
4
- # # This module allows you to authenticate to the site using a mail server.
5
- # # Let's say your organization is called blup, and everyone has someklutz@blup.com,
6
- # # Instead of registering a new username and password for an internal web application,
7
- # # why not simply reuse your email credentials?
8
- # # Of course this means that if the mail server is down, nobody can authenticate to your app.
9
- # # I might add a fallback for that in the future.
10
- # module Email
11
- # def self.included(base)
12
- # base.send(:include, InstanceMethods)
13
- # Config.module_eval do
14
- # class << self
15
- # attr_reader :email_protocols # email protocols like pop3, IMAP etc.
16
- #
17
- # def merge_mail_defaults!
18
- # @defaults.merge!(:@email_protocols => [])
19
- # end
20
- #
21
- # def email_protocols=(protocols)
22
- # protocols.each do |protocol|
23
- # include Protocols.const_get(protocol.to_s.split("_").map {|p| p.capitalize}.join(""))
24
- # end
25
- # end
26
- # end
27
- # merge_mail_defaults!
28
- # end
29
- # end
30
- #
31
- # module InstanceMethods
32
- # protected
33
- #
34
- # # sends user to authenticate at the provider's website.
35
- # # after authentication the user is redirected to the callback defined in the provider config
36
- # def login_at(protocol)
37
- #
38
- # end
39
- #
40
- # end
41
- # end
42
- # end
43
- # end
44
- # end
@@ -1,95 +0,0 @@
1
- module Sorcery
2
- module Controller
3
- module Submodules
4
- # This submodule helps you login users from OAuth providers such as Twitter.
5
- # This is the controller part which handles the http requests and tokens passed between the app and the provider.
6
- # For more configuration options see Sorcery::Model::Oauth.
7
- module Oauth
8
- def self.included(base)
9
- base.send(:include, InstanceMethods)
10
- Config.module_eval do
11
- class << self
12
- attr_reader :oauth_providers # oauth providers like twitter.
13
-
14
- def merge_oauth_defaults!
15
- @defaults.merge!(:@oauth_providers => [])
16
- end
17
-
18
- def oauth_providers=(providers)
19
- providers.each do |provider|
20
- include Providers.const_get(provider.to_s.split("_").map {|p| p.capitalize}.join(""))
21
- end
22
- end
23
- end
24
- merge_oauth_defaults!
25
- end
26
- end
27
-
28
- module InstanceMethods
29
- protected
30
-
31
- # sends user to authenticate at the provider's website.
32
- # after authentication the user is redirected to the callback defined in the provider config
33
- def auth_at_provider(provider)
34
- @provider = Config.send(provider)
35
- args = {}
36
- if @provider.respond_to?(:get_request_token)
37
- req_token = @provider.get_request_token
38
- session[:request_token] = req_token.token
39
- session[:request_token_secret] = req_token.secret
40
- args.merge!({:request_token => req_token.token, :request_token_secret => req_token.secret})
41
- end
42
- redirect_to @provider.authorize_url(args)
43
- end
44
-
45
- # tries to login the user from access token
46
- def login_from_access_token(provider)
47
- @provider = Config.send(provider)
48
- args = {}
49
- args.merge!({:oauth_verifier => params[:oauth_verifier], :request_token => session[:request_token], :request_token_secret => session[:request_token_secret]}) if @provider.respond_to?(:get_request_token)
50
- args.merge!({:code => params[:code]}) if params[:code]
51
- @access_token = @provider.get_access_token(args)
52
- @user_hash = @provider.get_user_hash(@access_token)
53
- if user = Config.user_class.load_from_provider(provider,@user_hash[:uid])
54
- reset_session
55
- login_user(user)
56
- user
57
- end
58
- end
59
-
60
- def get_user_hash(provider)
61
- @provider = Config.send(provider)
62
- @provider.get_user_hash(@access_token)
63
- end
64
-
65
- # this method automatically creates a new user from the data in the external user hash.
66
- # The mappings from user hash fields to user db fields are set at controller config.
67
- # If the hash field you would like to map is nested, use slashes. For example, Given a hash like:
68
- #
69
- # "user" => {"name"=>"moishe"}
70
- #
71
- # You will set the mapping:
72
- #
73
- # {:username => "user/name"}
74
- #
75
- # And this will cause 'moishe' to be set as the value of :username field.
76
- def create_from_provider!(provider)
77
- provider = provider.to_sym
78
- @provider = Config.send(provider)
79
- @user_hash = get_user_hash(provider)
80
- config = Config.user_class.sorcery_config
81
- attrs = {}
82
- @provider.user_info_mapping.each do |k,v|
83
- (varr = v.split("/")).size > 1 ? attrs.merge!(k => varr.inject(@user_hash[:user_info]) {|hsh,v| hsh[v] }) : attrs.merge!(k => @user_hash[:user_info][v])
84
- end
85
- Config.user_class.transaction do
86
- @user = Config.user_class.create!(attrs)
87
- Config.user_class.sorcery_config.authentications_class.create!({config.authentications_user_id_attribute_name => @user.id, config.provider_attribute_name => provider, config.provider_uid_attribute_name => @user_hash[:uid]})
88
- end
89
- @user
90
- end
91
- end
92
- end
93
- end
94
- end
95
- end
@@ -1 +0,0 @@
1
- --colour
@@ -1,27 +0,0 @@
1
- # SQLite version 3.x
2
- # gem install sqlite3-ruby (not necessary on OS X Leopard)
3
- development:
4
- adapter: sqlite3
5
- database: db/development.sqlite3
6
- pool: 5
7
- timeout: 5000
8
-
9
- # Warning: The database defined as "test" will be erased and
10
- # re-generated from your development database when you run "rake".
11
- # Do not set this db to the same as development or production.
12
- test:
13
- adapter: sqlite3
14
- database: db/test.sqlite3
15
- pool: 5
16
- timeout: 5000
17
-
18
- production:
19
- adapter: sqlite3
20
- database: db/production.sqlite3
21
- pool: 5
22
- timeout: 5000
23
-
24
- in_memory:
25
- adapter: sqlite3
26
- database: ":memory:"
27
- verbosity: quiet
@@ -1,62 +0,0 @@
1
- $: << File.join(File.dirname(__FILE__), '..', '..', 'lib' )
2
-
3
- require 'simplecov'
4
- SimpleCov.root File.join(File.dirname(__FILE__), "..", "..", "app_root" )
5
- SimpleCov.start do
6
- add_filter "/config/"
7
-
8
- add_group 'Controllers', 'app/controllers'
9
- add_group 'Models', 'app/models'
10
- add_group 'Helpers', 'app/helpers'
11
- add_group 'Libraries', 'lib'
12
- add_group 'Plugins', 'vendor/plugins'
13
- add_group 'Migrations', 'db/migrate'
14
- end
15
-
16
- require 'spork'
17
-
18
- Spork.prefork do
19
- # Set the default environment to sqlite3's in_memory database
20
- ENV['RAILS_ENV'] ||= 'in_memory'
21
- ENV['RAILS_ROOT'] = 'app_root'
22
-
23
- # Load the Rails environment and testing framework
24
- require "#{File.dirname(__FILE__)}/../config/environment"
25
- #require "#{File.dirname(__FILE__)}/../../init" # for plugins
26
- require 'rspec/rails'
27
-
28
- RSpec.configure do |config|
29
- config.use_transactional_fixtures = true
30
- config.use_instantiated_fixtures = false
31
- config.include RSpec::Rails::ControllerExampleGroup, :example_group => { :file_path => /controller(.)*_spec.rb$/ }
32
-
33
- config.before(:suite) do
34
- ActiveRecord::Migrator.migrate("#{Rails.root}/db/migrate/core")
35
- end
36
-
37
- config.after(:suite) do
38
- ActiveRecord::Migrator.rollback("#{Rails.root}/db/migrate/core")
39
- end
40
- end
41
-
42
- #----------------------------------------------------------------
43
- # needed when running individual specs
44
- require File.join(File.dirname(__FILE__), '..','app','models','user')
45
- require File.join(File.dirname(__FILE__), '..','app','models','authentication')
46
-
47
- class TestUser < ActiveRecord::Base
48
- activate_sorcery!
49
- end
50
-
51
- class TestMailer < ActionMailer::Base
52
-
53
- end
54
-
55
- include ::Sorcery::TestHelpers
56
- include ::Sorcery::TestHelpers::Rails
57
-
58
- end
59
-
60
- Spork.each_run do
61
- # This code will be run each time you run your specs.
62
- end
@@ -1,188 +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 activation submodule" do
5
- before(:all) do
6
- ActiveRecord::Migrator.migrate("#{APP_ROOT}/db/migrate/activation")
7
- end
8
-
9
- after(:all) do
10
- ActiveRecord::Migrator.rollback("#{APP_ROOT}/db/migrate/activation")
11
- end
12
-
13
- # ----------------- PLUGIN CONFIGURATION -----------------------
14
- describe User, "loaded plugin configuration" do
15
- before(:all) do
16
- sorcery_reload!([:user_activation], :user_activation_mailer => ::SorceryMailer)
17
- end
18
-
19
- after(:each) do
20
- User.sorcery_config.reset!
21
- sorcery_reload!([:user_activation], :user_activation_mailer => ::SorceryMailer)
22
- end
23
-
24
- it "should enable configuration option 'activation_state_attribute_name'" do
25
- sorcery_model_property_set(:activation_state_attribute_name, :status)
26
- User.sorcery_config.activation_state_attribute_name.should equal(:status)
27
- end
28
-
29
- it "should enable configuration option 'activation_token_attribute_name'" do
30
- sorcery_model_property_set(:activation_token_attribute_name, :code)
31
- User.sorcery_config.activation_token_attribute_name.should equal(:code)
32
- end
33
-
34
- it "should enable configuration option 'user_activation_mailer'" do
35
- sorcery_model_property_set(:user_activation_mailer, TestMailer)
36
- User.sorcery_config.user_activation_mailer.should equal(TestMailer)
37
- end
38
-
39
- it "should enable configuration option 'activation_needed_email_method_name'" do
40
- sorcery_model_property_set(:activation_needed_email_method_name, :my_activation_email)
41
- User.sorcery_config.activation_needed_email_method_name.should equal(:my_activation_email)
42
- end
43
-
44
- it "should enable configuration option 'activation_success_email_method_name'" do
45
- sorcery_model_property_set(:activation_success_email_method_name, :my_activation_email)
46
- User.sorcery_config.activation_success_email_method_name.should equal(:my_activation_email)
47
- end
48
-
49
- it "if mailer is nil on activation, throw exception!" do
50
- expect{sorcery_reload!([:user_activation])}.to raise_error(ArgumentError)
51
- end
52
- end
53
-
54
- # ----------------- ACTIVATION PROCESS -----------------------
55
- describe User, "activation process" do
56
- before(:all) do
57
- sorcery_reload!([:user_activation], :user_activation_mailer => ::SorceryMailer)
58
- end
59
-
60
- it "should generate an activation code on registration" do
61
- create_new_user
62
- @user.activation_token.should_not be_nil
63
- end
64
-
65
- it "should initialize user state to 'pending'" do
66
- create_new_user
67
- @user.activation_state.should == "pending"
68
- end
69
-
70
- it "should respond to 'activate!'" do
71
- create_new_user
72
- @user.should respond_to(:activate!)
73
- end
74
-
75
- it "should clear activation code and change state to 'active' on activation" do
76
- create_new_user
77
- activation_token = @user.activation_token
78
- @user.activate!
79
- @user2 = User.find(@user.id) # go to db to make sure it was saved and not just in memory
80
- @user2.activation_token.should be_nil
81
- @user2.activation_state.should == "active"
82
- User.find_by_activation_token(activation_token).should be_nil
83
- end
84
-
85
- it "should send the user an activation email" do
86
- old_size = ActionMailer::Base.deliveries.size
87
- create_new_user
88
- ActionMailer::Base.deliveries.size.should == old_size + 1
89
- end
90
-
91
- it "subsequent saves do not send activation email" do
92
- create_new_user
93
- old_size = ActionMailer::Base.deliveries.size
94
- @user.username = "Shauli"
95
- @user.save!
96
- ActionMailer::Base.deliveries.size.should == old_size
97
- end
98
-
99
- it "should send the user an activation success email on successful activation" do
100
- create_new_user
101
- old_size = ActionMailer::Base.deliveries.size
102
- @user.activate!
103
- ActionMailer::Base.deliveries.size.should == old_size + 1
104
- end
105
-
106
- it "subsequent saves do not send activation success email" do
107
- create_new_user
108
- @user.activate!
109
- old_size = ActionMailer::Base.deliveries.size
110
- @user.username = "Shauli"
111
- @user.save!
112
- ActionMailer::Base.deliveries.size.should == old_size
113
- end
114
-
115
- it "activation needed email is optional" do
116
- sorcery_model_property_set(:activation_needed_email_method_name, nil)
117
- old_size = ActionMailer::Base.deliveries.size
118
- create_new_user
119
- ActionMailer::Base.deliveries.size.should == old_size
120
- end
121
-
122
- it "activation success email is optional" do
123
- sorcery_model_property_set(:activation_success_email_method_name, nil)
124
- create_new_user
125
- old_size = ActionMailer::Base.deliveries.size
126
- @user.activate!
127
- ActionMailer::Base.deliveries.size.should == old_size
128
- end
129
- end
130
-
131
- describe User, "prevent non-active login feature" do
132
- before(:all) do
133
- sorcery_reload!([:user_activation], :user_activation_mailer => ::SorceryMailer)
134
- end
135
-
136
- it "should not allow a non-active user to authenticate" do
137
- create_new_user
138
- User.authenticate(@user.username,'secret').should be_false
139
- end
140
-
141
- it "should allow a non-active user to authenticate if configured so" do
142
- create_new_user
143
- sorcery_model_property_set(:prevent_non_active_users_to_login, false)
144
- User.authenticate(@user.username,'secret').should be_true
145
- end
146
- end
147
-
148
- describe User, "load_from_activation_token" do
149
- before(:all) do
150
- sorcery_reload!([:user_activation], :user_activation_mailer => ::SorceryMailer)
151
- end
152
-
153
- it "load_from_activation_token should return user when token is found" do
154
- create_new_user
155
- User.load_from_activation_token(@user.activation_token).should == @user
156
- end
157
-
158
- it "load_from_activation_token should NOT return user when token is NOT found" do
159
- create_new_user
160
- User.load_from_activation_token("a").should == nil
161
- end
162
-
163
- it "load_from_activation_token should return user when token is found and not expired" do
164
- sorcery_model_property_set(:activation_token_expiration_period, 500)
165
- create_new_user
166
- User.load_from_activation_token(@user.activation_token).should == @user
167
- end
168
-
169
- it "load_from_activation_token should NOT return user when token is found and expired" do
170
- sorcery_model_property_set(:activation_token_expiration_period, 0.1)
171
- create_new_user
172
- sleep 0.5
173
- User.load_from_activation_token(@user.activation_token).should == nil
174
- end
175
-
176
- it "load_from_activation_token should return nil if token is blank" do
177
- User.load_from_activation_token(nil).should == nil
178
- User.load_from_activation_token("").should == nil
179
- end
180
-
181
- it "load_from_activation_token should always be valid if expiration period is nil" do
182
- sorcery_model_property_set(:activation_token_expiration_period, nil)
183
- create_new_user
184
- User.load_from_activation_token(@user.activation_token).should == @user
185
- end
186
- end
187
-
188
- end
@@ -1,36 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
-
3
- describe "User with activity logging submodule" do
4
- before(:all) do
5
- end
6
-
7
- after(:all) do
8
- end
9
-
10
- # ----------------- PLUGIN CONFIGURATION -----------------------
11
- describe User, "loaded plugin configuration" do
12
- before(:all) do
13
- sorcery_reload!([:activity_logging])
14
- end
15
-
16
- after(:each) do
17
- User.sorcery_config.reset!
18
- end
19
-
20
- it "should allow configuration option 'last_login_at_attribute_name'" do
21
- sorcery_model_property_set(:last_login_at_attribute_name, :login_time)
22
- User.sorcery_config.last_login_at_attribute_name.should equal(:login_time)
23
- end
24
-
25
- it "should allow configuration option 'last_logout_at_attribute_name'" do
26
- sorcery_model_property_set(:last_logout_at_attribute_name, :logout_time)
27
- User.sorcery_config.last_logout_at_attribute_name.should equal(:logout_time)
28
- end
29
-
30
- it "should allow configuration option 'last_activity_at_attribute_name'" do
31
- sorcery_model_property_set(:last_activity_at_attribute_name, :activity_time)
32
- User.sorcery_config.last_activity_at_attribute_name.should equal(:activity_time)
33
- end
34
- end
35
-
36
- end