Skip to content

Commit 0406ed5

Browse files
authored
fix(auth): Fixed error code mapping for Auth errors (#1121)
1 parent ae5537e commit 0406ed5

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
@@ -187,7 +187,7 @@ String buildMessage(AuthServiceErrorResponse response) {
187187

188188
/**
189189
* JSON data binding for JSON error messages sent by Google identity toolkit service. These
190-
* error messages take the form `{"error": {"message": "CODE: OPTIONAL DETAILS"}}`.
190+
* error messages take the form `{"error": {"message": "CODE : OPTIONAL DETAILS"}}`.
191191
*/
192192
private static class AuthServiceErrorResponse {
193193

@@ -203,7 +203,7 @@ public String getCode() {
203203

204204
int separator = message.indexOf(':');
205205
if (separator != -1) {
206-
return message.substring(0, separator);
206+
return message.substring(0, separator).trim();
207207
}
208208

209209
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)