firebase / firebase-admin-dotnet

Firebase Admin .NET SDK
https://firebase.google.com/docs/admin/setup
Apache License 2.0
366 stars 131 forks source link

feat(auth): Add support for Firebase Authentication Emulator #289

Closed floppydisken closed 3 years ago

floppydisken commented 3 years ago

Adds support for Firebase Authentication Emulator. Heavily inspired by the Java version https://github.com/firebase/firebase-admin-java/pull/510/files

I really don't know the scope of adding emulation support for all features but I thought Authentication would be a start (and I need it for my project).

google-cla[bot] commented 3 years ago

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

:memo: Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here with @googlebot I signed it! and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

ℹ️ Googlers: Go here for more info.

hiranya911 commented 3 years ago

Thanks @floppydisken for the PR. Can you please address the CLA issue and test failures reported by GitHub Actions? We can take a look then.

floppydisken commented 3 years ago

@googlebot I signed it!

floppydisken commented 3 years ago

Thanks @floppydisken for the PR. Can you please address the CLA issue and test failures reported by GitHub Actions? We can take a look then.

Tests are now passing. However, I haven't done any tests against the emulator. Do you guys recommend an approach for doing so?

hiranya911 commented 3 years ago

I think at some point we can set up integration tests to run against the emulator. There's similar work happening in our other repos right now. But in the meantime we'll have to do with a combination of unit tests and other manual testing.

hiranya911 commented 3 years ago

Hi @yuchenshi. I was trying to run some of our integration tests against the emulator, and encountered some errors (10 out of 30 in FirebaseAuthTest). Some of the failures made sense to me, but the following few doesn't make sense. Can you help shed some light on what's going on?

X FirebaseAdmin.IntegrationTests.Auth.FirebaseAuthTest.GetUser [81ms]                                                                                                           
  Error Message:
   Assert.Null() Failure
Expected: (null)
Actual:   2021-03-25T00:38:13.6570000Z
  Stack Trace:
     at FirebaseAdmin.IntegrationTests.Auth.AbstractFirebaseAuthTest`1.GetUser() in /Users/hkj/Projects/firebase-admin-dotnet/public/FirebaseAdmin/FirebaseAdmin.IntegrationTests/Auth/AbstractFirebaseAuthTest.cs:line 229
--- End of stack trace from previous location where exception was thrown ---

X FirebaseAdmin.IntegrationTests.Auth.FirebaseAuthTest.CreateUser [5ms]                                                                                                         
  Error Message:
   Assert.Null() Failure
Expected: (null)
Actual:   2021-03-25T00:38:16.0810000Z
  Stack Trace:
     at FirebaseAdmin.IntegrationTests.Auth.AbstractFirebaseAuthTest`1.CreateUser() in /Users/hkj/Projects/firebase-admin-dotnet/public/FirebaseAdmin/FirebaseAdmin.IntegrationTests/Auth/AbstractFirebaseAuthTest.cs:line 209
--- End of stack trace from previous location where exception was thrown ---

X FirebaseAdmin.IntegrationTests.Auth.FirebaseAuthTest.UpdateUser [16ms]                                                                                                        
  Error Message:
   Assert.Null() Failure
Expected: (null)
Actual:   2021-03-25T00:38:16.0870000Z
  Stack Trace:
     at FirebaseAdmin.IntegrationTests.Auth.AbstractFirebaseAuthTest`1.UpdateUser() in /Users/hkj/Projects/firebase-admin-dotnet/public/FirebaseAdmin/FirebaseAdmin.IntegrationTests/Auth/AbstractFirebaseAuthTest.cs:line 252
--- End of stack trace from previous location where exception was thrown ---

It seems the emulator has set the LastSignInTimestamp on some user accounts that were freshly created.

Also do you know whether the emulator supports the following APIs?

        private const string EmailLinkSignInUrl =
            "https://www.googleapis.com/identitytoolkit/v3/relyingparty/emailLinkSignin";

        private const string ResetPasswordUrl =
            "https://www.googleapis.com/identitytoolkit/v3/relyingparty/resetPassword";

        private const string VerifyCustomTokenUrl =
            "https://www.googleapis.com/identitytoolkit/v3/relyingparty/verifyCustomToken";

        private const string VerifyPasswordUrl =
            "https://www.googleapis.com/identitytoolkit/v3/relyingparty/verifyPassword";

We call these APIs during integration tests, and in the emulator mode we'd want those calls directed to the emulator.

yuchenshi commented 3 years ago

I don't have bandwidth right now to look at test failures, but here's some responses to the questions and hopefully that helps.

It seems the emulator has set the LastSignInTimestamp on some user accounts that were freshly created.

I've noticed this as well but I cannot figure out what the right behavior should be. I'd appreciate it if you can help to pin this down in the form of a decision tree on when this should be set/updated or some test cases (even in pseudo code).

Also do you know whether the emulator supports the following APIs?

        private const string EmailLinkSignInUrl =
            "https://www.googleapis.com/identitytoolkit/v3/relyingparty/emailLinkSignin";

        private const string ResetPasswordUrl =
            "https://www.googleapis.com/identitytoolkit/v3/relyingparty/resetPassword";

        private const string VerifyCustomTokenUrl =
            "https://www.googleapis.com/identitytoolkit/v3/relyingparty/verifyCustomToken";

        private const string VerifyPasswordUrl =
            "https://www.googleapis.com/identitytoolkit/v3/relyingparty/verifyPassword";

We call these APIs during integration tests, and in the emulator mode we'd want those calls directed to the emulator.

All of these are supported under the emulator prefix, e.g.http://localhost:9099/www.googleapis.com/identitytoolkit/v3/relyingparty/emailLinkSignin. The emulator doesn't actually send emails obviously, but if the test cases just rely on returnOobLink then they should 100% work out of the box. The returned codes are redeemable.

hiranya911 commented 3 years ago

I'd appreciate it if you can help to pin this down in the form of a decision tree on when this should be set/updated or some test cases (even in pseudo code).

That's probably a question for somebody like @bojeil-google. The only suggestion I can offer (purely based on intuition) is that if a user has never signed in, the emulator shouldn't set the lastSignInTimestamp on the user record. This is especially true for freshly created user accounts.

All of these are supported under the emulator prefix,

That's awesome! We just need to make some minor modifications to the tests in that case.

bojeil-google commented 3 years ago

I'd appreciate it if you can help to pin this down in the form of a decision tree on when this should be set/updated or some test cases (even in pseudo code).

That's probably a question for somebody like @bojeil-google. The only suggestion I can offer (purely based on intuition) is that if a user has never signed in, the emulator shouldn't set the lastSignInTimestamp on the user record. This is especially true for freshly created user accounts.

All of these are supported under the emulator prefix,

That's awesome! We just need to make some minor modifications to the tests in that case.

@hiranya911 suggestion is a good rule of thumb. lastSignInTimestamp should only be set on actual sign in (tokens are minted) or if it is defined explicitly via admin API (e.g. userImport).

hiranya911 commented 3 years ago

Adding the latest integration test report (with emulator) for future reference:

% firebase emulators:exec --project fake-project-id --only auth 'dotnet test FirebaseAdmin/FirebaseAdmin.IntegrationTests --filter FirebaseAdmin.IntegrationTests.Auth.FirebaseAuthTest'
⚠  Could not find config (firebase.json) so using defaults.
i  emulators: Starting emulators: auth
i  Running script: dotnet test FirebaseAdmin/FirebaseAdmin.IntegrationTests --filter FirebaseAdmin.IntegrationTests.Auth.FirebaseAuthTest
Test run for /Users/hkj/Projects/firebase-admin-dotnet/public/FirebaseAdmin/FirebaseAdmin.IntegrationTests/bin/Debug/netcoreapp2.1/FirebaseAdmin.IntegrationTests.dll(.NETCoreApp,Version=v2.1)
Microsoft (R) Test Execution Command Line Tool Version 16.2.0-preview-20190606-02
Copyright (c) Microsoft Corporation.  All rights reserved.

Starting test execution, please wait...
⚠  Received a signed custom token. Auth Emulator does not validate JWTs and IS NOT SECURE
[xUnit.net 00:00:00.93]     FirebaseAdmin.IntegrationTests.Auth.FirebaseAuthTest.CreateCustomTokenWithClaims [FAIL]                                                               
[xUnit.net 00:00:01.03]     FirebaseAdmin.IntegrationTests.Auth.FirebaseAuthTest.GetUser [FAIL]                                                                                   
Test run in progress.⚠  Received a signed custom token. Auth Emulator does not validate JWTs and IS NOT SECURE
[xUnit.net 00:00:01.05]     FirebaseAdmin.IntegrationTests.Auth.FirebaseAuthTest.RevokeRefreshTokens [FAIL]                                                                       
[xUnit.net 00:00:01.10]     FirebaseAdmin.IntegrationTests.Auth.FirebaseAuthTest.DisableUser [FAIL]                                                                               
Test run in progress.⚠  Received a signed custom token. Auth Emulator does not validate JWTs and IS NOT SECURE
[xUnit.net 00:00:01.38]     FirebaseAdmin.IntegrationTests.Auth.FirebaseAuthTest.CreateCustomTokenWithoutServiceAccount [FAIL]                                                    
  X FirebaseAdmin.IntegrationTests.Auth.FirebaseAuthTest.CreateCustomTokenWithClaims [162ms]                                                                                      
  Error Message:
   FirebaseAdmin.Auth.FirebaseAuthException : Firebase ID token has no 'kid' claim.
  Stack Trace:
     at FirebaseAdmin.Auth.Jwt.FirebaseTokenVerifier.VerifyTokenAsync(String token, CancellationToken cancellationToken) in /Users/hkj/Projects/firebase-admin-dotnet/public/FirebaseAdmin/FirebaseAdmin/Auth/Jwt/FirebaseTokenVerifier.cs:line 253
   at FirebaseAdmin.Auth.AbstractFirebaseAuth.VerifyIdTokenAsync(String idToken, Boolean checkRevoked, CancellationToken cancellationToken) in /Users/hkj/Projects/firebase-admin-dotnet/public/FirebaseAdmin/FirebaseAdmin/Auth/AbstractFirebaseAuth.cs:line 311
   at FirebaseAdmin.Auth.AbstractFirebaseAuth.VerifyIdTokenAsync(String idToken, Boolean checkRevoked) in /Users/hkj/Projects/firebase-admin-dotnet/public/FirebaseAdmin/FirebaseAdmin/Auth/AbstractFirebaseAuth.cs:line 279
   at FirebaseAdmin.IntegrationTests.Auth.AbstractFirebaseAuthTest`1.AssertValidIdTokenAsync(String idToken, Boolean checkRevoked) in /Users/hkj/Projects/firebase-admin-dotnet/public/FirebaseAdmin/FirebaseAdmin.IntegrationTests/Auth/AbstractFirebaseAuthTest.cs:line 663
   at FirebaseAdmin.IntegrationTests.Auth.AbstractFirebaseAuthTest`1.CreateCustomTokenWithClaims() in /Users/hkj/Projects/firebase-admin-dotnet/public/FirebaseAdmin/FirebaseAdmin.IntegrationTests/Auth/AbstractFirebaseAuthTest.cs:line 75
--- End of stack trace from previous location where exception was thrown ---
  X FirebaseAdmin.IntegrationTests.Auth.FirebaseAuthTest.GetUser [95ms]                                                                                                           
  Error Message:
   Assert.Null() Failure
Expected: (null)
Actual:   2021-03-25T18:07:37.7570000Z
  Stack Trace:
     at FirebaseAdmin.IntegrationTests.Auth.AbstractFirebaseAuthTest`1.GetUser() in /Users/hkj/Projects/firebase-admin-dotnet/public/FirebaseAdmin/FirebaseAdmin.IntegrationTests/Auth/AbstractFirebaseAuthTest.cs:line 229
--- End of stack trace from previous location where exception was thrown ---
  X FirebaseAdmin.IntegrationTests.Auth.FirebaseAuthTest.RevokeRefreshTokens [21ms]                                                                                               
  Error Message:
   FirebaseAdmin.Auth.FirebaseAuthException : Firebase ID token has no 'kid' claim.
  Stack Trace:
     at FirebaseAdmin.Auth.Jwt.FirebaseTokenVerifier.VerifyTokenAsync(String token, CancellationToken cancellationToken) in /Users/hkj/Projects/firebase-admin-dotnet/public/FirebaseAdmin/FirebaseAdmin/Auth/Jwt/FirebaseTokenVerifier.cs:line 253
   at FirebaseAdmin.Auth.AbstractFirebaseAuth.VerifyIdTokenAsync(String idToken, Boolean checkRevoked, CancellationToken cancellationToken) in /Users/hkj/Projects/firebase-admin-dotnet/public/FirebaseAdmin/FirebaseAdmin/Auth/AbstractFirebaseAuth.cs:line 311
   at FirebaseAdmin.Auth.AbstractFirebaseAuth.VerifyIdTokenAsync(String idToken, Boolean checkRevoked) in /Users/hkj/Projects/firebase-admin-dotnet/public/FirebaseAdmin/FirebaseAdmin/Auth/AbstractFirebaseAuth.cs:line 279
   at FirebaseAdmin.IntegrationTests.Auth.AbstractFirebaseAuthTest`1.AssertValidIdTokenAsync(String idToken, Boolean checkRevoked) in /Users/hkj/Projects/firebase-admin-dotnet/public/FirebaseAdmin/FirebaseAdmin.IntegrationTests/Auth/AbstractFirebaseAuthTest.cs:line 663
   at FirebaseAdmin.IntegrationTests.Auth.AbstractFirebaseAuthTest`1.RevokeRefreshTokens() in /Users/hkj/Projects/firebase-admin-dotnet/public/FirebaseAdmin/FirebaseAdmin.IntegrationTests/Auth/AbstractFirebaseAuthTest.cs:line 120
--- End of stack trace from previous location where exception was thrown ---
  X FirebaseAdmin.IntegrationTests.Auth.FirebaseAuthTest.DisableUser [26ms]                                                                                                       
  Error Message:
   Assert.Null() Failure
Expected: (null)
Actual:   2021-03-25T18:07:37.8530000Z
  Stack Trace:
     at FirebaseAdmin.IntegrationTests.Auth.AbstractFirebaseAuthTest`1.DisableUser() in /Users/hkj/Projects/firebase-admin-dotnet/public/FirebaseAdmin/FirebaseAdmin.IntegrationTests/Auth/AbstractFirebaseAuthTest.cs:line 302
--- End of stack trace from previous location where exception was thrown ---
[xUnit.net 00:00:01.47]     FirebaseAdmin.IntegrationTests.Auth.FirebaseAuthTest.ImportUsersWithPassword [FAIL]                                                                   
[xUnit.net 00:00:01.51]     FirebaseAdmin.IntegrationTests.Auth.FirebaseAuthTest.SignInWithEmailLink [FAIL]                                                                       
[xUnit.net 00:00:01.55]     FirebaseAdmin.IntegrationTests.Auth.FirebaseAuthTest.LastRefreshTime [FAIL]                                                                           
Test run in progress.⚠  Received a signed custom token. Auth Emulator does not validate JWTs and IS NOT SECURE
[xUnit.net 00:00:01.57]     FirebaseAdmin.IntegrationTests.Auth.FirebaseAuthTest.SessionCookie [FAIL]                                                                             
  X FirebaseAdmin.IntegrationTests.Auth.FirebaseAuthTest.CreateCustomTokenWithoutServiceAccount [283ms]                                                                           
  Error Message:
   FirebaseAdmin.Auth.FirebaseAuthException : Firebase ID token has no 'kid' claim.
  Stack Trace:
     at FirebaseAdmin.Auth.Jwt.FirebaseTokenVerifier.VerifyTokenAsync(String token, CancellationToken cancellationToken) in /Users/hkj/Projects/firebase-admin-dotnet/public/FirebaseAdmin/FirebaseAdmin/Auth/Jwt/FirebaseTokenVerifier.cs:line 253
   at FirebaseAdmin.Auth.AbstractFirebaseAuth.VerifyIdTokenAsync(String idToken, Boolean checkRevoked, CancellationToken cancellationToken) in /Users/hkj/Projects/firebase-admin-dotnet/public/FirebaseAdmin/FirebaseAdmin/Auth/AbstractFirebaseAuth.cs:line 311
   at FirebaseAdmin.Auth.AbstractFirebaseAuth.VerifyIdTokenAsync(String idToken, Boolean checkRevoked) in /Users/hkj/Projects/firebase-admin-dotnet/public/FirebaseAdmin/FirebaseAdmin/Auth/AbstractFirebaseAuth.cs:line 279
   at FirebaseAdmin.IntegrationTests.Auth.AbstractFirebaseAuthTest`1.AssertValidIdTokenAsync(String idToken, Boolean checkRevoked) in /Users/hkj/Projects/firebase-admin-dotnet/public/FirebaseAdmin/FirebaseAdmin.IntegrationTests/Auth/AbstractFirebaseAuthTest.cs:line 663
   at FirebaseAdmin.IntegrationTests.Auth.AbstractFirebaseAuthTest`1.CreateCustomTokenWithoutServiceAccount() in /Users/hkj/Projects/firebase-admin-dotnet/public/FirebaseAdmin/FirebaseAdmin.IntegrationTests/Auth/AbstractFirebaseAuthTest.cs:line 106
--- End of stack trace from previous location where exception was thrown ---
  X FirebaseAdmin.IntegrationTests.Auth.FirebaseAuthTest.ImportUsersWithPassword [58ms]                                                                                           
  Error Message:
   System.Net.Http.HttpRequestException : Response status code does not indicate success: 400 (Bad Request).
  Stack Trace:
     at System.Net.Http.HttpResponseMessage.EnsureSuccessStatusCode()
   at FirebaseAdmin.IntegrationTests.Auth.AuthIntegrationUtils.SendAndDeserialize[T](HttpRequestMessage request) in /Users/hkj/Projects/firebase-admin-dotnet/public/FirebaseAdmin/FirebaseAdmin.IntegrationTests/Auth/AuthIntegrationUtils.cs:line 151
   at FirebaseAdmin.IntegrationTests.Auth.AuthIntegrationUtils.SignInWithPasswordAsync(String email, String password, String tenantId) in /Users/hkj/Projects/firebase-admin-dotnet/public/FirebaseAdmin/FirebaseAdmin.IntegrationTests/Auth/AuthIntegrationUtils.cs:line 133
   at FirebaseAdmin.IntegrationTests.Auth.AbstractFirebaseAuthTest`1.ImportUsersWithPassword() in /Users/hkj/Projects/firebase-admin-dotnet/public/FirebaseAdmin/FirebaseAdmin.IntegrationTests/Auth/AbstractFirebaseAuthTest.cs:line 592
--- End of stack trace from previous location where exception was thrown ---
  X FirebaseAdmin.IntegrationTests.Auth.FirebaseAuthTest.SignInWithEmailLink [20ms]                                                                                               
  Error Message:
   System.Net.Http.HttpRequestException : Response status code does not indicate success: 400 (Bad Request).
  Stack Trace:
     at System.Net.Http.HttpResponseMessage.EnsureSuccessStatusCode()
   at FirebaseAdmin.IntegrationTests.Auth.AuthIntegrationUtils.SendAndDeserialize[T](HttpRequestMessage request) in /Users/hkj/Projects/firebase-admin-dotnet/public/FirebaseAdmin/FirebaseAdmin.IntegrationTests/Auth/AuthIntegrationUtils.cs:line 151
   at FirebaseAdmin.IntegrationTests.Auth.AuthIntegrationUtils.SignInWithEmailLinkAsync(String email, String oobCode, String tenantId) in /Users/hkj/Projects/firebase-admin-dotnet/public/FirebaseAdmin/FirebaseAdmin.IntegrationTests/Auth/AuthIntegrationUtils.cs:line 110
   at FirebaseAdmin.IntegrationTests.Auth.AbstractFirebaseAuthTest`1.SignInWithEmailLink() in /Users/hkj/Projects/firebase-admin-dotnet/public/FirebaseAdmin/FirebaseAdmin.IntegrationTests/Auth/AbstractFirebaseAuthTest.cs:line 651
--- End of stack trace from previous location where exception was thrown ---
  X FirebaseAdmin.IntegrationTests.Auth.FirebaseAuthTest.LastRefreshTime [8ms]                                                                                                    
  Error Message:
   System.Net.Http.HttpRequestException : Response status code does not indicate success: 400 (Bad Request).
  Stack Trace:
     at System.Net.Http.HttpResponseMessage.EnsureSuccessStatusCode()
   at FirebaseAdmin.IntegrationTests.Auth.AuthIntegrationUtils.SendAndDeserialize[T](HttpRequestMessage request) in /Users/hkj/Projects/firebase-admin-dotnet/public/FirebaseAdmin/FirebaseAdmin.IntegrationTests/Auth/AuthIntegrationUtils.cs:line 151
   at FirebaseAdmin.IntegrationTests.Auth.AuthIntegrationUtils.SignInWithPasswordAsync(String email, String password, String tenantId) in /Users/hkj/Projects/firebase-admin-dotnet/public/FirebaseAdmin/FirebaseAdmin.IntegrationTests/Auth/AuthIntegrationUtils.cs:line 133
   at FirebaseAdmin.IntegrationTests.Auth.AbstractFirebaseAuthTest`1.LastRefreshTime() in /Users/hkj/Projects/firebase-admin-dotnet/public/FirebaseAdmin/FirebaseAdmin.IntegrationTests/Auth/AbstractFirebaseAuthTest.cs:line 346
--- End of stack trace from previous location where exception was thrown ---
  X FirebaseAdmin.IntegrationTests.Auth.FirebaseAuthTest.SessionCookie [26ms]                                                                                                     
  Error Message:
   FirebaseAdmin.Auth.FirebaseAuthException : Unexpected HTTP response with status: 404 (NotFound)
{
  "error": {
    "code": 404,
    "message": "Not Found",
    "errors": [
      {
        "message": "Not Found",
        "reason": "notFound"
      }
    ],
    "status": "NOT_FOUND"
  }
}
  Stack Trace:
     at FirebaseAdmin.Util.ErrorHandlingHttpClient`1.SendAndReadAsync(HttpRequestMessage request, CancellationToken cancellationToken) in /Users/hkj/Projects/firebase-admin-dotnet/public/FirebaseAdmin/FirebaseAdmin/Util/ErrorHandlingHttpClient.cs:line 114
   at FirebaseAdmin.Util.ErrorHandlingHttpClient`1.SendAndDeserializeAsync[TResult](HttpRequestMessage request, CancellationToken cancellationToken) in /Users/hkj/Projects/firebase-admin-dotnet/public/FirebaseAdmin/FirebaseAdmin/Util/ErrorHandlingHttpClient.cs:line 62
   at FirebaseAdmin.Auth.Users.FirebaseUserManager.PostAndDeserializeAsync[TResult](String path, Object body, CancellationToken cancellationToken) in /Users/hkj/Projects/firebase-admin-dotnet/public/FirebaseAdmin/FirebaseAdmin/Auth/Users/FirebaseUserManager.cs:line 421
   at FirebaseAdmin.Auth.Users.FirebaseUserManager.CreateSessionCookieAsync(String idToken, SessionCookieOptions options, CancellationToken cancellationToken) in /Users/hkj/Projects/firebase-admin-dotnet/public/FirebaseAdmin/FirebaseAdmin/Auth/Users/FirebaseUserManager.cs:line 372
   at FirebaseAdmin.Auth.FirebaseAuth.CreateSessionCookieAsync(String idToken, SessionCookieOptions options, CancellationToken cancellationToken) in /Users/hkj/Projects/firebase-admin-dotnet/public/FirebaseAdmin/FirebaseAdmin/Auth/FirebaseAuth.cs:line 117
   at FirebaseAdmin.Auth.FirebaseAuth.CreateSessionCookieAsync(String idToken, SessionCookieOptions options) in /Users/hkj/Projects/firebase-admin-dotnet/public/FirebaseAdmin/FirebaseAdmin/Auth/FirebaseAuth.cs:line 100
   at FirebaseAdmin.IntegrationTests.Auth.FirebaseAuthTest.SessionCookie() in /Users/hkj/Projects/firebase-admin-dotnet/public/FirebaseAdmin/FirebaseAdmin.IntegrationTests/Auth/FirebaseAuthTest.cs:line 37
--- End of stack trace from previous location where exception was thrown ---
[xUnit.net 00:00:01.58]     FirebaseAdmin.IntegrationTests.Auth.FirebaseAuthTest.CreateUser [FAIL]                                                                                
[xUnit.net 00:00:01.59]     FirebaseAdmin.IntegrationTests.Auth.FirebaseAuthTest.UpdateUser [FAIL]                                                                                
[xUnit.net 00:00:02.65]     FirebaseAdmin.IntegrationTests.Auth.FirebaseAuthTest.PasswordResetLink [FAIL]                                                                         
  X FirebaseAdmin.IntegrationTests.Auth.FirebaseAuthTest.CreateUser [5ms]                                                                                                         
  Error Message:
   Assert.Null() Failure
Expected: (null)
Actual:   2021-03-25T18:07:38.3450000Z
  Stack Trace:
     at FirebaseAdmin.IntegrationTests.Auth.AbstractFirebaseAuthTest`1.CreateUser() in /Users/hkj/Projects/firebase-admin-dotnet/public/FirebaseAdmin/FirebaseAdmin.IntegrationTests/Auth/AbstractFirebaseAuthTest.cs:line 209
--- End of stack trace from previous location where exception was thrown ---
  X FirebaseAdmin.IntegrationTests.Auth.FirebaseAuthTest.UpdateUser [13ms]                                                                                                        
  Error Message:
   Assert.Null() Failure
Expected: (null)
Actual:   2021-03-25T18:07:38.3510000Z
  Stack Trace:
     at FirebaseAdmin.IntegrationTests.Auth.AbstractFirebaseAuthTest`1.UpdateUser() in /Users/hkj/Projects/firebase-admin-dotnet/public/FirebaseAdmin/FirebaseAdmin.IntegrationTests/Auth/AbstractFirebaseAuthTest.cs:line 252
--- End of stack trace from previous location where exception was thrown ---
  X FirebaseAdmin.IntegrationTests.Auth.FirebaseAuthTest.PasswordResetLink [13ms]                                                                                                 
  Error Message:
   System.Net.Http.HttpRequestException : Response status code does not indicate success: 400 (Bad Request).
  Stack Trace:
     at System.Net.Http.HttpResponseMessage.EnsureSuccessStatusCode()
   at FirebaseAdmin.IntegrationTests.Auth.AuthIntegrationUtils.SendAndDeserialize[T](HttpRequestMessage request) in /Users/hkj/Projects/firebase-admin-dotnet/public/FirebaseAdmin/FirebaseAdmin.IntegrationTests/Auth/AuthIntegrationUtils.cs:line 151
   at FirebaseAdmin.IntegrationTests.Auth.AuthIntegrationUtils.ResetPasswordAsync(ResetPasswordRequest data) in /Users/hkj/Projects/firebase-admin-dotnet/public/FirebaseAdmin/FirebaseAdmin.IntegrationTests/Auth/AuthIntegrationUtils.cs:line 82
   at FirebaseAdmin.IntegrationTests.Auth.AbstractFirebaseAuthTest`1.PasswordResetLink() in /Users/hkj/Projects/firebase-admin-dotnet/public/FirebaseAdmin/FirebaseAdmin.IntegrationTests/Auth/AbstractFirebaseAuthTest.cs:line 631
--- End of stack trace from previous location where exception was thrown ---
Test run in progress..⚠  Received a signed custom token. Auth Emulator does not validate JWTs and IS NOT SECURE                                                                   
[xUnit.net 00:00:05.72]     FirebaseAdmin.IntegrationTests.Auth.FirebaseAuthTest.CreateCustomToken [FAIL]                                                                         
  X FirebaseAdmin.IntegrationTests.Auth.FirebaseAuthTest.CreateCustomToken [18ms]                                                                                                 
  Error Message:
   FirebaseAdmin.Auth.FirebaseAuthException : Firebase ID token has no 'kid' claim.
  Stack Trace:
     at FirebaseAdmin.Auth.Jwt.FirebaseTokenVerifier.VerifyTokenAsync(String token, CancellationToken cancellationToken) in /Users/hkj/Projects/firebase-admin-dotnet/public/FirebaseAdmin/FirebaseAdmin/Auth/Jwt/FirebaseTokenVerifier.cs:line 253
   at FirebaseAdmin.Auth.AbstractFirebaseAuth.VerifyIdTokenAsync(String idToken, Boolean checkRevoked, CancellationToken cancellationToken) in /Users/hkj/Projects/firebase-admin-dotnet/public/FirebaseAdmin/FirebaseAdmin/Auth/AbstractFirebaseAuth.cs:line 311
   at FirebaseAdmin.Auth.AbstractFirebaseAuth.VerifyIdTokenAsync(String idToken, Boolean checkRevoked) in /Users/hkj/Projects/firebase-admin-dotnet/public/FirebaseAdmin/FirebaseAdmin/Auth/AbstractFirebaseAuth.cs:line 279
   at FirebaseAdmin.IntegrationTests.Auth.AbstractFirebaseAuthTest`1.AssertValidIdTokenAsync(String idToken, Boolean checkRevoked) in /Users/hkj/Projects/firebase-admin-dotnet/public/FirebaseAdmin/FirebaseAdmin.IntegrationTests/Auth/AbstractFirebaseAuthTest.cs:line 663
   at FirebaseAdmin.IntegrationTests.Auth.AbstractFirebaseAuthTest`1.CreateCustomToken() in /Users/hkj/Projects/firebase-admin-dotnet/public/FirebaseAdmin/FirebaseAdmin.IntegrationTests/Auth/AbstractFirebaseAuthTest.cs:line 58
--- End of stack trace from previous location where exception was thrown ---

Test Run Failed.
Total tests: 30
     Passed: 17
     Failed: 13
 Total time: 7.5805 Seconds
⚠  Script exited unsuccessfully (code 1)
i  emulators: Shutting down emulators.
i  auth: Stopping Authentication Emulator
i  hub: Stopping emulator hub

Error: Script "dotnet test FirebaseAdmin/FirebaseAdmin.IntegrationTests --filter FirebaseAdmin.IntegrationTests.Auth.FirebaseAuthTest" exited with code 1

At a high-level all the traffic during tests is directed to the emulator, which is great. The test failures, as far as I can tell are due to one of three reasons:

  1. Emulator setting lastSignInTimestamp on freshly created user accounts.
  2. SDK not yet supporting CreateCustomTokenAsync() and VerifyIdTokenAsync() in emulator mode.
  3. Emulator possibly not supporting resetPassword endpoint.

Note that (2) is an action item for this repo, and something we should get addressed before going into a release.

hiranya911 commented 3 years ago

Thanks @floppydisken for patiently working through all the comments. We will continue to develop this feature on the auth-emulator branch (and feel welcome to give us a hand by sending more PRs).