Exemple #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)
Exemple #2
0
    def compare_source_and_decrypted(self):
        '''Verify that the source and decrypted tar are the same.

        This only works for tar files that have no payload blocks (either
        empty or only containing directories, etc...).
        '''
        with open(self.test_file, 'rb') as fp:
            sum = md5.new()
            sum.update(fp.read())
            orig_sum = sum.hexdigest()

        output_file = StringIO()
        with open(self.test_filed, 'rb') as in_fp:
            tarzan.decrypt_tarzan(
                in_fp, output_file, self.blockstore_directory,
                'test_password')
        sum = md5.new()
        sum.update(output_file.getvalue())
        result_sum = sum.hexdigest()

        self.assertEqual(orig_sum, result_sum)