From 7fee9ee8c9df35707e1036617d6a2dccb80c30ae Mon Sep 17 00:00:00 2001 From: Massimo Candela Date: Tue, 28 Apr 2020 15:35:26 +0200 Subject: [PATCH] added monitorRPKI tests --- src/connectors/connectorTest.js | 38 ++++++++++++++++++++++ tests/1_config.js | 16 ++++++++-- tests/2_alerting.js | 56 +++++++++++++++++++++++++++++++-- tests/config.test.yml | 21 ++++++++++--- tests/prefixes.test.yml | 2 ++ 5 files changed, 124 insertions(+), 9 deletions(-) diff --git a/src/connectors/connectorTest.js b/src/connectors/connectorTest.js index a71b6ed..d787236 100644 --- a/src/connectors/connectorTest.js +++ b/src/connectors/connectorTest.js @@ -382,6 +382,44 @@ export default class ConnectorTest extends Connector{ } ]; break; + + case "rpki": + updates = [ + { + data: { + announcements: [{ + prefixes: ["82.112.100.0/24"], // Valid + next_hop: "124.0.0.3" + }], + peer: "124.0.0.4", + path: [1, 2, 3, 4321, 2914] + }, + type: "ris_message" + }, + { + data: { + announcements: [{ + prefixes: ["8.8.8.8/22"], // Not covered + next_hop: "124.0.0.3" + }], + peer: "124.0.0.4", + path: [1, 2, 3, 4321, 5060, 2914] + }, + type: "ris_message" + }, + { + data: { + announcements: [{ + prefixes: ["103.21.244.0/24"], // Invalid + next_hop: "124.0.0.3" + }], + peer: "124.0.0.4", + path: [1, 2, 3, 4321, 13335] + }, + type: "ris_message" + } + ]; + break; default: return; } diff --git a/tests/1_config.js b/tests/1_config.js index 43686cd..2f2467a 100644 --- a/tests/1_config.js +++ b/tests/1_config.js @@ -97,7 +97,7 @@ describe("Composition", function() { it("loading monitors", function () { - expect(config.monitors.length).to.equal(6); + expect(config.monitors.length).to.equal(7); expect(config.monitors[0]).to .containSubset({ @@ -144,6 +144,18 @@ describe("Composition", function() { } }); + expect(config.monitors[5]).to + .containSubset({ + "channel": "rpki-monitor", + "name": "rpki-monitor", + "params": { + "thresholdMinPeers": 1, + "preCacheROAs": false, + "refreshVrpListMinutes": 15, + "checkUncovered": true + } + }); + expect(config.monitors[config.monitors.length - 1]).to .containSubset({ "channel": "software-update", @@ -297,7 +309,7 @@ describe("Composition", function() { ] }); - expect(input.asns.map(i => i.asn.getValue())).to.eql([ 2914, 3333, 65000 ]); + expect(input.asns.map(i => i.asn.getValue())).to.eql([ 2914, 3333, 13335, 65000 ]); }); }); diff --git a/tests/2_alerting.js b/tests/2_alerting.js index 85c8dd0..71abbbe 100644 --- a/tests/2_alerting.js +++ b/tests/2_alerting.js @@ -35,7 +35,7 @@ var chaiSubset = require('chai-subset'); chai.use(chaiSubset); var expect = chai.expect; -let asyncTimeout = 20000; +let asyncTimeout = 2000000; global.EXTERNAL_VERSION_FOR_TEST = "0.0.1"; global.EXTERNAL_CONFIG_FILE = "tests/config.test.yml"; @@ -477,8 +477,6 @@ describe("Alerting", function () { }).timeout(asyncTimeout); - - it("asn monitoring reporting", function (done) { pubSub.publish("test-type", "misconfiguration"); @@ -529,6 +527,58 @@ describe("Alerting", function () { }).timeout(asyncTimeout); + it("RPKI monitoring", function (done) { + + pubSub.publish("test-type", "rpki"); + + const expectedData = { + + + "a103_21_244_0_24AS13335": { + id: "a103_21_244_0_24AS13335", + origin: 'rpki-monitor', + affected: '103.21.244.0/24', + message: 'The route 103.21.244.0/24 announced by AS13335 is not RPKI valid. Accepted with AS path: [1,2,3,4321,13335]. Valid ROA: origin AS0 prefix 103.21.244.0/23 max length 23', + }, + + "a8_8_8_8_22AS2914": { + id: "a8_8_8_8_22AS2914", + origin: 'rpki-monitor', + affected: '8.8.8.8/22', + message: 'The route 8.8.8.8/22 announced by AS2914 is not covered by a ROA.', + } + }; + + let rpkiTestCompleted = false; + pubSub.subscribe("rpki-monitor", function (type, message) { + + if (!rpkiTestCompleted) { + 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]); + + expect(message).to.contain + .keys([ + "latest", + "earliest" + ]); + + delete expectedData[id]; + if (Object.keys(expectedData).length === 0) { + setTimeout(() => { + rpkiTestCompleted = true; + done(); + }, 5000); + } + } + }); + + }).timeout(asyncTimeout); it("fading alerting", function (done) { diff --git a/tests/config.test.yml b/tests/config.test.yml index b8c3b9f..678ad80 100644 --- a/tests/config.test.yml +++ b/tests/config.test.yml @@ -37,6 +37,16 @@ monitors: params: thresholdMinPeers: 2 + - file: monitorRPKI + channel: rpki-monitor + name: rpki-monitor + params: + thresholdMinPeers: 1 + preCacheROAs: false + refreshVrpListMinutes: 15 + checkUncovered: true + + reports: - file: reportFile channels: @@ -45,14 +55,12 @@ reports: - visibility - path - misconfiguration + - rpki-monitor params: persistAlertData: false alertDataDirectory: alertdata/ -notificationIntervalSeconds: 1800 # Repeat the same alert (which keeps being triggered) after x seconds -alertOnlyOnce: false -fadeOffSeconds: 10 -checkFadeOffGroupsSeconds: 2 + # The file containing the monitored prefixes. Please see monitored_prefixes_test.yml for an example # This is an array (use new lines and dashes!) @@ -76,6 +84,11 @@ processMonitors: host: null port: 8011 + +notificationIntervalSeconds: 1800 # Repeat the same alert (which keeps being triggered) after x seconds +alertOnlyOnce: false +fadeOffSeconds: 10 +checkFadeOffGroupsSeconds: 2 pidFile: bgpalerter.pid multiProcess: false maxMessagesPerSecond: 6000 \ No newline at end of file diff --git a/tests/prefixes.test.yml b/tests/prefixes.test.yml index 75f1d06..fedf18c 100644 --- a/tests/prefixes.test.yml +++ b/tests/prefixes.test.yml @@ -101,4 +101,6 @@ options: 2914: group: default 3333: + group: default + 13335: group: default \ No newline at end of file