Skip to content

Commit 44198e9

Browse files
author
Tyler Titsworth
authored
Auto-Enable Masking with Test Runner (#99)
1 parent 02a14d0 commit 44198e9

File tree

3 files changed

+8
-14
lines changed

3 files changed

+8
-14
lines changed

test-runner/.actions.json

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
{
22
"TEST": ["3", "4", "5"],
3-
"mask": [true],
43
"experimental": [true]
54
}

test-runner/test_runner.py

+6-12
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,6 @@ def parse_args(args: list):
6464
parser.add_argument(
6565
"-l", "--logs", dest="logs_path", default="output", help="-l /path/to/logs"
6666
)
67-
parser.add_argument(
68-
"-m",
69-
"--mask",
70-
dest="mask",
71-
action="store_true",
72-
help="Enable mask parameter for sensitive information in logs",
73-
)
7467

7568
return parser.parse_args(args)
7669

@@ -112,13 +105,14 @@ def get_test_list(args: dict, tests_yaml: List[dict]):
112105
List[dict]: list of expanded tests
113106
"""
114107
tests_list = {}
108+
disable_masking = False
115109
for test in tests_yaml:
116110
if re.search(r"\$\{([A-Za-z0-9_]*)\:\-(.*?)\}", test):
117111
if args.actions_path:
118112
with open(args.actions_path, "r", encoding="utf-8") as actions_file:
119113
for key, dval in json.load(actions_file).items():
120-
if key == "mask":
121-
[args.mask] = dval
114+
if key == "mask" and dval == [False]:
115+
disable_masking = True
122116
if isinstance(dval, list) and key != "experimental":
123117
for _, val in enumerate(dval):
124118
os.environ[key] = str(val)
@@ -141,7 +135,7 @@ def get_test_list(args: dict, tests_yaml: List[dict]):
141135
logging.error("Command not found for %s", test)
142136
sys.exit(1)
143137

144-
return tests_list
138+
return tests_list, disable_masking
145139

146140

147141
if __name__ == "__main__":
@@ -173,15 +167,15 @@ def get_test_list(args: dict, tests_yaml: List[dict]):
173167
except YAMLError as yaml_exc:
174168
logging.error(yaml_exc)
175169
sys.exit(1)
176-
tests_list = get_test_list(args, tests_json)
170+
tests_list, disable_masking = get_test_list(args, tests_json)
177171
logging.debug("Creating Test Objects from: %s", tests_list)
178172
# For each test, create a Test Object with the test name is the key of the test in yaml
179173
tests = [Test(name=test, **tests_list[test]) for test in tests_list]
180174
logging.info("Setup Completed - Running Tests")
181175
summary = []
182176
ERROR = False
183177
for idx, test in enumerate(tests):
184-
if not args.mask:
178+
if disable_masking:
185179
test.mask = []
186180
# Set Context to test-runner.log
187181
set_log_filename(logging.getLogger(), "test-runner", args.logs_path)

test-runner/tests/utest.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,9 @@ def test_get_test_list(test_args_input, test_json_input):
145145
"test7": {"cmd": "echo 'world: hello'", "mask": ["world"]},
146146
}
147147

148-
test_fn = get_test_list(test_args_input, test_json_input)
148+
test_fn, disable_masking = get_test_list(test_args_input, test_json_input)
149149
assert test_fn == test_val
150+
assert disable_masking is False
150151

151152

152153
def test_masking(test_class_input):

0 commit comments

Comments
 (0)