@@ -68,6 +68,51 @@ void serviceAccountReplacedWithJwtTokens() throws Exception {
68
68
assertThat (jwtCreds .getClientEmail ()).isEqualTo (serviceAccountCredentials .getClientEmail ());
69
69
assertThat (jwtCreds .getPrivateKeyId ()).isEqualTo (serviceAccountCredentials .getPrivateKeyId ());
70
70
assertThat (jwtCreds .getPrivateKey ()).isEqualTo (serviceAccountCredentials .getPrivateKey ());
71
+ assertThat (jwtCreds .getUniverseDomain ()).isEqualTo (Credentials .GOOGLE_DEFAULT_UNIVERSE );
72
+ }
73
+
74
+ @ Test
75
+ void serviceAccountReplacedWithJwtTokens_setEmptyDomain () throws Exception {
76
+ ServiceAccountCredentials serviceAccountCredentials =
77
+ CreateServiceAccountCredentials ().toBuilder ().setUniverseDomain ("" ).build ();
78
+
79
+ GoogleCredentialsProvider provider =
80
+ GoogleCredentialsProvider .newBuilder ()
81
+ .setScopesToApply (ImmutableList .of ("scope1" , "scope2" ))
82
+ .setJwtEnabledScopes (ImmutableList .of ("scope1" ))
83
+ .setOAuth2Credentials (serviceAccountCredentials )
84
+ .build ();
85
+
86
+ Credentials credentials = provider .getCredentials ();
87
+ assertThat (credentials ).isInstanceOf (ServiceAccountJwtAccessCredentials .class );
88
+ ServiceAccountJwtAccessCredentials jwtCreds = (ServiceAccountJwtAccessCredentials ) credentials ;
89
+ assertThat (jwtCreds .getClientId ()).isEqualTo (serviceAccountCredentials .getClientId ());
90
+ assertThat (jwtCreds .getClientEmail ()).isEqualTo (serviceAccountCredentials .getClientEmail ());
91
+ assertThat (jwtCreds .getPrivateKeyId ()).isEqualTo (serviceAccountCredentials .getPrivateKeyId ());
92
+ assertThat (jwtCreds .getPrivateKey ()).isEqualTo (serviceAccountCredentials .getPrivateKey ());
93
+ assertThat (jwtCreds .getUniverseDomain ()).isEqualTo (Credentials .GOOGLE_DEFAULT_UNIVERSE );
94
+ }
95
+
96
+ @ Test
97
+ void serviceAccountReplacedWithJwtTokens_customUniverseDomain () throws Exception {
98
+ ServiceAccountCredentials serviceAccountCredentials =
99
+ CreateServiceAccountCredentials ().toBuilder ().setUniverseDomain ("example.com" ).build ();
100
+
101
+ GoogleCredentialsProvider provider =
102
+ GoogleCredentialsProvider .newBuilder ()
103
+ .setScopesToApply (ImmutableList .of ("scope1" , "scope2" ))
104
+ .setJwtEnabledScopes (ImmutableList .of ("scope1" ))
105
+ .setOAuth2Credentials (serviceAccountCredentials )
106
+ .build ();
107
+
108
+ Credentials credentials = provider .getCredentials ();
109
+ assertThat (credentials ).isInstanceOf (ServiceAccountJwtAccessCredentials .class );
110
+ ServiceAccountJwtAccessCredentials jwtCreds = (ServiceAccountJwtAccessCredentials ) credentials ;
111
+ assertThat (jwtCreds .getClientId ()).isEqualTo (serviceAccountCredentials .getClientId ());
112
+ assertThat (jwtCreds .getClientEmail ()).isEqualTo (serviceAccountCredentials .getClientEmail ());
113
+ assertThat (jwtCreds .getPrivateKeyId ()).isEqualTo (serviceAccountCredentials .getPrivateKeyId ());
114
+ assertThat (jwtCreds .getPrivateKey ()).isEqualTo (serviceAccountCredentials .getPrivateKey ());
115
+ assertThat (jwtCreds .getUniverseDomain ()).isEqualTo ("example.com" );
71
116
}
72
117
73
118
@ Test
@@ -94,6 +139,8 @@ void noJwtWithoutScopeMatch() throws Exception {
94
139
assertThat (serviceAccountCredentials2 .getPrivateKey ())
95
140
.isEqualTo (serviceAccountCredentials .getPrivateKey ());
96
141
assertThat (serviceAccountCredentials2 .getScopes ()).containsExactly ("scope1" , "scope2" );
142
+ assertThat (serviceAccountCredentials2 .getUniverseDomain ())
143
+ .isEqualTo (Credentials .GOOGLE_DEFAULT_UNIVERSE );
97
144
}
98
145
99
146
@ Test
@@ -120,5 +167,7 @@ void useJwtAccessWithScope() throws Exception {
120
167
assertThat (serviceAccountCredentials2 .getPrivateKey ())
121
168
.isEqualTo (serviceAccountCredentials .getPrivateKey ());
122
169
assertTrue (serviceAccountCredentials2 .getUseJwtAccessWithScope ());
170
+ assertThat (serviceAccountCredentials2 .getUniverseDomain ())
171
+ .isEqualTo (Credentials .GOOGLE_DEFAULT_UNIVERSE );
123
172
}
124
173
}
0 commit comments