Skip to content

Commit

Permalink
Add E2E testing for Slurm parsing for ASPA and BGPsec
Browse files Browse the repository at this point in the history
  • Loading branch information
benjojo committed Feb 23, 2023
1 parent 1e32148 commit 94ab410
Show file tree
Hide file tree
Showing 4 changed files with 124 additions and 4 deletions.
44 changes: 42 additions & 2 deletions cmd/stayrtr/test.rpki.json
Original file line number Diff line number Diff line change
Expand Up @@ -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]
}
]
}
}
4 changes: 2 additions & 2 deletions prefixfile/slurm.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
79 changes: 79 additions & 0 deletions prefixfile/slurm_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package prefixfile

import (
"bytes"
"encoding/json"
"io"
"os"
"testing"

Expand Down Expand Up @@ -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
}
1 change: 1 addition & 0 deletions prefixfile/test.rpki.json

0 comments on commit 94ab410

Please sign in to comment.