Test unsafe regex pattern recognization

This commit is contained in:
shortcutme 2017-07-14 10:37:09 +02:00
parent 699a8be721
commit 3459d35ed2
No known key found for this signature in database
GPG key ID: 5B63BAE6CB9613AE

18
src/Test/TestSafeRe.py Normal file
View 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)