[DRE-commits] [ruby-activeldap] 01/03: Imported Upstream version 4.0.2

Marc Dequènes duck at moszumanska.debian.org
Tue Jan 28 01:36:41 UTC 2014


This is an automated email from the git hooks/post-receive script.

duck pushed a commit to branch master
in repository ruby-activeldap.

commit c9450996994501eefdacfb6d0735b3268e13d31f
Author: Marc Dequènes (Duck) <Duck at DuckCorp.org>
Date:   Tue Jan 28 01:34:36 2014 +0100

    Imported Upstream version 4.0.2
---
 Gemfile                                    |   2 +-
 README.textile                             |   3 +-
 checksums.yaml.gz                          | Bin 0 -> 270 bytes
 doc/text/news.textile                      |  37 +++++++++++
 doc/text/tutorial.textile                  |  24 +++++++
 lib/active_ldap/adapter/base.rb            |   3 +-
 lib/active_ldap/adapter/jndi.rb            |  11 +++-
 lib/active_ldap/adapter/jndi_connection.rb |   6 +-
 lib/active_ldap/base.rb                    |   1 +
 lib/active_ldap/callbacks.rb               |   4 --
 lib/active_ldap/persistence.rb             |   2 +-
 lib/active_ldap/schema.rb                  |  20 ++++++
 lib/active_ldap/schema/syntaxes.rb         |  15 +++++
 lib/active_ldap/user_password.rb           |   4 +-
 lib/active_ldap/validations.rb             |   4 +-
 lib/active_ldap/version.rb                 |   2 +-
 metadata.yml                               |  97 +++++++++++------------------
 test/test_base.rb                          |  21 +++----
 test/test_callback.rb                      |  14 ++++-
 test/test_schema.rb                        |  73 ++++++++++++++++++++++
 test/test_user_password.rb                 |   2 +
 21 files changed, 251 insertions(+), 94 deletions(-)

diff --git a/Gemfile b/Gemfile
index e3afc74..bf9ca7a 100644
--- a/Gemfile
+++ b/Gemfile
@@ -6,7 +6,7 @@ gemspec
 
 group :test do
   gem "net-ldap"
-  platforms :mri_18, :mri_19 do
+  platforms :mri do
     gem "ruby-ldap"
   end
   platforms :jruby do
diff --git a/README.textile b/README.textile
index 7166a04..a477ec0 100644
--- a/README.textile
+++ b/README.textile
@@ -45,7 +45,8 @@ h2. Notes
 
 h2. Rails
 
-See "Rails":doc/text/rails.textile page for Rails integration.
+See "Rails":file.rails.html ("doc/text/rails.textile":doc/text/rails.textile
+in the repository and on GitHub) page for Rails integration.
 
 h2. Licence
 
diff --git a/checksums.yaml.gz b/checksums.yaml.gz
new file mode 100644
index 0000000..4c01523
Binary files /dev/null and b/checksums.yaml.gz differ
diff --git a/doc/text/news.textile b/doc/text/news.textile
index c10655a..23b3a4f 100644
--- a/doc/text/news.textile
+++ b/doc/text/news.textile
@@ -1,5 +1,41 @@
 h1. News
 
+h2(#4-0-2). 4.0.2: 2014-01-04
+
+h3. Improvements
+
+* Supported sub-tree moving by all adapters.
+* Used YARD style link in documentation. [Reported by Fraser McCrossan]
+* Supported Object-Security-Descriptor (OID: 1.2.840.113556.1.4.907)
+  [GitHub:#66] [Reported by Nowhere Man]
+* Made JEPG syntax binary.
+* Supported binary encoding for values in a container.
+  [GitHub:#66] [Reported by Nowhere Man]
+* Added documentation about @:filter@ option of {ActiveLdap::Base.find}
+  into tutorial.
+  [GitHub:#72] [Patch by Fernando Martinez]
+* Migrated to gettext gem from gettext_i18n_rails gem because ActiveLdap
+  dosen't use any gettext_i18n_rails gem features..
+  [activeldap-discuss] [Reported by Christian Nennemann]
+* Supported retry on timeout on JNDI adapter.
+  [GitHub:#77] [Patch by Ryosuke Yamazaki]
+
+h3. Fixes
+
+* Removed needless newlines generated by @pack("m")@.
+  [GitHub:#75] [GitHub:#76] [Patch by Ryosuke Yamazaki]
+* Fixed a bug that @after_initialize@ isn't run.
+  [GitHub:#79] [Patch by Nobutaka OSHIRO]
+
+h3. Thanks
+
+* Fraser McCrossan
+* Nowhere Man
+* Fernando Martinez
+* Christian Nennemann
+* Ryosuke Yamazaki
+* Nobutaka OSHIRO
+
 h2(#4-0-1). 4.0.1: 2013-08-29
 
 h3. Improvements
@@ -49,6 +85,7 @@ h3. Improvements
   [Patch by superscott]
 * [GitHub:#63] Handled Errno::ECONNRESET as connection in
   net-ldap adapter [Patch by mpoornima]
+
 h3. Fixes
 
 * [GitHub:#44] Fixed a typo in document.
diff --git a/doc/text/tutorial.textile b/doc/text/tutorial.textile
index 6dc8bcd..f9132ba 100644
--- a/doc/text/tutorial.textile
+++ b/doc/text/tutorial.textile
@@ -403,6 +403,30 @@ If :attribute is unspecified, it defaults to the dn_attribute.
 It is also possible to override :attribute and :value by specifying :filter. This
 argument allows the direct specification of a LDAP filter to retrieve objects by.
 
+h5. Using the :filter option
+
+The filter option lets you pass in an LDAP query string.
+For example retrieving all groups with cn which starts with @'dev'@ and has @guid@ == 1:
+
+<pre>
+irb> Group.find(:all, :filter => '(&(cn=dev*)(guid=1))').collect {|group| group.cn}
+=> ["develop"]
+</pre>
+
+It also allows a hash like sintax (sparing you the need to write the query by hand ):
+
+<pre>
+irb> Group.find(:all, :filter => {:cn => 'dev*', :guid => 1 }).collect {|group| group.cn}
+=> ["develop", "developers", "sys", "sysadmin"]
+</pre>
+
+You can build complex queries combining the hash syntax with arrays and @:or@ and @:and@ operators retrieving all users whose name contains 'john' or cn ends with 'smith' or contains 'liz'
+
+<pre>
+irb> User.find(:all, filter: [:or, [:or, { :cn => '*smith', :name => '*john*'} ], { cn: '*liz*' }]).collect(&:cn)
+=> ['john.smith', 'jane.smith', 'john tha ripper', 'liz.taylor', ...]
+</pre>
+
 h4. .search
 
 .search is a class method that is accessible from any subclass of Base, and Base.
diff --git a/lib/active_ldap/adapter/base.rb b/lib/active_ldap/adapter/base.rb
index 3fe477a..b7e2f15 100644
--- a/lib/active_ldap/adapter/base.rb
+++ b/lib/active_ldap/adapter/base.rb
@@ -317,7 +317,8 @@ module ActiveLdap
           do_in_timeout(@timeout, &block)
         rescue Timeout::Error => e
           @logger.error {_('Requested action timed out.')}
-          if @retry_on_timeout and retry_limit < 0 and n_retries <= retry_limit
+          if @retry_on_timeout and (retry_limit < 0 or n_retries <= retry_limit)
+            n_retries += 1
             if connecting?
               retry
             elsif try_reconnect
diff --git a/lib/active_ldap/adapter/jndi.rb b/lib/active_ldap/adapter/jndi.rb
index 90b2191..ce6592b 100644
--- a/lib/active_ldap/adapter/jndi.rb
+++ b/lib/active_ldap/adapter/jndi.rb
@@ -23,7 +23,7 @@ module ActiveLdap
           uri = construct_uri(host, port, method == :ssl)
           with_start_tls = method == :start_tls
           info = {:uri => uri, :with_start_tls => with_start_tls}
-          [log("connect", info) {JndiConnection.new(host, port, method)},
+          [log("connect", info) {JndiConnection.new(host, port, method, @timeout)},
            uri, with_start_tls]
         end
       end
@@ -93,7 +93,9 @@ module ActiveLdap
       def execute(method, info=nil, *args, &block)
         name = (info || {}).delete(:name) || method
         log(name, info) {@connection.send(method, *args, &block)}
-      rescue JndiConnection::CommunicationException => e
+      rescue JndiConnection::CommunicationException, JndiConnection::ServiceUnavailableException => e
+        disconnect! if connecting?
+
         raise ActiveLdap::ConnectionError.new(e.getMessage())
       rescue JndiConnection::NamingException
         if /\[LDAP: error code (\d+) - ([^\]]+)\]/ =~ $!.to_s
@@ -101,7 +103,12 @@ module ActiveLdap
           klass = LdapError::ERRORS[Integer($1)]
           klass ||= ActiveLdap::LdapError
           raise klass, message
+        elsif /LDAP response read timed out/ =~ $!.to_s
+          disconnect! if connecting?
+
+          raise Timeout::Error.new($!.to_s)
         end
+
         raise
       end
 
diff --git a/lib/active_ldap/adapter/jndi_connection.rb b/lib/active_ldap/adapter/jndi_connection.rb
index 44730c2..405a682 100644
--- a/lib/active_ldap/adapter/jndi_connection.rb
+++ b/lib/active_ldap/adapter/jndi_connection.rb
@@ -27,6 +27,7 @@ module ActiveLdap
       Control = ldap.Control
 
       CommunicationException = naming.CommunicationException
+      ServiceUnavailableException = naming.ServiceUnavailableException
       NamingException = naming.NamingException
       NameNotFoundException = naming.NameNotFoundException
 
@@ -72,10 +73,11 @@ module ActiveLdap
         end
       end
 
-      def initialize(host, port, method)
+      def initialize(host, port, method, timeout)
         @host = host
         @port = port
         @method = method
+        @timeout = timeout
         @context = nil
         @tls = nil
       end
@@ -158,6 +160,8 @@ module ActiveLdap
         environment = {
           Context::INITIAL_CONTEXT_FACTORY => "com.sun.jndi.ldap.LdapCtxFactory",
           Context::PROVIDER_URL => ldap_uri,
+          'com.sun.jndi.ldap.connect.timeout' => (@timeout * 1000).to_i.to_s,
+          'com.sun.jndi.ldap.read.timeout' => (@timeout * 1000).to_i.to_s,
         }
         environment = HashTable.new(environment)
         context = InitialLdapContext.new(environment, nil)
diff --git a/lib/active_ldap/base.rb b/lib/active_ldap/base.rb
index 4bd9fff..9266ccc 100644
--- a/lib/active_ldap/base.rb
+++ b/lib/active_ldap/base.rb
@@ -689,6 +689,7 @@ module ActiveLdap
         raise ArgumentError, format % attributes.inspect
       end
       yield self if block_given?
+      run_callbacks :initialize unless _initialize_callbacks.empty?
     end
 
     # Returns true if the +comparison_object+ is the same object, or is of
diff --git a/lib/active_ldap/callbacks.rb b/lib/active_ldap/callbacks.rb
index ce97e99..880a4f6 100644
--- a/lib/active_ldap/callbacks.rb
+++ b/lib/active_ldap/callbacks.rb
@@ -42,10 +42,6 @@ module ActiveLdap
       end
     end
 
-    def initialize(*) #:nodoc:
-      run_callbacks(:initialize) { super }
-    end
-
     def destroy #:nodoc:
       run_callbacks(:destroy) { super }
     end
diff --git a/lib/active_ldap/persistence.rb b/lib/active_ldap/persistence.rb
index cea34dd..5c4856d 100644
--- a/lib/active_ldap/persistence.rb
+++ b/lib/active_ldap/persistence.rb
@@ -70,7 +70,7 @@ module ActiveLdap
           if old_dn_base == new_dn_base
             new_superior = nil
           else
-            new_superior = new_dn_base
+            new_superior = new_dn_base.to_s
           end
           modify_rdn_entry(@original_dn,
                            "#{dn_attribute}=#{DN.escape_value(new_dn_value)}",
diff --git a/lib/active_ldap/schema.rb b/lib/active_ldap/schema.rb
index c628e9a..67479ac 100644
--- a/lib/active_ldap/schema.rb
+++ b/lib/active_ldap/schema.rb
@@ -424,6 +424,26 @@ module ActiveLdap
         @binary
       end
 
+      # Sets binary encoding to value if the given attribute's syntax
+      # is binary syntax. Does nothing otherwise.
+      # @return [void]
+      def apply_encoding(value)
+        return unless binary?
+        case value
+        when Hash
+          value.each_value do |sub_value|
+            apply_encoding(sub_value)
+          end
+        when Array
+          value.each do |sub_value|
+            apply_encoding(sub_value)
+          end
+        else
+          return unless value.respond_to?(:force_encoding)
+          value.force_encoding("ASCII-8BIT")
+        end
+      end
+
       # binary_required?
       #
       # Returns true if the value MUST be transferred in binary
diff --git a/lib/active_ldap/schema/syntaxes.rb b/lib/active_ldap/schema/syntaxes.rb
index 5759fba..c002c8f 100644
--- a/lib/active_ldap/schema/syntaxes.rb
+++ b/lib/active_ldap/schema/syntaxes.rb
@@ -278,6 +278,10 @@ module ActiveLdap
       class JPEG < Base
         SYNTAXES["1.3.6.1.4.1.1466.115.121.1.28"] = self
 
+        def binary?
+          true
+        end
+
         private
         def validate_normalized_value(value, original_value)
           if value.unpack("n")[0] == 0xffd8
@@ -429,6 +433,17 @@ module ActiveLdap
           super
         end
       end
+
+      class ObjectSecurityDescriptor < OctetString
+        # @see http://tools.ietf.org/html/draft-armijo-ldap-syntax-00
+        #   Object-Security-Descriptor: 1.2.840.113556.1.4.907
+        #
+        #   Encoded as an Octet-String (OID 1.3.6.1.4.1.1466.115.121.1.40)
+        #
+        # @see http://msdn.microsoft.com/en-us/library/cc223229.aspx
+        #   String(NT-Sec-Desc) 1.2.840.113556.1.4.907
+        SYNTAXES["1.2.840.113556.1.4.907"] = self
+      end
     end
   end
 end
diff --git a/lib/active_ldap/user_password.rb b/lib/active_ldap/user_password.rb
index b620370..5445d41 100644
--- a/lib/active_ldap/user_password.rb
+++ b/lib/active_ldap/user_password.rb
@@ -54,7 +54,7 @@ module ActiveLdap
       end
       salt ||= Salt.generate(4)
       md5_hash_with_salt = "#{Digest::MD5.digest(password + salt)}#{salt}"
-      "{SMD5}#{[md5_hash_with_salt].pack('m').chomp}"
+      "{SMD5}#{[md5_hash_with_salt].pack('m').gsub("\n", '')}"
     end
 
     def extract_salt_for_smd5(smd5ed_password)
@@ -71,7 +71,7 @@ module ActiveLdap
       end
       salt ||= Salt.generate(4)
       sha1_hash_with_salt = "#{Digest::SHA1.digest(password + salt)}#{salt}"
-      "{SSHA}#{[sha1_hash_with_salt].pack('m').chomp}"
+      "{SSHA}#{[sha1_hash_with_salt].pack('m').gsub("\n", '')}"
     end
 
     def extract_salt_for_ssha(sshaed_password)
diff --git a/lib/active_ldap/validations.rb b/lib/active_ldap/validations.rb
index ade8d7d..6186ded 100644
--- a/lib/active_ldap/validations.rb
+++ b/lib/active_ldap/validations.rb
@@ -172,9 +172,7 @@ module ActiveLdap
       entry_attribute.schemata.each do |name, attribute|
         value = self[name]
         # Is it really proper location for setting encoding?
-        if attribute.binary? and value.respond_to?(:force_encoding)
-          value.force_encoding("ASCII-8BIT")
-        end
+        attribute.apply_encoding(value)
         next if self.class.blank_value?(value)
         validate_ldap_value(attribute, name, value)
       end
diff --git a/lib/active_ldap/version.rb b/lib/active_ldap/version.rb
index 1db98a3..5ae050b 100644
--- a/lib/active_ldap/version.rb
+++ b/lib/active_ldap/version.rb
@@ -1,3 +1,3 @@
 module ActiveLdap
-  VERSION = "4.0.1"
+  VERSION = "4.0.2"
 end
diff --git a/metadata.yml b/metadata.yml
index efb5ca4..687cfdc 100644
--- a/metadata.yml
+++ b/metadata.yml
@@ -1,8 +1,7 @@
 --- !ruby/object:Gem::Specification
 name: activeldap
 version: !ruby/object:Gem::Version
-  version: 4.0.1
-  prerelease: 
+  version: 4.0.2
 platform: ruby
 authors:
 - Will Drewry
@@ -10,12 +9,11 @@ authors:
 autorequire: 
 bindir: bin
 cert_chain: []
-date: 2013-08-29 00:00:00.000000000 Z
+date: 2014-01-04 00:00:00.000000000 Z
 dependencies:
 - !ruby/object:Gem::Dependency
   name: activemodel
   requirement: !ruby/object:Gem::Requirement
-    none: false
     requirements:
     - - ~>
       - !ruby/object:Gem::Version
@@ -23,7 +21,6 @@ dependencies:
   type: :runtime
   prerelease: false
   version_requirements: !ruby/object:Gem::Requirement
-    none: false
     requirements:
     - - ~>
       - !ruby/object:Gem::Version
@@ -31,167 +28,149 @@ dependencies:
 - !ruby/object:Gem::Dependency
   name: locale
   requirement: !ruby/object:Gem::Requirement
-    none: false
     requirements:
-    - - ! '>='
+    - - '>='
       - !ruby/object:Gem::Version
         version: '0'
   type: :runtime
   prerelease: false
   version_requirements: !ruby/object:Gem::Requirement
-    none: false
     requirements:
-    - - ! '>='
+    - - '>='
       - !ruby/object:Gem::Version
         version: '0'
 - !ruby/object:Gem::Dependency
   name: gettext
   requirement: !ruby/object:Gem::Requirement
-    none: false
     requirements:
-    - - ! '>='
+    - - '>='
       - !ruby/object:Gem::Version
         version: '0'
   type: :runtime
   prerelease: false
   version_requirements: !ruby/object:Gem::Requirement
-    none: false
     requirements:
-    - - ! '>='
+    - - '>='
       - !ruby/object:Gem::Version
         version: '0'
 - !ruby/object:Gem::Dependency
   name: gettext_i18n_rails
   requirement: !ruby/object:Gem::Requirement
-    none: false
     requirements:
-    - - ! '>='
+    - - '>='
       - !ruby/object:Gem::Version
         version: '0'
   type: :runtime
   prerelease: false
   version_requirements: !ruby/object:Gem::Requirement
-    none: false
     requirements:
-    - - ! '>='
+    - - '>='
       - !ruby/object:Gem::Version
         version: '0'
 - !ruby/object:Gem::Dependency
   name: bundler
   requirement: !ruby/object:Gem::Requirement
-    none: false
     requirements:
-    - - ! '>='
+    - - '>='
       - !ruby/object:Gem::Version
         version: '0'
   type: :development
   prerelease: false
   version_requirements: !ruby/object:Gem::Requirement
-    none: false
     requirements:
-    - - ! '>='
+    - - '>='
       - !ruby/object:Gem::Version
         version: '0'
 - !ruby/object:Gem::Dependency
   name: rake
   requirement: !ruby/object:Gem::Requirement
-    none: false
     requirements:
-    - - ! '>='
+    - - '>='
       - !ruby/object:Gem::Version
         version: '0'
   type: :development
   prerelease: false
   version_requirements: !ruby/object:Gem::Requirement
-    none: false
     requirements:
-    - - ! '>='
+    - - '>='
       - !ruby/object:Gem::Version
         version: '0'
 - !ruby/object:Gem::Dependency
   name: test-unit
   requirement: !ruby/object:Gem::Requirement
-    none: false
     requirements:
-    - - ! '>='
+    - - '>='
       - !ruby/object:Gem::Version
         version: '0'
   type: :development
   prerelease: false
   version_requirements: !ruby/object:Gem::Requirement
-    none: false
     requirements:
-    - - ! '>='
+    - - '>='
       - !ruby/object:Gem::Version
         version: '0'
 - !ruby/object:Gem::Dependency
   name: test-unit-notify
   requirement: !ruby/object:Gem::Requirement
-    none: false
     requirements:
-    - - ! '>='
+    - - '>='
       - !ruby/object:Gem::Version
         version: '0'
   type: :development
   prerelease: false
   version_requirements: !ruby/object:Gem::Requirement
-    none: false
     requirements:
-    - - ! '>='
+    - - '>='
       - !ruby/object:Gem::Version
         version: '0'
 - !ruby/object:Gem::Dependency
   name: yard
   requirement: !ruby/object:Gem::Requirement
-    none: false
     requirements:
-    - - ! '>='
+    - - '>='
       - !ruby/object:Gem::Version
         version: '0'
   type: :development
   prerelease: false
   version_requirements: !ruby/object:Gem::Requirement
-    none: false
     requirements:
-    - - ! '>='
+    - - '>='
       - !ruby/object:Gem::Version
         version: '0'
 - !ruby/object:Gem::Dependency
   name: RedCloth
   requirement: !ruby/object:Gem::Requirement
-    none: false
     requirements:
-    - - ! '>='
+    - - '>='
       - !ruby/object:Gem::Version
         version: '0'
   type: :development
   prerelease: false
   version_requirements: !ruby/object:Gem::Requirement
-    none: false
     requirements:
-    - - ! '>='
+    - - '>='
       - !ruby/object:Gem::Version
         version: '0'
 - !ruby/object:Gem::Dependency
   name: packnga
   requirement: !ruby/object:Gem::Requirement
-    none: false
     requirements:
-    - - ! '>='
+    - - '>='
       - !ruby/object:Gem::Version
         version: '0'
   type: :development
   prerelease: false
   version_requirements: !ruby/object:Gem::Requirement
-    none: false
     requirements:
-    - - ! '>='
+    - - '>='
       - !ruby/object:Gem::Version
         version: '0'
-description: ! "    'ActiveLdap' is a ruby library which provides a clean\n    objected
-  oriented interface to the Ruby/LDAP library.  It was inspired\n    by ActiveRecord.
-  This is not nearly as clean or as flexible as\n    ActiveRecord, but it is still
-  trivial to define new objects and manipulate\n    them with minimal difficulty.\n"
+description: |2
+      'ActiveLdap' is a ruby library which provides a clean
+      objected oriented interface to the Ruby/LDAP library.  It was inspired
+      by ActiveRecord. This is not nearly as clean or as flexible as
+      ActiveRecord, but it is still trivial to define new objects and manipulate
+      them with minimal difficulty.
 email:
 - redpig at dataspill.org
 - kou at cozmixng.org
@@ -347,34 +326,28 @@ files:
 - test/test_validation.rb
 homepage: http://ruby-activeldap.rubyforge.org/
 licenses:
-- Ruby's or GPLv2 or later
+- Ruby's
+- GPLv2 or later
+metadata: {}
 post_install_message: 
 rdoc_options: []
 require_paths:
 - lib
 required_ruby_version: !ruby/object:Gem::Requirement
-  none: false
   requirements:
-  - - ! '>='
+  - - '>='
     - !ruby/object:Gem::Version
       version: '0'
-      segments:
-      - 0
-      hash: -4556557570349939659
 required_rubygems_version: !ruby/object:Gem::Requirement
-  none: false
   requirements:
-  - - ! '>='
+  - - '>='
     - !ruby/object:Gem::Version
       version: '0'
-      segments:
-      - 0
-      hash: -4556557570349939659
 requirements: []
 rubyforge_project: ruby-activeldap
-rubygems_version: 1.8.23
+rubygems_version: 2.0.14
 signing_key: 
-specification_version: 3
+specification_version: 4
 summary: ActiveLdap is a object-oriented API to LDAP
 test_files:
 - test/add-phonetic-attribute-options-to-slapd.ldif
diff --git a/test/test_base.rb b/test/test_base.rb
index e9630e5..a587990 100644
--- a/test/test_base.rb
+++ b/test/test_base.rb
@@ -90,22 +90,15 @@ class TestBase < Test::Unit::TestCase
     make_ou("sub,ou=users")
     make_temporary_user(:simple => true) do |user,|
       user.id = "user2,ou=sub,#{@user_class.base}"
-      case user.connection.class.to_s.demodulize
-      when "Jndi"
-        assert_true(user.save)
+      assert_true(user.save)
 
-        found_user = nil
-        assert_nothing_raised do
-          found_user = @user_class.find("user2")
-        end
-        base = @user_class.base
-        assert_equal("#{@user_class.dn_attribute}=user2,ou=sub,#{base}",
-                     found_user.dn.to_s)
-      else
-        assert_raise(ActiveLdap::NotImplemented) do
-          user.save
-        end
+      found_user = nil
+      assert_nothing_raised do
+        found_user = @user_class.find("user2")
       end
+      base = @user_class.base
+      assert_equal("#{@user_class.dn_attribute}=user2,ou=sub,#{base}",
+                   found_user.dn.to_s)
     end
   end
 
diff --git a/test/test_callback.rb b/test/test_callback.rb
index 78602a5..83faf59 100644
--- a/test/test_callback.rb
+++ b/test/test_callback.rb
@@ -4,9 +4,21 @@ class TestCallback < Test::Unit::TestCase
   include AlTestUtils
 
   priority :must
+  def test_new
+    initialized_entries = []
+    @group_class.instance_variable_set("@initialized_entries",
+                                       initialized_entries)
+    @group_class.module_eval do
+      after_initialize "self.class.instance_variable_get('@initialized_entries') << self"
+    end
+    assert_equal([], initialized_entries)
+    new_group = @group_class.new(:cn => "new-cn")
+    assert_equal([new_group.cn].sort,
+                 initialized_entries.collect {|g| g.cn}.sort)
+  end
 
   priority :normal
-  def test_callback_after_find_and_after_initialize
+  def test_find
     make_temporary_group do |group|
       found_entries = []
       initialized_entries = []
diff --git a/test/test_schema.rb b/test/test_schema.rb
index c29cbde..6c89985 100644
--- a/test/test_schema.rb
+++ b/test/test_schema.rb
@@ -556,4 +556,77 @@ class TestSchema < Test::Unit::TestCase
     attribute_hash[:syntax] = syntax.id if syntax
     assert_equal(expected, attribute_hash)
   end
+
+  class TestAttribute < self
+    class TestApplyEncoding < self
+      class TestNotBinary < self
+        def setup
+          super
+          uid_schema =
+            "( 0.9.2342.19200300.100.1.1 NAME ( 'uid' 'userid' ) " +
+            "DESC 'RFC1274: user identifier' EQUALITY caseIgnoreMatch " +
+            "SUBSTR caseIgnoreSubstringsMatch " +
+            "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15{256} )"
+          entries = {
+            "attributeTypes" => [uid_schema],
+          }
+          schema = ActiveLdap::Schema.new(entries)
+          @attribute = schema.attribute("uid")
+        end
+
+        def test_do_nothing
+          value = ""
+          value.force_encoding("UTF-8")
+          @attribute.apply_encoding(value)
+          assert_equal(Encoding::UTF_8, value.encoding)
+        end
+      end
+
+      class TestBinary < self
+        def setup
+          super
+          jpeg_schema =
+            "( 1.3.6.1.4.1.1466.115.121.1.28 DESC 'JPEG' " +
+            "X-NOT-HUMAN-READABLE 'TRUE' )"
+          jpeg_photo_schema =
+            "( 0.9.2342.19200300.100.1.60 NAME 'jpegPhoto' " +
+            "DESC 'RFC2798: a JPEG image' SYNTAX " +
+            "1.3.6.1.4.1.1466.115.121.1.28 )"
+          entries = {
+            "attributeTypes" => [jpeg_photo_schema],
+            "ldapSyntaxes" => [jpeg_schema],
+          }
+          schema = ActiveLdap::Schema.new(entries)
+          @attribute = schema.attribute("jpegPhoto")
+        end
+
+        def test_string
+          value = ""
+          value.force_encoding("UTF-8")
+          @attribute.apply_encoding(value)
+          assert_equal(Encoding::ASCII_8BIT, value.encoding)
+        end
+
+        def test_array
+          values = [""]
+          values.each do |value|
+            value.force_encoding("UTF-8")
+          end
+          @attribute.apply_encoding(values)
+          assert_equal([Encoding::ASCII_8BIT],
+                       values.collect(&:encoding))
+        end
+
+        def test_hash
+          values = {:binary => ""}
+          values.each_value do |value|
+            value.force_encoding("UTF-8")
+          end
+          @attribute.apply_encoding(values)
+          assert_equal([Encoding::ASCII_8BIT],
+                       values.each_value.collect(&:encoding))
+        end
+      end
+    end
+  end
 end
diff --git a/test/test_user_password.rb b/test/test_user_password.rb
index e3393ec..a7aca36 100644
--- a/test/test_user_password.rb
+++ b/test/test_user_password.rb
@@ -10,9 +10,11 @@ class TestUserPassword < Test::Unit::TestCase
       "{MD5}DRB9CfW75Ayt495ccenptw==" => 'letmein', #MD5
       "{SMD5}8L2iXJuazftLVHrAf7ptPFQIDaw=" => 'letmein', #SMD5 as generated by slappasswd (4 bytes of salt)
       "{SMD5}kXibTNG+O98gaQtkugYcmSTiE+M2Z5TA" => 'letmein', #SMD5 as generated by Apache Directory Studio (8 bytes of salt)
+      "{SMD5}4PkkYH5qI6ydk/9pwvZD3DYwYzVlMzVlLTBkZDEtNGJhMi05NjI5LWRlODgyMDhiMWZmYQ==" => 'letmein', #SMD5 generated with 36 bytes of salt
       "{SHA}t6h1/B6iKLkGEEG3zsS9PFKrPOM=" => 'letmein', #SHA
       "{SSHA}YA87hc9/L/cCGR1HValcJb7a8AYxZXY4" => 'wibble', # SSHA as generated by slappasswd (4 bytes of salt)
       "{SSHA}6J6Ios3l1panY9sm0+g9l3/jFz2kwOPrVA4+OA==" => 'letmein', # SSHA as generated by Apache Directory Studio (8 bytes of salt)
+      "{SSHA}f/j1unqoJg1C1zjw8tvxSp4xpow2MGM1ZTM1ZS0wZGQxLTRiYTItOTYyOS1kZTg4MjA4YjFmZmE=" => 'letmein', #SSHA generated with 36 bytes of salt
       "letmein" => 'letmein', #Cleartext password
     }.each do |hash, plain|
       assert_send([ActiveLdap::UserPassword, :valid?,

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-ruby-extras/ruby-activeldap.git



More information about the Pkg-ruby-extras-commits mailing list