@@ -28,4 +28,29 @@ def test_uses_connection_search_when_domains_nil
28
28
@forest_search . search ( { } )
29
29
end
30
30
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
+
31
56
end
0 commit comments