From: Jeff King <peff@peff.net>
To: git@vger.kernel.org
Subject: [PATCHv2 07/13] credential: add credential.*.username
Date: Tue, 6 Dec 2011 01:22:50 -0500 [thread overview]
Message-ID: <20111206062250.GG29233@sigill.intra.peff.net> (raw)
In-Reply-To: <20111206062127.GA29046@sigill.intra.peff.net>
Credential helpers can help users avoid having to type their
username and password over and over. However, some users may
not want a helper for their password, or they may be running
a helper which caches for a short time. In this case, it is
convenient to provide the non-secret username portion of
their credential via config.
Signed-off-by: Jeff King <peff@peff.net>
---
credential.c | 4 ++++
t/t0300-credentials.sh | 13 +++++++++++++
t/t5550-http-fetch.sh | 16 ++++++++++++++++
3 files changed, 33 insertions(+), 0 deletions(-)
diff --git a/credential.c b/credential.c
index 96be1c2..3c17ea1 100644
--- a/credential.c
+++ b/credential.c
@@ -65,6 +65,10 @@ static int credential_config_callback(const char *var, const char *value,
if (!strcmp(key, "helper"))
string_list_append(&c->helpers, value);
+ else if (!strcmp(key, "username")) {
+ if (!c->username)
+ c->username = xstrdup(value);
+ }
return 0;
}
diff --git a/t/t0300-credentials.sh b/t/t0300-credentials.sh
index e3f61f4..57751a1 100755
--- a/t/t0300-credentials.sh
+++ b/t/t0300-credentials.sh
@@ -234,4 +234,17 @@ test_expect_success 'do not match configured credential' '
EOF
'
+test_expect_success 'pull username from config' '
+ test_config credential.https://example.com.username foo &&
+ check fill <<-\EOF
+ protocol=https
+ host=example.com
+ --
+ username=foo
+ password=askpass-password
+ --
+ askpass: Password for '\''https://foo@example.com'\'':
+ EOF
+'
+
test_done
diff --git a/t/t5550-http-fetch.sh b/t/t5550-http-fetch.sh
index 21e2f5d..18f4d59 100755
--- a/t/t5550-http-fetch.sh
+++ b/t/t5550-http-fetch.sh
@@ -113,6 +113,22 @@ test_expect_success 'http auth respects credential helper config' '
expect_askpass none
'
+test_expect_success 'http auth can get username from config' '
+ test_config_global "credential.$HTTPD_URL.username" user@host &&
+ >askpass-query &&
+ echo user@host >askpass-response &&
+ git clone "$HTTPD_URL/auth/repo.git" clone-auth-user &&
+ expect_askpass pass user@host
+'
+
+test_expect_success 'configured username does not override URL' '
+ test_config_global "credential.$HTTPD_URL.username" wrong &&
+ >askpass-query &&
+ echo user@host >askpass-response &&
+ git clone "$HTTPD_URL_USER/auth/repo.git" clone-auth-user2 &&
+ expect_askpass pass user@host
+'
+
test_expect_success 'fetch changes via http' '
echo content >>file &&
git commit -a -m two &&
--
1.7.8.rc4.4.g884ec
next prev parent reply other threads:[~2011-12-06 6:23 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-12-06 6:21 [PATCHv2 0/13] credential helpers Jeff King
2011-12-06 6:22 ` [PATCHv2 01/13] test-lib: add test_config_global variant Jeff King
2011-12-06 6:22 ` [PATCHv2 02/13] t5550: fix typo Jeff King
2011-12-06 6:22 ` [PATCHv2 03/13] introduce credentials API Jeff King
2011-12-06 6:22 ` [PATCHv2 04/13] credential: add function for parsing url components Jeff King
2011-12-06 6:22 ` [PATCHv2 05/13] http: use credential API to get passwords Jeff King
2011-12-06 6:22 ` [PATCHv2 06/13] credential: apply helper config Jeff King
2011-12-06 23:58 ` Junio C Hamano
2011-12-07 0:45 ` Jeff King
2011-12-07 0:49 ` Jeff King
2011-12-06 6:22 ` Jeff King [this message]
2011-12-06 6:22 ` [PATCHv2 08/13] credential: make relevance of http path configurable Jeff King
2011-12-06 6:22 ` [PATCHv2 09/13] docs: end-user documentation for the credential subsystem Jeff King
2011-12-06 6:22 ` [PATCHv2 10/13] credentials: add "cache" helper Jeff King
2011-12-06 6:23 ` [PATCHv2 11/13] strbuf: add strbuf_add*_urlencode Jeff King
2011-12-06 6:23 ` [PATCHv2 12/13] credentials: add "store" helper Jeff King
2011-12-06 21:50 ` Junio C Hamano
2011-12-09 23:19 ` Jeff King
2011-12-06 6:23 ` [PATCHv2 13/13] t: add test harness for external credential helpers Jeff King
2011-12-06 21:51 ` Junio C Hamano
2011-12-06 22:08 ` Jeff King
2011-12-06 21:40 ` [PATCHv2 0/13] " Junio C Hamano
2011-12-07 6:42 ` Jeff King
2011-12-08 21:34 ` Junio C Hamano
2011-12-09 2:29 ` Jeff King
2011-12-09 18:00 ` Junio C Hamano
2011-12-09 23:18 ` Jeff King
2011-12-09 23:34 ` Junio C Hamano
2011-12-09 23:39 ` Jeff King
2011-12-09 23:56 ` Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20111206062250.GG29233@sigill.intra.peff.net \
--to=peff@peff.net \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).