Skip to content

Commit a9c2e30

Browse files
authored
fixed bug when options.NPA_NC_CERT=False (#93)
Was incorrect handling, as values in environment variables are strings. --------- Signed-off-by: Alexander Piskun <bigcat88@icloud.com>
1 parent 36522d1 commit a9c2e30

File tree

4 files changed

+20
-1
lines changed

4 files changed

+20
-1
lines changed

.github/workflows/analysis-coverage.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -688,6 +688,7 @@ jobs:
688688
run: coverage run -m pytest && coverage xml && coverage html
689689
env:
690690
SKIP_AE_TESTS: 1
691+
NPA_NC_CERT: ''
691692

692693
- name: HTML coverage to artifacts
693694
uses: actions/upload-artifact@v3
@@ -821,6 +822,7 @@ jobs:
821822
env:
822823
NPA_TIMEOUT: None
823824
NPA_TIMEOUT_DAV: None
825+
NPA_NC_CERT: False
824826

825827
- name: HTML coverage to artifacts
826828
uses: actions/upload-artifact@v3

nc_py_api/options.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,14 @@
2727
except (TypeError, ValueError):
2828
NPA_TIMEOUT_DAV = None
2929

30-
NPA_NC_CERT = environ.get("NPA_NC_CERT", True)
30+
NPA_NC_CERT: typing.Union[bool, str]
3131
"""Option to enable/disable Nextcloud certificate verification.
3232
3333
SSL certificates (a.k.a CA bundle) used to verify the identity of requested hosts. Either **True** (default CA bundle),
3434
a path to an SSL certificate file, or **False** (which will disable verification)."""
35+
str_val = environ.get("NPA_NC_CERT", "True")
36+
NPA_NC_CERT = True
37+
if str_val.lower() in ("false", "0"):
38+
NPA_NC_CERT = False
39+
elif str_val.lower() not in ("true", "1"):
40+
NPA_NC_CERT = str_val

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,4 +181,5 @@ messages_control.disable = [
181181
"missing-function-docstring",
182182
"line-too-long",
183183
"too-few-public-methods",
184+
"too-many-public-methods",
184185
]

tests/options_test.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,16 @@ def test_timeouts():
3535
env_f.write("NPA_TIMEOUT_DAV=11")
3636
r = run(check_command, stderr=PIPE, env={}, cwd=project_dir, check=False)
3737
assert not r.stderr
38+
check_command = [sys.executable, "-c", "import nc_py_api\nassert nc_py_api.options.NPA_NC_CERT is False"]
39+
with open(env_file, "w") as env_f:
40+
env_f.write("NPA_NC_CERT=False")
41+
r = run(check_command, stderr=PIPE, env={}, cwd=project_dir, check=False)
42+
assert not r.stderr
43+
check_command = [sys.executable, "-c", "import nc_py_api\nassert nc_py_api.options.NPA_NC_CERT == ''"]
44+
with open(env_file, "w") as env_f:
45+
env_f.write('NPA_NC_CERT=""')
46+
r = run(check_command, stderr=PIPE, env={}, cwd=project_dir, check=False)
47+
assert not r.stderr
3848
finally:
3949
if os.path.exists(env_backup_file):
4050
os.rename(env_backup_file, env_file)

0 commit comments

Comments
 (0)