Skip to content

test: Implement fuzz tests for processors #1115

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Aug 12, 2025
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
137 changes: 99 additions & 38 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@
"eslint-plugin-react": "^7.21.5",
"eslint-plugin-standard": "^5.0.0",
"eslint-plugin-typescript": "^0.14.0",
"fast-check": "^4.2.0",
"husky": "^9.0.0",
"mocha": "^10.8.2",
"nyc": "^17.0.0",
Expand Down
38 changes: 38 additions & 0 deletions test/processors/blockForAuth.test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const fc = require('fast-check');
const chai = require('chai');
const sinon = require('sinon');
const proxyquire = require('proxyquire').noCallThru();
Expand Down Expand Up @@ -93,4 +94,41 @@ describe('blockForAuth', () => {
expect(message).to.include('/push/push@special#chars!');
});
});

describe('fuzzing', () => {
it('should create a step with correct parameters regardless of action ID', () => {
fc.assert(
fc.asyncProperty(fc.string(), async (actionId) => {
action.id = actionId;

const freshStepInstance = new Step('temp');
const setAsyncBlockStub = sinon.stub(freshStepInstance, 'setAsyncBlock');

const StepSpyLocal = sinon.stub().returns(freshStepInstance);
const getServiceUIURLStubLocal = sinon.stub().returns('http://localhost:8080');

const blockForAuth = proxyquire('../../src/proxy/processors/push-action/blockForAuth', {
'../../../service/urls': { getServiceUIURL: getServiceUIURLStubLocal },
'../../actions': { Step: StepSpyLocal }
});

const result = await blockForAuth.exec(req, action);

expect(StepSpyLocal.calledOnce).to.be.true;
expect(StepSpyLocal.calledWithExactly('authBlock')).to.be.true;
expect(setAsyncBlockStub.calledOnce).to.be.true;

const message = setAsyncBlockStub.firstCall.args[0];
expect(message).to.include(`http://localhost:8080/dashboard/push/${actionId}`);
expect(message).to.include('\x1B[32mGitProxy has received your push ✅\x1B[0m');
expect(message).to.include(`\x1B[34mhttp://localhost:8080/dashboard/push/${actionId}\x1B[0m`);
expect(message).to.include('🔗 Shareable Link');
expect(result).to.equal(action);
}),
{
numRuns: 100
}
);
});
});
});
69 changes: 69 additions & 0 deletions test/processors/checkAuthorEmails.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const sinon = require('sinon');
const proxyquire = require('proxyquire').noCallThru();
const { expect } = require('chai');
const fc = require('fast-check');

describe('checkAuthorEmails', () => {
let action;
Expand Down Expand Up @@ -168,4 +169,72 @@ describe('checkAuthorEmails', () => {
)).to.be.true;
});
});

describe('fuzzing', () => {
it('should not crash on random string in commit email', () => {
fc.assert(
fc.property(fc.string(), (commitEmail) => {
action.commitData = [
{ authorEmail: commitEmail }
];
exec({}, action);
}),
{
numRuns: 100
}
);

expect(action.step.error).to.be.true;
expect(stepSpy.calledWith(
'The following commit author e-mails are illegal: '
)).to.be.true;
});

it('should handle valid emails with random characters', () => {
fc.assert(
fc.property(fc.emailAddress(), (commitEmail) => {
action.commitData = [
{ authorEmail: commitEmail }
];
exec({}, action);
}),
{
numRuns: 100
}
);
expect(action.step.error).to.be.undefined;
});

it('should handle invalid types in commit email', () => {
fc.assert(
fc.property(fc.anything(), (commitEmail) => {
action.commitData = [
{ authorEmail: commitEmail }
];
exec({}, action);
}),
{
numRuns: 100
}
);

expect(action.step.error).to.be.true;
expect(stepSpy.calledWith(
'The following commit author e-mails are illegal: '
)).to.be.true;
});

it('should handle arrays of valid emails', () => {
fc.assert(
fc.property(fc.array(fc.emailAddress()), (commitEmails) => {
action.commitData = commitEmails.map(email => ({ authorEmail: email }));
exec({}, action);
}),
{
numRuns: 100
}
);
expect(action.step.error).to.be.undefined;
});
});
});
Loading
Loading