本文整理汇总了Python中twisted.test.proto_helpers.StringTransport.getPeer方法的典型用法代码示例。如果您正苦于以下问题:Python StringTransport.getPeer方法的具体用法?Python StringTransport.getPeer怎么用?Python StringTransport.getPeer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twisted.test.proto_helpers.StringTransport
的用法示例。
在下文中一共展示了StringTransport.getPeer方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_incompleteUsername
# 需要导入模块: from twisted.test.proto_helpers import StringTransport [as 别名]
# 或者: from twisted.test.proto_helpers.StringTransport import getPeer [as 别名]
def test_incompleteUsername(self):
"""
Test that a login attempt using a username without a domain part
results in a customized authentication failure message which points
out that a domain part should be included in the username.
"""
mta = mail.MailTransferAgent(store=self.store)
installOn(mta, self.store)
factory = mta.getFactory()
protocol = factory.buildProtocol(("192.168.1.1", 12345))
transport = StringTransport()
transport.getHost = lambda: IPv4Address("TCP", "192.168.1.1", 54321)
transport.getPeer = lambda: IPv4Address("TCP", "192.168.1.1", 12345)
protocol.makeConnection(transport)
protocol.dataReceived("EHLO example.net\r\n")
protocol.dataReceived("AUTH LOGIN\r\n")
protocol.dataReceived("testuser".encode("base64") + "\r\n")
transport.clear()
protocol.dataReceived("password".encode("base64") + "\r\n")
written = transport.value()
protocol.connectionLost(failure.Failure(error.ConnectionDone()))
self.assertEquals(
written,
"535 Authentication failure [Username without domain name (ie "
'"yourname" instead of "[email protected]") not allowed; try '
"with a domain name.]\r\n",
)