Skip to content

Commit 4afec75

Browse files
committed
Merge remote-tracking branch 'jberezanski/wincred-sso-r2'
2 parents f337efa + 44add45 commit 4afec75

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
@@ -48,6 +48,7 @@ helper_test_clean() {
4848
reject $1 https example.com user2
4949
reject $1 http path.tld user
5050
reject $1 https timeout.tld user
51+
reject $1 https sso.tld
5152
}
5253

5354
reject() {
@@ -254,6 +255,24 @@ helper_test() {
254255
password=pass2
255256
EOF
256257
'
258+
259+
test_expect_success "helper ($HELPER) can store empty username" '
260+
check approve $HELPER <<-\EOF &&
261+
protocol=https
262+
host=sso.tld
263+
username=
264+
password=
265+
EOF
266+
check fill $HELPER <<-\EOF
267+
protocol=https
268+
host=sso.tld
269+
--
270+
protocol=https
271+
host=sso.tld
272+
username=
273+
password=
274+
EOF
275+
'
257276
}
258277

259278
helper_test_timeout() {

0 commit comments

Comments
 (0)