1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
|
Description: Changed protected run/user/ directory to /tmp to fix crashes
Author: Josenilson Ferreira da Silva <nilsonfsilva@hotmail.com>
Forwarded: not-needed
Last-Update: 2024-12-04
Index: python-proton-vpn-api-core/tests/connection/test_vpnconfiguration.py
===================================================================
--- python-proton-vpn-api-core.orig/tests/connection/test_vpnconfiguration.py
+++ python-proton-vpn-api-core/tests/connection/test_vpnconfiguration.py
@@ -20,6 +20,8 @@ import os
import pytest
+import tempfile
+
from proton.vpn.connection import VPNServer, ProtocolPorts
from proton.vpn.connection.vpnconfiguration import VPNConfiguration
@@ -40,12 +42,11 @@ def teardown_module(module):
@pytest.fixture
-def modified_exec_env():
+def modified_exec_env(monkeypatch):
from proton.utils.environment import ExecutionEnvironment
- m = ExecutionEnvironment().path_runtime
- ExecutionEnvironment.path_runtime = VPNCONFIG_DIR
- yield ExecutionEnvironment().path_runtime
- ExecutionEnvironment.path_runtime = m
+ with tempfile.TemporaryDirectory() as temp_dir:
+ monkeypatch.setattr(ExecutionEnvironment, "path_runtime", temp_dir)
+ yield
@pytest.fixture
@@ -83,31 +84,33 @@ def test_ensure_configuration_file_is_cr
assert os.path.isfile(f)
-def test_ensure_configuration_file_is_deleted(vpn_server):
+def test_ensure_configuration_file_is_deleted(monkeypatch, vpn_server):
+ monkeypatch.setattr(
+ "proton.utils.environment.ExecutionEnvironment.path_runtime",
+ tempfile.mkdtemp()
+ )
cfg = MockVpnConfiguration(vpn_server, MockVpnCredentials(), MockSettings())
- fp = None
with cfg as f:
- fp = f
- assert os.path.isfile(fp)
-
- assert not os.path.isfile(fp)
+ assert os.path.isfile(f)
+ assert not os.path.isfile(f)
-def test_ensure_generate_is_returning_expected_content(vpn_server):
+def test_ensure_generate_is_returning_expected_content(monkeypatch, vpn_server):
+ temp_dir = tempfile.mkdtemp()
+ monkeypatch.setattr("proton.utils.environment.ExecutionEnvironment.path_runtime", temp_dir)
cfg = MockVpnConfiguration(vpn_server, MockVpnCredentials(), MockSettings())
- with cfg as f:
- with open(f) as _f:
- line = _f.readline()
- _cfg = MockVpnConfiguration(vpn_server, MockVpnCredentials(), MockSettings())
- assert line == _cfg.generate()
+ with cfg as f, open(f) as _f:
+ assert _f.readline() == MockVpnConfiguration(vpn_server, MockVpnCredentials(), MockSettings()).generate()
-def test_ensure_same_configuration_file_in_case_of_duplicate(vpn_server):
+def test_ensure_same_configuration_file_in_case_of_duplicate(monkeypatch, vpn_server):
+ monkeypatch.setattr(
+ "proton.utils.environment.ExecutionEnvironment.path_runtime",
+ tempfile.mkdtemp()
+ )
cfg = MockVpnConfiguration(vpn_server, MockVpnCredentials(), MockSettings())
- with cfg as f:
- with cfg as _f:
- assert os.path.isfile(f) and os.path.isfile(_f) and f == _f
-
+ with cfg as f, cfg as _f:
+ assert os.path.isfile(f) and os.path.isfile(_f) and f == _f
@pytest.mark.parametrize(
"expected_mask, cidr", [
|