Skip to content

Commit

Permalink
Merge pull request #373 from ruby-ldap/test-delete-tree
Browse files Browse the repository at this point in the history
Add test_delete_tree
  • Loading branch information
HarlemSquirrel committed Aug 24, 2020
2 parents 387d6e6 + 5893284 commit d95697c
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ Metrics/BlockNesting:
# Offense count: 11
# Configuration parameters: CountComments.
Metrics/ClassLength:
Max: 429
Max: 445

# Offense count: 23
Metrics/CyclomaticComplexity:
Expand Down
4 changes: 2 additions & 2 deletions lib/net/ldap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1351,14 +1351,14 @@ def normalize_encryption(args)
# Recursively delete a dn and it's subordinate children.
# This is useful when a server does not support the DELETE_TREE control code.
def recursive_delete(args)
raise EmptyDNError unless args.is_a?(Hash) && args.has_key?(:dn)
raise EmptyDNError unless args.is_a?(Hash) && args.key?(:dn)
# Delete Children
search(base: args[:dn], scope: Net::LDAP::SearchScope_SingleLevel) do |entry|
recursive_delete(dn: entry.dn)
end
# Delete Self
unless delete(dn: args[:dn])
raise Net::LDAP::Error, self.get_operation_result[:error_message].to_s
raise Net::LDAP::Error, get_operation_result[:error_message].to_s
end
true
end
Expand Down
33 changes: 33 additions & 0 deletions test/integration/test_delete.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,29 @@ def setup
assert @ldap.add(dn: @dn, attributes: attrs), @ldap.get_operation_result.inspect
end
assert @ldap.search(base: @dn, scope: Net::LDAP::SearchScope_BaseObject)

@parent_dn = "uid=parent,ou=People,dc=example,dc=org"
parent_attrs = {
objectclass: %w(top inetOrgPerson organizationalPerson person),
uid: "parent",
cn: "parent",
sn: "parent",
mail: "parent@rubyldap.com",
}
@child_dn = "uid=child,uid=parent,ou=People,dc=example,dc=org"
child_attrs = {
objectclass: %w(top inetOrgPerson organizationalPerson person),
uid: "child",
cn: "child",
sn: "child",
mail: "child@rubyldap.com",
}
unless @ldap.search(base: @parent_dn, scope: Net::LDAP::SearchScope_BaseObject)
assert @ldap.add(dn: @parent_dn, attributes: parent_attrs), @ldap.get_operation_result.inspect
assert @ldap.add(dn: @child_dn, attributes: child_attrs), @ldap.get_operation_result.inspect
end
assert @ldap.search(base: @parent_dn, scope: Net::LDAP::SearchScope_BaseObject)
assert @ldap.search(base: @child_dn, scope: Net::LDAP::SearchScope_BaseObject)
end

def test_delete
Expand All @@ -26,4 +49,14 @@ def test_delete
assert_equal Net::LDAP::ResultCodeNoSuchObject, result.code
assert_equal Net::LDAP::ResultStrings[Net::LDAP::ResultCodeNoSuchObject], result.message
end

def test_delete_tree
assert @ldap.delete_tree(dn: @parent_dn), @ldap.get_operation_result.inspect
refute @ldap.search(base: @parent_dn, scope: Net::LDAP::SearchScope_BaseObject)
refute @ldap.search(base: @child_dn, scope: Net::LDAP::SearchScope_BaseObject)

result = @ldap.get_operation_result
assert_equal Net::LDAP::ResultCodeNoSuchObject, result.code
assert_equal Net::LDAP::ResultStrings[Net::LDAP::ResultCodeNoSuchObject], result.message
end
end

0 comments on commit d95697c

Please sign in to comment.