Skip to content

Commit f84354f

Browse files
authored
Merge pull request #57 from brootware/dev
Dev
2 parents 2d94f89 + be2487b commit f84354f

File tree

6 files changed

+94
-6
lines changed

6 files changed

+94
-6
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api"
44

55
[tool.poetry]
66
name = "pyredactkit"
7-
version = "0.3.3"
7+
version = "0.3.4"
88
description = "Python cli tool to redact sensitive data"
99
authors = ["brootware <[email protected]>"]
1010
license = "GPL-3.0-or-later"

pyredactkit/core_redactor.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,22 @@ def __init__(self) -> None:
3535
"""
3636
return None
3737

38+
def identify_data(self, line: str) -> list:
39+
"""Function to identify specific option
40+
Args:
41+
line (str) : line to be supplied to identify pattern
42+
Returns:
43+
list (list): list of sensitive data found in lines
44+
"""
45+
sensitive_data = []
46+
for id in id_object.regexes:
47+
redact_pattern = id['pattern']
48+
if re.search(redact_pattern, line):
49+
pattern_string = re.search(redact_pattern, line)
50+
pattern_string = pattern_string.group(0)
51+
sensitive_data.append(pattern_string)
52+
return sensitive_data
53+
3854
def redact_all(self, line: str) -> tuple:
3955
"""Function to redact specific option
4056
Args:

pyredactkit/pyredactkit.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,5 +143,9 @@ def main():
143143
redact_obj.process_text(args.text)
144144

145145

146+
def api_return_core_identifier(text: str) -> list:
147+
return redact_obj.identify_data(text)
148+
149+
146150
if __name__ == "__main__":
147151
main()

tests/test_common_jobs.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import pytest
2-
import json
32
import os
43
from pyredactkit.common_jobs import CommonJobs
54

tests/test_core_redact.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,17 @@ def mocker_text_file(mocker):
6060
mocker.patch(builtin_open, mocked_open)
6161

6262

63+
def test_identify_data_should_return_list(redactor_obj):
64+
assert type(redactor_obj.identify_data(data)) == list, "identify_data function should return a list"
65+
66+
6367
def test_redact_all_function_should_return_string_and_dictionary(redactor_obj):
6468
set1 = redactor_obj.redact_all(data)
6569
set2 = ("This is a string", hash_table)
66-
assert type(set1[0]) == type(set2[0]), "1st element of redact_all function should return string"
67-
assert type(set1[1]) == type(set2[1]), "2nd element of redact_all function should return dictionary"
70+
assert type(set1[0]) == str, "1st element of redact_all function should return string"
71+
assert type(set1[1]) == dict, "2nd element of redact_all function should return dictionary"
6872
assert type(set1) == type(set2), "redact_all function should return a tuple"
6973

70-
7174
# def test_process_text_function_should_create_redacted_file_and_json(redactor_obj, tmp_path):
7275
# redactor_obj.process_text(data, tmp_path)
7376
# assert os.path.isfile(tmp_path / "redacted_file.txt"), "redacted_file.txt should be created"
@@ -77,4 +80,4 @@ def test_redact_all_function_should_return_string_and_dictionary(redactor_obj):
7780
# def test_process_core_file_function_should_create_redacted_file_and_json(redactor_obj, mocker_text_file, tmp_path):
7881
# redactor_obj.process_core_file(filename='fakefile', savedir=tmp_path)
7982
# assert os.path.isfile(tmp_path / "redacted_fakefile.txt"), "redacted_fakefile.txt should be created"
80-
# assert os.path.isfile(tmp_path / "redacted_fakefile.json"), "redacted_fakefile.json should be created"
83+
# assert os.path.isfile(tmp_path / "redacted_fakefile.json"), "redacted_fakefile.json should be created"

tests/test_custom_redact_engine.py

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import pytest
2+
import os
3+
import json
4+
from pyredactkit.custom_redactor import CustomRedactorEngine
5+
data = """John, please get that article on www.linkedin.com to me by 5:00PM on Jan 9th 2012. 4:00 would be ideal, actually. If you have any questions, You can reach me at(519)-236-2723 or get in touch with my associate at [email protected]
6+
this is my IP: 102.23.5.1
7+
My router is : 10.10.10.1
8+
71.159.188.33
9+
81.141.167.45
10+
165.65.59.139
11+
64.248.67.225
12+
13+
https://tech.gov.sg
14+
15+
My email is [email protected]
16+
17+
this is my IP: 102.23.5.1
18+
My router is: 10.10.10.1
19+
71.159.188.33
20+
81.141.167.45
21+
165.65.59.139
22+
64.248.67.225
23+
24+
Card_Number,Card_Family,Credit_Limit,Cust_ID
25+
8638-5407-3631-8196,Premium,530000,CC67088
26+
7106-4239-7093-1515,Gold,18000,CC12076
27+
6492-5655-8241-3530,Premium,596000,CC97173
28+
2868-5606-5152-5706,Gold,27000,CC55858
29+
1438-6906-2509-8219,Platinum,142000,CC90518
30+
2764-7023-8396-5255,Gold,50000,CC49168
31+
4864-7119-5608-7611,Premium,781000,CC66746
32+
5160-8427-6529-3274,Premium,490000,CC28930
33+
6691-5105-1556-4131,Premium,640000,CC76766
34+
1481-2536-2178-7547,Premium,653000,CC18007
35+
1355-1728-8274-9593,Premium,660000,CC23267
36+
9621-6787-7890-7470,Platinum,53000,CC52613
37+
6385-4594-8055-9081,Premium,737000,CC96267
38+
2595-8621-2855-9119,Premium,564000,CC22050
39+
7214-4915-6387-5429,Platinum,172000,CC72302
40+
7908-3850-6633-2606,Gold,43000,CC71044
41+
"""
42+
43+
44+
people_names = "John,Jones,Alex,Bruce"
45+
mask_names = "\u2588" * 15
46+
count_names = 4
47+
hash_table = {}
48+
49+
@pytest.fixture
50+
def custom_redactor():
51+
return CustomRedactorEngine()
52+
53+
54+
@pytest.fixture
55+
def mocker_json_file(mocker):
56+
content = {"key": "value"}
57+
mocked_open = mocker.mock_open(read_data=content)
58+
builtin_open = "builtins.open"
59+
mocker.patch(builtin_open, mocked_open)
60+
61+
# def test_redact_custom_function_should_return_string_and_dictionary(custom_redactor,mocker_json_file):
62+
# set1 = custom_redactor.redact_custom(data)
63+
# set2 = ("This is a string", hash_table)
64+
# assert isinstance(type(set1[0]), str), "1st element of redact_custom function should return string"
65+
# assert isinstance(type(set1[1]), dict), "2nd element of redact_custom function should return dictionary"
66+
# assert type(set1) == type(set2), "redact_custom function should return a tuple"

0 commit comments

Comments
 (0)