From a9c2e309088ee81cafb5670a51cc35cdd026f7b1 Mon Sep 17 00:00:00 2001 From: Alexander Piskun <13381981+bigcat88@users.noreply.github.com> Date: Mon, 21 Aug 2023 21:30:33 +0300 Subject: [PATCH] fixed bug when `options.NPA_NC_CERT=False` (#93) Was incorrect handling, as values in environment variables are strings. --------- Signed-off-by: Alexander Piskun --- .github/workflows/analysis-coverage.yml | 2 ++ nc_py_api/options.py | 8 +++++++- pyproject.toml | 1 + tests/options_test.py | 10 ++++++++++ 4 files changed, 20 insertions(+), 1 deletion(-) diff --git a/.github/workflows/analysis-coverage.yml b/.github/workflows/analysis-coverage.yml index fc576158..d9d2a2a9 100644 --- a/.github/workflows/analysis-coverage.yml +++ b/.github/workflows/analysis-coverage.yml @@ -688,6 +688,7 @@ jobs: run: coverage run -m pytest && coverage xml && coverage html env: SKIP_AE_TESTS: 1 + NPA_NC_CERT: '' - name: HTML coverage to artifacts uses: actions/upload-artifact@v3 @@ -821,6 +822,7 @@ jobs: env: NPA_TIMEOUT: None NPA_TIMEOUT_DAV: None + NPA_NC_CERT: False - name: HTML coverage to artifacts uses: actions/upload-artifact@v3 diff --git a/nc_py_api/options.py b/nc_py_api/options.py index 5729b24b..931be3ff 100644 --- a/nc_py_api/options.py +++ b/nc_py_api/options.py @@ -27,8 +27,14 @@ except (TypeError, ValueError): NPA_TIMEOUT_DAV = None -NPA_NC_CERT = environ.get("NPA_NC_CERT", True) +NPA_NC_CERT: typing.Union[bool, str] """Option to enable/disable Nextcloud certificate verification. SSL certificates (a.k.a CA bundle) used to verify the identity of requested hosts. Either **True** (default CA bundle), a path to an SSL certificate file, or **False** (which will disable verification).""" +str_val = environ.get("NPA_NC_CERT", "True") +NPA_NC_CERT = True +if str_val.lower() in ("false", "0"): + NPA_NC_CERT = False +elif str_val.lower() not in ("true", "1"): + NPA_NC_CERT = str_val diff --git a/pyproject.toml b/pyproject.toml index 62803307..f66177ad 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -181,4 +181,5 @@ messages_control.disable = [ "missing-function-docstring", "line-too-long", "too-few-public-methods", + "too-many-public-methods", ] diff --git a/tests/options_test.py b/tests/options_test.py index 1473dfcf..d6319cf8 100644 --- a/tests/options_test.py +++ b/tests/options_test.py @@ -35,6 +35,16 @@ def test_timeouts(): env_f.write("NPA_TIMEOUT_DAV=11") r = run(check_command, stderr=PIPE, env={}, cwd=project_dir, check=False) assert not r.stderr + check_command = [sys.executable, "-c", "import nc_py_api\nassert nc_py_api.options.NPA_NC_CERT is False"] + with open(env_file, "w") as env_f: + env_f.write("NPA_NC_CERT=False") + r = run(check_command, stderr=PIPE, env={}, cwd=project_dir, check=False) + assert not r.stderr + check_command = [sys.executable, "-c", "import nc_py_api\nassert nc_py_api.options.NPA_NC_CERT == ''"] + with open(env_file, "w") as env_f: + env_f.write('NPA_NC_CERT=""') + r = run(check_command, stderr=PIPE, env={}, cwd=project_dir, check=False) + assert not r.stderr finally: if os.path.exists(env_backup_file): os.rename(env_backup_file, env_file)