-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathtest_obfuscate.py
More file actions
73 lines (63 loc) · 2.18 KB
/
test_obfuscate.py
File metadata and controls
73 lines (63 loc) · 2.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
"""Tests for the obfuscation utilities used in fixtures and logging."""
import pytest
from pyoverkiz.obfuscate import obfuscate_email, obfuscate_sensitive_data
LOCAL_HOST = "gateway-1234-5678-1243.local:8443"
LOCAL_HOST_BY_IP = "192.168.1.105:8443"
class TestObfucscate:
"""Tests for obfuscation utilities (emails and sensitive data)."""
@pytest.mark.parametrize(
("email", "obfuscated"),
[
("contact@somfy.com", "c****@****y.com"),
("contact_-_nexity.com", "c****@****y.com"),
],
)
def test_email_obfuscate(self, email: str, obfuscated: str):
"""Verify email obfuscation produces the expected masked result."""
assert obfuscate_email(email) == obfuscated
class TestObfucscateSensitive:
"""Tests around obfuscating sensitive structures while preserving non-sensitive content."""
def test_obfuscate_list_with_none(self):
"""Ensure lists containing None values are handled without modification."""
data = {
"d": [
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
None,
None,
None,
None,
None,
None,
None,
]
}
assert obfuscate_sensitive_data(data) == data
def test_obfuscate_list_of_dicts(self):
"""Ensure obfuscate_sensitive_data handles a list of dicts."""
data = [
{"label": "My Scene", "oid": "abc-123"},
{"label": "Night Mode", "deviceURL": "io://1234-5678-1234/12345678"},
]
result = obfuscate_sensitive_data(data)
assert isinstance(result, list)
assert len(result) == 2
assert result[0]["label"] != "My Scene"
assert result[0]["oid"] == "abc-123" # oid is not a sensitive key
assert result[1]["label"] != "Night Mode"
assert result[1]["deviceURL"] != "io://1234-5678-1234/12345678"