@@ -41,7 +41,7 @@ type tokResp struct {
41
41
42
42
func TestDefaultCredentials_GdchServiceAccountKey (t * testing.T ) {
43
43
ctx := context .Background ()
44
- aud := "http://sampele -aud.com/"
44
+ aud := "http://sample -aud.com/"
45
45
b , err := os .ReadFile ("../internal/testdata/gdch.json" )
46
46
if err != nil {
47
47
t .Fatal (err )
@@ -285,7 +285,7 @@ func TestDefaultCredentials_UserCredentialsKey_UniverseDomain(t *testing.T) {
285
285
if err != nil {
286
286
t .Fatal (err )
287
287
}
288
- if want := "googleapis .com" ; got != want {
288
+ if want := "example .com" ; got != want {
289
289
t .Fatalf ("got %q, want %q" , got , want )
290
290
}
291
291
tok , err := creds .Token (context .Background ())
@@ -728,6 +728,39 @@ func TestDefaultCredentials_UniverseDomain(t *testing.T) {
728
728
opts * DetectOptions
729
729
want string
730
730
}{
731
+ {
732
+ name : "service account json" ,
733
+ opts : & DetectOptions {
734
+ CredentialsFile : "../internal/testdata/sa.json" ,
735
+ },
736
+ want : "googleapis.com" ,
737
+ },
738
+ {
739
+ name : "service account json with file universe domain" ,
740
+ opts : & DetectOptions {
741
+ CredentialsFile : "../internal/testdata/sa_universe_domain.json" ,
742
+ UseSelfSignedJWT : true ,
743
+ },
744
+ want : "example.com" ,
745
+ },
746
+ {
747
+ name : "service account json with options universe domain" ,
748
+ opts : & DetectOptions {
749
+ CredentialsFile : "../internal/testdata/sa.json" ,
750
+ UseSelfSignedJWT : true ,
751
+ UniverseDomain : "foo.com" ,
752
+ },
753
+ want : "foo.com" ,
754
+ },
755
+ {
756
+ name : "service account json with file and options universe domain" ,
757
+ opts : & DetectOptions {
758
+ CredentialsFile : "../internal/testdata/sa_universe_domain.json" ,
759
+ UseSelfSignedJWT : true ,
760
+ UniverseDomain : "foo.com" ,
761
+ },
762
+ want : "foo.com" ,
763
+ },
731
764
{
732
765
name : "user json" ,
733
766
opts : & DetectOptions {
@@ -736,71 +769,104 @@ func TestDefaultCredentials_UniverseDomain(t *testing.T) {
736
769
},
737
770
want : "googleapis.com" ,
738
771
},
772
+ {
773
+ name : "user json with options universe domain" ,
774
+ opts : & DetectOptions {
775
+ CredentialsFile : "../internal/testdata/user.json" ,
776
+ UniverseDomain : "foo.com" ,
777
+ },
778
+ want : "googleapis.com" ,
779
+ },
739
780
{
740
781
name : "user json with file universe domain" ,
741
782
opts : & DetectOptions {
742
783
CredentialsFile : "../internal/testdata/user_universe_domain.json" ,
743
784
TokenURL : "example.com" ,
744
785
},
745
- want : "googleapis .com" ,
786
+ want : "example .com" ,
746
787
},
747
788
{
748
- name : "service account token URL json " ,
789
+ name : "user json with file and options universe domain " ,
749
790
opts : & DetectOptions {
750
- CredentialsFile : "../internal/testdata/sa.json" ,
791
+ CredentialsFile : "../internal/testdata/user_universe_domain.json" ,
792
+ UniverseDomain : "foo.com" ,
751
793
},
752
- want : "googleapis .com" ,
794
+ want : "example .com" ,
753
795
},
754
796
{
755
797
name : "external account json" ,
756
798
opts : & DetectOptions {
757
- CredentialsFile : "../internal/testdata/exaccount_user.json" ,
758
- UseSelfSignedJWT : true ,
799
+ CredentialsFile : "../internal/testdata/exaccount_url.json" ,
759
800
},
760
801
want : "googleapis.com" ,
761
802
},
762
803
{
763
- name : "service account impersonation json" ,
804
+ name : "external account json with file universe domain " ,
764
805
opts : & DetectOptions {
765
- CredentialsFile : "../internal/testdata/imp.json" ,
766
- UseSelfSignedJWT : true ,
806
+ CredentialsFile : "../internal/testdata/exaccount_url_universe_domain.json" ,
807
+ },
808
+ want : "example.com" ,
809
+ },
810
+ {
811
+ name : "external account json with options universe domain" ,
812
+ opts : & DetectOptions {
813
+ CredentialsFile : "../internal/testdata/exaccount_url.json" ,
814
+ UniverseDomain : "foo.com" ,
815
+ },
816
+ want : "foo.com" ,
817
+ },
818
+ {
819
+ name : "external account json with file and options universe domain" ,
820
+ opts : & DetectOptions {
821
+ CredentialsFile : "../internal/testdata/exaccount_url_universe_domain.json" ,
822
+ UniverseDomain : "foo.com" ,
823
+ },
824
+ want : "foo.com" ,
825
+ },
826
+ {
827
+ name : "external account user json" ,
828
+ opts : & DetectOptions {
829
+ CredentialsFile : "../internal/testdata/exaccount_user.json" ,
767
830
},
768
831
want : "googleapis.com" ,
769
832
},
770
833
{
771
- name : "service account json with file universe domain" ,
834
+ name : "external account user json with file universe domain" ,
772
835
opts : & DetectOptions {
773
- CredentialsFile : "../internal/testdata/sa_universe_domain.json" ,
774
- UseSelfSignedJWT : true ,
836
+ CredentialsFile : "../internal/testdata/exaccount_user_universe_domain.json" ,
775
837
},
776
838
want : "example.com" ,
777
839
},
778
840
{
779
- name : "service account json with options universe domain" ,
841
+ name : "external account user json with options universe domain" ,
780
842
opts : & DetectOptions {
781
- CredentialsFile : "../internal/testdata/sa.json" ,
782
- UseSelfSignedJWT : true ,
783
- UniverseDomain : "foo.com" ,
843
+ CredentialsFile : "../internal/testdata/exaccount_user.json" ,
844
+ UniverseDomain : "foo.com" ,
784
845
},
785
- want : "foo .com" ,
846
+ want : "googleapis .com" ,
786
847
},
787
848
{
788
- name : "service account json with file and options universe domain" ,
849
+ name : "external account user json with file and options universe domain" ,
789
850
opts : & DetectOptions {
790
- CredentialsFile : "../internal/testdata/sa_universe_domain.json" ,
791
- UseSelfSignedJWT : true ,
792
- UniverseDomain : "bar.com" ,
851
+ CredentialsFile : "../internal/testdata/exaccount_user_universe_domain.json" ,
852
+ UniverseDomain : "foo.com" ,
793
853
},
794
- want : "bar .com" ,
854
+ want : "example .com" ,
795
855
},
796
856
{
797
- name : "external account json with options universe domain " ,
857
+ name : "impersonated service account json" ,
798
858
opts : & DetectOptions {
799
- CredentialsFile : "../internal/testdata/exaccount_user .json" ,
859
+ CredentialsFile : "../internal/testdata/imp .json" ,
800
860
UseSelfSignedJWT : true ,
801
- UniverseDomain : "foo.com" ,
802
861
},
803
- want : "foo.com" ,
862
+ want : "googleapis.com" ,
863
+ },
864
+ {
865
+ name : "impersonated service account json with file universe domain" ,
866
+ opts : & DetectOptions {
867
+ CredentialsFile : "../internal/testdata/imp_universe_domain.json" ,
868
+ },
869
+ want : "example.com" ,
804
870
},
805
871
{
806
872
name : "impersonated service account json with options universe domain" ,
@@ -811,6 +877,14 @@ func TestDefaultCredentials_UniverseDomain(t *testing.T) {
811
877
},
812
878
want : "foo.com" ,
813
879
},
880
+ {
881
+ name : "impersonated service account json with file and options universe domain" ,
882
+ opts : & DetectOptions {
883
+ CredentialsFile : "../internal/testdata/imp_universe_domain.json" ,
884
+ UniverseDomain : "foo.com" ,
885
+ },
886
+ want : "foo.com" ,
887
+ },
814
888
}
815
889
for _ , tt := range tests {
816
890
t .Run (tt .name , func (t * testing.T ) {
0 commit comments