| 1 |
//! Status Values |
| 2 |
|
| 3 |
use super::EnumDisplay; |
| 4 |
use strum::{EnumIter, EnumString}; |
| 5 |
|
| 6 |
/// RDAP status values registered with IANA. |
| 7 |
#[derive(PartialEq, Eq, Debug, EnumString, EnumDisplay, EnumIter)] |
| 8 |
pub enum StatusValue { |
| 9 |
#[strum(serialize = "validated")] |
| 10 |
Validated, |
| 11 |
#[strum(serialize = "renew prohibited")] |
| 12 |
RenewProhibited, |
| 13 |
#[strum(serialize = "update prohibited")] |
| 14 |
UpdatedProhibited, |
| 15 |
#[strum(serialize = "transfer prohibited")] |
| 16 |
TransferProhibited, |
| 17 |
#[strum(serialize = "delete prohibited")] |
| 18 |
DeleteProhibited, |
| 19 |
#[strum(serialize = "proxy")] |
| 20 |
Proxy, |
| 21 |
#[strum(serialize = "private")] |
| 22 |
Private, |
| 23 |
#[strum(serialize = "removed")] |
| 24 |
Removed, |
| 25 |
#[strum(serialize = "obscured")] |
| 26 |
Obscured, |
| 27 |
#[strum(serialize = "associated")] |
| 28 |
Associated, |
| 29 |
#[strum(serialize = "active")] |
| 30 |
Active, |
| 31 |
#[strum(serialize = "inactive")] |
| 32 |
Inactive, |
| 33 |
#[strum(serialize = "locked")] |
| 34 |
Locked, |
| 35 |
#[strum(serialize = "pending create")] |
| 36 |
PendingCreate, |
| 37 |
#[strum(serialize = "pending renew")] |
| 38 |
PendingRenew, |
| 39 |
#[strum(serialize = "pending transfer")] |
| 40 |
PendingTransfer, |
| 41 |
#[strum(serialize = "pending update")] |
| 42 |
PendingUpdate, |
| 43 |
#[strum(serialize = "pending delete")] |
| 44 |
PendingDelete, |
| 45 |
#[strum(serialize = "add period")] |
| 46 |
AddPeriod, |
| 47 |
#[strum(serialize = "auto renew period")] |
| 48 |
AutoRenewPeriod, |
| 49 |
#[strum(serialize = "client delete prohibited")] |
| 50 |
ClientDeleteProhibited, |
| 51 |
#[strum(serialize = "client hold")] |
| 52 |
ClientHold, |
| 53 |
#[strum(serialize = "client renew prohibited")] |
| 54 |
ClientRenewProhibited, |
| 55 |
#[strum(serialize = "client transfer prohibited")] |
| 56 |
ClientTransferProhibited, |
| 57 |
#[strum(serialize = "client update prohibited")] |
| 58 |
ClientUpdateProhibited, |
| 59 |
#[strum(serialize = "pending restore")] |
| 60 |
PendingRestore, |
| 61 |
#[strum(serialize = "redemption period")] |
| 62 |
RedemptionPeriod, |
| 63 |
#[strum(serialize = "renew period")] |
| 64 |
RenewPeriod, |
| 65 |
#[strum(serialize = "server delete prohibited")] |
| 66 |
ServerDeleteProhibited, |
| 67 |
#[strum(serialize = "server renew prohibited")] |
| 68 |
ServerRenewProhibited, |
| 69 |
#[strum(serialize = "server transfer prohibited")] |
| 70 |
ServerTransferProhibited, |
| 71 |
#[strum(serialize = "server update prohibited")] |
| 72 |
ServerUpdateProhibited, |
| 73 |
#[strum(serialize = "server hold")] |
| 74 |
ServerHold, |
| 75 |
#[strum(serialize = "transfer period")] |
| 76 |
TransferPeriod, |
| 77 |
#[strum(serialize = "administrative")] |
| 78 |
Administrative, |
| 79 |
#[strum(serialize = "reserved")] |
| 80 |
Reserved, |
| 81 |
} |
| 82 |
|
| 83 |
#[cfg(all(test, feature = "iana_registry_tests"))] |
| 84 |
mod tests { |
| 85 |
use super::*; |
| 86 |
use strum::IntoEnumIterator; |
| 87 |
|
| 88 |
const IANA_REGISTRY_URL: &str = |
| 89 |
"https://www.iana.org/assignments/rdap-json-values/rdap-json-values.xml"; |
| 90 |
|
| 91 |
#[test] |
| 92 |
fn iana_status_values_match_enum() { |
| 93 |
let client = reqwest::blocking::Client::builder() |
| 94 |
.user_agent("icann-rdap-iana-test") |
| 95 |
.build() |
| 96 |
.expect("failed to build reqwest client"); |
| 97 |
let resp = client |
| 98 |
.get(IANA_REGISTRY_URL) |
| 99 |
.header("Accept", "application/xml") |
| 100 |
.send() |
| 101 |
.expect("failed to fetch IANA RDAP JSON values registry"); |
| 102 |
let body = resp.text().expect("failed to read IANA registry body"); |
| 103 |
|
| 104 |
let mut iana_values: std::collections::HashSet<String> = std::collections::HashSet::new(); |
| 105 |
let records: Vec<&str> = body.split("<record").skip(1).collect(); |
| 106 |
for record in records { |
| 107 |
let type_start = match record.find("<type>") { |
| 108 |
Some(pos) => pos + 6, |
| 109 |
None => continue, |
| 110 |
}; |
| 111 |
let type_end = match record[type_start..].find("</type>") { |
| 112 |
Some(len) => len, |
| 113 |
None => continue, |
| 114 |
}; |
| 115 |
let type_val = record[type_start..type_start + type_end].trim().to_string(); |
| 116 |
if type_val != "status" { |
| 117 |
continue; |
| 118 |
} |
| 119 |
let value_start = match record.find("<value>") { |
| 120 |
Some(pos) => pos + 7, |
| 121 |
None => continue, |
| 122 |
}; |
| 123 |
let value_end = match record[value_start..].find("</value>") { |
| 124 |
Some(len) => len, |
| 125 |
None => continue, |
| 126 |
}; |
| 127 |
let value = record[value_start..value_start + value_end] |
| 128 |
.trim() |
| 129 |
.to_string(); |
| 130 |
iana_values.insert(value); |
| 131 |
} |
| 132 |
|
| 133 |
let mut enum_values: std::collections::HashSet<String> = std::collections::HashSet::new(); |
| 134 |
for variant in StatusValue::iter() { |
| 135 |
enum_values.insert(variant.to_string()); |
| 136 |
} |
| 137 |
|
| 138 |
let mut missing = Vec::new(); |
| 139 |
for value in &iana_values { |
| 140 |
if !enum_values.contains(value) { |
| 141 |
missing.push(value.clone()); |
| 142 |
} |
| 143 |
} |
| 144 |
|
| 145 |
let mut extra = Vec::new(); |
| 146 |
for value in &enum_values { |
| 147 |
if !iana_values.contains(value) { |
| 148 |
extra.push(value.clone()); |
| 149 |
} |
| 150 |
} |
| 151 |
|
| 152 |
missing.sort(); |
| 153 |
extra.sort(); |
| 154 |
|
| 155 |
if !missing.is_empty() || !extra.is_empty() { |
| 156 |
let mut msg = String::from("StatusValue enum does not match IANA registry:\n"); |
| 157 |
if !missing.is_empty() { |
| 158 |
msg.push_str("Missing from enum:\n"); |
| 159 |
for v in &missing { |
| 160 |
msg.push_str(&format!(" - {v}\n")); |
| 161 |
} |
| 162 |
} |
| 163 |
if !extra.is_empty() { |
| 164 |
msg.push_str("Not in IANA registry:\n"); |
| 165 |
for v in &extra { |
| 166 |
msg.push_str(&format!(" - {v}\n")); |
| 167 |
} |
| 168 |
} |
| 169 |
panic!("{msg}"); |
| 170 |
} |
| 171 |
} |
| 172 |
} |