'Test that a C{MAIL FROM} command with an address rejected by an
L{smtp.SMTP} instance\'s portal is responded to with the correct error
code.'

@implementer(ICredentialsChecker)
def test_portalRejectedSenderAddress(self):

    class DisallowAnonymousAccess(object, ):
        '\n                                                Checker    for    L{IAnonymous}    which    rejects    authentication    attempts.\n                                                '
        credentialInterfaces = (IAnonymous,)
        def requestAvatarId(self, credentials):
            return defer.fail(UnauthorizedLogin())
    realm = SingletonRealm(smtp.IMessageDelivery, NotImplementedDelivery())
    portal = Portal(realm, [DisallowAnonymousAccess()])
    proto = smtp.SMTP()
    proto.portal = portal
    trans = StringTransport()
    proto.makeConnection(trans)
    proto.dataReceived('HELO    example.com\r\n')
    trans.clear()
    proto.dataReceived('MAIL    FROM:<alice@example.com>\r\n')
    proto.connectionLost(error.ConnectionLost())
    self.assertEqual(trans.value(), '550    Cannot    receive    from    specified    address    <alice@example.com>:    Sender    not    acceptable\r\n')
