routing-controllers icon indicating copy to clipboard operation
routing-controllers copied to clipboard

fix: execute authMiddlewares before any middlewares

Open killix opened this issue 3 years ago • 5 comments

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 Screen Shot 2021-04-05 at 5 35 32 PM

Expected behavior

Screen Shot 2021-04-05 at 5 37 08 PM

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

killix avatar Apr 05 '21 21:04 killix

hurray!!! hopefully this gets merged soon.

AgentGoldPaw avatar Apr 13 '21 22:04 AgentGoldPaw

Please, cover these changes with unit tests

qdanik avatar Apr 18 '21 22:04 qdanik

Please, cover these changes with unit tests

Look no tests exist for middleware, I am wrong?

killix avatar May 06 '21 15:05 killix

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

apgapg avatar May 13 '21 15:05 apgapg

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).

jotamorais avatar Aug 04 '21 20:08 jotamorais

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.

github-actions[bot] avatar Oct 13 '23 01:10 github-actions[bot]