pmb.helpers.run_core: fix proxy env var logic
Fix that the list "cmd" was turned into a string if one of the proxy
vars was set in the environment. Add a test for this code path. Before
this patch:
$ FTP_PROXY=test pmbootstrap -v --details-to-stdout status
…
% cd /home/user/.local/var/pmbootstrap/cache_git/pmaports; git remote -v
run: FTP_PROXY=test ['git', 'remote', '-v']
ERROR: [Errno 2] No such file or directory: "FTP_PROXY=test ['git', 'remote', '-v']"
Fixes: 1a00c04f
("pmb.helpers.run_core: always configure proxy vars if set in environment")
Reviewed-by: Clayton Craft <clayton@craftyguy.net>
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C20230713182337.6185-3-ollieparanoid@postmarketos.org%3E
This commit is contained in:
parent
20a0ccf36f
commit
13c4ac425b
|
@ -1,6 +1,5 @@
|
|||
# Copyright 2023 Oliver Smith
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
import shlex
|
||||
import pmb.helpers.run_core
|
||||
|
||||
|
||||
|
|
|
@ -341,11 +341,13 @@ def core(args, log_message, cmd, working_dir=None, output="log",
|
|||
sanity_checks(output, output_return, check)
|
||||
|
||||
# Preserve proxy environment variables
|
||||
env = {}
|
||||
for var in ["FTP_PROXY", "ftp_proxy", "HTTP_PROXY", "http_proxy",
|
||||
"HTTPS_PROXY", "https_proxy", "HTTP_PROXY_AUTH"]:
|
||||
if var in os.environ:
|
||||
# Prepend setting var to cmd string
|
||||
cmd = f"{var}={os.environ[var]} {cmd}"
|
||||
env[var] = os.environ[var]
|
||||
if env:
|
||||
cmd = ["sh", "-c", flat_cmd(cmd, env=env)]
|
||||
|
||||
if args.sudo_timer and sudo:
|
||||
sudo_timer_start()
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
# Copyright 2023 Oliver Smith
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
""" Test pmb.helpers.run_core """
|
||||
import re
|
||||
import sys
|
||||
import subprocess
|
||||
import os
|
||||
import pytest
|
||||
import re
|
||||
import subprocess
|
||||
import sys
|
||||
import time
|
||||
|
||||
import pmb_test # noqa
|
||||
|
@ -127,7 +128,7 @@ def test_foreground_tui():
|
|||
assert func(["echo", "test"]) == 0
|
||||
|
||||
|
||||
def test_core(args):
|
||||
def test_core(args, monkeypatch):
|
||||
# Background
|
||||
func = pmb.helpers.run_core.core
|
||||
msg = "test"
|
||||
|
@ -157,6 +158,11 @@ def test_core(args):
|
|||
func(args, msg, ["sleep", "1"], output="log")
|
||||
assert re.search(r"^Command failed \(exit code -?\d*\): ", str(e.value))
|
||||
|
||||
# Preserve proxy environment variables
|
||||
monkeypatch.setattr(os, "environ", {"FTP_PROXY": "testproxy"})
|
||||
ret = func(args, msg, ["sh", "-c", 'echo "$FTP_PROXY"'], output_return=True)
|
||||
assert ret == "testproxy\n"
|
||||
|
||||
|
||||
@pytest.mark.skip_ci
|
||||
def test_sudo_timer(args):
|
||||
|
|
Loading…
Reference in New Issue