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:
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user