authlogic 2.1.2 → 2.1.3

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/.gitignore CHANGED
@@ -6,4 +6,4 @@ pkg/*
6
6
  coverage/*
7
7
  doc/*
8
8
  benchmarks/*
9
-
9
+ .specification
data/README.rdoc CHANGED
@@ -68,6 +68,7 @@ If you find a bug or a problem please post it in the issues section. If you need
68
68
  * <b>Authlogic LDAP addon:</b> http://github.com/binarylogic/authlogic_ldap
69
69
  * <b>Authlogic Facebook Connect:</b> http://github.com/kalasjocke/authlogic_facebook_connect
70
70
  * <b>Authlogic OAuth (Twitter):</b> http://github.com/jrallison/authlogic_oauth
71
+ * <b>Authlogic PAM:</b> http://github.com/nbudin/authlogic_pam
71
72
 
72
73
  If you create one of your own, please let me know about it so I can add it to this list. Or just fork the project, add your link, and send me a pull request.
73
74
 
@@ -242,4 +243,4 @@ What inspired me to create Authlogic was the messiness of the current authentica
242
243
  6. <b>Easily extendable.</b> One of the distinct advantages of using a library is the ability to use its API, assuming it has one. Authlogic has an *excellent* public API, meaning it can easily be extended and grow beyond the core library. Checkout the "add ons" list above to see what I mean.
243
244
 
244
245
 
245
- Copyright (c) 2009 {Ben Johnson of Binary Logic}[http://www.binarylogic.com], released under the MIT license
246
+ Copyright (c) 2009 {Ben Johnson of Binary Logic}[http://www.binarylogic.com], released under the MIT license
data/VERSION.yml CHANGED
@@ -1,4 +1,5 @@
1
1
  ---
2
- :patch: 2
3
- :major: 2
4
2
  :minor: 1
3
+ :patch: 3
4
+ :build:
5
+ :major: 2
data/authlogic.gemspec CHANGED
@@ -1,15 +1,15 @@
1
1
  # Generated by jeweler
2
- # DO NOT EDIT THIS FILE
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{authlogic}
8
- s.version = "2.1.2"
8
+ s.version = "2.1.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Ben Johnson of Binary Logic"]
12
- s.date = %q{2009-09-12}
12
+ s.date = %q{2009-11-12}
13
13
  s.email = %q{bjohnson@binarylogic.com}
14
14
  s.extra_rdoc_files = [
15
15
  "LICENSE",
@@ -49,7 +49,9 @@ Gem::Specification.new do |s|
49
49
  "lib/authlogic/crypto_providers/bcrypt.rb",
50
50
  "lib/authlogic/crypto_providers/md5.rb",
51
51
  "lib/authlogic/crypto_providers/sha1.rb",
52
+ "lib/authlogic/crypto_providers/sha256.rb",
52
53
  "lib/authlogic/crypto_providers/sha512.rb",
54
+ "lib/authlogic/crypto_providers/wordpress.rb",
53
55
  "lib/authlogic/i18n.rb",
54
56
  "lib/authlogic/i18n/translator.rb",
55
57
  "lib/authlogic/random.rb",
@@ -100,6 +102,7 @@ Gem::Specification.new do |s|
100
102
  "test/crypto_provider_test/aes256_test.rb",
101
103
  "test/crypto_provider_test/bcrypt_test.rb",
102
104
  "test/crypto_provider_test/sha1_test.rb",
105
+ "test/crypto_provider_test/sha256_test.rb",
103
106
  "test/crypto_provider_test/sha512_test.rb",
104
107
  "test/fixtures/companies.yml",
105
108
  "test/fixtures/employees.yml",
@@ -161,6 +164,7 @@ Gem::Specification.new do |s|
161
164
  "test/crypto_provider_test/aes256_test.rb",
162
165
  "test/crypto_provider_test/bcrypt_test.rb",
163
166
  "test/crypto_provider_test/sha1_test.rb",
167
+ "test/crypto_provider_test/sha256_test.rb",
164
168
  "test/crypto_provider_test/sha512_test.rb",
165
169
  "test/i18n_test.rb",
166
170
  "test/libs/affiliate.rb",
@@ -210,3 +214,4 @@ Gem::Specification.new do |s|
210
214
  s.add_dependency(%q<activesupport>, [">= 0"])
211
215
  end
212
216
  end
217
+
data/lib/authlogic.rb CHANGED
@@ -11,6 +11,7 @@ require File.dirname(__FILE__) + "/authlogic/controller_adapters/sinatra_adapter
11
11
 
12
12
  require File.dirname(__FILE__) + "/authlogic/crypto_providers/md5"
13
13
  require File.dirname(__FILE__) + "/authlogic/crypto_providers/sha1"
14
+ require File.dirname(__FILE__) + "/authlogic/crypto_providers/sha256"
14
15
  require File.dirname(__FILE__) + "/authlogic/crypto_providers/sha512"
15
16
  require File.dirname(__FILE__) + "/authlogic/crypto_providers/bcrypt"
16
17
  require File.dirname(__FILE__) + "/authlogic/crypto_providers/aes256"
@@ -1,6 +1,7 @@
1
1
  begin
2
2
  require "bcrypt"
3
3
  rescue LoadError
4
+ "sudo gem install bcrypt-ruby"
4
5
  end
5
6
 
6
7
  module Authlogic
@@ -0,0 +1,50 @@
1
+ require "digest/sha2"
2
+
3
+ module Authlogic
4
+ # The acts_as_authentic method has a crypto_provider option. This allows you to use any type of encryption you like.
5
+ # Just create a class with a class level encrypt and matches? method. See example below.
6
+ #
7
+ # === Example
8
+ #
9
+ # class MyAwesomeEncryptionMethod
10
+ # def self.encrypt(*tokens)
11
+ # # the tokens passed will be an array of objects, what type of object is irrelevant,
12
+ # # just do what you need to do with them and return a single encrypted string.
13
+ # # for example, you will most likely join all of the objects into a single string and then encrypt that string
14
+ # end
15
+ #
16
+ # def self.matches?(crypted, *tokens)
17
+ # # return true if the crypted string matches the tokens.
18
+ # # depending on your algorithm you might decrypt the string then compare it to the token, or you might
19
+ # # encrypt the tokens and make sure it matches the crypted string, its up to you
20
+ # end
21
+ # end
22
+ module CryptoProviders
23
+ # = Sha256
24
+ #
25
+ # Uses the Sha256 hash algorithm to encrypt passwords.
26
+ class Sha256
27
+ class << self
28
+ attr_accessor :join_token
29
+
30
+ # The number of times to loop through the encryption. This is ten because that is what restful_authentication defaults to.
31
+ def stretches
32
+ @stretches ||= 20
33
+ end
34
+ attr_writer :stretches
35
+
36
+ # Turns your raw password into a Sha256 hash.
37
+ def encrypt(*tokens)
38
+ digest = tokens.flatten.join(join_token)
39
+ stretches.times { digest = Digest::SHA256.hexdigest(digest) }
40
+ digest
41
+ end
42
+
43
+ # Does the crypted password match the tokens? Uses the same tokens that were used to encrypt.
44
+ def matches?(crypted, *tokens)
45
+ encrypt(*tokens) == crypted
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,43 @@
1
+ require 'digest/md5'
2
+ module Authlogic
3
+ module CryptoProviders
4
+ class Wordpress
5
+ class << self
6
+ ITOA64 = './0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
7
+
8
+ def matches?(crypted, *tokens)
9
+ stretches = 1 << ITOA64.index(crypted[3,1])
10
+ plain, salt = *tokens
11
+ hashed = Digest::MD5.digest(salt+plain)
12
+ stretches.times do |i|
13
+ hashed = Digest::MD5.digest(hashed+plain)
14
+ end
15
+ crypted[0,12]+encode_64(hashed, 16) == crypted
16
+ end
17
+
18
+ def encode_64(input, length)
19
+ output = ""
20
+ i = 0
21
+ while i < length
22
+ value = input[i]
23
+ i+=1
24
+ break if value.nil?
25
+ output += ITOA64[value & 0x3f, 1]
26
+ value |= input[i] << 8 if i < length
27
+ output += ITOA64[(value >> 6) & 0x3f, 1]
28
+
29
+ i+=1
30
+ break if i >= length
31
+ value |= input[i] << 16 if i < length
32
+ output += ITOA64[(value >> 12) & 0x3f,1]
33
+
34
+ i+=1
35
+ break if i >= length
36
+ output += ITOA64[(value >> 18) & 0x3f,1]
37
+ end
38
+ output
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -13,13 +13,13 @@ 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 = /\A#{email_name_regex}@#{domain_head_regex}#{domain_tld_regex}\z/i
16
+ @email_regex = /^#{email_name_regex}@#{domain_head_regex}#{domain_tld_regex}$/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
20
20
  # regular expression.
21
21
  def self.login
22
- /\A\w[\w\.+\-_@ ]+\z/
22
+ /\A\w[\w\.+\-_@ ]+$/
23
23
  end
24
24
  end
25
- end
25
+ end
@@ -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> "#{klass_name.underscore}_credentials"
26
+ # * <tt>Default:</tt> "#{guessed_klass_name.underscore}_credentials"
27
27
  # * <tt>Accepts:</tt> String
28
28
  def cookie_key(value = nil)
29
- rw_config(:cookie_key, value, "#{klass_name.underscore}_credentials")
29
+ rw_config(:cookie_key, value, "#{guessed_klass_name.underscore}_credentials")
30
30
  end
31
31
  alias_method :cookie_key=, :cookie_key
32
32
 
@@ -38,10 +38,13 @@ module Authlogic
38
38
 
39
39
  # Same as klass, just returns a string instead of the actual constant.
40
40
  def klass_name
41
- @klass_name ||=
42
- if guessed_name = name.scan(/(.*)Session/)[0]
43
- @klass_name = guessed_name[0]
44
- end
41
+ @klass_name ||= guessed_klass_name
42
+ end
43
+
44
+ # 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
45
48
  end
46
49
  end
47
50
 
@@ -100,6 +100,12 @@ module Authlogic
100
100
  #
101
101
  # setup :activate_authlogic
102
102
  def activate_authlogic
103
+ if @request && ! @request.respond_to?(:params)
104
+ class <<@request
105
+ alias_method :params, :parameters
106
+ end
107
+ end
108
+
103
109
  Authlogic::Session::Base.controller = (@request && Authlogic::TestCase::RailsRequestAdapter.new(@request)) || controller
104
110
  end
105
111
 
@@ -111,4 +117,4 @@ module Authlogic
111
117
  end
112
118
 
113
119
  ::Test::Unit::TestCase.send(:include, TestCase) if defined?(::Test::Unit::TestCase)
114
- end
120
+ end
@@ -1,13 +1,69 @@
1
+ # Test::Unit
2
+ # Place this file into your test/shoulda_macros directory
3
+ #
4
+ # Example:
5
+ #
6
+ # class UserTest
7
+ # should_have_authlogic
8
+ # end
9
+ #
10
+ # Rspec
11
+ # Place this file into your spec/support/shoulda directory
12
+ #
13
+ # Example:
14
+ #
15
+ # describe User do
16
+ # it { should have_authlogic }
17
+ # end
18
+
1
19
  module Authlogic
2
- module ShouldaMacros
3
- class Test::Unit::TestCase
4
- def self.should_be_authentic
20
+ module Shoulda
21
+
22
+ module Matchers
23
+ def have_authlogic
24
+ HaveAuthlogic.new
25
+ end
26
+ alias_method :be_authentic, :have_authlogic
27
+
28
+ class HaveAuthlogic
29
+
30
+ def matches?(subject)
31
+ subject.respond_to?(:password=) && subject.respond_to?(:valid_password?)
32
+ end
33
+
34
+ def failure_message
35
+ "Add the line 'acts_as_authentic' to your model"
36
+ end
37
+
38
+ def description
39
+ "have Authlogic"
40
+ end
41
+ end
42
+
43
+ end
44
+
45
+ module Macros
46
+ include Matchers
47
+
48
+ def should_have_authlogic
5
49
  klass = described_type rescue model_class
6
- should "acts as authentic" do
7
- assert klass.new.respond_to?(:password=)
8
- assert klass.new.respond_to?(:valid_password?)
50
+ matcher = HaveAuthlogic.new
51
+
52
+ should matcher.description do
53
+ assert matcher.matches?(klass.new), matcher.failure_message
9
54
  end
10
55
  end
56
+ alias_method :should_be_authentic, :should_have_authlogic
57
+
11
58
  end
59
+
60
+ end
61
+ end
62
+
63
+ if defined? Spec
64
+ Spec::Runner.configure do |config|
65
+ config.include(Authlogic::Shoulda::Matchers)
12
66
  end
13
- end
67
+ else
68
+ Test::Unit::TestCase.class_eval { extend Authlogic::Shoulda::Macros }
69
+ end
@@ -67,15 +67,15 @@ module ActsAsAuthenticTest
67
67
  def test_validates_format_of_email_field
68
68
  u = User.new
69
69
  u.email = "aaaaaaaaaaaaa"
70
- assert !u.valid?
70
+ u.valid?
71
71
  assert u.errors[:email].size > 0
72
72
 
73
73
  u.email = "a@a.com"
74
- assert !u.valid?
74
+ u.valid?
75
75
  assert u.errors[:email].size == 0
76
76
 
77
77
  u.email = "dakota.dux+1@gmail.com"
78
- assert !u.valid?
78
+ u.valid?
79
79
  assert u.errors[:email].size == 0
80
80
  end
81
81
 
@@ -33,7 +33,7 @@ module ActsAsAuthenticTest
33
33
  end
34
34
 
35
35
  def test_validates_format_of_login_field_options_config
36
- default = {:with => /\A\w[\w\.+\-_@ ]+\z/, :message => I18n.t('error_messages.login_invalid', :default => "should use only letters, numbers, spaces, and .-_@ please.")}
36
+ default = {:with => /\A\w[\w\.+\-_@ ]+$/, :message => I18n.t('error_messages.login_invalid', :default => "should use only letters, numbers, spaces, and .-_@ please.")}
37
37
  assert_equal default, User.validates_format_of_login_field_options
38
38
  assert_equal default, Employee.validates_format_of_login_field_options
39
39
 
@@ -0,0 +1,14 @@
1
+ require File.dirname(__FILE__) + '/../test_helper.rb'
2
+
3
+ module CryptoProviderTest
4
+ class Sha256Test < ActiveSupport::TestCase
5
+ def test_encrypt
6
+ assert Authlogic::CryptoProviders::Sha256.encrypt("mypass")
7
+ end
8
+
9
+ def test_matches
10
+ hash = Authlogic::CryptoProviders::Sha256.encrypt("mypass")
11
+ assert Authlogic::CryptoProviders::Sha256.matches?(hash, "mypass")
12
+ end
13
+ end
14
+ end
@@ -1,2 +1,6 @@
1
1
  class UserSession < Authlogic::Session::Base
2
- end
2
+ end
3
+
4
+ class BackOfficeUserSession < Authlogic::Session::Base
5
+ authenticate_with User
6
+ end
@@ -11,6 +11,11 @@ module SessionTest
11
11
  assert_equal "user_credentials", UserSession.cookie_key
12
12
  end
13
13
 
14
+ def test_default_cookie_key
15
+ assert_equal "user_credentials", UserSession.cookie_key
16
+ assert_equal "back_office_user_credentials", BackOfficeUserSession.cookie_key
17
+ end
18
+
14
19
  def test_remember_me
15
20
  UserSession.remember_me = true
16
21
  assert_equal true, UserSession.remember_me
@@ -20,6 +20,11 @@ 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
27
+ end
23
28
  end
24
29
 
25
30
  class InstanceMethodsTest < ActiveSupport::TestCase
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.1.2
4
+ version: 2.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Johnson of Binary Logic
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-09-12 00:00:00 -04:00
12
+ date: 2009-11-12 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -65,7 +65,9 @@ files:
65
65
  - lib/authlogic/crypto_providers/bcrypt.rb
66
66
  - lib/authlogic/crypto_providers/md5.rb
67
67
  - lib/authlogic/crypto_providers/sha1.rb
68
+ - lib/authlogic/crypto_providers/sha256.rb
68
69
  - lib/authlogic/crypto_providers/sha512.rb
70
+ - lib/authlogic/crypto_providers/wordpress.rb
69
71
  - lib/authlogic/i18n.rb
70
72
  - lib/authlogic/i18n/translator.rb
71
73
  - lib/authlogic/random.rb
@@ -116,6 +118,7 @@ files:
116
118
  - test/crypto_provider_test/aes256_test.rb
117
119
  - test/crypto_provider_test/bcrypt_test.rb
118
120
  - test/crypto_provider_test/sha1_test.rb
121
+ - test/crypto_provider_test/sha256_test.rb
119
122
  - test/crypto_provider_test/sha512_test.rb
120
123
  - test/fixtures/companies.yml
121
124
  - test/fixtures/employees.yml
@@ -198,6 +201,7 @@ test_files:
198
201
  - test/crypto_provider_test/aes256_test.rb
199
202
  - test/crypto_provider_test/bcrypt_test.rb
200
203
  - test/crypto_provider_test/sha1_test.rb
204
+ - test/crypto_provider_test/sha256_test.rb
201
205
  - test/crypto_provider_test/sha512_test.rb
202
206
  - test/i18n_test.rb
203
207
  - test/libs/affiliate.rb