Beispiel #1
0
def test_encrypt_plain_text():
    """
    The file is not encrypted.
    Test the encrypt plain_text.txt.
    This function return a new file with pattern <ORIGINAL_NAME>.enc
    """
    file_path = f'{here}/../files/plain_text.txt'
    password = '******'
    file_content = open_file(file_path)

    encrypt_file(file_content=file_content,
                 file_path=file_path,
                 passphrase=password)
    enc_file = open_file(f'{file_path}.enc')

    assert len(enc_file) > 0
Beispiel #2
0
def test_decrypt_plain_text_not_encrypted():
    """
    The file is not encrypted.
    Test the decrypt plain_text. Return a raise SystemExit
    """
    file_path = f'{here}/../files/plain_text.txt'
    password = '******'
    file_content = open_file(file_path)

    with pytest.raises(SystemExit):
        decrypt_file(file_content=file_content,
                     file_path=file_path,
                     passphrase=password)
Beispiel #3
0
def test_decrypt_xml_not_encrypted():
    """
    The file is not encrypted.
    Test the decrypt semi_structure_data. Return a raise SystemExit
    """
    file_path = f'{here}/../files/semi_structure_data.xml'
    password = '******'
    file_content = open_file(file_path)

    with pytest.raises(SystemExit):
        decrypt_file(file_content=file_content,
                     file_path=file_path,
                     passphrase=password)
Beispiel #4
0
def test_decrypt_empty_file_not_encrypted():
    """
    The file is not encrypted.
    Test the decrypt empty_file. Return a raise SystemExit
    """
    file_path = f'{here}/../files/empty_file'
    password = '******'
    file_content = open_file(file_path)

    # with pytest.raises(ValueError, match=r".*The file is empty.*"):
    with pytest.raises(SystemExit):
        decrypt_file(file_content=file_content,
                     file_path=file_path,
                     passphrase=password)
Beispiel #5
0
def main():
    parser = argparse.ArgumentParser(
        description='Encrypt or decrypt files with ONLY ONE COMAND')
    parser.add_argument('--func',
                        type=str,
                        required=True,
                        help='Function: encrypt or decrypt')
    parser.add_argument('--file', type=str, required=True, help='File path')
    parser.add_argument('--password',
                        type=str,
                        required=True,
                        help='Password to encrypt file')

    args = parser.parse_args()
    func = args.func
    password = args.password
    file_path = args.file

    print(f.renderText('encrypt file'))
    print(
        'Encrypt or decrypt files with ONLY ONE COMMAND '
        '\n----------------------------------------------------------------------'
    )
    print('PARAMETERS')
    print(f'func:\t\t{func}')
    print(f'password:\t{password}')
    print(f'file_path:\t{file_path}')
    print()

    readed_file = open_file(file_path)

    if 'encrypt' in func:
        encrypt_file(file_content=readed_file,
                     file_path=file_path,
                     passphrase=password)

    elif 'decrypt' in func:
        decrypt_file(file_content=readed_file,
                     file_path=file_path,
                     passphrase=password)