From 7321b6adb7ed67404a1d10edbf1e4b3276fcad48 Mon Sep 17 00:00:00 2001 From: Martin Hoffmann Date: Fri, 19 May 2023 09:21:48 +0200 Subject: [PATCH] Fix allowed ASN format in validity JSON input. (#861) The PR restores the ability to parse ASNs in JSON input to the validity command as either a string or a number. --- src/validity.rs | 16 ++++++++++++++++ test/validate/beacons.json | 12 ++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 test/validate/beacons.json diff --git a/src/validity.rs b/src/validity.rs index d500d2b..df293c1 100644 --- a/src/validity.rs +++ b/src/validity.rs @@ -498,6 +498,7 @@ struct Request { prefix: addr::Prefix, /// The origin AS number of the route announcement. + #[serde(deserialize_with = "Asn::deserialize_from_any")] asn: Asn, } @@ -516,3 +517,18 @@ const DESCRIPTION_BAD_LEN: &str = "At least one VRP Covers the Route Prefix, \ matching this route origin ASN"; const DESCRIPTION_NOT_FOUND: &str = "No VRP Covers the Route Prefix"; + +//============ Tests ========================================================= + +#[cfg(test)] +mod test { + use super::*; + + #[test] + fn request_list_from_json_reader() { + let _ = RequestList::from_json_reader( + &mut include_bytes!("../test/validate/beacons.json").as_ref() + ); + } +} + diff --git a/test/validate/beacons.json b/test/validate/beacons.json new file mode 100644 index 0000000..15943f5 --- /dev/null +++ b/test/validate/beacons.json @@ -0,0 +1,12 @@ +{ + "routes": [{ + "asn": "AS12654", + "prefix": "93.175.147.0/24" + }, + { + "asn": 12654, + "prefix": "2001:7fb:fd02::/48" + } + ] +} +