Skip to content

Commit

Permalink
Sanitize beeline principal parameter (#31983)
Browse files Browse the repository at this point in the history
Similar to other parameters of Beeline, principal should not
contain the semicolon.
  • Loading branch information
potiuk committed Jun 18, 2023
1 parent a298874 commit 6724eeb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
4 changes: 2 additions & 2 deletions airflow/providers/apache/hive/hooks/hive.py
Expand Up @@ -150,9 +150,9 @@ def _prepare_cli_cmd(self) -> list[Any]:
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
Expand Down
11 changes: 11 additions & 0 deletions tests/providers/apache/hive/hooks/test_hive.py
Expand Up @@ -891,3 +891,14 @@ def test_get_proxy_user_value(self):

# 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()

0 comments on commit 6724eeb

Please sign in to comment.