Skip to content

Commit

Permalink
Fix issue where a user is created when empty email and password is pa…
Browse files Browse the repository at this point in the history
…ssed (#5906)

* Fix issue where a user is created when passing an empty email and password

* Fix issue where a user is created when passing an empty email and password

---------

Co-authored-by: joehan <[email protected]>
  • Loading branch information
aalej and joehan authored Jun 1, 2023
1 parent 708efef commit ac21ab3
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
- Fix a bug preventing web framework's dev-mode from working out-of-box with Firebase Authentication. (#5894)
- Address additional cases where we were attempting to deploy a framework's development bundle (#5895)
- Fixes issue where Authentication emulator creates a user if empty email and empty password is provided. (#5639)
- Improve error message raised when `--import` flag directory does not exist. (#5851)
- Switch `ext:dev:init` to default 'billingRequired' to true in `extension.yaml`
- Remove `LOCATION` param from the `extensions.yaml` template for `ext:dev:init`
Expand Down
4 changes: 2 additions & 2 deletions src/emulator/auth/operations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,13 +198,13 @@ async function signUp(
}
}

if (reqBody.email) {
if (typeof reqBody.email === "string") {
assert(isValidEmailAddress(reqBody.email), "INVALID_EMAIL");
const email = canonicalizeEmailAddress(reqBody.email);
assert(!state.getUserByEmail(email), "EMAIL_EXISTS");
updates.email = email;
}
if (reqBody.password) {
if (typeof reqBody.password === "string") {
assert(
reqBody.password.length >= PASSWORD_MIN_LENGTH,
`WEAK_PASSWORD : Password should be at least ${PASSWORD_MIN_LENGTH} characters`
Expand Down
11 changes: 11 additions & 0 deletions src/test/emulators/auth/signUp.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,17 @@ describeAuthEmulator("accounts:signUp", ({ authApi }) => {
});
});

it("should throw error if empty email and password is provided", async () => {
await authApi()
.post("/identitytoolkit.googleapis.com/v1/accounts:signUp")
.send({ email: "", password: "" })
.query({ key: "fake-api-key" })
.then((res) => {
expectStatusCode(400, res);
expect(res.body.error).to.have.property("message").equals("INVALID_EMAIL");
});
});

it("should issue idToken and refreshToken on anon signUp", async () => {
await authApi()
.post("/identitytoolkit.googleapis.com/v1/accounts:signUp")
Expand Down

0 comments on commit ac21ab3

Please sign in to comment.