From 0a18e2a7178a0280d9dbe9462c6a2d99eb2fff91 Mon Sep 17 00:00:00 2001 From: Jonas Bardino Date: Fri, 29 May 2026 22:40:12 +0200 Subject: [PATCH 1/2] Add a few more user state dirs made by actual user creation and importantly expected e.g. during useradm operations like edit_user, delete_user, etc. and therefore difficult to do without when adding test coverage a.o. in #561. Introduce two more common DNs used across tests: Other User and No Such User. Polish a long comment with some typos and incomplete ending. --- tests/support/usersupp.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/tests/support/usersupp.py b/tests/support/usersupp.py index 65a02fa4a..4fcf68413 100644 --- a/tests/support/usersupp.py +++ b/tests/support/usersupp.py @@ -38,6 +38,8 @@ TEST_USER_DN = '/C=DK/ST=NA/L=NA/O=Test Org/OU=NA/CN=Test User/emailAddress=test@example.com' +OTHER_USER_DN = '/C=DK/ST=NA/L=NA/O=Other Org/OU=NA/CN=Other User/emailAddress=other@example.com' +NO_SUCH_USER_DN = '/C=DK/ST=NA/L=NA/O=No Such Org/OU=NA/CN=No Such User/emailAddress=nosuchuser@example.com' _FIXTURE_NAME_BY_USER_DN = { TEST_USER_DN: 'MiG-users.db--example' @@ -120,6 +122,15 @@ def _provision_test_user_dirs(testcase, distinguished_name): with open(test_user_settings_file, 'wb') as outfile: pickle.dump({}, outfile) + # create the test user cache, resource pending and mrsl files sub dirs + for sub in (self.configuration.user_cache, + self.configuration.resource_pending, + self.configuration.mrsl_files_dir): + conf_user_sub = os.path.normpath(sub) + test_user_sub_dir = os.path.join( + conf_user_sub, test_client_dir_name) + os.makedirs(test_user_sub_dir) + return test_user_dir @staticmethod @@ -134,8 +145,8 @@ def _provision_test_users(testcase, *distinguished_names): that the user db will be populated from arbitrary data and thus the test dependent upon this is less strongly assured, but if (as is the expectation) the basic operations are validated with - "indenpdent" data i.e. conained within fixtures as opposed to - generated by logic that extended tests which need + "independent" data i.e. contained within fixtures as opposed to + generated by logic that extended tests will need. """ conf_user_db_home = UserAssertMixin._provision_user_db_dir(testcase) From b0e9c42a01b95f11395fda91c77e08fa81208290 Mon Sep 17 00:00:00 2001 From: Jonas Bardino Date: Tue, 9 Jun 2026 12:13:19 +0200 Subject: [PATCH 2/2] Add a couple of good points from review feedback (thanks @albu-diku) as comments to get the PR wrapped up. Minor format-only changes from automatic long-line wrap in editor. --- tests/support/usersupp.py | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/tests/support/usersupp.py b/tests/support/usersupp.py index 4fcf68413..7a8a8eb98 100644 --- a/tests/support/usersupp.py +++ b/tests/support/usersupp.py @@ -81,19 +81,21 @@ def _provision_test_user(testcase, distinguished_name): try: fixture_relpath = _FIXTURE_NAME_BY_USER_DN[distinguished_name] except KeyError: - raise AssertionError('supplied test user is not known as a fixture') + raise AssertionError( + 'supplied test user is not known as a fixture') # note: this is a non-standard direct use of fixture preparation due # to this being bootstrap code and should not be used elsewhere - prepared_fixture = _PreparedFixture.from_relpath( - testcase, - fixture_relpath, - fixture_format='json' - ) + prepared_fixture = _PreparedFixture.from_relpath(testcase, + fixture_relpath, + fixture_format='json' + ) # write out the user database fixture containing the user - prepared_fixture.write_to_dir(conf_user_db_home, output_format='pickle') + prepared_fixture.write_to_dir(conf_user_db_home, + output_format='pickle') - test_user_dir = UserAssertMixin._provision_test_user_dirs(testcase, distinguished_name) + test_user_dir = UserAssertMixin._provision_test_user_dirs( + testcase, distinguished_name) return test_user_dir @@ -105,6 +107,7 @@ def _provision_test_user_dirs(testcase, distinguished_name): self = testcase + # NOTE: we basically need all the dirs in _USERADM_PATH_KEYS list. conf_user_home = os.path.normpath(self.configuration.user_home) test_client_dir_name = client_id_dir(distinguished_name) @@ -114,21 +117,24 @@ def _provision_test_user_dirs(testcase, distinguished_name): # create the test user settings directory conf_user_settings = os.path.normpath(self.configuration.user_settings) - test_user_settings_dir = os.path.join(conf_user_settings, test_client_dir_name) + test_user_settings_dir = os.path.join(conf_user_settings, + test_client_dir_name) os.makedirs(test_user_settings_dir) # create an empty user settings file - test_user_settings_file = os.path.join(test_user_settings_dir, 'settings') + test_user_settings_file = os.path.join(test_user_settings_dir, + 'settings') with open(test_user_settings_file, 'wb') as outfile: pickle.dump({}, outfile) + # TODO: clean up old _ensure_dirs_exist calls in tests to create these. # create the test user cache, resource pending and mrsl files sub dirs for sub in (self.configuration.user_cache, self.configuration.resource_pending, self.configuration.mrsl_files_dir): conf_user_sub = os.path.normpath(sub) - test_user_sub_dir = os.path.join( - conf_user_sub, test_client_dir_name) + test_user_sub_dir = os.path.join(conf_user_sub, + test_client_dir_name) os.makedirs(test_user_sub_dir) return test_user_dir @@ -167,7 +173,9 @@ def _provision_test_users(testcase, *distinguished_names): # suitably hinted so a production format pickle file ends up on-disk prepared_fixture = _PreparedFixture(testcase, 'MiG-users.db--example') prepared_fixture.fixture_data = users_by_dn - prepared_fixture.write_to_dir(conf_user_db_home, output_format='pickle') + prepared_fixture.write_to_dir(conf_user_db_home, + output_format='pickle') for distinguished_name in distinguished_names: - UserAssertMixin._provision_test_user_dirs(testcase, distinguished_name) + UserAssertMixin._provision_test_user_dirs(testcase, + distinguished_name)