def test_invalid_crypt_salt(): pytest.raises(AnsibleError, encrypt.CryptHash('bcrypt')._salt, '_', None) encrypt.CryptHash('bcrypt')._salt('1234567890123456789012', None) pytest.raises(AnsibleError, encrypt.CryptHash('bcrypt')._salt, 'kljsdf', None) encrypt.CryptHash('sha256_crypt')._salt('123456', None) pytest.raises(AnsibleError, encrypt.CryptHash('sha256_crypt')._salt, '1234567890123456789012', None)
def test_encrypt_default_rounds_no_passlib(): with passlib_off(): assert_hash("$1$12345678$tRy4cXc3kmcfRZVj4iFXr/", secret="123", algorithm="md5_crypt", salt="12345678") assert_hash("$5$12345678$uAZsE3BenI2G.nA8DpTl.9Dc8JiqacI53pEqRr5ppT7", secret="123", algorithm="sha256_crypt", salt="12345678") assert_hash("$6$12345678$LcV9LQiaPekQxZ.OfkMADjFdSO2k9zfbDQrHPVcYjSLqSdjLYpsgqviYvTEP/R41yPmhH3CCeEDqVhW1VHr3L.", secret="123", algorithm="sha512_crypt", salt="12345678") assert encrypt.CryptHash("md5_crypt").hash("123")
def assert_hash(expected, secret, algorithm, **settings): assert encrypt.CryptHash(algorithm).hash(secret, **settings) == expected if encrypt.PASSLIB_AVAILABLE: assert encrypt.passlib_or_crypt(secret, algorithm, **settings) == expected assert encrypt.PasslibHash(algorithm).hash(secret, **settings) == expected else: with pytest.raises(AnsibleFilterError): encrypt.PasslibHash(algorithm).hash(secret, **settings)