originally any credential found was tried for matching as far as it had a username and password, but that resulted in fatal errors as the rules were harden. now that we have a way to report malformed credentials, use it to notify the user when username/password was missing, instead of just silently skipping. do the same for credentials that are missing host (or had one that is empty) or that are missing a path (for supporting cert://) as well. Signed-off-by: Carlo Marcelo Arenas Belón <carenas@xxxxxxxxx> --- credential-store.c | 7 ++++--- t/t0302-credential-store.sh | 38 +++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 3 deletions(-) diff --git a/credential-store.c b/credential-store.c index 1cc5ca081a..53f77ff6f5 100644 --- a/credential-store.c +++ b/credential-store.c @@ -26,9 +26,10 @@ static int parse_credential_file(const char *fn, while (strbuf_getline_lf(&line, fh) != EOF) { lineno++; - if (!credential_from_url_gently(&entry, line.buf, 1)) { - if (entry.username && entry.password && - credential_match(c, &entry)) { + if (!credential_from_url_gently(&entry, line.buf, 1) && + ((entry.host && *entry.host) || entry.path) && + entry.username && entry.password) { + if (credential_match(c, &entry)) { found_credential = 1; if (match_cb) { match_cb(&entry); diff --git a/t/t0302-credential-store.sh b/t/t0302-credential-store.sh index 801c1eb200..3150f304cb 100755 --- a/t/t0302-credential-store.sh +++ b/t/t0302-credential-store.sh @@ -139,6 +139,44 @@ test_expect_success 'get: credentials without scheme are invalid' ' test_i18ngrep "ignoring invalid credential" stderr ' +test_expect_success 'get: credentials without valid host/path are invalid' ' + echo "https://user:pass@" >"$HOME/.git-credentials" && + cat >expect-stdout <<-\STDOUT && + protocol=https + host=example.com + username=askpass-username + password=askpass-password + STDOUT + test_config credential.helper store && + git credential fill <<-\EOF >stdout 2>stderr && + protocol=https + host=example.com + EOF + test_cmp expect-stdout stdout && + grep "askpass: Username for '\''https://example.com'\'':" stderr && + grep "askpass: Password for '\''https://askpass-username@xxxxxxxxxxx'\'':" stderr && + test_i18ngrep "ignoring invalid credential" stderr +' + +test_expect_success 'get: credentials without username/password are invalid' ' + echo "https://pass@xxxxxxxxxxx" >"$HOME/.git-credentials" && + cat >expect-stdout <<-\STDOUT && + protocol=https + host=example.com + username=askpass-username + password=askpass-password + STDOUT + test_config credential.helper store && + git credential fill <<-\EOF >stdout 2>stderr && + protocol=https + host=example.com + EOF + test_cmp expect-stdout stdout && + grep "askpass: Username for '\''https://example.com'\'':" stderr && + grep "askpass: Password for '\''https://askpass-username@xxxxxxxxxxx'\'':" stderr && + test_i18ngrep "ignoring invalid credential" stderr +' + test_expect_success 'get: store file can contain empty/bogus lines' ' echo "" > "$HOME/.git-credentials" && q_to_tab <<-\CONFIG >>"$HOME/.git-credentials" && -- 2.26.2.569.g1d74ac4d14