Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
- Fix bug where functions:artifacts:setpolicy command's --none option didn't work as expected (#8330)
- Fix bug in Auth emulator where accounts:lookup is case-sensitive for emails (#8344)
48 changes: 48 additions & 0 deletions src/emulator/auth/misc.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@
.query({ key: "fake-api-key" })
.then((res) => {
expectStatusCode(200, res);
expect(res.body.id_token).to.be.a("string");

Check warning on line 35 in src/emulator/auth/misc.spec.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe member access .id_token on an `any` value
expect(res.body.access_token).to.equal(res.body.id_token);

Check warning on line 36 in src/emulator/auth/misc.spec.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe member access .access_token on an `any` value

Check warning on line 36 in src/emulator/auth/misc.spec.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe member access .id_token on an `any` value
expect(res.body.refresh_token).to.be.a("string");

Check warning on line 37 in src/emulator/auth/misc.spec.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe member access .refresh_token on an `any` value
expect(res.body.expires_in)

Check warning on line 38 in src/emulator/auth/misc.spec.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe member access .expires_in on an `any` value
.to.be.a("string")
.matches(/[0-9]+/);
expect(res.body.project_id).to.equal("12345");

Check warning on line 41 in src/emulator/auth/misc.spec.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe member access .project_id on an `any` value
expect(res.body.token_type).to.equal("Bearer");

Check warning on line 42 in src/emulator/auth/misc.spec.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe member access .token_type on an `any` value
expect(res.body.user_id).to.equal(localId);

Check warning on line 43 in src/emulator/auth/misc.spec.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe member access .user_id on an `any` value
});
});

Expand All @@ -63,8 +63,8 @@
.query({ key: "fake-api-key" })
.then((res) => {
expectStatusCode(200, res);
expect(res.body.id_token).to.be.a("string");

Check warning on line 66 in src/emulator/auth/misc.spec.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe member access .id_token on an `any` value
expect(res.body.access_token).to.equal(res.body.id_token);

Check warning on line 67 in src/emulator/auth/misc.spec.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe member access .access_token on an `any` value
expect(res.body.refresh_token).to.be.a("string");
expect(res.body.expires_in)
.to.be.a("string")
Expand Down Expand Up @@ -339,6 +339,54 @@
});

describeAuthEmulator("accounts:lookup", ({ authApi }) => {
it("should return user by email when privileged", async () => {
const { email } = await registerUser(authApi(), {
email: "bob@example.com",
password: "password",
});

await authApi()
.post(`/identitytoolkit.googleapis.com/v1/projects/${PROJECT_ID}/accounts:lookup`)
.set("Authorization", "Bearer owner")
Comment thread Dismissed
.send({ email: [email] })
.then((res) => {
expectStatusCode(200, res);
expect(res.body.users).to.have.length(1);
expect(res.body.users[0].email).to.equal(email);
});
});

it("should return user by email even when uppercased", async () => {
const { email } = await registerUser(authApi(), {
email: "foo@example.com",
password: "password",
});
const caplitalizedEmail = email.toUpperCase();

await authApi()
.post(`/identitytoolkit.googleapis.com/v1/projects/${PROJECT_ID}/accounts:lookup`)
.set("Authorization", "Bearer owner")
Comment thread Dismissed
.send({ email: [caplitalizedEmail] })
.then((res) => {
console.log(res.body.users);
expectStatusCode(200, res);
expect(res.body.users).to.have.length(1);
expect(res.body.users[0].email).to.equal(email);
});
});

it("should return empty result when email is not found", async () => {
await authApi()
.post(`/identitytoolkit.googleapis.com/v1/projects/${PROJECT_ID}/accounts:lookup`)
.set("Authorization", "Bearer owner")
Comment thread Dismissed
.send({ email: ["non-existent-email@example.com"] })
.then((res) => {
console.log(res.body.users);
expectStatusCode(200, res);
expect(res.body).not.to.have.property("users");
});
});

it("should return user by localId when privileged", async () => {
const { localId } = await registerAnonUser(authApi());

Expand Down
3 changes: 2 additions & 1 deletion src/emulator/auth/operations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,8 @@ function lookup(
tryAddUser(state.getUserByLocalId(localId));
}
for (const email of reqBody.email ?? []) {
tryAddUser(state.getUserByEmail(email));
const canonicalizedEmail = canonicalizeEmailAddress(email);
tryAddUser(state.getUserByEmail(canonicalizedEmail));
}
for (const phoneNumber of reqBody.phoneNumber ?? []) {
tryAddUser(state.getUserByPhoneNumber(phoneNumber));
Expand Down
Loading