99from kubernetes .client import AuthenticationV1Api , AuthorizationV1Api
1010from kubernetes .client .rest import ApiException
1111
12- from auth .k8s import (
12+ from authentication .k8s import (
1313 K8sClientSingleton ,
1414 K8SAuthDependency ,
1515 ClusterIDUnavailableError ,
@@ -75,8 +75,8 @@ async def test_auth_dependency_valid_token(mocker):
7575 dependency = K8SAuthDependency ()
7676
7777 # Mock the Kubernetes API calls
78- mock_authn_api = mocker .patch ("auth .k8s.K8sClientSingleton.get_authn_api" )
79- mock_authz_api = mocker .patch ("auth .k8s.K8sClientSingleton.get_authz_api" )
78+ mock_authn_api = mocker .patch ("authentication .k8s.K8sClientSingleton.get_authn_api" )
79+ mock_authz_api = mocker .patch ("authentication .k8s.K8sClientSingleton.get_authz_api" )
8080
8181 # Mock a successful token review response
8282 mock_authn_api .return_value .create_token_review .return_value = MockK8sResponse (
@@ -108,8 +108,8 @@ async def test_auth_dependency_invalid_token(mocker):
108108 dependency = K8SAuthDependency ()
109109
110110 # Mock the Kubernetes API calls
111- mock_authn_api = mocker .patch ("auth .k8s.K8sClientSingleton.get_authn_api" )
112- mock_authz_api = mocker .patch ("auth .k8s.K8sClientSingleton.get_authz_api" )
111+ mock_authn_api = mocker .patch ("authentication .k8s.K8sClientSingleton.get_authn_api" )
112+ mock_authz_api = mocker .patch ("authentication .k8s.K8sClientSingleton.get_authz_api" )
113113
114114 # Setup mock responses for invalid token
115115 mock_authn_api .return_value .create_token_review .return_value = MockK8sResponse (
@@ -138,7 +138,7 @@ async def test_auth_dependency_invalid_token(mocker):
138138async def test_cluster_id_is_used_for_kube_admin (mocker ):
139139 """Test the cluster id is used as user_id when user is kube:admin."""
140140 dependency = K8SAuthDependency ()
141- mock_authz_api = mocker .patch ("auth .k8s.K8sClientSingleton.get_authz_api" )
141+ mock_authz_api = mocker .patch ("authentication .k8s.K8sClientSingleton.get_authz_api" )
142142 mock_authz_api .return_value .create_subject_access_review .return_value = (
143143 MockK8sResponse (allowed = True )
144144 )
@@ -152,7 +152,7 @@ async def test_cluster_id_is_used_for_kube_admin(mocker):
152152 )
153153
154154 mocker .patch (
155- "auth .k8s.get_user_info" ,
155+ "authentication .k8s.get_user_info" ,
156156 return_value = MockK8sResponseStatus (
157157 authenticated = True ,
158158 allowed = True ,
@@ -162,7 +162,7 @@ async def test_cluster_id_is_used_for_kube_admin(mocker):
162162 ),
163163 )
164164 mocker .patch (
165- "auth .k8s.K8sClientSingleton.get_cluster_id" ,
165+ "authentication .k8s.K8sClientSingleton.get_cluster_id" ,
166166 return_value = "some-cluster-id" ,
167167 )
168168
@@ -192,7 +192,7 @@ def test_auth_dependency_config(mocker):
192192def test_get_cluster_id (mocker ):
193193 """Test get_cluster_id function."""
194194 mock_get_custom_objects_api = mocker .patch (
195- "auth .k8s.K8sClientSingleton.get_custom_objects_api"
195+ "authentication .k8s.K8sClientSingleton.get_custom_objects_api"
196196 )
197197
198198 cluster_id = {"spec" : {"clusterID" : "some-cluster-id" }}
@@ -230,18 +230,20 @@ def test_get_cluster_id(mocker):
230230
231231def test_get_cluster_id_in_cluster (mocker ):
232232 """Test get_cluster_id function when running inside of cluster."""
233- mocker .patch ("auth.k8s.RUNNING_IN_CLUSTER" , True )
234- mocker .patch ("auth.k8s.K8sClientSingleton.__new__" )
235- mock_get_cluster_id = mocker .patch ("auth.k8s.K8sClientSingleton._get_cluster_id" )
233+ mocker .patch ("authentication.k8s.RUNNING_IN_CLUSTER" , True )
234+ mocker .patch ("authentication.k8s.K8sClientSingleton.__new__" )
235+ mock_get_cluster_id = mocker .patch (
236+ "authentication.k8s.K8sClientSingleton._get_cluster_id"
237+ )
236238
237239 mock_get_cluster_id .return_value = "some-cluster-id"
238240 assert K8sClientSingleton .get_cluster_id () == "some-cluster-id"
239241
240242
241243def test_get_cluster_id_outside_of_cluster (mocker ):
242244 """Test get_cluster_id function when running outside of cluster."""
243- mocker .patch ("auth .k8s.RUNNING_IN_CLUSTER" , False )
244- mocker .patch ("auth .k8s.K8sClientSingleton.__new__" )
245+ mocker .patch ("authentication .k8s.RUNNING_IN_CLUSTER" , False )
246+ mocker .patch ("authentication .k8s.K8sClientSingleton.__new__" )
245247
246248 # ensure cluster_id is None to trigger the condition
247249 K8sClientSingleton ._cluster_id = None
0 commit comments