Skip to content

Commit 2c79396

Browse files
committed
t5516/t5601: avoid using localhost for failing HTTPS requests
In 6dcbdc0 (remote: create fetch.credentialsInUrl config, 2022-06-06), we added four test cases that validate various behavior around passing credentials as part of the URL (which is considered unsafe in general). These tests do not _actually_ try to connect anywhere, but have to use the https:// protocol in order to validate the intended code paths. However, using `localhost` for such a connection causes several problems: - There might be a web server running on localhost, and we do not actually want to connect to that. - The DNS resolver, or the local firewall, might take a substantial amount of time (or forever, whichever comes first) to fail to connect, slowing down the test cases unnecessarily. Let's instead use an IPv4 address that is guaranteed never to offer a web server: 224.0.0.1 (which is part of the IP multicast range). Incidentally, this seems to fix an issue where the tests fail in the Windows jobs of Git's CI builds. Signed-off-by: Johannes Schindelin <[email protected]>
1 parent c404d30 commit 2c79396

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

t/t5516-fetch-push.sh

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1854,32 +1854,32 @@ test_expect_success 'refuse to push a hidden ref, and make sure do not pollute t
18541854
'
18551855

18561856
test_expect_success LIBCURL 'fetch warns or fails when using username:password' '
1857-
message="URL '\''https://username:<redacted>@localhost/'\'' uses plaintext credentials" &&
1858-
test_must_fail git -c transfer.credentialsInUrl=allow fetch https://username:password@localhost 2>err &&
1857+
message="URL '\''https://username:<redacted>@224.0.0.1/'\'' uses plaintext credentials" &&
1858+
test_must_fail git -c transfer.credentialsInUrl=allow fetch https://username:password@224.0.0.1 2>err &&
18591859
! grep "$message" err &&
18601860
1861-
test_must_fail git -c transfer.credentialsInUrl=warn fetch https://username:password@localhost 2>err &&
1861+
test_must_fail git -c transfer.credentialsInUrl=warn fetch https://username:password@224.0.0.1 2>err &&
18621862
grep "warning: $message" err >warnings &&
18631863
test_line_count = 3 warnings &&
18641864
1865-
test_must_fail git -c transfer.credentialsInUrl=die fetch https://username:password@localhost 2>err &&
1865+
test_must_fail git -c transfer.credentialsInUrl=die fetch https://username:password@224.0.0.1 2>err &&
18661866
grep "fatal: $message" err >warnings &&
18671867
test_line_count = 1 warnings &&
18681868
1869-
test_must_fail git -c transfer.credentialsInUrl=die fetch https://username:@localhost 2>err &&
1869+
test_must_fail git -c transfer.credentialsInUrl=die fetch https://username:@224.0.0.1 2>err &&
18701870
grep "fatal: $message" err >warnings &&
18711871
test_line_count = 1 warnings
18721872
'
18731873

18741874

18751875
test_expect_success LIBCURL 'push warns or fails when using username:password' '
1876-
message="URL '\''https://username:<redacted>@localhost/'\'' uses plaintext credentials" &&
1877-
test_must_fail git -c transfer.credentialsInUrl=allow push https://username:password@localhost 2>err &&
1876+
message="URL '\''https://username:<redacted>@224.0.0.1/'\'' uses plaintext credentials" &&
1877+
test_must_fail git -c transfer.credentialsInUrl=allow push https://username:password@224.0.0.1 2>err &&
18781878
! grep "$message" err &&
18791879
1880-
test_must_fail git -c transfer.credentialsInUrl=warn push https://username:password@localhost 2>err &&
1880+
test_must_fail git -c transfer.credentialsInUrl=warn push https://username:password@224.0.0.1 2>err &&
18811881
grep "warning: $message" err >warnings &&
1882-
test_must_fail git -c transfer.credentialsInUrl=die push https://username:password@localhost 2>err &&
1882+
test_must_fail git -c transfer.credentialsInUrl=die push https://username:password@224.0.0.1 2>err &&
18831883
grep "fatal: $message" err >warnings &&
18841884
test_line_count = 1 warnings
18851885
'

t/t5601-clone.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,19 +72,19 @@ test_expect_success 'clone respects GIT_WORK_TREE' '
7272
'
7373

7474
test_expect_success LIBCURL 'clone warns or fails when using username:password' '
75-
message="URL '\''https://username:<redacted>@localhost/'\'' uses plaintext credentials" &&
76-
test_must_fail git -c transfer.credentialsInUrl=allow clone https://username:password@localhost attempt1 2>err &&
75+
message="URL '\''https://username:<redacted>@224.0.0.1/'\'' uses plaintext credentials" &&
76+
test_must_fail git -c transfer.credentialsInUrl=allow clone https://username:password@224.0.0.1 attempt1 2>err &&
7777
! grep "$message" err &&
7878
79-
test_must_fail git -c transfer.credentialsInUrl=warn clone https://username:password@localhost attempt2 2>err &&
79+
test_must_fail git -c transfer.credentialsInUrl=warn clone https://username:password@224.0.0.1 attempt2 2>err &&
8080
grep "warning: $message" err >warnings &&
8181
test_line_count = 2 warnings &&
8282
83-
test_must_fail git -c transfer.credentialsInUrl=die clone https://username:password@localhost attempt3 2>err &&
83+
test_must_fail git -c transfer.credentialsInUrl=die clone https://username:password@224.0.0.1 attempt3 2>err &&
8484
grep "fatal: $message" err >warnings &&
8585
test_line_count = 1 warnings &&
8686
87-
test_must_fail git -c transfer.credentialsInUrl=die clone https://username:@localhost attempt3 2>err &&
87+
test_must_fail git -c transfer.credentialsInUrl=die clone https://username:@224.0.0.1 attempt3 2>err &&
8888
grep "fatal: $message" err >warnings &&
8989
test_line_count = 1 warnings
9090
'

0 commit comments

Comments
 (0)