33
33
import com .google .api .client .testing .http .MockHttpTransport ;
34
34
import com .google .api .client .testing .http .MockLowLevelHttpResponse ;
35
35
import com .google .auth .oauth2 .GoogleCredentials ;
36
+ import com .google .common .base .Strings ;
36
37
import com .google .common .collect .ImmutableList ;
37
38
import com .google .common .collect .Iterables ;
38
39
import com .google .firebase .ErrorCode ;
@@ -63,8 +64,13 @@ public class FirebaseTenantClientTest {
63
64
64
65
private static final String TEST_TOKEN = "token" ;
65
66
67
+ private static final String TEST_EMULATOR_TOKEN = "owner" ;
68
+
66
69
private static final GoogleCredentials credentials = new MockGoogleCredentials (TEST_TOKEN );
67
70
71
+ private static final GoogleCredentials emulator_credentials =
72
+ new MockGoogleCredentials (TEST_EMULATOR_TOKEN );
73
+
68
74
private static final String PROJECT_BASE_URL =
69
75
"https://identitytoolkit.googleapis.com/v2/projects/test-project-id" ;
70
76
@@ -342,7 +348,7 @@ private static void checkTenant(Tenant tenant, String tenantId) {
342
348
343
349
private static void checkRequestHeaders (TestResponseInterceptor interceptor ) {
344
350
HttpHeaders headers = interceptor .getResponse ().getRequest ().getHeaders ();
345
- String auth = "Bearer " + TEST_TOKEN ;
351
+ String auth = "Bearer " + ( isEmulatorMode () ? TEST_EMULATOR_TOKEN : TEST_TOKEN ) ;
346
352
assertEquals (auth , headers .getFirstHeaderStringValue ("Authorization" ));
347
353
348
354
String clientVersion = "Java/Admin/" + SdkUtils .getVersion ();
@@ -362,7 +368,7 @@ private static TestResponseInterceptor initializeAppForTenantManagement(String..
362
368
}
363
369
MockHttpTransport transport = new MultiRequestMockHttpTransport (mocks );
364
370
FirebaseApp .initializeApp (FirebaseOptions .builder ()
365
- .setCredentials (credentials )
371
+ .setCredentials (isEmulatorMode () ? emulator_credentials : credentials )
366
372
.setHttpTransport (transport )
367
373
.setProjectId ("test-project-id" )
368
374
.build ());
@@ -408,4 +414,10 @@ private static GenericJson parseRequestContent(TestResponseInterceptor intercept
408
414
interceptor .getResponse ().getRequest ().getContent ().writeTo (out );
409
415
return JSON_FACTORY .fromString (new String (out .toByteArray ()), GenericJson .class );
410
416
}
417
+
418
+ private static boolean isEmulatorMode () {
419
+ return !Strings .isNullOrEmpty (
420
+ FirebaseProcessEnvironment .getenv ("FIREBASE_AUTH_EMULATOR_HOST" )
421
+ );
422
+ }
411
423
}
0 commit comments