From dc72c7c3c82dc63b6c35522af890433aadcc6fce Mon Sep 17 00:00:00 2001 From: Brian Botha Date: Fri, 24 May 2024 15:17:41 +1000 Subject: [PATCH] tests: random data can be correct sometimes, fixed tests that failed due to this [ci skip] --- tests/git/http.test.ts | 10 ++++++---- tests/git/utils.test.ts | 4 +++- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/tests/git/http.test.ts b/tests/git/http.test.ts index 702292f7b..a5d816c80 100644 --- a/tests/git/http.test.ts +++ b/tests/git/http.test.ts @@ -150,12 +150,14 @@ describe('Git Http', () => { 'agent=git/isomorphic-git@1.24.5', ]); }); - test.prop([fc.uint8Array({ minLength: 100 })])( + test.prop([fc.uint8Array({ minLength: 100 }).noShrink()])( 'parsePackRequest handles random data', async (data) => { - await expect( - gitHttp.parsePackRequest([Buffer.from(data)]), - ).rejects.toThrow(validationErrors.ErrorParse); + const bufferData = Buffer.from(data); + fc.pre(!/^[0-9a-f]{4}$/.test(bufferData.subarray(0, 4).toString())) + await expect(gitHttp.parsePackRequest([bufferData])).rejects.toThrow( + validationErrors.ErrorParse, + ); }, ); test('generatePackData', async () => { diff --git a/tests/git/utils.test.ts b/tests/git/utils.test.ts index f981cb238..d604c27b2 100644 --- a/tests/git/utils.test.ts +++ b/tests/git/utils.test.ts @@ -240,7 +240,9 @@ describe('Git utils', () => { test.prop([fc.uint8Array({ size: 'medium', minLength: 1 }).noShrink()])( 'parseRequestLine handles bad data', async (randomData) => { - expect(() => gitUtils.parseRequestLine(Buffer.from(randomData))).toThrow( + const bufferData = Buffer.from(randomData); + fc.pre(!/^[0-9a-f]{4}$/.test(bufferData.subarray(0, 4).toString())) + expect(() => gitUtils.parseRequestLine(bufferData)).toThrow( validationErrors.ErrorParse, ); },