Skip to content

Commit

Permalink
Merge branch 'master' into mongo支持简单加密
Browse files Browse the repository at this point in the history
  • Loading branch information
feiazifeiazi authored Dec 27, 2024
2 parents 255c206 + 1940735 commit 5a9ad0c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
3 changes: 3 additions & 0 deletions sql/utils/data_masking.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,9 @@ def analyze_query_tree(select_list, instance):

def regex(masking_rule, value):
"""利用正则表达式脱敏数据"""
# 如果为null或none或空字符串,则不脱敏直接返回。
if not value:
return value
rule_regex = masking_rule["rule_regex"]

rule_type = masking_rule["rule_type"]
Expand Down
6 changes: 5 additions & 1 deletion sql/utils/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,7 @@ def test_data_masking_not_hit_rules(self, _inception):

@patch("sql.utils.data_masking.GoInceptionEngine")
def test_data_masking_hit_rules_not_exists_star(self, _inception):
"""数据库返回时添加了null结果。"""
_inception.return_value.query_data_masking.return_value = [
{
"index": 0,
Expand All @@ -619,14 +620,17 @@ def test_data_masking_hit_rules_not_exists_star(self, _inception):
}
]
sql = """select phone from users;"""
rows = (("18888888888",), ("18888888889",), ("18888888810",))
rows = (("18888888888",), (None,), ("18888888889",), ("18888888810",))
query_result = ReviewSet(column_list=["phone"], rows=rows, full_sql=sql)
r = data_masking(self.ins, "archery", sql, query_result)
print("test_data_masking_hit_rules_not_exists_star:", r.rows)
mask_result_rows = [
[
"188****8888",
],
[
None,
],
[
"188****8889",
],
Expand Down

0 comments on commit 5a9ad0c

Please sign in to comment.