Test unsafe regex pattern recognization
This commit is contained in:
parent
699a8be721
commit
3459d35ed2
1 changed files with 18 additions and 0 deletions
18
src/Test/TestSafeRe.py
Normal file
18
src/Test/TestSafeRe.py
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
from util import SafeRe
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
|
||||||
|
class TestSafeRe:
|
||||||
|
def testSafeMatch(self):
|
||||||
|
assert SafeRe.match(
|
||||||
|
"((js|css)/(?!all.(js|css))|data/users/.*db|data/users/.*/.*|data/archived|.*.py)",
|
||||||
|
"js/ZeroTalk.coffee"
|
||||||
|
)
|
||||||
|
assert SafeRe.match(".+/data.json", "data/users/1J3rJ8ecnwH2EPYa6MrgZttBNc61ACFiCj/data.json")
|
||||||
|
|
||||||
|
@pytest.mark.parametrize("pattern", ["([a-zA-Z]+)*", "(a|aa)+*", "(a|a?)+", "(.*a){10}"])
|
||||||
|
def testUnsafeMatch(self, pattern):
|
||||||
|
with pytest.raises(SafeRe.UnsafePatternError) as err:
|
||||||
|
SafeRe.match(pattern, "aaaaaaaaaaaaaaaaaaaaaaaa!")
|
||||||
|
assert "Potentially unsafe" in str(err)
|
Loading…
Reference in a new issue