Ejemplo n.º 1
0
    def loop_through(self, clean=False, resync=False):
        """Go through all entries and take action based on user input.

        This method can be called after check() has been executed,
        otherwise it cannot properly report on the existence of
        files.
        """
        count_nok = 0
        total_files = len(self.registered_files)

        print('Plaindir: {}'.format(self.parameters['plaindir']))
        print('Securedir: {}'.format(self.parameters['securedir']))
        print('\nSTATUS PLAINFILE{}ENCFILE'.format(' '*27))

        for filename, entry in self.registered_files.items():

            unenc_exists = 'u'
            enc_exists = 'e'
            status = 'ok'

            if not entry['unencrypted_file_check']:
                unenc_exists = ''
            if not entry['encrypted_file_check']:
                enc_exists = ''

            if clean and (not unenc_exists or not enc_exists):
                if unenc_exists:
                    print("delete unenc")
                    FileOps.delete_file(self.parameters['plaindir'],
                                     entry['unencrypted_file'])

                if enc_exists:
                    print("delete enc")
                    FileOps.delete_file(self.parameters['securedir'],
                                     entry['encrypted_file'])

                self.clean_registry(entry['unencrypted_file'])
                total_files -= 1
            elif not unenc_exists and resync:
                de = DirEncryption(None, self.database)
                de.decrypt(entry['encrypted_file'],
                           entry['unencrypted_file'],
                           self.passphrase)
                unenc_exists = 'u'
            elif not unenc_exists or not enc_exists:
                status = 'NOK'
                count_nok += 1


            print('%-3s %1s%1s %-35s %-30s' % (status, unenc_exists, enc_exists,
                    self.registered_files[filename]['unencrypted_file'],
                    self.registered_files[filename]['encrypted_file']))

        print('\nTotal files in the register: {}'.format(total_files))
        print('Check: {} ok, {} not ok'.format(total_files - count_nok, count_nok))
Ejemplo n.º 2
0
def test_decrypt(expanduser, Inventory, GPGOps):

    Inventory().__enter__().read_parameters.return_value = saved_params

    expanduser.side_effect = [
        saved_params['plaindir'], saved_params['securedir'],
        saved_params['gpg_homedir'], saved_params['gpg_binary']
    ]

    de = DirEncryption(test_args)
    de.decrypt('test_enc_file', 'test_plain_file', 'trustno1')

    de.gpg.decrypt.assert_called_once_with(
        os.path.join(saved_params['securedir'], 'test_enc_file'),
        os.path.join(saved_params['plaindir'], 'test_plain_file'), 'trustno1')