1
0
mirror of https://github.com/nttgin/BGPalerter.git synced 2024-05-19 06:50:08 +00:00

introduced tests for RIS dump

This commit is contained in:
Massimo Candela
2021-05-28 02:50:36 +02:00
parent a8143dc0b2
commit d8cdff9e4b
8 changed files with 176 additions and 0 deletions

View File

@@ -76,6 +76,7 @@ jobs:
npm run test-generate
npm run test-reports
npm run test-neighbor
npm run test-dump
- name: Tests RPKI
run: |

View File

@@ -23,6 +23,7 @@
"test-kafka": "./node_modules/.bin/mocha --exit tests/kafka_tests/*.js --require @babel/register",
"test-neighbor": "./node_modules/.bin/mocha --exit tests/neighbor_tests/*.js --require @babel/register",
"test-npm": "./node_modules/.bin/mocha --exit tests/npm_tests/*.js --require @babel/register",
"test-dump": "rm -rf volumetests/ && ./node_modules/.bin/mocha --exit tests/dump_tests/*.js --require @babel/register",
"test-rpki": "./node_modules/.bin/mocha --exit tests/rpki_tests/tests.default.js --require @babel/register && ./node_modules/.bin/mocha --exit tests/rpki_tests/tests.external.js --require @babel/register && ./node_modules/.bin/mocha --exit tests/rpki_tests/tests.external-missing-roas.js --require @babel/register && rm -f -R .cache/ && ./node_modules/.bin/mocha --exit tests/rpki_tests/tests.external-roas.js --require @babel/register && ./node_modules/.bin/mocha --exit tests/rpki_tests/tests.api.js --require @babel/register",
"build": "./build.sh",
"compile": "rm -rf dist/ && ./node_modules/.bin/babel index.js -d dist && ./node_modules/.bin/babel src -d dist/src && cp package.json dist/package.json && cp README.md dist/README.md && cp .npm* dist/",

View File

@@ -0,0 +1,57 @@
environment: test
connectors:
- file: connectorRISDump
name: dmp
monitors:
- file: monitorHijack
channel: hijack
name: basic-hijack-detection
params:
thresholdMinPeers: 0
reports:
- file: reportFile
channels:
- hijack
- newprefix
- visibility
- path
- misconfiguration
- rpki
params:
persistAlertData: false
alertDataDirectory: alertdata/
# The file containing the monitored prefixes. Please see monitored_prefixes_test.yml for an example
# This is an array (use new lines and dashes!)
monitoredPrefixesFiles:
- prefixes.test.yml
logging:
directory: logs
logRotatePattern: YYYY-MM-DD # Whenever the pattern changes, a new file is created and the old one rotated
maxRetainedFiles: 10
maxFileSizeMB: 15
compressOnRotation: true
checkForUpdatesAtBoot: true
persistStatus: true
volume: volumetests/
rpki:
preCacheROAs: true
refreshVrpListMinutes: 15
vrpFile: tests/dump_tests/vrps.json
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

View File

@@ -0,0 +1,4 @@
reportFile:
test:
- filename

View File

@@ -0,0 +1,7 @@
193.0.20.0/23:
description: No description provided
asn:
- 1234
ignoreMorespecifics: false
ignore: false
group: noc

105
tests/dump_tests/tests.js Normal file
View File

@@ -0,0 +1,105 @@
/*
* BSD 3-Clause License
*
* Copyright (c) 2019, NTT Ltd.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
const chai = require("chai");
const fs = require("fs");
const chaiSubset = require('chai-subset');
const readLastLines = require("read-last-lines");
chai.use(chaiSubset);
const expect = chai.expect;
const volume = "volumetests/";
const asyncTimeout = 120000;
global.EXTERNAL_VERSION_FOR_TEST = "0.0.1";
global.EXTERNAL_CONFIG_FILE = volume + "config.test.yml";
// Prepare test environment
if (!fs.existsSync(volume)) {
fs.mkdirSync(volume);
} else {
fs.rmdirSync(volume, { recursive: true });
fs.mkdirSync(volume);
}
fs.copyFileSync("tests/dump_tests/config.test.yml", volume + "config.test.yml");
fs.copyFileSync("tests/dump_tests/prefixes.test.yml", volume + "prefixes.test.yml");
describe("Alerting", function () {
it("RIS dump test", function (done) {
const worker = require("../../index");
const pubSub = worker.pubSub;
const expectedData = {
"3333-193.0.20.0/23": {
id: '3333-193.0.20.0/23',
truncated: false,
origin: 'basic-hijack-detection',
affected: 1234,
message: 'The prefix 193.0.20.0/23 (No description provided) is announced by AS3333 instead of AS1234',
data: [
{
affected: 1234
}
]
}
};
let dumpTestCompleted = false;
pubSub.subscribe("hijack", function (message, type) {
try {
if (!dumpTestCompleted) {
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]);
delete expectedData[id];
if (Object.keys(expectedData).length === 0) {
setTimeout(() => {
dumpTestCompleted = true;
done();
}, 5000);
}
}
} catch (error) {
dumpTestCompleted = true;
done(error);
}
});
}).timeout(asyncTimeout);
});

View File

@@ -0,0 +1 @@
[]