|
10 | 10 | from constants import ( |
11 | 11 | AUTH_MOD_NOOP, |
12 | 12 | AUTH_MOD_K8S, |
| 13 | + AUTH_MOD_JWK_TOKEN, |
13 | 14 | DATA_COLLECTOR_COLLECTION_INTERVAL, |
14 | 15 | DATA_COLLECTOR_CONNECTION_TIMEOUT, |
15 | 16 | ) |
16 | 17 |
|
17 | 18 | from models.config import ( |
18 | 19 | AuthenticationConfiguration, |
19 | 20 | Configuration, |
| 21 | + JwkConfiguration, |
20 | 22 | LlamaStackConfiguration, |
21 | 23 | ServiceConfiguration, |
22 | 24 | UserDataCollection, |
@@ -682,6 +684,52 @@ def test_authentication_configuration() -> None: |
682 | 684 | assert auth_config.k8s_cluster_api is None |
683 | 685 |
|
684 | 686 |
|
| 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 | + |
685 | 733 | def test_authentication_configuration_supported() -> None: |
686 | 734 | """Test the AuthenticationConfiguration constructor.""" |
687 | 735 | auth_config = AuthenticationConfiguration( |
|
0 commit comments