1
0

Code quality
Some checks failed
Run Python tests (through Pytest) / Test (push) Failing after 24s
Python Ruff Code Quality / ruff (push) Successful in 22s
Verify Python project can be installed, loaded and have version checked / Test (push) Successful in 22s

This commit is contained in:
Jon Michael Aanes 2024-10-27 17:49:06 +01:00
parent 83f310e28a
commit 81264a3b6c
Signed by: Jmaa
SSH Key Fingerprint: SHA256:Ab0GfHGCblESJx7JRE4fj4bFy/KRpeLhi41y4pF3sNA
2 changed files with 14 additions and 8 deletions

View File

@ -206,11 +206,14 @@ class SecretLoader:
) )
return self._convert_pass_process_result_to_password( return self._convert_pass_process_result_to_password(
process.returncode, process.stdout process.returncode,
process.stdout,
) )
def _convert_pass_process_result_to_password( def _convert_pass_process_result_to_password(
self, returncode: int, stdout: bytes self,
returncode: int,
stdout: bytes,
) -> str | None: ) -> str | None:
if returncode != 0: if returncode != 0:
return None return None

View File

@ -1,6 +1,7 @@
import secret_loader
import pytest import pytest
import secret_loader
def test_hardcoded(): def test_hardcoded():
loader = secret_loader.SecretLoader(ENV_KEY_PREFIX='TEST', KEY='VALUE') loader = secret_loader.SecretLoader(ENV_KEY_PREFIX='TEST', KEY='VALUE')
@ -37,10 +38,12 @@ def test_fail_hardcoded_prefix_with_trailing_underscore():
def test_lookup_unknown_or_fail(): def test_lookup_unknown_or_fail():
loader = secret_loader.SecretLoader( loader = secret_loader.SecretLoader(
ENV_KEY_PREFIX='TEST', PASS_STORE_SUBFOLDER='test' ENV_KEY_PREFIX='TEST',
PASS_STORE_SUBFOLDER='test', # noqa: S106
) )
with pytest.raises( with pytest.raises(
ValueError, match='Failed to load secret with key:.*UNKNOWN.*' ValueError,
match='Failed to load secret with key:.*UNKNOWN.*',
) as e: ) as e:
assert loader.load_or_fail('UNKNOWN') assert loader.load_or_fail('UNKNOWN')
@ -51,8 +54,8 @@ def test_lookup_unknown_or_fail():
def test_convert_process(): def test_convert_process():
loader = secret_loader.SecretLoader() loader = secret_loader.SecretLoader()
assert loader._convert_pass_process_result_to_password(1, b'') is None assert loader._convert_pass_process_result_to_password(1, b'') is None # noqa: SLF001
assert ( assert (
loader._convert_pass_process_result_to_password(0, b'Hello\nWorld') == 'Hello' loader._convert_pass_process_result_to_password(0, b'Hello\nWorld') == 'Hello' # noqa: SLF001
) )
assert loader._convert_pass_process_result_to_password(0, b'') == '' assert loader._convert_pass_process_result_to_password(0, b'') == '' # noqa: SLF001