@@ -111,6 +111,16 @@ def test_get_connection_without_predefined_mount_point(self, mock_hvac):
111111 connection = test_client .get_connection (conn_id = "airflow/test_postgres" )
112112 assert connection .get_uri () == "postgresql://airflow:airflow@host:5432/airflow?foo=bar&baz=taz"
113113
114+ # When mount_point=None and conn_id does not contain "/",
115+ # backend should return None and not call Vault
116+
117+ mock_client .reset_mock ()
118+
119+ result = test_client .get_connection ("simple_id" )
120+
121+ assert result is None
122+ mock_client .secrets .kv .v2 .read_secret_version .assert_not_called ()
123+
114124 @mock .patch ("airflow.providers.hashicorp._internal_client.vault_client.hvac" )
115125 def test_get_variable_value (self , mock_hvac ):
116126 mock_client = mock .MagicMock ()
@@ -488,6 +498,40 @@ def test_connections_path_none_value(self, mock_hvac):
488498 assert test_client .get_connection (conn_id = "test" ) is None
489499 mock_hvac .Client .assert_not_called ()
490500
501+ @mock .patch ("airflow.providers.hashicorp._internal_client.vault_client.hvac" )
502+ def test_get_connection_with_empty_connections_path (self , mock_hvac ):
503+ mock_client = mock .MagicMock ()
504+ mock_hvac .Client .return_value = mock_client
505+
506+ mock_client .secrets .kv .v2 .read_secret_version .return_value = {
507+ "data" : {
508+ "data" : {"conn_uri" : "postgresql://user:pass@host:5432/db" },
509+ "metadata" : {"version" : 1 },
510+ }
511+ }
512+
513+ kwargs = {
514+ "connections_path" : "" ,
515+ "mount_point" : "airflow" ,
516+ "auth_type" : "token" ,
517+ "url" : "http://127.0.0.1:8200" ,
518+ "token" : "token" ,
519+ }
520+
521+ backend = VaultBackend (** kwargs )
522+
523+ connection = backend .get_connection ("my_conn" )
524+
525+ # Assert Vault was called without "connections/" prefix
526+ mock_client .secrets .kv .v2 .read_secret_version .assert_called_once_with (
527+ mount_point = "airflow" ,
528+ path = "my_conn" ,
529+ version = None ,
530+ raise_on_deleted_version = True ,
531+ )
532+
533+ assert connection .get_uri () == "postgres://user:pass@host:5432/db"
534+
491535 @mock .patch ("airflow.providers.hashicorp._internal_client.vault_client.hvac" )
492536 def test_variables_path_none_value (self , mock_hvac ):
493537 mock_client = mock .MagicMock ()
0 commit comments