2929# Mock Phase class
3030class MockPhase :
3131 def get (self , env_name , app_name , keys , path ):
32- if env_name == "prod" and path == "/frontend" :
32+ if env_name == "prod" and path == "/frontend" and app_name == "test_app" :
3333 return [{"key" : "SECRET_KEY" , "value" : "prod_secret_value" }]
34+ if env_name == "production" and path == "/" and app_name == "backend_api" :
35+ return [{"key" : "API_KEY" , "value" : "backend_api_key" }]
36+ if env_name == "staging" and path == "/auth" and app_name == "auth_service" :
37+ return [{"key" : "AUTH_TOKEN" , "value" : "auth_service_token" }]
3438 raise EnvironmentNotFoundException (env_name = env_name )
3539
3640@pytest .fixture
@@ -115,4 +119,41 @@ def test_resolve_local_reference_missing_path(phase, current_application_name, c
115119def test_resolve_invalid_reference_format (phase , current_application_name , current_env_name ):
116120 ref = "invalid_format"
117121 resolved_value = resolve_secret_reference (ref , secrets_dict , phase , current_application_name , current_env_name )
118- assert resolved_value == "${invalid_format}"
122+ assert resolved_value == "${invalid_format}"
123+
124+ # Tests for Cross-Application References
125+ def test_resolve_cross_app_reference (phase , current_application_name , current_env_name ):
126+ ref = "backend_api::production.API_KEY"
127+ resolved_value = resolve_secret_reference (ref , secrets_dict , phase , current_application_name , current_env_name )
128+ assert resolved_value == "backend_api_key"
129+
130+ def test_resolve_cross_app_reference_with_path (phase , current_application_name , current_env_name ):
131+ ref = "auth_service::staging./auth/AUTH_TOKEN"
132+ resolved_value = resolve_secret_reference (ref , secrets_dict , phase , current_application_name , current_env_name )
133+ assert resolved_value == "auth_service_token"
134+
135+ def test_resolve_missing_cross_app_key (phase , current_application_name , current_env_name ):
136+ ref = "another_app::dev.MISSING_KEY"
137+ resolved_value = resolve_secret_reference (ref , secrets_dict , phase , current_application_name , current_env_name )
138+ assert resolved_value == "${another_app::dev.MISSING_KEY}"
139+
140+ def test_resolve_all_secrets_with_cross_app (phase , current_application_name , current_env_name ):
141+ value = "Use this key: ${KEY}, this cross-app key: ${backend_api::production.API_KEY}, and this path key: ${/backend/payments/STRIPE_KEY}"
142+ all_secrets = [
143+ {"environment" : "current" , "path" : "/" , "key" : "KEY" , "value" : "value1" },
144+ {"environment" : "current" , "path" : "/backend/payments" , "key" : "STRIPE_KEY" , "value" : "stripe_value" }
145+ ]
146+ resolved_value = resolve_all_secrets (value , all_secrets , phase , current_application_name , current_env_name )
147+ expected_value = "Use this key: value1, this cross-app key: backend_api_key, and this path key: stripe_value"
148+ assert resolved_value == expected_value
149+
150+ # Complex Case: Mixed references including cross-app with missing values
151+ def test_resolve_mixed_references_with_cross_app (phase , current_application_name , current_env_name ):
152+ value = "Local: ${KEY}, Cross-Env: ${staging.DEBUG}, Cross-App: ${backend_api::production.API_KEY}, Missing Cross-App: ${missing_app::prod.KEY}"
153+ all_secrets = [
154+ {"environment" : "current" , "path" : "/" , "key" : "KEY" , "value" : "value1" },
155+ {"environment" : "staging" , "path" : "/" , "key" : "DEBUG" , "value" : "staging_debug_value" }
156+ ]
157+ resolved_value = resolve_all_secrets (value , all_secrets , phase , current_application_name , current_env_name )
158+ expected_value = "Local: value1, Cross-Env: staging_debug_value, Cross-App: backend_api_key, Missing Cross-App: ${missing_app::prod.KEY}"
159+ assert resolved_value == expected_value
0 commit comments