Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(369)

Unified Diff: recipe_engine/recipe_test_api.py

Issue 2707593002: Whitelist allowed test names
Patch Set: Use correct regex Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | recipe_engine/unittests/recipe_test_api_test.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: recipe_engine/recipe_test_api.py
diff --git a/recipe_engine/recipe_test_api.py b/recipe_engine/recipe_test_api.py
index e9e0431d86c7a4a68f8649ee32ff4315d0dbe768..d4186fb2af50f626863c37061d9953fb52dbf365 100644
--- a/recipe_engine/recipe_test_api.py
+++ b/recipe_engine/recipe_test_api.py
@@ -4,6 +4,7 @@
import contextlib
import inspect
+import re
from collections import namedtuple, defaultdict
@@ -187,9 +188,18 @@ PostprocessHook = namedtuple(
'PostprocessHook', 'func args kwargs filename lineno')
+def is_valid_test_name(name):
+ return bool(re.match(r'^(\w)+$', name))
+
+
class TestData(BaseTestData):
def __init__(self, name=None):
super(TestData, self).__init__()
+ # Allow empty names; sometimes we create test datas to merge two test datas
+ # together.
+ if name and not is_valid_test_name(name):
+ raise ValueError("Invalid test name %r" % name)
+
self.name = name
self.properties = {} # key -> val
self.mod_data = defaultdict(ModuleTestData)
« no previous file with comments | « no previous file | recipe_engine/unittests/recipe_test_api_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698