mirror of
https://github.com/nttgin/BGPalerter.git
synced 2024-05-19 06:50:08 +00:00
cover with tests prefix generation procedure
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -11,4 +11,5 @@ alertdata/
|
|||||||
.npmrc
|
.npmrc
|
||||||
.cache/
|
.cache/
|
||||||
volumetests/
|
volumetests/
|
||||||
tests/rpki_tests/vrp.json
|
tests/rpki_tests/vrp.json
|
||||||
|
tests/generate_tests/prefixes.yml
|
@@ -12,3 +12,4 @@ alertdata/
|
|||||||
.cache/
|
.cache/
|
||||||
volumetests/
|
volumetests/
|
||||||
tests/rpki_tests/vrp.json
|
tests/rpki_tests/vrp.json
|
||||||
|
tests/generate_tests/prefixes.yml
|
@@ -11,6 +11,8 @@ jobs:
|
|||||||
script: npm run test-reports
|
script: npm run test-reports
|
||||||
- name: "Tests rpki"
|
- name: "Tests rpki"
|
||||||
script: npm run test-rpki
|
script: npm run test-rpki
|
||||||
|
- name: "Tests prefix generation"
|
||||||
|
script: npm run test-generate
|
||||||
- name: "Tests with proxy"
|
- name: "Tests with proxy"
|
||||||
before_script:
|
before_script:
|
||||||
- npm install -g anyproxy
|
- npm install -g anyproxy
|
||||||
|
@@ -13,6 +13,7 @@
|
|||||||
"test": "rm -rf volumetests/ && ./node_modules/.bin/mocha --exit tests/*.js --require @babel/register && rm -rf volumetests/",
|
"test": "rm -rf volumetests/ && ./node_modules/.bin/mocha --exit tests/*.js --require @babel/register && rm -rf volumetests/",
|
||||||
"test-reports": "./node_modules/.bin/mocha --exit tests/reports_tests/*.js --require @babel/register",
|
"test-reports": "./node_modules/.bin/mocha --exit tests/reports_tests/*.js --require @babel/register",
|
||||||
"test-proxy": "./node_modules/.bin/mocha --exit tests/proxy_tests/*.js --require @babel/register",
|
"test-proxy": "./node_modules/.bin/mocha --exit tests/proxy_tests/*.js --require @babel/register",
|
||||||
|
"test-generate": "./node_modules/.bin/mocha --exit tests/generate_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",
|
"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",
|
||||||
"build": "./build.sh",
|
"build": "./build.sh",
|
||||||
"watch-and-serve": "nodemon -e yml,js,json,txt --inspect --exec babel-node index.js",
|
"watch-and-serve": "nodemon -e yml,js,json,txt --inspect --exec babel-node index.js",
|
||||||
|
@@ -36,7 +36,6 @@ import Input from "./input";
|
|||||||
import ipUtils from "ip-sub";
|
import ipUtils from "ip-sub";
|
||||||
import { AS } from "../model";
|
import { AS } from "../model";
|
||||||
|
|
||||||
|
|
||||||
export default class InputYml extends Input {
|
export default class InputYml extends Input {
|
||||||
|
|
||||||
constructor(config){
|
constructor(config){
|
||||||
|
84
tests/generate_tests/config.test.yml
Normal file
84
tests/generate_tests/config.test.yml
Normal file
@@ -0,0 +1,84 @@
|
|||||||
|
environment: test
|
||||||
|
|
||||||
|
connectors:
|
||||||
|
- file: connectorTest
|
||||||
|
name: tes
|
||||||
|
params:
|
||||||
|
testType: withdrawal
|
||||||
|
|
||||||
|
monitors:
|
||||||
|
- file: monitorHijack
|
||||||
|
channel: hijack
|
||||||
|
name: basic-hijack-detection
|
||||||
|
params:
|
||||||
|
thresholdMinPeers: 0
|
||||||
|
|
||||||
|
- file: monitorNewPrefix
|
||||||
|
channel: newprefix
|
||||||
|
name: prefix-detection
|
||||||
|
params:
|
||||||
|
thresholdMinPeers: 0
|
||||||
|
|
||||||
|
- file: monitorVisibility
|
||||||
|
channel: visibility
|
||||||
|
name: withdrawal-detection
|
||||||
|
params:
|
||||||
|
thresholdMinPeers: 4
|
||||||
|
|
||||||
|
- file: monitorPath
|
||||||
|
channel: path
|
||||||
|
name: path-matching
|
||||||
|
params:
|
||||||
|
thresholdMinPeers: 0
|
||||||
|
|
||||||
|
- file: monitorAS
|
||||||
|
channel: misconfiguration
|
||||||
|
name: asn-monitor
|
||||||
|
params:
|
||||||
|
thresholdMinPeers: 2
|
||||||
|
|
||||||
|
- file: monitorRPKI
|
||||||
|
channel: rpki
|
||||||
|
name: rpki-monitor
|
||||||
|
params:
|
||||||
|
thresholdMinPeers: 1
|
||||||
|
preCacheROAs: false
|
||||||
|
checkUncovered: true
|
||||||
|
|
||||||
|
|
||||||
|
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.yml
|
||||||
|
|
||||||
|
logging:
|
||||||
|
directory: logs
|
||||||
|
logRotatePattern: YYYY-MM-DD # Whenever the pattern changes, a new file is created and the old one rotated
|
||||||
|
backlogSize: 1
|
||||||
|
maxRetainedFiles: 10
|
||||||
|
maxFileSizeMB: 15
|
||||||
|
compressOnRotation: true
|
||||||
|
|
||||||
|
checkForUpdatesAtBoot: false
|
||||||
|
|
||||||
|
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
|
46
tests/generate_tests/prefixes.final.default.yml
Normal file
46
tests/generate_tests/prefixes.final.default.yml
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
193.0.10.0/23:
|
||||||
|
description: No description provided (valid ROA available)
|
||||||
|
asn:
|
||||||
|
- 3333
|
||||||
|
ignoreMorespecifics: false
|
||||||
|
ignore: false
|
||||||
|
group: default
|
||||||
|
193.0.20.0/23:
|
||||||
|
description: No description provided (valid ROA available)
|
||||||
|
asn:
|
||||||
|
- 3333
|
||||||
|
ignoreMorespecifics: false
|
||||||
|
ignore: false
|
||||||
|
group: default
|
||||||
|
193.0.0.0/21:
|
||||||
|
description: No description provided (valid ROA available)
|
||||||
|
asn:
|
||||||
|
- 3333
|
||||||
|
ignoreMorespecifics: false
|
||||||
|
ignore: false
|
||||||
|
group: default
|
||||||
|
193.0.12.0/23:
|
||||||
|
description: No description provided (valid ROA available)
|
||||||
|
asn:
|
||||||
|
- 3333
|
||||||
|
ignoreMorespecifics: false
|
||||||
|
ignore: false
|
||||||
|
group: default
|
||||||
|
193.0.18.0/23:
|
||||||
|
description: No description provided (valid ROA available)
|
||||||
|
asn:
|
||||||
|
- 3333
|
||||||
|
ignoreMorespecifics: false
|
||||||
|
ignore: false
|
||||||
|
group: default
|
||||||
|
193.0.22.0/23:
|
||||||
|
description: No description provided (valid ROA available)
|
||||||
|
asn:
|
||||||
|
- 3333
|
||||||
|
ignoreMorespecifics: false
|
||||||
|
ignore: false
|
||||||
|
group: default
|
||||||
|
options:
|
||||||
|
monitorASns:
|
||||||
|
'3333':
|
||||||
|
group: default
|
46
tests/generate_tests/prefixes.final.group.yml
Normal file
46
tests/generate_tests/prefixes.final.group.yml
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
193.0.10.0/23:
|
||||||
|
description: No description provided (valid ROA available)
|
||||||
|
asn:
|
||||||
|
- 3333
|
||||||
|
ignoreMorespecifics: false
|
||||||
|
ignore: false
|
||||||
|
group: test
|
||||||
|
193.0.20.0/23:
|
||||||
|
description: No description provided (valid ROA available)
|
||||||
|
asn:
|
||||||
|
- 3333
|
||||||
|
ignoreMorespecifics: false
|
||||||
|
ignore: false
|
||||||
|
group: test
|
||||||
|
193.0.0.0/21:
|
||||||
|
description: No description provided (valid ROA available)
|
||||||
|
asn:
|
||||||
|
- 3333
|
||||||
|
ignoreMorespecifics: false
|
||||||
|
ignore: false
|
||||||
|
group: test
|
||||||
|
193.0.12.0/23:
|
||||||
|
description: No description provided (valid ROA available)
|
||||||
|
asn:
|
||||||
|
- 3333
|
||||||
|
ignoreMorespecifics: false
|
||||||
|
ignore: false
|
||||||
|
group: test
|
||||||
|
193.0.18.0/23:
|
||||||
|
description: No description provided (valid ROA available)
|
||||||
|
asn:
|
||||||
|
- 3333
|
||||||
|
ignoreMorespecifics: false
|
||||||
|
ignore: false
|
||||||
|
group: test
|
||||||
|
193.0.22.0/23:
|
||||||
|
description: No description provided (valid ROA available)
|
||||||
|
asn:
|
||||||
|
- 3333
|
||||||
|
ignoreMorespecifics: false
|
||||||
|
ignore: false
|
||||||
|
group: test
|
||||||
|
options:
|
||||||
|
monitorASns:
|
||||||
|
'3333':
|
||||||
|
group: test
|
122
tests/generate_tests/tests.js
Normal file
122
tests/generate_tests/tests.js
Normal file
@@ -0,0 +1,122 @@
|
|||||||
|
/*
|
||||||
|
* 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 yaml = require("js-yaml");
|
||||||
|
const chaiSubset = require('chai-subset');
|
||||||
|
const generatePrefixes = require('../../src/generatePrefixesList');
|
||||||
|
const expect = chai.expect;
|
||||||
|
const asyncTimeout = 60000;
|
||||||
|
|
||||||
|
chai.use(chaiSubset);
|
||||||
|
|
||||||
|
global.EXTERNAL_CONFIG_FILE = "tests/generate_tests/config.test.yml";
|
||||||
|
// const worker = require("../../index");
|
||||||
|
// const pubSub = worker.pubSub;
|
||||||
|
|
||||||
|
describe("Prefix List", function() {
|
||||||
|
|
||||||
|
it("generate file - default group", function (done) {
|
||||||
|
const asns = ["3333"];
|
||||||
|
const outputFile = "tests/generate_tests/prefixes.yml";
|
||||||
|
const originalFile = "tests/generate_tests/prefixes.final.default.yml";
|
||||||
|
|
||||||
|
const inputParameters = {
|
||||||
|
asnList: asns,
|
||||||
|
outputFile,
|
||||||
|
exclude: ["2001:67c:2e8::/48"],
|
||||||
|
excludeDelegated: true,
|
||||||
|
prefixes: null,
|
||||||
|
monitoredASes: asns,
|
||||||
|
httpProxy: null,
|
||||||
|
debug: false,
|
||||||
|
historical: false,
|
||||||
|
group: null
|
||||||
|
}
|
||||||
|
console.log = function(){};
|
||||||
|
generatePrefixes(inputParameters)
|
||||||
|
.then(() => {
|
||||||
|
const result = fs.readFileSync(outputFile, 'utf8');
|
||||||
|
fs.unlinkSync(outputFile);
|
||||||
|
const original = fs.readFileSync(originalFile, 'utf8');
|
||||||
|
const resultJson = yaml.safeLoad(result) || {};
|
||||||
|
const originalJson = yaml.safeLoad(original) || {};
|
||||||
|
|
||||||
|
Object.keys(resultJson)
|
||||||
|
Object.keys(originalJson)
|
||||||
|
|
||||||
|
expect(resultJson).to.contain.keys(Object.keys(originalJson));
|
||||||
|
expect(Object.keys(resultJson).length).to.equal(Object.keys(originalJson).length);
|
||||||
|
|
||||||
|
expect(resultJson).to.containSubset(originalJson);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
}).timeout(asyncTimeout);
|
||||||
|
|
||||||
|
it("generate file - specific group", function (done) {
|
||||||
|
const asns = ["3333"];
|
||||||
|
const outputFile = "tests/generate_tests/prefixes.yml";
|
||||||
|
const originalFile = "tests/generate_tests/prefixes.final.group.yml";
|
||||||
|
|
||||||
|
const inputParameters = {
|
||||||
|
asnList: asns,
|
||||||
|
outputFile,
|
||||||
|
exclude: ["2001:67c:2e8::/48"],
|
||||||
|
excludeDelegated: true,
|
||||||
|
prefixes: null,
|
||||||
|
monitoredASes: asns,
|
||||||
|
httpProxy: null,
|
||||||
|
debug: false,
|
||||||
|
historical: false,
|
||||||
|
group: "test"
|
||||||
|
}
|
||||||
|
console.log = function(){};
|
||||||
|
generatePrefixes(inputParameters)
|
||||||
|
.then(() => {
|
||||||
|
const result = fs.readFileSync(outputFile, 'utf8');
|
||||||
|
fs.unlinkSync(outputFile);
|
||||||
|
const original = fs.readFileSync(originalFile, 'utf8');
|
||||||
|
const resultJson = yaml.safeLoad(result) || {};
|
||||||
|
const originalJson = yaml.safeLoad(original) || {};
|
||||||
|
|
||||||
|
Object.keys(resultJson)
|
||||||
|
Object.keys(originalJson)
|
||||||
|
|
||||||
|
expect(resultJson).to.contain.keys(Object.keys(originalJson));
|
||||||
|
expect(Object.keys(resultJson).length).to.equal(Object.keys(originalJson).length);
|
||||||
|
|
||||||
|
expect(resultJson).to.containSubset(originalJson);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
}).timeout(asyncTimeout);
|
||||||
|
});
|
Reference in New Issue
Block a user