Skip to content

Commit cbaee6c

Browse files
fixed flushed chunk not masked (#75)
1 parent 6b72e87 commit cbaee6c

File tree

3 files changed

+49
-2
lines changed

3 files changed

+49
-2
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@codefresh-io/task-logger",
3-
"version": "1.8.10",
3+
"version": "1.8.11",
44
"description": "Codefresh utilities for working with build logs",
55
"main": "index.js",
66
"scripts": {

taskLogger/MaskingStream.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ class MaskingStream extends Transform {
6464
// this chunk from the buffer (it is the first chunk, for sure).
6565
this.chunks.shift();
6666
chunk.sent = true;
67-
this.push(chunk.data);
67+
this.push(this.taskLogger._maskBlacklistWords(chunk.data));
6868
}, this.chunkFlushTimeout);
6969
}
7070

taskLogger/test/TaskLogger.unit.spec.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,53 @@ describe('Base TaskLogger tests', () => {
477477
expect(receivedBuffer.toString('utf-8')).to.be.equal(expectedResult);
478478
});
479479

480+
it('should send a masked chunk if no new chunk arrives before the timeout', async () => {
481+
const blacklist = {
482+
SECRET: '1234567890ABCD',
483+
SHORTER_SECRET: 'abcd',
484+
};
485+
486+
const taskLogger = getTaskLoggerInstance(undefined, { blacklist });
487+
const maskingStream = taskLogger.createMaskingStream({ chunkFlushTimeout: 50 });
488+
489+
const containerOutput = [
490+
{ sent: 'hello: abcd', delay: 0 },
491+
{ sent: ' end', delay: 200 },
492+
];
493+
const expectedResult = `hello: ${SECRET_REPLACEMENT} end`;
494+
495+
let i = 0;
496+
const containerOutputStream = new Readable({
497+
read() {
498+
const output = containerOutput[i];
499+
i += 1;
500+
if (!output) {
501+
this.push(null); // end stream
502+
return;
503+
}
504+
setTimeout(() => {
505+
this.push(output.sent);
506+
}, output.delay);
507+
}
508+
});
509+
510+
let receivedBuffer = Buffer.from('');
511+
const finalOutputStream = new Writable({
512+
write(chunk, encoding, done) {
513+
receivedBuffer = Buffer.concat([receivedBuffer, chunk]);
514+
done();
515+
}
516+
});
517+
518+
const deferred = Q.defer();
519+
finalOutputStream.on('finish', deferred.resolve.bind(deferred));
520+
521+
containerOutputStream.pipe(maskingStream).pipe(finalOutputStream);
522+
523+
await deferred.promise;
524+
expect(receivedBuffer.toString('utf-8')).to.be.equal(expectedResult);
525+
});
526+
480527
it('should ignore masks with empty secret', () => {
481528
const blacklist = {
482529
EMPTY_SECRET: '',

0 commit comments

Comments
 (0)