From codesite-noreply at google.com Wed Apr 4 02:00:01 2007 From: codesite-noreply at google.com (codesite-noreply at google.com) Date: Tue, 03 Apr 2007 23:00:01 -0700 Subject: [Ruby-activeldap-commit] [ruby-activeldap commit] r152 - in trunk: lib/active_ldap test Message-ID: <16362292aa042d432a3783ef6fd81@google.com> Author: koutou Date: Tue Apr 3 22:59:43 2007 New Revision: 152 Modified: trunk/lib/active_ldap/schema.rb trunk/test/test_schema.rb Log: * Support Fedora-DS's non-numerical oid schema. Patch by Daniel Pfile. Thanks! Modified: trunk/lib/active_ldap/schema.rb ============================================================================== --- trunk/lib/active_ldap/schema.rb (original) +++ trunk/lib/active_ldap/schema.rb Tue Apr 3 22:59:43 2007 @@ -31,6 +31,9 @@ alias_method :[], :attribute alias_method :attr, :attribute + NUMERIC_OID_RE = "\\d[\\d\\.]+" + DESCRIPTION_RE = "[a-zA-Z][a-zA-Z\\d\\-]*" + OID_RE = "(?:#{NUMERIC_OID_RE}|#{DESCRIPTION_RE}-oid)" def attributes(group, id_or_name) return {} if group.empty? or id_or_name.empty? @@ -46,7 +49,7 @@ return ids[id] if ids.has_key?(id) while schema = @entries[group].shift - next unless /\A\s*\(\s*([\d\.]+)\s*(.*)\s*\)\s*\z/ =~ schema + next unless /\A\s*\(\s*(#{OID_RE})\s*(.*)\s*\)\s*\z/ =~ schema schema_id = $1 rest = $2 next if ids.has_key?(schema_id) Modified: trunk/test/test_schema.rb ============================================================================== --- trunk/test/test_schema.rb (original) +++ trunk/test/test_schema.rb Tue Apr 3 22:59:43 2007 @@ -1,6 +1,34 @@ require 'al-test-utils' class TestSchema < Test::Unit::TestCase + def test_text_oid + text_oid_schema = "( mysite-oid NAME 'mysite' " + + "SUP groupofuniquenames STRUCTURAL " + + "MUST ( mysitelang $ mysiteurl ) " + + "MAY ( mysitealias $ mysitecmsurl ) " + + "X-ORIGIN 'user defined' )" + expect = { + :name => ["mysite"], + :sup => ["groupofuniquenames"], + :structural => ["TRUE"], + :must => %w(mysitelang mysiteurl), + :may => %w(mysitealias mysitecmsurl), + :x_origin => ["user defined"] + } + assert_schema(expect, "mysite", text_oid_schema) + + text_oid_attribute_schema = "( mysiteurl-oid NAME 'mysiteurl' " + + "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 " + + "SINGLE-VALUE X-ORIGIN 'user defined' )" + expect = { + :name => ["mysiteurl"], + :syntax => ["1.3.6.1.4.1.1466.115.121.1.15"], + :single_value => ["TRUE"], + :x_origin => ["user defined"] + } + assert_schema(expect, "mysiteurl", text_oid_attribute_schema) + end + def test_name_as_key top_schema = "( 2.5.6.0 NAME 'top' DESC 'top of the superclass chain' " + "ABSTRACT MUST objectClass )" From codesite-noreply at google.com Wed Apr 25 21:18:32 2007 From: codesite-noreply at google.com (codesite-noreply at google.com) Date: Wed, 25 Apr 2007 18:18:32 -0700 Subject: [Ruby-activeldap-commit] [ruby-activeldap commit] r153 - trunk/test Message-ID: <163600cc53042ef9cc0ed428234d@google.com> Author: koutou Date: Wed Apr 25 18:18:15 2007 New Revision: 153 Modified: trunk/test/test_base.rb Log: * cleanup. Modified: trunk/test/test_base.rb ============================================================================== --- trunk/test/test_base.rb (original) +++ trunk/test/test_base.rb Wed Apr 25 18:18:15 2007 @@ -11,14 +11,14 @@ units.new("two").save! units.new("three").save! - assert_equal(["one", "two", "three", "units"].sort, - units.find(:all, :scope => :sub).collect {|unit| unit.ou}.sort) + ous = units.find(:all, :scope => :sub).collect {|unit| unit.ou} + assert_equal(["one", "two", "three", "units"].sort, ous.sort) - assert_equal(["units"].sort, - units.find(:all, :scope => :base).collect {|unit| unit.ou}.sort) + ous = units.find(:all, :scope => :base).collect {|unit| unit.ou} + assert_equal(["units"].sort, ous.sort) - assert_equal(["one", "two", "three"].sort, - units.find(:all, :scope => :one).collect {|unit| unit.ou}.sort) + ous = units.find(:all, :scope => :one).collect {|unit| unit.ou} + assert_equal(["one", "two", "three"].sort, ous.sort) end def test_initialize_with_recommended_classes From codesite-noreply at google.com Wed Apr 25 21:28:06 2007 From: codesite-noreply at google.com (codesite-noreply at google.com) Date: Wed, 25 Apr 2007 18:28:06 -0700 Subject: [Ruby-activeldap-commit] [ruby-activeldap commit] r154 - trunk/lib/active_ldap Message-ID: Author: koutou Date: Wed Apr 25 18:27:49 2007 New Revision: 154 Modified: trunk/lib/active_ldap/object_class.rb Log: * fixed strange error message. Modified: trunk/lib/active_ldap/object_class.rb ============================================================================== --- trunk/lib/active_ldap/object_class.rb (original) +++ trunk/lib/active_ldap/object_class.rb Wed Apr 25 18:27:49 2007 @@ -52,7 +52,7 @@ schema.exist_name?("objectClasses", new_class) end unless invalid_classes.empty? - message = "unknown objectClass to LDAP server" + message = "unknown objectClass in LDAP server" message = "#{message}: #{invalid_classes.join(', ')}" raise ObjectClassError, message end From codesite-noreply at google.com Wed Apr 25 22:38:48 2007 From: codesite-noreply at google.com (codesite-noreply at google.com) Date: Wed, 25 Apr 2007 19:38:48 -0700 Subject: [Ruby-activeldap-commit] [ruby-activeldap commit] r155 - in trunk: lib/active_ldap test Message-ID: Author: koutou Date: Wed Apr 25 19:38:32 2007 New Revision: 155 Modified: trunk/lib/active_ldap/schema.rb trunk/test/test_base.rb trunk/test/test_schema.rb Log: * supported "_" in schema's attribute name. (It seems that RFC doesn't allow "_" for attribute name.) * fixed a bug that oid name after SUP may be dropped. Modified: trunk/lib/active_ldap/schema.rb ============================================================================== --- trunk/lib/active_ldap/schema.rb (original) +++ trunk/lib/active_ldap/schema.rb Wed Apr 25 19:38:32 2007 @@ -16,7 +16,7 @@ end # attribute - # + # # This is just like LDAP::Schema#attribute except that it allows # look up in any of the given keys. # e.g. @@ -197,12 +197,34 @@ [id, name] end + # from RFC 2252 + attribute_type_description_reserved_names = + ["NAME", "DESC", "OBSOLETE", "SUP", "EQUALITY", "ORDERING", "SUBSTR", + "SYNTAX", "SINGLE-VALUE", "COLLECTIVE", "NO-USER-MODIFICATION", "USAGE"] + syntax_description_reserved_names = ["DESC"] + object_class_description_reserved_names = + ["NAME", "DESC", "OBSOLETE", "SUP", "ABSTRACT", "STRUCTURAL", + "AUXILIARY", "MUST", "MAY"] + matching_rule_description_reserved_names = + ["NAME", "DESC", "OBSOLETE", "SYNTAX"] + matching_rule_use_description_reserved_names = + ["NAME", "DESC", "OBSOLETE", "APPLIES"] + private_experiment_reserved_names = ["X-[A-Z\\-_]+"] + reserved_names = + (attribute_type_description_reserved_names + + syntax_description_reserved_names + + object_class_description_reserved_names + + matching_rule_description_reserved_names + + matching_rule_use_description_reserved_names + + private_experiment_reserved_names).uniq + RESERVED_NAMES_RE = /(?:#{reserved_names.join('|')})/ + def parse_attributes(str, attributes) - str.scan(/([A-Z\-]+)\s+ + str.scan(/([A-Z\-_]+)\s+ (?:\(\s*([\w\-]+(?:\s+\$\s+[\w\-]+)+)\s*\)| \(\s*([^\)]*)\s*\)| '([^\']*)'| - ([a-z][\w\-]*)| + ((?!#{RESERVED_NAMES_RE})[a-zA-Z][a-zA-Z\d\-;]*)| (\d[\d\.\{\}]+)| () )/x @@ -221,7 +243,7 @@ when no_value values = ["TRUE"] end - attributes[name] = values + attributes[normalize_attribute_name(name)] = values end end @@ -260,7 +282,7 @@ end def normalize_attribute_name(name) - name.upcase + name.upcase.gsub(/_/, "-") end end # Schema end Modified: trunk/test/test_base.rb ============================================================================== --- trunk/test/test_base.rb (original) +++ trunk/test/test_base.rb Wed Apr 25 19:38:32 2007 @@ -4,6 +4,8 @@ include AlTestUtils priority :must + + priority :normal def test_nested_ou make_ou("units") units = ou_class("ou=units") Modified: trunk/test/test_schema.rb ============================================================================== --- trunk/test/test_schema.rb (original) +++ trunk/test/test_schema.rb Wed Apr 25 19:38:32 2007 @@ -1,6 +1,65 @@ require 'al-test-utils' class TestSchema < Test::Unit::TestCase + priority :must + def test_attribute_name_with_under_score + top_schema = + "( 2.5.6.0 NAME 'Top' STRUCTURAL MUST objectClass MAY ( " + + "cAPublicKey $ cAPrivateKey $ certificateValidityInterval $ " + + "authorityRevocation $ lastReferencedTime $ " + + "equivalentToMe $ ACL $ backLink $ binderyProperty $ " + + "Obituary $ Reference $ revision $ " + + "ndsCrossCertificatePair $ certificateRevocation $ " + + "usedBy $ GUID $ otherGUID $ DirXML-Associations $ " + + "creatorsName $ modifiersName $ unknownBaseClass $ " + + "unknownAuxiliaryClass $ auditFileLink $ " + + "masvProposedLabelel $ masvDefaultRange $ " + + "masvAuthorizedRange $ objectVersion $ " + + "auxClassCompatibility $ rbsAssignedRoles $ " + + "rbsOwnedCollections $ rbsAssignedRoles2 $ " + + "rbsOwnedCollections2 ) X-NDS_NONREMOVABLE '1' " + + "X-NDS_ACL_TEMPLATES '16#subtree#[Creator]#[Entry Rights]' )" + + expect = { + :name => ["Top"], + :structural => ["TRUE"], + :must => ["objectClass"], + :x_nds_nonremovable => ["1"], + :x_nds_acl_templates => ['16#subtree#[Creator]#[Entry Rights]'], + } + assert_schema(expect, "Top", top_schema) + end + + def test_sup_with_oid_start_with_upper_case + organizational_person_schema = + "( 2.5.6.7 NAME 'organizationalPerson' SUP Person STRUCTURAL MAY " + + "( facsimileTelephoneNumber $ l $ eMailAddress $ ou $ " + + "physicalDeliveryOfficeName $ postalAddress $ postalCode $ " + + "postOfficeBox $ st $ street $ title $ mailboxLocation $ " + + "mailboxID $ uid $ mail $ employeeNumber $ destinationIndicator $ " + + "internationaliSDNNumber $ preferredDeliveryMethod $ " + + "registeredAddress $ teletexTerminalIdentifier $ telexNumber $ " + + "x121Address $ businessCategory $ roomNumber $ x500UniqueIdentifier " + + ") X-NDS_NAMING ( 'cn' 'ou' 'uid' ) X-NDS_CONTAINMENT ( " + + "'Organization' 'organizationalUnit' 'domain' ) X-NDS_NAME " + + "'Organizational Person' X-NDS_NOT_CONTAINER '1' " + + "X-NDS_NONREMOVABLE '1' )" + + expect = { + :name => ["organizationalPerson"], + :sup => ["Person"], + :structural => ["TRUE"], + :x_nds_naming => ["cn", "ou", "uid"], + :x_nds_containment => ["Organization", "organizationalUnit", "domain"], + :x_nds_name => ["Organizational Person"], + :x_nds_not_container => ["1"], + :x_nds_nonremovable => ["1"], + } + assert_schema(expect, "organizationalPerson", + organizational_person_schema) + end + + priority :normal def test_text_oid text_oid_schema = "( mysite-oid NAME 'mysite' " + "SUP groupofuniquenames STRUCTURAL " + @@ -187,7 +246,7 @@ expect.each do |key, value| normalized_key = key.to_s.gsub(/_/, "-") normalized_expect[normalized_key] = value - actual[normalized_key] = schema.attr(sub, name, normalized_key) + actual[normalized_key] = schema[sub, name, normalized_key] end assert_equal(normalized_expect, actual) end From codesite-noreply at google.com Wed Apr 25 22:53:13 2007 From: codesite-noreply at google.com (codesite-noreply at google.com) Date: Wed, 25 Apr 2007 19:53:13 -0700 Subject: [Ruby-activeldap-commit] [ruby-activeldap commit] r156 - trunk/lib/active_ldap Message-ID: Author: koutou Date: Wed Apr 25 19:52:56 2007 New Revision: 156 Modified: trunk/lib/active_ldap/schema.rb Log: * added nil check. Modified: trunk/lib/active_ldap/schema.rb ============================================================================== --- trunk/lib/active_ldap/schema.rb (original) +++ trunk/lib/active_ldap/schema.rb Wed Apr 25 19:52:56 2007 @@ -268,10 +268,12 @@ def alias_map(group) ensure_parse(group) - @schema_info[group][:aliases] + return {} if @schema_info[group].nil? + @schema_info[group][:aliases] || {} end def ensure_parse(group) + return if @entries[group].nil? unless @entries[group].empty? attribute(group, 'nonexistent', 'nonexistent') end From codesite-noreply at google.com Thu Apr 26 21:34:00 2007 From: codesite-noreply at google.com (codesite-noreply at google.com) Date: Thu, 26 Apr 2007 18:34:00 -0700 Subject: [Ruby-activeldap-commit] [ruby-activeldap commit] r157 - trunk/lib/active_ldap Message-ID: Author: koutou Date: Thu Apr 26 18:33:41 2007 New Revision: 157 Modified: trunk/lib/active_ldap/base.rb Log: * improved default dn_attribute value of ldap_mapping. Modified: trunk/lib/active_ldap/base.rb ============================================================================== --- trunk/lib/active_ldap/base.rb (original) +++ trunk/lib/active_ldap/base.rb Thu Apr 26 18:33:41 2007 @@ -202,7 +202,6 @@ class << self # Hide new in Base private :new - private :dn_attribute # Connect and bind to LDAP creating a class variable for use by # all ActiveLdap objects. @@ -307,7 +306,14 @@ # :scope => :sub def ldap_mapping(options={}) validate_ldap_mapping_options(options) - dn_attribute = options[:dn_attribute] || default_dn_attribute + dn_attribute = options[:dn_attribute] + if dn_attribute.nil? + parent_class = ancestors[1] + if parent_class.respond_to?(:dn_attribute) + dn_attribute = parent_class.dn_attribute + end + dn_attribute ||= default_dn_attribute + end prefix = options[:prefix] || default_prefix classes = options[:classes] recommended_classes = options[:recommended_classes] @@ -320,7 +326,6 @@ self.recommended_classes = recommended_classes public_class_method :new - public_class_method :dn_attribute end alias_method :base_inheritable, :base @@ -428,7 +433,7 @@ # find # - # Finds the first match for value where |value| is the value of some + # Finds the first match for value where |value| is the value of some # |field|, or the wildcard match. This is only useful for derived classes. # usage: Subclass.find(:attribute => "cn", :value => "some*val") # Subclass.find('some*val') From codesite-noreply at google.com Thu Apr 26 21:51:07 2007 From: codesite-noreply at google.com (codesite-noreply at google.com) Date: Thu, 26 Apr 2007 18:51:07 -0700 Subject: [Ruby-activeldap-commit] [ruby-activeldap commit] r158 - in trunk: lib/active_ldap test Message-ID: Author: koutou Date: Thu Apr 26 18:50:46 2007 New Revision: 158 Modified: trunk/lib/active_ldap/distinguished_name.rb trunk/test/test_base.rb trunk/test/test_dn.rb Log: * normalized each value in DN when comparing DNs. Reported by James Hughes. Thanks! Modified: trunk/lib/active_ldap/distinguished_name.rb ============================================================================== --- trunk/lib/active_ldap/distinguished_name.rb (original) +++ trunk/lib/active_ldap/distinguished_name.rb Thu Apr 26 18:50:46 2007 @@ -217,7 +217,7 @@ rdns.collect do |rdn| normalized_rdn = {} rdn.each do |key, value| - normalized_rdn[key.upcase] = value + normalized_rdn[key.upcase] = value.upcase end normalized_rdn end Modified: trunk/test/test_base.rb ============================================================================== --- trunk/test/test_base.rb (original) +++ trunk/test/test_base.rb Thu Apr 26 18:50:46 2007 @@ -4,6 +4,15 @@ include AlTestUtils priority :must + def test_case_insensitive_nested_ou + ou_class("ou=Users").new("Sub").save! + make_temporary_user(:uid => "test-user,ou=SUB") do |user, password| + sub_user_class = Class.new(@user_class) + sub_user_class.ldap_mapping :prefix => "ou=sub" + assert_equal("uid=test-user,ou=sub,#{@user_class.base}", + sub_user_class.find(user.uid).dn) + end + end priority :normal def test_nested_ou Modified: trunk/test/test_dn.rb ============================================================================== --- trunk/test/test_dn.rb (original) +++ trunk/test/test_dn.rb Thu Apr 26 18:50:46 2007 @@ -10,6 +10,11 @@ end priority :must + def test_case_insensitive_dn_minus + assert_dn_minus("dc=xxx", "dc=xxx,dc=LoCaL,dc=net", "dc=LOCAL,dc=net") + end + + priority :normal def test_dn_hash dn1 = ActiveLdap::DN.parse("o=xxx,dc=local,dc=net") dn2 = ActiveLdap::DN.parse("O = xxx , DC = local , DC = net") From codesite-noreply at google.com Fri Apr 27 00:07:08 2007 From: codesite-noreply at google.com (codesite-noreply at google.com) Date: Thu, 26 Apr 2007 21:07:08 -0700 Subject: [Ruby-activeldap-commit] [ruby-activeldap commit] r159 - in trunk: lib/active_ldap test Message-ID: <163600d406042f1044dcdb211c7d3@google.com> Author: koutou Date: Thu Apr 26 21:06:51 2007 New Revision: 159 Modified: trunk/lib/active_ldap/object_class.rb trunk/test/test_object_class.rb Log: * added ActiveLdap::ObjectClass#ensure_recommended_classes. Modified: trunk/lib/active_ldap/object_class.rb ============================================================================== --- trunk/lib/active_ldap/object_class.rb (original) +++ trunk/lib/active_ldap/object_class.rb Thu Apr 26 21:06:51 2007 @@ -11,16 +11,20 @@ replace_class((classes + target_classes.flatten).uniq) end + def ensure_recommended_classes + add_class(self.class.recommended_classes) + end + def remove_class(*target_classes) - new_classes = (classes - target_classes.flatten).uniq - assert_object_classes(new_classes) - set_attribute('objectClass', new_classes) + replace_class((classes - target_classes.flatten).uniq) end def replace_class(*target_classes) new_classes = target_classes.flatten.uniq assert_object_classes(new_classes) - set_attribute('objectClass', new_classes) + if new_classes.sort != classes.sort + set_attribute('objectClass', new_classes) + end end def classes Modified: trunk/test/test_object_class.rb ============================================================================== --- trunk/test/test_object_class.rb (original) +++ trunk/test/test_object_class.rb Thu Apr 26 21:06:51 2007 @@ -4,6 +4,21 @@ include AlTestUtils priority :must + def test_ensure_recommended_classes + make_temporary_group do |group| + added_class = "room" + + assert_equal([], group.class.recommended_classes) + group.class.recommended_classes << added_class + assert_equal([added_class], group.class.recommended_classes) + + assert_equal([added_class], + group.class.recommended_classes - group.classes) + group.ensure_recommended_classes + assert_equal([], + group.class.recommended_classes - group.classes) + end + end priority :normal def test_unknown_object_class From codesite-noreply at google.com Fri Apr 27 08:19:03 2007 From: codesite-noreply at google.com (codesite-noreply at google.com) Date: Fri, 27 Apr 2007 05:19:03 -0700 Subject: [Ruby-activeldap-commit] [ruby-activeldap commit] r160 - trunk/lib/active_ldap Message-ID: Author: koutou Date: Fri Apr 27 05:18:47 2007 New Revision: 160 Modified: trunk/lib/active_ldap/base.rb Log: * cleanup. Modified: trunk/lib/active_ldap/base.rb ============================================================================== --- trunk/lib/active_ldap/base.rb (original) +++ trunk/lib/active_ldap/base.rb Fri Apr 27 05:18:47 2007 @@ -306,14 +306,7 @@ # :scope => :sub def ldap_mapping(options={}) validate_ldap_mapping_options(options) - dn_attribute = options[:dn_attribute] - if dn_attribute.nil? - parent_class = ancestors[1] - if parent_class.respond_to?(:dn_attribute) - dn_attribute = parent_class.dn_attribute - end - dn_attribute ||= default_dn_attribute - end + dn_attribute = options[:dn_attribute] || default_dn_attribute prefix = options[:prefix] || default_prefix classes = options[:classes] recommended_classes = options[:recommended_classes] @@ -727,7 +720,12 @@ def default_dn_attribute if name.empty? - "cn" + dn_attribute = nil + parent_class = ancestors[1] + if parent_class.respond_to?(:dn_attribute) + dn_attribute = parent_class.dn_attribute + end + dn_attribute || "cn" else Inflector.underscore(Inflector.demodulize(name)) end