diff --git a/cmd/stayrtr/test.rpki.json b/cmd/stayrtr/test.rpki.json index 5f71ea3..45840fe 100644 --- a/cmd/stayrtr/test.rpki.json +++ b/cmd/stayrtr/test.rpki.json @@ -43,6 +43,46 @@ { "asn": 33764, "prefix": "2001:42d0:1500::/40", "maxLength": 40, "ta": "afrinic", "expires": 1827518625 }, { "asn": 27808, "prefix": "2800:38::/32", "maxLength": 128, "ta": "lacnic", "expires": 1827677646 }, { "asn": 16814, "prefix": "2800:40::/32", "maxLength": 48, "ta": "lacnic", "expires": 1827665407 }, - { "asn": 16814, "prefix": "2800:40::/32", "maxLength": 32, "ta": "lacnic", "expires": 1827665407 } - ] + { "asn": 16814, "prefix": "2800:40::/32", "maxLength": 32, "ta": "lacnic", "expires": 1827665407 }, + { "asn": 1, "prefix": "192.0.2.0/24", "maxLength": 24, "ta": "lmao", "expires": 1827665407 } + ], + "bgpsec_keys": [ + { + "asn": 15562, + "pubkey": "MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEgFcjQ/g//LAQerAH2Mpp+GucoDAGBbhIqD33wNPsXxnAGb+mtZ7XQrVO9DQ6UlAShtig5+QfEKpTtFgiqfiAFQ==", + "ski": "5d4250e2d81d4448d8a29efce91d29ff075ec9e2" + }, + { + "asn": 64496, + "pubkey": "MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEhv5HEBGixUjKJTlenvcD1Axyi07rFdVY1KhN4vMPYy5y0Mx6zfaiEqJN27jK/l61xC36Vsaezd7eXAsZ1AEEsQ==", + "ski": "510f485d29a29db7b515f9c478f8ed3cb7aa7d23" + }, + { + "asn": 15562, + "pubkey": "MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAE4FxJr0n2bux1uX1Evl+QWwZYvIadPjLuFX2mxqKuAGUhKnr7VLLDgrE++l9p5eH2kWTNVAN22FUU3db/RKpE2w==", + "ski": "be889b55d0b737397d75c49f485b858fa98ad11f" + } + ], + "provider_authorizations": { + "ipv4": [ + { + "customer_asid": 15562, + "providers": [2914,8283,51088,206238] + }, + { + "customer_asid": 64496, + "providers": [1299,6939,7480,32097,50058,61138] + } + ], + "ipv6": [ + { + "customer_asid": 64496, + "providers": [1299,6939,7480,32097,50058,61138] + }, + { + "customer_asid": 15562, + "providers": [2914,8283,51088,206238] + } + ] + } } diff --git a/prefixfile/slurm.json b/prefixfile/slurm.json index 19fa1bd..1c3b837 100644 --- a/prefixfile/slurm.json +++ b/prefixfile/slurm.json @@ -57,13 +57,13 @@ { "asn": 64496, "comment": "My known key for my important ASN", - "SKI": "au5McBIzw6kEM2t29AXSfw==", + "SKI": "NQYXZ0PgL2fdRscxGdVDa+fhAQY=", "routerPublicKey": "MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEhv5HEBGixUjKJTlenvcD1Axyi07rFdVY1KhN4vMPYy5y0Mx6zfaiEqJN27jK/l61xC36Vsaezd7eXAsZ1AEEsQ==" } ], "aspaAssertions": [ { - "customer_asid": 64496, + "customer_asid": 64499, "afi": "ipv6", "provider_set": [64497, 64498], "comment": "Pretend 64497 and 64498 are upstream for 64496 in the IPv6 AFI" diff --git a/prefixfile/slurm_test.go b/prefixfile/slurm_test.go index aa86e15..80aaad3 100644 --- a/prefixfile/slurm_test.go +++ b/prefixfile/slurm_test.go @@ -1,6 +1,9 @@ package prefixfile import ( + "bytes" + "encoding/json" + "io" "os" "testing" @@ -214,3 +217,79 @@ func TestFilterOnVAPs(t *testing.T) { assert.Len(t, removed, 1) assert.Equal(t, uint32(65001), removed[0].CustomerAsid) } + +func TestSlurmEndToEnd(t *testing.T) { + slurmfd, err := os.Open("slurm.json") + if err != nil { + panic(err) + } + config, err := DecodeJSONSlurm(slurmfd) + if err != nil { + t.Errorf("Unable to decode json: %v", err) + } + + rpkifd, err := os.Open("test.rpki.json") + if err != nil { + panic(err) + } + rpkidata, err := io.ReadAll(rpkifd) + if err != nil { + panic(err) + } + vrplist, err := decodeJSON(rpkidata) + if err != nil { + panic(err) + } + + finalVRP, _, finalASPA6, finalBgpsec := + config.FilterAssert(vrplist.Data, vrplist.ASPA.IPv4, vrplist.ASPA.IPv6, vrplist.BgpSecKeys, nil) + + foundAssertVRP := false + for _, vrps := range finalVRP { + if vrps.Prefix == "192.0.2.0/24" { + t.Fatalf("Found filtered VRP") + } + + if vrps.Prefix == "198.51.100.0/24" { + foundAssertVRP = true + } + } + if !foundAssertVRP { + t.Fatalf("Did not find asserted VRP") + } + + foundAssertVAP := false + for _, vaps := range finalASPA6 { + if vaps.CustomerAsid == 64499 { + foundAssertVAP = true + } + if vaps.CustomerAsid == 64496 { + t.Fatalf("Found filtered ASPA") + } + } + if !foundAssertVAP { + t.Fatalf("Did not find asserted VAP") + } + + foundAssertBRK := false + for _, brks := range finalBgpsec { + if brks.Ski == "510f485d29a29db7b515f9c478f8ed3cb7aa7d23" { + t.FailNow() + } + if brks.Ski == "3506176743e02f67dd46c73119d5436be7e10106" { + foundAssertBRK = true + } + } + if !foundAssertBRK { + t.Fatalf("Did not find asserted BR") + } +} + +func decodeJSON(data []byte) (*VRPList, error) { + buf := bytes.NewBuffer(data) + dec := json.NewDecoder(buf) + + var vrplistjson VRPList + err := dec.Decode(&vrplistjson) + return &vrplistjson, err +} diff --git a/prefixfile/test.rpki.json b/prefixfile/test.rpki.json new file mode 120000 index 0000000..b324e2c --- /dev/null +++ b/prefixfile/test.rpki.json @@ -0,0 +1 @@ +../cmd/stayrtr/test.rpki.json \ No newline at end of file