Skip to content

Commit 8f1f1de

Browse files
committed
Increase coverage.
1 parent 66ad857 commit 8f1f1de

File tree

1 file changed

+67
-3
lines changed

1 file changed

+67
-3
lines changed

tests/test_mig_shared_vgridaccess.py

Lines changed: 67 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,10 @@
3333
from mig.shared.fileio import pickle, read_file
3434
from mig.shared.vgrid import vgrid_list, vgrid_set_entities, vgrid_settings
3535
from mig.shared.vgridaccess import CONF, MEMBERS, OWNERS, RESOURCES, SETTINGS, \
36-
USERID, VGRIDS, check_vgrid_access, force_update_resource_map, \
37-
force_update_user_map, force_update_vgrid_map, get_resource_map, \
38-
get_user_map, get_vgrid_map, load_resource_map, refresh_vgrid_map, \
36+
USERID, VGRIDS, check_vgrid_access, check_vgrids_modified, \
37+
force_update_resource_map, force_update_user_map, force_update_vgrid_map, \
38+
get_re_provider_map, get_resource_map, get_user_map, get_vgrid_map, \
39+
load_resource_map, refresh_vgrid_map, resources_using_re, unmap_vgrid, \
3940
user_vgrid_access, vgrid_inherit_map
4041
from tests.support import MigTestCase, ensure_dirs_exist, testmain
4142

@@ -56,8 +57,10 @@ class TestMigSharedVgridAccess(MigTestCase):
5657
'/C=DK/ST=NA/L=NA/O=Test Org/OU=NA/CN=Test Outsider/'\
5758
'emailAddress=outsider@example.com'
5859
TEST_RESOURCE_ID = 'test.example.org.0'
60+
5961
TEST_OWNER_UUID = 'ff326a2b984828d9b32077c9b0b35a05'
6062
TEST_USER_UUID = '707a2213995b4fb385793b5a7cb82a18'
63+
TEST_RESOURCE_ALIAS = '0835f310d6422c36e33eeb7d0d3e9cf5'
6164

6265
def _provide_configuration(self):
6366
"""Prepare isolated test config"""
@@ -369,6 +372,67 @@ def test_general_vgrid_access(self):
369372
self.TEST_OUTSIDER_DN)
370373
self.assertFalse(self.test_vgrid in allowed_vgrids)
371374

375+
def test_get_re_provider_map(self):
376+
"""Test RE provider map includes test resource"""
377+
test_re = 'Python'
378+
res_config = {'RUNTIMEENVIRONMENT': [(test_re, '/python/path')]}
379+
self._create_resource(self.TEST_RESOURCE_ID, [
380+
self.TEST_OWNER_DN], res_config)
381+
382+
# Update maps to include new resource
383+
force_update_resource_map(self.configuration)
384+
385+
# Verify RE appears in provider mapping
386+
re_map = get_re_provider_map(self.configuration)
387+
self.assertIn(test_re, re_map)
388+
self.assertIn(self.TEST_RESOURCE_ALIAS, re_map[test_re])
389+
390+
def test_resources_using_re(self):
391+
"""Test finding resources with specific runtime environment"""
392+
test_re = 'Bash'
393+
res_config = {'RUNTIMEENVIRONMENT': [(test_re, '/bash/path')]}
394+
self._create_resource(self.TEST_RESOURCE_ID, [
395+
self.TEST_OWNER_DN], res_config)
396+
397+
# Refresh resource map
398+
force_update_resource_map(self.configuration)
399+
400+
# Verify resource appears in RE-specific results
401+
res_list = resources_using_re(self.configuration, test_re)
402+
self.assertIn(self.TEST_RESOURCE_ALIAS, res_list)
403+
404+
def test_unmap_vgrid(self):
405+
"""Verify unmapping marks vgrid modified for update in cached data"""
406+
mod_list, mod_stamp = check_vgrids_modified(self.configuration)
407+
self.assertNotIn(self.test_vgrid, mod_list)
408+
409+
# Unmap and verify mark modified
410+
unmap_vgrid(self.configuration, self.test_vgrid)
411+
412+
mod_list, mod_stamp = check_vgrids_modified(self.configuration)
413+
self.assertIn(self.test_vgrid, mod_list)
414+
415+
def test_access_nonexistent_vgrid(self):
416+
"""Ensure checks fail cleanly for non-existent vgrid"""
417+
allowed = check_vgrid_access(self.configuration, self.TEST_MEMBER_DN,
418+
'no-such-vgrid')
419+
self.assertFalse(allowed)
420+
421+
# Should not appear in allowed vgrids
422+
allowed_vgrids = user_vgrid_access(
423+
self.configuration, self.TEST_MEMBER_DN)
424+
self.assertFalse('no-such-vgrid' in allowed_vgrids)
425+
426+
def test_empty_member_access(self):
427+
"""Verify members-only vgrid rejects outsiders"""
428+
self._create_vgrid(self.test_vgrid, [], [self.TEST_MEMBER_DN])
429+
force_update_vgrid_map(self.configuration)
430+
431+
# Outsider should be blocked despite no owners
432+
allowed = check_vgrid_access(self.configuration, self.TEST_OUTSIDER_DN,
433+
self.test_vgrid)
434+
self.assertFalse(allowed)
435+
372436

373437
if __name__ == '__main__':
374438
testmain()

0 commit comments

Comments
 (0)