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

Unified Diff: chrome/test/functional/ispy/common/ispy_utils.py

Issue 100623002: Add error handling to validate expectation names. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: nit Created 7 years 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 | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/test/functional/ispy/common/ispy_utils.py
diff --git a/chrome/test/functional/ispy/common/ispy_utils.py b/chrome/test/functional/ispy/common/ispy_utils.py
index 6fa7d08fe33f66e3ee9a66a17b6550271153594d..a5d140af58f1972e736bd638e09c9ec532b82fed 100644
--- a/chrome/test/functional/ispy/common/ispy_utils.py
+++ b/chrome/test/functional/ispy/common/ispy_utils.py
@@ -13,6 +13,13 @@ import sys
import image_tools
+_INVALID_EXPECTATION_CHARS = ['/', '\\', ' ', '"', '\'']
+
+
+def IsValidExpectationName(expectation_name):
+ return not any(c in _INVALID_EXPECTATION_CHARS for c in expectation_name)
+
+
def GetExpectationPath(expectation, file_name=''):
"""Get the path to a test file in the given test run and expectation.
@@ -96,7 +103,14 @@ class ISpyUtils(object):
expectation: name for this expectation, any existing expectation with the
name will be replaced.
images: a list of RGB encoded PIL.Images
+
+ Raises:
+ ValueError: if the expectation name is invalid.
"""
+ if not IsValidExpectationName(expectation):
+ raise ValueError("Expectation name contains an illegal character: %s." %
+ str(_INVALID_EXPECTATION_CHARS))
+
mask = image_tools.InflateMask(image_tools.CreateMask(images), 7)
self.UploadImage(
GetExpectationPath(expectation, 'expected.png'), images[0])
@@ -112,7 +126,12 @@ class ISpyUtils(object):
Raises:
cloud_bucket.NotFoundError: if the given expectation is not found.
+ ValueError: if the expectation name is invalid.
"""
+ if not IsValidExpectationName(expectation):
+ raise ValueError("Expectation name contains an illegal character: %s." %
+ str(_INVALID_EXPECTATION_CHARS))
+
expectation_tuple = self.GetExpectation(expectation)
if not image_tools.SameImage(
actual, expectation_tuple.expected, mask=expectation_tuple.mask):
@@ -198,7 +217,14 @@ class ISpyUtils(object):
images: a json encoded list of base64 encoded png images.
pink_out: an image.
RGB: a json list representing the RGB values of a color to mask out.
+
+ Raises:
+ ValueError: if expectation name is invalid.
"""
+ if not IsValidExpectationName(expectation):
+ raise ValueError("Expectation name contains an illegal character: %s." %
+ str(_INVALID_EXPECTATION_CHARS))
+
# convert the pink_out into a mask
black = (0, 0, 0, 255)
white = (255, 255, 255, 255)
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698