ProtonVPN / python-proton-vpn-api-core

GNU General Public License v3.0
12 stars 4 forks source link

Some tests failed in container environments #4

Open guoyunhe opened 2 weeks ago

guoyunhe commented 2 weeks ago

We are happy to answer your questions about the code or discuss technical ideas.

Please complete the following checklist (by adding [x]):


I am trying to updating this package on openSUSE RPM repository. Some of the tests are failing because the code cannot access /var/user in the container environment:

[    6s] tests/connection/test_vpnconfiguration.py:111: 
[    6s] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
[    6s] proton/vpn/connection/vpnconfiguration.py:64: in __enter__
[    6s]     self._delete_existing_configuration()
[    6s] proton/vpn/connection/vpnconfiguration.py:89: in _delete_existing_configuration
[    6s]     for file in self.__base_path:
[    6s] proton/vpn/connection/vpnconfiguration.py:99: in __base_path
[    6s]     return ExecutionEnvironment().path_runtime
[    6s] /usr/lib/python3.10/site-packages/proton/utils/environment.py:57: in path_runtime
[    6s]     self.generate_dirs(self._path_runtime)
[    6s] /usr/lib/python3.10/site-packages/proton/utils/environment.py:68: in generate_dirs
[    6s]     os.makedirs(path, mode=0o700, exist_ok=True)
[    6s] /usr/lib64/python3.10/os.py:215: in makedirs
[    6s]     makedirs(head, exist_ok=exist_ok)
[    6s] /usr/lib64/python3.10/os.py:215: in makedirs
[    6s]     makedirs(head, exist_ok=exist_ok)
[    6s] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
[    6s] 
[    6s] name = '/run/user', mode = 511, exist_ok = True
[    6s] 
[    6s]     def makedirs(name, mode=0o777, exist_ok=False):
[    6s]         """makedirs(name [, mode=0o777][, exist_ok=False])
[    6s]     
[    6s]         Super-mkdir; create a leaf directory and all intermediate ones.  Works like
[    6s]         mkdir, except that any intermediate path segment (not just the rightmost)
[    6s]         will be created if it does not exist. If the target directory already
[    6s]         exists, raise an OSError if exist_ok is False. Otherwise no exception is
[    6s]         raised.  This is recursive.
[    6s]     
[    6s]         """
[    6s]         head, tail = path.split(name)
[    6s]         if not tail:
[    6s]             head, tail = path.split(head)
[    6s]         if head and tail and not path.exists(head):
[    6s]             try:
[    6s]                 makedirs(head, exist_ok=exist_ok)
[    6s]             except FileExistsError:
[    6s]                 # Defeats race condition when another thread created the path
[    6s]                 pass
[    6s]             cdir = curdir
[    6s]             if isinstance(tail, bytes):
[    6s]                 cdir = bytes(curdir, 'ASCII')
[    6s]             if tail == cdir:           # xxx/newdir/. exists if xxx/newdir exists
[    6s]                 return
[    6s]         try:
[    6s] >           mkdir(name, mode)
[    6s] E           PermissionError: [Errno 13] Permission denied: '/run/user'
[    6s] 
[    6s] /usr/lib64/python3.10/os.py:225: PermissionError

Any idea how to fix it?

alexandrevicenzi commented 2 days ago

Adding something like the following to DummyVPNConnection might fix the issue.

def __base_path(self):
    return "/tmp/some/path/"

The problem is that OBS does not allow access to certain things outside the build directory, so a patch needs to be added to the package.

I did not test this, but I can test it later and submit an SR.