Skip to content

Commit c5db5a0

Browse files
committed
test: gitLeaks step with findings
1 parent 9ce9f5e commit c5db5a0

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
@@ -122,5 +122,46 @@ describe('gitleaks', () => {
122122
expect(logStub.calledWith('succeded')).to.be.true;
123123
expect(logStub.calledWith('No leaks found')).to.be.true;
124124
});
125+
126+
it('should handle scan with findings', async () => {
127+
stubs.getAPIs.returns({ gitleaks: { enabled: true } });
128+
129+
const gitRootCommitMock = {
130+
exitCode: 0,
131+
stdout: 'rootcommit123\n',
132+
stderr: ''
133+
};
134+
135+
const gitleaksMock = {
136+
exitCode: 99,
137+
stdout: 'Found secret in file.txt\n',
138+
stderr: 'Warning: potential leak'
139+
};
140+
141+
stubs.spawn
142+
.onFirstCall().returns({
143+
on: (event, cb) => {
144+
if (event === 'close') cb(gitRootCommitMock.exitCode);
145+
return { stdout: { on: () => {} }, stderr: { on: () => {} } };
146+
},
147+
stdout: { on: (_, cb) => cb(gitRootCommitMock.stdout) },
148+
stderr: { on: (_, cb) => cb(gitRootCommitMock.stderr) }
149+
})
150+
.onSecondCall().returns({
151+
on: (event, cb) => {
152+
if (event === 'close') cb(gitleaksMock.exitCode);
153+
return { stdout: { on: () => {} }, stderr: { on: () => {} } };
154+
},
155+
stdout: { on: (_, cb) => cb(gitleaksMock.stdout) },
156+
stderr: { on: (_, cb) => cb(gitleaksMock.stderr) }
157+
});
158+
159+
const result = await exec(req, action);
160+
161+
expect(result.error).to.be.true;
162+
expect(result.steps).to.have.lengthOf(1);
163+
expect(result.steps[0].error).to.be.true;
164+
expect(stepSpy.calledWith('\nFound secret in file.txt\nWarning: potential leak')).to.be.true;
165+
});
125166
});
126167
});

0 commit comments

Comments
 (0)