Skip to content

Commit 5947355

Browse files
authored
Merge pull request #61 from con2/issue-59
fixes #59, closes #60
2 parents 5744482 + 742e64d commit 5947355

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

emrichen/tags/hash.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,15 @@ class _BaseHash(BaseTag):
1212
description: Hashes the given data using the {name} algorithm. If the data is not binary, it is converted to UTF-8 bytes.
1313
"""
1414

15+
value_types = (
16+
str,
17+
object,
18+
)
19+
1520
hasher: Any = None # TODO: what's the proper type for a hasher factory?
1621

1722
def enrich(self, context: Context) -> str:
18-
data = self.data
23+
data = context.enrich(self.data)
1924
if not isinstance(data, bytes):
2025
if not isinstance(data, str):
2126
data = str(data)

tests/test_hash.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,22 @@
11
import pytest
22

3-
from emrichen import Template
3+
from emrichen import Context, Template
44

55
HASHES = {
66
'MD5': '8b1a9953c4611296a827abf8c47804d7',
77
'SHA1': 'f7ff9e8b7bb2e09b70935a5d785e0cc5d9d0abf0',
88
'SHA256': '185f8db32271fe25f561a6fc938b2e264306ec304eda518007d1764826381969',
99
}
1010

11+
@pytest.mark.parametrize('h', sorted(HASHES.items()), ids=sorted(HASHES))
12+
def test_hash_variable(h):
13+
algo, expected = h
14+
15+
VARIABLES = """
16+
helloVar: Hello
17+
"""
18+
19+
assert Template.parse(f'!{algo},Var helloVar').enrich(Context(VARIABLES)) == [expected]
1120

1221
@pytest.mark.parametrize('h', sorted(HASHES.items()), ids=sorted(HASHES))
1322
def test_hash(h):

0 commit comments

Comments
 (0)