diff mbox series

[RFC,2/5] fetch+push tests: add missing coverage for 6dcbdc0d661

Message ID RFC-patch-2.5-38af32c5b96-20220615T104503Z-avarab@gmail.com (mailing list archive)
State New, archived
Headers show
Series fix issues in transfer.credentialsInUrl | expand

Commit Message

Ævar Arnfjörð Bjarmason June 15, 2022, 10:53 a.m. UTC
Add tests that were missing from 6dcbdc0d661 (remote: create
fetch.credentialsInUrl config, 2022-06-06), we want to test how we
handle cases where the config comes from a file, and that we handle
"pushURL" correctly.

Currently the "pushURL" case isn't handled at all, i.e. URLs aren't
warned about in "remote.*pushurl" , only for "remote.*.url".

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 t/t5516-fetch-push.sh | 41 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 41 insertions(+)

Comments

Derrick Stolee June 15, 2022, 12:39 p.m. UTC | #1
On 6/15/22 6:53 AM, Ævar Arnfjörð Bjarmason wrote:
> Add tests that were missing from 6dcbdc0d661 (remote: create
> fetch.credentialsInUrl config, 2022-06-06), we want to test how we
> handle cases where the config comes from a file, and that we handle
> "pushURL" correctly.

The tests use your renamed transfer.credentialsInUrl, but you haven't
renamed at this point.

> Currently the "pushURL" case isn't handled at all, i.e. URLs aren't
> warned about in "remote.*pushurl" , only for "remote.*.url".

Good find. I suppose that the second test_expect_success will _fail_
at the point of this patch?

Thanks,
-Stolee
diff mbox series

Patch

diff --git a/t/t5516-fetch-push.sh b/t/t5516-fetch-push.sh
index 4b32ae39a39..51d695e475a 100755
--- a/t/t5516-fetch-push.sh
+++ b/t/t5516-fetch-push.sh
@@ -1852,6 +1852,26 @@  test_expect_success 'fetch warns or fails when using username:password' '
 	test_line_count = 1 warnings
 '
 
+test_expect_success CURL 'fetch warns or fails when using username:password in config' '
+	message="URL '\''https://username:<redacted>@localhost/'\'' uses plaintext credentials" &&
+
+	test_when_finished "rm -rf repo" &&
+	git init repo &&
+	test_commit -C repo A &&
+	git -C repo remote add pwd-url https://username:password@localhost &&
+	test_must_fail git -C repo -c transfer.credentialsInUrl=allow fetch pwd-url 2>err &&
+	! grep "$message" err &&
+
+	test_must_fail git -C repo -c transfer.credentialsInUrl=warn fetch pwd-url 2>err &&
+	grep "warning: $message" err >warnings &&
+	test_line_count = 3 warnings &&
+
+	git -C repo remote set-url --push pwd-url https://username:password@localhost &&
+	git -C repo remote set-url pwd-url https://localhost &&
+
+	test_must_fail git -C repo -c transfer.credentialsInUrl=warn fetch pwd-url 2>err &&
+	! grep "fatal: $message" err
+'
 
 test_expect_success 'push warns or fails when using username:password' '
 	message="URL '\''https://username:<redacted>@localhost/'\'' uses plaintext credentials" &&
@@ -1867,4 +1887,25 @@  test_expect_success 'push warns or fails when using username:password' '
 	test_line_count = 1 warnings
 '
 
+test_expect_success CURL 'push warns or fails when using username:password in config' '
+	message="URL '\''https://username:<redacted>@localhost/'\'' uses plaintext credentials" &&
+
+	test_when_finished "rm -rf repo" &&
+	git init repo &&
+	test_commit -C repo A &&
+	git -C repo remote add pwd-url https://username:password@localhost &&
+	test_must_fail git -C repo -c transfer.credentialsInUrl=allow push pwd-url HEAD:refs/heads/branch 2>err &&
+	! grep "$message" err &&
+
+	test_must_fail git -C repo -c transfer.credentialsInUrl=warn push pwd-url HEAD:refs/heads/branch 2>err &&
+	grep "warning: $message" err >warnings &&
+	test_line_count = 2 warnings &&
+
+	git -C repo remote set-url --push pwd-url https://username:password@localhost &&
+	git -C repo remote set-url pwd-url https://localhost &&
+
+	test_must_fail git -C repo -c transfer.credentialsInUrl=warn push pwd-url HEAD:refs/heads/branch 2>err &&
+	! grep "warning: $message" err
+'
+
 test_done