|
38 | 38 |
|
39 | 39 | from tests.support import MIG_BASE, TEST_OUTPUT_DIR, MigTestCase, \ |
40 | 40 | FakeConfiguration, testmain, cleanpath, is_path_within |
| 41 | +from tests.support.fixturesupp import FixtureAssertMixin |
| 42 | +from tests.support.picklesupp import PickleAssertMixin |
41 | 43 |
|
42 | 44 | from mig.shared.defaults import keyword_auto, htaccess_filename, \ |
43 | 45 | DEFAULT_USER_ID_FORMAT |
44 | | -from mig.shared.useradm import assure_current_htaccess |
| 46 | +from mig.shared.useradm import assure_current_htaccess, create_user, \ |
| 47 | + _ensure_dirs_needed_for_userdb |
45 | 48 |
|
46 | 49 | DUMMY_USER = 'dummy-user' |
47 | 50 | DUMMY_STALE_USER = 'dummy-stale-user' |
|
80 | 83 | ) |
81 | 84 |
|
82 | 85 |
|
| 86 | +class TestMigSharedUsedadm_create_user(MigTestCase, |
| 87 | + FixtureAssertMixin, |
| 88 | + PickleAssertMixin): |
| 89 | + def before_each(self): |
| 90 | + configuration = self.configuration |
| 91 | + |
| 92 | + _ensure_dirs_needed_for_userdb(self.configuration) |
| 93 | + |
| 94 | + self.expected_user_db_home = configuration.user_db_home[0:-1] |
| 95 | + self.expected_user_db_file = os.path.join( |
| 96 | + self.expected_user_db_home, 'MiG-users.db') |
| 97 | + |
| 98 | + def _provide_configuration(self): |
| 99 | + return 'testconfig' |
| 100 | + |
| 101 | + def test_user_db_is_created(self): |
| 102 | + user_dict = {} |
| 103 | + user_dict['full_name'] = "Test User" |
| 104 | + user_dict['organization'] = "Test Org" |
| 105 | + user_dict['state'] = "NA" |
| 106 | + user_dict['country'] = "DK" |
| 107 | + user_dict['email'] = "user@example.com" |
| 108 | + user_dict['comment'] = "This is the create comment" |
| 109 | + user_dict['password'] = "password" |
| 110 | + create_user(user_dict, self.configuration, |
| 111 | + keyword_auto, default_renew=True) |
| 112 | + |
| 113 | + # presence of user home |
| 114 | + path_kind = MigTestCase._absolute_path_kind(self.expected_user_db_home) |
| 115 | + self.assertEqual(path_kind, 'dir') |
| 116 | + |
| 117 | + # presence of user db |
| 118 | + path_kind = MigTestCase._absolute_path_kind(self.expected_user_db_file) |
| 119 | + self.assertEqual(path_kind, 'file') |
| 120 | + |
| 121 | + def test_user_entry_is_recorded(self): |
| 122 | + def _adjust_user_dict_for_compare(user_obj): |
| 123 | + obj = dict(user_obj) |
| 124 | + obj['created'] = 9999999999.9999999 |
| 125 | + obj['expire'] = 9999999999.9999999 |
| 126 | + obj['unique_id'] = '__UNIQUE_ID__' |
| 127 | + return obj |
| 128 | + |
| 129 | + def _generate_salt(): |
| 130 | + return b'CCCC12344321CCCC' |
| 131 | + |
| 132 | + expected_user_id = '/C=DK/ST=NA/L=NA/O=Test Org/OU=NA/CN=Test User/emailAddress=test@example.com' |
| 133 | + expected_user_password_hash = "PBKDF2$sha256$10000$XMZGaar/pU4PvWDr$w0dYjezF6JGtSiYPexyZMt3lM2134uix" |
| 134 | + |
| 135 | + user_dict = {} |
| 136 | + user_dict['full_name'] = "Test User" |
| 137 | + user_dict['organization'] = "Test Org" |
| 138 | + user_dict['state'] = "NA" |
| 139 | + user_dict['country'] = "DK" |
| 140 | + user_dict['email'] = "test@example.com" |
| 141 | + user_dict['comment'] = "This is the create comment" |
| 142 | + user_dict['locality'] = "" |
| 143 | + user_dict['organizational_unit'] = "" |
| 144 | + user_dict['password'] = "" |
| 145 | + user_dict['password_hash'] = expected_user_password_hash |
| 146 | + |
| 147 | + create_user(user_dict, self.configuration, |
| 148 | + keyword_auto, default_renew=True) |
| 149 | + |
| 150 | + pickled = self.assertPickledFile(self.expected_user_db_file, |
| 151 | + apply_hints=['convert_dict_bytes_to_strings_kv']) |
| 152 | + self.assertIn(expected_user_id, pickled) |
| 153 | + |
| 154 | + prepared = self.prepareFixtureAssert('MiG-users.db--example', |
| 155 | + fixture_format='json') |
| 156 | + |
| 157 | + # TODO: remove resetting the handful of keys here done because changes |
| 158 | + # to make them assertion frienfly values will increase the size |
| 159 | + # of the diff which, at time of commit, are best minimised. |
| 160 | + actual_user_object = _adjust_user_dict_for_compare(pickled[expected_user_id]) |
| 161 | + expected_user_object = _adjust_user_dict_for_compare(prepared.fixture_data[expected_user_id]) |
| 162 | + |
| 163 | + self.maxDiff = None |
| 164 | + self.assertEqual(actual_user_object, expected_user_object) |
| 165 | + |
| 166 | + |
83 | 167 | class MigSharedUseradm__assure_current_htaccess(MigTestCase): |
84 | 168 | """Unit test helper for the migrid code pointed to in class name""" |
85 | 169 |
|
|
0 commit comments