Example #1
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)
 def test_createResponseBody_bridges_obfs3(self):
     """A request for 'get transport obfs3' should receive a response."""
     lines = self._getIncomingLines("testing@localhost")
     lines[4] = "get transport obfs3"
     ret = autoresponder.createResponseBody(lines, self.ctx, self.toAddress)
     self.assertSubstring("Here are your bridges", ret)
     self.assertSubstring("obfs3", ret)
Example #4
0
 def test_createResponseBody_bridges_obfs3(self):
     """A request for 'get transport obfs3' should receive a response."""
     lines = self._getIncomingLines("testing@localhost")
     lines[4] = "get transport obfs3"
     ret = autoresponder.createResponseBody(lines, self.ctx, self.toAddress)
     self.assertSubstring("Here are your bridges", ret)
     self.assertSubstring("obfs3", ret)
 def test_createResponseBody_bridges_obfsobfswebz(self):
     """We should only pay attention to the *last* in a crazy request."""
     lines = self._getIncomingLines("testing@localhost")
     lines[4] = "get unblocked webz"
     lines.append("get transport obfs2")
     lines.append("get transport obfs3")
     ret = autoresponder.createResponseBody(lines, self.ctx, self.toAddress)
     self.assertSubstring("Here are your bridges", ret)
     self.assertSubstring("obfs3", ret)
Example #6
0
 def test_createResponseBody_bridges_obfsobfswebz(self):
     """We should only pay attention to the *last* in a crazy request."""
     lines = self._getIncomingLines("testing@localhost")
     lines[4] = "get unblocked webz"
     lines.append("get transport obfs2")
     lines.append("get transport obfs3")
     ret = autoresponder.createResponseBody(lines, self.ctx, self.toAddress)
     self.assertSubstring("Here are your bridges", ret)
     self.assertSubstring("obfs3", ret)
    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)
Example #8
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_bridges_invalid(self):
     """An invalid request for 'transport obfs3' should get help text."""
     lines = self._getIncomingLines("testing@localhost")
     lines[4] = "transport obfs3"
     ret = autoresponder.createResponseBody(lines, self.ctx, self.toAddress)
     self.assertSubstring("COMMANDs", ret)
 def test_createResponseBody_getKey(self):
     """A request for 'get key' should receive our GPG key."""
     lines = self._getIncomingLines()
     lines[4] = "get key"
     ret = autoresponder.createResponseBody(lines, self.ctx, self.toAddress)
     self.assertSubstring('-----BEGIN PGP PUBLIC KEY BLOCK-----', ret)
Example #11
0
 def test_createResponseBody_bridges_invalid(self):
     """An invalid request for 'transport obfs3' should get help text."""
     lines = self._getIncomingLines("testing@localhost")
     lines[4] = "transport obfs3"
     ret = autoresponder.createResponseBody(lines, self.ctx, self.toAddress)
     self.assertSubstring("COMMANDs", ret)
Example #12
0
 def test_createResponseBody_getKey(self):
     """A request for 'get key' should receive our GPG key."""
     lines = self._getIncomingLines()
     lines[4] = "get key"
     ret = autoresponder.createResponseBody(lines, self.ctx, self.toAddress)
     self.assertSubstring('-----BEGIN PGP PUBLIC KEY BLOCK-----', ret)