Skip to content

Commit 30c0a30

Browse files
bk2204gitster
authored andcommitted
t: add credential tests for authtype
It's helpful to have some basic tests for credential helpers supporting the authtype and credential fields. Let's add some tests for this case so that we can make sure newly supported helpers work correctly. Note that we explicitly check that credential helpers can produce different sets of authtype and credential values based on the username. While the username is not used in the HTTP protocol with authtype and credential, it can still be specified in the URL and thus may be part of the protocol. Additionally, because it is common for users to have multiple accounts on one service (say, both personal and professional accounts), it's very helpful to be able to store different credentials for different accounts in the same helper, and that doesn't become less useful if one is using, say, Bearer authentication instead of Basic. Thus, credential helpers should be expected to support this functionality as basic functionality, so verify here that they do so. Signed-off-by: brian m. carlson <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent ac4c7cb commit 30c0a30

File tree

1 file changed

+123
-0
lines changed

1 file changed

+123
-0
lines changed

t/lib-credential.sh

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,129 @@ helper_test_oauth_refresh_token() {
538538
'
539539
}
540540

541+
helper_test_authtype() {
542+
HELPER=$1
543+
544+
test_expect_success "helper ($HELPER) stores authtype and credential" '
545+
check approve $HELPER <<-\EOF
546+
capability[]=authtype
547+
authtype=Bearer
548+
credential=random-token
549+
protocol=https
550+
host=git.example.com
551+
EOF
552+
'
553+
554+
test_expect_success "helper ($HELPER) gets authtype and credential" '
555+
check fill $HELPER <<-\EOF
556+
capability[]=authtype
557+
protocol=https
558+
host=git.example.com
559+
--
560+
capability[]=authtype
561+
authtype=Bearer
562+
credential=random-token
563+
protocol=https
564+
host=git.example.com
565+
--
566+
EOF
567+
'
568+
569+
test_expect_success "helper ($HELPER) stores authtype and credential with username" '
570+
check approve $HELPER <<-\EOF
571+
capability[]=authtype
572+
authtype=Bearer
573+
credential=other-token
574+
protocol=https
575+
host=git.example.com
576+
username=foobar
577+
EOF
578+
'
579+
580+
test_expect_success "helper ($HELPER) gets authtype and credential with username" '
581+
check fill $HELPER <<-\EOF
582+
capability[]=authtype
583+
protocol=https
584+
host=git.example.com
585+
username=foobar
586+
--
587+
capability[]=authtype
588+
authtype=Bearer
589+
credential=other-token
590+
protocol=https
591+
host=git.example.com
592+
username=foobar
593+
--
594+
EOF
595+
'
596+
597+
test_expect_success "helper ($HELPER) does not get authtype and credential with different username" '
598+
check fill $HELPER <<-\EOF
599+
capability[]=authtype
600+
protocol=https
601+
host=git.example.com
602+
username=barbaz
603+
--
604+
protocol=https
605+
host=git.example.com
606+
username=barbaz
607+
password=askpass-password
608+
--
609+
askpass: Password for '\''https://[email protected]'\'':
610+
EOF
611+
'
612+
613+
test_expect_success "helper ($HELPER) does not store ephemeral authtype and credential" '
614+
check approve $HELPER <<-\EOF &&
615+
capability[]=authtype
616+
authtype=Bearer
617+
credential=git2-token
618+
protocol=https
619+
host=git2.example.com
620+
ephemeral=1
621+
EOF
622+
623+
check fill $HELPER <<-\EOF
624+
capability[]=authtype
625+
protocol=https
626+
host=git2.example.com
627+
--
628+
protocol=https
629+
host=git2.example.com
630+
username=askpass-username
631+
password=askpass-password
632+
--
633+
askpass: Username for '\''https://git2.example.com'\'':
634+
askpass: Password for '\''https://[email protected]'\'':
635+
EOF
636+
'
637+
638+
test_expect_success "helper ($HELPER) does not store ephemeral username and password" '
639+
check approve $HELPER <<-\EOF &&
640+
capability[]=authtype
641+
protocol=https
642+
host=git2.example.com
643+
user=barbaz
644+
password=secret
645+
ephemeral=1
646+
EOF
647+
648+
check fill $HELPER <<-\EOF
649+
capability[]=authtype
650+
protocol=https
651+
host=git2.example.com
652+
--
653+
protocol=https
654+
host=git2.example.com
655+
username=askpass-username
656+
password=askpass-password
657+
--
658+
askpass: Username for '\''https://git2.example.com'\'':
659+
askpass: Password for '\''https://[email protected]'\'':
660+
EOF
661+
'
662+
}
663+
541664
write_script askpass <<\EOF
542665
echo >&2 askpass: $*
543666
what=$(echo $1 | cut -d" " -f1 | tr A-Z a-z | tr -cd a-z)

0 commit comments

Comments
 (0)