From a6fa019822c2c38d88455e6214e93b98ac40e3fd Mon Sep 17 00:00:00 2001 From: jonathanedey Date: Tue, 26 Aug 2025 10:46:14 -0400 Subject: [PATCH 1/2] fix(auth): Fixed auth error code parsing --- auth/user_mgt.go | 2 +- auth/user_mgt_test.go | 2 +- integration/auth/user_mgt_test.go | 14 ++++++++++++++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/auth/user_mgt.go b/auth/user_mgt.go index 63a5c381..cc37f56b 100644 --- a/auth/user_mgt.go +++ b/auth/user_mgt.go @@ -1510,7 +1510,7 @@ func parseErrorResponse(resp *internal.Response) (string, string) { idx := strings.Index(code, ":") if idx != -1 { detail = strings.TrimSpace(code[idx+1:]) - code = code[:idx] + code = strings.TrimSpace(code[:idx]) } return code, detail diff --git a/auth/user_mgt_test.go b/auth/user_mgt_test.go index 53ccdc58..445cf718 100644 --- a/auth/user_mgt_test.go +++ b/auth/user_mgt_test.go @@ -2191,7 +2191,7 @@ func TestHTTPErrorWithCode(t *testing.T) { } func TestAuthErrorWithCodeAndDetails(t *testing.T) { - resp := []byte(`{"error":{"message":"USER_NOT_FOUND: extra details"}}`) + resp := []byte(`{"error":{"message":"USER_NOT_FOUND : extra details"}}`) s := echoServer(resp, t) defer s.Close() s.Client.baseClient.httpClient.RetryConfig = nil diff --git a/integration/auth/user_mgt_test.go b/integration/auth/user_mgt_test.go index 1c37cd0a..f372b176 100644 --- a/integration/auth/user_mgt_test.go +++ b/integration/auth/user_mgt_test.go @@ -35,6 +35,7 @@ import ( const ( continueURL = "http://localhost/?a=1&b=2#c=3" + invalidContinueURL = "http://www.localhost/?a=1&b=2#c=3" continueURLKey = "continueUrl" oobCodeKey = "oobCode" modeKey = "mode" @@ -1297,6 +1298,19 @@ func TestEmailSignInLink(t *testing.T) { } } +func TestAuthErrorParse(t *testing.T) { + user := newUserWithParams(t) + defer deleteUser(user.UID) + _, err := client.EmailSignInLink(context.Background(), user.Email, &auth.ActionCodeSettings{ + URL: invalidContinueURL, + HandleCodeInApp: false, + }) + want := "domain of the continue url is not whitelisted: Domain not whitelisted by project" + if err == nil || !auth.IsUnauthorizedContinueURI(err) || err.Error() != want { + t.Errorf("EmailSignInLink() expected error, got: %s, want: %s", err, want) + } +} + func resetPassword(email, oldPassword, newPassword, oobCode string) error { req := map[string]interface{}{ "email": email, From eff5ede06ede9948328d7d9916faa4485b7fed15 Mon Sep 17 00:00:00 2001 From: jonathanedey Date: Tue, 26 Aug 2025 11:41:48 -0400 Subject: [PATCH 2/2] fix(auth): Fixed test to use error message prefix --- integration/auth/user_mgt_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/integration/auth/user_mgt_test.go b/integration/auth/user_mgt_test.go index f372b176..4311e77a 100644 --- a/integration/auth/user_mgt_test.go +++ b/integration/auth/user_mgt_test.go @@ -1305,8 +1305,8 @@ func TestAuthErrorParse(t *testing.T) { URL: invalidContinueURL, HandleCodeInApp: false, }) - want := "domain of the continue url is not whitelisted: Domain not whitelisted by project" - if err == nil || !auth.IsUnauthorizedContinueURI(err) || err.Error() != want { + want := "domain of the continue url is not whitelisted: " + if err == nil || !auth.IsUnauthorizedContinueURI(err) || !strings.HasPrefix(err.Error(), want) { t.Errorf("EmailSignInLink() expected error, got: %s, want: %s", err, want) } }