Skip to content

Commit

Permalink
Merge pull request #57 from brootware/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
brootware authored Jul 24, 2022
2 parents 2d94f89 + be2487b commit f84354f
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 6 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api"

[tool.poetry]
name = "pyredactkit"
version = "0.3.3"
version = "0.3.4"
description = "Python cli tool to redact sensitive data"
authors = ["brootware <[email protected]>"]
license = "GPL-3.0-or-later"
Expand Down
16 changes: 16 additions & 0 deletions pyredactkit/core_redactor.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,22 @@ def __init__(self) -> None:
"""
return None

def identify_data(self, line: str) -> list:
"""Function to identify specific option
Args:
line (str) : line to be supplied to identify pattern
Returns:
list (list): list of sensitive data found in lines
"""
sensitive_data = []
for id in id_object.regexes:
redact_pattern = id['pattern']
if re.search(redact_pattern, line):
pattern_string = re.search(redact_pattern, line)
pattern_string = pattern_string.group(0)
sensitive_data.append(pattern_string)
return sensitive_data

def redact_all(self, line: str) -> tuple:
"""Function to redact specific option
Args:
Expand Down
4 changes: 4 additions & 0 deletions pyredactkit/pyredactkit.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,5 +143,9 @@ def main():
redact_obj.process_text(args.text)


def api_return_core_identifier(text: str) -> list:
return redact_obj.identify_data(text)


if __name__ == "__main__":
main()
1 change: 0 additions & 1 deletion tests/test_common_jobs.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import pytest
import json
import os
from pyredactkit.common_jobs import CommonJobs

Expand Down
11 changes: 7 additions & 4 deletions tests/test_core_redact.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,17 @@ def mocker_text_file(mocker):
mocker.patch(builtin_open, mocked_open)


def test_identify_data_should_return_list(redactor_obj):
assert type(redactor_obj.identify_data(data)) == list, "identify_data function should return a list"


def test_redact_all_function_should_return_string_and_dictionary(redactor_obj):
set1 = redactor_obj.redact_all(data)
set2 = ("This is a string", hash_table)
assert type(set1[0]) == type(set2[0]), "1st element of redact_all function should return string"
assert type(set1[1]) == type(set2[1]), "2nd element of redact_all function should return dictionary"
assert type(set1[0]) == str, "1st element of redact_all function should return string"
assert type(set1[1]) == dict, "2nd element of redact_all function should return dictionary"
assert type(set1) == type(set2), "redact_all function should return a tuple"


# def test_process_text_function_should_create_redacted_file_and_json(redactor_obj, tmp_path):
# redactor_obj.process_text(data, tmp_path)
# assert os.path.isfile(tmp_path / "redacted_file.txt"), "redacted_file.txt should be created"
Expand All @@ -77,4 +80,4 @@ def test_redact_all_function_should_return_string_and_dictionary(redactor_obj):
# def test_process_core_file_function_should_create_redacted_file_and_json(redactor_obj, mocker_text_file, tmp_path):
# redactor_obj.process_core_file(filename='fakefile', savedir=tmp_path)
# assert os.path.isfile(tmp_path / "redacted_fakefile.txt"), "redacted_fakefile.txt should be created"
# assert os.path.isfile(tmp_path / "redacted_fakefile.json"), "redacted_fakefile.json should be created"
# assert os.path.isfile(tmp_path / "redacted_fakefile.json"), "redacted_fakefile.json should be created"
66 changes: 66 additions & 0 deletions tests/test_custom_redact_engine.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import pytest
import os
import json
from pyredactkit.custom_redactor import CustomRedactorEngine
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]
this is my IP: 102.23.5.1
My router is : 10.10.10.1
71.159.188.33
81.141.167.45
165.65.59.139
64.248.67.225
https://tech.gov.sg
My email is [email protected]
this is my IP: 102.23.5.1
My router is: 10.10.10.1
71.159.188.33
81.141.167.45
165.65.59.139
64.248.67.225
Card_Number,Card_Family,Credit_Limit,Cust_ID
8638-5407-3631-8196,Premium,530000,CC67088
7106-4239-7093-1515,Gold,18000,CC12076
6492-5655-8241-3530,Premium,596000,CC97173
2868-5606-5152-5706,Gold,27000,CC55858
1438-6906-2509-8219,Platinum,142000,CC90518
2764-7023-8396-5255,Gold,50000,CC49168
4864-7119-5608-7611,Premium,781000,CC66746
5160-8427-6529-3274,Premium,490000,CC28930
6691-5105-1556-4131,Premium,640000,CC76766
1481-2536-2178-7547,Premium,653000,CC18007
1355-1728-8274-9593,Premium,660000,CC23267
9621-6787-7890-7470,Platinum,53000,CC52613
6385-4594-8055-9081,Premium,737000,CC96267
2595-8621-2855-9119,Premium,564000,CC22050
7214-4915-6387-5429,Platinum,172000,CC72302
7908-3850-6633-2606,Gold,43000,CC71044
"""


people_names = "John,Jones,Alex,Bruce"
mask_names = "\u2588" * 15
count_names = 4
hash_table = {}

@pytest.fixture
def custom_redactor():
return CustomRedactorEngine()


@pytest.fixture
def mocker_json_file(mocker):
content = {"key": "value"}
mocked_open = mocker.mock_open(read_data=content)
builtin_open = "builtins.open"
mocker.patch(builtin_open, mocked_open)

# def test_redact_custom_function_should_return_string_and_dictionary(custom_redactor,mocker_json_file):
# set1 = custom_redactor.redact_custom(data)
# set2 = ("This is a string", hash_table)
# assert isinstance(type(set1[0]), str), "1st element of redact_custom function should return string"
# assert isinstance(type(set1[1]), dict), "2nd element of redact_custom function should return dictionary"
# assert type(set1) == type(set2), "redact_custom function should return a tuple"

0 comments on commit f84354f

Please sign in to comment.