Skip to content

Commit

Permalink
add rate limiting
Browse files Browse the repository at this point in the history
Signed-off-by: Jason Sherman <[email protected]>
  • Loading branch information
usingtechnology committed Oct 1, 2024
1 parent 26ca355 commit cfd5a3b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
2 changes: 2 additions & 0 deletions app/src/forms/form/formMetadata/routes.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
const routes = require('express').Router();
const { currentUser, hasFormPermissions } = require('../../auth/middleware/userAccess');
const rateLimiter = require('../../common/middleware').apiKeyRateLimiter;
const validateParameter = require('../../common/middleware/validateParameter');
const P = require('../../common/constants').Permissions;

const controller = require('./controller');

routes.use(currentUser);
routes.use(rateLimiter);

routes.param('formId', validateParameter.validateFormId);

Expand Down
8 changes: 4 additions & 4 deletions app/tests/unit/forms/form/formMetadata/routes.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ describe(`${basePath}/:formId/formMetadata`, () => {
expect(apiAccess).toBeCalledTimes(0);
expect(controller.delete).toBeCalledTimes(1);
expect(hasFormPermissionsMock).toBeCalledTimes(1);
expect(rateLimiter.apiKeyRateLimiter).toBeCalledTimes(0);
expect(rateLimiter.apiKeyRateLimiter).toBeCalledTimes(1);
expect(userAccess.currentUser).toBeCalledTimes(1);
expect(validateParameter.validateFormId).toBeCalledTimes(1);
});
Expand All @@ -88,7 +88,7 @@ describe(`${basePath}/:formId/formMetadata`, () => {
expect(apiAccess).toBeCalledTimes(0);
expect(controller.read).toBeCalledTimes(1);
expect(hasFormPermissionsMock).toBeCalledTimes(1);
expect(rateLimiter.apiKeyRateLimiter).toBeCalledTimes(0);
expect(rateLimiter.apiKeyRateLimiter).toBeCalledTimes(1);
expect(userAccess.currentUser).toBeCalledTimes(1);
expect(validateParameter.validateFormId).toBeCalledTimes(1);
});
Expand All @@ -103,7 +103,7 @@ describe(`${basePath}/:formId/formMetadata`, () => {
expect(apiAccess).toBeCalledTimes(0);
expect(controller.create).toBeCalledTimes(1);
expect(hasFormPermissionsMock).toBeCalledTimes(1);
expect(rateLimiter.apiKeyRateLimiter).toBeCalledTimes(0);
expect(rateLimiter.apiKeyRateLimiter).toBeCalledTimes(1);
expect(userAccess.currentUser).toBeCalledTimes(1);
expect(validateParameter.validateFormId).toBeCalledTimes(1);
});
Expand All @@ -118,7 +118,7 @@ describe(`${basePath}/:formId/formMetadata`, () => {
expect(apiAccess).toBeCalledTimes(0);
expect(controller.update).toBeCalledTimes(1);
expect(hasFormPermissionsMock).toBeCalledTimes(1);
expect(rateLimiter.apiKeyRateLimiter).toBeCalledTimes(0);
expect(rateLimiter.apiKeyRateLimiter).toBeCalledTimes(1);
expect(userAccess.currentUser).toBeCalledTimes(1);
expect(validateParameter.validateFormId).toBeCalledTimes(1);
});
Expand Down

0 comments on commit cfd5a3b

Please sign in to comment.