def test_open():
    w = WinDivert("false")
    w.open()
    assert w.is_open
    w.close()
    assert not w.is_open

    with w:
        # open a second one.
        with WinDivert("false") as w2:
            assert w2.is_open

        assert w.is_open
        assert "open" in repr(w)

        with pytest.raises(RuntimeError):
            w.open()

    assert not w.is_open
    assert "closed" in repr(w)

    with pytest.raises(RuntimeError):
        w.recv()
    with pytest.raises(RuntimeError):
        w.close()
def test_open():
    w = WinDivert("false")
    w.open()
    assert w.is_open
    w.close()
    assert not w.is_open

    with w:
        # open a second one.
        with WinDivert("false") as w2:
            assert w2.is_open

        assert w.is_open
        assert "open" in repr(w)

        with pytest.raises(RuntimeError):
            w.open()

    assert not w.is_open
    assert "closed" in repr(w)

    with pytest.raises(RuntimeError):
        w.recv()
    with pytest.raises(RuntimeError):
        w.close()
Exemple #3
0
 def test_open_handle(self):
     """
     Tests the open_handle method.
     """
     handle = WinDivert(self.dll_path).open_handle(filter="tcp.DstPort == 23", priority=1000)
     self.assertIsInstance(handle, Handle)
     self.assertTrue(handle.is_opened)
     handle.close()
     self.assertFalse(handle.is_opened)
def test_unregister():
    w = WinDivert("false")
    w.open()
    WinDivert.unregister()
    time.sleep(0.1)
    assert WinDivert.is_registered()
    w.close()
    # may not trigger immediately.
    while WinDivert.is_registered():
        time.sleep(0.01)  # pragma: no cover
def test_unregister():
    w = WinDivert("false")
    w.open()
    WinDivert.unregister()
    time.sleep(0.1)
    assert WinDivert.is_registered()
    w.close()
    # may not trigger immediately.
    while WinDivert.is_registered():
        time.sleep(0.01)  # pragma: no cover
Exemple #6
0
 def test_open_handle(self):
     """
     Tests the open_handle method.
     """
     # with cd(os.path.dirname(self.dll_path)):
     handle = WinDivert(self.dll_path).open_handle(filter="tcp.DstPort == 23")
     self.assertIsInstance(handle, Handle)
     self.assertTrue(handle.is_opened)
     handle.close()
     self.assertFalse(handle.is_opened)
Exemple #7
0
 def test_open_handle(self):
     """
     Tests the open_handle method.
     """
     # with cd(os.path.dirname(self.dll_path)):
     handle = WinDivert().open_handle(filter="tcp.DstPort == 23")
     assert isinstance(handle, Handle)
     assert handle.is_opened
     handle.close()
     assert not handle.is_opened
Exemple #8
0
 def test_open_handle(self):
     """
     Tests the open_handle method.
     """
     handle = WinDivert(self.dll_path).open_handle(
         filter="tcp.DstPort == 23", priority=1000)
     self.assertIsInstance(handle, Handle)
     self.assertTrue(handle.is_opened)
     handle.close()
     self.assertFalse(handle.is_opened)
Exemple #9
0
 def test_open_handle(self):
     """
     Tests the open_handle method.
     """
     # with cd(os.path.dirname(self.dll_path)):
     handle = WinDivert(
         self.dll_path).open_handle(filter="tcp.DstPort == 23")
     self.assertIsInstance(handle, Handle)
     self.assertTrue(handle.is_opened)
     handle.close()
     self.assertFalse(handle.is_opened)