Skip to content

Commit 6b450e0

Browse files
committed
test(fuzz): getDiff
1 parent 58a17a2 commit 6b450e0

File tree

2 files changed

+55
-1
lines changed

2 files changed

+55
-1
lines changed

test/processors/checkUserPushPermission.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const { Action, Step } = require('../../src/proxy/actions');
77
chai.should();
88
const expect = chai.expect;
99

10-
describe.only('checkUserPushPermission', () => {
10+
describe('checkUserPushPermission', () => {
1111
let exec;
1212
let getUsersStub;
1313
let isUserPushAllowedStub;

test/processors/getDiff.test.js

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const path = require('path');
22
const simpleGit = require('simple-git');
33
const fs = require('fs').promises;
4+
const fc = require('fast-check');
45
const { Action } = require('../../src/proxy/actions');
56
const { exec } = require('../../src/proxy/processors/push-action/getDiff');
67

@@ -148,4 +149,57 @@ describe('getDiff', () => {
148149
expect(result.steps[0].content).to.not.be.null;
149150
expect(result.steps[0].content.length).to.be.greaterThan(0);
150151
});
152+
153+
describe('fuzzing', () => {
154+
it('should handle random action inputs without crashing', async function () {
155+
// Not comprehensive but helps prevent crashing on bad input
156+
await fc.assert(
157+
fc.asyncProperty(
158+
fc.string({ minLength: 0, maxLength: 40 }),
159+
fc.string({ minLength: 0, maxLength: 40 }),
160+
fc.array(fc.record({ parent: fc.string({ minLength: 0, maxLength: 40 }) }), { maxLength: 3 }),
161+
async (from, to, commitData) => {
162+
const action = new Action('id', 'push', 'POST', Date.now(), 'test/repo');
163+
action.proxyGitPath = __dirname;
164+
action.repoName = 'temp-test-repo';
165+
action.commitFrom = from;
166+
action.commitTo = to;
167+
action.commitData = commitData;
168+
169+
const result = await exec({}, action);
170+
171+
expect(result).to.have.property('steps');
172+
expect(result.steps[0]).to.have.property('error');
173+
expect(result.steps[0]).to.have.property('content');
174+
}
175+
),
176+
{ numRuns: 10 }
177+
);
178+
});
179+
180+
it('should handle randomized commitFrom and commitTo of proper length', async function () {
181+
await fc.assert(
182+
fc.asyncProperty(
183+
fc.stringMatching(/^[0-9a-fA-F]{40}$/),
184+
fc.stringMatching(/^[0-9a-fA-F]{40}$/),
185+
async (from, to) => {
186+
const action = new Action('id', 'push', 'POST', Date.now(), 'test/repo');
187+
action.proxyGitPath = __dirname;
188+
action.repoName = 'temp-test-repo';
189+
action.commitFrom = from;
190+
action.commitTo = to;
191+
action.commitData = [
192+
{ parent: '0000000000000000000000000000000000000000' }
193+
];
194+
195+
const result = await exec({}, action);
196+
197+
expect(result.steps[0].error).to.be.true;
198+
expect(result.steps[0].errorMessage).to.contain('Invalid revision range');
199+
}
200+
),
201+
{ numRuns: 10 }
202+
);
203+
});
204+
});
151205
});

0 commit comments

Comments
 (0)