Skip to content

Commit d426b5d

Browse files
fix copilot suggestions
Signed-off-by: hassaansaleem28 <iamhassaans@gmail.com>
1 parent 9deb3fd commit d426b5d

File tree

2 files changed

+30
-4
lines changed

2 files changed

+30
-4
lines changed

ingestion/src/metadata/ingestion/source/database/oracle/connection.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
Source connection handler
1414
"""
1515
import base64
16+
import binascii
1617
import io
1718
import os
1819
import shutil
@@ -21,7 +22,7 @@
2122
import weakref
2223
import zipfile
2324
from copy import deepcopy
24-
from typing import Any, Optional
25+
from typing import Optional
2526
from urllib.parse import quote_plus
2627

2728
import oracledb
@@ -106,7 +107,7 @@ def _is_autonomous_connection(self) -> bool:
106107
@staticmethod
107108
def _get_autonomous_connection_config(
108109
connection_type: OracleAutonomousConnection,
109-
) -> Any:
110+
) -> OracleAutonomousConnection:
110111
return connection_type
111112

112113
@staticmethod
@@ -144,8 +145,10 @@ def _safe_extract_wallet_archive(zip_ref: zipfile.ZipFile, target_dir: str) -> N
144145

145146
def _extract_wallet_content(self, wallet_content: SecretStr) -> str:
146147
try:
147-
decoded_wallet = base64.b64decode(wallet_content.get_secret_value())
148-
except (ValueError, TypeError) as exc:
148+
decoded_wallet = base64.b64decode(
149+
wallet_content.get_secret_value(), validate=True
150+
)
151+
except (binascii.Error, TypeError) as exc:
149152
raise ValueError(
150153
"Invalid walletContent. Expected a base64-encoded wallet zip."
151154
) from exc

ingestion/tests/unit/test_source_connection.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1373,6 +1373,29 @@ def test_oracle_autonomous_wallet_content_zip_slip_rejected(
13731373
assert "unsafe file paths" in str(error.exception)
13741374
assert oracle_connection._wallet_temp_dir is None
13751375

1376+
@patch(
1377+
"metadata.ingestion.source.database.oracle.connection.create_generic_db_connection"
1378+
)
1379+
def test_oracle_autonomous_wallet_content_invalid_base64_rejected(
1380+
self, mock_create_generic_db_connection
1381+
):
1382+
connection = OracleConnectionConfig(
1383+
username="admin",
1384+
password="password",
1385+
oracleConnectionType=OracleAutonomousConnection(
1386+
tnsAlias="myadb_high",
1387+
walletContent="Zm9v$",
1388+
),
1389+
)
1390+
oracle_connection = OracleConnection(connection)
1391+
mock_create_generic_db_connection.return_value = "dummy_engine"
1392+
1393+
with self.assertRaises(ValueError) as error:
1394+
oracle_connection._get_client()
1395+
1396+
assert "base64-encoded wallet zip" in str(error.exception)
1397+
assert oracle_connection._wallet_temp_dir is None
1398+
13761399
def test_exasol_url(self):
13771400
from metadata.ingestion.source.database.exasol.connection import (
13781401
get_connection_url,

0 commit comments

Comments
 (0)