Empact-authlogic 3.0.3 → 3.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -4,13 +4,13 @@
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
- s.name = %q{Empact-authlogic}
8
- s.version = "3.0.3"
7
+ s.name = "Empact-authlogic"
8
+ s.version = "3.1.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = [%q{Ben Johnson of Binary Logic}, %q{Ben Woosley}]
12
- s.date = %q{2011-08-14}
13
- s.email = %q{bjohnson@binarylogic.com}
11
+ s.authors = ["Ben Johnson of Binary Logic", "Ben Woosley"]
12
+ s.date = "2012-04-18"
13
+ s.email = "bjohnson@binarylogic.com"
14
14
  s.extra_rdoc_files = [
15
15
  "LICENSE",
16
16
  "README.rdoc"
@@ -145,76 +145,21 @@ Gem::Specification.new do |s|
145
145
  "test/session_test/validation_test.rb",
146
146
  "test/test_helper.rb"
147
147
  ]
148
- s.homepage = %q{http://github.com/binarylogic/authlogic}
149
- s.require_paths = [%q{lib}]
150
- s.rubygems_version = %q{1.8.5}
151
- s.summary = %q{A clean, simple, and unobtrusive ruby authentication solution.}
152
- s.test_files = [
153
- "test/acts_as_authentic_test/base_test.rb",
154
- "test/acts_as_authentic_test/email_test.rb",
155
- "test/acts_as_authentic_test/logged_in_status_test.rb",
156
- "test/acts_as_authentic_test/login_test.rb",
157
- "test/acts_as_authentic_test/magic_columns_test.rb",
158
- "test/acts_as_authentic_test/password_test.rb",
159
- "test/acts_as_authentic_test/perishable_token_test.rb",
160
- "test/acts_as_authentic_test/persistence_token_test.rb",
161
- "test/acts_as_authentic_test/restful_authentication_test.rb",
162
- "test/acts_as_authentic_test/session_maintenance_test.rb",
163
- "test/acts_as_authentic_test/single_access_test.rb",
164
- "test/authenticates_many_test.rb",
165
- "test/crypto_provider_test/aes256_test.rb",
166
- "test/crypto_provider_test/bcrypt_test.rb",
167
- "test/crypto_provider_test/sha1_test.rb",
168
- "test/crypto_provider_test/sha256_test.rb",
169
- "test/crypto_provider_test/sha512_test.rb",
170
- "test/i18n_test.rb",
171
- "test/libs/affiliate.rb",
172
- "test/libs/company.rb",
173
- "test/libs/employee.rb",
174
- "test/libs/employee_session.rb",
175
- "test/libs/ldaper.rb",
176
- "test/libs/ordered_hash.rb",
177
- "test/libs/project.rb",
178
- "test/libs/user.rb",
179
- "test/libs/user_session.rb",
180
- "test/random_test.rb",
181
- "test/session_test/activation_test.rb",
182
- "test/session_test/active_record_trickery_test.rb",
183
- "test/session_test/brute_force_protection_test.rb",
184
- "test/session_test/callbacks_test.rb",
185
- "test/session_test/cookies_test.rb",
186
- "test/session_test/credentials_test.rb",
187
- "test/session_test/existence_test.rb",
188
- "test/session_test/http_auth_test.rb",
189
- "test/session_test/id_test.rb",
190
- "test/session_test/klass_test.rb",
191
- "test/session_test/magic_columns_test.rb",
192
- "test/session_test/magic_states_test.rb",
193
- "test/session_test/params_test.rb",
194
- "test/session_test/password_test.rb",
195
- "test/session_test/perishability_test.rb",
196
- "test/session_test/persistence_test.rb",
197
- "test/session_test/scopes_test.rb",
198
- "test/session_test/session_test.rb",
199
- "test/session_test/timeout_test.rb",
200
- "test/session_test/unauthorized_record_test.rb",
201
- "test/session_test/validation_test.rb",
202
- "test/test_helper.rb"
203
- ]
148
+ s.homepage = "http://github.com/binarylogic/authlogic"
149
+ s.require_paths = ["lib"]
150
+ s.rubygems_version = "1.8.11"
151
+ s.summary = "A clean, simple, and unobtrusive ruby authentication solution."
204
152
 
205
153
  if s.respond_to? :specification_version then
206
154
  s.specification_version = 3
207
155
 
208
156
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
209
157
  s.add_runtime_dependency(%q<activerecord>, [">= 3.0.7"])
210
- s.add_runtime_dependency(%q<activerecord>, [">= 3.0.7"])
211
158
  else
212
159
  s.add_dependency(%q<activerecord>, [">= 3.0.7"])
213
- s.add_dependency(%q<activerecord>, [">= 3.0.7"])
214
160
  end
215
161
  else
216
162
  s.add_dependency(%q<activerecord>, [">= 3.0.7"])
217
- s.add_dependency(%q<activerecord>, [">= 3.0.7"])
218
163
  end
219
164
  end
220
165
 
data/Gemfile CHANGED
@@ -5,6 +5,7 @@ gem 'activerecord', '>= 3.0.7'
5
5
  group :test do
6
6
  gem 'bcrypt-ruby'
7
7
  gem 'jeweler'
8
- gem 'ruby-debug19'
8
+ gem 'rake'
9
+ gem 'debugger', require: false
9
10
  gem 'sqlite3'
10
11
  end
@@ -1,42 +1,38 @@
1
1
  GEM
2
2
  remote: http://rubygems.org/
3
3
  specs:
4
- activemodel (3.0.7)
5
- activesupport (= 3.0.7)
6
- builder (~> 2.1.2)
7
- i18n (~> 0.5.0)
8
- activerecord (3.0.7)
9
- activemodel (= 3.0.7)
10
- activesupport (= 3.0.7)
11
- arel (~> 2.0.2)
12
- tzinfo (~> 0.3.23)
13
- activesupport (3.0.7)
14
- archive-tar-minitar (0.5.2)
15
- arel (2.0.9)
16
- bcrypt-ruby (2.1.4)
17
- builder (2.1.2)
18
- columnize (0.3.2)
4
+ activemodel (3.1.1)
5
+ activesupport (= 3.1.1)
6
+ builder (~> 3.0.0)
7
+ i18n (~> 0.6)
8
+ activerecord (3.1.1)
9
+ activemodel (= 3.1.1)
10
+ activesupport (= 3.1.1)
11
+ arel (~> 2.2.1)
12
+ tzinfo (~> 0.3.29)
13
+ activesupport (3.1.1)
14
+ multi_json (~> 1.0)
15
+ arel (2.2.1)
16
+ bcrypt-ruby (3.0.1)
17
+ builder (3.0.0)
18
+ columnize (0.3.6)
19
+ debugger (1.1.1)
20
+ columnize (>= 0.3.1)
21
+ debugger-linecache (~> 1.1)
22
+ debugger-ruby_core_source (~> 1.1)
23
+ debugger-linecache (1.1.1)
24
+ debugger-ruby_core_source (>= 1.1.1)
25
+ debugger-ruby_core_source (1.1.1)
19
26
  git (1.2.5)
20
- i18n (0.5.0)
21
- jeweler (1.5.2)
22
- bundler (~> 1.0.0)
27
+ i18n (0.6.0)
28
+ jeweler (1.6.4)
29
+ bundler (~> 1.0)
23
30
  git (>= 1.2.5)
24
31
  rake
25
- linecache19 (0.5.12)
26
- ruby_core_source (>= 0.1.4)
27
- rake (0.8.7)
28
- ruby-debug-base19 (0.11.25)
29
- columnize (>= 0.3.1)
30
- linecache19 (>= 0.5.11)
31
- ruby_core_source (>= 0.1.4)
32
- ruby-debug19 (0.11.6)
33
- columnize (>= 0.3.1)
34
- linecache19 (>= 0.5.11)
35
- ruby-debug-base19 (>= 0.11.19)
36
- ruby_core_source (0.1.5)
37
- archive-tar-minitar (>= 0.5.2)
38
- sqlite3 (1.3.3)
39
- tzinfo (0.3.27)
32
+ multi_json (1.0.3)
33
+ rake (0.9.2)
34
+ sqlite3 (1.3.4)
35
+ tzinfo (0.3.30)
40
36
 
41
37
  PLATFORMS
42
38
  ruby
@@ -44,6 +40,7 @@ PLATFORMS
44
40
  DEPENDENCIES
45
41
  activerecord (>= 3.0.7)
46
42
  bcrypt-ruby
43
+ debugger
47
44
  jeweler
48
- ruby-debug19
45
+ rake
49
46
  sqlite3
data/Rakefile CHANGED
@@ -12,7 +12,6 @@ begin
12
12
  gem.email = "bjohnson@binarylogic.com"
13
13
  gem.homepage = "http://github.com/binarylogic/authlogic"
14
14
  gem.authors = ["Ben Johnson of Binary Logic", "Ben Woosley"]
15
- gem.add_bundler_dependencies
16
15
  end
17
16
  Jeweler::GemcutterTasks.new
18
17
  rescue LoadError
@@ -22,7 +21,8 @@ end
22
21
  require 'rake/testtask'
23
22
  Rake::TestTask.new(:test) do |test|
24
23
  test.libs << 'test'
25
- test.pattern = 'test/**/*_test.rb'
24
+ # Work around a Rake::TestTask bug: https://github.com/jimweirich/rake/issues/51
25
+ test.test_files = FileList['test/**/*_test.rb']
26
26
  test.verbose = true
27
27
  end
28
28
 
@@ -1,5 +1,5 @@
1
- ---
1
+ ---
2
2
  :major: 3
3
- :minor: 0
4
- :patch: 3
5
- :build:
3
+ :minor: 1
4
+ :patch: 0
5
+ :build: !!null
@@ -28,7 +28,7 @@ module Authlogic
28
28
  # See the various sub modules for the configuration they provide.
29
29
  def acts_as_authentic(unsupported_options = nil, &block)
30
30
  # Stop all configuration if the DB is not set up
31
- return if !db_setup?
31
+ raise StandardError.new("You must establish a database connection before using acts_as_authentic") if !db_setup?
32
32
 
33
33
  raise ArgumentError.new("You are using the old v1.X.X configuration method for Authlogic. Instead of " +
34
34
  "passing a hash of configuration options to acts_as_authentic, pass a block: acts_as_authentic { |c| c.my_option = my_value }") if !unsupported_options.nil?
@@ -31,8 +31,8 @@ module Authlogic
31
31
 
32
32
  klass.class_eval do
33
33
  include InstanceMethods
34
- scope :logged_in, where("last_request_at > ?", logged_in_timeout.seconds.ago)
35
- scope :logged_out, where("last_request_at is NULL or last_request_at <= ?", logged_in_timeout.seconds.ago)
34
+ scope :logged_in, lambda{ where("last_request_at > ?", logged_in_timeout.seconds.ago) }
35
+ scope :logged_out, lambda{ where("last_request_at is NULL or last_request_at <= ?", logged_in_timeout.seconds.ago) }
36
36
  end
37
37
  end
38
38
 
@@ -94,7 +94,7 @@ module Authlogic
94
94
  # manner that they handle that. If you are using the login field and set false for the :case_sensitive option in
95
95
  # validates_uniqueness_of_login_field_options this method will modify the query to look something like:
96
96
  #
97
- # where("LOWER(#{quoted_table_name}.#{login_field}) = ?", login.downcase).first
97
+ # where("#{quoted_table_name}.#{field} LIKE ?", login).first
98
98
  #
99
99
  # If you don't specify this it calls the good old find_by_* method:
100
100
  #
@@ -139,4 +139,4 @@ module Authlogic
139
139
  end
140
140
  end
141
141
  end
142
- end
142
+ end
@@ -58,7 +58,7 @@ module Authlogic
58
58
  alias_method :ignore_blank_passwords=, :ignore_blank_passwords
59
59
 
60
60
  # When calling valid_password?("some pass") do you want to check that password against what's in that object or whats in
61
- # the datbase. Take this example:
61
+ # the database. Take this example:
62
62
  #
63
63
  # u = User.first
64
64
  # u.password = "new pass"
@@ -243,7 +243,7 @@ module Authlogic
243
243
  end
244
244
 
245
245
  # Accepts a raw password to determine if it is the correct password or not. Notice the second argument. That defaults to the value of
246
- # check_passwords_against_database. See that method for mor information, but basically it just tells Authlogic to check the password
246
+ # check_passwords_against_database. See that method for more information, but basically it just tells Authlogic to check the password
247
247
  # against the value in the database or the value in the object.
248
248
  def valid_password?(attempted_password, check_against_database = check_passwords_against_database?)
249
249
  crypted = check_against_database && send("#{crypted_password_field}_changed?") ? send("#{crypted_password_field}_was") : send(crypted_password_field)
@@ -352,4 +352,4 @@ module Authlogic
352
352
  end
353
353
  end
354
354
  end
355
- end
355
+ end
@@ -1,7 +1,7 @@
1
1
  module Authlogic
2
2
  module ActsAsAuthentic
3
3
  # Maintains the persistence token, the token responsible for persisting sessions. This token
4
- # gets stores in the session and the cookie.
4
+ # gets stored in the session and the cookie.
5
5
  module PersistenceToken
6
6
  def self.included(klass)
7
7
  klass.class_eval do
@@ -1,3 +1,5 @@
1
+ require 'action_controller'
2
+
1
3
  module Authlogic
2
4
  module ControllerAdapters
3
5
  # Adapts authlogic to work with rails. The point is to close the gap between what authlogic expects and what the rails controller object
@@ -58,4 +58,4 @@ module Authlogic
58
58
  end
59
59
  end
60
60
 
61
- Sinatra::Request.send(:include, Authlogic::ControllerAdapters::SinatraAdapter::Adapter::Implementation)
61
+ Sinatra::Base.send(:include, Authlogic::ControllerAdapters::SinatraAdapter::Adapter::Implementation)
@@ -27,7 +27,7 @@ module Authlogic
27
27
  class << self
28
28
  attr_accessor :join_token
29
29
 
30
- # The number of times to loop through the encryption. This is ten because that is what restful_authentication defaults to.
30
+ # The number of times to loop through the encryption. This is twenty because that is what restful_authentication defaults to.
31
31
  def stretches
32
32
  @stretches ||= 20
33
33
  end
@@ -40,6 +40,7 @@ module Authlogic
40
40
  # not_confirmed: Your account is not confirmed
41
41
  # not_approved: Your account is not approved
42
42
  # no_authentication_details: You did not provide any details for authentication.
43
+ # general_credentials_error: Login/Password combination is not valid
43
44
  # models:
44
45
  # user_session: UserSession (or whatever name you are using)
45
46
  # attributes:
@@ -3,31 +3,16 @@ module Authlogic
3
3
  # So if you are using this in a rails app you should have this library.
4
4
  module Random
5
5
  extend self
6
-
7
- SecureRandom = (defined?(::SecureRandom) && ::SecureRandom) || (defined?(::ActiveSupport::SecureRandom) && ::ActiveSupport::SecureRandom)
8
-
9
- if SecureRandom
10
- def hex_token
11
- SecureRandom.hex(64)
12
- end
13
-
14
- def friendly_token
15
- # use base64url as defined by RFC4648
16
- SecureRandom.base64(15).tr('+/=', '').strip.delete("\n")
17
- end
18
- else
19
- def hex_token
20
- Authlogic::CryptoProviders::Sha512.encrypt(Time.now.to_s + (1..10).collect{ rand.to_s }.join)
21
- end
22
-
23
- FRIENDLY_CHARS = ("a".."z").to_a + ("A".."Z").to_a + ("0".."9").to_a
24
-
25
- def friendly_token
26
- newpass = ""
27
- 1.upto(20) { |i| newpass << FRIENDLY_CHARS[rand(FRIENDLY_CHARS.size-1)] }
28
- newpass
29
- end
6
+
7
+ SecureRandom = (defined?(::SecureRandom) ? ::SecureRandom : ActiveSupport::SecureRandom)
8
+
9
+ def hex_token
10
+ SecureRandom.hex(64)
30
11
  end
31
12
 
13
+ def friendly_token
14
+ # use base64url as defined by RFC4648
15
+ SecureRandom.base64(15).tr('+/=', '').strip.delete("\n")
16
+ end
32
17
  end
33
18
  end
@@ -13,7 +13,7 @@ module Authlogic
13
13
  email_name_regex = %{[A-Z0-9!#$\%&'*+/=?^_`{|}~\\-.]+}
14
14
  domain_head_regex = '(?:[A-Z0-9\-]+\.)+'
15
15
  domain_tld_regex = '(?:[A-Z]{2,4}|museum|travel)'
16
- @email_regex = /^#{email_name_regex}@#{domain_head_regex}#{domain_tld_regex}$/i
16
+ @email_regex = /\A#{email_name_regex}@#{domain_head_regex}#{domain_tld_regex}\z/i
17
17
  end
18
18
 
19
19
  # A simple regular expression that only allows for letters, numbers, spaces, and .-_@. Just a standard login / username
@@ -63,10 +63,11 @@ module Authlogic
63
63
 
64
64
  def self.included(base) #:nodoc:
65
65
  base.send :include, ActiveSupport::Callbacks
66
- base.define_callbacks *METHODS
67
-
66
+ base.define_callbacks *METHODS + [{:terminator => 'result == false'}]
67
+ base.define_callbacks *['persist', {:terminator => 'result == true'}]
68
+
68
69
  # If Rails 3, support the new callback syntax
69
- if base.send(base.respond_to?(:singleton_class) ? :singleton_class : :metaclass).method_defined?(:set_callback)
70
+ if base.singleton_class.method_defined?(:set_callback)
70
71
  METHODS.each do |method|
71
72
  base.class_eval <<-"end_eval", __FILE__, __LINE__
72
73
  def self.#{method}(*methods, &block)
@@ -81,14 +82,10 @@ module Authlogic
81
82
  METHODS.each do |method|
82
83
  class_eval <<-"end_eval", __FILE__, __LINE__
83
84
  def #{method}
84
- run_callbacks(:#{method}) { |result, object| result == false }
85
+ run_callbacks(:#{method})
85
86
  end
86
87
  end_eval
87
88
  end
88
-
89
- def persist
90
- run_callbacks(:persist) { |result, object| result == true }
91
- end
92
89
 
93
90
  def save_record(alternate_record = nil)
94
91
  r = alternate_record || record
@@ -23,10 +23,10 @@ module Authlogic
23
23
  # session = UserSession.new(:super_high_secret)
24
24
  # session.cookie_key => "super_high_secret_user_credentials"
25
25
  #
26
- # * <tt>Default:</tt> "#{guessed_klass_name.underscore}_credentials"
26
+ # * <tt>Default:</tt> "#{klass_name.underscore}_credentials"
27
27
  # * <tt>Accepts:</tt> String
28
28
  def cookie_key(value = nil)
29
- rw_config(:cookie_key, value, "#{guessed_klass_name.underscore}_credentials")
29
+ rw_config(:cookie_key, value, "#{klass_name.underscore}_credentials")
30
30
  end
31
31
  alias_method :cookie_key=, :cookie_key
32
32
 
@@ -19,7 +19,7 @@ module Authlogic
19
19
  def rw_config(key, value, default_value = nil, read_value = nil)
20
20
  if value == read_value
21
21
  return acts_as_authentic_config[key] if acts_as_authentic_config.include?(key)
22
- rw_config(key, default_value)
22
+ rw_config(key, default_value) unless default_value.nil?
23
23
  else
24
24
  config = acts_as_authentic_config.clone
25
25
  config[key] = value
@@ -74,4 +74,4 @@ module Authlogic
74
74
  end
75
75
  end
76
76
  end
77
- end
77
+ end
@@ -77,7 +77,7 @@ module Authlogic
77
77
  if !login.blank? && !password.blank?
78
78
  send("#{login_field}=", login)
79
79
  send("#{password_field}=", password)
80
- return valid?
80
+ valid?
81
81
  end
82
82
  end
83
83
 
@@ -6,13 +6,13 @@ module Authlogic
6
6
  klass.class_eval do
7
7
  extend Config
8
8
  include InstanceMethods
9
-
9
+
10
10
  class << self
11
11
  attr_accessor :configured_klass_methods
12
12
  end
13
13
  end
14
14
  end
15
-
15
+
16
16
  module Config
17
17
  # Lets you change which model to use for authentication.
18
18
  #
@@ -23,31 +23,22 @@ module Authlogic
23
23
  @klass = klass
24
24
  end
25
25
  alias_method :authenticate_with=, :authenticate_with
26
-
26
+
27
27
  # The name of the class that this session is authenticating with. For example, the UserSession class will
28
28
  # authenticate with the User class unless you specify otherwise in your configuration. See authenticate_with
29
29
  # for information on how to change this value.
30
30
  def klass
31
- @klass ||=
32
- if klass_name
33
- klass_name.constantize
34
- else
35
- nil
36
- end
37
- end
38
-
39
- # Same as klass, just returns a string instead of the actual constant.
40
- def klass_name
41
- @klass_name ||= guessed_klass_name
31
+ @klass ||= klass_name ? klass_name.constantize : nil
42
32
  end
43
-
33
+
44
34
  # The string of the model name class guessed from the actual session class name.
45
- def guessed_klass_name
46
- guessed_name = name.scan(/(.*)Session/)[0]
47
- guessed_name[0] if guessed_name
35
+ def klass_name
36
+ return @klass_name if defined?(@klass_name)
37
+ @klass_name = name.scan(/(.*)Session/)[0]
38
+ @klass_name = klass_name ? klass_name[0] : nil
48
39
  end
49
40
  end
50
-
41
+
51
42
  module InstanceMethods
52
43
  # Creating an alias method for the "record" method based on the klass name, so that we can do:
53
44
  #
@@ -63,7 +54,7 @@ module Authlogic
63
54
  end
64
55
  super
65
56
  end
66
-
57
+
67
58
  private
68
59
  def klass
69
60
  self.class.klass
@@ -46,7 +46,7 @@ module Authlogic
46
46
 
47
47
  module InstanceMethods
48
48
  # Let's you know if the session is being persisted or not, meaning the user does not have to explicitly log in
49
- # in order to be logged in. If the session has no associated record, it will try to find a record and persis
49
+ # in order to be logged in. If the session has no associated record, it will try to find a record and persist
50
50
  # the session. This is the method that the class level method find uses to ultimately persist the session.
51
51
  def persisting?
52
52
  return true if !record.nil?
@@ -93,6 +93,10 @@ module ActsAsAuthenticTest
93
93
  u.email = "dakota.d'ux@gmail.com"
94
94
  u.valid?
95
95
  assert u.errors[:email].size == 0
96
+
97
+ u.email = "<script>alert(123);</script>\nnobody@example.com"
98
+ assert !u.valid?
99
+ assert u.errors[:email].size > 0
96
100
  end
97
101
 
98
102
  def test_validates_uniqueness_of_email_field
@@ -2,6 +2,8 @@ require 'test_helper'
2
2
 
3
3
  module ActsAsAuthenticTest
4
4
  class LoggedInStatusTest < ActiveSupport::TestCase
5
+ ERROR_MSG = 'Multiple calls to %s should result in different relations'
6
+
5
7
  def test_logged_in_timeout_config
6
8
  assert_equal 10.minutes.to_i, User.logged_in_timeout
7
9
  assert_equal 10.minutes.to_i, Employee.logged_in_timeout
@@ -13,12 +15,24 @@ module ActsAsAuthenticTest
13
15
  end
14
16
 
15
17
  def test_named_scope_logged_in
18
+ # Testing that the scope returned differs, because the time it was called should be
19
+ # slightly different. This is an attempt to make sure the scope is lambda wrapped
20
+ # so that it is re-evaluated every time its called. My biggest concern is that the
21
+ # test happens so fast that the test fails... I just don't know a better way to test it!
22
+ assert User.logged_in.where_values != User.logged_in.where_values, ERROR_MSG % '#logged_in'
23
+
16
24
  assert_equal 0, User.logged_in.count
17
25
  User.first.update_attribute(:last_request_at, Time.now)
18
26
  assert_equal 1, User.logged_in.count
19
27
  end
20
28
 
21
29
  def test_named_scope_logged_out
30
+ # Testing that the scope returned differs, because the time it was called should be
31
+ # slightly different. This is an attempt to make sure the scope is lambda wrapped
32
+ # so that it is re-evaluated every time its called. My biggest concern is that the
33
+ # test happens so fast that the test fails... I just don't know a better way to test it!
34
+ assert User.logged_in.where_values != User.logged_out.where_values, ERROR_MSG % '#logged_out'
35
+
22
36
  assert_equal 2, User.logged_out.count
23
37
  User.first.update_attribute(:last_request_at, Time.now)
24
38
  assert_equal 1, User.logged_out.count
@@ -2,5 +2,4 @@ class UserSession < Authlogic::Session::Base
2
2
  end
3
3
 
4
4
  class BackOfficeUserSession < Authlogic::Session::Base
5
- authenticate_with User
6
5
  end
@@ -3,40 +3,7 @@ require 'test_helper'
3
3
  class RandomTest < ActiveSupport::TestCase
4
4
  def test_random_tokens_are_indeed_random
5
5
  # this might fail if you are *really* unlucky :)
6
- with_any_random do
7
- assert_not_equal Authlogic::Random.hex_token, Authlogic::Random.hex_token
8
- assert_not_equal Authlogic::Random.friendly_token, Authlogic::Random.friendly_token
9
- end
6
+ assert_not_equal Authlogic::Random.hex_token, Authlogic::Random.hex_token
7
+ assert_not_equal Authlogic::Random.friendly_token, Authlogic::Random.friendly_token
10
8
  end
11
-
12
- private
13
- def with_any_random(&block)
14
- [true, false].each {|val| with_secure_random_enabled(val, &block)}
15
- end
16
-
17
- def with_secure_random_enabled(enabled = true)
18
- # can't really test SecureRandom if we don't have an implementation
19
- return if enabled && !Authlogic::Random::SecureRandom
20
-
21
- current_sec_rand = Authlogic::Random::SecureRandom
22
- reload_authlogic_with_sec_random!(current_sec_rand, enabled)
23
-
24
- yield
25
- ensure
26
- reload_authlogic_with_sec_random!(current_sec_rand)
27
- end
28
-
29
- def reload_authlogic_with_sec_random!(secure_random, enabled = true)
30
- silence_warnings do
31
- secure_random.parent.const_set(secure_random.name.sub("#{secure_random.parent}::", ''), enabled ? secure_random : nil)
32
- load(File.dirname(__FILE__) + '/../lib/authlogic/random.rb')
33
- end
34
- end
35
-
36
- def silence_warnings
37
- old_verbose, $VERBOSE = $VERBOSE, nil
38
- yield
39
- ensure
40
- $VERBOSE = old_verbose
41
- end
42
9
  end
@@ -1,6 +1,54 @@
1
1
  require 'test_helper'
2
2
 
3
+ class WackyUserSession < Authlogic::Session::Base
4
+ attr_accessor :counter
5
+ authenticate_with User
6
+
7
+ def initialize
8
+ @counter = 0
9
+ super
10
+ end
11
+
12
+ def persist_by_false
13
+ self.counter += 1
14
+ return false
15
+ end
16
+
17
+ def persist_by_true
18
+ self.counter += 1
19
+ return true
20
+ end
21
+ end
22
+
3
23
  module SessionTest
4
24
  class CallbacksTest < ActiveSupport::TestCase
25
+ def setup
26
+ WackyUserSession.reset_callbacks(:persist)
27
+ end
28
+
29
+ def test_no_callbacks
30
+ assert_equal [], WackyUserSession._persist_callbacks.map(&:filter)
31
+ session = WackyUserSession.new
32
+ session.send(:persist)
33
+ assert_equal 0, session.counter
34
+ end
35
+
36
+ def test_true_callback_cancelling_later_callbacks
37
+ WackyUserSession.persist :persist_by_true, :persist_by_false
38
+ assert_equal [:persist_by_true, :persist_by_false], WackyUserSession._persist_callbacks.map(&:filter)
39
+
40
+ session = WackyUserSession.new
41
+ session.send(:persist)
42
+ assert_equal 1, session.counter
43
+ end
44
+
45
+ def test_false_callback_continuing_to_later_callbacks
46
+ WackyUserSession.persist :persist_by_false, :persist_by_true
47
+ assert_equal [:persist_by_false, :persist_by_true], WackyUserSession._persist_callbacks.map(&:filter)
48
+
49
+ session = WackyUserSession.new
50
+ session.send(:persist)
51
+ assert_equal 2, session.counter
52
+ end
5
53
  end
6
54
  end
@@ -6,35 +6,35 @@ module SessionTest
6
6
  def test_cookie_key
7
7
  UserSession.cookie_key = "my_cookie_key"
8
8
  assert_equal "my_cookie_key", UserSession.cookie_key
9
-
9
+
10
10
  UserSession.cookie_key "user_credentials"
11
11
  assert_equal "user_credentials", UserSession.cookie_key
12
12
  end
13
-
13
+
14
14
  def test_default_cookie_key
15
15
  assert_equal "user_credentials", UserSession.cookie_key
16
16
  assert_equal "back_office_user_credentials", BackOfficeUserSession.cookie_key
17
17
  end
18
-
18
+
19
19
  def test_remember_me
20
20
  UserSession.remember_me = true
21
21
  assert_equal true, UserSession.remember_me
22
22
  session = UserSession.new
23
23
  assert_equal true, session.remember_me
24
-
24
+
25
25
  UserSession.remember_me false
26
26
  assert_equal false, UserSession.remember_me
27
27
  session = UserSession.new
28
28
  assert_equal false, session.remember_me
29
29
  end
30
-
30
+
31
31
  def test_remember_me_for
32
32
  UserSession.remember_me_for = 3.years
33
33
  assert_equal 3.years, UserSession.remember_me_for
34
34
  session = UserSession.new
35
35
  session.remember_me = true
36
36
  assert_equal 3.years, session.remember_me_for
37
-
37
+
38
38
  UserSession.remember_me_for 3.months
39
39
  assert_equal 3.months, UserSession.remember_me_for
40
40
  session = UserSession.new
@@ -66,48 +66,48 @@ module SessionTest
66
66
  assert_equal false, session.httponly
67
67
  end
68
68
  end
69
-
69
+
70
70
  class InstanceMethodsTest < ActiveSupport::TestCase
71
71
  def test_credentials
72
72
  session = UserSession.new
73
73
  session.credentials = {:remember_me => true}
74
74
  assert_equal true, session.remember_me
75
75
  end
76
-
76
+
77
77
  def test_remember_me
78
78
  session = UserSession.new
79
79
  assert_equal false, session.remember_me
80
80
  assert !session.remember_me?
81
-
81
+
82
82
  session.remember_me = false
83
83
  assert_equal false, session.remember_me
84
84
  assert !session.remember_me?
85
-
85
+
86
86
  session.remember_me = true
87
87
  assert_equal true, session.remember_me
88
88
  assert session.remember_me?
89
-
89
+
90
90
  session.remember_me = nil
91
91
  assert_nil session.remember_me
92
92
  assert !session.remember_me?
93
-
93
+
94
94
  session.remember_me = "1"
95
95
  assert_equal "1", session.remember_me
96
96
  assert session.remember_me?
97
-
97
+
98
98
  session.remember_me = "true"
99
99
  assert_equal "true", session.remember_me
100
100
  assert session.remember_me?
101
101
  end
102
-
102
+
103
103
  def test_remember_me_until
104
104
  session = UserSession.new
105
105
  assert_nil session.remember_me_until
106
-
106
+
107
107
  session.remember_me = true
108
108
  assert 3.months.from_now <= session.remember_me_until
109
109
  end
110
-
110
+
111
111
  def test_persist_persist_by_cookie
112
112
  ben = users(:ben)
113
113
  assert !UserSession.find
@@ -115,14 +115,14 @@ module SessionTest
115
115
  assert session = UserSession.find
116
116
  assert_equal ben, session.record
117
117
  end
118
-
118
+
119
119
  def test_after_save_save_cookie
120
120
  ben = users(:ben)
121
121
  session = UserSession.new(ben)
122
122
  assert session.save
123
123
  assert_equal "#{ben.persistence_token}::#{ben.id}", controller.cookies["user_credentials"]
124
124
  end
125
-
125
+
126
126
  def test_after_destroy_destroy_cookie
127
127
  ben = users(:ben)
128
128
  set_cookie_for(ben)
@@ -40,6 +40,7 @@ module SessionTest
40
40
  assert_equal "benrocks", session.send(:protected_password)
41
41
  assert !controller.http_auth_requested?
42
42
  end
43
+ unset_session
43
44
  UserSession.request_http_basic_auth = true
44
45
  UserSession.http_basic_auth_realm = 'PersistTestRealm'
45
46
  http_basic_auth_for(ben) do
@@ -7,12 +7,12 @@ module SessionTest
7
7
  UserSession.authenticate_with = Employee
8
8
  assert_equal "Employee", UserSession.klass_name
9
9
  assert_equal Employee, UserSession.klass
10
-
10
+
11
11
  UserSession.authenticate_with User
12
12
  assert_equal "User", UserSession.klass_name
13
13
  assert_equal User, UserSession.klass
14
14
  end
15
-
15
+
16
16
  def test_klass
17
17
  assert_equal User, UserSession.klass
18
18
  end
@@ -20,13 +20,13 @@ module SessionTest
20
20
  def test_klass_name
21
21
  assert_equal "User", UserSession.klass_name
22
22
  end
23
-
24
- def test_guessed_klass_name
25
- assert_equal "User", UserSession.guessed_klass_name
26
- assert_equal "BackOfficeUser", BackOfficeUserSession.guessed_klass_name
23
+
24
+ def test_klass_name_uses_custom_name
25
+ assert_equal "User", UserSession.klass_name
26
+ assert_equal "BackOfficeUser", BackOfficeUserSession.klass_name
27
27
  end
28
28
  end
29
-
29
+
30
30
  class InstanceMethodsTest < ActiveSupport::TestCase
31
31
  def test_record_method
32
32
  ben = users(:ben)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: Empact-authlogic
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.3
4
+ version: 3.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,11 +10,11 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2011-08-14 00:00:00.000000000Z
13
+ date: 2012-04-18 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activerecord
17
- requirement: &2164354060 !ruby/object:Gem::Requirement
17
+ requirement: &70148993109920 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ! '>='
@@ -22,18 +22,7 @@ dependencies:
22
22
  version: 3.0.7
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *2164354060
26
- - !ruby/object:Gem::Dependency
27
- name: activerecord
28
- requirement: &2164350480 !ruby/object:Gem::Requirement
29
- none: false
30
- requirements:
31
- - - ! '>='
32
- - !ruby/object:Gem::Version
33
- version: 3.0.7
34
- type: :runtime
35
- prerelease: false
36
- version_requirements: *2164350480
25
+ version_requirements: *70148993109920
37
26
  description:
38
27
  email: bjohnson@binarylogic.com
39
28
  executables: []
@@ -184,7 +173,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
184
173
  version: '0'
185
174
  segments:
186
175
  - 0
187
- hash: -2975867320564342286
176
+ hash: 1446451024535166867
188
177
  required_rubygems_version: !ruby/object:Gem::Requirement
189
178
  none: false
190
179
  requirements:
@@ -193,58 +182,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
193
182
  version: '0'
194
183
  requirements: []
195
184
  rubyforge_project:
196
- rubygems_version: 1.8.5
185
+ rubygems_version: 1.8.11
197
186
  signing_key:
198
187
  specification_version: 3
199
188
  summary: A clean, simple, and unobtrusive ruby authentication solution.
200
- test_files:
201
- - test/acts_as_authentic_test/base_test.rb
202
- - test/acts_as_authentic_test/email_test.rb
203
- - test/acts_as_authentic_test/logged_in_status_test.rb
204
- - test/acts_as_authentic_test/login_test.rb
205
- - test/acts_as_authentic_test/magic_columns_test.rb
206
- - test/acts_as_authentic_test/password_test.rb
207
- - test/acts_as_authentic_test/perishable_token_test.rb
208
- - test/acts_as_authentic_test/persistence_token_test.rb
209
- - test/acts_as_authentic_test/restful_authentication_test.rb
210
- - test/acts_as_authentic_test/session_maintenance_test.rb
211
- - test/acts_as_authentic_test/single_access_test.rb
212
- - test/authenticates_many_test.rb
213
- - test/crypto_provider_test/aes256_test.rb
214
- - test/crypto_provider_test/bcrypt_test.rb
215
- - test/crypto_provider_test/sha1_test.rb
216
- - test/crypto_provider_test/sha256_test.rb
217
- - test/crypto_provider_test/sha512_test.rb
218
- - test/i18n_test.rb
219
- - test/libs/affiliate.rb
220
- - test/libs/company.rb
221
- - test/libs/employee.rb
222
- - test/libs/employee_session.rb
223
- - test/libs/ldaper.rb
224
- - test/libs/ordered_hash.rb
225
- - test/libs/project.rb
226
- - test/libs/user.rb
227
- - test/libs/user_session.rb
228
- - test/random_test.rb
229
- - test/session_test/activation_test.rb
230
- - test/session_test/active_record_trickery_test.rb
231
- - test/session_test/brute_force_protection_test.rb
232
- - test/session_test/callbacks_test.rb
233
- - test/session_test/cookies_test.rb
234
- - test/session_test/credentials_test.rb
235
- - test/session_test/existence_test.rb
236
- - test/session_test/http_auth_test.rb
237
- - test/session_test/id_test.rb
238
- - test/session_test/klass_test.rb
239
- - test/session_test/magic_columns_test.rb
240
- - test/session_test/magic_states_test.rb
241
- - test/session_test/params_test.rb
242
- - test/session_test/password_test.rb
243
- - test/session_test/perishability_test.rb
244
- - test/session_test/persistence_test.rb
245
- - test/session_test/scopes_test.rb
246
- - test/session_test/session_test.rb
247
- - test/session_test/timeout_test.rb
248
- - test/session_test/unauthorized_record_test.rb
249
- - test/session_test/validation_test.rb
250
- - test/test_helper.rb
189
+ test_files: []