1010 AuthenticationConfiguration ,
1111 Configuration ,
1212 JwkConfiguration ,
13+ RHIdentityConfiguration ,
1314 LlamaStackConfiguration ,
1415 ServiceConfiguration ,
1516 UserDataCollection ,
1920 AUTH_MOD_NOOP ,
2021 AUTH_MOD_K8S ,
2122 AUTH_MOD_JWK_TOKEN ,
23+ AUTH_MOD_RH_IDENTITY ,
2224)
2325
2426
@@ -36,6 +38,7 @@ def test_authentication_configuration() -> None:
3638 assert auth_config .skip_tls_verification is False
3739 assert auth_config .k8s_ca_cert_path is None
3840 assert auth_config .k8s_cluster_api is None
41+ assert auth_config .rh_identity_config is None
3942
4043 # try to retrieve JWK configuration
4144 with pytest .raises (
@@ -45,6 +48,92 @@ def test_authentication_configuration() -> None:
4548 _ = auth_config .jwk_configuration
4649
4750
51+ def test_authentication_configuration_rh_identity () -> None :
52+ """Test the AuthenticationConfiguration with RH identity token."""
53+
54+ auth_config = AuthenticationConfiguration (
55+ module = AUTH_MOD_RH_IDENTITY ,
56+ skip_tls_verification = False ,
57+ k8s_ca_cert_path = None ,
58+ k8s_cluster_api = None ,
59+ rh_identity_config = RHIdentityConfiguration (required_entitlements = []),
60+ )
61+ assert auth_config is not None
62+ assert auth_config .module == AUTH_MOD_RH_IDENTITY
63+ assert auth_config .skip_tls_verification is False
64+ assert auth_config .k8s_ca_cert_path is None
65+ assert auth_config .k8s_cluster_api is None
66+ assert auth_config .rh_identity_config is not None
67+
68+
69+ def test_authentication_configuration_rh_identity_default_value () -> None :
70+ """Test the AuthenticationConfiguration with RH identity token."""
71+
72+ auth_config = AuthenticationConfiguration (
73+ module = AUTH_MOD_RH_IDENTITY ,
74+ skip_tls_verification = False ,
75+ k8s_ca_cert_path = None ,
76+ k8s_cluster_api = None ,
77+ rh_identity_config = RHIdentityConfiguration (),
78+ )
79+ assert auth_config is not None
80+ assert auth_config .module == AUTH_MOD_RH_IDENTITY
81+ assert auth_config .skip_tls_verification is False
82+ assert auth_config .k8s_ca_cert_path is None
83+ assert auth_config .k8s_cluster_api is None
84+ assert auth_config .rh_identity_config is not None
85+
86+
87+ def test_authentication_configuration_rh_identity_one_entitlement () -> None :
88+ """Test the AuthenticationConfiguration with RH identity token."""
89+
90+ auth_config = AuthenticationConfiguration (
91+ module = AUTH_MOD_RH_IDENTITY ,
92+ skip_tls_verification = False ,
93+ k8s_ca_cert_path = None ,
94+ k8s_cluster_api = None ,
95+ rh_identity_config = RHIdentityConfiguration (required_entitlements = ["foo" ]),
96+ )
97+ assert auth_config is not None
98+ assert auth_config .module == AUTH_MOD_RH_IDENTITY
99+ assert auth_config .skip_tls_verification is False
100+ assert auth_config .k8s_ca_cert_path is None
101+ assert auth_config .k8s_cluster_api is None
102+ assert auth_config .rh_identity_config is not None
103+
104+
105+ def test_authentication_configuration_rh_identity_more_entitlements () -> None :
106+ """Test the AuthenticationConfiguration with RH identity token."""
107+
108+ auth_config = AuthenticationConfiguration (
109+ module = AUTH_MOD_RH_IDENTITY ,
110+ skip_tls_verification = False ,
111+ k8s_ca_cert_path = None ,
112+ k8s_cluster_api = None ,
113+ rh_identity_config = RHIdentityConfiguration (
114+ required_entitlements = ["foo" , "bar" , "baz" ]
115+ ),
116+ )
117+ assert auth_config is not None
118+ assert auth_config .module == AUTH_MOD_RH_IDENTITY
119+ assert auth_config .skip_tls_verification is False
120+ assert auth_config .k8s_ca_cert_path is None
121+ assert auth_config .k8s_cluster_api is None
122+ assert auth_config .rh_identity_config is not None
123+
124+
125+ def test_authentication_configuration_rh_identity_but_insufficient_config () -> None :
126+ """Test the AuthenticationConfiguration with RH identity token."""
127+
128+ with pytest .raises (ValidationError , match = "RH" ):
129+ AuthenticationConfiguration (
130+ module = AUTH_MOD_RH_IDENTITY ,
131+ skip_tls_verification = False ,
132+ k8s_ca_cert_path = None ,
133+ k8s_cluster_api = None ,
134+ )
135+
136+
48137def test_authentication_configuration_jwk_token () -> None :
49138 """Test the AuthenticationConfiguration with JWK token."""
50139
@@ -140,7 +229,7 @@ def test_authentication_configuration_module_unsupported() -> None:
140229 )
141230
142231
143- def test_authentication_configuration_in_config () -> None :
232+ def test_authentication_configuration_in_config_noop () -> None :
144233 """Test the authentication configuration in main config."""
145234 # pylint: disable=no-member
146235 cfg = Configuration (
@@ -161,7 +250,11 @@ def test_authentication_configuration_in_config() -> None:
161250 assert cfg .authentication .k8s_ca_cert_path is None
162251 assert cfg .authentication .k8s_cluster_api is None
163252
164- cfg2 = Configuration (
253+
254+ def test_authentication_configuration_in_config_k8s () -> None :
255+ """Test the authentication configuration in main config."""
256+ # pylint: disable=no-member
257+ cfg = Configuration (
165258 name = "test_name" ,
166259 service = ServiceConfiguration (),
167260 llama_stack = LlamaStackConfiguration (
@@ -179,10 +272,66 @@ def test_authentication_configuration_in_config() -> None:
179272 k8s_cluster_api = None ,
180273 ),
181274 )
182- assert cfg2 .authentication is not None
183- assert cfg2 .authentication .module == AUTH_MOD_K8S
184- assert cfg2 .authentication .skip_tls_verification is True
185- assert cfg2 .authentication .k8s_ca_cert_path == Path (
186- "tests/configuration/server.crt"
275+ assert cfg .authentication is not None
276+ assert cfg .authentication .module == AUTH_MOD_K8S
277+ assert cfg .authentication .skip_tls_verification is True
278+ assert cfg .authentication .k8s_ca_cert_path == Path ("tests/configuration/server.crt" )
279+ assert cfg .authentication .k8s_cluster_api is None
280+
281+
282+ def test_authentication_configuration_in_config_rh_identity () -> None :
283+ """Test the authentication configuration in main config."""
284+ # pylint: disable=no-member
285+ cfg = Configuration (
286+ name = "test_name" ,
287+ service = ServiceConfiguration (),
288+ llama_stack = LlamaStackConfiguration (
289+ use_as_library_client = True ,
290+ library_client_config_path = "tests/configuration/run.yaml" ,
291+ ),
292+ user_data_collection = UserDataCollection (
293+ feedback_enabled = False , feedback_storage = None
294+ ),
295+ mcp_servers = [],
296+ authentication = AuthenticationConfiguration (
297+ module = AUTH_MOD_RH_IDENTITY ,
298+ skip_tls_verification = True ,
299+ k8s_ca_cert_path = "tests/configuration/server.crt" ,
300+ k8s_cluster_api = None ,
301+ rh_identity_config = RHIdentityConfiguration (required_entitlements = []),
302+ ),
303+ )
304+ assert cfg .authentication is not None
305+ assert cfg .authentication .module == AUTH_MOD_RH_IDENTITY
306+ assert cfg .authentication .skip_tls_verification is True
307+ assert cfg .authentication .k8s_ca_cert_path == Path ("tests/configuration/server.crt" )
308+ assert cfg .authentication .k8s_cluster_api is None
309+
310+
311+ def test_authentication_configuration_in_config_jwktoken () -> None :
312+ """Test the authentication configuration in main config."""
313+ # pylint: disable=no-member
314+ cfg = Configuration (
315+ name = "test_name" ,
316+ service = ServiceConfiguration (),
317+ llama_stack = LlamaStackConfiguration (
318+ use_as_library_client = True ,
319+ library_client_config_path = "tests/configuration/run.yaml" ,
320+ ),
321+ user_data_collection = UserDataCollection (
322+ feedback_enabled = False , feedback_storage = None
323+ ),
324+ mcp_servers = [],
325+ authentication = AuthenticationConfiguration (
326+ module = AUTH_MOD_JWK_TOKEN ,
327+ skip_tls_verification = True ,
328+ k8s_ca_cert_path = "tests/configuration/server.crt" ,
329+ k8s_cluster_api = None ,
330+ jwk_config = JwkConfiguration (url = "http://foo.bar.baz" ),
331+ ),
187332 )
188- assert cfg2 .authentication .k8s_cluster_api is None
333+ assert cfg .authentication is not None
334+ assert cfg .authentication .module == AUTH_MOD_JWK_TOKEN
335+ assert cfg .authentication .skip_tls_verification is True
336+ assert cfg .authentication .k8s_ca_cert_path == Path ("tests/configuration/server.crt" )
337+ assert cfg .authentication .k8s_cluster_api is None
0 commit comments