File tree Expand file tree Collapse file tree 2 files changed +33
-1
lines changed Expand file tree Collapse file tree 2 files changed +33
-1
lines changed Original file line number Diff line number Diff line change 42
42
use Google \Auth \FetchAuthTokenInterface ;
43
43
use Google \Auth \GetQuotaProjectInterface ;
44
44
use Google \Auth \GetUniverseDomainInterface ;
45
+ use Google \Auth \Credentials \GCECredentials ;
45
46
use Google \Auth \HttpHandler \Guzzle6HttpHandler ;
46
47
use Google \Auth \HttpHandler \Guzzle7HttpHandler ;
47
48
use Google \Auth \HttpHandler \HttpHandlerFactory ;
@@ -273,7 +274,7 @@ public function getAuthorizationHeaderCallback($audience = null)
273
274
*/
274
275
public function checkUniverseDomain ()
275
276
{
276
- if (false === $ this ->hasCheckedUniverse ) {
277
+ if (false === $ this ->hasCheckedUniverse && $ this -> shouldCheckUniverseDomain () ) {
277
278
$ credentialsUniverse = $ this ->credentialsFetcher instanceof GetUniverseDomainInterface
278
279
? $ this ->credentialsFetcher ->getUniverseDomain ()
279
280
: GetUniverseDomainInterface::DEFAULT_UNIVERSE_DOMAIN ;
@@ -288,6 +289,24 @@ public function checkUniverseDomain()
288
289
}
289
290
}
290
291
292
+ /**
293
+ * Skip universe domain check for Metadata server (e.g. GCE) credentials.
294
+ *
295
+ * @return bool
296
+ */
297
+ private function shouldCheckUniverseDomain (): bool
298
+ {
299
+ $ fetcher = $ this ->credentialsFetcher instanceof FetchAuthTokenCache
300
+ ? $ this ->credentialsFetcher ->getFetcher ()
301
+ : $ this ->credentialsFetcher ;
302
+
303
+ if ($ fetcher instanceof GCECredentials) {
304
+ return false ;
305
+ }
306
+
307
+ return true ;
308
+ }
309
+
291
310
/**
292
311
* @param array $scopes
293
312
* @param callable $authHttpHandler
Original file line number Diff line number Diff line change @@ -303,6 +303,19 @@ public function provideCheckUniverseDomainPasses()
303
303
];
304
304
}
305
305
306
+ public function testCheckUniverseDomainOnGceCredentialsDoesNotCheck ()
307
+ {
308
+ $ fetcher = $ this ->prophesize (GCECredentials::class);
309
+ $ fetcher ->getUniverseDomain ()->shouldNotBeCalled ();
310
+ $ credentialsWrapper = new CredentialsWrapper (
311
+ $ fetcher ->reveal (),
312
+ null ,
313
+ 'some-random-universe-domain '
314
+ );
315
+
316
+ $ credentialsWrapper ->checkUniverseDomain ();
317
+ }
318
+
306
319
/**
307
320
* @dataProvider getBearerStringData
308
321
*/
You can’t perform that action at this time.
0 commit comments