Ejemplo n.º 1
0
  def testEnumerateInterfaces(self):
    # Stub out wmi.WMI().Win32_NetworkAdapterConfiguration()
    wmi_object = self.windows.wmi.WMI.return_value
    wmi_object.Win32_NetworkAdapterConfiguration.return_value = [
        client_test_lib.WMIWin32NetworkAdapterConfigurationMock()
    ]

    enumif = self.windows.EnumerateInterfaces()

    replies = []

    def Collect(reply):
      replies.append(reply)

    enumif.SendReply = Collect
    enumif.Run(None)

    self.assertEqual(len(replies), 1)
    interface = replies[0]
    self.assertEqual(len(interface.addresses), 4)
    addresses = [x.human_readable_address for x in interface.addresses]
    self.assertItemsEqual(addresses, [
        "192.168.1.20", "ffff::ffff:aaaa:1111:aaaa",
        "dddd:0:8888:6666:bbbb:aaaa:eeee:bbbb",
        "dddd:0:8888:6666:bbbb:aaaa:ffff:bbbb"
    ])
Ejemplo n.º 2
0
    def testEnumerateInterfaces(self):
        # Stub out wmi.WMI().Win32_NetworkAdapterConfiguration(IPEnabled=1)
        wmi_object = self.windows.wmi.WMI.return_value
        wmi_object.Win32_NetworkAdapterConfiguration.return_value = [
            client_test_lib.WMIWin32NetworkAdapterConfigurationMock()
        ]

        enumif = self.windows.EnumerateInterfaces()
        interface_dict_list = list(enumif.RunNetAdapterWMIQuery())

        self.assertEqual(len(interface_dict_list), 1)
        interface = interface_dict_list[0]
        self.assertEqual(len(interface["addresses"]), 4)
        addresses = [x.human_readable_address for x in interface["addresses"]]
        self.assertItemsEqual(addresses, [
            "192.168.1.20", "ffff::ffff:aaaa:1111:aaaa",
            "dddd:0:8888:6666:bbbb:aaaa:eeee:bbbb",
            "dddd:0:8888:6666:bbbb:aaaa:ffff:bbbb"
        ])
Ejemplo n.º 3
0
    def testEnumerateInterfacesMock(self):
        # Stub out wmi.WMI().Win32_NetworkAdapterConfiguration()
        wmi = mock.MagicMock()
        wmi.Win32_NetworkAdapterConfiguration.return_value = [
            client_test_lib.WMIWin32NetworkAdapterConfigurationMock()
        ]

        replies = []
        with mock.patch.object(windows.wmi, "WMI", return_value=wmi):
            enumif = windows.EnumerateInterfaces()
            enumif.SendReply = replies.append
            enumif.Run(None)

        self.assertLen(replies, 1)
        interface = replies[0]
        self.assertLen(interface.addresses, 4)
        addresses = [x.human_readable_address for x in interface.addresses]
        self.assertCountEqual(addresses, [
            "192.168.1.20", "ffff::ffff:aaaa:1111:aaaa",
            "dddd:0:8888:6666:bbbb:aaaa:eeee:bbbb",
            "dddd:0:8888:6666:bbbb:aaaa:ffff:bbbb"
        ])