authlogic 2.0.0 → 2.0.1

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

Potentially problematic release.


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

data/CHANGELOG.rdoc CHANGED
@@ -1,4 +1,11 @@
1
- == 2.0.0
1
+ == 2.0.1
2
+
3
+ * Validate length of password.
4
+ * Dont save sessions with a ! during session maintenance.
5
+ * Add self_and_descendants_from_active_record for Rails 2.3
6
+ * Abort acts_as_authentic if there is no DB connection or table.
7
+
8
+ == 2.0.0 released 2009-3-23
2
9
 
3
10
  * Refactored nearly all code and tests, especially acts_as_authentic. Got rid of the meta programming and rewrote to use modules and hooks. Also moved all configuration into their related modules.
4
11
  * Set up a strong API with hooks to allow you to modify behavior and most importantly, easily create "add on" modules or alternate authentication methods, etc.
@@ -10,7 +17,7 @@
10
17
  * Added MD5 crypto provider for legacy systems.
11
18
  * Make password salt field optional for legacy systems.
12
19
 
13
- == 1.4.4
20
+ == 1.4.4 released 2009-3-2
14
21
 
15
22
  * Moved session maintenance to a before_save, to save on queries executed and to skip an unexpected / additional save on the user object.
16
23
  * Extracted random string generation into its own class and leverages SecureRandom if it is available
data/README.rdoc CHANGED
@@ -54,9 +54,9 @@ These modules are for the acts_as_authentic method you call in your model. It co
54
54
  * Authlogic::ActsAsAuthentic::PerishableToken - Handles maintaining the perishable token field, also provides a class level method for finding record using the token.
55
55
  * Authlogic::ActsAsAuthentic::PersistenceToken - Handles maintaining the persistence token. This is the token stored in cookies and sessions to persist the users session.
56
56
  * Authlogic::ActsAsAuthentic::RestfulAuthentication - Provides configuration options to easily migrate from the restful_authentication plugin.
57
- * Authlogic::ActsAsAuthentic::Scope - Allows you to scope validations, etc. Just like the :scope option for validates_uniqueness_of
58
57
  * Authlogic::ActsAsAuthentic::SessionMaintenance - Handles automatically logging the user in. EX: a new user registers, automatically log them in.
59
58
  * Authlogic::ActsAsAuthentic::SingleAccessToken - Handles maintaining the single access token.
59
+ * Authlogic::ActsAsAuthentic::ValidationsScope - Allows you to scope validations, etc. Just like the :scope option for validates_uniqueness_of
60
60
 
61
61
  === Authlogic::Session sub modules
62
62
 
@@ -222,7 +222,7 @@ Here are some common next steps. They might or might not apply to you. For a com
222
222
  8. Need to internationalize your app? See Authlogic::I18n
223
223
  9. Need help testing? See the Authlogic::Testing
224
224
 
225
- == Interesting in how it works?
225
+ == Interested in how it works?
226
226
 
227
227
  Interested in how all of this all works? Basically a before filter is automatically set in your controller which lets Authlogic know about the current controller object. This "activates" Authlogic and allows Authlogic to set sessions, cookies, login via basic http auth, etc. If you are using your framework in a multiple thread environment, don't worry. I kept that in mind and made this thread safe.
228
228
 
data/Rakefile CHANGED
@@ -14,6 +14,7 @@ Hoe.new("Authlogic", Authlogic::Version::STRING) do |p|
14
14
  p.history_file = "CHANGELOG.rdoc"
15
15
  p.readme_file = "README.rdoc"
16
16
  p.extra_rdoc_files = ["CHANGELOG.rdoc", "README.rdoc"]
17
+ p.remote_rdoc_dir = ''
17
18
  p.test_globs = ["test/*/test_*.rb", "test/*/*_test.rb"]
18
19
  p.extra_deps = %w(activesupport)
19
20
  p.post_install_message = "Version 2.0 introduces some changes that break backwards compatibility. The big change is how acts_as_authentic accepts configuration options. Instead of a hash, it now accepts a block: acts_as_authentic { |c| c.my_config_option = my_value}. See the docs for more details."
@@ -24,6 +24,13 @@ module Authlogic
24
24
  #
25
25
  # See the various sub modules for the configuration they provide.
26
26
  def acts_as_authentic(&block)
27
+ # Stop all configuration if the DB is not set up
28
+ begin
29
+ column_names
30
+ rescue Exception
31
+ return
32
+ end
33
+
27
34
  yield self if block_given?
28
35
  acts_as_authentic_modules.each { |mod| include mod }
29
36
  end
@@ -40,6 +40,15 @@ module Authlogic
40
40
  end
41
41
  alias_method :validate_password_field=, :validate_password_field
42
42
 
43
+ # A hash of options for the validates_length_of call for the password field. Allows you to change this however you want.
44
+ #
45
+ # * <tt>Default:</tt> {:minimum => 4, :if => :require_password?}
46
+ # * <tt>Accepts:</tt> Hash of options accepted by validates_length_of
47
+ def validates_length_of_password_field_options(value = nil)
48
+ config(:validates_length_of_password_field_options, value, {:minimum => 4, :if => :require_password?})
49
+ end
50
+ alias_method :validates_length_of_password_field_options=, :validates_length_of_password_field_options
51
+
43
52
  # A hash of options for the validates_confirmation_of call for the password field. Allows you to change this however you want.
44
53
  #
45
54
  # * <tt>Default:</tt> {:minimum => 4, :if => "#{password_salt_field}_changed?".to_sym}
@@ -51,10 +60,10 @@ module Authlogic
51
60
 
52
61
  # A hash of options for the validates_length_of call for the password_confirmation field. Allows you to change this however you want.
53
62
  #
54
- # * <tt>Default:</tt> {:minimum => 4, :if => :require_password_confirmation?}
63
+ # * <tt>Default:</tt> {:minimum => 4, :if => :require_password_?}
55
64
  # * <tt>Accepts:</tt> Hash of options accepted by validates_length_of
56
65
  def validates_length_of_password_confirmation_field_options(value = nil)
57
- config(:validates_length_of_password_confirmation_field_options, value, {:minimum => 4, :if => :require_password_confirmation?})
66
+ config(:validates_length_of_password_confirmation_field_options, value, {:minimum => 4, :if => :require_password?})
58
67
  end
59
68
  alias_method :validates_length_of_password_confirmation_field_options=, :validates_length_of_password_confirmation_field_options
60
69
 
@@ -111,6 +120,7 @@ module Authlogic
111
120
  def self.included(klass)
112
121
  klass.class_eval do
113
122
  if validate_password_field
123
+ validates_length_of :password, validates_length_of_password_field_options
114
124
  validates_confirmation_of :password, validates_confirmation_of_password_field_options
115
125
  validates_length_of :password_confirmation, validates_length_of_password_confirmation_field_options
116
126
  end
@@ -190,7 +200,7 @@ module Authlogic
190
200
  end
191
201
  end
192
202
 
193
- def require_password_confirmation?
203
+ def require_password?
194
204
  new_record? || (password_salt_field && send("#{password_salt_field}_changed?")) || send(crypted_password_field).blank?
195
205
  end
196
206
 
@@ -98,7 +98,7 @@ module Authlogic
98
98
  # We only want to automatically login into the first session, since this is the main session. The other sessions are sessions
99
99
  # that need to be created after logging into the main session.
100
100
  session_id = session_ids.first
101
- session_class.create!(*[self, self, session_id].compact)
101
+ session_class.create(*[self, self, session_id].compact)
102
102
 
103
103
  return true
104
104
  end
@@ -17,7 +17,7 @@ module Authlogic
17
17
  # company:
18
18
  #
19
19
  # acts_as_authentic do |c|
20
- # c.validation_scope = :company_id
20
+ # c.validations_scope = :company_id
21
21
  # end
22
22
  #
23
23
  # * <tt>Default:</tt> nil
@@ -19,9 +19,15 @@ module Authlogic
19
19
  klass.human_name(*args)
20
20
  end
21
21
 
22
+ # For rails < 2.3, mispelled
22
23
  def self_and_descendents_from_active_record
23
24
  [self]
24
25
  end
26
+
27
+ # For Rails >2.3, fix mispelling
28
+ def self_and_descendants_from_active_record
29
+ [self]
30
+ end
25
31
  end
26
32
 
27
33
  module InstanceMethods
@@ -44,7 +44,7 @@ module Authlogic # :nodoc:
44
44
 
45
45
  MAJOR = 2
46
46
  MINOR = 0
47
- TINY = 0
47
+ TINY = 1
48
48
 
49
49
  # The current version as a Version instance
50
50
  CURRENT = new(MAJOR, MINOR, TINY)
@@ -32,6 +32,17 @@ module ActsAsAuthenticTest
32
32
  assert User.validate_password_field
33
33
  end
34
34
 
35
+ def test_validates_length_of_password_field_options_config
36
+ default = {:minimum => 4, :if => :require_password?}
37
+ assert_equal default, User.validates_length_of_password_field_options
38
+ assert_equal default, Employee.validates_length_of_password_field_options
39
+
40
+ User.validates_length_of_password_field_options = {:yes => "no"}
41
+ assert_equal({:yes => "no"}, User.validates_length_of_password_field_options)
42
+ User.validates_length_of_password_field_options default
43
+ assert_equal default, User.validates_length_of_password_field_options
44
+ end
45
+
35
46
  def test_validates_confirmation_of_password_field_options_config
36
47
  default = {:minimum => 4, :if => "#{User.password_salt_field}_changed?".to_sym}
37
48
  assert_equal default, User.validates_confirmation_of_password_field_options
@@ -44,7 +55,7 @@ module ActsAsAuthenticTest
44
55
  end
45
56
 
46
57
  def test_validates_length_of_password_confirmation_field_options_config
47
- default = {:minimum => 4, :if => :require_password_confirmation?}
58
+ default = {:minimum => 4, :if => :require_password?}
48
59
  assert_equal default, User.validates_length_of_password_confirmation_field_options
49
60
  assert_equal default, Employee.validates_length_of_password_confirmation_field_options
50
61
 
@@ -107,6 +118,17 @@ module ActsAsAuthenticTest
107
118
  User.transition_from_crypto_providers = []
108
119
  end
109
120
 
121
+ def test_validates_length_of_password
122
+ u = User.new
123
+ u.password_confirmation = "test2"
124
+ assert !u.valid?
125
+ assert u.errors.on(:password)
126
+
127
+ u.password = "test"
128
+ assert !u.valid?
129
+ assert !u.errors.on(:password_confirmation)
130
+ end
131
+
110
132
  def test_validates_confirmation_of_password
111
133
  u = User.new
112
134
  u.password = "test"
@@ -6,6 +6,14 @@ module ActsAsAuthenticTest
6
6
  assert User.create(:login => "awesome", :password => "saweet", :password_confirmation => "saweet", :email => "awesome@awesome.com")
7
7
  assert UserSession.find
8
8
  end
9
+
10
+ def test_updating_session_with_failed_magic_state
11
+ ben = users(:ben)
12
+ ben.confirmed = false
13
+ ben.password = "newpass"
14
+ ben.password_confirmation = "newpass"
15
+ assert ben.save
16
+ end
9
17
 
10
18
  def test_update_session_after_password_modify
11
19
  ben = users(:ben)
data/test/test_helper.rb CHANGED
@@ -82,14 +82,14 @@ require File.dirname(__FILE__) + '/libs/user'
82
82
  require File.dirname(__FILE__) + '/libs/user_session'
83
83
  require File.dirname(__FILE__) + '/libs/company'
84
84
 
85
-
86
85
  Authlogic::CryptoProviders::AES256.key = "myafdsfddddddddddddddddddddddddddddddddddddddddddddddd"
87
86
 
88
87
  class ActiveSupport::TestCase
88
+ include ActiveRecord::TestFixtures
89
89
  self.fixture_path = File.dirname(__FILE__) + "/fixtures"
90
- self.use_transactional_fixtures = true
90
+ self.use_transactional_fixtures = false
91
91
  self.use_instantiated_fixtures = false
92
- self.pre_loaded_fixtures = true
92
+ self.pre_loaded_fixtures = false
93
93
  fixtures :all
94
94
  setup :activate_authlogic
95
95
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: authlogic
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Johnson of Binary Logic