mirror of
https://github.com/outline/outline.git
synced 2026-06-13 11:25:03 +03:00
fix: Allow user account lookup with mismatching email capitalization (#9929)
This commit is contained in:
@@ -16,7 +16,7 @@ describe("accountProvisioner", () => {
|
||||
describe("hosted", () => {
|
||||
it("should create a new user and team", async () => {
|
||||
const spy = jest.spyOn(WelcomeEmail.prototype, "schedule");
|
||||
const email = faker.internet.email().toLowerCase();
|
||||
const email = faker.internet.email();
|
||||
const { user, team, isNewTeam, isNewUser } = await accountProvisioner(
|
||||
ctx,
|
||||
{
|
||||
@@ -71,7 +71,7 @@ describe("accountProvisioner", () => {
|
||||
});
|
||||
const authentications = await existing.$get("authentications");
|
||||
const authentication = authentications[0];
|
||||
const newEmail = faker.internet.email().toLowerCase();
|
||||
const newEmail = faker.internet.email();
|
||||
const { user, isNewUser, isNewTeam } = await accountProvisioner(ctx, {
|
||||
user: {
|
||||
name: existing.name,
|
||||
@@ -113,7 +113,7 @@ describe("accountProvisioner", () => {
|
||||
|
||||
const providers = await existingTeam.$get("authenticationProviders");
|
||||
const authenticationProvider = providers[0];
|
||||
const email = faker.internet.email().toLowerCase();
|
||||
const email = faker.internet.email();
|
||||
const userWithoutAuth = await buildUser({
|
||||
email,
|
||||
teamId: existingTeam.id,
|
||||
@@ -245,7 +245,7 @@ describe("accountProvisioner", () => {
|
||||
const admin = await buildAdmin({ teamId: existingTeam.id });
|
||||
const providers = await existingTeam.$get("authenticationProviders");
|
||||
const authenticationProvider = providers[0];
|
||||
const email = faker.internet.email().toLowerCase();
|
||||
const email = faker.internet.email();
|
||||
|
||||
await TeamDomain.create({
|
||||
teamId: existingTeam.id,
|
||||
@@ -344,7 +344,7 @@ describe("accountProvisioner", () => {
|
||||
"authenticationProviders"
|
||||
);
|
||||
const authenticationProvider = authenticationProviders[0];
|
||||
const email = faker.internet.email().toLowerCase();
|
||||
const email = faker.internet.email();
|
||||
const { user, isNewUser } = await accountProvisioner(ctx, {
|
||||
user: {
|
||||
name: "Jenny Tester",
|
||||
@@ -384,6 +384,53 @@ describe("accountProvisioner", () => {
|
||||
|
||||
spy.mockRestore();
|
||||
});
|
||||
|
||||
it("should handle emails with capital letters correctly", async () => {
|
||||
const spy = jest.spyOn(WelcomeEmail.prototype, "schedule");
|
||||
const email = "Jenny.Tester@EXAMPLE.COM";
|
||||
|
||||
const params = {
|
||||
user: {
|
||||
name: "Jenny Tester",
|
||||
email,
|
||||
avatarUrl: faker.image.avatar(),
|
||||
},
|
||||
team: {
|
||||
name: "New workspace",
|
||||
avatarUrl: faker.image.avatar(),
|
||||
subdomain: faker.internet.domainWord(),
|
||||
},
|
||||
authenticationProvider: {
|
||||
name: "google",
|
||||
providerId: faker.internet.domainName(),
|
||||
},
|
||||
authentication: {
|
||||
providerId: uuidv4(),
|
||||
accessToken: "123",
|
||||
scopes: ["read"],
|
||||
},
|
||||
};
|
||||
|
||||
const { user, isNewTeam, isNewUser } = await accountProvisioner(
|
||||
ctx,
|
||||
params
|
||||
);
|
||||
|
||||
expect(user.email).toEqual(email);
|
||||
expect(isNewUser).toEqual(true);
|
||||
expect(isNewTeam).toEqual(true);
|
||||
expect(spy).toHaveBeenCalled();
|
||||
|
||||
// Test that we can find the user again
|
||||
const existing = await accountProvisioner(ctx, params);
|
||||
|
||||
expect(user.email).toEqual(email);
|
||||
expect(existing.isNewTeam).toEqual(false);
|
||||
expect(existing.isNewUser).toEqual(false);
|
||||
expect(existing.user.id).toEqual(user.id);
|
||||
|
||||
spy.mockRestore();
|
||||
});
|
||||
});
|
||||
|
||||
describe("self hosted", () => {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { InferCreationAttributes } from "sequelize";
|
||||
import { InferCreationAttributes, Op } from "sequelize";
|
||||
import { UserRole } from "@shared/types";
|
||||
import InviteAcceptedEmail from "@server/emails/templates/InviteAcceptedEmail";
|
||||
import {
|
||||
@@ -111,9 +111,10 @@ export default async function userProvisioner(
|
||||
"withTeam",
|
||||
]).findOne({
|
||||
where: {
|
||||
// Email from auth providers may be capitalized and we should respect that
|
||||
// however any existing invites will always be lowercased.
|
||||
email: email.toLowerCase(),
|
||||
// Email from auth providers may be capitalized
|
||||
email: {
|
||||
[Op.iLike]: email,
|
||||
},
|
||||
teamId,
|
||||
},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user