Example #1
0
    def test_wrong_host(self):
        '''GPG fingerprint: unknown hostname'''

        httpd.start(4443, self.data_dir, True, self.localhost_pem)

        result = jockey.detection.download_gpg_fingerprint(
            'https://127.0.0.1:4443/fingerprint')
        self.assertEqual(result, None, result)
Example #2
0
    def test_bad_fingerprint_syntax(self):
        '''GPG fingerprint: no fingerprint found'''

        httpd.start(4443, self.data_dir, True, self.localhost_pem)

        result = jockey.detection.download_gpg_fingerprint(
            'https://localhost:4443/bad_fingerprint')
        self.assertEqual(result, None, result)
Example #3
0
    def test_404(self):
        '''GPG fingerprint: nonexisting address'''

        httpd.start(4443, self.data_dir, True, self.localhost_pem)

        result = jockey.detection.download_gpg_fingerprint(
            'https://localhost:4443/nonexisting')
        self.assertEqual(result, None, result)
Example #4
0
    def test_wrong_cert(self):
        '''wrong certificate'''

        OSLib.inst.ssl_cert_file_paths = [self.localhost_expired_pem]
        httpd.start(4443, '.', True, self.localhost_pem)
        result = jockey.detection.download_gpg_fingerprint(
            'https://127.0.0.1:4443/fingerprint')
        self.assertEqual(result, None, result)
Example #5
0
    def test_expired_cert(self):
        '''expired certificate'''

        httpd.start(4443, self.data_dir, True, self.localhost_expired_pem)

        result = jockey.detection.download_gpg_fingerprint(
                'https://127.0.0.1:4443/fingerprint')
        self.assertEqual(result, None, result)
Example #6
0
    def test_wrong_cert(self):
        '''wrong certificate'''

        OSLib.inst.ssl_cert_file_paths = [self.localhost_expired_pem]
        httpd.start(4443, '.', True, self.localhost_pem)
        result = jockey.detection.download_gpg_fingerprint(
                'https://127.0.0.1:4443/fingerprint')
        self.assertEqual(result, None, result)
Example #7
0
    def test_404(self):
        '''GPG fingerprint: nonexisting address'''

        httpd.start(4443, self.data_dir, True, self.localhost_pem)

        result = jockey.detection.download_gpg_fingerprint(
                'https://localhost:4443/nonexisting')
        self.assertEqual(result, None, result)
Example #8
0
    def test_wrong_host(self):
        '''GPG fingerprint: unknown hostname'''

        httpd.start(4443, self.data_dir, True, self.localhost_pem)

        result = jockey.detection.download_gpg_fingerprint(
                'https://127.0.0.1:4443/fingerprint')
        self.assertEqual(result, None, result)
Example #9
0
    def test_valid(self):
        '''GPG fingerprint: valid certificate, hostname, and fingerprint'''

        httpd.start(4443, self.data_dir, True, self.localhost_pem)

        result = jockey.detection.download_gpg_fingerprint(
                'https://localhost:4443/fingerprint')
        self.assertEqual(result, '0000 1111 2222 3333 4444  5555 6666 7777 8888 9999')
Example #10
0
    def test_bad_fingerprint_syntax(self):
        '''GPG fingerprint: no fingerprint found'''

        httpd.start(4443, self.data_dir, True, self.localhost_pem)

        result = jockey.detection.download_gpg_fingerprint(
                'https://localhost:4443/bad_fingerprint')
        self.assertEqual(result, None, result)
Example #11
0
    def test_expired_cert(self):
        '''expired certificate'''

        httpd.start(4443, self.data_dir, True, self.localhost_expired_pem)

        result = jockey.detection.download_gpg_fingerprint(
            'https://127.0.0.1:4443/fingerprint')
        self.assertEqual(result, None, result)
Example #12
0
    def test_valid(self):
        '''GPG fingerprint: valid certificate, hostname, and fingerprint'''

        httpd.start(4443, self.data_dir, True, self.localhost_pem)

        result = jockey.detection.download_gpg_fingerprint(
            'https://localhost:4443/fingerprint')
        self.assertEqual(result,
                         '0000 1111 2222 3333 4444  5555 6666 7777 8888 9999')
Example #13
0
    def _start_keyserver(klass):
        '''Run a keyserver on localhost (just serves the test suite key).'''

        dir = os.path.join(OSLib.inst.workdir, 'pks')
        os.mkdir(dir, 0o700)
        # quiesce a message from gpg
        open(os.path.join(dir, 'secring.gpg'), 'w').close()
        lookup = open(os.path.join(dir, 'lookup'), 'w')
        assert subprocess.call(['gpg', '--homedir', dir, '--no-default-keyring',
            '--primary-keyring', os.path.join(os.path.dirname(__file__), 'data/pubring.gpg'),
            '--export', '-a'], stdout=lookup) == 0
        httpd.start(11371, OSLib.inst.workdir)
Example #14
0
    def test_system_cert(self):
        '''system-wide trusted certificate shouldn't match local test server'''

        if not self.orig_cert_file_paths:
            print('[SKIP, not available]')
            return

        OSLib.inst.ssl_cert_file_paths = self.orig_cert_file_paths
        httpd.start(4443, '.', True, self.localhost_pem)

        result = jockey.detection.download_gpg_fingerprint(
            'https://127.0.0.1:4443/fingerprint')
        self.assertEqual(result, None, result)
Example #15
0
    def test_system_cert(self):
        '''system-wide trusted certificate shouldn't match local test server'''

        if not self.orig_cert_file_paths:
            print('[SKIP, not available]')
            return

        OSLib.inst.ssl_cert_file_paths = self.orig_cert_file_paths
        httpd.start(4443, '.', True, self.localhost_pem)

        result = jockey.detection.download_gpg_fingerprint(
                'https://127.0.0.1:4443/fingerprint')
        self.assertEqual(result, None, result)
Example #16
0
    def test_download_http_nocancel(self):
        '''download_url(), HTTP, no cancelling'''

        self.stop_capture()

        ui = sandbox.TestUI()

        # temporary file
        httpd.start(8427, OSLib.inst.workdir)
        (fname, h) = ui.download_url('http://localhost:8427/stuff')
        httpd.stop()
        self.assertEqual(open(fname).read(), self.big_file_contents)
        os.unlink(fname)

        self.assertRaises(IndexError, ui.pop_error)

        # we got progress reports
        self.assertEqual(ui.cur_progress, [
            'http://localhost:8427/stuff',
            len(self.big_file_contents),
            len(self.big_file_contents)
        ])

        # specified file name
        dest = os.path.join(OSLib.inst.workdir, 'destfile')
        httpd.start(8427, OSLib.inst.workdir)
        (fname, h) = ui.download_url('http://localhost:8427/stuff', dest)
        httpd.stop()
        self.assertEqual(fname, dest)
        self.assertEqual(open(dest).read(), self.big_file_contents)
        os.unlink(dest)

        self.assertRaises(IndexError, ui.pop_error)

        # we got progress reports
        self.assertEqual(ui.cur_progress, [
            'http://localhost:8427/stuff',
            len(self.big_file_contents),
            len(self.big_file_contents)
        ])

        # nonexisting file
        httpd.start(8427, OSLib.inst.workdir)
        (fname, h) = ui.download_url('http://localhost:8427/nonexisting')
        httpd.stop()
        self.assertEqual(fname, None)

        # one error message about download failure
        self.assert_(ui.pop_error())
        self.assertRaises(IndexError, ui.pop_error)

        # nonexisting server
        httpd.start(8427, OSLib.inst.workdir)
        (fname, h) = ui.download_url('http://i.do.not.exist:8080/nonexisting')
        httpd.stop()
        self.assertEqual(fname, None)

        # one error message about download failure
        self.assert_(ui.pop_error())
        self.assertRaises(IndexError, ui.pop_error)
Example #17
0
    def test_download_http_nocancel(self):
        '''download_url(), HTTP, no cancelling'''

        self.stop_capture()

        ui = sandbox.TestUI()

        # temporary file
        httpd.start(8427, OSLib.inst.workdir)
        (fname, h) = ui.download_url('http://localhost:8427/stuff')
        httpd.stop()
        self.assertEqual(open(fname).read(), self.big_file_contents)
        os.unlink(fname)

        self.assertRaises(IndexError, ui.pop_error)

        # we got progress reports
        self.assertEqual(ui.cur_progress, ['http://localhost:8427/stuff',
            len(self.big_file_contents), len(self.big_file_contents)])

        # specified file name
        dest = os.path.join(OSLib.inst.workdir, 'destfile')
        httpd.start(8427, OSLib.inst.workdir)
        (fname, h) = ui.download_url('http://localhost:8427/stuff', dest)
        httpd.stop()
        self.assertEqual(fname, dest)
        self.assertEqual(open(dest).read(), self.big_file_contents)
        os.unlink(dest)

        self.assertRaises(IndexError, ui.pop_error)

        # we got progress reports
        self.assertEqual(ui.cur_progress, ['http://localhost:8427/stuff',
            len(self.big_file_contents), len(self.big_file_contents)])

        # nonexisting file
        httpd.start(8427, OSLib.inst.workdir)
        (fname, h) = ui.download_url('http://localhost:8427/nonexisting')
        httpd.stop()
        self.assertEqual(fname, None)

        # one error message about download failure
        self.assert_(ui.pop_error())
        self.assertRaises(IndexError, ui.pop_error)

        # nonexisting server
        httpd.start(8427, OSLib.inst.workdir)
        (fname, h) = ui.download_url('http://i.do.not.exist:8080/nonexisting')
        httpd.stop()
        self.assertEqual(fname, None)

        # one error message about download failure
        self.assert_(ui.pop_error())
        self.assertRaises(IndexError, ui.pop_error)
Example #18
0
    def test_robots_txt(self):

        file_uri = 'robots.txt'

        # start httpd in the background
        httpd_pid = os.fork()
        if httpd_pid == 0:
            httpd.start(config.settings['server'], config.db_connect)

        response = requests.get('http://' +
                                config.settings['server']['http_addr'] + ':' +
                                str(config.settings['server']['http_port']) +
                                '/' + file_uri)

        f = open(
            os.path.join(config.settings['server']['htdocs_dir'], file_uri),
            'r')
        expected_response = f.read()
        f.close()

        self.assertEqual(expected_response, response.text)
Example #19
0
    def test_robots_txt(self):

        file_uri = "robots.txt"

        # start httpd in the background
        httpd_pid = os.fork()
        if httpd_pid == 0:
            httpd.start(config.settings["server"], config.db_connect)

        response = requests.get(
            "http://"
            + config.settings["server"]["http_addr"]
            + ":"
            + str(config.settings["server"]["http_port"])
            + "/"
            + file_uri
        )

        f = open(os.path.join(config.settings["server"]["htdocs_dir"], file_uri), "r")
        expected_response = f.read()
        f.close()

        self.assertEqual(expected_response, response.text)
Example #20
0
    def test_download_http_cancel(self):
        '''download_url(), HTTP, cancelling'''

        self.stop_capture()

        ui = sandbox.TestUI()

        # temporary file
        httpd.start(8427, OSLib.inst.workdir)
        ui.cancel_progress = True
        (fname, h) = ui.download_url('http://localhost:8427/stuff')
        httpd.stop()
        self.assertEqual(fname, None)

        self.assertRaises(IndexError, ui.pop_error)

        # we got progress reports
        self.assertEqual(ui.cur_progress[2], len(self.big_file_contents))
        ratio = float(ui.cur_progress[1]) / len(self.big_file_contents)
        self.assert_(ratio >= 0.3, ratio)
        self.assert_(ratio < 0.5)

        # specified file name
        dest = os.path.join(OSLib.inst.workdir, 'destfile')
        ui.cancel_progress = True
        httpd.start(8427, OSLib.inst.workdir)
        (fname, h) = ui.download_url('http://localhost:8427/stuff', dest)
        httpd.stop()
        self.assertEqual(fname, None)

        self.assertRaises(IndexError, ui.pop_error)

        # we got progress reports
        self.assertEqual(ui.cur_progress[2], len(self.big_file_contents))
        ratio = float(ui.cur_progress[1]) / len(self.big_file_contents)
        self.assert_(ratio >= 0.3, ratio)
        self.assert_(ratio < 0.5)
Example #21
0
    def test_download_http_cancel(self):
        '''download_url(), HTTP, cancelling'''

        self.stop_capture()

        ui = sandbox.TestUI()

        # temporary file
        httpd.start(8427, OSLib.inst.workdir)
        ui.cancel_progress = True
        (fname, h) = ui.download_url('http://localhost:8427/stuff')
        httpd.stop()
        self.assertEqual(fname, None)

        self.assertRaises(IndexError, ui.pop_error)

        # we got progress reports
        self.assertEqual(ui.cur_progress[2], len(self.big_file_contents))
        ratio = float(ui.cur_progress[1])/len(self.big_file_contents)
        self.assert_(ratio >= 0.3, ratio)
        self.assert_(ratio < 0.5)

        # specified file name
        dest = os.path.join(OSLib.inst.workdir, 'destfile')
        ui.cancel_progress = True
        httpd.start(8427, OSLib.inst.workdir)
        (fname, h) = ui.download_url('http://localhost:8427/stuff', dest)
        httpd.stop()
        self.assertEqual(fname, None)

        self.assertRaises(IndexError, ui.pop_error)

        # we got progress reports
        self.assertEqual(ui.cur_progress[2], len(self.big_file_contents))
        ratio = float(ui.cur_progress[1])/len(self.big_file_contents)
        self.assert_(ratio >= 0.3, ratio)
        self.assert_(ratio < 0.5)
Example #22
0
    parser.add_argument(
        'tests_dir',
        nargs=1,
        help="path to policeman tests directory (already translated to js)"
    )

    parser.add_argument(
        'addon_dir',
        nargs=1,
        help="path to policeman built addon directory"
    )

    parser.add_argument(
        '-b',
        '--binary',
        nargs=1,
        default=DEFAULT_FIREFOX_PATH,
        help="Firefox executable path (default: %s)" % DEFAULT_FIREFOX_PATH,
    )

    return parser.parse_args()

if __name__ == '__main__':
    args = parse_args()

    httpd.start()
    data = TesterData(httpd, args)

    tests = find_tests(data)
    run_tests(tests, data)