|
1 | 1 | const sinon = require('sinon');
|
2 | 2 | const proxyquire = require('proxyquire').noCallThru();
|
3 | 3 | const { expect } = require('chai');
|
| 4 | +const fc = require('fast-check'); |
4 | 5 |
|
5 | 6 | describe('checkAuthorEmails', () => {
|
6 | 7 | let action;
|
@@ -168,4 +169,72 @@ describe('checkAuthorEmails', () => {
|
168 | 169 | )).to.be.true;
|
169 | 170 | });
|
170 | 171 | });
|
| 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 | + }); |
171 | 240 | });
|
0 commit comments