feat: v2 rate limiting (#16882)
* refactor: pass redis storage to throttler guard * chore: upgrade throttler to latest * feat: ApiKey RateLimit table * chore: upgrade redis storage throttler * feat: rate limit by api key * refactor: on delete api key cascade rate limit * fix: permissions guard work with oauth credentials * chore: set rate limit in env * tests: throttler * feat: include rate limit name in response * fix: correctly handle multiple rate limits * chore: remove unused import * delete migrations * chore: prisma migration * doc * dummy * fix: permissions guard unit test * refactor: remove route specific @Throttles * fix: permissions guard
This commit is contained in:
1 parent
9d3be8de03
commit
4b6a389212
15 files changed
+747
-80
No files matched your search
@@ -0,0 +1,22 @@
|
||||
import { PrismaWriteService } from "@/modules/prisma/prisma-write.service";
|
||||
import { TestingModule } from "@nestjs/testing";
|
||||
|
||||
export class RateLimitRepositoryFixture {
|
||||
private dbWrite: PrismaWriteService["prisma"];
|
||||
|
||||
constructor(private readonly module: TestingModule) {
|
||||
this.dbWrite = module.get(PrismaWriteService).prisma;
|
||||
}
|
||||
|
||||
async createRateLimit(name: string, apiKeyId: string, ttl: number, limit: number, blockDuration: number) {
|
||||
return await this.dbWrite.rateLimit.create({
|
||||
data: {
|
||||
name,
|
||||
apiKeyId,
|
||||
ttl,
|
||||
limit,
|
||||
blockDuration,
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -16,6 +16,10 @@ const env: Partial<Omit<Environment, "NODE_ENV">> = {
|
||||
API_KEY_PREFIX: "cal_test_",
|
||||
GET_LICENSE_KEY_URL: " https://console.cal.com/api/license",
|
||||
CALCOM_LICENSE_KEY: "c4234812-12ab-42s6-a1e3-55bedd4a5bb7",
|
||||
RATE_LIMIT_DEFAULT_TTL_MS: 60000,
|
||||
// note(Lauris): setting high limit so that e2e tests themselves are not rate limited
|
||||
RATE_LIMIT_DEFAULT_LIMIT: 10000,
|
||||
RATE_LIMIT_DEFAULT_BLOCK_DURATION_MS: 60000,
|
||||
};
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-ignore
|
||||
|
||||
Reference in new issue
Block a user