fix: Validate provider details when connecting authentication (#14704)

* fix: Validate provider details when connecting authentication

* fix: Limit provider validation to personal Google accounts

* fix: Only validate provider details when connecting a new provider
This commit is contained in:
Tom Moor authored and GitHub committed 2026-11-26 01:29:07 +00:00
1 parent 4f25f3854e
commit e622b016fc
2 files changed
+70

No files matched your search

@@ -893,6 +893,70 @@ describe("accountProvisioner", () => {
expect(isNewUser).toEqual(false);
});
it("should not connect or reconnect an authentication provider with an empty providerId", async () => {
const admin = await buildAdmin();
const team = admin.team;
const [existingProvider] = await team.$get("authenticationProviders");
await expect(
accountProvisioner(createContext({ ip, user: admin }), {
user: {
name: admin.name,
email: admin.email!,
},
team: {
teamId: team.id,
subdomain: team.subdomain!,
},
authenticationProvider: {
name: existingProvider.name,
providerId: "",
},
authentication: {
providerId: randomUUID(),
scopes: ["read"],
},
})
).rejects.toThrow();
const providers = await team.$get("authenticationProviders");
expect(providers.length).toEqual(1);
expect(providers[0].providerId).toEqual(existingProvider.providerId);
});
it("should allow an admin through an already connected provider with an empty providerId", async () => {
const team = await buildTeam({
authenticationProviders: [{ name: "discord", providerId: "" }],
});
const admin = await buildAdmin({ teamId: team.id });
const { user } = await accountProvisioner(
createContext({ ip, user: admin }),
{
user: {
name: admin.name,
email: admin.email!,
},
team: {
teamId: team.id,
subdomain: team.subdomain!,
},
authenticationProvider: {
name: "discord",
providerId: "",
},
authentication: {
providerId: randomUUID(),
scopes: ["read"],
},
}
);
expect(user.id).toEqual(admin.id);
const providers = await team.$get("authenticationProviders");
expect(providers.length).toEqual(1);
});
it("should add an authentication provider when the team has several of the same type", async () => {
const team = await buildTeam({
authenticationProviders: [
+6
View File
@@ -117,6 +117,12 @@ async function accountProvisioner(
provider.providerId === authenticationProviderParams.providerId
);
if (!isConnected && !authenticationProviderParams.providerId) {
throw InvalidAuthenticationError(
"A personal account cannot be used to connect a sign-in provider"
);
}
if (!isConnected && providers.length === 1) {
// Update in place so that existing user authentications stay linked.
await sequelize.transaction((transaction) =>