Debian Codegraph @

src/check/mod.rs

raw
1 //! Conformance checks of RDAP structures.
2
3 use std::{any::TypeId, sync::LazyLock};
4
5 use {
6 crate::response::RdapResponse,
7 serde::{Deserialize, Serialize},
8 strum::IntoEnumIterator,
9 strum::{EnumIter, EnumMessage, EnumString, FromRepr, VariantArray},
10 };
11
12 use strum::Display as EnumDisplay;
13
14 #[doc(inline)]
15 pub use string::*;
16
17 mod autnum;
18 mod domain;
19 mod entity;
20 mod error;
21 mod help;
22 mod httpdata;
23 mod nameserver;
24 mod network;
25 pub mod process;
26 mod rpki;
27 mod search;
28 mod string;
29 mod types;
30
31 /// The max length of the check class string representations.
32 pub static CHECK_CLASS_LEN: LazyLock<usize> = LazyLock::new(|| {
33 CheckClass::iter()
34 .max_by_key(|x| x.to_string().len())
35 .map_or(8, |x| x.to_string().len())
36 });
37
38 /// Describes the classes of checks.
39 #[derive(
40 EnumIter,
41 EnumString,
42 Debug,
43 EnumDisplay,
44 PartialEq,
45 Eq,
46 PartialOrd,
47 Ord,
48 Serialize,
49 Deserialize,
50 Clone,
51 Copy,
52 VariantArray,
53 )]
54 #[strum(serialize_all = "snake_case")]
55 #[serde(rename_all = "snake_case")]
56 pub enum CheckClass {
57 /// Informational
58 ///
59 /// This class represents informational items.
60 #[strum(serialize = "Info")]
61 Informational,
62
63 /// Specification Note
64 ///
65 /// This class represents notes about the RDAP response with respect to
66 /// the various RDAP and RDAP related specifications.
67 #[strum(serialize = "SpecNote")]
68 SpecificationNote,
69
70 /// STD 95 Warnings
71 ///
72 /// This class represents warnings that may cause some clients to be unable
73 /// to conduct some operations.
74 #[strum(serialize = "Std95Warn")]
75 Std95Warning,
76
77 /// STD 95 Errors
78 ///
79 /// This class represents errors in the RDAP with respect to STD 95.
80 #[strum(serialize = "Std95Err")]
81 Std95Error,
82
83 /// Cidr0 Errors
84 ///
85 /// This class represents errors with respect to CIDR0.
86 #[strum(serialize = "Cidr0Err")]
87 Cidr0Error,
88
89 /// Gtld Profile Errors
90 ///
91 /// This class represents errors with respect to the gTLD RDAP profile.
92 #[strum(serialize = "GtldProfileErr")]
93 GtldProfileError,
94
95 /// Rpki1 Errors
96 ///
97 /// This class represents errors with respect to the RPKI extension.
98 #[strum(serialize = "Rpki1Err")]
99 Rpki1Error,
100 }
101
102 /// All check classes
103 pub static ALL_CHECK_CLASSES: &[CheckClass] = CheckClass::VARIANTS;
104 /// All warning and error check classes.
105 pub static WARNING_CHECK_CLASSES: &[CheckClass] = &[
106 CheckClass::Std95Warning,
107 CheckClass::Std95Error,
108 CheckClass::Cidr0Error,
109 CheckClass::GtldProfileError,
110 ];
111 /// All error check classes.
112 pub static ERROR_CHECK_CLASSES: &[CheckClass] = &[
113 CheckClass::Std95Error,
114 CheckClass::Cidr0Error,
115 CheckClass::GtldProfileError,
116 ];
117
118 /// Represents the name of an RDAP structure for which a check appears.
119 ///
120 /// An RDAP data structure is not the same as a Rust struct in that RDAP
121 /// data structures may consist of arrays and sometimes structured data
122 /// within a string.
123 #[derive(
124 Debug,
125 Serialize,
126 Deserialize,
127 Clone,
128 Copy,
129 PartialEq,
130 PartialOrd,
131 Eq,
132 Ord,
133 EnumDisplay,
134 EnumString,
135 )]
136 #[strum(serialize_all = "snake_case")]
137 #[serde(rename_all = "snake_case")]
138 pub enum RdapStructure {
139 Autnum,
140 AutnumSearchResults,
141 Cidr0,
142 Domain,
143 DomainSearchResults,
144 DsData,
145 Entities,
146 Entity,
147 EntitySearchResults,
148 Event,
149 Events,
150 Error,
151 Help,
152 Handle,
153 HttpData,
154 IpNetwork,
155 IpSearchResults,
156 KeyData,
157 Link,
158 Links,
159 Nameserver,
160 NameserverSearchResults,
161 NoticeOrRemark,
162 Notice,
163 Notices,
164 PublicIds,
165 Port43,
166 RdapConformance,
167 Redacted,
168 Remark,
169 Remarks,
170 Rpk1Roa,
171 Rpk1Aspa,
172 Rpk1X509ResourceCert,
173 Rpk1RoaSearchResults,
174 Rpk1AspaSearchResults,
175 Rpk1X509ResourceCertSearchResults,
176 SecureDns,
177 Status,
178 }
179
180 /// Contains many [CheckItem] structures and sub checks.
181 ///
182 /// Checks are found on object classes and structures defined in [RdapStructure].
183 #[derive(Debug, Serialize, Deserialize, Clone, PartialEq, PartialOrd, Eq, Ord)]
184 pub struct Checks {
185 /// The structure for which this check is relevant.
186 pub rdap_struct: RdapStructure,
187 /// Index of the structure in an array.
188 pub index: Option<usize>,
189 /// The check items for this structure.
190 pub items: Vec<CheckItem>,
191 /// Sub or child checks belonging to substructures.
192 pub sub_checks: Vec<Checks>,
193 }
194
195 impl Checks {
196 pub fn for_item(rdap_struct: RdapStructure, check_item: CheckItem) -> Self {
197 Self {
198 rdap_struct,
199 index: None,
200 items: vec![check_item],
201 sub_checks: vec![],
202 }
203 }
204
205 pub fn sub(&self, rdap_struct: RdapStructure) -> Option<&Self> {
206 self.sub_checks
207 .iter()
208 .find(|check| check.rdap_struct == rdap_struct)
209 }
210 }
211
212 /// A specific check item.
213 #[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, PartialOrd, Ord)]
214 pub struct CheckItem {
215 pub check_class: CheckClass,
216 pub check: Check,
217 }
218
219 impl std::fmt::Display for CheckItem {
220 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
221 f.write_fmt(format_args!(
222 "{}:({:0>4}) {}",
223 self.check_class,
224 self.check as usize,
225 self.check
226 .get_message()
227 .unwrap_or("[Check has no description]"),
228 ))
229 }
230 }
231
232 // Represents a summary of a [CheckItem] when it is processed for the purposes of serialization.
233 #[derive(Debug, Serialize, Clone, PartialEq, Eq, PartialOrd, Ord)]
234 pub struct CheckSummary {
235 pub code: usize,
236 pub structure: String,
237 pub message: String,
238 pub item: CheckItem,
239 }
240
241 impl CheckSummary {
242 pub fn summarize(&self) -> (String, String) {
243 (self.structure.clone(), self.item.to_string())
244 }
245 }
246
247 /// Trait for an item that can get checks.
248 pub trait GetChecks {
249 fn get_checks(&self, index: Option<usize>, params: CheckParams) -> Checks;
250 }
251
252 /// Parameters for finding checks.
253 #[derive(Clone, Copy)]
254 pub struct CheckParams<'a> {
255 pub root: &'a RdapResponse,
256 pub parent_type: TypeId,
257 pub allow_unreg_ext: bool,
258 }
259
260 impl CheckParams<'_> {
261 pub fn from_parent(&self, parent_type: TypeId) -> Self {
262 Self {
263 root: self.root,
264 parent_type,
265 allow_unreg_ext: self.allow_unreg_ext,
266 }
267 }
268
269 pub fn for_rdap(rdap: &RdapResponse) -> CheckParams<'_> {
270 CheckParams {
271 root: rdap,
272 parent_type: rdap.get_type(),
273 allow_unreg_ext: false,
274 }
275 }
276 }
277
278 impl GetChecks for RdapResponse {
279 fn get_checks(&self, index: Option<usize>, params: CheckParams) -> Checks {
280 match &self {
281 Self::Entity(e) => e.get_checks(index, params),
282 Self::Domain(d) => d.get_checks(index, params),
283 Self::Nameserver(n) => n.get_checks(index, params),
284 Self::Autnum(a) => a.get_checks(index, params),
285 Self::Network(n) => n.get_checks(index, params),
286 Self::DomainSearchResults(r) => r.get_checks(index, params),
287 Self::EntitySearchResults(r) => r.get_checks(index, params),
288 Self::NameserverSearchResults(r) => r.get_checks(index, params),
289 Self::IpSearchResults(r) => r.get_checks(index, params),
290 Self::AutnumSearchResults(r) => r.get_checks(index, params),
291 Self::Rpki1Roa(r) => r.get_checks(index, params),
292 Self::Rpki1Aspa(r) => r.get_checks(index, params),
293 Self::Rpki1X509ResourceCert(r) => r.get_checks(index, params),
294 Self::Rpki1RoaSearchResults(r) => r.get_checks(index, params),
295 Self::Rpki1AspaSearchResults(r) => r.get_checks(index, params),
296 Self::Rpki1X509ResourceCertSearchResults(r) => r.get_checks(index, params),
297 Self::ErrorResponse(e) => e.get_checks(index, params),
298 Self::Help(h) => h.get_checks(index, params),
299 }
300 }
301 }
302
303 /// Trait to get checks for groups of data structures such as those
304 /// related to [crate::response::Common] and [crate::response::ObjectCommon].
305 pub trait GetGroupChecks {
306 fn get_group_checks(&self, params: CheckParams) -> Vec<Checks>;
307 }
308
309 /// Traverse the checks, and return true if one is found.
310 pub fn traverse_checks<F>(
311 checks: &Checks,
312 classes: &[CheckClass],
313 parent_tree: Option<String>,
314 f: &mut F,
315 ) -> bool
316 where
317 F: FnMut(&str, &CheckItem),
318 {
319 let mut found = false;
320 let struct_tree = format!(
321 "{}/{}{}",
322 parent_tree.unwrap_or_else(|| "[ROOT]".to_string()),
323 checks.rdap_struct,
324 checks
325 .index
326 .map_or_else(|| "".to_string(), |i| format!("/[{i}]")),
327 );
328 for item in &checks.items {
329 if classes.contains(&item.check_class) {
330 f(&struct_tree, item);
331 found = true;
332 }
333 }
334 for sub_checks in &checks.sub_checks {
335 if traverse_checks(sub_checks, classes, Some(struct_tree.clone()), f) {
336 found = true
337 }
338 }
339 found
340 }
341
342 // Is a check found in any check or subcheck.
343 pub fn contains_check(check: Check, checks: &Checks) -> bool {
344 checks.items.iter().any(|c| c.check == check)
345 || checks.sub_checks.iter().any(|c| contains_check(check, c))
346 }
347
348 /// Returns true if the check is in a check list
349 pub fn is_checked(check: Check, checks: &[Checks]) -> bool {
350 checks.iter().any(|c| is_checked_item(check, c))
351 }
352
353 /// Returns true if the check is in a list of check items.
354 pub fn is_checked_item(check: Check, checks: &Checks) -> bool {
355 checks.items.iter().any(|c| c.check == check)
356 }
357
358 /// The variant check types.
359 #[derive(
360 Debug,
361 EnumMessage,
362 EnumString,
363 EnumDisplay,
364 Serialize,
365 Deserialize,
366 PartialEq,
367 PartialOrd,
368 Eq,
369 Ord,
370 Clone,
371 Copy,
372 FromRepr,
373 )]
374 #[strum(serialize_all = "snake_case")]
375 #[serde(rename_all = "snake_case")]
376 pub enum Check {
377 // RDAP Conformance 100 - 199
378 #[strum(message = "RFC 9083 requires 'rdapConformance' on the root object.")]
379 RdapConformanceMissing = 100,
380 #[strum(message = "'rdapConformance' can only appear at the top of response.")]
381 RdapConformanceInvalidParent = 101,
382 #[strum(message = "declared extension may not be registered.")]
383 UnknownExtension = 102,
384 #[strum(message = "'rdapConformance' is empty.")]
385 RdapConformanceIsEmpty = 103,
386
387 // Link 200 - 299
388 #[strum(message = "'value' property not found in Link structure as required by RFC 9083")]
389 LinkMissingValueProperty = 200,
390 #[strum(message = "'rel' property not found in Link structure as required by RFC 9083")]
391 LinkMissingRelProperty = 201,
392 #[strum(message = "ambiguous follow because related link has no 'type' property")]
393 LinkRelatedHasNoType = 202,
394 #[strum(message = "ambiguous follow because related link does not have RDAP media type")]
395 LinkRelatedIsNotRdap = 203,
396 #[strum(message = "self link has no 'type' property")]
397 LinkSelfHasNoType = 204,
398 #[strum(message = "self link does not have RDAP media type")]
399 LinkSelfIsNotRdap = 205,
400 #[strum(message = "RFC 9083 recommends self links for all object classes")]
401 LinkObjectClassHasNoSelf = 206,
402 #[strum(message = "'href' property not found in Link structure as required by RFC 9083")]
403 LinkMissingHrefProperty = 207,
404 #[strum(message = "ambiguous follow because the 'href' may not contain an RDAP URL")]
405 LinkRelatedNotToRdap = 208,
406 #[strum(message = "links array is empty")]
407 LinksArrayIsEmpty = 209,
408
409 // Domain Variant 300 - 399
410 #[strum(message = "empty domain variant is ambiguous")]
411 VariantEmptyDomain = 300,
412
413 // Event 400 - 499
414 #[strum(message = "event date is absent")]
415 EventDateIsAbsent = 400,
416 #[strum(message = "event date is not RFC 3339 compliant")]
417 EventDateIsNotRfc3339 = 401,
418 #[strum(message = "event action is absent")]
419 EventActionIsAbsent = 402,
420 #[strum(message = "event action is unknown")]
421 EventActionIsUnknown = 403,
422 #[strum(message = "event array is empty")]
423 EventsArrayIsEmpty = 404,
424
425 // Notice Or Remark 500 - 599
426 #[strum(message = "RFC 9083 requires a description in a notice or remark")]
427 NoticeOrRemarkDescriptionIsAbsent = 500,
428 #[strum(message = "RFC 9083 requires a description to be an array of strings")]
429 NoticeOrRemarkDescriptionIsString = 501,
430 #[strum(message = "type for notice/remark is unknown")]
431 NoticeOrRemarkUnknownType = 502,
432 #[strum(message = "notices array is empty")]
433 NoticesArrayIsEmpty = 503,
434 #[strum(message = "remarks array is empty")]
435 RemarksArrayIsEmpty = 504,
436
437 // Handle 600 - 699
438 #[strum(message = "handle appears to be empty or only whitespace")]
439 HandleIsEmpty = 600,
440 #[strum(message = "handle is not a string")]
441 HandleIsNotString = 601,
442 #[strum(message = "parent handle is not a string")]
443 ParentHandleIsNotString = 602,
444
445 // Status 700 - 799
446 #[strum(message = "status appears to be empty or only whitespace")]
447 StatusIsEmpty = 700,
448 #[strum(message = "status value not registered")]
449 StatusValueUnknown = 701,
450
451 // Role 800 - 899
452 #[strum(message = "role appears to be empty or only whitespace")]
453 RoleIsEmpty = 800,
454 #[strum(message = "entity role may not be registered")]
455 UnknownRole = 801,
456 #[strum(message = "role is a string, not array of strings")]
457 RoleIsString = 802,
458
459 // LDH Name 900 - 999
460 #[strum(message = "ldhName does not appear to be an LDH name")]
461 LdhNameInvalid = 900,
462 #[strum(message = "Documentation domain name. See RFC 6761")]
463 LdhNameDocumentation = 901,
464 #[strum(message = "Unicode name does not match LDH")]
465 LdhNameDoesNotMatchUnicode = 902,
466
467 // Unicode Name 1000 - 1099
468 #[strum(message = "unicodeName does not appear to be a domain name")]
469 UnicodeNameInvalidDomain = 1000,
470 #[strum(message = "unicodeName does not appear to be valid Unicode")]
471 UnicodeNameInvalidUnicode = 1001,
472
473 // Network Or Autnum Name 1100 - 1199
474 #[strum(message = "name appears to be empty or only whitespace")]
475 NetworkOrAutnumNameIsEmpty = 1100,
476 #[strum(message = "name is not a string")]
477 NetworkOrAutnumNameIsNotString = 1101,
478
479 // Network or Autnum Type 1200 - 1299
480 #[strum(message = "type appears to be empty or only whitespace")]
481 NetworkOrAutnumTypeIsEmpty = 1200,
482 #[strum(message = "type is not a string")]
483 NetworkOrAutnumTypeIsNotString = 1201,
484
485 // IP Address 1300 - 1399
486 #[strum(message = "start or end IP address is missing")]
487 IpAddressMissing = 1300,
488 #[strum(message = "IP address is malformed")]
489 IpAddressMalformed = 1301,
490 #[strum(message = "end IP address comes before start IP address")]
491 IpAddressEndBeforeStart = 1302,
492 #[strum(message = "IP version does not match IP address")]
493 IpAddressVersionMismatch = 1303,
494 #[strum(message = "IP version is malformed")]
495 IpAddressMalformedVersion = 1304,
496 #[strum(message = "IP address list is empty")]
497 IpAddressListIsEmpty = 1305,
498 #[strum(message = "\"This network.\" See RFC 791")]
499 IpAddressThisNetwork = 1306,
500 #[strum(message = "Private use. See RFC 1918")]
501 IpAddressPrivateUse = 1307,
502 #[strum(message = "Shared NAT network. See RFC 6598")]
503 IpAddressSharedNat = 1308,
504 #[strum(message = "Loopback network. See RFC 1122")]
505 IpAddressLoopback = 1309,
506 #[strum(message = "Link local network. See RFC 3927")]
507 IpAddressLinkLocal = 1310,
508 #[strum(message = "Unique local network. See RFC 8190")]
509 IpAddressUniqueLocal = 1311,
510 #[strum(message = "Documentation network. See RFC 5737")]
511 IpAddressDocumentationNet = 1312,
512 #[strum(message = "Reserved network. See RFC 1112")]
513 IpAddressReservedNet = 1313,
514 #[strum(message = "IP address array is a string.")]
515 IpAddressArrayIsString = 1314,
516 #[strum(message = "IP version is not a string")]
517 IpVersionIsNotString = 1315,
518
519 // Autnum 1400 - 1499
520 #[strum(message = "start or end autnum is missing")]
521 AutnumMissing = 1400,
522 #[strum(message = "end AS number comes before start AS number")]
523 AutnumEndBeforeStart = 1401,
524 #[strum(message = "Private use. See RFC 6996")]
525 AutnumPrivateUse = 1402,
526 #[strum(message = "Documentation AS number. See RFC 5398")]
527 AutnumDocumentation = 1403,
528 #[strum(message = "Reserved AS number. See RFC 6996")]
529 AutnumReserved = 1404,
530
531 // Vcard 1500 - 1599
532 #[strum(message = "vCard array does not contain a vCard")]
533 VcardArrayIsEmpty = 1500,
534 #[strum(message = "vCard has no fn property")]
535 VcardHasNoFn = 1501,
536 #[strum(message = "vCard fn property is empty")]
537 VcardFnIsEmpty = 1502,
538
539 // Port 43 1600 - 1699
540 #[strum(message = "port43 appears to be empty or only whitespace")]
541 Port43IsEmpty = 1600,
542
543 // Public ID 1700 - 1799
544 #[strum(message = "publicId type is absent")]
545 PublicIdTypeIsAbsent = 1700,
546 #[strum(message = "publicId identifier is absent")]
547 PublicIdIdentifierIsAbsent = 1701,
548 #[strum(message = "publicId type is not a string")]
549 PublicIdTypeIsNotString = 1702,
550 #[strum(message = "publicId identifier is not a string")]
551 PublicIdIdentifierIsNotString = 1703,
552
553 // HTTP 1800 - 1899
554 #[strum(message = "Use of access-control-allow-origin is recommended.")]
555 CorsAllowOriginRecommended = 1800,
556 #[strum(message = "Use of access-control-allow-origin with asterisk is recommended.")]
557 CorsAllowOriginStarRecommended = 1801,
558 #[strum(message = "Use of access-control-allow-credentials is not recommended.")]
559 CorsAllowCredentialsNotRecommended = 1802,
560 #[strum(message = "No content-type header received.")]
561 ContentTypeIsAbsent = 1803,
562 #[strum(message = "Content-type is not application/rdap+json.")]
563 ContentTypeIsNotRdap = 1804,
564
565 // Cidr0 1900 - 1999
566 #[strum(message = "Cidr0 v4 prefix is absent")]
567 Cidr0V4PrefixIsAbsent = 1900,
568 #[strum(message = "Cidr0 v4 length is absent")]
569 Cidr0V4LengthIsAbsent = 1901,
570 #[strum(message = "Cidr0 v6 prefix is absent")]
571 Cidr0V6PrefixIsAbsent = 1902,
572 #[strum(message = "Cidr0 v6 length is absent")]
573 Cidr0V6LengthIsAbsent = 1903,
574 #[strum(message = "Cidr0 array is empty.")]
575 Cidr0ArrayIsEmpty = 1904,
576
577 // Gtld Profile 2000 - 2099
578 #[strum(message = "RDAP Service Must use HTTPS.")]
579 MustUseHttps = 2000,
580 #[strum(message = "access-control-allow-origin is not asterisk")]
581 AllowOriginNotStar = 2001,
582
583 // Explicit Testing Errors 2100 - 2199
584 #[strum(message = "CNAME without A records.")]
585 CnameWithoutARecords = 2100,
586 #[strum(message = "CNAME without AAAA records.")]
587 CnameWithoutAAAARecords = 2101,
588 #[strum(message = "No A records.")]
589 NoARecords = 2102,
590 #[strum(message = "No AAAA records.")]
591 NoAAAARecords = 2103,
592 #[strum(message = "Expected extension not found.")]
593 ExpectedExtensionNotFound = 2104,
594 #[strum(message = "IPv6 Support Required.")]
595 Ipv6SupportRequiredByGtldProfile = 2105,
596
597 // Secure DNS 2200 - 2299
598 #[strum(message = "delegationSigned is a string not a bool.")]
599 DelegationSignedIsString = 2200,
600 #[strum(message = "zoneSigned is a string not a bool.")]
601 ZoneSignedIsString = 2201,
602 #[strum(message = "maxSigLife is a string not a number.")]
603 MaxSigLifeIsString = 2202,
604 // key data
605 #[strum(message = "keyData algorithm is a string not a number.")]
606 KeyDatumAlgorithmIsString = 2203,
607 #[strum(message = "keyData algorithm is out of range.")]
608 KeyDatumAlgorithmIsOutOfRange = 2204,
609 #[strum(message = "keyData flags is a string not a number.")]
610 KeyDatumFlagsIsString = 2205,
611 #[strum(message = "keyData flags is out of range.")]
612 KeyDatumFlagsIsOutOfRange = 2206,
613 #[strum(message = "keyData protocol is a string not a number.")]
614 KeyDatumProtocolIsString = 2207,
615 #[strum(message = "keyData protocol is out of range.")]
616 KeyDatumProtocolIsOutOfRange = 2208,
617 // ds data
618 #[strum(message = "dsData algorithm is a string not a number.")]
619 DsDatumAlgorithmIsString = 2213,
620 #[strum(message = "dsData algorithm is out of range.")]
621 DsDatumAlgorithmIsOutOfRange = 2214,
622 #[strum(message = "dsData keyTag is a string not a number.")]
623 DsDatumKeyTagIsString = 2215,
624 #[strum(message = "dsData keyTag is out of range.")]
625 DsDatumKeyTagIsOutOfRange = 2216,
626 #[strum(message = "dsData digestType is a string not a number.")]
627 DsDatumDigestTypeIsString = 2217,
628 #[strum(message = "dsData digestType is out of range.")]
629 DsDatumDigestTypeIsOutOfRange = 2218,
630 // empty arrays
631 #[strum(message = "keyData array is empty.")]
632 KeyDataArrayIsEmpty = 2219,
633 #[strum(message = "dsData array is empty.")]
634 DsDataArrayIsEmpty = 2220,
635
636 // Network or Autnum Country 2300 - 2399
637 #[strum(message = "country is not a string")]
638 NetworkOrAutnumCountryIsNotString = 2300,
639
640 // Entities 2400 - 2499
641 #[strum(message = "entity array is empty")]
642 EntityArrayIsEmpty = 2400,
643
644 // Error 2500 - 2599
645 #[strum(message = "errorCode is a string not a number")]
646 ErrorCodeIsString = 2500,
647 #[strum(message = "title is not a string")]
648 TitleIsNotString = 2501,
649 #[strum(message = "description is a string not an array")]
650 DescriptionIsString = 2502,
651
652 // RPKI 2600 - 2699
653 #[strum(message = "rpkiType is not a valid value")]
654 Rpk1RpkiTypeInvalid = 2600,
655 #[strum(message = "originAutnum is missing in ROA")]
656 Rpk1RoaOriginAutnumMissing = 2601,
657 #[strum(message = "roaIps is empty in ROA")]
658 Rpk1RoaIpsIsEmpty = 2602,
659 #[strum(message = "customerAutnum is missing in ASPA")]
660 Rpk1AspaCustomerAutnumMissing = 2603,
661 #[strum(message = "providerAutnums is empty in ASPA")]
662 Rpk1AspaProviderAutnumsIsEmpty = 2604,
663 #[strum(message = "serialNumber is missing in X.509 certificate")]
664 Rpk1X509SerialNumberMissing = 2605,
665 #[strum(message = "issuer is missing in X.509 certificate")]
666 Rpk1X509IssuerMissing = 2606,
667 }
668
669 impl Check {
670 pub fn check_item(self) -> CheckItem {
671 let check_class = match self {
672 Self::RdapConformanceMissing
673 | Self::RdapConformanceInvalidParent
674 | Self::RdapConformanceIsEmpty => CheckClass::Std95Error,
675 Self::UnknownExtension => CheckClass::Std95Warning,
676
677 Self::LinkMissingValueProperty | Self::LinkMissingRelProperty => CheckClass::Std95Error,
678 Self::LinkRelatedHasNoType | Self::LinkRelatedIsNotRdap => CheckClass::Std95Warning,
679 Self::LinkSelfHasNoType | Self::LinkSelfIsNotRdap => CheckClass::Std95Error,
680 Self::LinkObjectClassHasNoSelf => CheckClass::SpecificationNote,
681 Self::LinkMissingHrefProperty => CheckClass::Std95Error,
682 Self::LinkRelatedNotToRdap => CheckClass::Std95Warning,
683 Self::LinksArrayIsEmpty => CheckClass::Std95Warning,
684
685 Self::VariantEmptyDomain => CheckClass::Std95Warning,
686
687 Self::EventDateIsAbsent
688 | Self::EventDateIsNotRfc3339
689 | Self::EventActionIsAbsent
690 | Self::NoticeOrRemarkDescriptionIsAbsent
691 | Self::NoticeOrRemarkDescriptionIsString => CheckClass::Std95Error,
692 Self::EventActionIsUnknown => CheckClass::Std95Warning,
693 Self::EventsArrayIsEmpty => CheckClass::Std95Warning,
694 Self::NoticeOrRemarkUnknownType => CheckClass::Std95Warning,
695 Self::NoticesArrayIsEmpty | Self::RemarksArrayIsEmpty => CheckClass::Std95Warning,
696
697 Self::HandleIsEmpty => CheckClass::Std95Warning,
698 Self::HandleIsNotString => CheckClass::Std95Error,
699 Self::ParentHandleIsNotString => CheckClass::Std95Error,
700
701 Self::StatusIsEmpty | Self::RoleIsEmpty => CheckClass::Std95Error,
702 Self::StatusValueUnknown => CheckClass::Std95Warning,
703 Self::UnknownRole => CheckClass::Std95Warning,
704 Self::RoleIsString | Self::LdhNameInvalid => CheckClass::Std95Error,
705 Self::LdhNameDocumentation => CheckClass::Informational,
706 Self::LdhNameDoesNotMatchUnicode => CheckClass::Std95Warning,
707
708 Self::UnicodeNameInvalidDomain | Self::UnicodeNameInvalidUnicode => {
709 CheckClass::Std95Error
710 }
711
712 Self::NetworkOrAutnumNameIsEmpty => CheckClass::Std95Warning,
713 Self::NetworkOrAutnumNameIsNotString => CheckClass::Std95Error,
714 Self::NetworkOrAutnumTypeIsEmpty => CheckClass::Std95Warning,
715 Self::NetworkOrAutnumTypeIsNotString => CheckClass::Std95Error,
716 Self::IpAddressMissing => CheckClass::Std95Warning,
717 Self::IpAddressMalformed => CheckClass::Std95Error,
718 Self::IpAddressEndBeforeStart | Self::IpAddressVersionMismatch => {
719 CheckClass::Std95Warning
720 }
721 Self::IpAddressMalformedVersion | Self::IpAddressListIsEmpty => CheckClass::Std95Error,
722 Self::IpAddressThisNetwork
723 | Self::IpAddressPrivateUse
724 | Self::IpAddressSharedNat
725 | Self::IpAddressLoopback
726 | Self::IpAddressLinkLocal
727 | Self::IpAddressUniqueLocal
728 | Self::IpAddressDocumentationNet
729 | Self::IpAddressReservedNet => CheckClass::Informational,
730 Self::IpAddressArrayIsString => CheckClass::Std95Error,
731 Self::IpVersionIsNotString => CheckClass::Std95Error,
732
733 Self::AutnumMissing | Self::AutnumEndBeforeStart => CheckClass::Std95Warning,
734 Self::AutnumPrivateUse | Self::AutnumDocumentation | Self::AutnumReserved => {
735 CheckClass::Informational
736 }
737
738 Self::VcardArrayIsEmpty | Self::VcardHasNoFn => CheckClass::Std95Error,
739 Self::VcardFnIsEmpty => CheckClass::SpecificationNote,
740
741 Self::Port43IsEmpty | Self::PublicIdTypeIsAbsent | Self::PublicIdIdentifierIsAbsent => {
742 CheckClass::Std95Error
743 }
744 Self::PublicIdTypeIsNotString => CheckClass::Std95Error,
745 Self::PublicIdIdentifierIsNotString => CheckClass::Std95Error,
746
747 Self::CorsAllowOriginRecommended
748 | Self::CorsAllowOriginStarRecommended
749 | Self::CorsAllowCredentialsNotRecommended => CheckClass::Std95Warning,
750 Self::ContentTypeIsAbsent | Self::ContentTypeIsNotRdap => CheckClass::Std95Error,
751
752 Self::Cidr0V4PrefixIsAbsent
753 | Self::Cidr0V4LengthIsAbsent
754 | Self::Cidr0V6PrefixIsAbsent
755 | Self::Cidr0V6LengthIsAbsent => CheckClass::Cidr0Error,
756 Self::Cidr0ArrayIsEmpty => CheckClass::Cidr0Error,
757
758 Self::MustUseHttps | Self::AllowOriginNotStar => CheckClass::GtldProfileError,
759
760 Self::CnameWithoutARecords | Self::CnameWithoutAAAARecords => CheckClass::Std95Error,
761 Self::NoARecords | Self::NoAAAARecords => CheckClass::SpecificationNote,
762 Self::ExpectedExtensionNotFound => CheckClass::Std95Error,
763 Self::Ipv6SupportRequiredByGtldProfile => CheckClass::GtldProfileError,
764
765 Self::DelegationSignedIsString
766 | Self::ZoneSignedIsString
767 | Self::MaxSigLifeIsString
768 | Self::KeyDatumAlgorithmIsString
769 | Self::KeyDatumAlgorithmIsOutOfRange
770 | Self::KeyDatumFlagsIsString
771 | Self::KeyDatumFlagsIsOutOfRange
772 | Self::KeyDatumProtocolIsString
773 | Self::KeyDatumProtocolIsOutOfRange
774 | Self::DsDatumAlgorithmIsString
775 | Self::DsDatumAlgorithmIsOutOfRange
776 | Self::DsDatumKeyTagIsString
777 | Self::DsDatumKeyTagIsOutOfRange
778 | Self::DsDatumDigestTypeIsString
779 | Self::DsDatumDigestTypeIsOutOfRange => CheckClass::Std95Error,
780 Self::KeyDataArrayIsEmpty | Self::DsDataArrayIsEmpty => CheckClass::Std95Warning,
781
782 Self::NetworkOrAutnumCountryIsNotString => CheckClass::Std95Error,
783
784 Self::EntityArrayIsEmpty => CheckClass::Std95Warning,
785
786 Self::ErrorCodeIsString | Self::TitleIsNotString | Self::DescriptionIsString => {
787 CheckClass::Std95Error
788 }
789
790 Self::Rpk1RpkiTypeInvalid
791 | Self::Rpk1RoaOriginAutnumMissing
792 | Self::Rpk1RoaIpsIsEmpty
793 | Self::Rpk1AspaCustomerAutnumMissing
794 | Self::Rpk1AspaProviderAutnumsIsEmpty
795 | Self::Rpk1X509SerialNumberMissing
796 | Self::Rpk1X509IssuerMissing => CheckClass::Rpki1Error,
797 };
798 CheckItem {
799 check_class,
800 check: self,
801 }
802 }
803 }
804
805 #[cfg(test)]
806 mod tests {
807 use crate::check::RdapStructure;
808
809 use super::{Check, CheckClass, CheckItem, Checks, contains_check, traverse_checks};
810
811 #[test]
812 fn test_traverse_info_checks() {
813 // GIVEN
814 let checks = Checks {
815 rdap_struct: RdapStructure::Entity,
816 index: None,
817 items: vec![CheckItem {
818 check_class: CheckClass::Informational,
819 check: Check::VariantEmptyDomain,
820 }],
821 sub_checks: vec![],
822 };
823
824 // WHEN
825 let found = traverse_checks(
826 &checks,
827 &[CheckClass::Informational],
828 None,
829 &mut |struct_tree, check_item| println!("{struct_tree} -> {check_item}"),
830 );
831
832 // THEN
833 assert!(found);
834 }
835
836 #[test]
837 fn test_traverse_specwarn_checks_for_info() {
838 // GIVEN
839 let checks = Checks {
840 rdap_struct: RdapStructure::Entity,
841 index: None,
842 items: vec![CheckItem {
843 check_class: CheckClass::Std95Warning,
844 check: Check::VariantEmptyDomain,
845 }],
846 sub_checks: vec![],
847 };
848
849 // WHEN
850 let found = traverse_checks(
851 &checks,
852 &[CheckClass::Informational],
853 None,
854 &mut |struct_tree, check_item| println!("{struct_tree} -> {check_item}"),
855 );
856
857 // THEN
858 assert!(!found);
859 }
860
861 #[test]
862 fn test_traverse_info_subchecks() {
863 // GIVEN
864 let checks = Checks {
865 rdap_struct: RdapStructure::Entity,
866 index: None,
867 items: vec![],
868 sub_checks: vec![Checks {
869 rdap_struct: RdapStructure::Autnum,
870 index: None,
871 items: vec![CheckItem {
872 check_class: CheckClass::Informational,
873 check: Check::VariantEmptyDomain,
874 }],
875 sub_checks: vec![],
876 }],
877 };
878
879 // WHEN
880 let found = traverse_checks(
881 &checks,
882 &[CheckClass::Informational],
883 None,
884 &mut |struct_tree, check_item| println!("{struct_tree} -> {check_item}"),
885 );
886
887 // THEN
888 assert!(found);
889 }
890
891 #[test]
892 fn test_traverse_specwarn_subchecks_for_info() {
893 // GIVEN
894 let checks = Checks {
895 rdap_struct: RdapStructure::Entity,
896 index: None,
897 items: vec![],
898 sub_checks: vec![Checks {
899 rdap_struct: RdapStructure::Autnum,
900 index: None,
901 items: vec![CheckItem {
902 check_class: CheckClass::Std95Warning,
903 check: Check::VariantEmptyDomain,
904 }],
905 sub_checks: vec![],
906 }],
907 };
908
909 // WHEN
910 let found = traverse_checks(
911 &checks,
912 &[CheckClass::Informational],
913 None,
914 &mut |struct_tree, check_item| println!("{struct_tree} -> {check_item}"),
915 );
916
917 // THEN
918 assert!(!found);
919 }
920
921 #[test]
922 fn test_traverse_checks_and_subchecks() {
923 // GIVEN
924 let checks = Checks {
925 rdap_struct: RdapStructure::Entity,
926 index: None,
927 items: vec![CheckItem {
928 check_class: CheckClass::Informational,
929 check: Check::RdapConformanceInvalidParent,
930 }],
931 sub_checks: vec![Checks {
932 rdap_struct: RdapStructure::Autnum,
933 index: None,
934 items: vec![CheckItem {
935 check_class: CheckClass::Informational,
936 check: Check::VariantEmptyDomain,
937 }],
938 sub_checks: vec![],
939 }],
940 };
941
942 // WHEN
943 let mut structs: Vec<String> = vec![];
944 let found = traverse_checks(
945 &checks,
946 &[CheckClass::Informational],
947 None,
948 &mut |struct_tree, _check_item| structs.push(struct_tree.to_string()),
949 );
950
951 // THEN
952 assert!(found);
953 dbg!(&structs);
954 assert!(structs.contains(&"[ROOT]/entity".to_string()));
955 assert!(structs.contains(&"[ROOT]/entity/autnum".to_string()));
956 }
957
958 #[test]
959 fn test_contains_check_with_item() {
960 // GIVEN check structure
961 let checks = Checks::for_item(
962 RdapStructure::Autnum,
963 Check::RdapConformanceMissing.check_item(),
964 );
965
966 // WHEN
967 let found = contains_check(Check::RdapConformanceMissing, &checks);
968
969 // THEN
970 assert!(found);
971 }
972
973 #[test]
974 fn test_contains_check_with_subchecks() {
975 // GIVEN check structure
976 let sub_check = Checks::for_item(
977 RdapStructure::Entity,
978 Check::RdapConformanceInvalidParent.check_item(),
979 );
980 let checks = Checks {
981 rdap_struct: RdapStructure::Autnum,
982 index: None,
983 items: vec![],
984 sub_checks: vec![sub_check],
985 };
986
987 // WHEN
988 let found = contains_check(Check::RdapConformanceInvalidParent, &checks);
989
990 // THEN
991 assert!(found);
992 }
993
994 #[test]
995 fn test_not_contains_check_with_item() {
996 // GIVEN check structure
997 let checks = Checks {
998 rdap_struct: RdapStructure::Autnum,
999 index: None,
1000 items: vec![],
1001 sub_checks: vec![],
1002 };
1003
1004 // WHEN
1005 let found = contains_check(Check::RdapConformanceMissing, &checks);
1006
1007 // THEN
1008 assert!(!found);
1009 }
1010 }