Skip to content

Commit b3c3049

Browse files
JDragovichAlertLogickkuzmin
authored andcommitted
Stop blank ingest calls (#20)
* add gaurd to stop injest call if data is falsey * add return statement to guard * check for empty arrya and object * remove extranious checks and just check if its falsey
1 parent 0556c1d commit b3c3049

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

al_aws_collector.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,11 +199,15 @@ class AlAwsCollector {
199199
return response.send(event, context, response.FAILED, {Error: exception});
200200
});
201201
}
202-
202+
203203
send(data, callback){
204204
var collector = this;
205205
var ingestType = collector._ingestType;
206-
206+
207+
if(!data){
208+
return callback(null);
209+
}
210+
207211
zlib.deflate(data, function(compressionErr, compressed) {
208212
if (compressionErr) {
209213
return callback(compressionErr);

test/al_aws_collector_test.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ describe('al_aws_collector tests', function() {
318318
describe('mocking ingestC', function() {
319319
var ingestCSecmsgsStub;
320320
var ingestCVpcFlowStub;
321-
before(function() {
321+
beforeEach(function() {
322322
ingestCSecmsgsStub = sinon.stub(m_alCollector.IngestC.prototype, 'sendSecmsgs').callsFake(
323323
function fakeFn(data, callback) {
324324
return new Promise (function(resolve, reject) {
@@ -334,10 +334,23 @@ describe('al_aws_collector tests', function() {
334334
});
335335
});
336336

337-
after(function() {
337+
afterEach(function() {
338338
ingestCSecmsgsStub.restore();
339339
ingestCVpcFlowStub.restore();
340340
});
341+
342+
it('dont send if data is falsey', function(done) {
343+
AlAwsCollector.load().then(function(creds) {
344+
var collector = new AlAwsCollector(
345+
context, 'cwe', AlAwsCollector.IngestTypes.SECMSGS, '1.0.0', creds);
346+
var data = '';
347+
collector.send(data, function(error) {
348+
assert.ifError(error);
349+
sinon.assert.notCalled(ingestCSecmsgsStub);
350+
done();
351+
});
352+
});
353+
});
341354

342355
it('send secmsgs success', function(done) {
343356
AlAwsCollector.load().then(function(creds) {

0 commit comments

Comments
 (0)