forked from aws-powertools/powertools-lambda-python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_data_masking.py
69 lines (57 loc) · 2.79 KB
/
test_data_masking.py
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
import importlib
from types import ModuleType
import pytest
from aws_lambda_powertools.utilities.data_masking.base import DataMasking
DATA_MASKING_PACKAGE = "aws_lambda_powertools.utilities.data_masking"
DATA_MASKING_INIT_SLA: float = 0.002
DATA_MASKING_NESTED_ENCRYPT_SLA: float = 0.001
json_blob = {
"id": 1,
"name": "John Doe",
"age": 30,
"email": "[email protected]",
"address": {"street": "123 Main St", "city": "Anytown", "state": "CA", "zip": "12345"},
"phone_numbers": ["+1-555-555-1234", "+1-555-555-5678"],
"interests": ["Hiking", "Traveling", "Photography", "Reading"],
"job_history": {
"company": {
"company_name": "Acme Inc.",
"company_address": "5678 Interview Dr.",
},
"position": "Software Engineer",
"start_date": "2015-01-01",
"end_date": "2017-12-31",
},
"about_me": """
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla tincidunt velit quis
sapien mollis, at egestas massa tincidunt. Suspendisse ultrices arcu a dolor dapibus,
ut pretium turpis volutpat. Vestibulum at sapien quis sapien dignissim volutpat ut a enim.
Praesent fringilla sem eu dui convallis luctus. Donec ullamcorper, sapien ut convallis congue,
risus mauris pretium tortor, nec dignissim arcu urna a nisl. Vivamus non fermentum ex. Proin
interdum nisi id sagittis egestas. Nam sit amet nisi nec quam pharetra sagittis. Aliquam erat
volutpat. Donec nec luctus sem, nec ornare lorem. Vivamus vitae orci quis enim faucibus placerat.
Nulla facilisi. Proin in turpis orci. Donec imperdiet velit ac tellus gravida, eget laoreet tellus
malesuada. Praesent venenatis tellus ac urna blandit, at varius felis posuere. Integer a commodo nunc.
""",
}
json_blob_fields = ["address.street", "job_history.company.company_name"]
def import_data_masking_utility() -> ModuleType:
"""Dynamically imports and return DataMasking module"""
return importlib.import_module(DATA_MASKING_PACKAGE)
@pytest.mark.perf
@pytest.mark.benchmark(group="core", disable_gc=True, warmup=False)
def test_data_masking_init(benchmark):
benchmark.pedantic(import_data_masking_utility)
stat = benchmark.stats.stats.max
if stat > DATA_MASKING_INIT_SLA:
pytest.fail(f"High level imports should be below {DATA_MASKING_INIT_SLA}s: {stat}")
def mask_json_blob():
data_masker = DataMasking()
data_masker.mask(json_blob, json_blob_fields)
@pytest.mark.perf
@pytest.mark.benchmark(group="core", disable_gc=True, warmup=False)
def test_data_masking_encrypt_with_json_blob(benchmark):
benchmark.pedantic(mask_json_blob)
stat = benchmark.stats.stats.max
if stat > DATA_MASKING_NESTED_ENCRYPT_SLA:
pytest.fail(f"High level imports should be below {DATA_MASKING_NESTED_ENCRYPT_SLA}s: {stat}")