Skip to content

Commit b5a0ae2

Browse files
committed
More integrity self-checks.
1 parent 85adb30 commit b5a0ae2

File tree

1 file changed

+77
-31
lines changed

1 file changed

+77
-31
lines changed

tests/test_mig_shared_vgridaccess.py

Lines changed: 77 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,13 @@ def _reset_caches(self):
144144
vgridaccess.last_load[field] = 0
145145
vgridaccess.last_map[field].clear()
146146

147+
def _verify_vgrid_map_integrity(self, vgrid_map):
148+
"""Assure integrity of all vgrid map entries"""
149+
for vgrid_name in vgrid_map.get(VGRIDS, {}):
150+
for field in (OWNERS, MEMBERS, SETTINGS, RESOURCES):
151+
vgrid_entry = vgrid_map[VGRIDS][vgrid_name]
152+
self.assertIn(field, vgrid_entry)
153+
147154
def before_each(self):
148155
"""Create clean test environment for vgridaccess tests"""
149156
used_state_dirs = [
@@ -174,10 +181,7 @@ def before_each(self):
174181
self.assertEqual(vgrid_map.get(VGRIDS, {}), self.MINIMAL_VGRIDS)
175182

176183
# Make sure all vgrid map entries are complete
177-
for vgrid_name in vgrid_map.get(VGRIDS, {}):
178-
for field in (OWNERS, MEMBERS, SETTINGS, RESOURCES):
179-
vgrid_entry = vgrid_map[VGRIDS][vgrid_name]
180-
self.assertIn(field, vgrid_entry)
184+
self._verify_vgrid_map_integrity(vgrid_map)
181185

182186
res_map = force_update_resource_map(self.configuration)
183187
# Make sure no resource map entries exist initially
@@ -226,11 +230,12 @@ def test_force_update_vgrid_map(self):
226230
self.assertEqual(vgrid_map_before.get(VGRIDS, {}), self.MINIMAL_VGRIDS)
227231

228232
self._create_vgrid(self.TEST_VGRID_NAME, [self.TEST_OWNER_DN])
229-
updated_vgrid = force_update_vgrid_map(self.configuration)
230-
self.assertTrue(updated_vgrid)
233+
updated_vgrid_map = force_update_vgrid_map(self.configuration)
234+
self._verify_vgrid_map_integrity(updated_vgrid_map)
235+
self.assertTrue(updated_vgrid_map)
231236
self.assertNotEqual(len(vgrid_map_before.get(VGRIDS, {})),
232-
len(updated_vgrid.get(VGRIDS, {})))
233-
self.assertIn(self.TEST_VGRID_NAME, updated_vgrid.get(VGRIDS, {}))
237+
len(updated_vgrid_map.get(VGRIDS, {})))
238+
self.assertIn(self.TEST_VGRID_NAME, updated_vgrid_map.get(VGRIDS, {}))
234239

235240
def test_refresh_user_map(self):
236241
"""Minimal test for user map refresh functionality"""
@@ -267,7 +272,9 @@ def test_get_resource_map(self):
267272
def test_get_vgrid_map(self):
268273
"""Minimal test for user map refresh functionality"""
269274
self._create_vgrid(self.TEST_VGRID_NAME, [self.TEST_OWNER_DN])
270-
force_update_vgrid_map(self.configuration)
275+
initial_vgrid_map = force_update_vgrid_map(self.configuration)
276+
self._verify_vgrid_map_integrity(initial_vgrid_map)
277+
self.assertIn(self.TEST_VGRID_NAME, initial_vgrid_map.get(VGRIDS, {}))
271278
vgrid_map = get_vgrid_map(self.configuration)
272279
self.assertIn(self.TEST_VGRID_NAME, vgrid_map.get(VGRIDS, {}))
273280

@@ -313,7 +320,10 @@ def test_load_vgrid_map(self):
313320
# Add test vgrid
314321
now = time.time()
315322
self._create_vgrid(self.TEST_VGRID_NAME, [self.TEST_OWNER_DN])
316-
force_update_vgrid_map(self.configuration)
323+
initial_vgrid_map = force_update_vgrid_map(self.configuration)
324+
self._verify_vgrid_map_integrity(initial_vgrid_map)
325+
self.assertIn(self.TEST_VGRID_NAME, initial_vgrid_map.get(VGRIDS, {}))
326+
317327
# Verify updated map contains vgrid after refresh
318328
vgrid_map, map_stamp = load_vgrid_map(self.configuration)
319329
self.assertIn(self.TEST_VGRID_NAME, vgrid_map.get(VGRIDS, {}))
@@ -349,7 +359,9 @@ def test_user_allowed_res_units(self):
349359
"""Test user_allowed_res_units returns allowed units"""
350360
self._create_resource(self.TEST_RESOURCE_ID, [self.TEST_OWNER_DN])
351361
self._create_vgrid(self.TEST_VGRID_NAME, [self.TEST_OWNER_DN])
352-
force_update_vgrid_map(self.configuration)
362+
initial_vgrid_map = force_update_vgrid_map(self.configuration)
363+
self._verify_vgrid_map_integrity(initial_vgrid_map)
364+
self.assertIn(self.TEST_VGRID_NAME, initial_vgrid_map.get(VGRIDS, {}))
353365
force_update_resource_map(self.configuration)
354366
allowed = user_allowed_res_units(
355367
self.configuration, self.TEST_OWNER_DN, "exe")
@@ -360,7 +372,9 @@ def test_user_allowed_res_exes(self):
360372
"""Test user_allowed_res_exes returns allowed exes"""
361373
self._create_resource(self.TEST_RESOURCE_ID, [self.TEST_OWNER_DN])
362374
self._create_vgrid(self.TEST_VGRID_NAME, [self.TEST_OWNER_DN])
363-
force_update_vgrid_map(self.configuration)
375+
initial_vgrid_map = force_update_vgrid_map(self.configuration)
376+
self._verify_vgrid_map_integrity(initial_vgrid_map)
377+
self.assertIn(self.TEST_VGRID_NAME, initial_vgrid_map.get(VGRIDS, {}))
364378
force_update_resource_map(self.configuration)
365379
allowed = user_allowed_res_exes(self.configuration, self.TEST_OWNER_DN)
366380
self.assertTrue(isinstance(allowed, dict))
@@ -370,7 +384,9 @@ def test_user_allowed_res_stores(self):
370384
"""Test user_allowed_res_stores returns allowed stores"""
371385
self._create_resource(self.TEST_RESOURCE_ID, [self.TEST_OWNER_DN])
372386
self._create_vgrid(self.TEST_VGRID_NAME, [self.TEST_OWNER_DN])
373-
force_update_vgrid_map(self.configuration)
387+
initial_vgrid_map = force_update_vgrid_map(self.configuration)
388+
self._verify_vgrid_map_integrity(initial_vgrid_map)
389+
self.assertIn(self.TEST_VGRID_NAME, initial_vgrid_map.get(VGRIDS, {}))
374390
force_update_resource_map(self.configuration)
375391
allowed = user_allowed_res_stores(
376392
self.configuration, self.TEST_OWNER_DN)
@@ -381,7 +397,9 @@ def test_user_visible_res_exes(self):
381397
"""Test user_visible_res_exes returns visible exes"""
382398
self._create_resource(self.TEST_RESOURCE_ID, [self.TEST_OWNER_DN])
383399
self._create_vgrid(self.TEST_VGRID_NAME, [self.TEST_OWNER_DN])
384-
force_update_vgrid_map(self.configuration)
400+
initial_vgrid_map = force_update_vgrid_map(self.configuration)
401+
self._verify_vgrid_map_integrity(initial_vgrid_map)
402+
self.assertIn(self.TEST_VGRID_NAME, initial_vgrid_map.get(VGRIDS, {}))
385403
force_update_resource_map(self.configuration)
386404
visible = user_visible_res_exes(self.configuration, self.TEST_OWNER_DN)
387405
self.assertTrue(isinstance(visible, dict))
@@ -391,7 +409,9 @@ def test_user_visible_res_stores(self):
391409
"""Test user_visible_res_stores returns visible stores"""
392410
self._create_resource(self.TEST_RESOURCE_ID, [self.TEST_OWNER_DN])
393411
self._create_vgrid(self.TEST_VGRID_NAME, [self.TEST_OWNER_DN])
394-
force_update_vgrid_map(self.configuration)
412+
initial_vgrid_map = force_update_vgrid_map(self.configuration)
413+
self._verify_vgrid_map_integrity(initial_vgrid_map)
414+
self.assertIn(self.TEST_VGRID_NAME, initial_vgrid_map.get(VGRIDS, {}))
395415
force_update_resource_map(self.configuration)
396416
visible = user_visible_res_stores(
397417
self.configuration, self.TEST_OWNER_DN)
@@ -404,7 +424,9 @@ def test_user_allowed_user_confs(self):
404424
self._provision_test_user(self, self.TEST_USER_DN)
405425
self._create_vgrid(self.TEST_VGRID_NAME, [self.TEST_OWNER_DN],
406426
[self.TEST_USER_DN])
407-
force_update_vgrid_map(self.configuration)
427+
initial_vgrid_map = force_update_vgrid_map(self.configuration)
428+
self._verify_vgrid_map_integrity(initial_vgrid_map)
429+
self.assertIn(self.TEST_VGRID_NAME, initial_vgrid_map.get(VGRIDS, {}))
408430
force_update_user_map(self.configuration)
409431
allowed = user_allowed_user_confs(
410432
self.configuration, self.TEST_OWNER_DN)
@@ -484,7 +506,9 @@ def test_user_vgrid_access(self):
484506
self._provision_test_user(self, self.TEST_OWNER_DN)
485507
self._create_vgrid(self.TEST_VGRID_NAME, [self.TEST_OWNER_DN])
486508
# Refresh maps to reflect new content
487-
force_update_vgrid_map(self.configuration)
509+
initial_vgrid_map = force_update_vgrid_map(self.configuration)
510+
self._verify_vgrid_map_integrity(initial_vgrid_map)
511+
self.assertIn(self.TEST_VGRID_NAME, initial_vgrid_map.get(VGRIDS, {}))
488512
allowed_vgrids = user_vgrid_access(self.configuration,
489513
self.TEST_OWNER_DN)
490514
self.assertIn(self.TEST_VGRID_NAME, allowed_vgrids)
@@ -500,7 +524,9 @@ def test_res_vgrid_access(self):
500524
self._create_vgrid(self.TEST_VGRID_NAME, resources=[
501525
self.TEST_RESOURCE_ID])
502526
# Refresh maps to reflect new content
503-
force_update_vgrid_map(self.configuration)
527+
initial_vgrid_map = force_update_vgrid_map(self.configuration)
528+
self._verify_vgrid_map_integrity(initial_vgrid_map)
529+
self.assertIn(self.TEST_VGRID_NAME, initial_vgrid_map.get(VGRIDS, {}))
504530
allowed = res_vgrid_access(self.configuration, self.TEST_RESOURCE_ID)
505531
self.assertIn(self.TEST_VGRID_NAME, allowed)
506532

@@ -512,8 +538,9 @@ def test_vgrid_map_refresh(self):
512538

513539
self._create_vgrid(self.TEST_VGRID_NAME, [self.TEST_OWNER_DN])
514540
# Force refresh map
515-
updated_map = force_update_vgrid_map(self.configuration)
516-
vgrids = updated_map.get(VGRIDS, {})
541+
updated_vgrid_map = force_update_vgrid_map(self.configuration)
542+
self._verify_vgrid_map_integrity(updated_vgrid_map)
543+
vgrids = updated_vgrid_map.get(VGRIDS, {})
517544
self.assertIn(self.TEST_VGRID_NAME, vgrids)
518545
self.assertEqual(vgrids[self.TEST_VGRID_NAME]
519546
[OWNERS], [self.TEST_OWNER_DN])
@@ -523,7 +550,9 @@ def test_user_map_access(self):
523550
# Add user as member
524551
self._create_vgrid(self.TEST_VGRID_NAME, owners=[self.TEST_OWNER_DN],
525552
members=[self.TEST_MEMBER_DN])
526-
force_update_vgrid_map(self.configuration)
553+
initial_vgrid_map = force_update_vgrid_map(self.configuration)
554+
self._verify_vgrid_map_integrity(initial_vgrid_map)
555+
self.assertIn(self.TEST_VGRID_NAME, initial_vgrid_map.get(VGRIDS, {}))
527556
# Verify member access
528557
allowed = check_vgrid_access(self.configuration, self.TEST_MEMBER_DN,
529558
self.TEST_VGRID_NAME)
@@ -541,6 +570,8 @@ def test_resource_map_update(self):
541570
self._create_vgrid(self.TEST_VGRID_NAME, owners=[self.TEST_OWNER_DN],
542571
resources=[self.TEST_RESOURCE_ID])
543572
updated_vgrid_map = force_update_vgrid_map(self.configuration)
573+
self._verify_vgrid_map_integrity(updated_vgrid_map)
574+
self.assertIn(self.TEST_VGRID_NAME, updated_vgrid_map.get(VGRIDS, {}))
544575
# Check vgrid map contains resource entry
545576
vgrid_data = updated_vgrid_map.get(VGRIDS, {})
546577
top_vgrid_data = vgrid_data.get(self.TEST_VGRID_NAME, {})
@@ -563,10 +594,12 @@ def test_settings_inheritance(self):
563594
self._create_vgrid(sub_vgrid)
564595

565596
# Force refresh of cached map
566-
updated_map = force_update_vgrid_map(self.configuration)
597+
updated_vgrid_map = force_update_vgrid_map(self.configuration)
598+
self._verify_vgrid_map_integrity(updated_vgrid_map)
599+
self.assertIn(self.TEST_VGRID_NAME, updated_vgrid_map.get(VGRIDS, {}))
567600

568601
# Retrieve vgrid data from cached map
569-
vgrid_data = updated_map.get(VGRIDS, {})
602+
vgrid_data = updated_vgrid_map.get(VGRIDS, {})
570603
self.assertTrue(vgrid_data)
571604

572605
# Retrieve top vgrid settings from cached map
@@ -587,7 +620,8 @@ def test_settings_inheritance(self):
587620
# Verify hidden setting unset without inheritance
588621
self.assertFalse(sub_settings_dict.get('hidden'))
589622

590-
inherited_map = vgrid_inherit_map(self.configuration, updated_map)
623+
inherited_map = vgrid_inherit_map(
624+
self.configuration, updated_vgrid_map)
591625
vgrid_data = inherited_map.get(VGRIDS, {})
592626
self.assertTrue(vgrid_data)
593627

@@ -606,7 +640,9 @@ def test_unmap_inheritance(self):
606640
self._create_vgrid(sub_vgrid)
607641

608642
# Force refresh of cached map
609-
updated_map = force_update_vgrid_map(self.configuration)
643+
updated_vgrid_map = force_update_vgrid_map(self.configuration)
644+
self._verify_vgrid_map_integrity(updated_vgrid_map)
645+
self.assertIn(self.TEST_VGRID_NAME, updated_vgrid_map.get(VGRIDS, {}))
610646

611647
# Unmap and verify mark modified
612648
unmap_inheritance(self.configuration, self.TEST_VGRID_NAME,
@@ -622,6 +658,7 @@ def test_user_map_fields(self):
622658
self._provision_test_user(self, self.TEST_USER_DN)
623659
# Force fresh user map
624660
initial_vgrid_map = force_update_vgrid_map(self.configuration)
661+
self._verify_vgrid_map_integrity(initial_vgrid_map)
625662
user_map = force_update_user_map(self.configuration)
626663
test_owner = user_map.get(self.TEST_OWNER_DN, {})
627664
self.assertEqual(test_owner.get(USERID), self.TEST_OWNER_UUID)
@@ -638,6 +675,7 @@ def test_resource_revoked_access(self):
638675
resources=[self.TEST_RESOURCE_ID])
639676

640677
initial_vgrid_map = force_update_vgrid_map(self.configuration)
678+
self._verify_vgrid_map_integrity(initial_vgrid_map)
641679
self.assertIn(self.TEST_VGRID_NAME, initial_vgrid_map.get(VGRIDS, {}))
642680
# Check vgrid map contains resource entry
643681
vgrid_data = initial_vgrid_map.get(VGRIDS, {})
@@ -655,15 +693,17 @@ def test_resource_revoked_access(self):
655693
self.assertEqual(success_and_msg, (True, ''))
656694

657695
updated_vgrid_map = force_update_vgrid_map(self.configuration)
696+
self._verify_vgrid_map_integrity(updated_vgrid_map)
697+
self.assertIn(self.TEST_VGRID_NAME, updated_vgrid_map.get(VGRIDS, {}))
658698
# Check vgrid map no longer contains resource entry
659699
vgrid_data = updated_vgrid_map.get(VGRIDS, {})
660700
top_vgrid_data = vgrid_data.get(self.TEST_VGRID_NAME, {})
661701
top_vgrid_res = top_vgrid_data.get(RESOURCES, {})
662702
self.assertNotIn(self.TEST_RESOURCE_ID, top_vgrid_res)
663703

664704
# Verify resource still in resource map
665-
updated_map = force_update_resource_map(self.configuration)
666-
self.assertIn(self.TEST_RESOURCE_ID, updated_map)
705+
updated_res_map = force_update_resource_map(self.configuration)
706+
self.assertIn(self.TEST_RESOURCE_ID, updated_res_map)
667707

668708
def test_non_recursive_inheritance(self):
669709
"""Verify non-recursive map excludes nested vgrids"""
@@ -675,6 +715,7 @@ def test_non_recursive_inheritance(self):
675715

676716
# Force update to avoid auto caching and get non-recursive map
677717
initial_vgrid_map = force_update_vgrid_map(self.configuration)
718+
self._verify_vgrid_map_integrity(initial_vgrid_map)
678719
self.assertIn(parent_vgrid, initial_vgrid_map.get(VGRIDS, {}))
679720
self.assertIn(child_vgrid, initial_vgrid_map.get(VGRIDS, {}))
680721
vgrid_map = get_vgrid_map(self.configuration, recursive=False)
@@ -700,10 +741,11 @@ def test_hidden_setting_propagation(self):
700741
('hidden', True)])
701742

702743
# Verify parent remains visible in cache
703-
updated_map = force_update_vgrid_map(self.configuration)
704-
self.assertIn(parent_vgrid, updated_map.get(VGRIDS, {}))
705-
self.assertIn(child_vgrid, updated_map.get(VGRIDS, {}))
706-
parent_data = updated_map.get(VGRIDS, {}).get(parent_vgrid, {})
744+
updated_vgrid_map = force_update_vgrid_map(self.configuration)
745+
self._verify_vgrid_map_integrity(updated_vgrid_map)
746+
self.assertIn(parent_vgrid, updated_vgrid_map.get(VGRIDS, {}))
747+
self.assertIn(child_vgrid, updated_vgrid_map.get(VGRIDS, {}))
748+
parent_data = updated_vgrid_map.get(VGRIDS, {}).get(parent_vgrid, {})
707749
parent_settings = dict(parent_data.get(SETTINGS, []))
708750
self.assertNotEqual(parent_settings.get('hidden'), True)
709751

@@ -713,6 +755,7 @@ def test_default_vgrid_access(self):
713755
members=[self.TEST_MEMBER_DN])
714756

715757
initial_vgrid_map = force_update_vgrid_map(self.configuration)
758+
self._verify_vgrid_map_integrity(initial_vgrid_map)
716759
self.assertIn(self.TEST_VGRID_NAME, initial_vgrid_map.get(VGRIDS, {}))
717760

718761
# Even non-member should have access to default vgrid
@@ -738,6 +781,7 @@ def test_general_vgrid_access(self):
738781
members=[self.TEST_MEMBER_DN])
739782

740783
initial_vgrid_map = force_update_vgrid_map(self.configuration)
784+
self._verify_vgrid_map_integrity(initial_vgrid_map)
741785
self.assertIn(self.TEST_VGRID_NAME, initial_vgrid_map.get(VGRIDS, {}))
742786

743787
# Test vgrid must allow owner and members access
@@ -771,6 +815,7 @@ def test_user_allowed_res_confs(self):
771815
self._create_vgrid(self.TEST_VGRID_NAME, owners=[self.TEST_OWNER_DN],
772816
resources=[self.TEST_RESOURCE_ID])
773817
initial_vgrid_map = force_update_vgrid_map(self.configuration)
818+
self._verify_vgrid_map_integrity(initial_vgrid_map)
774819
self.assertIn(self.TEST_VGRID_NAME, initial_vgrid_map.get(VGRIDS, {}))
775820
force_update_resource_map(self.configuration)
776821
# Owner should be allowed access
@@ -865,6 +910,7 @@ def test_empty_member_access(self):
865910
"""Verify members-only vgrid rejects outsiders"""
866911
self._create_vgrid(self.TEST_VGRID_NAME, [], [self.TEST_MEMBER_DN])
867912
initial_vgrid_map = force_update_vgrid_map(self.configuration)
913+
self._verify_vgrid_map_integrity(initial_vgrid_map)
868914
self.assertIn(self.TEST_VGRID_NAME, initial_vgrid_map.get(VGRIDS, {}))
869915

870916
# Outsider should be blocked despite no owners

0 commit comments

Comments
 (0)