ephraimbuddy commented on code in PR #75917:
URL: https://github.com/apache/airflow/pull/75917#discussion_r4481710578


##########
providers/git/tests/unit/git/hooks/test_git.py:
##########
@@ -781,6 +855,76 @@ def 
test_token_credential_env_skipped_for_ssh_transport(self, create_connection_
             assert "GIT_CONFIG_COUNT" not in hook.env
             assert "AIRFLOW_GIT_TOKEN" not in hook.env
 
+    @pytest.mark.parametrize(
+        ("url", "supported", "expected_count", "expected_key"),
+        [
+            pytest.param(AIRFLOW_HTTPS_URL, True, "3", 
f"http.{AIRFLOW_HTTPS_URL}.proactiveAuth", id="https"),
+            pytest.param(AIRFLOW_HTTPS_URL, False, "2", None, 
id="git-older-than-2.46"),
+            pytest.param(AIRFLOW_HTTP_URL, True, "2", None, id="plain-http"),
+        ],
+    )
+    def test_proactive_auth_config(
+        self,
+        url,
+        supported,
+        expected_count,
+        expected_key,
+        proactive_auth_supported,
+        create_connection_without_db,
+    ):
+        proactive_auth_supported.return_value = supported
+        create_connection_without_db(
+            Connection(conn_id="git_proactive_auth", host=url, 
password=ACCESS_TOKEN, conn_type="git")
+        )
+        hook = GitHook(git_conn_id="git_proactive_auth")
+
+        with hook.configure_hook_env():
+            assert hook.env["GIT_CONFIG_COUNT"] == expected_count
+            assert hook.env.get("GIT_CONFIG_KEY_2") == expected_key
+            assert hook.env.get("GIT_CONFIG_VALUE_2") == ("basic" if 
expected_key else None)
+
+    @pytest.mark.skipif(Git().version_info < (2, 46), 
reason="http.proactiveAuth needs git 2.46+")
+    def test_token_reaches_a_public_repository_without_a_challenge(
+        self, proactive_auth_supported, create_connection_without_db, tmp_path
+    ):
+        proactive_auth_supported.return_value = True
+        with recording_public_https_git_server(tmp_path) as (port, received, 
cert_file):
+            url = f"https://127.0.0.1:{port}/repo.git";
+            create_connection_without_db(
+                Connection(
+                    conn_id="git_public_repo",
+                    host=url,
+                    login="token_user",
+                    password=ACCESS_TOKEN,
+                    conn_type="git",
+                )
+            )
+            hook = GitHook(git_conn_id="git_public_repo")
+
+            with hook.configure_hook_env():
+                git_ls_remote(url, {**hook.env, "GIT_SSL_CAINFO": 
str(cert_file)})
+
+        assert set(received) == {f"token_user:{ACCESS_TOKEN}"}
+
+    @pytest.mark.parametrize(
+        ("version_info", "side_effect", "expected"),
+        [
+            pytest.param((2, 46, 0), None, True, id="2.46"),
+            pytest.param((2, 51, 2), None, True, id="2.51"),
+            pytest.param((2, 45, 4), None, False, id="2.45"),
+            pytest.param((), GitCommandNotFound("git", "not found"), False, 
id="unknown"),

Review Comment:
   Thanks, this addresses everything. Two small follow-ups inline.



##########
providers/git/src/airflow/providers/git/hooks/git.py:
##########
@@ -128,6 +129,7 @@ def __init__(
         embedded_user, embedded_token = self._strip_embedded_credentials()
         self.user_name = connection.login or embedded_user or "user"
         self.auth_token = connection.password or embedded_token
+        self.proactive_auth = extra.get("proactive_auth") is True

Review Comment:
   URI-form extras are strings, so `?proactive_auth=true` is silently ignored. 
Accept `"true"` or raise on non-bool? Also worth adding to the UI placeholders.



##########
providers/git/src/airflow/providers/git/hooks/git.py:
##########
@@ -332,18 +334,24 @@ def _token_credential_env(self) -> Generator[None]:
             # `credential.helper` would otherwise answer `get` first and our 
token would never
             # be used. git also invokes every helper on `approve`, so a 
`store` helper would
             # persist it to ~/.git-credentials. Reset the scope to empty first 
(git help credentials).
+            config = [
+                (f"credential.{scope}.helper", ""),
+                # git runs the value through a shell. The ! marks it as a 
command and preserves quoting.

Review Comment:
   Nit: please keep the original comment; it said why quoting matters (spaces 
in the temp path).



##########
providers/git/docs/changelog.rst:
##########
@@ -19,6 +19,12 @@
 Changelog
 ---------
 
+.. warning::

Review Comment:
   Now that it's opt-in, this isn't breaking. I'd drop it (my earlier ask, 
sorry).



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to