Ignore:
Timestamp:
Jan 12, 2013, 4:40:38 PM (8 years ago)
Author:
Ralph Meijer <ralphm@…>
Branch:
default
Message:

Properly encode IDN domain names for SRV lookups.

Before Twisted 12.3.0, the SRV lookup done for outgoing
connections succeeded if passed a unicode string with all-ASCII
code points. A recent change made the DNS code more strict, and
only byte string are accepted as domain name. See
http://twistedmatrix.com/trac/ticket/6245 for details.

This change makes sure domain names are encoded to their ASCII
Compatible Equivalent (ACE) version before passing the resulting
byte string to twisted.names.srvconnect.SRVConnector, as per
RFC 3490.

Note that while connecting to servers with an IDN domain name
now works properly, authentication using MD5-Digest SASL mechanism
will fail until http://twistedmatrix.com/trac/ticket/5066 has been
resolved.

Fixes: #77.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • wokkel/test/test_generic.py

    r171 r178  
    269269        """
    270270        self.assertIdentical(None, self.request.timeout)
     271
     272
     273
     274class PrepareIDNNameTests(unittest.TestCase):
     275    """
     276    Tests for L{wokkel.generic.prepareIDNName}.
     277    """
     278
     279    def test_bytestring(self):
     280        """
     281        An ASCII-encoded byte string is left as-is.
     282        """
     283        name = b"example.com"
     284        result = generic.prepareIDNName(name)
     285        self.assertEqual(b"example.com", result)
     286
     287
     288    def test_unicode(self):
     289        """
     290        A unicode all-ASCII name is converted to an ASCII byte string.
     291        """
     292        name = u"example.com"
     293        result = generic.prepareIDNName(name)
     294        self.assertEqual(b"example.com", result)
     295
     296
     297    def test_unicodeNonASCII(self):
     298        """
     299        A unicode with non-ASCII is converted to its ACE equivalent.
     300        """
     301        name = u"\u00e9chec.example.com"
     302        result = generic.prepareIDNName(name)
     303        self.assertEqual(b"xn--chec-9oa.example.com", result)
     304
     305
     306    def test_unicodeHalfwidthIdeographicFullStop(self):
     307        """
     308        Exotic dots in unicode names are converted to Full Stop.
     309        """
     310        name = u"\u00e9chec.example\uff61com"
     311        result = generic.prepareIDNName(name)
     312        self.assertEqual(b"xn--chec-9oa.example.com", result)
     313
     314
     315    def test_unicodeTrailingDot(self):
     316        """
     317        Unicode names with trailing dots retain the trailing dot.
     318
     319        L{encodings.idna.ToASCII} doesn't allow the empty string as the input,
     320        hence the implementation needs to strip a trailing dot, and re-add it
     321        after encoding the labels.
     322        """
     323        name = u"example.com."
     324        result = generic.prepareIDNName(name)
     325        self.assertEqual(b"example.com.", result)
Note: See TracChangeset for help on using the changeset viewer.