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


##########
providers/git/tests/unit/git/hooks/test_git.py:
##########
@@ -781,6 +847,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):
+            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_NO_VERIFY": "true"})

Review Comment:
   Why is this config here and not in the connection?



##########
providers/git/tests/unit/git/hooks/test_git.py:
##########
@@ -24,19 +24,25 @@
 import pathlib
 import shlex
 import socketserver
+import ssl
 import subprocess
 import tempfile
 import threading
 import warnings
-from datetime import UTC
+from datetime import UTC, datetime
 from unittest import mock
 
 import pytest
-from git import Repo
+from cryptography import x509
+from cryptography.hazmat.primitives import hashes, serialization
+from cryptography.hazmat.primitives.asymmetric import ec
+from cryptography.x509.oid import NameOID

Review Comment:
   Move these in to the fixture please. (also is there no nicer interface in 
cryptography to generate a cert then these low level primitives?)



##########
providers/git/src/airflow/providers/git/hooks/git.py:
##########
@@ -28,15 +28,36 @@
 import warnings
 from collections.abc import Generator
 from datetime import UTC, datetime, timedelta
+from functools import cache
 from typing import Any
 from urllib.parse import unquote
 
+from git import Git
+from git.exc import GitError

Review Comment:
   Nothing else appears to use these imports? So move them in to the ver check 
function



-- 
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