@@ -34,9 +34,11 @@ import (
3434)
3535
3636const (
37- credEnvVar = "GOOGLE_APPLICATION_CREDENTIALS"
38- testProjectID = "mock-project-id"
39- testVersion = "test-version"
37+ credEnvVar = "GOOGLE_APPLICATION_CREDENTIALS"
38+ testProjectID = "mock-project-id"
39+ testVersion = "test-version"
40+ defaultIDToolkitV1Endpoint = "https://identitytoolkit.googleapis.com/v1"
41+ defaultIDToolkitV2Beta1Endpoint = "https://identitytoolkit.googleapis.com/v2beta1"
4042)
4143
4244var (
@@ -280,6 +282,38 @@ func TestNewClientExplicitNoAuth(t *testing.T) {
280282 }
281283}
282284
285+ func TestNewClientEmulatorHostEnvVar (t * testing.T ) {
286+ emulatorHost := "localhost:9099"
287+ idToolkitV1Endpoint := "http://localhost:9099/identitytoolkit.googleapis.com/v1"
288+ idToolkitV2Beta1Endpoint := "http://localhost:9099/identitytoolkit.googleapis.com/v2beta1"
289+
290+ os .Setenv (emulatorHostEnvVar , emulatorHost )
291+ defer os .Unsetenv (emulatorHostEnvVar )
292+
293+ conf := & internal.AuthConfig {
294+ Opts : []option.ClientOption {
295+ option .WithoutAuthentication (),
296+ },
297+ }
298+ client , err := NewClient (context .Background (), conf )
299+ if err != nil {
300+ t .Fatal (err )
301+ }
302+ baseClient := client .baseClient
303+ if baseClient .userManagementEndpoint != idToolkitV1Endpoint {
304+ t .Errorf ("baseClient.userManagementEndpoint = %q; want = %q" , baseClient .userManagementEndpoint , idToolkitV1Endpoint )
305+ }
306+ if baseClient .providerConfigEndpoint != idToolkitV2Beta1Endpoint {
307+ t .Errorf ("baseClient.providerConfigEndpoint = %q; want = %q" , baseClient .providerConfigEndpoint , idToolkitV2Beta1Endpoint )
308+ }
309+ if baseClient .tenantMgtEndpoint != idToolkitV2Beta1Endpoint {
310+ t .Errorf ("baseClient.tenantMgtEndpoint = %q; want = %q" , baseClient .tenantMgtEndpoint , idToolkitV2Beta1Endpoint )
311+ }
312+ if _ , ok := baseClient .signer .(emulatedSigner ); ! ok {
313+ t .Errorf ("baseClient.signer = %#v; want = %#v" , baseClient .signer , emulatedSigner {})
314+ }
315+ }
316+
283317func TestCustomToken (t * testing.T ) {
284318 client := & Client {
285319 baseClient : & baseClient {
@@ -663,6 +697,27 @@ func TestVerifyIDTokenWithNoProjectID(t *testing.T) {
663697 }
664698}
665699
700+ func TestVerifyIDTokenInEmulatorMode (t * testing.T ) {
701+ os .Setenv (emulatorHostEnvVar , "localhost:9099" )
702+ defer os .Unsetenv (emulatorHostEnvVar )
703+
704+ conf := & internal.AuthConfig {
705+ ProjectID : "" ,
706+ Opts : optsWithTokenSource ,
707+ }
708+ c , err := NewClient (context .Background (), conf )
709+ if err != nil {
710+ t .Fatal (err )
711+ }
712+
713+ defer func () {
714+ if r := recover (); r == nil {
715+ t .Error ("VeridyIDToken() didn't panic" )
716+ }
717+ }()
718+ c .VerifyIDToken (context .Background (), testIDToken )
719+ }
720+
666721func TestCustomTokenVerification (t * testing.T ) {
667722 client := & Client {
668723 baseClient : & baseClient {
@@ -682,7 +737,7 @@ func TestCustomTokenVerification(t *testing.T) {
682737}
683738
684739func TestCertificateRequestError (t * testing.T ) {
685- tv , err := newIDTokenVerifier (context .Background (), testProjectID )
740+ tv , err := newIDTokenVerifier (context .Background (), testProjectID , false )
686741 if err != nil {
687742 t .Fatal (err )
688743 }
@@ -1022,7 +1077,7 @@ func signerForTests(ctx context.Context) (cryptoSigner, error) {
10221077}
10231078
10241079func idTokenVerifierForTests (ctx context.Context ) (* tokenVerifier , error ) {
1025- tv , err := newIDTokenVerifier (ctx , testProjectID )
1080+ tv , err := newIDTokenVerifier (ctx , testProjectID , false )
10261081 if err != nil {
10271082 return nil , err
10281083 }
@@ -1036,7 +1091,7 @@ func idTokenVerifierForTests(ctx context.Context) (*tokenVerifier, error) {
10361091}
10371092
10381093func cookieVerifierForTests (ctx context.Context ) (* tokenVerifier , error ) {
1039- tv , err := newSessionCookieVerifier (ctx , testProjectID )
1094+ tv , err := newSessionCookieVerifier (ctx , testProjectID , false )
10401095 if err != nil {
10411096 return nil , err
10421097 }
@@ -1163,23 +1218,26 @@ func checkCookieVerifier(tv *tokenVerifier, projectID string) error {
11631218}
11641219
11651220func checkBaseClient (client * Client , wantProjectID string ) error {
1166- umc := client .baseClient
1167- if umc .userManagementEndpoint != idToolkitV1Endpoint {
1168- return fmt .Errorf ("userManagementEndpoint = %q; want = %q" , umc .userManagementEndpoint , idToolkitV1Endpoint )
1221+ baseClient := client .baseClient
1222+ if baseClient .userManagementEndpoint != defaultIDToolkitV1Endpoint {
1223+ return fmt .Errorf ("userManagementEndpoint = %q; want = %q" , baseClient .userManagementEndpoint , defaultIDToolkitV1Endpoint )
1224+ }
1225+ if baseClient .providerConfigEndpoint != defaultIDToolkitV2Beta1Endpoint {
1226+ return fmt .Errorf ("providerConfigEndpoint = %q; want = %q" , baseClient .providerConfigEndpoint , defaultIDToolkitV2Beta1Endpoint )
11691227 }
1170- if umc . providerConfigEndpoint != providerConfigEndpoint {
1171- return fmt .Errorf ("providerConfigEndpoint = %q; want = %q" , umc .providerConfigEndpoint , providerConfigEndpoint )
1228+ if baseClient . tenantMgtEndpoint != defaultIDToolkitV2Beta1Endpoint {
1229+ return fmt .Errorf ("providerConfigEndpoint = %q; want = %q" , baseClient .providerConfigEndpoint , defaultIDToolkitV2Beta1Endpoint )
11721230 }
1173- if umc .projectID != wantProjectID {
1174- return fmt .Errorf ("projectID = %q; want = %q" , umc .projectID , wantProjectID )
1231+ if baseClient .projectID != wantProjectID {
1232+ return fmt .Errorf ("projectID = %q; want = %q" , baseClient .projectID , wantProjectID )
11751233 }
11761234
11771235 req , err := http .NewRequest (http .MethodGet , "https://firebase.google.com" , nil )
11781236 if err != nil {
11791237 return err
11801238 }
11811239
1182- for _ , opt := range umc .httpClient .Opts {
1240+ for _ , opt := range baseClient .httpClient .Opts {
11831241 opt (req )
11841242 }
11851243 version := req .Header .Get ("X-Client-Version" )
0 commit comments