-
Notifications
You must be signed in to change notification settings - Fork 135
test: increase action test coverage #1038
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
JamieSlome
merged 23 commits into
finos:main
from
jescalada:increase-push-action-test-coverage
Jun 5, 2025
Merged
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
8423fd0
test: blockForAuth action
jescalada 27ccfb9
test: checkAuthorEmails action and fix bugs
jescalada e9f978f
test: checkCommitMessages and lint/reformat
jescalada 0777677
fix: npm test pattern
jescalada 84e2af5
test: skip failing plugin tests (node 18 compat issue)
jescalada 70857f5
test: checkIfWaitingAuth
jescalada b52ca15
test: checkUserPushPermission
jescalada 06be914
test: getDiff (preliminary)
jescalada e283768
chore: move and rename clearBareClone test
jescalada b05a1e3
test: fix missing git config error and refactor fs import
jescalada 19ae3e0
chore: fix linter
jescalada 8194897
fix: getDiff empty commitData check test
jescalada 9d54b5e
test: if statement in getDiff action
jescalada 8b16d11
test: gitLeaks setup and preliminary test
jescalada b10a051
fix: add check for disabled gitLeaks config
jescalada 9ce9f5e
test: gitLeaks happy path case
jescalada c5db5a0
test: gitLeaks step with findings
jescalada 71748c7
test: gitLeaks custom config case
jescalada 4f145bb
Merge remote-tracking branch 'origin/main' into increase-push-action-…
jescalada e461d95
test: invalid config path case
jescalada 6c7116c
test: gitLeaks edge cases and errors
jescalada 314d940
test: writePack action
jescalada 5252093
Merge branch 'main' into increase-push-action-test-coverage
JamieSlome File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
title = "sample gitleaks config" | ||
|
||
[[rules]] | ||
id = "generic-api-key" | ||
description = "Generic API Key" | ||
regex = '''(?i)(?:key|api|token|secret)[\s:=]+([a-z0-9]{32,})''' | ||
tags = ["key", "api-key"] | ||
|
||
[[rules]] | ||
id = "aws-access-key-id" | ||
description = "AWS Access Key ID" | ||
regex = '''AKIA[0-9A-Z]{16}''' | ||
tags = ["aws", "key"] | ||
|
||
[[rules]] | ||
id = "basic-auth" | ||
description = "Auth Credentials" | ||
regex = '''(?i)(https?://)[a-z0-9]+:[a-z0-9]+@''' | ||
tags = ["auth", "password"] | ||
|
||
[[rules]] | ||
id = "jwt-token" | ||
description = "JSON Web Token" | ||
regex = '''eyJ[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]{10,}\.?[A-Za-z0-9._-]*''' | ||
tags = ["jwt", "token"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
const chai = require('chai'); | ||
const sinon = require('sinon'); | ||
const proxyquire = require('proxyquire').noCallThru(); | ||
const { Step } = require('../../src/proxy/actions'); | ||
|
||
chai.should(); | ||
const expect = chai.expect; | ||
|
||
describe('blockForAuth', () => { | ||
let action; | ||
let exec; | ||
let getServiceUIURLStub; | ||
let req; | ||
let stepInstance; | ||
let StepSpy; | ||
|
||
beforeEach(() => { | ||
req = { | ||
protocol: 'https', | ||
headers: { host: 'example.com' } | ||
}; | ||
|
||
action = { | ||
id: 'push_123', | ||
addStep: sinon.stub() | ||
}; | ||
|
||
stepInstance = new Step('temp'); | ||
sinon.stub(stepInstance, 'setAsyncBlock'); | ||
|
||
StepSpy = sinon.stub().returns(stepInstance); | ||
|
||
getServiceUIURLStub = sinon.stub().returns('http://localhost:8080'); | ||
|
||
const blockForAuth = proxyquire('../../src/proxy/processors/push-action/blockForAuth', { | ||
'../../../service/urls': { getServiceUIURL: getServiceUIURLStub }, | ||
'../../actions': { Step: StepSpy } | ||
}); | ||
|
||
exec = blockForAuth.exec; | ||
}); | ||
|
||
afterEach(() => { | ||
sinon.restore(); | ||
}); | ||
|
||
describe('exec', () => { | ||
|
||
it('should generate a correct shareable URL', async () => { | ||
await exec(req, action); | ||
expect(getServiceUIURLStub.calledOnce).to.be.true; | ||
expect(getServiceUIURLStub.calledWithExactly(req)).to.be.true; | ||
}); | ||
|
||
it('should create step with correct parameters', async () => { | ||
await exec(req, action); | ||
|
||
expect(StepSpy.calledOnce).to.be.true; | ||
expect(StepSpy.calledWithExactly('authBlock')).to.be.true; | ||
expect(stepInstance.setAsyncBlock.calledOnce).to.be.true; | ||
|
||
const message = stepInstance.setAsyncBlock.firstCall.args[0]; | ||
expect(message).to.include('http://localhost:8080/dashboard/push/push_123'); | ||
expect(message).to.include('\x1B[32mGitProxy has received your push ✅\x1B[0m'); | ||
expect(message).to.include('\x1B[34mhttp://localhost:8080/dashboard/push/push_123\x1B[0m'); | ||
expect(message).to.include('🔗 Shareable Link'); | ||
}); | ||
|
||
it('should add step to action exactly once', async () => { | ||
await exec(req, action); | ||
expect(action.addStep.calledOnce).to.be.true; | ||
expect(action.addStep.calledWithExactly(stepInstance)).to.be.true; | ||
}); | ||
|
||
it('should return action instance', async () => { | ||
const result = await exec(req, action); | ||
expect(result).to.equal(action); | ||
}); | ||
|
||
it('should handle https URL format', async () => { | ||
getServiceUIURLStub.returns('https://git-proxy-hosted-ui.com'); | ||
await exec(req, action); | ||
|
||
const message = stepInstance.setAsyncBlock.firstCall.args[0]; | ||
expect(message).to.include('https://git-proxy-hosted-ui.com/dashboard/push/push_123'); | ||
}); | ||
|
||
it('should handle special characters in action ID', async () => { | ||
action.id = 'push@special#chars!'; | ||
await exec(req, action); | ||
|
||
const message = stepInstance.setAsyncBlock.firstCall.args[0]; | ||
expect(message).to.include('/push/push@special#chars!'); | ||
}); | ||
}); | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,171 @@ | ||
const sinon = require('sinon'); | ||
const proxyquire = require('proxyquire').noCallThru(); | ||
const { expect } = require('chai'); | ||
|
||
describe('checkAuthorEmails', () => { | ||
let action; | ||
let commitConfig | ||
let exec; | ||
let getCommitConfigStub; | ||
let stepSpy; | ||
let StepStub; | ||
|
||
beforeEach(() => { | ||
StepStub = class { | ||
constructor() { | ||
this.error = undefined; | ||
} | ||
log() {} | ||
setError() {} | ||
}; | ||
stepSpy = sinon.spy(StepStub.prototype, 'log'); | ||
sinon.spy(StepStub.prototype, 'setError'); | ||
|
||
commitConfig = { | ||
author: { | ||
email: { | ||
domain: { allow: null }, | ||
local: { block: null } | ||
} | ||
} | ||
}; | ||
getCommitConfigStub = sinon.stub().returns(commitConfig); | ||
|
||
action = { | ||
commitData: [], | ||
addStep: sinon.stub().callsFake((step) => { | ||
action.step = new StepStub(); | ||
Object.assign(action.step, step); | ||
return action.step; | ||
}) | ||
}; | ||
|
||
const checkAuthorEmails = proxyquire('../../src/proxy/processors/push-action/checkAuthorEmails', { | ||
'../../../config': { getCommitConfig: getCommitConfigStub }, | ||
'../../actions': { Step: StepStub } | ||
}); | ||
|
||
exec = checkAuthorEmails.exec; | ||
}); | ||
|
||
afterEach(() => { | ||
sinon.restore(); | ||
}); | ||
|
||
describe('exec', () => { | ||
it('should allow valid emails when no restrictions', async () => { | ||
action.commitData = [ | ||
{ authorEmail: '[email protected]' }, | ||
{ authorEmail: '[email protected]' } | ||
]; | ||
|
||
await exec({}, action); | ||
|
||
expect(action.step.error).to.be.undefined; | ||
}); | ||
|
||
it('should block emails from forbidden domains', async () => { | ||
commitConfig.author.email.domain.allow = 'example\\.com$'; | ||
action.commitData = [ | ||
{ authorEmail: '[email protected]' }, | ||
{ authorEmail: '[email protected]' } | ||
]; | ||
|
||
await exec({}, action); | ||
|
||
expect(action.step.error).to.be.true; | ||
expect(stepSpy.calledWith( | ||
'The following commit author e-mails are illegal: [email protected]' | ||
)).to.be.true; | ||
expect(StepStub.prototype.setError.calledWith( | ||
'Your push has been blocked. Please verify your Git configured e-mail address is valid (e.g. [email protected])' | ||
)).to.be.true; | ||
}); | ||
|
||
it('should block emails with forbidden usernames', async () => { | ||
commitConfig.author.email.local.block = 'blocked'; | ||
action.commitData = [ | ||
{ authorEmail: '[email protected]' }, | ||
{ authorEmail: '[email protected]' } | ||
]; | ||
|
||
await exec({}, action); | ||
|
||
expect(action.step.error).to.be.true; | ||
expect(stepSpy.calledWith( | ||
'The following commit author e-mails are illegal: [email protected]' | ||
)).to.be.true; | ||
}); | ||
|
||
it('should handle empty email strings', async () => { | ||
action.commitData = [ | ||
{ authorEmail: '' }, | ||
{ authorEmail: '[email protected]' } | ||
]; | ||
|
||
await exec({}, action); | ||
|
||
expect(action.step.error).to.be.true; | ||
expect(stepSpy.calledWith( | ||
'The following commit author e-mails are illegal: ' | ||
)).to.be.true; | ||
}); | ||
|
||
it('should allow emails when both checks pass', async () => { | ||
commitConfig.author.email.domain.allow = 'example\\.com$'; | ||
commitConfig.author.email.local.block = 'forbidden'; | ||
action.commitData = [ | ||
{ authorEmail: '[email protected]' }, | ||
{ authorEmail: '[email protected]' } | ||
]; | ||
|
||
await exec({}, action); | ||
|
||
expect(action.step.error).to.be.undefined; | ||
}); | ||
|
||
it('should block emails that fail both checks', async () => { | ||
commitConfig.author.email.domain.allow = 'example\\.com$'; | ||
commitConfig.author.email.local.block = 'forbidden'; | ||
action.commitData = [ | ||
{ authorEmail: '[email protected]' } | ||
]; | ||
|
||
await exec({}, action); | ||
|
||
expect(action.step.error).to.be.true; | ||
expect(stepSpy.calledWith( | ||
'The following commit author e-mails are illegal: [email protected]' | ||
)).to.be.true; | ||
}); | ||
|
||
it('should handle emails without domain', async () => { | ||
action.commitData = [ | ||
{ authorEmail: 'nodomain@' } | ||
]; | ||
|
||
await exec({}, action); | ||
|
||
expect(action.step.error).to.be.true; | ||
expect(stepSpy.calledWith( | ||
'The following commit author e-mails are illegal: nodomain@' | ||
)).to.be.true; | ||
}); | ||
|
||
it('should handle multiple illegal emails', async () => { | ||
commitConfig.author.email.domain.allow = 'example\\.com$'; | ||
action.commitData = [ | ||
{ authorEmail: '[email protected]' }, | ||
{ authorEmail: '[email protected]' }, | ||
{ authorEmail: '[email protected]' } | ||
]; | ||
|
||
await exec({}, action); | ||
|
||
expect(action.step.error).to.be.true; | ||
expect(stepSpy.calledWith( | ||
'The following commit author e-mails are illegal: [email protected],[email protected]' | ||
)).to.be.true; | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.