Example #1
0
def test_cryptostring_has_symbol():
    s_util = CryptoString()
    crypto_string = 'Th1sP@sswordH4sSymbols!'
    assert s_util.has_symbol(crypto_string) is True
    crypto_string = r'!@#$%^&*()[]\}{|<>?,./~`'
    assert s_util.has_symbol(crypto_string) is True
    crypto_string = 'ThisPasswordH4sNoSymbols'
    assert s_util.has_symbol(crypto_string) is False
Example #2
0
def test_cryptostring_all_profile():
    s_util = CryptoString(profile='all')
    crypto_string = s_util.get_crypto_string()
    assert s_util.has_lower(crypto_string) is True
    assert s_util.has_upper(crypto_string) is True
    assert s_util.has_number(crypto_string) is True
    assert s_util.has_symbol(crypto_string) is True
Example #3
0
def test_cryptostring_hex_upper_profile():
    s_util = CryptoString(profile='hex_upper')
    crypto_string = s_util.get_crypto_string()
    assert s_util.has_lower(crypto_string) is False
    assert s_util.has_upper(crypto_string) is True
    assert s_util.has_number(crypto_string) is True
    assert s_util.has_symbol(crypto_string) is False
    bad_letters = any(char in 'GHIJKLMNOPQRSTUVWXYZ' for char in crypto_string)
    assert not bad_letters
Example #4
0
def test_cryptostring_hex_lower_profile():
    s_util = CryptoString(profile='hex_lower')
    crypto_string = s_util.get_crypto_string()
    assert s_util.has_lower(crypto_string) is True
    assert s_util.has_upper(crypto_string) is False
    assert s_util.has_number(crypto_string) is True
    assert s_util.has_symbol(crypto_string) is False
    bad_letters = any(char in 'ghijklmnopqrstuvwxyz' for char in crypto_string)
    assert not bad_letters
Example #5
0
def test_cryptostring_default_profile():
    s_util = CryptoString(profile='default')
    crypto_string = s_util.get_crypto_string()
    assert s_util.has_lower(crypto_string) is True
    assert s_util.has_upper(crypto_string) is True
    assert s_util.has_number(crypto_string) is True
    assert s_util.has_symbol(crypto_string) is True
    bad_symbols = any(
        char in '!"$%()*,./:;<>[]^_`{|}~\'' for char in crypto_string)
    assert not bad_symbols
Example #6
0
def test_profiles_catalog(*_):
    _dir = tempfile.mkdtemp()
    os.makedirs(os.path.join(_dir, 'cicd_site_repo'), exist_ok=True)
    PassphraseGenerator('cicd', _dir, 'test_author').generate()
    s_util = CryptoString()

    for passphrase in TEST_PROFILES_CATALOG['data']['passphrases']:
        passphrase_file_name = '{}.yaml'.format(passphrase['document_name'])
        passphrase_file_path = os.path.join(_dir, 'site', 'cicd', 'secrets',
                                            'passphrases',
                                            passphrase_file_name)
        assert os.path.isfile(passphrase_file_path)
        with open(passphrase_file_path) as stream:
            doc = yaml.safe_load(stream)
            decrypted_passphrase = encryption.decrypt(
                doc['data']['managedDocument']['data'],
                os.environ['PEGLEG_PASSPHRASE'].encode(),
                os.environ['PEGLEG_SALT'].encode()).decode()
            assert len(decrypted_passphrase) == 24
            if passphrase_file_name == "default_passphrase.yaml":
                assert s_util.has_lower(decrypted_passphrase) is True
                assert s_util.has_upper(decrypted_passphrase) is True
                assert s_util.has_number(decrypted_passphrase) is True
                assert s_util.has_symbol(decrypted_passphrase) is True
                bad_symbols = any(char in '!"$%()*,./:;<>[]^_`{|}~\''
                                  for char in decrypted_passphrase)
                assert not bad_symbols
            elif passphrase_file_name == "alphanumeric_passphrase.yaml":
                assert s_util.has_lower(decrypted_passphrase) is True
                assert s_util.has_upper(decrypted_passphrase) is True
                assert s_util.has_number(decrypted_passphrase) is True
                assert s_util.has_symbol(decrypted_passphrase) is False
            elif passphrase_file_name == "alphanumeric_lower_passphrase.yaml":
                assert s_util.has_lower(decrypted_passphrase) is True
                assert s_util.has_upper(decrypted_passphrase) is False
                assert s_util.has_number(decrypted_passphrase) is True
                assert s_util.has_symbol(decrypted_passphrase) is False
            elif passphrase_file_name == "alphanumeric_upper_passphrase.yaml":
                assert s_util.has_lower(decrypted_passphrase) is False
                assert s_util.has_upper(decrypted_passphrase) is True
                assert s_util.has_number(decrypted_passphrase) is True
                assert s_util.has_symbol(decrypted_passphrase) is False
            elif passphrase_file_name == "all_passphrase.yaml":
                assert s_util.has_lower(decrypted_passphrase) is True
                assert s_util.has_upper(decrypted_passphrase) is True
                assert s_util.has_number(decrypted_passphrase) is True
                assert s_util.has_symbol(decrypted_passphrase) is True
            elif passphrase_file_name == "hex_lower_passphrase.yaml":
                assert s_util.has_lower(decrypted_passphrase) is True
                assert s_util.has_upper(decrypted_passphrase) is False
                assert s_util.has_number(decrypted_passphrase) is True
                assert s_util.has_symbol(decrypted_passphrase) is False
                bad_letters = any(char in 'ghijklmnopqrstuvwxyz'
                                  for char in decrypted_passphrase)
                assert not bad_letters
            elif passphrase_file_name == "hex_upper_passphrase.yaml":
                assert s_util.has_lower(decrypted_passphrase) is False
                assert s_util.has_upper(decrypted_passphrase) is True
                assert s_util.has_number(decrypted_passphrase) is True
                assert s_util.has_symbol(decrypted_passphrase) is False
                bad_letters = any(char in 'GHIJKLMNOPQRSTUVWXYZ'
                                  for char in decrypted_passphrase)
                assert not bad_letters