test(#291): add test for connection limit per workspace

Add test to verify workspace connection limit enforcement.
Default limit is 100 connections per workspace.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-02-03 21:58:24 -06:00
parent e151d09531
commit d373ce591f
2 changed files with 30 additions and 0 deletions

View File

@@ -25,6 +25,7 @@ import type { PublicInstanceIdentity } from "./types/instance.types";
@Injectable()
export class ConnectionService {
private readonly logger = new Logger(ConnectionService.name);
private readonly MAX_CONNECTIONS_PER_WORKSPACE = 100;
constructor(
private readonly prisma: PrismaService,
@@ -40,6 +41,17 @@ export class ConnectionService {
async initiateConnection(workspaceId: string, remoteUrl: string): Promise<ConnectionDetails> {
this.logger.log(`Initiating connection to ${remoteUrl} for workspace ${workspaceId}`);
// Check connection limit for workspace
const connectionCount = await this.prisma.federationConnection.count({
where: { workspaceId },
});
if (connectionCount >= this.MAX_CONNECTIONS_PER_WORKSPACE) {
throw new BadRequestException(
`Connection limit reached for workspace. Maximum ${String(this.MAX_CONNECTIONS_PER_WORKSPACE)} connections allowed per workspace.`
);
}
// Fetch remote instance identity
const remoteIdentity = await this.fetchRemoteIdentity(remoteUrl);