-
Notifications
You must be signed in to change notification settings - Fork 4.9k
fix(routeFromHAR): hack harRouter to merge set-cookie headers #38255
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
Open
yepitschunked
wants to merge
1
commit into
microsoft:main
Choose a base branch
from
yepitschunked:fix_multiple_setcookie
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+24
−1
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -358,6 +358,14 @@ it('should record overridden requests to har', async ({ contextFactory, server } | |
| expect(await page2.evaluate(fetchFunction, { path: '/echo', body: '12' })).toBe('12'); | ||
| }); | ||
|
|
||
| it('should replay requests with multiple set-cookie headers properly', async ({ context, asset }) => { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's also add a test for recording and replaying a multicookie: diff --git i/tests/library/browsercontext-har.spec.ts w/tests/library/browsercontext-har.spec.ts
index 6e6404590..4f5c39581 100644
--- i/tests/library/browsercontext-har.spec.ts
+++ w/tests/library/browsercontext-har.spec.ts
@@ -452,6 +452,33 @@ it('should ignore boundary when matching multipart/form-data body', {
await expect(page2.locator('div')).toHaveText('done');
});
+it('should record multiple set-cookie headers', {
+ annotation: { type: 'issue', description: 'https://github.com/microsoft/playwright/issues/31495' }
+}, async ({ contextFactory, server }, testInfo) => {
+ server.setRoute('/empty.html', (req, res) => {
+ res.setHeader('Content-Type', 'text/html');
+ res.setHeader('set-cookie', ['first=foo', 'second=bar']);
+ res.end();
+ });
+
+ const harPath = testInfo.outputPath('har.zip');
+ console.log('HAR path:', harPath);
+ const context1 = await contextFactory();
+ await context1.routeFromHAR(harPath, { update: true });
+ const page1 = await context1.newPage();
+ await page1.goto(server.EMPTY_PAGE);
+ const cookie1 = await page1.evaluate(() => document.cookie);
+ expect(cookie1.split('; ').sort().join('; ')).toBe('first=foo; second=bar');
+ await context1.close();
+
+ const context2 = await contextFactory();
+ await context2.routeFromHAR(harPath, { notFound: 'abort' });
+ const page2 = await context2.newPage();
+ await page2.goto(server.EMPTY_PAGE);
+ const cookie2 = await page2.evaluate(() => document.cookie);
+ expect(cookie2.split('; ').sort().join('; ')).toBe('first=foo; second=bar');
+});
+
it('should update har.zip for page', async ({ contextFactory, server }, testInfo) => {
const harPath = testInfo.outputPath('har.zip');
const context1 = await contextFactory(); |
||
| const path = asset('har-fulfill.har'); | ||
| await context.routeFromHAR(path); | ||
| const page = await context.newPage(); | ||
| await page.goto('http://no.playwright/'); | ||
| expect(await page.context().cookies()).toEqual([expect.objectContaining({ name: 'playwright', value: 'works' }), expect.objectContaining({ name: 'with', value: 'multiple-set-cookie-headers' })]); | ||
| }); | ||
|
|
||
| it('should disambiguate by header', async ({ contextFactory, server }, testInfo) => { | ||
| server.setRoute('/echo', async (req, res) => { | ||
| res.end(req.headers['baz']); | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will delete
set-cookieheader if there is only one entry. Let's add a test for that case. Also let's not take original headers array if there is no set-cookie header.