Exemplo n.º 1
0
    def test_getBridges_rateLimitExceeded(self):
        if os.environ.get("CI"):
            if not self.pid or not processExists(self.pid):
                raise FailTest("Could not start BridgeDB process on CI server!")
        if not self.pid or not processExists(self.pid):
            raise SkipTest("Can't run test: no BridgeDB process running.")

        # send the mail to bridgedb, choosing a random email address
        FROM_ADDRESS = FROM_ADDRESS_TEMPLATE % random.randint(
            MIN_FROM_ADDRESS, MAX_FROM_ADDRESS)
        sendMail(FROM_ADDRESS)

        # then check that our local SMTP server received a response
        # and that response contained some bridges
        self.server.getAndCheckMessageContains("Here are your bridges")

        # send another request from the same email address
        sendMail(FROM_ADDRESS)

        # this time, the email response should not contain any bridges
        self.server.getAndCheckMessageContains(
            "You have exceeded the rate limit. Please slow down!")

        # then we send another request from the same email address
        sendMail(FROM_ADDRESS)

        # now there should be no response at all (wait 1 second to make sure)
        self.server.checkNoMessageReceived(timeoutInSecs=1.0)
Exemplo n.º 2
0
    def test_getBridges_rateLimitExceeded(self):
        if os.environ.get("CI"):
            if not self.pid or not processExists(self.pid):
                raise FailTest(
                    "Could not start BridgeDB process on CI server!")
        if not self.pid or not processExists(self.pid):
            raise SkipTest("Can't run test: no BridgeDB process running.")

        # send the mail to bridgedb, choosing a random email address
        FROM_ADDRESS = FROM_ADDRESS_TEMPLATE % random.randint(
            MIN_FROM_ADDRESS, MAX_FROM_ADDRESS)
        sendMail(FROM_ADDRESS)

        # then check that our local SMTP server received a response
        # and that response contained some bridges
        self.server.getAndCheckMessageContains("Here are your bridges")

        # send another request from the same email address
        sendMail(FROM_ADDRESS)

        # this time, the email response should not contain any bridges
        self.server.getAndCheckMessageContains(
            "You have exceeded the rate limit. Please slow down!")

        # then we send another request from the same email address
        sendMail(FROM_ADDRESS)

        # now there should be no response at all (wait 1 second to make sure)
        self.server.checkNoMessageReceived(timeoutInSecs=1.0)
Exemplo n.º 3
0
    def test_getBridges(self):
        if os.environ.get("CI"):
            if not self.pid or not processExists(self.pid):
                raise FailTest("Could not start BridgeDB process on CI server!")
        if not self.pid or not processExists(self.pid):
            raise SkipTest("Can't run test: no BridgeDB process running.")

        # send the mail to bridgedb, choosing a random email address
        sendMail(fromAddress=FROM_ADDRESS_TEMPLATE
                 % random.randint(MIN_FROM_ADDRESS, MAX_FROM_ADDRESS))

        # then check that our local SMTP server received a response
        # and that response contained some bridges
        self.server.getAndCheckMessageContains("Here are your bridges")
    def test_bridgedb_SIGHUP_assignments_log(self):
        """Test that BridgeDB creates a new ``assignments.log`` file after
        receiving a SIGHUP.
        """
        if os.environ.get("CI"):
            if not self.pid or not processExists(self.pid):
                raise FailTest("Could not start BridgeDB process on CI server!")
        if not self.pid or not processExists(self.pid):
            raise SkipTest("Can't run test: no BridgeDB process running.")

        os.unlink(self.assignmentsFile)
        os.kill(self.pid, signal.SIGHUP)
        self.doSleep()
        self.assertTrue(os.path.isfile(self.assignmentsFile))
Exemplo n.º 5
0
    def test_bridgedb_SIGHUP_assignments_log(self):
        """Test that BridgeDB creates a new ``assignments.log`` file after
        receiving a SIGHUP.
        """
        if os.environ.get("CI"):
            if not self.pid or not processExists(self.pid):
                raise FailTest("Could not start BridgeDB process on CI server!")
        if not self.pid or not processExists(self.pid):
            raise SkipTest("Can't run test: no BridgeDB process running.")

        os.unlink(self.assignmentsFile)
        os.kill(self.pid, signal.SIGHUP)
        self.doSleep()
        self.assertTrue(os.path.isfile(self.assignmentsFile))
Exemplo n.º 6
0
    def test_getBridges(self):
        if os.environ.get("CI"):
            if not self.pid or not processExists(self.pid):
                raise FailTest(
                    "Could not start BridgeDB process on CI server!")
        if not self.pid or not processExists(self.pid):
            raise SkipTest("Can't run test: no BridgeDB process running.")

        # send the mail to bridgedb, choosing a random email address
        sendMail(fromAddress=FROM_ADDRESS_TEMPLATE %
                 random.randint(MIN_FROM_ADDRESS, MAX_FROM_ADDRESS))

        # then check that our local SMTP server received a response
        # and that response contained some bridges
        self.server.getAndCheckMessageContains("Here are your bridges")
Exemplo n.º 7
0
    def test_get_scramblesuit_ipv4(self):
        if os.environ.get("CI"):
            if not self.pid or not processExists(self.pid):
                raise FailTest(
                    "Could not start BridgeDB process on CI server!")
        else:
            raise SkipTest(("The mechanize tests cannot handle self-signed  "
                            "TLS certificates, and thus require opening "
                            "another port for running a plaintext HTTP-only "
                            "BridgeDB webserver. Because of this, these tests "
                            "are only run on CI servers."))

        self.openBrowser()
        self.goToOptionsPage()

        PT = 'scramblesuit'
        soup = self.submitOptions(transport=PT,
                                  ipv6=False,
                                  captchaResponse=CAPTCHA_RESPONSE)
        bridges = self.getBridgeLinesFromSoup(soup, fieldsPerBridge=4)
        for bridge in bridges:
            pt = bridge[0]
            password = bridge[-1]
            self.assertEquals(PT, pt)
            self.assertTrue(
                password.find("password="******"Password field missing expected text")
    def test_bridgedb_assignments_log(self):
        """This test should only be run if a BridgeDB server has already been
        started in another process.

        To see how this is done for the Travis CI tests, see the
        'before_script' section of the ``.travis.yml`` file in the top
        directory of this repository.

        This test ensures that an ``assignments.log`` file is created after a
        BridgeDB process was started.
        """
        if os.environ.get("CI"):
            if not self.pid or not processExists(self.pid):
                raise FailTest("Could not start BridgeDB process on CI server!")
        if not self.pid or not processExists(self.pid):
            raise SkipTest("Can't run test: no BridgeDB process running.")

        self.assertTrue(os.path.isfile(self.assignmentsFile))
Exemplo n.º 9
0
    def test_bridgedb_assignments_log(self):
        """This test should only be run if a BridgeDB server has already been
        started in another process.

        To see how this is done for the Travis CI tests, see the
        'before_script' section of the ``.travis.yml`` file in the top
        directory of this repository.

        This test ensures that an ``assignments.log`` file is created after a
        BridgeDB process was started.
        """
        if os.environ.get("CI"):
            if not self.pid or not processExists(self.pid):
                raise FailTest("Could not start BridgeDB process on CI server!")
        if not self.pid or not processExists(self.pid):
            raise SkipTest("Can't run test: no BridgeDB process running.")

        self.assertTrue(os.path.isfile(self.assignmentsFile))
Exemplo n.º 10
0
    def test_bridgedb_SIGUSR1_buckets(self):
        """Test that BridgeDB dumps buckets appropriately after a SIGUSR1."""
        if os.environ.get("CI"):
            if not self.pid or not processExists(self.pid):
                raise FailTest("Could not start BridgeDB process on CI server!")
        if not self.pid or not processExists(self.pid):
            raise SkipTest("Can't run test: no BridgeDB process running.")

        os.kill(self.pid, signal.SIGUSR1)
        self.doSleep()
        buckets = [['email', False], ['https', False], ['unallocated', False]]
        for rundirfile in os.listdir(self.rundir):
            for bucket in buckets:
                if rundirfile.startswith(bucket[0]):
                    bucket[1] = True
                    break
        for bucket in buckets:
            self.assertTrue(bucket[1], "%s bucket was not dumped!" % bucket[0])
Exemplo n.º 11
0
    def setUp(self):
        if not os.environ.get("CI"):
            raise SkipTest(("The mechanize tests cannot handle self-signed  "
                            "TLS certificates, and thus require opening "
                            "another port for running a plaintext HTTP-only "
                            "BridgeDB webserver. Because of this, these tests "
                            "are only run on CI servers."))
        if not PID or not processExists(PID):
            raise FailTest("Could not start BridgeDB process on CI server!")

        self.br = None
Exemplo n.º 12
0
    def setUp(self):
        if not os.environ.get("CI"):
            raise SkipTest(("The mechanize tests cannot handle self-signed  "
                            "TLS certificates, and thus require opening "
                            "another port for running a plaintext HTTP-only "
                            "BridgeDB webserver. Because of this, these tests "
                            "are only run on CI servers."))
        if not PID or not processExists(PID):
            raise FailTest("Could not start BridgeDB process on CI server!")

        self.br = None
Exemplo n.º 13
0
    def test_getBridges_stressTest(self):
        '''Sends a large number of emails in a short period of time, and checks
        that a response is received for each message.
        '''
        if os.environ.get("CI"):
            if not self.pid or not processExists(self.pid):
                raise FailTest("Could not start BridgeDB process on CI server!")
        if not self.pid or not processExists(self.pid):
            raise SkipTest("Can't run test: no BridgeDB process running.")

        NUM_MAILS = 100
        for i in range(NUM_MAILS):
            # Note: if by chance two emails with the same FROM_ADDRESS are
            # generated, this test will fail Setting 'MAX_FROM_ADDRESS' to be
            # a high value reduces the probability of this occuring, but does
            # not rule it out
            sendMail(fromAddress=FROM_ADDRESS_TEMPLATE
                     % random.randint(MIN_FROM_ADDRESS, MAX_FROM_ADDRESS))

        for i in range(NUM_MAILS):
            self.server.getAndCheckMessageContains("Here are your bridges")
Exemplo n.º 14
0
    def test_getBridges_stressTest(self):
        '''Sends a large number of emails in a short period of time, and checks
        that a response is received for each message.
        '''
        if os.environ.get("CI"):
            if not self.pid or not processExists(self.pid):
                raise FailTest(
                    "Could not start BridgeDB process on CI server!")
        if not self.pid or not processExists(self.pid):
            raise SkipTest("Can't run test: no BridgeDB process running.")

        NUM_MAILS = 100
        for i in range(NUM_MAILS):
            # Note: if by chance two emails with the same FROM_ADDRESS are
            # generated, this test will fail Setting 'MAX_FROM_ADDRESS' to be
            # a high value reduces the probability of this occuring, but does
            # not rule it out
            sendMail(fromAddress=FROM_ADDRESS_TEMPLATE %
                     random.randint(MIN_FROM_ADDRESS, MAX_FROM_ADDRESS))

        for i in range(NUM_MAILS):
            self.server.getAndCheckMessageContains("Here are your bridges")
Exemplo n.º 15
0
    def test_get_obfs4_ipv4(self):
        """Try asking for obfs4 bridges, and check that the PT arguments in the
        returned bridge lines were space-separated.

        This is a regression test for #12932, see
        https://bugs.torproject.org/12932.
        """
        if os.environ.get("CI"):
            if not self.pid or not processExists(self.pid):
                raise FailTest(
                    "Could not start BridgeDB process on CI server!")
        else:
            raise SkipTest(("The mechanize tests cannot handle self-signed  "
                            "TLS certificates, and thus require opening "
                            "another port for running a plaintext HTTP-only "
                            "BridgeDB webserver. Because of this, these tests "
                            "are only run on CI servers."))

        self.openBrowser()
        self.goToOptionsPage()

        PT = 'obfs4'

        try:
            soup = self.submitOptions(transport=PT,
                                      ipv6=False,
                                      captchaResponse=CAPTCHA_RESPONSE)
        except ValueError as error:
            if 'non-disabled' in str(error):
                raise SkipTest(
                    "Pluggable Transport obfs4 is currently disabled.")

        bridges = self.getBridgeLinesFromSoup(soup, fieldsPerBridge=6)
        for bridge in bridges:
            pt = bridge[0]
            ptArgs = bridge[-3:]
            self.assertEquals(PT, pt)
            self.assertTrue(
                len(ptArgs) == 3,
                ("Expected obfs4 bridge line to have 3 PT args, "
                 "found %d instead: %s") % (len(ptArgs), ptArgs))
Exemplo n.º 16
0
    def test_get_obfs3_ipv4(self):
        if os.environ.get("CI"):
            if not self.pid or not processExists(self.pid):
                raise FailTest("Could not start BridgeDB process on CI server!")
        else:
            raise SkipTest(("The mechanize tests cannot handle self-signed  "
                            "TLS certificates, and thus require opening "
                            "another port for running a plaintext HTTP-only "
                            "BridgeDB webserver. Because of this, these tests "
                            "are only run on CI servers."))

        self.openBrowser()
        self.goToOptionsPage()

        PT = 'obfs3'
        soup = self.submitOptions(transport=PT, ipv6=False,
                                  captchaResponse=CAPTCHA_RESPONSE)
        bridges = self.getBridgeLinesFromSoup(soup, fieldsPerBridge=3)
        for bridge in bridges:
            pt = bridge[0]
            self.assertEquals(PT, pt)
Exemplo n.º 17
0
    def test_get_obfs4_ipv4_publickey(self):
        """Ask for obfs4 bridges and check that there is an 'public-key' PT
        argument in the bridge lines.
        """
        if os.environ.get("CI"):
            if not self.pid or not processExists(self.pid):
                raise FailTest(
                    "Could not start BridgeDB process on CI server!")
        else:
            raise SkipTest(("The mechanize tests cannot handle self-signed  "
                            "TLS certificates, and thus require opening "
                            "another port for running a plaintext HTTP-only "
                            "BridgeDB webserver. Because of this, these tests "
                            "are only run on CI servers."))

        self.openBrowser()
        self.goToOptionsPage()

        PT = 'obfs4'

        try:
            soup = self.submitOptions(transport=PT,
                                      ipv6=False,
                                      captchaResponse=CAPTCHA_RESPONSE)
        except ValueError as error:
            if 'non-disabled' in str(error):
                raise SkipTest(
                    "Pluggable Transport obfs4 is currently disabled.")

        bridges = self.getBridgeLinesFromSoup(soup, fieldsPerBridge=6)
        for bridge in bridges:
            ptArgs = bridge[-3:]
            hasPublicKey = False
            for arg in ptArgs:
                if 'public-key' in arg:
                    hasPublicKey = True

            self.assertTrue(
                hasPublicKey,
                "obfs4 bridge line is missing 'public-key' PT arg.")
Exemplo n.º 18
0
    def test_get_vanilla_ipv6(self):
        if os.environ.get("CI"):
            if not self.pid or not processExists(self.pid):
                raise FailTest("Could not start BridgeDB process on CI server!")
        else:
            raise SkipTest(("The mechanize tests cannot handle self-signed  "
                            "TLS certificates, and thus require opening "
                            "another port for running a plaintext HTTP-only "
                            "BridgeDB webserver. Because of this, these tests "
                            "are only run on CI servers."))

        self.openBrowser()
        self.goToOptionsPage()

        PT = '0'
        soup = self.submitOptions(transport=PT, ipv6=True,
                                  captchaResponse=CAPTCHA_RESPONSE)
        bridges = self.getBridgeLinesFromSoup(soup, fieldsPerBridge=2)
        for bridge in bridges:
            self.assertTrue(bridge != None)
            addr = bridge[0].rsplit(':', 1)[0].strip('[]')
            self.assertIsInstance(ipaddr.IPAddress(addr), ipaddr.IPv6Address)
Exemplo n.º 19
0
    def test_get_obfs4_ipv4(self):
        """Try asking for obfs4 bridges, and check that the PT arguments in the
        returned bridge lines were space-separated.

        This is a regression test for #12932, see
        https://bugs.torproject.org/12932.
        """
        if os.environ.get("CI"):
            if not self.pid or not processExists(self.pid):
                raise FailTest("Could not start BridgeDB process on CI server!")
        else:
            raise SkipTest(("The mechanize tests cannot handle self-signed  "
                            "TLS certificates, and thus require opening "
                            "another port for running a plaintext HTTP-only "
                            "BridgeDB webserver. Because of this, these tests "
                            "are only run on CI servers."))

        self.openBrowser()
        self.goToOptionsPage()

        PT = 'obfs4'

        try:
            soup = self.submitOptions(transport=PT, ipv6=False,
                                      captchaResponse=CAPTCHA_RESPONSE)
        except ValueError as error:
            if 'non-disabled' in str(error):
                raise SkipTest("Pluggable Transport obfs4 is currently disabled.")

        bridges = self.getBridgeLinesFromSoup(soup, fieldsPerBridge=6)
        for bridge in bridges:
            pt = bridge[0]
            ptArgs = bridge[-3:]
            self.assertEquals(PT, pt)
            self.assertTrue(len(ptArgs) == 3,
                            ("Expected obfs4 bridge line to have 3 PT args, "
                             "found %d instead: %s") % (len(ptArgs), ptArgs))
Exemplo n.º 20
0
    def test_get_obfs4_ipv4_nodeid(self):
        """Ask for obfs4 bridges and check that there is an 'node-id' PT
        argument in the bridge lines.
        """
        if os.environ.get("CI"):
            if not self.pid or not processExists(self.pid):
                raise FailTest("Could not start BridgeDB process on CI server!")
        else:
            raise SkipTest(("The mechanize tests cannot handle self-signed  "
                            "TLS certificates, and thus require opening "
                            "another port for running a plaintext HTTP-only "
                            "BridgeDB webserver. Because of this, these tests "
                            "are only run on CI servers."))

        self.openBrowser()
        self.goToOptionsPage()

        PT = 'obfs4'

        try:
            soup = self.submitOptions(transport=PT, ipv6=False,
                                      captchaResponse=CAPTCHA_RESPONSE)
        except ValueError as error:
            if 'non-disabled' in str(error):
                raise SkipTest("Pluggable Transport obfs4 is currently disabled.")

        bridges = self.getBridgeLinesFromSoup(soup, fieldsPerBridge=6)
        for bridge in bridges:
            ptArgs = bridge[-3:]
            hasNodeID = False
            for arg in ptArgs:
                if 'node-id' in arg:
                    hasNodeID = True

            self.assertTrue(hasNodeID,
                            "obfs4 bridge line is missing 'node-id' PT arg.")
Exemplo n.º 21
0
    def test_get_vanilla_ipv6(self):
        if os.environ.get("CI"):
            if not self.pid or not processExists(self.pid):
                raise FailTest(
                    "Could not start BridgeDB process on CI server!")
        else:
            raise SkipTest(("The mechanize tests cannot handle self-signed  "
                            "TLS certificates, and thus require opening "
                            "another port for running a plaintext HTTP-only "
                            "BridgeDB webserver. Because of this, these tests "
                            "are only run on CI servers."))

        self.openBrowser()
        self.goToOptionsPage()

        PT = '0'
        soup = self.submitOptions(transport=PT,
                                  ipv6=True,
                                  captchaResponse=CAPTCHA_RESPONSE)
        bridges = self.getBridgeLinesFromSoup(soup, fieldsPerBridge=2)
        for bridge in bridges:
            self.assertTrue(bridge != None)
            addr = bridge[0].rsplit(':', 1)[0].strip('[]')
            self.assertIsInstance(ipaddr.IPAddress(addr), ipaddr.IPv6Address)