summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorLance Stout <lancestout@gmail.com>2012-07-24 20:01:18 -0700
committerLance Stout <lancestout@gmail.com>2012-07-24 20:01:18 -0700
commitc42f1ad4c79863261977a9c5ea3b33be0b51b946 (patch)
tree8eee86ddb082f51dea0866f16146bcd1f4f13c1f /tests
parenta3ec1af2053bc0be4864ae290e6e5fc39f3fd5fe (diff)
parent9d8de7fc15afc39a666d2ac16b62a068dfc55112 (diff)
downloadslixmpp-c42f1ad4c79863261977a9c5ea3b33be0b51b946.tar.gz
slixmpp-c42f1ad4c79863261977a9c5ea3b33be0b51b946.tar.bz2
slixmpp-c42f1ad4c79863261977a9c5ea3b33be0b51b946.tar.xz
slixmpp-c42f1ad4c79863261977a9c5ea3b33be0b51b946.zip
Merge branch 'master' into develop
Diffstat (limited to 'tests')
-rw-r--r--tests/test_jid.py143
-rw-r--r--tests/test_tostring.py4
2 files changed, 144 insertions, 3 deletions
diff --git a/tests/test_jid.py b/tests/test_jid.py
index ef1145d3..aeb635a1 100644
--- a/tests/test_jid.py
+++ b/tests/test_jid.py
@@ -1,5 +1,5 @@
from sleekxmpp.test import *
-from sleekxmpp.xmlstream.jid import JID
+from sleekxmpp import JID, InvalidJID
class TestJIDClass(SleekTest):
@@ -137,5 +137,146 @@ class TestJIDClass(SleekTest):
self.assertFalse(jid1 == jid2, "Same JIDs are not considered equal")
self.assertTrue(jid1 != jid2, "Same JIDs are considered not equal")
+ def testZeroLengthDomain(self):
+ self.assertRaises(InvalidJID, JID, domain='')
+ self.assertRaises(InvalidJID, JID, 'user@/resource')
+
+ def testZeroLengthLocalPart(self):
+ self.assertRaises(InvalidJID, JID, local='', domain='test.com')
+ self.assertRaises(InvalidJID, JID, '@/test.com')
+
+ def testZeroLengthResource(self):
+ self.assertRaises(InvalidJID, JID, domain='test.com', resource='')
+ self.assertRaises(InvalidJID, JID, 'test.com/')
+
+ def test1023LengthDomain(self):
+ domain = ('a.' * 509) + 'a.com'
+ jid1 = JID(domain=domain)
+ jid2 = JID('user@%s/resource' % domain)
+
+ def test1023LengthLocalPart(self):
+ local = 'a' * 1023
+ jid1 = JID(local=local, domain='test.com')
+ jid2 = JID('%s@test.com' % local)
+
+ def test1023LengthResource(self):
+ resource = 'r' * 1023
+ jid1 = JID(domain='test.com', resource=resource)
+ jid2 = JID('test.com/%s' % resource)
+
+ def test1024LengthDomain(self):
+ domain = ('a.' * 509) + 'aa.com'
+ self.assertRaises(InvalidJID, JID, domain=domain)
+ self.assertRaises(InvalidJID, JID, 'user@%s/resource' % domain)
+
+ def test1024LengthLocalPart(self):
+ local = 'a' * 1024
+ self.assertRaises(InvalidJID, JID, local=local, domain='test.com')
+ self.assertRaises(InvalidJID, JID, '%s@/test.com' % local)
+
+ def test1024LengthResource(self):
+ resource = 'r' * 1024
+ self.assertRaises(InvalidJID, JID, domain='test.com', resource=resource)
+ self.assertRaises(InvalidJID, JID, 'test.com/%s' % resource)
+
+ def testTooLongDomainLabel(self):
+ domain = ('a' * 64) + '.com'
+ self.assertRaises(InvalidJID, JID, domain=domain)
+ self.assertRaises(InvalidJID, JID, 'user@%s/resource' % domain)
+
+ def testDomainEmptyLabel(self):
+ domain = 'aaa..bbb.com'
+ self.assertRaises(InvalidJID, JID, domain=domain)
+ self.assertRaises(InvalidJID, JID, 'user@%s/resource' % domain)
+
+ def testDomainIPv4(self):
+ domain = '127.0.0.1'
+ jid1 = JID(domain=domain)
+ jid2 = JID('user@%s/resource' % domain)
+
+ def testDomainIPv6(self):
+ domain = '[::1]'
+ jid1 = JID(domain=domain)
+ jid2 = JID('user@%s/resource' % domain)
+
+ def testDomainInvalidIPv6NoBrackets(self):
+ domain = '::1'
+ jid1 = JID(domain=domain)
+ jid2 = JID('user@%s/resource' % domain)
+
+ self.assertEqual(jid1.domain, '[::1]')
+ self.assertEqual(jid2.domain, '[::1]')
+
+ def testDomainInvalidIPv6MissingBracket(self):
+ domain = '[::1'
+ jid1 = JID(domain=domain)
+ jid2 = JID('user@%s/resource' % domain)
+
+ self.assertEqual(jid1.domain, '[::1]')
+ self.assertEqual(jid2.domain, '[::1]')
+
+ def testDomainWithPort(self):
+ domain = 'example.com:5555'
+ self.assertRaises(InvalidJID, JID, domain=domain)
+ self.assertRaises(InvalidJID, JID, 'user@%s/resource' % domain)
+
+ def testDomainWithTrailingDot(self):
+ domain = 'example.com.'
+ jid1 = JID(domain=domain)
+ jid2 = JID('user@%s/resource' % domain)
+
+ self.assertEqual(jid1.domain, 'example.com')
+ self.assertEqual(jid2.domain, 'example.com')
+
+ def testDomainWithDashes(self):
+ domain = 'example.com-'
+ self.assertRaises(InvalidJID, JID, domain=domain)
+ self.assertRaises(InvalidJID, JID, 'user@%s/resource' % domain)
+
+ domain = '-example.com'
+ self.assertRaises(InvalidJID, JID, domain=domain)
+ self.assertRaises(InvalidJID, JID, 'user@%s/resource' % domain)
+
+ def testACEDomain(self):
+ domain = 'xn--bcher-kva.ch'
+ jid1 = JID(domain=domain)
+ jid2 = JID('user@%s/resource' % domain)
+
+ self.assertEqual(jid1.domain.encode('utf-8'), b'b\xc3\xbccher.ch')
+ self.assertEqual(jid2.domain.encode('utf-8'), b'b\xc3\xbccher.ch')
+
+ def testJIDEscapeExistingSequences(self):
+ jid = JID(local='blah\\foo\\20bar', domain='example.com')
+ self.assertEqual(jid.local, 'blah\\foo\\5c20bar')
+
+ def testJIDEscape(self):
+ jid = JID(local='here\'s_a_wild_&_/cr%zy/_address_for:<wv>("IMPS")',
+ domain='example.com')
+ self.assertEqual(jid.local, r'here\27s_a_wild_\26_\2fcr%zy\2f_address_for\3a\3cwv\3e(\22IMPS\22)')
+
+ def testJIDUnescape(self):
+ jid = JID(local='here\'s_a_wild_&_/cr%zy/_address_for:<wv>("IMPS")',
+ domain='example.com')
+ ujid = jid.unescape()
+ self.assertEqual(ujid.local, 'here\'s_a_wild_&_/cr%zy/_address_for:<wv>("IMPS")')
+
+ jid = JID(local='blah\\foo\\20bar', domain='example.com')
+ ujid = jid.unescape()
+ self.assertEqual(ujid.local, 'blah\\foo\\20bar')
+
+ def testStartOrEndWithEscapedSpaces(self):
+ local = ' foo'
+ self.assertRaises(InvalidJID, JID, local=local, domain='example.com')
+ self.assertRaises(InvalidJID, JID, '%s@example.com' % local)
+
+ local = 'bar '
+ self.assertRaises(InvalidJID, JID, local=local, domain='example.com')
+ self.assertRaises(InvalidJID, JID, '%s@example.com' % local)
+
+ # Need more input for these cases. A JID starting with \20 *is* valid
+ # according to RFC 6122, but is not according to XEP-0106.
+ #self.assertRaises(InvalidJID, JID, '%s@example.com' % '\\20foo2')
+ #self.assertRaises(InvalidJID, JID, '%s@example.com' % 'bar2\\20')
+
suite = unittest.TestLoader().loadTestsFromTestCase(TestJIDClass)
diff --git a/tests/test_tostring.py b/tests/test_tostring.py
index e456d28e..cd50a7c1 100644
--- a/tests/test_tostring.py
+++ b/tests/test_tostring.py
@@ -1,7 +1,7 @@
from sleekxmpp.test import *
from sleekxmpp.stanza import Message
from sleekxmpp.xmlstream.stanzabase import ET, ElementBase
-from sleekxmpp.xmlstream.tostring import tostring, xml_escape
+from sleekxmpp.xmlstream.tostring import tostring, escape
class TestToString(SleekTest):
@@ -30,7 +30,7 @@ class TestToString(SleekTest):
def testXMLEscape(self):
"""Test escaping XML special characters."""
original = """<foo bar="baz">'Hi & welcome!'</foo>"""
- escaped = xml_escape(original)
+ escaped = escape(original)
desired = """&lt;foo bar=&quot;baz&quot;&gt;&apos;Hi"""
desired += """ &amp; welcome!&apos;&lt;/foo&gt;"""