Skip to content

Commit 611fa9e

Browse files
committed
Unit tests for JWK auth. configuration
1 parent 58d6101 commit 611fa9e

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

tests/unit/models/test_config.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,15 @@
1010
from constants import (
1111
AUTH_MOD_NOOP,
1212
AUTH_MOD_K8S,
13+
AUTH_MOD_JWK_TOKEN,
1314
DATA_COLLECTOR_COLLECTION_INTERVAL,
1415
DATA_COLLECTOR_CONNECTION_TIMEOUT,
1516
)
1617

1718
from models.config import (
1819
AuthenticationConfiguration,
1920
Configuration,
21+
JwkConfiguration,
2022
LlamaStackConfiguration,
2123
ServiceConfiguration,
2224
UserDataCollection,
@@ -682,6 +684,52 @@ def test_authentication_configuration() -> None:
682684
assert auth_config.k8s_cluster_api is None
683685

684686

687+
def test_authentication_configuration_jwk_token() -> None:
688+
"""Test the AuthenticationConfiguration with JWK token."""
689+
690+
auth_config = AuthenticationConfiguration(
691+
module=AUTH_MOD_JWK_TOKEN,
692+
skip_tls_verification=False,
693+
k8s_ca_cert_path=None,
694+
k8s_cluster_api=None,
695+
jwk_config=JwkConfiguration(url="http://foo.bar.baz"),
696+
)
697+
assert auth_config is not None
698+
assert auth_config.module == AUTH_MOD_JWK_TOKEN
699+
assert auth_config.skip_tls_verification is False
700+
assert auth_config.k8s_ca_cert_path is None
701+
assert auth_config.k8s_cluster_api is None
702+
703+
704+
def test_authentication_configuration_jwk_token_but_insufficient_config() -> None:
705+
"""Test the AuthenticationConfiguration with JWK token."""
706+
707+
with pytest.raises(ValidationError, match="JwkConfiguration"):
708+
AuthenticationConfiguration(
709+
module=AUTH_MOD_JWK_TOKEN,
710+
skip_tls_verification=False,
711+
k8s_ca_cert_path=None,
712+
k8s_cluster_api=None,
713+
jwk_config=JwkConfiguration(),
714+
)
715+
716+
717+
def test_authentication_configuration_jwk_token_but_not_config() -> None:
718+
"""Test the AuthenticationConfiguration with JWK token."""
719+
720+
with pytest.raises(
721+
ValidationError,
722+
match="Value error, JWK configuration must be specified when using JWK token",
723+
):
724+
AuthenticationConfiguration(
725+
module=AUTH_MOD_JWK_TOKEN,
726+
skip_tls_verification=False,
727+
k8s_ca_cert_path=None,
728+
k8s_cluster_api=None,
729+
# no JwkConfiguration
730+
)
731+
732+
685733
def test_authentication_configuration_supported() -> None:
686734
"""Test the AuthenticationConfiguration constructor."""
687735
auth_config = AuthenticationConfiguration(

0 commit comments

Comments
 (0)