Skip to content

Commit 4c2b26c

Browse files
committed
Updated all tests accordingly
1 parent 74b12da commit 4c2b26c

File tree

7 files changed

+23
-21
lines changed

7 files changed

+23
-21
lines changed

tests/unit/app/endpoints/test_authorized.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from starlette.datastructures import Headers
66

77
from app.endpoints.authorized import authorized_endpoint_handler
8-
from auth.utils import extract_user_token
8+
from authentication.utils import extract_user_token
99

1010
MOCK_AUTH = ("test-id", "test-user", True, "token")
1111

tests/unit/authentication/test_auth.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""Unit tests for functions defined in auth/__init__.py"""
22

3-
from auth import get_auth_dependency
4-
from auth import noop, noop_with_token, k8s
3+
from authentication import get_auth_dependency
4+
from authentication import noop, noop_with_token, k8s
55
from constants import AUTH_MOD_NOOP, AUTH_MOD_NOOP_WITH_TOKEN, AUTH_MOD_K8S
66
from configuration import configuration
77

tests/unit/authentication/test_jwk_token.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from pydantic import AnyHttpUrl
1010
from authlib.jose import JsonWebKey, JsonWebToken
1111

12-
from auth.jwk_token import JwkTokenAuthDependency, _jwk_cache
12+
from authentication.jwk_token import JwkTokenAuthDependency, _jwk_cache
1313
from constants import DEFAULT_USER_NAME, DEFAULT_USER_UID, NO_USER_TOKEN
1414
from models.config import JwkConfiguration, JwtConfiguration
1515

tests/unit/authentication/test_k8s.py

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from kubernetes.client import AuthenticationV1Api, AuthorizationV1Api
1010
from 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):
138138
async 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):
192192
def 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

231231
def 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

241243
def 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

tests/unit/authentication/test_noop.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""Unit tests for functions defined in auth/noop.py"""
22

33
from fastapi import Request
4-
from auth.noop import NoopAuthDependency
4+
from authentication.noop import NoopAuthDependency
55
from constants import DEFAULT_USER_NAME, DEFAULT_USER_UID, NO_USER_TOKEN
66

77

tests/unit/authentication/test_noop_with_token.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from fastapi import Request, HTTPException
44
import pytest
55

6-
from auth.noop_with_token import NoopWithTokenAuthDependency
6+
from authentication.noop_with_token import NoopWithTokenAuthDependency
77
from constants import DEFAULT_USER_NAME, DEFAULT_USER_UID
88

99

tests/unit/authentication/test_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from fastapi import HTTPException
44
from starlette.datastructures import Headers
55

6-
from auth.utils import extract_user_token
6+
from authentication.utils import extract_user_token
77

88

99
def test_extract_user_token():

0 commit comments

Comments
 (0)