Skip to content

Commit 540d073

Browse files
committed
fix(auth): Fixed error code mapping for Auth errors
1 parent 212ecea commit 540d073

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

src/main/java/com/google/firebase/auth/internal/AuthErrorHandler.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ String buildMessage(AuthServiceErrorResponse response) {
180180

181181
/**
182182
* JSON data binding for JSON error messages sent by Google identity toolkit service. These
183-
* error messages take the form `{"error": {"message": "CODE: OPTIONAL DETAILS"}}`.
183+
* error messages take the form `{"error": {"message": "CODE : OPTIONAL DETAILS"}}`.
184184
*/
185185
private static class AuthServiceErrorResponse {
186186

@@ -196,7 +196,7 @@ public String getCode() {
196196

197197
int separator = message.indexOf(':');
198198
if (separator != -1) {
199-
return message.substring(0, separator);
199+
return message.substring(0, separator).trim();
200200
}
201201

202202
return message;

src/test/java/com/google/firebase/auth/FirebaseAuthIT.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ public class FirebaseAuthIT {
8282
private static final JsonFactory jsonFactory = ApiClientUtils.getDefaultJsonFactory();
8383
private static final HttpTransport transport = ApiClientUtils.getDefaultTransport();
8484
private static final String ACTION_LINK_CONTINUE_URL = "http://localhost/?a=1&b=2#c=3";
85+
private static final String INVALID_ACTION_LINK_CONTINUE_URL = "http://www.localhost/?a=1&b=2#c=3";
8586

8687
private static final FirebaseAuth auth = FirebaseAuth.getInstance(
8788
IntegrationTestUtils.ensureDefaultApp());
@@ -868,6 +869,31 @@ public void testGenerateSignInWithEmailLink() throws Exception {
868869
assertTrue(auth.getUser(user.getUid()).isEmailVerified());
869870
}
870871

872+
@Test
873+
public void testAuthErrorCodeParse() throws Exception {
874+
RandomUser user = UserTestUtils.generateRandomUserInfo();
875+
temporaryUser.create(new UserRecord.CreateRequest()
876+
.setUid(user.getUid())
877+
.setEmail(user.getEmail())
878+
.setEmailVerified(false)
879+
.setPassword("password"));
880+
try {
881+
auth.generateSignInWithEmailLink(user.getEmail(), ActionCodeSettings.builder()
882+
.setUrl(INVALID_ACTION_LINK_CONTINUE_URL)
883+
.build());
884+
fail("No error thrown for invlaid custom hosting domain");
885+
} catch (FirebaseAuthException e) {
886+
assertEquals(
887+
"The domain of the continue URL is not whitelisted (UNAUTHORIZED_DOMAIN): Domain not "
888+
+ "allowlisted by project",
889+
e.getMessage());
890+
assertEquals(ErrorCode.INVALID_ARGUMENT, e.getErrorCode());
891+
assertNotNull(e.getCause());
892+
assertNotNull(e.getHttpResponse());
893+
assertEquals(AuthErrorCode.UNAUTHORIZED_CONTINUE_URL, e.getAuthErrorCode());
894+
}
895+
}
896+
871897
@Test
872898
public void testOidcProviderConfigLifecycle() throws Exception {
873899
// Create provider config

0 commit comments

Comments
 (0)