]> git.ipfire.org Git - thirdparty/git.git/blobdiff - t/lib-credential.sh
t: add credential tests for authtype
[thirdparty/git.git] / t / lib-credential.sh
index 44799c0d38fdb35d1c56a3e9ac8d91a963d2ee1c..58b9c7406058904838832d35719478797a01d1ee 100644 (file)
@@ -538,6 +538,129 @@ helper_test_oauth_refresh_token() {
        '
 }
 
+helper_test_authtype() {
+       HELPER=$1
+
+       test_expect_success "helper ($HELPER) stores authtype and credential" '
+               check approve $HELPER <<-\EOF
+               capability[]=authtype
+               authtype=Bearer
+               credential=random-token
+               protocol=https
+               host=git.example.com
+               EOF
+       '
+
+       test_expect_success "helper ($HELPER) gets authtype and credential" '
+               check fill $HELPER <<-\EOF
+               capability[]=authtype
+               protocol=https
+               host=git.example.com
+               --
+               capability[]=authtype
+               authtype=Bearer
+               credential=random-token
+               protocol=https
+               host=git.example.com
+               --
+               EOF
+       '
+
+       test_expect_success "helper ($HELPER) stores authtype and credential with username" '
+               check approve $HELPER <<-\EOF
+               capability[]=authtype
+               authtype=Bearer
+               credential=other-token
+               protocol=https
+               host=git.example.com
+               username=foobar
+               EOF
+       '
+
+       test_expect_success "helper ($HELPER) gets authtype and credential with username" '
+               check fill $HELPER <<-\EOF
+               capability[]=authtype
+               protocol=https
+               host=git.example.com
+               username=foobar
+               --
+               capability[]=authtype
+               authtype=Bearer
+               credential=other-token
+               protocol=https
+               host=git.example.com
+               username=foobar
+               --
+               EOF
+       '
+
+       test_expect_success "helper ($HELPER) does not get authtype and credential with different username" '
+               check fill $HELPER <<-\EOF
+               capability[]=authtype
+               protocol=https
+               host=git.example.com
+               username=barbaz
+               --
+               protocol=https
+               host=git.example.com
+               username=barbaz
+               password=askpass-password
+               --
+               askpass: Password for '\''https://barbaz@git.example.com'\'':
+               EOF
+       '
+
+       test_expect_success "helper ($HELPER) does not store ephemeral authtype and credential" '
+               check approve $HELPER <<-\EOF &&
+               capability[]=authtype
+               authtype=Bearer
+               credential=git2-token
+               protocol=https
+               host=git2.example.com
+               ephemeral=1
+               EOF
+
+               check fill $HELPER <<-\EOF
+               capability[]=authtype
+               protocol=https
+               host=git2.example.com
+               --
+               protocol=https
+               host=git2.example.com
+               username=askpass-username
+               password=askpass-password
+               --
+               askpass: Username for '\''https://git2.example.com'\'':
+               askpass: Password for '\''https://askpass-username@git2.example.com'\'':
+               EOF
+       '
+
+       test_expect_success "helper ($HELPER) does not store ephemeral username and password" '
+               check approve $HELPER <<-\EOF &&
+               capability[]=authtype
+               protocol=https
+               host=git2.example.com
+               user=barbaz
+               password=secret
+               ephemeral=1
+               EOF
+
+               check fill $HELPER <<-\EOF
+               capability[]=authtype
+               protocol=https
+               host=git2.example.com
+               --
+               protocol=https
+               host=git2.example.com
+               username=askpass-username
+               password=askpass-password
+               --
+               askpass: Username for '\''https://git2.example.com'\'':
+               askpass: Password for '\''https://askpass-username@git2.example.com'\'':
+               EOF
+       '
+}
+
 write_script askpass <<\EOF
 echo >&2 askpass: $*
 what=$(echo $1 | cut -d" " -f1 | tr A-Z a-z | tr -cd a-z)