-
-
Notifications
You must be signed in to change notification settings - Fork 792
test: consume bodies of fetch responses to fix failing macos 20 ci #4528
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
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
a003112
test: warmup for macos and node 20
Uzlopak cd4f73e
Merge branch 'main' into warmup-macos-encoding
Uzlopak 04081e9
refactor cookies.js
Uzlopak c654323
Merge branch 'main' into warmup-macos-encoding
Uzlopak 15bcb46
maybe tspl is the culprit
Uzlopak 234c00f
eat this
Uzlopak 4011b8d
cookie
Uzlopak fb9e3bf
fix
Uzlopak 33f7fb4
await the text
Uzlopak f4cc9a5
fix remarks
Uzlopak 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,111 +1,114 @@ | ||
| 'use strict' | ||
|
|
||
| const { strictEqual, deepStrictEqual } = require('node:assert').strict | ||
| const { once } = require('node:events') | ||
| const { createServer } = require('node:http') | ||
| const { test } = require('node:test') | ||
| const assert = require('node:assert') | ||
| const { tspl } = require('@matteo.collina/tspl') | ||
| const { test, describe, before, after } = require('node:test') | ||
| const { stringify: qsStringify } = require('node:querystring') | ||
| const { Client, fetch, Headers } = require('../..') | ||
| const { closeServerAsPromise } = require('../utils/node-http') | ||
| const pem = require('@metcoder95/https-pem') | ||
| const { createSecureServer } = require('node:http2') | ||
| const { closeClientAndServerAsPromise } = require('../utils/node-http') | ||
|
|
||
| test('Can receive set-cookie headers from a server using fetch - issue #1262', async (t) => { | ||
| const server = createServer({ joinDuplicateHeaders: true }, (req, res) => { | ||
| res.setHeader('set-cookie', 'name=value; Domain=example.com') | ||
| res.end() | ||
| }).listen(0) | ||
| describe('cookies', () => { | ||
| let server | ||
|
|
||
| t.after(closeServerAsPromise(server)) | ||
| await once(server, 'listening') | ||
|
|
||
| const response = await fetch(`http://localhost:${server.address().port}`) | ||
|
|
||
| assert.strictEqual(response.headers.get('set-cookie'), 'name=value; Domain=example.com') | ||
| before(() => { | ||
| server = createServer({ joinDuplicateHeaders: true }, (req, res) => { | ||
| const searchParams = new URL(req.url, 'http://localhost').searchParams | ||
| if (searchParams.has('set-cookie')) { | ||
| res.setHeader('set-cookie', searchParams.get('set-cookie')) | ||
| } | ||
| res.end(req.headers.cookie) | ||
| }) | ||
|
|
||
| const response2 = await fetch(`http://localhost:${server.address().port}`, { | ||
| credentials: 'include' | ||
| return once(server.listen(0), 'listening') | ||
| }) | ||
|
Uzlopak marked this conversation as resolved.
|
||
|
|
||
| assert.strictEqual(response2.headers.get('set-cookie'), 'name=value; Domain=example.com') | ||
| }) | ||
|
|
||
| test('Can send cookies to a server with fetch - issue #1463', async (t) => { | ||
| const server = createServer({ joinDuplicateHeaders: true }, (req, res) => { | ||
| assert.strictEqual(req.headers.cookie, 'value') | ||
| res.end() | ||
| }).listen(0) | ||
|
|
||
| t.after(closeServerAsPromise(server)) | ||
| await once(server, 'listening') | ||
|
|
||
| const headersInit = [ | ||
| new Headers([['cookie', 'value']]), | ||
| { cookie: 'value' }, | ||
| [['cookie', 'value']] | ||
| ] | ||
| after(() => { | ||
| server.close() | ||
| return once(server, 'close') | ||
|
Uzlopak marked this conversation as resolved.
|
||
| }) | ||
|
|
||
| for (const headers of headersInit) { | ||
| await fetch(`http://localhost:${server.address().port}`, { headers }) | ||
| } | ||
| }) | ||
| test('Can receive set-cookie headers from a server using fetch - issue #1262', async () => { | ||
| const query = qsStringify({ | ||
| 'set-cookie': 'name=value; Domain=example.com' | ||
| }) | ||
| const response = await fetch(`http://localhost:${server.address().port}?${query}`) | ||
|
|
||
| test('Cookie header is delimited with a semicolon rather than a comma - issue #1905', async (t) => { | ||
| const { strictEqual } = tspl(t, { plan: 1 }) | ||
| strictEqual(response.headers.get('set-cookie'), 'name=value; Domain=example.com') | ||
| strictEqual(await response.text(), '') | ||
|
|
||
| const server = createServer({ joinDuplicateHeaders: true }, (req, res) => { | ||
| strictEqual(req.headers.cookie, 'FOO=lorem-ipsum-dolor-sit-amet; BAR=the-quick-brown-fox') | ||
| res.end() | ||
| }).listen(0) | ||
| const response2 = await fetch(`http://localhost:${server.address().port}?${query}`, { | ||
| credentials: 'include' | ||
| }) | ||
|
|
||
| t.after(closeServerAsPromise(server)) | ||
| await once(server, 'listening') | ||
| strictEqual(response2.headers.get('set-cookie'), 'name=value; Domain=example.com') | ||
| strictEqual(await response2.text(), '') | ||
| }) | ||
|
|
||
| await fetch(`http://localhost:${server.address().port}`, { | ||
| headers: [ | ||
| ['cookie', 'FOO=lorem-ipsum-dolor-sit-amet'], | ||
| ['cookie', 'BAR=the-quick-brown-fox'] | ||
| test('Can send cookies to a server with fetch - issue #1463', async () => { | ||
| const headersInit = [ | ||
| new Headers([['cookie', 'value']]), | ||
| { cookie: 'value' }, | ||
| [['cookie', 'value']] | ||
| ] | ||
|
|
||
| for (const headers of headersInit) { | ||
| const response = await fetch(`http://localhost:${server.address().port}`, { headers }) | ||
| const text = await response.text() | ||
| strictEqual(text, 'value') | ||
| } | ||
| }) | ||
| }) | ||
|
|
||
| test('Can receive set-cookie headers from a http2 server using fetch - issue #2885', async (t) => { | ||
| const server = createSecureServer(pem) | ||
| server.on('stream', async (stream, headers) => { | ||
| stream.respond({ | ||
| 'content-type': 'text/plain; charset=utf-8', | ||
| 'x-method': headers[':method'], | ||
| 'set-cookie': 'Space=Cat; Secure; HttpOnly', | ||
| ':status': 200 | ||
| test('Cookie header is delimited with a semicolon rather than a comma - issue #1905', async () => { | ||
| const response = await fetch(`http://localhost:${server.address().port}`, { | ||
| headers: [ | ||
| ['cookie', 'FOO=lorem-ipsum-dolor-sit-amet'], | ||
| ['cookie', 'BAR=the-quick-brown-fox'] | ||
| ] | ||
| }) | ||
|
|
||
| stream.end('test') | ||
| strictEqual(await response.text(), 'FOO=lorem-ipsum-dolor-sit-amet; BAR=the-quick-brown-fox') | ||
| }) | ||
|
|
||
| server.listen() | ||
| await once(server, 'listening') | ||
| test('Can receive set-cookie headers from a http2 server using fetch - issue #2885', async () => { | ||
| const server = createSecureServer(pem) | ||
| server.on('stream', (stream, headers) => { | ||
| stream.respond({ | ||
| 'content-type': 'text/plain; charset=utf-8', | ||
| 'x-method': headers[':method'], | ||
| 'set-cookie': 'Space=Cat; Secure; HttpOnly', | ||
| ':status': 200 | ||
| }) | ||
|
|
||
| stream.end('test') | ||
| }) | ||
|
|
||
| const client = new Client(`https://localhost:${server.address().port}`, { | ||
| connect: { | ||
| rejectUnauthorized: false | ||
| }, | ||
| allowH2: true | ||
| }) | ||
| await once(server.listen(0), 'listening') | ||
|
|
||
| const client = new Client(`https://localhost:${server.address().port}`, { | ||
| connect: { | ||
| rejectUnauthorized: false | ||
| }, | ||
| allowH2: true | ||
| }) | ||
|
|
||
| const response = await fetch( | ||
| `https://localhost:${server.address().port}/`, | ||
| // Needs to be passed to disable the reject unauthorized | ||
| { | ||
| method: 'GET', | ||
| dispatcher: client, | ||
| headers: { | ||
| 'content-type': 'text-plain' | ||
| const response = await fetch( | ||
| `https://localhost:${server.address().port}/`, | ||
| // Needs to be passed to disable the reject unauthorized | ||
| { | ||
| method: 'GET', | ||
| dispatcher: client, | ||
| headers: { | ||
| 'content-type': 'text-plain' | ||
| } | ||
| } | ||
| } | ||
| ) | ||
| ) | ||
|
|
||
| t.after(closeClientAndServerAsPromise(client, server)) | ||
| deepStrictEqual(response.headers.getSetCookie(), ['Space=Cat; Secure; HttpOnly']) | ||
| strictEqual(await response.text(), 'test') | ||
|
|
||
| assert.deepStrictEqual(response.headers.getSetCookie(), ['Space=Cat; Secure; HttpOnly']) | ||
| await client.close() | ||
| await new Promise((resolve, reject) => server.close(err => err ? reject(err) : resolve())) | ||
|
Uzlopak marked this conversation as resolved.
Uzlopak marked this conversation as resolved.
|
||
| }) | ||
| }) | ||
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.