diff options
Diffstat (limited to 'test/units/utils/test_encrypt.py')
-rw-r--r-- | test/units/utils/test_encrypt.py | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/test/units/utils/test_encrypt.py b/test/units/utils/test_encrypt.py index 72fe3b07..be325790 100644 --- a/test/units/utils/test_encrypt.py +++ b/test/units/utils/test_encrypt.py @@ -27,17 +27,26 @@ class passlib_off(object): def assert_hash(expected, secret, algorithm, **settings): + assert encrypt.do_encrypt(secret, algorithm, **settings) == expected if encrypt.PASSLIB_AVAILABLE: - assert encrypt.passlib_or_crypt(secret, algorithm, **settings) == expected assert encrypt.PasslibHash(algorithm).hash(secret, **settings) == expected else: - assert encrypt.passlib_or_crypt(secret, algorithm, **settings) == expected with pytest.raises(AnsibleError) as excinfo: encrypt.PasslibHash(algorithm).hash(secret, **settings) assert excinfo.value.args[0] == "passlib must be installed and usable to hash with '%s'" % algorithm @pytest.mark.skipif(sys.platform.startswith('darwin'), reason='macOS requires passlib') +def test_passlib_or_crypt(): + with passlib_off(): + expected = "$5$rounds=5000$12345678$uAZsE3BenI2G.nA8DpTl.9Dc8JiqacI53pEqRr5ppT7" + assert encrypt.passlib_or_crypt("123", "sha256_crypt", salt="12345678", rounds=5000) == expected + + expected = "$5$12345678$uAZsE3BenI2G.nA8DpTl.9Dc8JiqacI53pEqRr5ppT7" + assert encrypt.passlib_or_crypt("123", "sha256_crypt", salt="12345678", rounds=5000) == expected + + +@pytest.mark.skipif(sys.platform.startswith('darwin'), reason='macOS requires passlib') def test_encrypt_with_rounds_no_passlib(): with passlib_off(): assert_hash("$5$rounds=5000$12345678$uAZsE3BenI2G.nA8DpTl.9Dc8JiqacI53pEqRr5ppT7", |