Skip to content
This repository was archived by the owner on Nov 9, 2017. It is now read-only.

Commit a9586f2

Browse files
committed
Merge 'jberezanski/wincred-sso-r2' into HEAD
2 parents b186a66 + 52ab6cb commit a9586f2

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

contrib/credential/wincred/git-credential-wincred.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,12 @@ static WCHAR *wusername, *password, *protocol, *host, *path, target[1024];
9494
static void write_item(const char *what, LPCWSTR wbuf, int wlen)
9595
{
9696
char *buf;
97+
98+
if (!wbuf || !wlen) {
99+
printf("%s=\n", what);
100+
return;
101+
}
102+
97103
int len = WideCharToMultiByte(CP_UTF8, 0, wbuf, wlen, NULL, 0, NULL,
98104
FALSE);
99105
buf = xmalloc(len);
@@ -141,7 +147,7 @@ static int match_part(LPCWSTR *ptarget, LPCWSTR want, LPCWSTR delim)
141147
static int match_cred(const CREDENTIALW *cred)
142148
{
143149
LPCWSTR target = cred->TargetName;
144-
if (wusername && wcscmp(wusername, cred->UserName))
150+
if (wusername && wcscmp(wusername, cred->UserName ? cred->UserName : L""))
145151
return 0;
146152

147153
return match_part(&target, L"git", L":") &&
@@ -164,7 +170,7 @@ static void get_credential(void)
164170
for (i = 0; i < num_creds; ++i)
165171
if (match_cred(creds[i])) {
166172
write_item("username", creds[i]->UserName,
167-
wcslen(creds[i]->UserName));
173+
creds[i]->UserName ? wcslen(creds[i]->UserName) : 0);
168174
write_item("password",
169175
(LPCWSTR)creds[i]->CredentialBlob,
170176
creds[i]->CredentialBlobSize / sizeof(WCHAR));

t/lib-credential.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ helper_test_clean() {
4444
reject $1 https example.com user2
4545
reject $1 http path.tld user
4646
reject $1 https timeout.tld user
47+
reject $1 https sso.tld
4748
}
4849

4950
reject() {
@@ -250,6 +251,24 @@ helper_test() {
250251
password=pass2
251252
EOF
252253
'
254+
255+
test_expect_success "helper ($HELPER) can store empty username" '
256+
check approve $HELPER <<-\EOF &&
257+
protocol=https
258+
host=sso.tld
259+
username=
260+
password=
261+
EOF
262+
check fill $HELPER <<-\EOF
263+
protocol=https
264+
host=sso.tld
265+
--
266+
protocol=https
267+
host=sso.tld
268+
username=
269+
password=
270+
EOF
271+
'
253272
}
254273

255274
helper_test_timeout() {

0 commit comments

Comments
 (0)