From 1f6ebb0c3c05c9acef895c25f7d57c947cdb8626 Mon Sep 17 00:00:00 2001 From: Chad Smith Date: Tue, 8 Feb 2022 13:11:31 -0700 Subject: [PATCH] tests: when generating crypted password, generate in target env There are inconsistencies for cryptographic libraries across major distribution releases. From a bionic host, attempting run run crypt.crypt locally using salt and format info from a Jammmy /etc/shadow file will result in a failure to produce an encrpted password. To avoid inconsistencies of python cryptographic libs across Linux releases, perform the password encryption on the system under test. --- tests/integration_tests/modules/test_set_password.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/tests/integration_tests/modules/test_set_password.py b/tests/integration_tests/modules/test_set_password.py index e0f8b692235..0e35cd26de5 100644 --- a/tests/integration_tests/modules/test_set_password.py +++ b/tests/integration_tests/modules/test_set_password.py @@ -8,8 +8,6 @@ they use a mixin to share their test definitions, because we can (of course) only specify one user-data per instance. """ -import crypt - import pytest import yaml @@ -162,9 +160,13 @@ def test_explicit_password_set_correctly(self, class_client): shadow_users, _ = self._fetch_and_parse_etc_shadow(class_client) fmt_and_salt = shadow_users["tom"].rsplit("$", 1)[0] - expected_value = crypt.crypt("mypassword123!", fmt_and_salt) - - assert expected_value == shadow_users["tom"] + GEN_CRYPT_CONTENT = ( + "import crypt\n" + f"print(crypt.crypt('mypassword123!', '{fmt_and_salt}'))\n" + ) + class_client.write_to_file("/gen_crypt.py", GEN_CRYPT_CONTENT) + result = class_client.execute("python3 /gen_crypt.py") + assert result.stdout == shadow_users["tom"] def test_shadow_expected_users(self, class_client): """Test that the right set of users is in /etc/shadow."""