-
-
Notifications
You must be signed in to change notification settings - Fork 481
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The cookies object recevied in the handlers varies depending on the placement of the handler within the setupServer
function.
#2126
Comments
Hi, @NZepeda! It may not be the best idea to use I also have a concern that you aren't testing anything in your test: https://github.com/NZepeda/msw-cookies-example/blob/d7d900d6e0202c8b8a522b1c88b4958b8782c181/src/test/mock.test.ts. What the test cases assert right now is that MSW handles cookies correctly. If this is a trimmed test case you created to illustrate the issue then it's okay. But if it's not, don't test third-party libraries, test your code instead. |
Hi @kettanaito, What we are trying to simulate is a prod setup with an Http-Only, Secure cookie. Is there no way to set this up in This is related to #1586 |
Since you cannot read the HttpOnly cookie in JavaScript, what would you test then? Nothing in your application can depend on it. I suspect you are talking about forwarding that cookie to the server request (i.e. credentials)? If that's the case, it's done by the browser for you. Please tell me more about your test case. |
We use a cookie to authenticate a WebSocket connection to the server. When the UI assets (JS, HTML, css, etc.) are served by the server itself (which is the deployment that we recommended), then when you try connecting to the UI, you must first pass the Spring security layer before the UI assets can be fetched. We are looking to test all this authentication flow with |
To add on to this, @kettanaito, as you recommended above, I've removed usage of the For the test, I've set up a Within the test suite itself, I set the session cookie once by mutating This seems like a bug within For more clarity:
This is the value of the
Can you confirm whether or not this is expected? |
Prerequisites
Environment check
msw
versionNode.js version
18.12.1
Reproduction repository
https://github.com/NZepeda/msw-cookies-example
Reproduction steps
git clone https://github.com/NZepeda/msw-cookies-example
cd msw-cookies-example
pnpm install
pnpm test mock
Current behavior
In my test, I've set the cookie to be sent with the request via the
store.add
function of@mswjs/cookies
. I have a few handlers for myserver
that check the received cookie from the request and test it against a static stringauthorizedSessionCookieValue
.The first test passes as the received cookie value is the same as
authorizedSessionCookieValue
, but the second test fails. This seems to be due to the placement of the handler within thesetupServer
function. It seems like the first handler (which the first test hits) receives the correct cookie value, in my case{ MyCookie: 'ABCD1234' }
, however, the third handler (which the second test hits) receives a cookie value of{ MyCookie: 'ABCD1234, MyCookie=ABCD1234' }
, which causes the test to fail.Expected behavior
I would expect the received
cookies
object from each handler to be the same.The text was updated successfully, but these errors were encountered: