Skip to content

Commit c06f0b0

Browse files
author
Dave Sims
committed
Test for iterating over domain controllers
1 parent a799cc4 commit c06f0b0

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

test/forest_search_test.rb

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,29 @@ def test_uses_connection_search_when_domains_nil
2828
@forest_search.search({})
2929
end
3030

31+
def test_iterates_over_domain_controllers_when_forest_present
32+
mock_domains = Object.new
33+
mock_domain_controller = Object.new
34+
35+
# Mock out two Domain Controller connections (Net::LDAP objects)
36+
mock_dc_connection1 = Object.new
37+
mock_dc_connection2 = Object.new
38+
rootdn = "DC=ad,DC=ghe,DC=local"
39+
# Create a mock forest that contains the two mock DCs
40+
# This assumes a single-l
41+
forest = [[rootdn, mock_dc_connection1],[rootdn, mock_dc_connection2]]
42+
43+
# First search returns the Hash of domain controllers
44+
# This is what the forest is built from.
45+
@connection.expects(:search).returns(mock_domains)
46+
mock_domains.expects(:each_with_object).returns(forest)
47+
48+
# Then we expect that a search will be performed on the LDAP object
49+
# created from the returned forest of domain controllers
50+
mock_dc_connection1.expects(:search)
51+
mock_dc_connection2.expects(:search)
52+
base = "CN=user1,CN=Users,DC=ad,DC=ghe,DC=local"
53+
@forest_search.search({:base => base})
54+
end
55+
3156
end

0 commit comments

Comments
 (0)