diff --git a/tests/1_config.js b/tests/1_config.js index 916592c..46b4f1f 100644 --- a/tests/1_config.js +++ b/tests/1_config.js @@ -95,7 +95,7 @@ describe("Composition", function() { it("loading monitors", function () { - expect(config.monitors.length).to.equal(5); + expect(config.monitors.length).to.equal(6); expect(config.monitors[0]).to .containSubset({ @@ -133,6 +133,15 @@ describe("Composition", function() { } }); + expect(config.monitors[4]).to + .containSubset({ + "channel": "misconfiguration", + "name": "asn-monitor", + "params": { + "thresholdMinPeers": 0 + } + }); + expect(config.monitors[config.monitors.length - 1]).to .containSubset({ "channel": "software-update", @@ -140,6 +149,7 @@ describe("Composition", function() { "params": undefined }); + expect(config.monitors[0]).to.have .property('class') }); @@ -170,6 +180,7 @@ describe("Composition", function() { it("loading prefixes", function () { expect(input.prefixes.length).to.equal(12); + expect(JSON.parse(JSON.stringify(input))).to .containSubset({ "prefixes": [ @@ -266,6 +277,7 @@ describe("Composition", function() { ] }); + expect(input.asns.length).to.equal(2); }); }); diff --git a/tests/2_alerting.js b/tests/2_alerting.js index c5224c0..e794608 100644 --- a/tests/2_alerting.js +++ b/tests/2_alerting.js @@ -439,6 +439,65 @@ describe("Alerting", function () { expect(Object.keys(expectedData).includes(id)).to.equal(true); expect(expectedData[id] != null).to.equal(true); + expect(message).to + .containSubset(expectedData[id]); + + expect(message).to.contain + .keys([ + "latest", + "earliest" + ]); + + delete expectedData[id]; + if (Object.keys(expectedData).length === 0){ + done(); + } + }); + + }).timeout(asyncTimeout); + + + + + + it("asn monitoring reporting", function (done) { + + pubSub.publish("test-type", "misconfiguration"); + + const expectedData = { + "2914-2.2.2.2/22": { + id: '2914-2.2.2.2/22', + origin: 'asn-monitor', + affected: 2914, + message: 'AS2914 is announcing 2.2.2.2/22 but this prefix is not in the configured list of announced prefixes', + data: [ + { + extra: {}, + matchedRule: { + group: 'default', + asn: [2914], + }, + matchedMessage: { + type: 'announcement', + prefix: '2.2.2.2/22', + peer: '124.0.0.3', + path: [1, 2, 3, 4321, 5060, 2914], + originAS: [2914], + nextHop: '124.0.0.3' + } + } + ] + } + }; + + pubSub.subscribe("misconfiguration", function (type, message) { + + message = JSON.parse(JSON.stringify(message)); + const id = message.id; + + expect(Object.keys(expectedData).includes(id)).to.equal(true); + expect(expectedData[id] != null).to.equal(true); + expect(message).to .containSubset(expectedData[id]); diff --git a/tests/config.test.yml b/tests/config.test.yml index 248c1c4..9f3c6e9 100644 --- a/tests/config.test.yml +++ b/tests/config.test.yml @@ -31,6 +31,12 @@ monitors: params: thresholdMinPeers: 0 + - file: monitorAS + channel: misconfiguration + name: asn-monitor + params: + thresholdMinPeers: 0 + reports: - file: reportFile channels: @@ -38,6 +44,7 @@ reports: - newprefix - visibility - path + - misconfiguration notificationIntervalSeconds: 1800 # Repeat the same alert (which keeps being triggered) after x seconds alertOnlyOnce: false diff --git a/tests/prefixes.test.yml b/tests/prefixes.test.yml index 0ca22b1..dde9dd2 100644 --- a/tests/prefixes.test.yml +++ b/tests/prefixes.test.yml @@ -82,4 +82,11 @@ path: match: ".*2914$" minLength: 2 - matchDescription: test description \ No newline at end of file + matchDescription: test description + +options: + monitorASns: + 2914: + group: default + 3333: + group: default \ No newline at end of file