Skip to content

Commit 7417531

Browse files
author
Wout Feys
committed
Add in unit tests for indents and comments for detect_code_injection
1 parent 2009f16 commit 7417531

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,33 @@
11
import pytest
22
from .detect_code_injection import detect_code_injection
3+
4+
5+
def is_injection(statement, user_input=None):
6+
if user_input == None:
7+
assert detect_code_injection(statement, statement) is True
8+
else:
9+
assert detect_code_injection(statement, user_input) is True
10+
11+
12+
def is_not_injection(statement, user_input=None):
13+
if user_input == None:
14+
assert detect_code_injection(statement, statement) is False
15+
else:
16+
assert detect_code_injection(statement, user_input) is False
17+
18+
19+
def test_not_dangerous_comments():
20+
is_not_injection("# Hello! This (Might) Be Dangerous")
21+
is_not_injection(
22+
"""# Well hello
23+
# Hello there !"""
24+
)
25+
is_not_injection(' """Hello again!""" ')
26+
27+
28+
def test_newline_and_indent_not_dangerous():
29+
is_not_injection("\n\n\n\n\n\n\n\n")
30+
is_not_injection("\r\n\r\n\r\n")
31+
is_not_injection(" ")
32+
is_not_injection(" ")
33+
is_not_injection(" \r\n \n \n \t")

0 commit comments

Comments
 (0)