1# coding=utf-8 2 3import inkex 4from color_custom import Custom 5from .test_inkex_extensions import ColorBaseCase 6 7class ColorCustomTest(ColorBaseCase): 8 effect_class = Custom 9 color_tests = [ 10 # The default ranges are set to 0, and thus the color should not change. 11 ("none", "none"), 12 ((255, 255, 255), "#ffffff"), 13 ((100, 0, 0), "#c80000", ['-r r*2']), 14 ((12, 34, 56), "#0c3822", ['-g b', '-b g']), 15 ((12, 34, 56), "#183822", ['-g b', '-b g', '-r r*2']), 16 ((0, 0, 0), "#100000", ['-s 255', '-r 16']), 17 ((0, 0, 0), "#0f0000", ['-s 1', '-r 0.0625']), 18 ((0, 0, 0), "#ff0000", ['-r 400']), 19 ((0, 0, 0), "#000000", ['-r -400']), 20 ("red", "#fe0000", ['-s 400']), 21 ] 22 23 def test_evil_fails(self): 24 """ 25 eval shouldn't allow for evil things to happen 26 27 Here we try and check if a file exists but it could just as easily 28 overwrite or delete the file 29 30 """ 31 args = ["-r __import__('os').path.exists('__init__.py')", self.empty_svg] 32 self.effect.run(args) 33 34 with self.assertRaises(TypeError): 35 self.effect.modify_color('fill', inkex.Color('black')) 36 37 def test_invalid_operator(self): 38 args = ["-r r % 100", self.empty_svg] 39 self.effect.run(args) 40 41 with self.assertRaises(KeyError): 42 self.effect.modify_color('fill', inkex.Color('black')) 43 44 def test_bad_syntax(self): 45 args = ["-r r + 100)", self.empty_svg] 46 self.effect.run(args) 47 48 with self.assertRaises(SyntaxError): 49 self.effect.modify_color('fill', inkex.Color('black')) 50