2017-05-16 18:26:07 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Test configuration loading and parsing
|
|
|
|
// using the default config
|
|
|
|
|
|
|
|
func TestLoadConfigs(t *testing.T) {
|
|
|
|
|
2018-07-05 14:41:37 +02:00
|
|
|
config, err := loadConfig("../etc/alicelg/alice.example.conf")
|
2017-05-17 16:11:52 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Error("Could not load test config:", err)
|
|
|
|
}
|
|
|
|
|
2017-05-22 11:13:36 +02:00
|
|
|
if config.Server.Listen == "" {
|
|
|
|
t.Error("Listen string not present.")
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(config.Ui.RoutesColumns) == 0 {
|
|
|
|
t.Error("Route columns settings missing")
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(config.Ui.RoutesRejections.Reasons) == 0 {
|
|
|
|
t.Error("Rejection reasons missing")
|
|
|
|
}
|
2018-08-09 22:49:32 +02:00
|
|
|
|
|
|
|
// Check communities
|
2018-09-07 10:24:51 +02:00
|
|
|
label, err := config.Ui.BgpCommunities.Lookup("1:23")
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
if label != "some tag" {
|
2018-08-09 22:49:32 +02:00
|
|
|
t.Error("expcted to find example community 1:23 with 'some tag'",
|
2018-09-07 10:24:51 +02:00
|
|
|
"but got:", label)
|
2018-08-09 22:49:32 +02:00
|
|
|
}
|
2017-05-16 18:26:07 +02:00
|
|
|
}
|
2018-07-05 14:55:12 +02:00
|
|
|
|
|
|
|
func TestSourceConfigDefaultsOverride(t *testing.T) {
|
|
|
|
|
|
|
|
config, err := loadConfig("../etc/alicelg/alice.example.conf")
|
|
|
|
if err != nil {
|
|
|
|
t.Error("Could not load test config:", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get sources
|
|
|
|
rs1 := config.Sources[0]
|
|
|
|
rs2 := config.Sources[1]
|
|
|
|
|
|
|
|
// Source 1 should be on default time
|
|
|
|
// Source 2 should have an override
|
|
|
|
// For now it should be sufficient to test if
|
|
|
|
// the serverTime(rs1) != serverTime(rs2)
|
|
|
|
if rs1.Birdwatcher.ServerTime == rs2.Birdwatcher.ServerTime {
|
|
|
|
t.Error("Server times should be different between",
|
|
|
|
"source 1 and 2 in example configuration",
|
|
|
|
"(alice.example.conf)")
|
|
|
|
}
|
|
|
|
|
2018-07-05 15:27:03 +02:00
|
|
|
// Check presence of timezone, default: UTC (rs1)
|
|
|
|
// override: Europe/Bruessels (rs2)
|
|
|
|
if rs1.Birdwatcher.Timezone != "UTC" {
|
|
|
|
t.Error("Expected RS1 Timezone to be default: UTC")
|
|
|
|
}
|
|
|
|
|
|
|
|
if rs2.Birdwatcher.Timezone != "Europe/Brussels" {
|
|
|
|
t.Error("Expected 'Europe/Brussels', got", rs2.Birdwatcher.Timezone)
|
|
|
|
}
|
2018-07-05 14:55:12 +02:00
|
|
|
}
|
2018-09-17 18:17:41 +02:00
|
|
|
|
|
|
|
func TestBlackholeParsing(t *testing.T) {
|
|
|
|
config, err := loadConfig("../etc/alicelg/alice.example.conf")
|
|
|
|
if err != nil {
|
|
|
|
t.Error("Could not load test config:", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get first source
|
|
|
|
rs1 := config.Sources[0]
|
|
|
|
|
|
|
|
if len(rs1.Blackholes) != 2 {
|
|
|
|
t.Error("Rs1 should have configured 2 blackholes. Got:", rs1.Blackholes)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if rs1.Blackholes[0] != "10.23.6.666" {
|
|
|
|
t.Error("Unexpected blackhole, got:", rs1.Blackholes[0])
|
|
|
|
}
|
|
|
|
}
|
2018-09-17 22:28:20 +02:00
|
|
|
|
|
|
|
func TestSourceASN(t *testing.T) {
|
|
|
|
config, err := loadConfig("../etc/alicelg/alice.example.conf")
|
|
|
|
if err != nil {
|
|
|
|
t.Error("Could not load test config:", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get sources
|
|
|
|
rs1 := config.Sources[0]
|
|
|
|
if rs1.Asn != 99999 {
|
|
|
|
t.Error("Expected RS1 ASN to be: 99999, not:", rs1.Asn)
|
|
|
|
}
|
|
|
|
|
|
|
|
rs2 := config.Sources[1]
|
|
|
|
if rs2.Asn != 9033 {
|
|
|
|
t.Error("Expected RS2 to fall back to AS9033, not:", rs2.Asn)
|
|
|
|
}
|
|
|
|
}
|
2018-09-22 17:56:30 +02:00
|
|
|
|
|
|
|
func TestRpkiConfig(t *testing.T) {
|
|
|
|
config, err := loadConfig("../etc/alicelg/alice.example.conf")
|
|
|
|
if err != nil {
|
|
|
|
t.Error("Could not load test config:", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(config.Ui.Rpki.Valid) != 3 {
|
|
|
|
t.Error("Unexpected RPKI:VALID,", config.Ui.Rpki.Valid)
|
|
|
|
}
|
2018-09-23 17:22:39 +02:00
|
|
|
if len(config.Ui.Rpki.Invalid) != 4 {
|
2018-09-22 17:56:30 +02:00
|
|
|
t.Error("Unexpected RPKI:INVALID,", config.Ui.Rpki.Invalid)
|
2018-09-23 17:22:39 +02:00
|
|
|
return // We would fail hard later
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check fallback
|
|
|
|
if config.Ui.Rpki.NotChecked[0] != "9033" {
|
|
|
|
t.Error(
|
|
|
|
"Expected NotChecked to fall back to defaults, got:",
|
|
|
|
config.Ui.Rpki.NotChecked,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check range postprocessing
|
|
|
|
if config.Ui.Rpki.Invalid[3] != "*" {
|
|
|
|
t.Error("Missing wildcard from config")
|
2018-09-22 17:56:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
t.Log(config.Ui.Rpki)
|
|
|
|
}
|