def test_sslv3_disabled(self):
        '''Test disabled SSLv3 support'''

        cfgfile = open('/etc/dovecot/dovecot.conf', 'a')
        cfgfile.write("ssl_protocols = !SSLv3")
        cfgfile.close()

        self.dovecot.reload_conf(self)

        # Make sure SSLv3 is disabled
        rc, report = testlib.cmd_pipe(
            ["echo", "-n"],
            ["openssl", "s_client", "-ssl3", "-connect", "localhost:995"])
        expected = 1
        result = 'Got exit code %d, expected %d\n' % (rc, expected)
        self.assertEquals(expected, rc, result + report)

        self.assertTrue("ssl handshake failure" in report,
                        "Could not find handshake failure in report!")

        # Now make sure TLSv1 still works
        rc, report = testlib.cmd_pipe(
            ["echo", "-n"],
            ["openssl", "s_client", "-tls1", "-connect", "localhost:995"])
        expected = 0
        result = 'Got exit code %d, expected %d\n' % (rc, expected)
        self.assertEquals(expected, rc, result + report)

        self.assertTrue("Protocol  : TLSv1" in report,
                        "Couldn't find TLSv1 in report!")
Ejemplo n.º 2
0
    def _fetch_url(self, url, html=True, search=None, timeout=30):
        '''Fetch url'''
        self.assertTrue(html == True or search != None,
                        "Must have a search string for text")

        self._start_uzbl(url)
        self.assertTrue(self.uzbl_socket != None, "Don't have a uzbl socket")

        report = "\nLOAD_PROGRESS 0"
        count = 0
        while "LOAD_PROGRESS" in report and count < timeout:
            rc, report = testlib.cmd_pipe(
                ['echo', 'js document.documentElement.outerHTML'],
                ['socat', '-',
                 'unix-connect:"%s"' % self.uzbl_socket])
            expected = 0
            result = 'Got exit code %d, expected %d\n' % (rc, expected)
            self.assertEquals(expected, rc, result + report)
            count += 1
            self.assertTrue(
                count < timeout,
                "Could not fetch page after '%d' seconds" % timeout)
            time.sleep(1)

        # make sure uzbl is done loading
        time.sleep(1)

        # now that LOAD progress is not in there, we should have the page
        self.assertTrue(self.uzbl_socket != None, "Don't have a uzbl socket")
        rc, report = testlib.cmd_pipe(
            ['echo', 'js document.documentElement.outerHTML'],
            ['socat', '-',
             'unix-connect:"%s"' % self.uzbl_socket])
        expected = 0
        result = 'Got exit code %d, expected %d\n' % (rc, expected)
        self.assertEquals(expected, rc, result + report)

        out = report

        if not html:
            rc, report = testlib.cmd_pipe(['echo', out],
                                          ['lynx', '-dump', '-stdin'])
            expected = 0
            result = 'Got exit code %d, expected %d\n' % (rc, expected)
            self.assertEquals(expected, rc, result + report)
            out = report

        if search == None:
            search = "</html>"
        self.assertTrue(search in out,
                        "Could not find '%s' in:\n%s" % (search, out))
        return out
    def _add_superuser(self, username=None, email=None, password="******"):
        '''Add superuser'''
        os.chdir(self.django_project_manage_dir)

        if not username:
            username = "******"
        if not email:
            email = "%s@%s.local" % (username, socket.gethostname())

        # Requires setting the password later
        #rc, report = testlib.cmd(['python', './manage.py', 'createsuperuser',
        #                          '--username=%s' % username,
        #                          '--email=%s' % email,
        #                          '--noinput'])

        # Hacky, but does not require setting the password later
        os.chmod('./manage.py', 0755)
        rc, report = testlib.cmd_pipe([
            'echo',
            "from django.contrib.auth.models import User; User.objects.create_superuser('%s', '%s', '%s')"
            % (username, email, password)
        ], ['./manage.py', 'shell'])
        expected = 0
        result = 'Got exit code %d, expected %d\n' % (rc, expected)
        self.assertEquals(expected, rc, result + report)
        search = "User: %s" % username
        self.assertTrue(
            search in report,
            "Could not find '%s' in report:\n%s" % (search, report))

        os.chdir(self.current_dir)
Ejemplo n.º 4
0
    def test_in(self):
        '''bsdcpio: Copy in'''
        # get the contents of the directory
        (rc, tmp) = testlib.cmd(["find", self.archive_dir])
        find_report = self.clean_trailing_slash(self.sort_output(tmp))

        # create archives
        for f in self.formats:
            (rc, report) = testlib.cmd_pipe(["find", self.archive_dir], \
                                            ["bsdcpio", "-o", "-v", "-H", f, \
                                             "-F", "archive." + f])
            expected = 0
            result = 'Got exit code %d, expected %d\n' % (rc, expected)
            self.assertEquals(expected, rc, result + report)

        # test the contents of the created archives
        for f in self.formats:
            testlib.recursive_rm(self.archive_dir)
            (rc, report) = testlib.cmd(["bsdcpio", "-i", "-v", "-F", \
                                        "archive." + f])
            expected = 0
            result = 'Got exit code %d, expected %d\n' % (rc, expected)
            self.assertEquals(expected, rc, result + report)

            (rc, tmp) = testlib.cmd(["find", self.archive_dir])
            listing_report = self.clean_trailing_slash(self.sort_output(tmp))
            result = 'Find has:\n%s\n%s has:\n%s\n' % (find_report, \
                                                       "archive." + f, \
                                                       listing_report)
            self.assertEquals(find_report, listing_report, result)
Ejemplo n.º 5
0
    def test_out(self):
        '''bsdcpio: Copy out'''
        # create the archives
        for f in self.formats:
            (rc, report) = testlib.cmd_pipe(["find", self.archive_dir, '-depth', '-print'], \
                                            ["bsdcpio", "-o", "-v", "-H", f, \
                                             "-F", "archive." + f])
            expected = 0
            result = 'Got exit code %d, expected %d\n' % (rc, expected)
            self.assertEquals(expected, rc, result + report)

        # get the contents
        (rc, tmp) = testlib.cmd(["find", self.archive_dir])
        find_report = self.clean_trailing_slash(self.sort_output(tmp))

        # verify the contents
        for f in self.formats:
            (rc, report) = testlib.cmd(["bsdcpio", "--list", "--quiet", \
                                        "-I", "archive." + f])
            expected = 0
            result = 'Got exit code %d, expected %d\n' % (rc, expected)
            self.assertEquals(expected, rc, result + report)

            # verify all the files are present
            sorted_report = self.clean_trailing_slash(self.sort_output(report))
            result = 'Find has:\n%s\n%s has:\n%s\n' % (find_report, \
                                                       "archive." + f, \
                                                       sorted_report)
            self.assertEquals(find_report, sorted_report, result)
Ejemplo n.º 6
0
    def create_sample_cpio_archives(self,
                                    formats=[
                                        'bin', 'odc', 'newc', 'crc', 'hpbin',
                                        'hpodc', 'tar', 'ustar'
                                    ]):
        '''Create cpio archives'''
        archives = []
        prev_dir = os.getcwd()
        os.chdir(self.tempdir)

        # get the contents
        (rc, tmp) = testlib.cmd(["find", self.archive_dir])
        find_report = self.clean_trailing_slash(self.sort_output(tmp))

        # create the archives
        for f in formats:
            archive_name = os.path.join(self.tempdir, "archive." + f)
            archives.append(archive_name)
            (rc, report) = testlib.cmd_pipe(["find", self.archive_dir, '-depth', '-print'], \
                                            ["cpio", "-o", "-v", "-H", f, \
                                             "-F", "archive." + f])
            expected = 0
            result = 'Got exit code %d, expected %d\n' % (rc, expected)
            self.assertEquals(expected, rc, result + report)

        os.chdir(prev_dir)
        return archives
    def test_out_append(self):
        '''Copy out (append)'''
        # first create the base archives
        for f in self.formats:
            (rc, report) = testlib.cmd_pipe(["find", self.archive_dir], \
                                            ["cpio", "-o", "-v", "-H", f, \
                                             "-F", "archive." + f])
            expected = 0
            result = 'Got exit code %d, expected %d\n' % (rc, expected)
            self.assertEquals(expected, rc, result + report)
        time.sleep(1)

        # add the file to the hieracrchy
        added_file = os.path.join(self.archive_root, "added1")
        testlib.create_fill(added_file, "new content")

        # get the updated contents
        (rc, tmp) = testlib.cmd(["find", self.archive_dir])
        find_report = self.clean_trailing_slash(self.sort_output(tmp))

        for f in self.formats:
            (rc, report) = testlib.cmd_pipe(["find", \
                                             os.path.join(self.archive_dir, \
                                               os.path.basename(added_file))], \
                                            ["cpio", "-o", "-v", "-H", f, \
                                             "-F", "archive." + f, '-A'])
            expected = 0
            result = 'Got exit code %d, expected %d\n' % (rc, expected)
            self.assertEquals(expected, rc, result + report)

            (rc, report) = testlib.cmd(["cpio", "--list", "--quiet", \
                                        "-I", "archive." + f])
            expected = 0
            result = 'Got exit code %d, expected %d\n' % (rc, expected)
            self.assertEquals(expected, rc, result + report)

            # verify all the files are present
            sorted_report = self.clean_trailing_slash(self.sort_output(report))
            result = 'Find has:\n%s\n%s has:\n%s\n' % (find_report, \
                                                       "archive." + f, \
                                                       sorted_report)
            self.assertEquals(find_report, sorted_report, result)
Ejemplo n.º 8
0
    def test_rev(self):
        '''Test rev'''
        input_string = 'UbuntuRocks'
        output_string = 'skcoRutnubU'

        rc, report = testlib.cmd_pipe(['echo', input_string], 'rev')
        expected = 0
        result = 'Got exit code %d, expected %d\n' % (rc, expected)
        self.assertEquals(expected, rc, result + report)

        result = "Couldn't find '%s' in report" % output_string
        self.assertTrue(output_string in report, result + report)
    def test_sslv3(self):
        '''Test SSLv3 support'''

        rc, report = testlib.cmd_pipe(
            ["echo", "-n"],
            ["openssl", "s_client", "-ssl3", "-connect", "localhost:995"])
        expected = 0
        result = 'Got exit code %d, expected %d\n' % (rc, expected)
        self.assertEquals(expected, rc, result + report)

        self.assertTrue("Protocol  : SSLv3" in report,
                        "Couldn't find SSLv3 in report!")
Ejemplo n.º 10
0
    def test_pass(self):
        '''bsdcpio: Copy pass'''
        destdir = "dest"
        os.mkdir(destdir)

        # get the contents of the directory
        (rc, tmp) = testlib.cmd(["find", self.archive_dir])
        find_report = self.clean_trailing_slash(self.sort_output(tmp))

        # passthrough copy
        (rc, report) = testlib.cmd_pipe(["find", self.archive_dir], \
                                        ["bsdcpio", "-p", "-v", "dest"])

        os.chdir(destdir)
        (rc, tmp) = testlib.cmd(["find", self.archive_dir])
        listing_report = self.clean_trailing_slash(self.sort_output(tmp))
        result = 'Find has:\n%s\n%s has:\n%s\n' % (find_report, \
                                                   destdir, listing_report)
        self.assertEquals(find_report, listing_report, result)