538
'
539
}
540
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://barbaz@git.example.com'\'':
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://askpass-username@git2.example.com'\'':
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://askpass-username@git2.example.com'\'':
660
+ EOF
661
+ '
662
+}
663
+
664
write_script askpass <<\EOF
665
echo >&2 askpass: $*
666
what=$(echo $1 | cut -d" " -f1 | tr A-Z a-z | tr -cd a-z)