@@ -2,6 +2,7 @@ const chai = require('chai');
22const sinon = require ( 'sinon' ) ;
33const proxyquire = require ( 'proxyquire' ) ;
44const { Action, Step } = require ( '../../src/proxy/actions' ) ;
5+ const fc = require ( 'fast-check' ) ;
56
67chai . should ( ) ;
78const expect = chai . expect ;
@@ -150,5 +151,53 @@ describe('checkCommitMessages', () => {
150151 ) ) . to . be . true ;
151152 expect ( logStub . calledWith ( 'The following commit messages are illegal: secret password here' ) ) . to . be . true ;
152153 } ) ;
154+
155+ describe ( 'fuzzing' , ( ) => {
156+ it ( 'should not crash on arbitrary commit messages' , async ( ) => {
157+ await fc . assert (
158+ fc . asyncProperty (
159+ fc . array (
160+ fc . record ( {
161+ message : fc . oneof (
162+ fc . string ( ) ,
163+ fc . constant ( null ) ,
164+ fc . constant ( undefined ) ,
165+ fc . integer ( ) ,
166+ fc . double ( ) ,
167+ fc . boolean ( ) ,
168+ fc . object ( ) ,
169+ ) ,
170+ author : fc . string ( )
171+ } ) ,
172+ { maxLength : 20 }
173+ ) ,
174+ async ( fuzzedCommits ) => {
175+ const fuzzAction = new Action (
176+ 'fuzz' ,
177+ 'push' ,
178+ 'POST' ,
179+ Date . now ( ) ,
180+ 'fuzz/repo'
181+ ) ;
182+ fuzzAction . commitData = Array . isArray ( fuzzedCommits ) ? fuzzedCommits : [ ] ;
183+
184+ const result = await exec ( { } , fuzzAction ) ;
185+
186+ expect ( result ) . to . have . property ( 'steps' ) ;
187+ expect ( result . steps [ 0 ] ) . to . have . property ( 'error' ) . that . is . a ( 'boolean' ) ;
188+ }
189+ ) ,
190+ {
191+ examples : [
192+ [ { message : '' , author : 'me' } ] ,
193+ [ { message : '1234-5678-9012-3456' , author : 'me' } ] ,
194+ [ { message : null , author : 'me' } ] ,
195+ [ { message : { } , author : 'me' } ] ,
196+ [ { message : 'SeCrEt' , author : 'me' } ]
197+ ]
198+ }
199+ ) ;
200+ } ) ;
201+ } ) ;
153202 } ) ;
154203} ) ;
0 commit comments