@@ -41,7 +41,7 @@ type tokResp struct {
4141
4242func TestDefaultCredentials_GdchServiceAccountKey (t * testing.T ) {
4343 ctx := context .Background ()
44- aud := "http://sampele -aud.com/"
44+ aud := "http://sample -aud.com/"
4545 b , err := os .ReadFile ("../internal/testdata/gdch.json" )
4646 if err != nil {
4747 t .Fatal (err )
@@ -285,7 +285,7 @@ func TestDefaultCredentials_UserCredentialsKey_UniverseDomain(t *testing.T) {
285285 if err != nil {
286286 t .Fatal (err )
287287 }
288- if want := "googleapis .com" ; got != want {
288+ if want := "example .com" ; got != want {
289289 t .Fatalf ("got %q, want %q" , got , want )
290290 }
291291 tok , err := creds .Token (context .Background ())
@@ -728,6 +728,39 @@ func TestDefaultCredentials_UniverseDomain(t *testing.T) {
728728 opts * DetectOptions
729729 want string
730730 }{
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+ },
731764 {
732765 name : "user json" ,
733766 opts : & DetectOptions {
@@ -736,71 +769,104 @@ func TestDefaultCredentials_UniverseDomain(t *testing.T) {
736769 },
737770 want : "googleapis.com" ,
738771 },
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+ },
739780 {
740781 name : "user json with file universe domain" ,
741782 opts : & DetectOptions {
742783 CredentialsFile : "../internal/testdata/user_universe_domain.json" ,
743784 TokenURL : "example.com" ,
744785 },
745- want : "googleapis .com" ,
786+ want : "example .com" ,
746787 },
747788 {
748- name : "service account token URL json " ,
789+ name : "user json with file and options universe domain " ,
749790 opts : & DetectOptions {
750- CredentialsFile : "../internal/testdata/sa.json" ,
791+ CredentialsFile : "../internal/testdata/user_universe_domain.json" ,
792+ UniverseDomain : "foo.com" ,
751793 },
752- want : "googleapis .com" ,
794+ want : "example .com" ,
753795 },
754796 {
755797 name : "external account json" ,
756798 opts : & DetectOptions {
757- CredentialsFile : "../internal/testdata/exaccount_user.json" ,
758- UseSelfSignedJWT : true ,
799+ CredentialsFile : "../internal/testdata/exaccount_url.json" ,
759800 },
760801 want : "googleapis.com" ,
761802 },
762803 {
763- name : "service account impersonation json" ,
804+ name : "external account json with file universe domain " ,
764805 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" ,
767830 },
768831 want : "googleapis.com" ,
769832 },
770833 {
771- name : "service account json with file universe domain" ,
834+ name : "external account user json with file universe domain" ,
772835 opts : & DetectOptions {
773- CredentialsFile : "../internal/testdata/sa_universe_domain.json" ,
774- UseSelfSignedJWT : true ,
836+ CredentialsFile : "../internal/testdata/exaccount_user_universe_domain.json" ,
775837 },
776838 want : "example.com" ,
777839 },
778840 {
779- name : "service account json with options universe domain" ,
841+ name : "external account user json with options universe domain" ,
780842 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" ,
784845 },
785- want : "foo .com" ,
846+ want : "googleapis .com" ,
786847 },
787848 {
788- name : "service account json with file and options universe domain" ,
849+ name : "external account user json with file and options universe domain" ,
789850 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" ,
793853 },
794- want : "bar .com" ,
854+ want : "example .com" ,
795855 },
796856 {
797- name : "external account json with options universe domain " ,
857+ name : "impersonated service account json" ,
798858 opts : & DetectOptions {
799- CredentialsFile : "../internal/testdata/exaccount_user .json" ,
859+ CredentialsFile : "../internal/testdata/imp .json" ,
800860 UseSelfSignedJWT : true ,
801- UniverseDomain : "foo.com" ,
802861 },
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" ,
804870 },
805871 {
806872 name : "impersonated service account json with options universe domain" ,
@@ -811,6 +877,14 @@ func TestDefaultCredentials_UniverseDomain(t *testing.T) {
811877 },
812878 want : "foo.com" ,
813879 },
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+ },
814888 }
815889 for _ , tt := range tests {
816890 t .Run (tt .name , func (t * testing.T ) {
0 commit comments