LCORE-1027: Unit tests for RH identity authentication plugin#826
Conversation
WalkthroughThis PR introduces RH Identity authentication support by adding Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes
Possibly related PRs
Suggested labels
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (4)
tests/unit/models/config/test_authentication_configuration.py (4)
27-49: Add a negative test forrh_identity_configurationon non-RH modulesThe extra assertion that
auth_config.rh_identity_config is Nonefor the noop module is good. To fully cover the newrh_identity_configurationproperty, consider adding a dedicated test that verifies it raises on non-RH modules, similar to howjwk_configurationis validated:def test_authentication_configuration_rh_identity_property_unavailable_for_non_rh() -> None: auth_config = AuthenticationConfiguration( module=AUTH_MOD_NOOP, skip_tls_verification=False, k8s_ca_cert_path=None, k8s_cluster_api=None, ) with pytest.raises( ValueError, match="RH Identity configuration is only available for RH Identity authentication module", ): _ = auth_config.rh_identity_configurationThis guards the public property contract rather than just the underlying field.
51-123: Strengthen RH Identity tests by assertingrequired_entitlementsand exercising the propertyThese four tests nicely cover the constructor success cases for RH Identity with different entitlement setups, but they currently only assert that
rh_identity_configis notNone. Given the test names, it would be more robust to also assert the actualrequired_entitlementsvalues and to exercise therh_identity_configurationproperty. For example:def test_authentication_configuration_rh_identity() -> None: @@ - assert auth_config.rh_identity_config is not None + assert auth_config.rh_identity_config is not None + assert auth_config.rh_identity_configuration is auth_config.rh_identity_config + assert auth_config.rh_identity_configuration.required_entitlements == [] @@ def test_authentication_configuration_rh_identity_default_value() -> None: @@ - assert auth_config.rh_identity_config is not None + assert auth_config.rh_identity_config is not None + assert auth_config.rh_identity_configuration is auth_config.rh_identity_config + assert auth_config.rh_identity_configuration.required_entitlements is None @@ def test_authentication_configuration_rh_identity_one_entitlement() -> None: @@ - assert auth_config.rh_identity_config is not None + assert auth_config.rh_identity_config is not None + assert auth_config.rh_identity_configuration is auth_config.rh_identity_config + assert auth_config.rh_identity_configuration.required_entitlements == ["foo"] @@ def test_authentication_configuration_rh_identity_more_entitlements() -> None: @@ - assert auth_config.rh_identity_config is not None + assert auth_config.rh_identity_config is not None + assert auth_config.rh_identity_configuration is auth_config.rh_identity_config + assert auth_config.rh_identity_configuration.required_entitlements == [ + "foo", + "bar", + "baz", + ]This both validates the intended semantics of different entitlement configurations and ensures the new property is tested on the happy path.
125-135: Tighten the ValidationError assertion for insufficient RH Identity config
match="RH"is very broad and would pass for almost any RH-related ValidationError. To better document and lock in the expected failure reason, consider matching the more specific substring from the validator message:-def test_authentication_configuration_rh_identity_but_insufficient_config() -> None: - """Test the AuthenticationConfiguration with RH identity token.""" - - with pytest.raises(ValidationError, match="RH"): - AuthenticationConfiguration( +def test_authentication_configuration_rh_identity_but_insufficient_config() -> None: + """Test the AuthenticationConfiguration with RH identity token.""" + + with pytest.raises( + ValidationError, + match="RH Identity configuration must be specified", + ): + AuthenticationConfiguration( module=AUTH_MOD_RH_IDENTITY, skip_tls_verification=False, k8s_ca_cert_path=None, k8s_cluster_api=None, )This makes the test more resilient to unrelated changes while still tolerating any prefixes added by the validation framework.
254-337: Consider deduplicatingConfigurationsetup across in-config testsThe three tests
test_authentication_configuration_in_config_k8s,_rh_identity, and_jwktokenall construct aConfigurationinstance with nearly identical arguments, differing only in theauthenticationblock. To reduce duplication and make future changes to the common config cheaper, you could factor out shared kwargs into a helper or fixture, e.g.:import pytest from typing import Any @pytest.fixture def base_configuration_kwargs() -> dict[str, Any]: return { "name": "test_name", "service": ServiceConfiguration(), "llama_stack": LlamaStackConfiguration( use_as_library_client=True, library_client_config_path="tests/configuration/run.yaml", ), "user_data_collection": UserDataCollection( feedback_enabled=False, feedback_storage=None ), "mcp_servers": [], }and then:
def test_authentication_configuration_in_config_k8s(base_configuration_kwargs: dict[str, Any]) -> None: cfg = Configuration( authentication=AuthenticationConfiguration( module=AUTH_MOD_K8S, skip_tls_verification=True, k8s_ca_cert_path="tests/configuration/server.crt", k8s_cluster_api=None, ), **base_configuration_kwargs, ) ...Apply the same pattern for RH Identity and JWK. The current tests are fine as-is; this is just a maintainability improvement.
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
tests/unit/models/config/test_authentication_configuration.py(7 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-09-02T11:09:40.404Z
Learnt from: radofuchs
Repo: lightspeed-core/lightspeed-stack PR: 485
File: tests/e2e/features/environment.py:87-95
Timestamp: 2025-09-02T11:09:40.404Z
Learning: In the lightspeed-stack e2e tests, noop authentication tests use the default lightspeed-stack.yaml configuration, while noop-with-token tests use the Authorized tag to trigger a config swap to the specialized noop-with-token configuration file.
Applied to files:
tests/unit/models/config/test_authentication_configuration.py
🧬 Code graph analysis (1)
tests/unit/models/config/test_authentication_configuration.py (1)
src/models/config.py (7)
RHIdentityConfiguration(412-415)AuthenticationConfiguration(418-473)Configuration(623-649)ServiceConfiguration(149-166)LlamaStackConfiguration(177-220)UserDataCollection(223-256)JwkConfiguration(405-409)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
- GitHub Check: build-pr
- GitHub Check: Konflux kflux-prd-rh02 / lightspeed-stack-on-pull-request
- GitHub Check: e2e_tests (ci)
- GitHub Check: e2e_tests (azure)
🔇 Additional comments (2)
tests/unit/models/config/test_authentication_configuration.py (2)
9-24: Imports for RH Identity configuration and constant are consistentAdding
RHIdentityConfigurationandAUTH_MOD_RH_IDENTITYhere keeps this test module aligned with the new configuration model and constants; no issues spotted.
232-252: DefaultConfiguration.authenticationbehavior is well coveredThis test validates that the default
Configuration.authenticationmodule isAUTH_MOD_NOOPand that the associated TLS/K8s fields are unset, which is exactly what we want from the implicit configuration. No further changes needed here.
Description
LCORE-1027: Unit tests for RH identity authentication plugin
Type of change
Related Tickets & Documents
Summary by CodeRabbit
Release Notes
New Features
Tests
✏️ Tip: You can customize this high-level summary in your review settings.