Skip to content

Commit

Permalink
fixed bug when options.NPA_NC_CERT=False (#93)
Browse files Browse the repository at this point in the history
Was incorrect handling, as values in environment variables are strings.

---------

Signed-off-by: Alexander Piskun <[email protected]>
  • Loading branch information
bigcat88 authored Aug 21, 2023
1 parent 36522d1 commit a9c2e30
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .github/workflows/analysis-coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
8 changes: 7 additions & 1 deletion nc_py_api/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -181,4 +181,5 @@ messages_control.disable = [
"missing-function-docstring",
"line-too-long",
"too-few-public-methods",
"too-many-public-methods",
]
10 changes: 10 additions & 0 deletions tests/options_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit a9c2e30

Please sign in to comment.