Ejemplo n.º 1
0
    def test_waiting_on_managment_port_failing(self):
        server = ManagmentServer(failing=True)
        server.listen(55667)

        with patch.object(OpenVPN, "_get_free_port", MagicMock(return_value=55667)):
            vpn = OpenVPN(host="")
            self.assertFalse(vpn.wait_for_openvpn_to_connect(wait_between_retries=0.1, retries=3))
Ejemplo n.º 2
0
    def test_crafting_openvpn_args(self):
        vpn = OpenVPN(
            binary="/usr/bin/openvpn",
            ca="hey.ca",
            key="hey.key",
            cert="hey.cert",
            host="vova.com",
            port=55669
        )

        expectedResults = [
            "/usr/bin/openvpn",
            "--management", "localhost", str(self.FREE_PORT),
            "--remote", "vova.com", "55669",

            "--client",
            "--route-metric", "1",
            "--ns-cert-type", "server",
            "--proto", "tcp",
            "--dev", "tun",
            "--resolv-retry", "infinite",
            "--ping-exit", "90",
            "--ca", "hey.ca",
            "--cert", "hey.cert",
            "--key", "hey.key",
        ]

        self.assertEqual(vpn.command(), expectedResults)
Ejemplo n.º 3
0
    def test_waiting_on_managment_port(self):
        server = ManagmentServer(failing=False)
        server.listen(55669)

        with patch.object(OpenVPN, "_get_free_port", MagicMock(return_value=55669)):
            vpn = OpenVPN(host="")
            self.assertTrue(vpn.wait_for_openvpn_to_connect(wait_between_retries=0.1))
            self.assertTrue(vpn.get_peer_address(), "154.70.152.238")
Ejemplo n.º 4
0
    def test_kwargs_expanding(self):
        vpn = OpenVPN(
            host="",
            foo="",
            pita="pita_arg",
            baba="baba_arg",
        )

        self.assertEqual(vpn.expand_kwargs(),
                         ["--baba", "baba_arg", "--pita", "pita_arg", "--foo"])
Ejemplo n.º 5
0
    def test_waiting_on_managment_port_failing(self):
        server = ManagmentServer(failing=True)
        server.listen(55667)

        with patch.object(OpenVPN, "_get_free_port",
                          MagicMock(return_value=55667)):
            vpn = OpenVPN(host="")
            self.assertFalse(
                vpn.wait_for_openvpn_to_connect(wait_between_retries=0.1,
                                                retries=3))
Ejemplo n.º 6
0
    def test_waiting_on_managment_port(self):
        server = ManagmentServer(failing=False)
        server.listen(55669)

        with patch.object(OpenVPN, "_get_free_port",
                          MagicMock(return_value=55669)):
            vpn = OpenVPN(host="")
            self.assertTrue(
                vpn.wait_for_openvpn_to_connect(wait_between_retries=0.1))
            self.assertTrue(vpn.get_peer_address(), "154.70.152.238")
Ejemplo n.º 7
0
    def test_kwargs_expanding(self):
        vpn = OpenVPN(
            host="",
            foo="",
            pita="pita_arg",
            baba="baba_arg",
        )

        self.assertEqual(
            vpn.expand_kwargs(),
            ["--baba", "baba_arg", "--pita", "pita_arg", "--foo"]
        )
Ejemplo n.º 8
0
    def test_crafting_openvpn_args(self):
        vpn = OpenVPN(binary="/usr/bin/openvpn",
                      ca="hey.ca",
                      key="hey.key",
                      cert="hey.cert",
                      host="vova.com",
                      port=55669)

        expectedResults = [
            "/usr/bin/openvpn",
            "--management",
            "localhost",
            str(self.FREE_PORT),
            "--remote",
            "vova.com",
            "55669",
            "--client",
            "--route-metric",
            "1",
            "--ns-cert-type",
            "server",
            "--proto",
            "tcp",
            "--dev",
            "tun",
            "--resolv-retry",
            "infinite",
            "--ping-exit",
            "90",
            "--ca",
            "hey.ca",
            "--cert",
            "hey.cert",
            "--key",
            "hey.key",
        ]

        self.assertEqual(vpn.command(), expectedResults)