This is an automated email from the ASF dual-hosted git repository.
potiuk pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git
The following commit(s) were added to refs/heads/main by this push:
new ddcd30e7c7 Validate connection host field for Sqoop connection (#32968)
ddcd30e7c7 is described below
commit ddcd30e7c7f5daeab5f74fb3224a4d5e33cec95d
Author: Pankaj Koti <[email protected]>
AuthorDate: Mon Jul 31 18:48:42 2023 +0530
Validate connection host field for Sqoop connection (#32968)
The connection `host` field should not contain a `?` for the
sqoop connection as it is not intended to include query params
in the `host` field.
---
airflow/providers/apache/sqoop/hooks/sqoop.py | 3 +++
tests/providers/apache/sqoop/hooks/test_sqoop.py | 15 +++++++++++++++
2 files changed, 18 insertions(+)
diff --git a/airflow/providers/apache/sqoop/hooks/sqoop.py
b/airflow/providers/apache/sqoop/hooks/sqoop.py
index b46984c9f0..297c567c19 100644
--- a/airflow/providers/apache/sqoop/hooks/sqoop.py
+++ b/airflow/providers/apache/sqoop/hooks/sqoop.py
@@ -113,6 +113,9 @@ class SqoopHook(BaseHook):
raise AirflowException(f"Sqoop command failed: {masked_cmd}")
def _prepare_command(self, export: bool = False) -> list[str]:
+ if "?" in self.conn.host:
+ raise ValueError("The sqoop connection host should not contain a
'?' character")
+
sqoop_cmd_type = "export" if export else "import"
connection_cmd = ["sqoop", sqoop_cmd_type]
diff --git a/tests/providers/apache/sqoop/hooks/test_sqoop.py
b/tests/providers/apache/sqoop/hooks/test_sqoop.py
index 2570b356bf..0075ebec9b 100644
--- a/tests/providers/apache/sqoop/hooks/test_sqoop.py
+++ b/tests/providers/apache/sqoop/hooks/test_sqoop.py
@@ -101,6 +101,16 @@ class TestSqoopHook:
extra=None,
)
)
+ db.merge_conn(
+ Connection(
+ conn_id="invalid_host_conn",
+ conn_type="mssql",
+ schema="schema",
+ host="rmdbs?query_param1=value1",
+ port=5050,
+ extra=None,
+ )
+ )
@patch("subprocess.Popen")
def test_popen(self, mock_popen):
@@ -370,3 +380,8 @@ class TestSqoopHook:
# Case no mssql
hook = SqoopHook(conn_id="sqoop_test")
assert f"{hook.conn.host}:{hook.conn.port}/{hook.conn.schema}" in
hook._prepare_command()
+
+ def test_invalid_host(self):
+ hook = SqoopHook(conn_id="invalid_host_conn")
+ with pytest.raises(ValueError, match="host should not contain a"):
+ hook._prepare_command()