vlucas/frisby

Request object not getting modified

agrawalarpit14 opened this issue · 8 comments

I have a middleware which attaches a UserId to the request object.(similar to the explanation in https://stackoverflow.com/questions/12518132/modifying-express-js-request-object) It functions properly while using the application. But while running frisby the request object is not getting modified.

Following is the middleware I used:

exports.appendUserId = () => {
  return (req, res, next) => {
    try {
      req.body.UserId = this.authenticatedUsers.tokenMap[utils.jwtFrom(req)].data.id
      console.log("UserId:", this.authenticatedUsers.tokenMap[utils.jwtFrom(req)].data.id)
      console.log("req.body.UserId:", req.body.UserId)

      req.body.UserId = 1
      console.log("req.body.UserId:", req.body.UserId)

      next()
    } catch (error) {
      res.status(401).json({ status: 'error', message: error })
    }
  }
}

Expected Terminal Output:

UserId: 2
req.body.UserId: 2
req.body.UserId: 1

Present Terminal Output:

UserId: 2
req.body.UserId: undefined
req.body.UserId: undefined

@agrawalarpit14

This code is server side.
How is frisby used on client side ?

Hi!! @H1Gdev Yes, the code is server side. Actually, here some values are attached to the request object after the req comes from the client side before actual processing is done.

Here frisby is used for checking the server side only.

You can take a look at the codebase here, if it helps.

Thank You!! so much

Are you sending the appropriate headers with JWT tokens from Frisby also?

Yeah, it's the exact same as I use on my frontend calls.😅

On the front-end, the browser is probably forwarding along cookies that have been set after you login. In Frisby, you have to set these yourself manually. Have you done that?

Hi @vlucas If I am ryt, cookies won't make any difference in this request(We don't use cookies in this component of the project).

Following, I'm also having the same problem. I can only attach things under req.headers but can't attach under different property names (e.g. req.cookies)

Oh I see. So this is code in Express.js that is somehow not working properly when hitting the API endpoint with Frisby.js? It seems pretty unlikely that Frisby.js itself would be the cause. Are you able to replicate this with another tool like Curl, HTTPie or RequestBin?

Frisby does not automatically save and re-use cookies from previous requests, so that might be the root issue here...