Ejemplo n.º 1
0
    def basic_tarzan_comparison(self):
        with open(self.test_file, 'rb') as fp:
            source_file_list = sorted(tarfile.open(fileobj=fp).getnames())

        output_file = StringIO()
        with open(self.test_filed, 'rb') as in_fp:
            tarzan.list_tarzan(
                in_fp, output_file, self.blockstore_directory,
                'test_password')

        output = output_file.getvalue()
        self.assertEqual(
            sorted([x.split()[-1] for x in output.split('\n') if x]),
            source_file_list)

        output_file = StringIO()
        with open(self.test_filed, 'rb') as in_fp:
            tarzan.decrypt_tarzan(
                in_fp, output_file, self.blockstore_directory,
                'test_password')

        #  decrypted tarzan has appropriate file names (payload still detached)
        output_file.seek(0)
        tf = tarfile.open(fileobj=output_file)
        self.assertEqual(
            sorted(tf.getnames()),
            source_file_list)
Ejemplo n.º 2
0
    def test_TarPipeEmpty(self):
        os.system('tar cfT "%s" /dev/null' % self.test_file)
        with open(self.test_file, 'rb') as in_fp, open(
                self.test_filed, 'wb') as out_fp:
            tarzan.filter_tar(
                in_fp, out_fp, self.blockstore_directory, 'test_password')

        with self.assertRaises(tarzan.InvalidTarzanInputError):
            with open(self.test_filed, 'rb') as in_fp:
                tarzan.list_tarzan(
                    in_fp, self.dev_null, self.blockstore_directory,
                    'bad_password')

        output_file = StringIO()
        with open(self.test_filed, 'rb') as in_fp:
            tarzan.list_tarzan(
                in_fp, output_file, self.blockstore_directory,
                'test_password')
        self.assertEqual(output_file.getvalue(), '')

        self.compare_source_and_decrypted()