|
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 |
|
@@ -116,4 +117,57 @@ describe('getDiff', () => { |
116 | 117 | expect(result.steps[0].content).to.not.be.null; |
117 | 118 | expect(result.steps[0].content.length).to.be.greaterThan(0); |
118 | 119 | }); |
| 120 | + |
| 121 | + describe('fuzzing', () => { |
| 122 | + it('should handle random action inputs without crashing', async function () { |
| 123 | + // Not comprehensive but helps prevent crashing on bad input |
| 124 | + await fc.assert( |
| 125 | + fc.asyncProperty( |
| 126 | + fc.string({ minLength: 0, maxLength: 40 }), |
| 127 | + fc.string({ minLength: 0, maxLength: 40 }), |
| 128 | + fc.array(fc.record({ parent: fc.string({ minLength: 0, maxLength: 40 }) }), { maxLength: 3 }), |
| 129 | + async (from, to, commitData) => { |
| 130 | + const action = new Action('id', 'push', 'POST', Date.now(), 'test/repo'); |
| 131 | + action.proxyGitPath = __dirname; |
| 132 | + action.repoName = 'temp-test-repo'; |
| 133 | + action.commitFrom = from; |
| 134 | + action.commitTo = to; |
| 135 | + action.commitData = commitData; |
| 136 | + |
| 137 | + const result = await exec({}, action); |
| 138 | + |
| 139 | + expect(result).to.have.property('steps'); |
| 140 | + expect(result.steps[0]).to.have.property('error'); |
| 141 | + expect(result.steps[0]).to.have.property('content'); |
| 142 | + } |
| 143 | + ), |
| 144 | + { numRuns: 10 } |
| 145 | + ); |
| 146 | + }); |
| 147 | + |
| 148 | + it('should handle randomized commitFrom and commitTo of proper length', async function () { |
| 149 | + await fc.assert( |
| 150 | + fc.asyncProperty( |
| 151 | + fc.stringMatching(/^[0-9a-fA-F]{40}$/), |
| 152 | + fc.stringMatching(/^[0-9a-fA-F]{40}$/), |
| 153 | + async (from, to) => { |
| 154 | + const action = new Action('id', 'push', 'POST', Date.now(), 'test/repo'); |
| 155 | + action.proxyGitPath = __dirname; |
| 156 | + action.repoName = 'temp-test-repo'; |
| 157 | + action.commitFrom = from; |
| 158 | + action.commitTo = to; |
| 159 | + action.commitData = [ |
| 160 | + { parent: '0000000000000000000000000000000000000000' } |
| 161 | + ]; |
| 162 | + |
| 163 | + const result = await exec({}, action); |
| 164 | + |
| 165 | + expect(result.steps[0].error).to.be.true; |
| 166 | + expect(result.steps[0].errorMessage).to.contain('Invalid revision range'); |
| 167 | + } |
| 168 | + ), |
| 169 | + { numRuns: 10 } |
| 170 | + ); |
| 171 | + }); |
| 172 | + }); |
119 | 173 | }); |
0 commit comments