|
27 | 27 | from metadata.generated.schema.metadataIngestion.workflow import ( |
28 | 28 | OpenMetadataWorkflowConfig, |
29 | 29 | ) |
| 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 |
30 | 35 | from metadata.ingestion.source.search.opensearch.metadata import OpensearchSource |
31 | 36 |
|
32 | 37 | # Mock OpenSearch configuration |
@@ -208,3 +213,44 @@ def __init__(self, methodName, test_connection) -> None: |
208 | 213 | def test_partition_parse_columns(self): |
209 | 214 | actual_index = next(self.os_source.yield_search_index(MOCK_DETAILS)).right |
210 | 215 | 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