Exemplo n.º 1
0
    def test_email_metrics(self):

        config = _createConfig()
        context = _createMailServerContext(config)
        message = SMTPMessage(context)
        message.lines = [
            "From: [email protected]",
            "To: [email protected]",
            "Subject: testing",
            "",
            "get transport obfs4",
        ]

        message.message = message.getIncomingMessage()
        responder = message.responder
        tr = proto_helpers.StringTransportWithDisconnection()
        tr.protocol = responder
        responder.makeConnection(tr)

        email_metrix = metrics.EmailMetrics()

        key1 = "email.obfs4.gmail.success.none"
        email_metrix.recordValidEmailRequest(responder)
        self.assertTrue(email_metrix.hotMetrics[key1] == 1)

        key2 = "email.obfs4.gmail.fail.none"
        email_metrix.recordInvalidEmailRequest(responder)
        self.assertTrue(email_metrix.hotMetrics[key2] == 1)
Exemplo n.º 2
0
 def setUp(self):
     """Create a server.MailServerContext and EmailBasedDistributor."""
     self.config = _createConfig()
     self.context = _createMailServerContext(self.config)
     self.smtpFromAddr = self.context.smtpFromAddr  # 'bridges@localhost'
     self.sched = Unscheduled()
     self.dist = self.context.distributor
Exemplo n.º 3
0
 def setUp(self):
     """Create a MailServerContext and EmailDistributor."""
     self.config = _createConfig()
     self.context = _createMailServerContext(self.config)
     self.smtpFromAddr = self.context.smtpFromAddr  # 'bridges@localhost'
     self.sched = Unscheduled()
     self.dist = self.context.distributor
 def setUp(self):
     """Create fake email, distributor, and associated context data."""
     self._moveGPGTestKeyfile()
     self.toAddress = "*****@*****.**"
     self.config = _createConfig()
     self.ctx = _createMailServerContext(self.config)
     self.distributor = self.ctx.distributor
 def setUp(self):
     """Create fake email, distributor, and associated context data."""
     self._moveGPGTestKeyfile()
     self.toAddress = "*****@*****.**"
     self.config = _createConfig()
     self.ctx = _createMailServerContext(self.config)
     self.distributor = self.ctx.distributor
Exemplo n.º 6
0
    def test_createResponseBody_two_requests_TooSoonEmail(self):
        """The same client making two requests in a row should receive a
        rate-limit warning for the second response.
        """
        # Set up a mock distributor which keeps state:
        dist = DummyEmailDistributorWithState()
        ctx = _createMailServerContext(self.config, dist)

        lines = self._getIncomingLines("testing@localhost")
        first = autoresponder.createResponseBody(lines, ctx, self.toAddress)
        self.assertSubstring("Here are your bridges", first)
        second = autoresponder.createResponseBody(lines, ctx, self.toAddress)
        self.assertSubstring("Please slow down", second)
    def test_createResponseBody_two_requests_TooSoonEmail(self):
        """The same client making two requests in a row should receive a
        rate-limit warning for the second response.
        """
        # Set up a mock distributor which keeps state:
        dist = DummyEmailDistributorWithState()
        ctx = _createMailServerContext(self.config, dist)

        lines = self._getIncomingLines("testing@localhost")
        first = autoresponder.createResponseBody(lines, ctx, self.toAddress)
        self.assertSubstring("Here are your bridges", first)
        second = autoresponder.createResponseBody(lines, ctx, self.toAddress)
        self.assertSubstring("Please slow down", second)
Exemplo n.º 8
0
    def setUp(self):
        """Set up our :class:`server.SMTPIncomingDelivery` instance, and reset the
        following ``TestCase`` attributes to ``None``:
            - ``helo``
            - ``proto``
            - ``origin``
            - ``user``
        """
        self.config = _createConfig()
        self.context = _createMailServerContext(self.config)
        self.delivery = server.SMTPIncomingDelivery()

        self.helo = None
        self.proto = None
        self.origin = None
        self.user = None
Exemplo n.º 9
0
    def setUp(self):
        """Set up our :class:`server.SMTPIncomingDelivery` instance, and reset the
        following ``TestCase`` attributes to ``None``:
            - ``helo``
            - ``proto``
            - ``origin``
            - ``user``
        """
        self.config = _createConfig()
        self.context = _createMailServerContext(self.config)
        self.delivery = server.SMTPIncomingDelivery()

        self.helo = None
        self.proto = None
        self.origin = None
        self.user = None
Exemplo n.º 10
0
    def setUp(self):
        """Set up a localhost SMTPIncomingServerFactory handler incoming SMTP
        connections.
        """
        config = _createConfig()
        context = _createMailServerContext(config)
        factory = server.SMTPIncomingServerFactory()
        factory.setContext(context)
        factory.protocol.timeout = None  # Otherwise the reactor gets dirty

        self.smtpFromAddr = context.smtpFromAddr  # 'bridges@localhost'
        self.proto = factory.buildProtocol(('127.0.0.1', 0))
        self.transport = proto_helpers.StringTransportWithDisconnection()
        self.proto.setTimeout(None)
        # Set the protocol; StringTransportWithDisconnection is a bit janky:
        self.transport.protocol = self.proto
        self.proto.makeConnection(self.transport)
Exemplo n.º 11
0
    def setUp(self):
        """Set up a localhost SMTPIncomingServerFactory handler incoming SMTP
        connections.
        """
        config = _createConfig()
        context = _createMailServerContext(config)
        factory = server.SMTPIncomingServerFactory()
        factory.setContext(context)
        factory.protocol.timeout = None  # Otherwise the reactor gets dirty

        self.smtpFromAddr = context.smtpFromAddr  # 'bridges@localhost'
        self.proto = factory.buildProtocol(('127.0.0.1', 0))
        self.transport = proto_helpers.StringTransportWithDisconnection()
        self.proto.setTimeout(None)
        # Set the protocol; StringTransportWithDisconnection is a bit janky:
        self.transport.protocol = self.proto
        self.proto.makeConnection(self.transport)
Exemplo n.º 12
0
    def test_createResponseBody_three_requests_TooSoonEmail(self):
        """Alice making a request, next Bob making a request, and then Alice again,
        should result in both of their first requests getting them bridges,
        and then Alice's second request gets her a rate-limit warning email.
        """
        # Set up a mock distributor which keeps state:
        dist = DummyEmailDistributorWithState()
        ctx = _createMailServerContext(self.config, dist)

        aliceLines = self._getIncomingLines("alice@localhost")
        aliceFirst = autoresponder.createResponseBody(aliceLines, ctx,
                                                      self.toAddress)
        self.assertSubstring("Here are your bridges", aliceFirst)

        bobLines = self._getIncomingLines("bob@localhost")
        bobFirst = autoresponder.createResponseBody(bobLines, ctx,
                                                    self.toAddress)
        self.assertSubstring("Here are your bridges", bobFirst)

        aliceSecond = autoresponder.createResponseBody(aliceLines, ctx,
                                                       self.toAddress)
        self.assertSubstring("Please slow down", aliceSecond)
    def test_createResponseBody_three_requests_TooSoonEmail(self):
        """Alice making a request, next Bob making a request, and then Alice again,
        should result in both of their first requests getting them bridges,
        and then Alice's second request gets her a rate-limit warning email.
        """
        # Set up a mock distributor which keeps state:
        dist = DummyEmailDistributorWithState()
        ctx = _createMailServerContext(self.config, dist)

        aliceLines = self._getIncomingLines("alice@localhost")
        aliceFirst = autoresponder.createResponseBody(aliceLines, ctx,
                                                      self.toAddress)
        self.assertSubstring("Here are your bridges", aliceFirst)

        bobLines = self._getIncomingLines("bob@localhost")
        bobFirst = autoresponder.createResponseBody(bobLines, ctx,
                                                    self.toAddress)
        self.assertSubstring("Here are your bridges", bobFirst)

        aliceSecond = autoresponder.createResponseBody(aliceLines, ctx,
                                                       self.toAddress)
        self.assertSubstring("Please slow down", aliceSecond)
Exemplo n.º 14
0
 def setUp(self):
     self.config = _createConfig()
     self.context = _createMailServerContext(self.config)
     self.message = SMTPMessage(self.context)
Exemplo n.º 15
0
 def setUp(self):
     self.config = _createConfig()
     self.context = _createMailServerContext(self.config)
     self.message = server.SMTPMessage(self.context,
                                       canonicalFromSMTP='localhost')
     self.line = string.ascii_lowercase
 def setUp(self):
     self.config = _createConfig()
     self.context = _createMailServerContext(self.config)
     self.message = SMTPMessage(self.context)
Exemplo n.º 17
0
 def setUp(self):
     self.config = _createConfig()
     self.context = _createMailServerContext(self.config)
     self.message = server.SMTPMessage(self.context,
                                       canonicalFromSMTP='localhost')
     self.line = string.ascii_lowercase