@@ -27,91 +27,76 @@ class TestCatalogRBAC:
2727 """Test suite for catalog ConfigMap RBAC"""
2828
2929 @pytest .mark .smoke
30- @pytest .mark .parametrize (
31- "user_params,configmap_name" ,
32- [
33- pytest .param (
34- {},
35- DEFAULT_MODEL_CATALOG_CM ,
36- id = "admin_read_default_sources" ,
37- marks = (pytest .mark .pre_upgrade , pytest .mark .post_upgrade , pytest .mark .install ),
38- ),
39- pytest .param (
40- {},
41- DEFAULT_CUSTOM_MODEL_CATALOG ,
42- id = "admin_read_custom_sources" ,
43- marks = (pytest .mark .pre_upgrade , pytest .mark .post_upgrade , pytest .mark .install ),
44- ),
45- pytest .param (
46- {"user_type" : "test" },
47- DEFAULT_MODEL_CATALOG_CM ,
48- id = "non_admin_denied_default_sources" ,
49- ),
50- pytest .param (
51- {"user_type" : "test" },
52- DEFAULT_CUSTOM_MODEL_CATALOG ,
53- id = "non_admin_denied_custom_sources" ,
54- ),
55- ],
56- )
57- def test_catalog_configmap_rbac (
30+ @pytest .mark .pre_upgrade
31+ @pytest .mark .post_upgrade
32+ @pytest .mark .install
33+ @pytest .mark .parametrize ("configmap_name" , [DEFAULT_MODEL_CATALOG_CM , DEFAULT_CUSTOM_MODEL_CATALOG ])
34+ def test_admin_can_read_catalog_configmaps (
5835 self ,
59- is_byoidc : bool ,
6036 admin_client : DynamicClient ,
6137 model_registry_namespace : str ,
62- user_credentials_rbac : dict [str , str ],
63- login_as_test_user : None ,
64- user_params : dict ,
6538 configmap_name : str ,
6639 ):
6740 """
68- RHOAIENG-41850: Verify RBAC permissions for catalog ConfigMaps.
41+ RHOAIENG-41850: Verify that admin users can read both catalog ConfigMaps.
6942
70- Admin users should have:
43+ Admins should have:
7144 - get/watch on model-catalog-default-sources (read-only)
7245 - get/watch/update/patch on model-catalog-sources (read/write)
7346
74- Non-admin users should receive 403 Forbidden when accessing either ConfigMap.
75-
7647 Note: Admin write access to model-catalog-sources is already tested by existing tests
7748 (test_custom_model_catalog.py, test_catalog_source_merge.py) which use admin_client
7849 to successfully update ConfigMaps via ResourceEditor.
7950 """
80- is_test_user = user_params .get ("user_type" ) == "test"
81-
82- # Select client based on user type
83- client = get_client () if is_test_user else admin_client
8451 catalog_cm = ConfigMap (
8552 name = configmap_name ,
8653 namespace = model_registry_namespace ,
87- client = client ,
54+ client = admin_client ,
8855 )
8956
90- if is_test_user :
91- if is_byoidc :
92- pytest .skip (reason = "BYOIDC test users may have pre-configured group memberships" )
93- # Non-admin user - should receive 403 Forbidden
94- with pytest .raises (ApiException ) as exc_info :
95- _ = catalog_cm .instance # Trigger the API call
57+ assert catalog_cm .exists , f"ConfigMap '{ configmap_name } ' not found in namespace '{ model_registry_namespace } '"
9658
97- assert exc_info .value .status == 403 , (
98- f"Expected HTTP 403 Forbidden for non-admin user accessing '{ configmap_name } ', "
99- f"but got { exc_info .value .status } : { exc_info .value .reason } "
100- )
101- LOGGER .info (
102- f"Non-admin user '{ user_credentials_rbac ['username' ]} ' correctly denied access "
103- f"to ConfigMap '{ configmap_name } '"
104- )
105- else :
106- # Admin user - should be able to read
107- assert catalog_cm .exists , (
108- f"ConfigMap '{ configmap_name } ' not found in namespace '{ model_registry_namespace } '"
109- )
59+ data = catalog_cm .instance .data
60+ assert data is not None , f"Admin should be able to read ConfigMap '{ configmap_name } ' data"
11061
111- data = catalog_cm . instance . data
112- assert data is not None , f"Admin should be able to read ConfigMap '{ configmap_name } ' data "
62+ sources_yaml = data . get ( "sources.yaml" )
63+ assert sources_yaml is not None , f"ConfigMap '{ configmap_name } ' should contain 'sources.yaml' key "
11364
114- sources_yaml = data .get ("sources.yaml" )
115- assert sources_yaml is not None , f"ConfigMap '{ configmap_name } ' should contain 'sources.yaml' key"
65+ LOGGER .info (f"Admin successfully read ConfigMap '{ configmap_name } '" )
11666
117- LOGGER .info (f"Admin successfully read ConfigMap '{ configmap_name } '" )
67+ @pytest .mark .smoke
68+ @pytest .mark .parametrize ("configmap_name" , [DEFAULT_MODEL_CATALOG_CM , DEFAULT_CUSTOM_MODEL_CATALOG ])
69+ def test_non_admin_cannot_access_catalog_configmaps (
70+ self ,
71+ is_byoidc : bool ,
72+ model_registry_namespace : str ,
73+ user_credentials_rbac : dict [str , str ],
74+ login_as_test_user : None ,
75+ configmap_name : str ,
76+ ):
77+ """
78+ RHOAIENG-41850: Verify that non-admin users cannot access catalog ConfigMaps,
79+ receiving a 403 Forbidden error.
80+ """
81+ if is_byoidc :
82+ pytest .skip (reason = "BYOIDC test users may have pre-configured group memberships" )
83+
84+ # get_client() uses the current kubeconfig context (set by login_as_test_user fixture)
85+ user_client = get_client ()
86+
87+ with pytest .raises (ApiException ) as exc_info :
88+ catalog_cm = ConfigMap (
89+ name = configmap_name ,
90+ namespace = model_registry_namespace ,
91+ client = user_client ,
92+ )
93+ _ = catalog_cm .instance # Access the ConfigMap instance to trigger the API call
94+
95+ assert exc_info .value .status == 403 , (
96+ f"Expected HTTP 403 Forbidden for non-admin user accessing '{ configmap_name } ', "
97+ f"but got { exc_info .value .status } : { exc_info .value .reason } "
98+ )
99+ LOGGER .info (
100+ f"Non-admin user '{ user_credentials_rbac ['username' ]} ' correctly denied access "
101+ f"to ConfigMap '{ configmap_name } '"
102+ )
0 commit comments