summaryrefslogtreecommitdiffstats
path: root/share/extensions/tests/test_color_custom.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 18:24:48 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 18:24:48 +0000
commitcca66b9ec4e494c1d919bff0f71a820d8afab1fa (patch)
tree146f39ded1c938019e1ed42d30923c2ac9e86789 /share/extensions/tests/test_color_custom.py
parentInitial commit. (diff)
downloadinkscape-cca66b9ec4e494c1d919bff0f71a820d8afab1fa.tar.xz
inkscape-cca66b9ec4e494c1d919bff0f71a820d8afab1fa.zip
Adding upstream version 1.2.2.upstream/1.2.2upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'share/extensions/tests/test_color_custom.py')
-rw-r--r--share/extensions/tests/test_color_custom.py50
1 files changed, 50 insertions, 0 deletions
diff --git a/share/extensions/tests/test_color_custom.py b/share/extensions/tests/test_color_custom.py
new file mode 100644
index 0000000..75b444f
--- /dev/null
+++ b/share/extensions/tests/test_color_custom.py
@@ -0,0 +1,50 @@
+# coding=utf-8
+
+import inkex
+from color_custom import Custom
+from .test_inkex_extensions import ColorBaseCase
+
+
+class ColorCustomTest(ColorBaseCase):
+ effect_class = Custom
+ color_tests = [
+ # The default ranges are set to 0, and thus the color should not change.
+ ("none", "none"),
+ ((255, 255, 255), "#ffffff"),
+ ((100, 0, 0), "#c80000", ["-r r*2"]),
+ ((12, 34, 56), "#0c3822", ["-g b", "-b g"]),
+ ((12, 34, 56), "#183822", ["-g b", "-b g", "-r r*2"]),
+ ((0, 0, 0), "#100000", ["-s 255", "-r 16"]),
+ ((0, 0, 0), "#0f0000", ["-s 1", "-r 0.0625"]),
+ ((0, 0, 0), "#ff0000", ["-r 400"]),
+ ((0, 0, 0), "#000000", ["-r -400"]),
+ ("red", "#fe0000", ["-s 400"]),
+ ]
+
+ def test_evil_fails(self):
+ """
+ eval shouldn't allow for evil things to happen
+
+ Here we try and check if a file exists but it could just as easily
+ overwrite or delete the file
+
+ """
+ args = ["-r __import__('os').path.exists('__init__.py')", self.empty_svg]
+ self.effect.run(args)
+
+ with self.assertRaises(TypeError):
+ self.effect.modify_color("fill", inkex.Color("black"))
+
+ def test_invalid_operator(self):
+ args = ["-r r % 100", self.empty_svg]
+ self.effect.run(args)
+
+ with self.assertRaises(KeyError):
+ self.effect.modify_color("fill", inkex.Color("black"))
+
+ def test_bad_syntax(self):
+ args = ["-r r + 100)", self.empty_svg]
+ self.effect.run(args)
+
+ with self.assertRaises(SyntaxError):
+ self.effect.modify_color("fill", inkex.Color("black"))