示例#1
0
def test_find_unencrypted_files__empty_dir(walk, expanduser, Inventory,
                                           GPGOps):

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

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

    register = {
        'unenc_1': {
            'unencrypted_file': 'unenc_1',
            'encrypted_file': 'uuid-1',
            'public_id': saved_params['public_id'],
            'is_link': 0,
            'target': ''
        }
    }

    walk.return_value = []

    de = DirEncryption(test_args)
    files = de.find_unencrypted_files(register)

    eq_(files, {})
def test_find_unencrypted_files(stat, walk, 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']
    ]

    register = {
        'unenc_1': {
            'unencrypted_file': 'unenc_1',
            'encrypted_file': 'uuid-1',
            'public_id': saved_params['public_id']
        }
    }

    walk.return_value = [
        (saved_params['plaindir'], ['subdir_1'], ['unenc_1', 'unenc_2']),
        (os.path.join(saved_params['plaindir'], 'subdir_1'), [], ['unenc_3'])
    ]

    stat.return_value.st_mtime = 1400

    de = DirEncryption(test_args)
    files = de.find_unencrypted_files(register)

    eq_(len(files), 2)
    ok_('unenc_2' in files.keys())
    ok_(os.path.join('subdir_1', 'unenc_3') in files.keys())
示例#3
0
def test_find_unencrypted_files(islink, stat, walk, expanduser, Inventory,
                                GPGOps):

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

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

    register = {
        'unenc_1': {
            'unencrypted_file': 'unenc_1',
            'encrypted_file': 'uuid-1',
            'public_id': saved_params['public_id'],
            'is_link': 0,
            'target': ''
        }
    }

    walk.return_value = [(saved_params['plaindir'], ['subdir_1'],
                          ['unenc_1', 'unenc_2', 'unenc_3']),
                         (os.path.join(saved_params['plaindir'],
                                       'subdir_1'), [], ['unenc_4'])]

    stat.return_value.st_mtime = 1234567895
    islink.return_value = True
    de = DirEncryption(test_args)
    files = de.find_unencrypted_files(register)
    eq_(len(files), 0)

    islink.reset_mock()
    islink.return_value = False
    files = de.find_unencrypted_files(register)
    eq_(len(files), 4)
    ok_('unenc_3' in files.keys())
    ok_(os.path.join('subdir_1', 'unenc_4') in files.keys())

    stat.reset_mock()
    stat.return_value.st_mtime = 1234567885
    files = de.find_unencrypted_files(register)
    eq_(len(files), 3)