Skip to content

Commit d95697c

Browse files
Merge pull request #373 from ruby-ldap/test-delete-tree
Add test_delete_tree
2 parents 387d6e6 + 5893284 commit d95697c

File tree

3 files changed

+36
-3
lines changed

3 files changed

+36
-3
lines changed

.rubocop_todo.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ Metrics/BlockNesting:
221221
# Offense count: 11
222222
# Configuration parameters: CountComments.
223223
Metrics/ClassLength:
224-
Max: 429
224+
Max: 445
225225

226226
# Offense count: 23
227227
Metrics/CyclomaticComplexity:

lib/net/ldap.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -1351,14 +1351,14 @@ def normalize_encryption(args)
13511351
# Recursively delete a dn and it's subordinate children.
13521352
# This is useful when a server does not support the DELETE_TREE control code.
13531353
def recursive_delete(args)
1354-
raise EmptyDNError unless args.is_a?(Hash) && args.has_key?(:dn)
1354+
raise EmptyDNError unless args.is_a?(Hash) && args.key?(:dn)
13551355
# Delete Children
13561356
search(base: args[:dn], scope: Net::LDAP::SearchScope_SingleLevel) do |entry|
13571357
recursive_delete(dn: entry.dn)
13581358
end
13591359
# Delete Self
13601360
unless delete(dn: args[:dn])
1361-
raise Net::LDAP::Error, self.get_operation_result[:error_message].to_s
1361+
raise Net::LDAP::Error, get_operation_result[:error_message].to_s
13621362
end
13631363
true
13641364
end

test/integration/test_delete.rb

+33
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,29 @@ def setup
1616
assert @ldap.add(dn: @dn, attributes: attrs), @ldap.get_operation_result.inspect
1717
end
1818
assert @ldap.search(base: @dn, scope: Net::LDAP::SearchScope_BaseObject)
19+
20+
@parent_dn = "uid=parent,ou=People,dc=example,dc=org"
21+
parent_attrs = {
22+
objectclass: %w(top inetOrgPerson organizationalPerson person),
23+
uid: "parent",
24+
cn: "parent",
25+
sn: "parent",
26+
mail: "parent@rubyldap.com",
27+
}
28+
@child_dn = "uid=child,uid=parent,ou=People,dc=example,dc=org"
29+
child_attrs = {
30+
objectclass: %w(top inetOrgPerson organizationalPerson person),
31+
uid: "child",
32+
cn: "child",
33+
sn: "child",
34+
mail: "child@rubyldap.com",
35+
}
36+
unless @ldap.search(base: @parent_dn, scope: Net::LDAP::SearchScope_BaseObject)
37+
assert @ldap.add(dn: @parent_dn, attributes: parent_attrs), @ldap.get_operation_result.inspect
38+
assert @ldap.add(dn: @child_dn, attributes: child_attrs), @ldap.get_operation_result.inspect
39+
end
40+
assert @ldap.search(base: @parent_dn, scope: Net::LDAP::SearchScope_BaseObject)
41+
assert @ldap.search(base: @child_dn, scope: Net::LDAP::SearchScope_BaseObject)
1942
end
2043

2144
def test_delete
@@ -26,4 +49,14 @@ def test_delete
2649
assert_equal Net::LDAP::ResultCodeNoSuchObject, result.code
2750
assert_equal Net::LDAP::ResultStrings[Net::LDAP::ResultCodeNoSuchObject], result.message
2851
end
52+
53+
def test_delete_tree
54+
assert @ldap.delete_tree(dn: @parent_dn), @ldap.get_operation_result.inspect
55+
refute @ldap.search(base: @parent_dn, scope: Net::LDAP::SearchScope_BaseObject)
56+
refute @ldap.search(base: @child_dn, scope: Net::LDAP::SearchScope_BaseObject)
57+
58+
result = @ldap.get_operation_result
59+
assert_equal Net::LDAP::ResultCodeNoSuchObject, result.code
60+
assert_equal Net::LDAP::ResultStrings[Net::LDAP::ResultCodeNoSuchObject], result.message
61+
end
2962
end

0 commit comments

Comments
 (0)