Skip to content

Commit ae4fa7e

Browse files
committed
test(fuzz): checkAuthorEmails
1 parent 5e32384 commit ae4fa7e

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed

test/processors/checkAuthorEmails.test.js

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const sinon = require('sinon');
22
const proxyquire = require('proxyquire').noCallThru();
33
const { expect } = require('chai');
4+
const fc = require('fast-check');
45

56
describe('checkAuthorEmails', () => {
67
let action;
@@ -168,4 +169,72 @@ describe('checkAuthorEmails', () => {
168169
)).to.be.true;
169170
});
170171
});
172+
173+
describe('fuzzing', () => {
174+
it('should not crash on random string in commit email', () => {
175+
fc.assert(
176+
fc.property(fc.string(), (commitEmail) => {
177+
action.commitData = [
178+
{ authorEmail: commitEmail }
179+
];
180+
exec({}, action);
181+
}),
182+
{
183+
numRuns: 100
184+
}
185+
);
186+
187+
expect(action.step.error).to.be.true;
188+
expect(stepSpy.calledWith(
189+
'The following commit author e-mails are illegal: '
190+
)).to.be.true;
191+
});
192+
193+
it('should handle valid emails with random characters', () => {
194+
fc.assert(
195+
fc.property(fc.emailAddress(), (commitEmail) => {
196+
action.commitData = [
197+
{ authorEmail: commitEmail }
198+
];
199+
exec({}, action);
200+
}),
201+
{
202+
numRuns: 100
203+
}
204+
);
205+
expect(action.step.error).to.be.undefined;
206+
});
207+
208+
it('should handle invalid types in commit email', () => {
209+
fc.assert(
210+
fc.property(fc.anything(), (commitEmail) => {
211+
action.commitData = [
212+
{ authorEmail: commitEmail }
213+
];
214+
exec({}, action);
215+
}),
216+
{
217+
numRuns: 100
218+
}
219+
);
220+
221+
expect(action.step.error).to.be.true;
222+
expect(stepSpy.calledWith(
223+
'The following commit author e-mails are illegal: '
224+
)).to.be.true;
225+
});
226+
227+
it('should handle arrays of valid emails', () => {
228+
fc.assert(
229+
fc.property(fc.array(fc.emailAddress()), (commitEmails) => {
230+
action.commitData = commitEmails.map(email => ({ authorEmail: email }));
231+
exec({}, action);
232+
}),
233+
{
234+
numRuns: 100
235+
}
236+
);
237+
expect(action.step.error).to.be.undefined;
238+
});
239+
});
171240
});

0 commit comments

Comments
 (0)