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..4311e77a 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: " + if err == nil || !auth.IsUnauthorizedContinueURI(err) || !strings.HasPrefix(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,