This is an automated email from the ASF dual-hosted git repository.
kaxilnaik 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 513bba7a659 Don't add auth token to git bundle view urls (#48516)
513bba7a659 is described below
commit 513bba7a6595cac9d47074a784c0b71d5414cb11
Author: Jed Cunningham <[email protected]>
AuthorDate: Sat Mar 29 02:36:52 2025 -0600
Don't add auth token to git bundle view urls (#48516)
We definitely do not want to show auth tokens in the view urls generated
by the git bundle. We strip them if they are present now.
---
.../git/src/airflow/providers/git/bundles/git.py | 5 +++
providers/git/tests/unit/git/bundles/test_git.py | 48 +++++++++++++++++-----
2 files changed, 43 insertions(+), 10 deletions(-)
diff --git a/providers/git/src/airflow/providers/git/bundles/git.py
b/providers/git/src/airflow/providers/git/bundles/git.py
index 2a337796b1b..0c24a4664be 100644
--- a/providers/git/src/airflow/providers/git/bundles/git.py
+++ b/providers/git/src/airflow/providers/git/bundles/git.py
@@ -223,6 +223,11 @@ class GitDagBundle(BaseDagBundle):
host = parsed_url.hostname
if not host:
return None
+ if parsed_url.username or parsed_url.password:
+ new_netloc = host
+ if parsed_url.port:
+ new_netloc += f":{parsed_url.port}"
+ url = parsed_url._replace(netloc=new_netloc).geturl()
host_patterns = {
"github.com": f"{url}/tree/{version}",
"gitlab.com": f"{url}/-/tree/{version}",
diff --git a/providers/git/tests/unit/git/bundles/test_git.py
b/providers/git/tests/unit/git/bundles/test_git.py
index 5113ffa0882..553cffa0f91 100644
--- a/providers/git/tests/unit/git/bundles/test_git.py
+++ b/providers/git/tests/unit/git/bundles/test_git.py
@@ -357,33 +357,61 @@ class TestGitDagBundle:
assert mock_gitRepo.return_value.remotes.origin.fetch.call_count == 2
@pytest.mark.parametrize(
- "repo_url, expected_url",
+ "repo_url, extra_conn_kwargs, expected_url",
[
- ("[email protected]:apache/airflow.git",
"https://github.com/apache/airflow/tree/0f0f0f"),
- ("[email protected]:apache/airflow",
"https://github.com/apache/airflow/tree/0f0f0f"),
- ("https://github.com/apache/airflow",
"https://github.com/apache/airflow/tree/0f0f0f"),
- ("https://github.com/apache/airflow.git",
"https://github.com/apache/airflow/tree/0f0f0f"),
- ("[email protected]:apache/airflow.git",
"https://gitlab.com/apache/airflow/-/tree/0f0f0f"),
- ("[email protected]:apache/airflow.git",
"https://bitbucket.org/apache/airflow/src/0f0f0f"),
+ ("[email protected]:apache/airflow.git", None,
"https://github.com/apache/airflow/tree/0f0f0f"),
+ ("[email protected]:apache/airflow", None,
"https://github.com/apache/airflow/tree/0f0f0f"),
+ ("https://github.com/apache/airflow", None,
"https://github.com/apache/airflow/tree/0f0f0f"),
+ ("https://github.com/apache/airflow.git", None,
"https://github.com/apache/airflow/tree/0f0f0f"),
+ ("[email protected]:apache/airflow.git", None,
"https://gitlab.com/apache/airflow/-/tree/0f0f0f"),
+ ("[email protected]:apache/airflow.git", None,
"https://bitbucket.org/apache/airflow/src/0f0f0f"),
(
"[email protected]:apache/airflow.git",
+ None,
"https://myorg.github.com/apache/airflow/tree/0f0f0f",
),
(
"https://myorg.github.com/apache/airflow.git",
+ None,
"https://myorg.github.com/apache/airflow/tree/0f0f0f",
),
- ("/dev/null", None),
- ("file:///dev/null", None),
+ ("/dev/null", None, None),
+ ("file:///dev/null", None, None),
+ (
+ "https://github.com/apache/airflow",
+ {"password": "abc123"},
+ "https://github.com/apache/airflow/tree/0f0f0f",
+ ),
+ (
+ "https://github.com/apache/airflow",
+ {"login": "abc123"},
+ "https://github.com/apache/airflow/tree/0f0f0f",
+ ),
+ (
+ "https://github.com/apache/airflow",
+ {"login": "abc123", "password": "def456"},
+ "https://github.com/apache/airflow/tree/0f0f0f",
+ ),
+ (
+ "https://github.com:443/apache/airflow",
+ None,
+ "https://github.com:443/apache/airflow/tree/0f0f0f",
+ ),
+ (
+ "https://github.com:443/apache/airflow",
+ {"password": "abc123"},
+ "https://github.com:443/apache/airflow/tree/0f0f0f",
+ ),
],
)
@mock.patch("airflow.providers.git.bundles.git.Repo")
- def test_view_url(self, mock_gitrepo, repo_url, expected_url, session):
+ def test_view_url(self, mock_gitrepo, repo_url, extra_conn_kwargs,
expected_url, session):
session.query(Connection).delete()
conn = Connection(
conn_id="git_default",
host=repo_url,
conn_type="git",
+ **(extra_conn_kwargs or {}),
)
session.add(conn)
session.commit()