routing-controllers
routing-controllers copied to clipboard
fix: execute authMiddlewares before any middlewares
Description
The authorization checker is executed after the middlewares (beforeMiddlewares). This not really make sens when you want to limit access to resources.
Actual behavior
Expected behavior
Checklist
- [x] the pull request title describes what this PR does (not a vague title like
Update index.md
) - [x] the pull request targets the default branch of the repository (
develop
) - [x] the code follows the established code style of the repository
-
npm run prettier:check
passes -
npm run lint:check
passes
-
- [ ] tests are added for the changes I made (if any source code was modified)
- [ ] documentation added or updated
- [x] I have run the project locally and verified that there are no errors
Fixes
fixes #697
hurray!!! hopefully this gets merged soon.
Please, cover these changes with unit tests
Please, cover these changes with unit tests
Look no tests exist for middleware, I am wrong?
Hi This is actually causing no parsing middleware to run. For eg to get cookies I need to do that manually because app.use(cookieParser())
isn't being executed before authchecker.
authorizationChecker: async (action: Action, roles: string[]) => {
try {
// Get cookies and parse them
const cookies = cookie.parse(action.request.headers.cookie)
I now have to do this manually. Similar goes for req.session
Please, cover these changes with unit tests
Look no tests exist for middleware, I am wrong?
We do have tests for middleware at /test/functional/middlewares-order.spec.ts and /test/functional/express-middlewares.spec.ts but for some reason jest is not including them nor do the coverage report shows them. This PR should include the test coverage (with the existing scenarios and any other you can think of).
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.