Skip to content

Commit b29bfca

Browse files
committed
test(opensearch): add regression test for AWS session token connection (#21941)
1 parent 7547566 commit b29bfca

1 file changed

Lines changed: 46 additions & 0 deletions

File tree

ingestion/tests/unit/topology/search/test_opensearch.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@
2727
from metadata.generated.schema.metadataIngestion.workflow import (
2828
OpenMetadataWorkflowConfig,
2929
)
30+
from metadata.generated.schema.entity.services.connections.search.openSearchConnection import (
31+
OpenSearchConnection,
32+
)
33+
from metadata.generated.schema.security.credentials.awsCredentials import AWSCredentials
34+
from metadata.ingestion.source.search.opensearch.connection import get_connection
3035
from metadata.ingestion.source.search.opensearch.metadata import OpensearchSource
3136

3237
# Mock OpenSearch configuration
@@ -208,3 +213,44 @@ def __init__(self, methodName, test_connection) -> None:
208213
def test_partition_parse_columns(self):
209214
actual_index = next(self.os_source.yield_search_index(MOCK_DETAILS)).right
210215
self.assertEqual(actual_index, EXPECTED_RESULT)
216+
217+
218+
class OpenSearchConnectionTest(TestCase):
219+
"""
220+
Test OpenSearch connection handler with AWS credentials
221+
"""
222+
223+
@patch("metadata.ingestion.source.search.opensearch.connection.OpenSearch")
224+
@patch("metadata.ingestion.source.search.opensearch.connection.AWS4Auth")
225+
def test_aws_auth_with_session_token(self, mock_aws4auth, mock_opensearch):
226+
"""
227+
Regression test for issue #21941: session token should not crash
228+
and should be passed as a plain string.
229+
"""
230+
from unittest.mock import MagicMock
231+
232+
mock_opensearch.return_value = MagicMock()
233+
mock_aws4auth.return_value = MagicMock()
234+
235+
conn = OpenSearchConnection(
236+
hostPort="https://fake.us-east-1.es.amazonaws.com:443",
237+
authType=AWSCredentials(
238+
awsAccessKeyId="ASIAXXX",
239+
awsSecretAccessKey="mysecret",
240+
awsSessionToken="mytoken", # This is the string that was causing crashes
241+
awsRegion="us-east-1",
242+
),
243+
)
244+
245+
# This should NOT raise AttributeError: 'str' object has no attribute 'get_secret_value'
246+
client = get_connection(conn)
247+
self.assertIsNotNone(client)
248+
249+
# Verify AWS4Auth was called with the session_token as a plain string
250+
mock_aws4auth.assert_called_once_with(
251+
"ASIAXXX",
252+
"mysecret",
253+
"us-east-1",
254+
"es",
255+
session_token="mytoken",
256+
)

0 commit comments

Comments
 (0)