# HG changeset patch # User Goffi # Date 1384262171 -3600 # Node ID 4284b6ad8aa347845e6b4ba3eff5501926c9a2db # Parent 65b30bc7f1b315b9c5d11c1d62f813ff81fa738e tests: plugin text syntaxes sanitisation tests diff -r 65b30bc7f1b3 -r 4284b6ad8aa3 src/test/helpers.py --- a/src/test/helpers.py Tue Nov 12 14:16:11 2013 +0100 +++ b/src/test/helpers.py Tue Nov 12 14:16:11 2013 +0100 @@ -72,6 +72,8 @@ setattr(self, name, checkCall) + def addMethod(self, name, int_suffix, in_sign, out_sign, method, async=False): + pass class FakeMemory(object): """Class to simulate and test memory object""" @@ -94,6 +96,8 @@ def delWaitingSub(self, contact_jid, profile_key): pass + def updateParams(self, xml): + pass class FakeTriggerManager(object): diff -r 65b30bc7f1b3 -r 4284b6ad8aa3 src/test/test_plugin_text_syntaxes.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/test_plugin_text_syntaxes.py Tue Nov 12 14:16:11 2013 +0100 @@ -0,0 +1,88 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- + +# SAT: a jabber client +# Copyright (C) 2009, 2010, 2011, 2012, 2013 Jérôme Poisson (goffi@goffi.org) + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. + +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + +""" Plugin text syntaxes tests """ + +from sat.test import helpers +from sat.plugins import plugin_misc_text_syntaxes + + +class SanitisationTest(helpers.SatTestCase): + + def setUp(self): + self.host = helpers.FakeSAT() + self.text_syntaxes = plugin_misc_text_syntaxes.TextSyntaxes(self.host) + + + def test_xhtml_sanitise(self): + evil_html = """ + + + + + + + + + a link + another link +

a paragraph

+
secret EVIL!
+ of EVIL! + +
+ Password: +
+ annoying EVIL! + spam spam SPAM! + + + """ # example from lxml: /usr/share/doc/python-lxml-doc/html/lxmlhtml.html#cleaning-up-html + + expected = """
+ + + a link + another link +

a paragraph

+
secret EVIL!
+ of EVIL! + Password: + annoying EVIL! + spam spam SPAM! + + +
""" + + d = self.text_syntaxes.clean_xhtml(evil_html) + d.addCallback(self.assertEqualXML, expected, ignore_blank=True) + return d + + + def test_styles_sanitise(self): + evil_html = """

test retest
toto

""" + + expected = """

test retest
toto

""" + + d = self.text_syntaxes.clean_xhtml(evil_html) + d.addCallback(self.assertEqualXML, expected) + return d