|
1 | 1 | const path = require('path');
|
2 | 2 | const simpleGit = require('simple-git');
|
3 | 3 | const fs = require('fs').promises;
|
| 4 | +const fc = require('fast-check'); |
4 | 5 | const { Action } = require('../../src/proxy/actions');
|
5 | 6 | const { exec } = require('../../src/proxy/processors/push-action/getDiff');
|
6 | 7 |
|
@@ -148,4 +149,57 @@ describe('getDiff', () => {
|
148 | 149 | expect(result.steps[0].content).to.not.be.null;
|
149 | 150 | expect(result.steps[0].content.length).to.be.greaterThan(0);
|
150 | 151 | });
|
| 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 | + }); |
151 | 205 | });
|
0 commit comments