Compare commits

..

No commits in common. "3ec1942b4e4b4b385b285c7c470230fbb1bbe247" and "c7f52e8b045dc22352b7a532a884621d649e1f57" have entirely different histories.

3 changed files with 1 additions and 80 deletions

View file

@ -6,10 +6,6 @@ import keyring
from injectable import injectable
from pykeepass import PyKeePass, create_database
import logging
logger = logging.getLogger(__name__)
class KeyRequest:
def __init__(self, prompt: str):
self.field_name = None
@ -18,8 +14,7 @@ class KeyRequest:
self._parse_prompt(prompt)
def _parse_prompt(self, prompt: str):
logger.debug(f"Got prompt: {prompt}")
prompt_parts = prompt.replace('\n', '').split(".")
prompt_parts = prompt.split(".")
key = None
match len(prompt_parts):
case 1:
@ -31,7 +26,6 @@ class KeyRequest:
case _:
key = None
if key is None:
logger.warning(f"Prompt {prompt} cannot be parsed")
return
key_parts = key.split("/")
self.path = key_parts[:] if len(key_parts) > 1 else None
@ -63,8 +57,6 @@ class Passwords:
request = KeyRequest(k)
with self.open() as kp:
kp_entry = kp.find_entries(path=request.path, first=True, title=request.entry_name)
if kp_entry is None:
logger.warning(f"No value found for key {k}")
output[k] = self._get_field_value(kp_entry, request.field_name)
return output

View file

@ -1,7 +0,0 @@
value=${sample}
nested=${some/nested/value}
mixed=${some/nested/value.username}
custom=${custom.field}
uname=${sample.username}
invalid=${double.dot.example}

View file

@ -1,64 +0,0 @@
from pathlib import Path
import pytest
import yaml
from karl.services import Passwords
from karl.services.mo import Mo
@pytest.fixture(scope='class')
def target_path():
# p = Path('tests/files/test1/test.env')
p = Path('files/test1/test.env')
# posprzątaj przed testem, gdyby plik istniał z poprzednich uruchomień
if p.exists():
p.unlink()
yield p
# sprzątanie po teście
if p.exists():
p.unlink()
@pytest.fixture(scope='class')
def test1_content(target_path: Path):
mo = Mo(Passwords())
mo.process(Path('files/test1/test.mo.env').absolute())
# mo.process(Path('tests/files/test1/test.mo.env').absolute())
assert target_path.absolute().exists()
content = target_path.read_text()
assert '${' not in content
props = {}
prop_lines = content.split('\n')
for line in prop_lines:
if len(line)> 1:
splitted = line.split('=')
props[splitted[0]] = splitted[1]
# props = {prop[0]:prop[1] for prop in content.split('\n')}
print(props)
yield props
class TestEnvParsing:
def test_simple(self, test1_content: dict):
assert test1_content['value'] == 'some_pass'
def test_nested(self, test1_content: dict):
assert test1_content['nested'] == 'nested_pass'
def test_mixed(self, test1_content: dict):
assert test1_content['mixed'] == 'nested_username'
def test_custom_field(self, test1_content: dict):
assert test1_content['custom'] == 'custom_content'
def test_username_field(self, test1_content: dict):
assert test1_content['uname'] == 'sample_username'
def test_invalid_key(self, test1_content: dict):
assert test1_content.get('invalid') == 'None'