| 1 | import { Readable } from 'node:stream'; |
| 2 | import { buffer as |
| 3 | import { gzipSync } |
| 4 | import { describe, expect |
| 5 | |
| 6 | import { GitRawBodyMiddleware } |
| 7 | import type { GitAuthenticatedBufferedRequest |
| 8 | |
| 9 | function request(body: |
| 10 | return Object.assign |
| 11 | headers, |
| 12 | }) as unknown |
| 13 | } |
| 14 | |
| 15 | describe('GitRawBodyMiddleware', () |
| 16 | const middleware = |
| 17 | const response = |
| 18 | |
| 19 | it('spools the request before the handler runs', |
| 20 | const req = |
| 21 | const next = |
| 22 | |
| 23 | await middleware.use |
| 24 | |
| 25 | expect((await readStream |
| 26 | '0032command\n0000PACK', |
| 27 | ); |
| 28 | expect(next).toHaveBeenCalledWith |
| 29 | }); |
| 30 | |
| 31 | it('inflates a gzipped body', |
| 32 | const raw = |
| 33 | const req = |
| 34 | |
| 35 | await middleware.use |
| 36 | |
| 37 | expect(await readStream |
| 38 | }); |
| 39 | |
| 40 | it('passes a decode failure to the error handler', |
| 41 | const req = |
| 42 | 'content-encoding': 'gzip', |
| 43 | }); |
| 44 | const next = |
| 45 | |
| 46 | await middleware.use |
| 47 | |
| 48 | expect(next).toHaveBeenCalledWith |
| 49 | }); |
| 50 | }); |