You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by po...@apache.org on 2023/06/18 06:50:18 UTC

[airflow] branch main updated: Sanitize beeline principal parameter (#31983)

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 6724eeb621 Sanitize beeline principal parameter (#31983)
6724eeb621 is described below

commit 6724eeb6210d5965937eaf9dae3e476eb30f8268
Author: Jarek Potiuk <ja...@potiuk.com>
AuthorDate: Sun Jun 18 08:50:12 2023 +0200

    Sanitize beeline principal parameter (#31983)
    
    Similar to other parameters of Beeline, principal should not
    contain the semicolon.
---
 airflow/providers/apache/hive/hooks/hive.py    |  4 ++--
 tests/providers/apache/hive/hooks/test_hive.py | 11 +++++++++++
 2 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/airflow/providers/apache/hive/hooks/hive.py b/airflow/providers/apache/hive/hooks/hive.py
index fea826a8c3..945e6ba308 100644
--- a/airflow/providers/apache/hive/hooks/hive.py
+++ b/airflow/providers/apache/hive/hooks/hive.py
@@ -150,9 +150,9 @@ class HiveCliHook(BaseHook):
                 template = conn.extra_dejson.get("principal", "hive/_HOST@EXAMPLE.COM")
                 if "_HOST" in template:
                     template = utils.replace_hostname_pattern(utils.get_components(template))
-
                 proxy_user = self._get_proxy_user()
-
+                if ";" in template:
+                    raise RuntimeError("The principal should not contain the ';' character")
                 jdbc_url += f";principal={template};{proxy_user}"
             elif self.auth:
                 jdbc_url += ";auth=" + self.auth
diff --git a/tests/providers/apache/hive/hooks/test_hive.py b/tests/providers/apache/hive/hooks/test_hive.py
index 5c0940d409..9f55e870b7 100644
--- a/tests/providers/apache/hive/hooks/test_hive.py
+++ b/tests/providers/apache/hive/hooks/test_hive.py
@@ -891,3 +891,14 @@ class TestHiveCli:
 
         # Verify
         assert "hive.server2.proxy.user=a_user_proxy" in result[2]
+
+    def test_get_wrong_principal(self):
+        hook = MockHiveCliHook()
+        returner = mock.MagicMock()
+        returner.extra_dejson = {"principal": "principal with ; semicolon"}
+        hook.use_beeline = True
+        hook.conn = returner
+
+        # Run
+        with pytest.raises(RuntimeError, match="The principal should not contain the ';' character"):
+            hook._prepare_cli_cmd()