Skip to content

Commit a6fa019

Browse files
committed
fix(auth): Fixed auth error code parsing
1 parent d5fbad8 commit a6fa019

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

auth/user_mgt.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1510,7 +1510,7 @@ func parseErrorResponse(resp *internal.Response) (string, string) {
15101510
idx := strings.Index(code, ":")
15111511
if idx != -1 {
15121512
detail = strings.TrimSpace(code[idx+1:])
1513-
code = code[:idx]
1513+
code = strings.TrimSpace(code[:idx])
15141514
}
15151515

15161516
return code, detail

auth/user_mgt_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2191,7 +2191,7 @@ func TestHTTPErrorWithCode(t *testing.T) {
21912191
}
21922192

21932193
func TestAuthErrorWithCodeAndDetails(t *testing.T) {
2194-
resp := []byte(`{"error":{"message":"USER_NOT_FOUND: extra details"}}`)
2194+
resp := []byte(`{"error":{"message":"USER_NOT_FOUND : extra details"}}`)
21952195
s := echoServer(resp, t)
21962196
defer s.Close()
21972197
s.Client.baseClient.httpClient.RetryConfig = nil

integration/auth/user_mgt_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import (
3535

3636
const (
3737
continueURL = "http://localhost/?a=1&b=2#c=3"
38+
invalidContinueURL = "http://www.localhost/?a=1&b=2#c=3"
3839
continueURLKey = "continueUrl"
3940
oobCodeKey = "oobCode"
4041
modeKey = "mode"
@@ -1297,6 +1298,19 @@ func TestEmailSignInLink(t *testing.T) {
12971298
}
12981299
}
12991300

1301+
func TestAuthErrorParse(t *testing.T) {
1302+
user := newUserWithParams(t)
1303+
defer deleteUser(user.UID)
1304+
_, err := client.EmailSignInLink(context.Background(), user.Email, &auth.ActionCodeSettings{
1305+
URL: invalidContinueURL,
1306+
HandleCodeInApp: false,
1307+
})
1308+
want := "domain of the continue url is not whitelisted: Domain not whitelisted by project"
1309+
if err == nil || !auth.IsUnauthorizedContinueURI(err) || err.Error() != want {
1310+
t.Errorf("EmailSignInLink() expected error, got: %s, want: %s", err, want)
1311+
}
1312+
}
1313+
13001314
func resetPassword(email, oldPassword, newPassword, oobCode string) error {
13011315
req := map[string]interface{}{
13021316
"email": email,

0 commit comments

Comments
 (0)