def test_decrypt_all(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']
    ]

    Inventory().__enter__().read_register.return_value = {
        'unenc_file_1': {
            'unencrypted_file': 'unenc_1',
            'encrypted_file': 'uuid-1',
            'public_id': saved_params['public_id']
        },
        'unenc_file_2': {
            'unencrypted_file': 'unenc_2',
            'encrypted_file': 'uuid-2',
            'public_id': saved_params['public_id']
        },
        'unenc_file_3': {
            'unencrypted_file': 'unenc_3',
            'encrypted_file': 'uuid-3',
            'public_id': 'some_other_id'
        }
    }

    de = DirEncryption(test_args)
    de.decrypt_all('trustno1')

    eq_(de.decrypt.call_count, 2)
    eq_(de.decrypt.call_args_list[0][0], ('uuid-1', 'unenc_1', 'trustno1'))
    eq_(de.decrypt.call_args_list[1][0], ('uuid-2', 'unenc_2', 'trustno1'))
def test_decrypt_all__no_files(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']
    ]

    Inventory().__enter__().read_register.return_value = {}

    de = DirEncryption(test_args)
    de.decrypt_all('trustno1')

    eq_(de.decrypt.call_count, 0)
示例#3
0
            help='Print verbose messages during execution')

    parser.add_argument('-p', '--plaindir',    help='Unencrypted directory')
    parser.add_argument('-s', '--securedir',   help='Encrypted directory')
    parser.add_argument('-i', '--public-id',   help='GPG public id')
    parser.add_argument('-P', '--passphrase',
            help='Passphrase to decrypt files.')
    parser.add_argument('-H', '--gpg-homedir', help='GPG home directory')
    parser.add_argument('-k', '--gpg-keyring', help='GPG keyring file')
    parser.add_argument('-b', '--gpg-binary',  help='GPG binary file')

    args = parser.parse_args()

    if args.configure:
        header()
        c = RunConfig(database=database)
    elif args.encrypt:
        e = DirEncryption(args, database=database)
        e.encrypt_all()
    elif args.decrypt:
        if args.passphrase:
            passphrase = args.passphrase
        else:
            passphrase = getpass.getpass('Passphrase: ')
        e = DirEncryption(args, database=database)
        e.decrypt_all(passphrase)
    else:
        header()
        print('Please specify encrypt (-e) or decrypt (-d) operation,')
        print('or --configure to set up configuration.')