-
Notifications
You must be signed in to change notification settings - Fork 7.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(core): Prevent invalid compressed responses from making execution…
…s stuck forever (#8315)
- Loading branch information
Showing
2 changed files
with
40 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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 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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { Readable } from 'node:stream'; | ||
import { createGunzip } from 'node:zlib'; | ||
import { toBuffer } from '@/BinaryData/utils'; | ||
|
||
describe('BinaryData/utils', () => { | ||
describe('toBuffer', () => { | ||
it('should handle buffer objects', async () => { | ||
const body = Buffer.from('test'); | ||
expect((await toBuffer(body)).toString()).toEqual('test'); | ||
}); | ||
|
||
it('should handle valid uncompressed Readable streams', async () => { | ||
const body = Readable.from(Buffer.from('test')); | ||
expect((await toBuffer(body)).toString()).toEqual('test'); | ||
}); | ||
|
||
it('should handle valid compressed Readable streams', async () => { | ||
const gunzip = createGunzip(); | ||
const body = Readable.from( | ||
Buffer.from('1f8b08000000000000032b492d2e01000c7e7fd804000000', 'hex'), | ||
).pipe(gunzip); | ||
expect((await toBuffer(body)).toString()).toEqual('test'); | ||
}); | ||
|
||
it('should throw on invalid compressed Readable streams', async () => { | ||
const gunzip = createGunzip(); | ||
const body = Readable.from(Buffer.from('0001f8b080000000000000000', 'hex')).pipe(gunzip); | ||
await expect(toBuffer(body)).rejects.toThrow(new Error('Failed to decompress response')); | ||
}); | ||
}); | ||
}); |