Skip to content

Commit f40199f

Browse files
hickforddscho
authored andcommitted
credential-cache: respect authtype capability
Previously, credential-cache populated authtype regardless whether "get" request had authtype capability. As documented in git-credential.txt, authtype "should not be sent unless the appropriate capability ... is provided". Add test. Without this change, the test failed because "credential fill" printed an incomplete credential with only protocol and host attributes (the unexpected authtype attribute was discarded by credential.c). Signed-off-by: M Hickford <mirth.hickford@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 5cc2d6c commit f40199f

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

Diff for: builtin/credential-cache--daemon.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,9 @@ static void serve_one_client(FILE *in, FILE *out)
142142
fprintf(out, "username=%s\n", e->item.username);
143143
if (e->item.password)
144144
fprintf(out, "password=%s\n", e->item.password);
145-
if (credential_has_capability(&c.capa_authtype, CREDENTIAL_OP_HELPER) && e->item.authtype)
145+
if (credential_has_capability(&c.capa_authtype, CREDENTIAL_OP_RESPONSE) && e->item.authtype)
146146
fprintf(out, "authtype=%s\n", e->item.authtype);
147-
if (credential_has_capability(&c.capa_authtype, CREDENTIAL_OP_HELPER) && e->item.credential)
147+
if (credential_has_capability(&c.capa_authtype, CREDENTIAL_OP_RESPONSE) && e->item.credential)
148148
fprintf(out, "credential=%s\n", e->item.credential);
149149
if (e->item.password_expiry_utc != TIME_MAX)
150150
fprintf(out, "password_expiry_utc=%"PRItime"\n",

Diff for: t/lib-credential.sh

+15
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,21 @@ helper_test_authtype() {
566566
EOF
567567
'
568568

569+
test_expect_success "helper ($HELPER) gets authtype and credential only if request has authtype capability" '
570+
check fill $HELPER <<-\EOF
571+
protocol=https
572+
host=git.example.com
573+
--
574+
protocol=https
575+
host=git.example.com
576+
username=askpass-username
577+
password=askpass-password
578+
--
579+
askpass: Username for '\''https://git.example.com'\'':
580+
askpass: Password for '\''https://askpass-username@git.example.com'\'':
581+
EOF
582+
'
583+
569584
test_expect_success "helper ($HELPER) stores authtype and credential with username" '
570585
check approve $HELPER <<-\EOF
571586
capability[]=authtype

0 commit comments

Comments
 (0)