mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-18 18:41:14 +00:00
fix(core): Don't allow creating more projects than allowed by exploiting a race condition (#15218)
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import { GlobalConfig } from '@n8n/config';
|
||||
import type { Project } from '@n8n/db';
|
||||
import { FolderRepository } from '@n8n/db';
|
||||
import { ProjectRelationRepository } from '@n8n/db';
|
||||
@@ -432,6 +433,34 @@ describe('POST /projects/', () => {
|
||||
|
||||
expect(await Container.get(ProjectRepository).count({ where: { type: 'team' } })).toBe(2);
|
||||
});
|
||||
|
||||
const globalConfig = Container.get(GlobalConfig);
|
||||
// Preventing this relies on transactions and we can't use them with the
|
||||
// sqlite legacy driver due to data loss risks.
|
||||
if (!globalConfig.database.isLegacySqlite) {
|
||||
test('should respect the quota when trying to create multiple projects in parallel (no race conditions)', async () => {
|
||||
expect(await Container.get(ProjectRepository).count({ where: { type: 'team' } })).toBe(0);
|
||||
testServer.license.setQuota('quota:maxTeamProjects', 3);
|
||||
const ownerUser = await createOwner();
|
||||
const ownerAgent = testServer.authAgentFor(ownerUser);
|
||||
await expect(
|
||||
Container.get(ProjectRepository).count({ where: { type: 'team' } }),
|
||||
).resolves.toBe(0);
|
||||
|
||||
await Promise.all([
|
||||
ownerAgent.post('/projects/').send({ name: 'Test Team Project 1' }),
|
||||
ownerAgent.post('/projects/').send({ name: 'Test Team Project 2' }),
|
||||
ownerAgent.post('/projects/').send({ name: 'Test Team Project 3' }),
|
||||
ownerAgent.post('/projects/').send({ name: 'Test Team Project 4' }),
|
||||
ownerAgent.post('/projects/').send({ name: 'Test Team Project 5' }),
|
||||
ownerAgent.post('/projects/').send({ name: 'Test Team Project 6' }),
|
||||
]);
|
||||
|
||||
await expect(
|
||||
Container.get(ProjectRepository).count({ where: { type: 'team' } }),
|
||||
).resolves.toBe(3);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
describe('PATCH /projects/:projectId', () => {
|
||||
|
||||
Reference in New Issue
Block a user