Skip to content

Commit

Permalink
Restore the test for unicode writing.
Browse files Browse the repository at this point in the history
  • Loading branch information
pythonspeed committed Jan 29, 2024
1 parent cb8ca5e commit e896cee
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion src/twisted/protocols/test/test_tls.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@

from hypothesis import given, strategies as st

from twisted.internet.task import Clock
from twisted.internet.task import Clock, deferLater
from twisted.internet import reactor
from twisted.python.compat import iterbytes

try:
Expand Down Expand Up @@ -687,6 +688,31 @@ def connectionMade(self):

return self.writeBeforeHandshakeTest(SimpleSendingProtocol, data)

def test_writeUnicodeRaisesTypeError(self):
"""
Writing C{unicode} to L{TLSMemoryBIOProtocol} throws a C{TypeError}.
"""
notBytes = "hello"
result = []

class SimpleSendingProtocol(Protocol):
def connectionMade(self):
try:
self.transport.write(notBytes)
self.transport.write(b"bytes")
self.transport.loseConnection()
except TypeError:
result.append(True)
self.transport.abortConnection()

def flush_logged_errors():
self.assertEqual(len(self.flushLoggedErrors(ConnectionLost, TypeError)), 2)

d = self.writeBeforeHandshakeTest(SimpleSendingProtocol, b"bytes")
d.addBoth(lambda ign: self.assertEqual(result, [True]))
d.addBoth(lambda ign: deferLater(reactor, 0, flush_logged_errors))
return d

def test_multipleWrites(self):
"""
If multiple separate TLS messages are received in a single chunk from
Expand Down

0 comments on commit e896cee

Please sign in to comment.