Skip to content

Commit 9ce9f5e

Browse files
committed
test: gitLeaks happy path case
1 parent b10a051 commit 9ce9f5e

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

test/processors/gitLeaks.test.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,5 +81,46 @@ describe('gitleaks', () => {
8181
expect(logStub.calledWith('gitleaks is disabled, skipping')).to.be.true;
8282
});
8383

84+
it('should handle successful scan with no findings', async () => {
85+
stubs.getAPIs.returns({ gitleaks: { enabled: true } });
86+
87+
const gitRootCommitMock = {
88+
exitCode: 0,
89+
stdout: 'rootcommit123\n',
90+
stderr: ''
91+
};
92+
93+
const gitleaksMock = {
94+
exitCode: 0,
95+
stdout: '',
96+
stderr: 'No leaks found'
97+
};
98+
99+
stubs.spawn
100+
.onFirstCall().returns({
101+
on: (event, cb) => {
102+
if (event === 'close') cb(gitRootCommitMock.exitCode);
103+
return { stdout: { on: () => {} }, stderr: { on: () => {} } };
104+
},
105+
stdout: { on: (_, cb) => cb(gitRootCommitMock.stdout) },
106+
stderr: { on: (_, cb) => cb(gitRootCommitMock.stderr) }
107+
})
108+
.onSecondCall().returns({
109+
on: (event, cb) => {
110+
if (event === 'close') cb(gitleaksMock.exitCode);
111+
return { stdout: { on: () => {} }, stderr: { on: () => {} } };
112+
},
113+
stdout: { on: (_, cb) => cb(gitleaksMock.stdout) },
114+
stderr: { on: (_, cb) => cb(gitleaksMock.stderr) }
115+
});
116+
117+
const result = await exec(req, action);
118+
119+
expect(result.error).to.be.false;
120+
expect(result.steps).to.have.lengthOf(1);
121+
expect(result.steps[0].error).to.be.false;
122+
expect(logStub.calledWith('succeded')).to.be.true;
123+
expect(logStub.calledWith('No leaks found')).to.be.true;
124+
});
84125
});
85126
});

0 commit comments

Comments
 (0)