| 1 |
//! RDAP Domain Object Class |
| 2 |
use std::collections::HashSet; |
| 3 |
|
| 4 |
use crate::prelude::{ContentExtensions, ttl::Ttl0Data}; |
| 5 |
|
| 6 |
use { |
| 7 |
crate::prelude::{Common, Extension, ObjectCommon}, |
| 8 |
buildstructor::Builder, |
| 9 |
serde::{Deserialize, Serialize}, |
| 10 |
}; |
| 11 |
|
| 12 |
use super::{ |
| 13 |
CommonFields, Entity, Event, GetSelfLink, Notice, ObjectCommonFields, Port43, PublicId, Remark, |
| 14 |
SelfLink, ToChild, ToResponse, VectorStringish, |
| 15 |
lenient::{Boolish, Numberish}, |
| 16 |
nameserver::Nameserver, |
| 17 |
network::Network, |
| 18 |
to_opt_vec, to_opt_vectorstringish, |
| 19 |
types::{Events, Link, Links, PublicIds}, |
| 20 |
}; |
| 21 |
|
| 22 |
/// Represents an RDAP variant name. |
| 23 |
#[derive(Serialize, Deserialize, Builder, Clone, Debug, PartialEq, Eq)] |
| 24 |
pub struct VariantName { |
| 25 |
#[serde(rename = "ldhName")] |
| 26 |
#[serde(skip_serializing_if = "Option::is_none")] |
| 27 |
pub ldh_name: Option<String>, |
| 28 |
|
| 29 |
#[serde(rename = "unicodeName")] |
| 30 |
#[serde(skip_serializing_if = "Option::is_none")] |
| 31 |
pub unicode_name: Option<String>, |
| 32 |
} |
| 33 |
|
| 34 |
impl VariantName { |
| 35 |
/// Getter for ldhName. |
| 36 |
pub fn ldh_name(&self) -> Option<&str> { |
| 37 |
self.ldh_name.as_deref() |
| 38 |
} |
| 39 |
|
| 40 |
/// Getter for unicodeName. |
| 41 |
pub fn unicode_name(&self) -> Option<&str> { |
| 42 |
self.unicode_name.as_deref() |
| 43 |
} |
| 44 |
} |
| 45 |
|
| 46 |
/// Represents an RDAP IDN variant. |
| 47 |
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)] |
| 48 |
pub struct Variant { |
| 49 |
#[serde(rename = "relation")] |
| 50 |
#[serde(skip_serializing_if = "Option::is_none")] |
| 51 |
pub relations: Option<VectorStringish>, |
| 52 |
|
| 53 |
#[serde(rename = "idnTable")] |
| 54 |
#[serde(skip_serializing_if = "Option::is_none")] |
| 55 |
pub idn_table: Option<String>, |
| 56 |
|
| 57 |
#[serde(rename = "variantNames")] |
| 58 |
#[serde(skip_serializing_if = "Option::is_none")] |
| 59 |
pub variant_names: Option<Vec<VariantName>>, |
| 60 |
} |
| 61 |
|
| 62 |
#[buildstructor::buildstructor] |
| 63 |
impl Variant { |
| 64 |
#[builder(visibility = "pub")] |
| 65 |
fn new( |
| 66 |
relations: Vec<String>, |
| 67 |
idn_table: Option<String>, |
| 68 |
variant_names: Vec<VariantName>, |
| 69 |
) -> Self { |
| 70 |
Self { |
| 71 |
relations: to_opt_vectorstringish(relations), |
| 72 |
idn_table, |
| 73 |
variant_names: to_opt_vec(variant_names), |
| 74 |
} |
| 75 |
} |
| 76 |
|
| 77 |
/// Getter for relations. |
| 78 |
pub fn relations(&self) -> &[String] { |
| 79 |
self.relations |
| 80 |
.as_ref() |
| 81 |
.map(|v| v.vec().as_ref()) |
| 82 |
.unwrap_or_default() |
| 83 |
} |
| 84 |
|
| 85 |
/// Getter for variantNames. |
| 86 |
pub fn variant_names(&self) -> &[VariantName] { |
| 87 |
self.variant_names.as_deref().unwrap_or_default() |
| 88 |
} |
| 89 |
|
| 90 |
/// Getter for idnTable. |
| 91 |
pub fn idn_table(&self) -> Option<&str> { |
| 92 |
self.idn_table.as_deref() |
| 93 |
} |
| 94 |
} |
| 95 |
|
| 96 |
/// Represents `dsData`. |
| 97 |
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)] |
| 98 |
pub struct DsDatum { |
| 99 |
#[serde(rename = "keyTag")] |
| 100 |
#[serde(skip_serializing_if = "Option::is_none")] |
| 101 |
pub key_tag: Option<Numberish<u32>>, |
| 102 |
|
| 103 |
#[serde(skip_serializing_if = "Option::is_none")] |
| 104 |
pub algorithm: Option<Numberish<u8>>, |
| 105 |
|
| 106 |
#[serde(skip_serializing_if = "Option::is_none")] |
| 107 |
pub digest: Option<String>, |
| 108 |
|
| 109 |
#[serde(rename = "digestType")] |
| 110 |
#[serde(skip_serializing_if = "Option::is_none")] |
| 111 |
pub digest_type: Option<Numberish<u8>>, |
| 112 |
|
| 113 |
#[serde(skip_serializing_if = "Option::is_none")] |
| 114 |
pub links: Option<Links>, |
| 115 |
|
| 116 |
#[serde(skip_serializing_if = "Option::is_none")] |
| 117 |
pub events: Option<Events>, |
| 118 |
} |
| 119 |
|
| 120 |
#[buildstructor::buildstructor] |
| 121 |
impl DsDatum { |
| 122 |
/// Builder for `dsData` |
| 123 |
#[builder(visibility = "pub")] |
| 124 |
fn new( |
| 125 |
key_tag: Option<u32>, |
| 126 |
algorithm: Option<u8>, |
| 127 |
digest: Option<String>, |
| 128 |
digest_type: Option<u8>, |
| 129 |
links: Vec<Link>, |
| 130 |
events: Vec<Event>, |
| 131 |
) -> Self { |
| 132 |
Self { |
| 133 |
key_tag: key_tag.map(Numberish::<u32>::from), |
| 134 |
algorithm: algorithm.map(Numberish::<u8>::from), |
| 135 |
digest, |
| 136 |
digest_type: digest_type.map(Numberish::<u8>::from), |
| 137 |
links: to_opt_vec(links), |
| 138 |
events: to_opt_vec(events), |
| 139 |
} |
| 140 |
} |
| 141 |
|
| 142 |
/// Getter for links. |
| 143 |
pub fn links(&self) -> &[Link] { |
| 144 |
self.links.as_deref().unwrap_or_default() |
| 145 |
} |
| 146 |
|
| 147 |
/// Getter for events. |
| 148 |
pub fn events(&self) -> &[Event] { |
| 149 |
self.events.as_deref().unwrap_or_default() |
| 150 |
} |
| 151 |
|
| 152 |
/// Returns a u32 if it was given; otherwise, None. |
| 153 |
pub fn key_tag(&self) -> Option<u32> { |
| 154 |
self.key_tag.as_ref().and_then(|n| n.as_u32()) |
| 155 |
} |
| 156 |
|
| 157 |
/// Returns a u8 if it was given; otherwise, None. |
| 158 |
pub fn algorithm(&self) -> Option<u8> { |
| 159 |
self.algorithm.as_ref().and_then(|n| n.as_u8()) |
| 160 |
} |
| 161 |
|
| 162 |
/// Returns a u8 if it was given; otherwise, None. |
| 163 |
pub fn digest_type(&self) -> Option<u8> { |
| 164 |
self.digest_type.as_ref().and_then(|n| n.as_u8()) |
| 165 |
} |
| 166 |
|
| 167 |
/// Convenience method. |
| 168 |
pub fn digest(&self) -> Option<&str> { |
| 169 |
self.digest.as_deref() |
| 170 |
} |
| 171 |
} |
| 172 |
|
| 173 |
/// Represents `keyData`. |
| 174 |
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)] |
| 175 |
pub struct KeyDatum { |
| 176 |
#[serde(skip_serializing_if = "Option::is_none")] |
| 177 |
pub flags: Option<Numberish<u16>>, |
| 178 |
|
| 179 |
#[serde(skip_serializing_if = "Option::is_none")] |
| 180 |
pub protocol: Option<Numberish<u8>>, |
| 181 |
|
| 182 |
#[serde(rename = "publicKey")] |
| 183 |
#[serde(skip_serializing_if = "Option::is_none")] |
| 184 |
pub public_key: Option<String>, |
| 185 |
|
| 186 |
#[serde(skip_serializing_if = "Option::is_none")] |
| 187 |
pub algorithm: Option<Numberish<u8>>, |
| 188 |
|
| 189 |
#[serde(skip_serializing_if = "Option::is_none")] |
| 190 |
pub links: Option<Links>, |
| 191 |
|
| 192 |
#[serde(skip_serializing_if = "Option::is_none")] |
| 193 |
pub events: Option<Events>, |
| 194 |
} |
| 195 |
|
| 196 |
#[buildstructor::buildstructor] |
| 197 |
impl KeyDatum { |
| 198 |
/// Builder for `keyData` |
| 199 |
#[builder(visibility = "pub")] |
| 200 |
fn new( |
| 201 |
flags: Option<u16>, |
| 202 |
protocol: Option<u8>, |
| 203 |
public_key: Option<String>, |
| 204 |
algorithm: Option<u8>, |
| 205 |
links: Vec<Link>, |
| 206 |
events: Vec<Event>, |
| 207 |
) -> Self { |
| 208 |
Self { |
| 209 |
flags: flags.map(Numberish::<u16>::from), |
| 210 |
protocol: protocol.map(Numberish::<u8>::from), |
| 211 |
public_key, |
| 212 |
algorithm: algorithm.map(Numberish::<u8>::from), |
| 213 |
links: to_opt_vec(links), |
| 214 |
events: to_opt_vec(events), |
| 215 |
} |
| 216 |
} |
| 217 |
|
| 218 |
/// Getter for links. |
| 219 |
pub fn links(&self) -> &[Link] { |
| 220 |
self.links.as_deref().unwrap_or_default() |
| 221 |
} |
| 222 |
|
| 223 |
/// Getter for events. |
| 224 |
pub fn events(&self) -> &[Event] { |
| 225 |
self.events.as_deref().unwrap_or_default() |
| 226 |
} |
| 227 |
|
| 228 |
/// Returns a u16 if it was given; otherwise, None. |
| 229 |
pub fn flags(&self) -> Option<u16> { |
| 230 |
self.flags.as_ref().and_then(|n| n.as_u16()) |
| 231 |
} |
| 232 |
|
| 233 |
/// Returns a u8 if it was given; otherwise, None. |
| 234 |
pub fn protocol(&self) -> Option<u8> { |
| 235 |
self.protocol.as_ref().and_then(|n| n.as_u8()) |
| 236 |
} |
| 237 |
|
| 238 |
/// Returns a u8 if it was given; otherwise, None. |
| 239 |
pub fn algorithm(&self) -> Option<u8> { |
| 240 |
self.algorithm.as_ref().and_then(|n| n.as_u8()) |
| 241 |
} |
| 242 |
|
| 243 |
/// Getter for publicKey. |
| 244 |
pub fn public_key(&self) -> Option<&str> { |
| 245 |
self.public_key.as_deref() |
| 246 |
} |
| 247 |
} |
| 248 |
|
| 249 |
/// Represents the DNSSEC information of a domain. |
| 250 |
/// |
| 251 |
/// The following shows how to use the builders to |
| 252 |
/// create a domain with secure DNS information. |
| 253 |
/// |
| 254 |
/// ```rust |
| 255 |
/// use icann_rdap_common::prelude::*; |
| 256 |
/// |
| 257 |
/// // Builds DNS security `keyData`. |
| 258 |
/// let key_datum = KeyDatum::builder() |
| 259 |
/// .flags(257) |
| 260 |
/// .protocol(3) |
| 261 |
/// .algorithm(8) |
| 262 |
/// .public_key("AwEAAa6eDzronzjEDbT...Jg1M5N rBSPkuXpdFE=") |
| 263 |
/// .build(); |
| 264 |
/// |
| 265 |
/// // Builds DNS security `dsData`. |
| 266 |
/// let ds_datum = DsDatum::builder() |
| 267 |
/// .algorithm(13) |
| 268 |
/// .key_tag(20149) |
| 269 |
/// .digest_type(2) |
| 270 |
/// .digest("cf066bceadb799a27b62e3e82dc2e4da314c1807db98f13d82f0043b1418cf4e") |
| 271 |
/// .build(); |
| 272 |
/// |
| 273 |
/// // Builds DNS security. |
| 274 |
/// let secure_dns = SecureDns::builder() |
| 275 |
/// .ds_data(ds_datum) |
| 276 |
/// .key_data(key_datum) |
| 277 |
/// .zone_signed(true) |
| 278 |
/// .delegation_signed(false) |
| 279 |
/// .max_sig_life(604800) |
| 280 |
/// .build(); |
| 281 |
/// |
| 282 |
/// // Builds `domain` with DNS security. |
| 283 |
/// let domain = Domain::builder() |
| 284 |
/// .ldh_name("example.com") |
| 285 |
/// .handle("EXAMPLE-DOMAIN") |
| 286 |
/// .status("active") |
| 287 |
/// .secure_dns(secure_dns) |
| 288 |
/// .build(); |
| 289 |
/// ``` |
| 290 |
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)] |
| 291 |
pub struct SecureDns { |
| 292 |
#[serde(rename = "zoneSigned")] |
| 293 |
#[serde(skip_serializing_if = "Option::is_none")] |
| 294 |
pub zone_signed: Option<Boolish>, |
| 295 |
|
| 296 |
#[serde(rename = "delegationSigned")] |
| 297 |
#[serde(skip_serializing_if = "Option::is_none")] |
| 298 |
pub delegation_signed: Option<Boolish>, |
| 299 |
|
| 300 |
#[serde(rename = "maxSigLife")] |
| 301 |
#[serde(skip_serializing_if = "Option::is_none")] |
| 302 |
pub max_sig_life: Option<Numberish<u64>>, |
| 303 |
|
| 304 |
#[serde(rename = "dsData")] |
| 305 |
#[serde(skip_serializing_if = "Option::is_none")] |
| 306 |
pub ds_data: Option<Vec<DsDatum>>, |
| 307 |
|
| 308 |
#[serde(rename = "keyData")] |
| 309 |
#[serde(skip_serializing_if = "Option::is_none")] |
| 310 |
pub key_data: Option<Vec<KeyDatum>>, |
| 311 |
} |
| 312 |
|
| 313 |
#[buildstructor::buildstructor] |
| 314 |
impl SecureDns { |
| 315 |
/// Builder for `secureDNS`. |
| 316 |
#[builder(visibility = "pub")] |
| 317 |
fn new( |
| 318 |
zone_signed: Option<bool>, |
| 319 |
delegation_signed: Option<bool>, |
| 320 |
max_sig_life: Option<u64>, |
| 321 |
ds_datas: Vec<DsDatum>, |
| 322 |
key_datas: Vec<KeyDatum>, |
| 323 |
) -> Self { |
| 324 |
Self { |
| 325 |
zone_signed: zone_signed.map(Boolish::from), |
| 326 |
delegation_signed: delegation_signed.map(Boolish::from), |
| 327 |
max_sig_life: max_sig_life.map(Numberish::<u64>::from), |
| 328 |
ds_data: to_opt_vec(ds_datas), |
| 329 |
key_data: to_opt_vec(key_datas), |
| 330 |
} |
| 331 |
} |
| 332 |
|
| 333 |
/// Getter for dsData. |
| 334 |
pub fn ds_data(&self) -> &[DsDatum] { |
| 335 |
self.ds_data.as_deref().unwrap_or_default() |
| 336 |
} |
| 337 |
|
| 338 |
/// Getter for keyData. |
| 339 |
pub fn key_data(&self) -> &[KeyDatum] { |
| 340 |
self.key_data.as_deref().unwrap_or_default() |
| 341 |
} |
| 342 |
|
| 343 |
/// Returns true if a truish value was given; otherwise, false. |
| 344 |
pub fn zone_signed(&self) -> Option<bool> { |
| 345 |
self.zone_signed.as_ref().map(|b| b.into_bool()) |
| 346 |
} |
| 347 |
|
| 348 |
/// Returns true if a truish value was given; otherwise, false. |
| 349 |
pub fn delegation_signed(&self) -> Option<bool> { |
| 350 |
self.delegation_signed.as_ref().map(|b| b.into_bool()) |
| 351 |
} |
| 352 |
|
| 353 |
/// Returns max_sig_life as a u64 if it was given; otherwise, None. |
| 354 |
pub fn max_sig_life(&self) -> Option<u64> { |
| 355 |
self.max_sig_life.as_ref().and_then(|n| n.as_u64()) |
| 356 |
} |
| 357 |
} |
| 358 |
|
| 359 |
/// Represents an RDAP [domain](https://rdap.rcode3.com/protocol/object_classes.html#domain) response. |
| 360 |
/// |
| 361 |
/// Using the builder is recommended to construct this structure as it |
| 362 |
/// will fill-in many of the mandatory fields. |
| 363 |
/// The following is an example. |
| 364 |
/// |
| 365 |
/// ```rust |
| 366 |
/// use icann_rdap_common::prelude::*; |
| 367 |
/// |
| 368 |
/// let domain = Domain::response_obj() |
| 369 |
/// .ldh_name("foo.example.com") |
| 370 |
/// .handle("foo_example_com-1") |
| 371 |
/// .status("active") |
| 372 |
/// .build(); |
| 373 |
/// let c = serde_json::to_string_pretty(&domain).unwrap(); |
| 374 |
/// eprintln!("{c}"); |
| 375 |
/// ``` |
| 376 |
/// |
| 377 |
/// This will produce the following. |
| 378 |
/// |
| 379 |
/// ```norust |
| 380 |
/// { |
| 381 |
/// "rdapConformance": [ |
| 382 |
/// "rdap_level_0" |
| 383 |
/// ], |
| 384 |
/// "objectClassName": "domain", |
| 385 |
/// "handle": "foo_example_com-1", |
| 386 |
/// "status": [ |
| 387 |
/// "active" |
| 388 |
/// ], |
| 389 |
/// "ldhName": "foo.example.com" |
| 390 |
/// } |
| 391 |
/// ``` |
| 392 |
/// |
| 393 |
/// Domains have many sub-structures that are also constructed |
| 394 |
/// using builders, which may then be passed into a Domain |
| 395 |
/// builder. |
| 396 |
/// |
| 397 |
/// ```rust |
| 398 |
/// use icann_rdap_common::prelude::*; |
| 399 |
/// |
| 400 |
/// let nameservers = vec![ |
| 401 |
/// Nameserver::builder() |
| 402 |
/// .ldh_name("ns1.example.com") |
| 403 |
/// .address("127.0.0.1") |
| 404 |
/// .build() |
| 405 |
/// .unwrap(), |
| 406 |
/// Nameserver::builder() |
| 407 |
/// .ldh_name("ns2.example.com") |
| 408 |
/// .build() |
| 409 |
/// .unwrap(), |
| 410 |
/// ]; |
| 411 |
/// |
| 412 |
/// let ds_datum = DsDatum::builder() |
| 413 |
/// .algorithm(13) |
| 414 |
/// .key_tag(20149) |
| 415 |
/// .digest_type(2) |
| 416 |
/// .digest("cf066bceadb799a27b62e3e82dc2e4da314c1807db98f13d82f0043b1418cf4e") |
| 417 |
/// .build(); |
| 418 |
/// |
| 419 |
/// let secure_dns = SecureDns::builder() |
| 420 |
/// .ds_data(ds_datum) |
| 421 |
/// .zone_signed(true) |
| 422 |
/// .delegation_signed(false) |
| 423 |
/// .build(); |
| 424 |
/// |
| 425 |
/// let domain = Domain::builder() |
| 426 |
/// .ldh_name("foo.example.com") |
| 427 |
/// .handle("foo_example_com-3") |
| 428 |
/// .status("active") |
| 429 |
/// .nameservers(nameservers) |
| 430 |
/// .secure_dns(secure_dns) |
| 431 |
/// .build(); |
| 432 |
/// ``` |
| 433 |
/// |
| 434 |
/// In the example above, the nameservers are added to builder as a `Vec`. However, |
| 435 |
/// the builder can also take them individually. |
| 436 |
/// |
| 437 |
/// ```rust |
| 438 |
/// use icann_rdap_common::prelude::*; |
| 439 |
/// |
| 440 |
/// let ns1 = Nameserver::builder() |
| 441 |
/// .ldh_name("ns1.example.com") |
| 442 |
/// .address("127.0.0.1") |
| 443 |
/// .build() |
| 444 |
/// .unwrap(); |
| 445 |
/// let ns2 = Nameserver::builder() |
| 446 |
/// .ldh_name("ns2.example.com") |
| 447 |
/// .build() |
| 448 |
/// .unwrap(); |
| 449 |
/// |
| 450 |
/// let domain = Domain::builder() |
| 451 |
/// .ldh_name("foo.example.com") |
| 452 |
/// .nameserver(ns1) |
| 453 |
/// .nameserver(ns2) |
| 454 |
/// .build(); |
| 455 |
/// ``` |
| 456 |
/// |
| 457 |
/// Access to the domain information should be done via the getter functions. |
| 458 |
/// See [CommonFields] and [ObjectCommonFields] for common getter functions. |
| 459 |
/// ```rust |
| 460 |
/// # use icann_rdap_common::prelude::*; |
| 461 |
/// # let domain = Domain::builder() |
| 462 |
/// # .ldh_name("foo.example.com") |
| 463 |
/// # .build(); |
| 464 |
/// let handle = domain.handle(); |
| 465 |
/// let ldh_name = domain.ldh_name(); |
| 466 |
/// let unicode_name = domain.unicode_name(); |
| 467 |
/// let nameservers = domain.nameservers(); |
| 468 |
/// let public_ids = domain.public_ids(); |
| 469 |
/// let variants = domain.variants(); |
| 470 |
/// ``` |
| 471 |
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)] |
| 472 |
pub struct Domain { |
| 473 |
#[serde(flatten)] |
| 474 |
pub common: Common, |
| 475 |
|
| 476 |
#[serde(flatten)] |
| 477 |
pub object_common: ObjectCommon, |
| 478 |
|
| 479 |
#[serde(rename = "ldhName")] |
| 480 |
#[serde(skip_serializing_if = "Option::is_none")] |
| 481 |
pub ldh_name: Option<String>, |
| 482 |
|
| 483 |
#[serde(rename = "unicodeName")] |
| 484 |
#[serde(skip_serializing_if = "Option::is_none")] |
| 485 |
pub unicode_name: Option<String>, |
| 486 |
|
| 487 |
#[serde(skip_serializing_if = "Option::is_none")] |
| 488 |
pub variants: Option<Vec<Variant>>, |
| 489 |
|
| 490 |
#[serde(rename = "secureDNS")] |
| 491 |
#[serde(skip_serializing_if = "Option::is_none")] |
| 492 |
pub secure_dns: Option<SecureDns>, |
| 493 |
|
| 494 |
#[serde(skip_serializing_if = "Option::is_none")] |
| 495 |
pub nameservers: Option<Vec<Nameserver>>, |
| 496 |
|
| 497 |
#[serde(rename = "publicIds")] |
| 498 |
#[serde(skip_serializing_if = "Option::is_none")] |
| 499 |
pub public_ids: Option<PublicIds>, |
| 500 |
|
| 501 |
#[serde(skip_serializing_if = "Option::is_none")] |
| 502 |
pub network: Option<Network>, |
| 503 |
|
| 504 |
#[serde(skip_serializing_if = "Option::is_none")] |
| 505 |
pub ttl0_data: Option<Ttl0Data>, |
| 506 |
} |
| 507 |
|
| 508 |
#[buildstructor::buildstructor] |
| 509 |
impl Domain { |
| 510 |
/// Builds a basic domain object for use with embedding into response objects. |
| 511 |
/// |
| 512 |
/// ```rust |
| 513 |
/// use icann_rdap_common::prelude::*; |
| 514 |
/// |
| 515 |
/// let domain = Domain::builder() |
| 516 |
/// .ldh_name("foo.example.com") //required for this builder. |
| 517 |
/// .handle("foo_example_com-1") |
| 518 |
/// .status("active") |
| 519 |
/// .remark(Remark::builder().title("example domain").build()) |
| 520 |
/// // ... |
| 521 |
/// .build(); |
| 522 |
/// ``` |
| 523 |
#[builder(visibility = "pub")] |
| 524 |
fn new<T: Into<String>>( |
| 525 |
ldh_name: T, |
| 526 |
unicode_name: Option<String>, |
| 527 |
nameservers: Vec<Nameserver>, |
| 528 |
handle: Option<String>, |
| 529 |
remarks: Vec<Remark>, |
| 530 |
links: Vec<Link>, |
| 531 |
events: Vec<Event>, |
| 532 |
statuses: Vec<String>, |
| 533 |
port_43: Option<Port43>, |
| 534 |
entities: Vec<Entity>, |
| 535 |
public_ids: Vec<PublicId>, |
| 536 |
secure_dns: Option<SecureDns>, |
| 537 |
variants: Vec<Variant>, |
| 538 |
network: Option<Network>, |
| 539 |
ttl0_data: Option<Ttl0Data>, |
| 540 |
redacted: Option<Vec<crate::response::redacted::Redacted>>, |
| 541 |
) -> Self { |
| 542 |
Self { |
| 543 |
common: Common::builder().build(), |
| 544 |
object_common: ObjectCommon::domain() |
| 545 |
.and_handle(handle) |
| 546 |
.and_remarks(to_opt_vec(remarks)) |
| 547 |
.and_links(to_opt_vec(links)) |
| 548 |
.and_events(to_opt_vec(events)) |
| 549 |
.status(statuses) |
| 550 |
.and_port_43(port_43) |
| 551 |
.and_entities(to_opt_vec(entities)) |
| 552 |
.and_redacted(redacted) |
| 553 |
.build(), |
| 554 |
ldh_name: Some(ldh_name.into()), |
| 555 |
unicode_name, |
| 556 |
variants: to_opt_vec(variants), |
| 557 |
secure_dns, |
| 558 |
nameservers: to_opt_vec(nameservers), |
| 559 |
public_ids: to_opt_vec(public_ids), |
| 560 |
network, |
| 561 |
ttl0_data, |
| 562 |
} |
| 563 |
} |
| 564 |
|
| 565 |
/// Builds a domain object for a response. |
| 566 |
/// |
| 567 |
/// ```rust |
| 568 |
/// use icann_rdap_common::prelude::*; |
| 569 |
/// |
| 570 |
/// let domain = Domain::response_obj() |
| 571 |
/// .ldh_name("foo.example.com") //required for this builder. |
| 572 |
/// .handle("foo_example_com-1") |
| 573 |
/// .status("active") |
| 574 |
/// .extension(ExtensionId::IcannRdapResponseProfile1.as_ref()) |
| 575 |
/// .extension(ExtensionId::IcannRdapTechnicalImplementationGuide1.as_ref()) |
| 576 |
/// .notice(Notice::builder().title("test").build()) |
| 577 |
/// // ... |
| 578 |
/// .build(); |
| 579 |
/// ``` |
| 580 |
#[builder(entry = "response_obj", visibility = "pub")] |
| 581 |
fn new_response_obj<T: Into<String>>( |
| 582 |
ldh_name: T, |
| 583 |
unicode_name: Option<String>, |
| 584 |
nameservers: Vec<Nameserver>, |
| 585 |
handle: Option<String>, |
| 586 |
remarks: Vec<Remark>, |
| 587 |
links: Vec<Link>, |
| 588 |
events: Vec<Event>, |
| 589 |
statuses: Vec<String>, |
| 590 |
port_43: Option<Port43>, |
| 591 |
entities: Vec<Entity>, |
| 592 |
notices: Vec<Notice>, |
| 593 |
public_ids: Vec<PublicId>, |
| 594 |
secure_dns: Option<SecureDns>, |
| 595 |
variants: Vec<Variant>, |
| 596 |
network: Option<Network>, |
| 597 |
ttl0_data: Option<Ttl0Data>, |
| 598 |
extensions: Vec<Extension>, |
| 599 |
redacted: Option<Vec<crate::response::redacted::Redacted>>, |
| 600 |
) -> Self { |
| 601 |
let common = Common::level0() |
| 602 |
.extensions(extensions) |
| 603 |
.and_notices(to_opt_vec(notices)) |
| 604 |
.build(); |
| 605 |
let mut domain = Domain::builder() |
| 606 |
.ldh_name(ldh_name) |
| 607 |
.and_unicode_name(unicode_name) |
| 608 |
.nameservers(nameservers) |
| 609 |
.and_handle(handle) |
| 610 |
.remarks(remarks) |
| 611 |
.links(links) |
| 612 |
.events(events) |
| 613 |
.statuses(statuses) |
| 614 |
.and_port_43(port_43) |
| 615 |
.entities(entities) |
| 616 |
.public_ids(public_ids) |
| 617 |
.and_secure_dns(secure_dns) |
| 618 |
.variants(variants) |
| 619 |
.and_network(network) |
| 620 |
.and_ttl0_data(ttl0_data) |
| 621 |
.and_redacted(redacted) |
| 622 |
.build(); |
| 623 |
domain.common = common; |
| 624 |
domain |
| 625 |
} |
| 626 |
|
| 627 |
/// Builds an IDN object for use with embedding into response objects. |
| 628 |
/// |
| 629 |
/// ```rust |
| 630 |
/// use icann_rdap_common::prelude::*; |
| 631 |
/// |
| 632 |
/// let domain = Domain::idn() |
| 633 |
/// .unicode_name("foo.example.com") // required for this builder |
| 634 |
/// .handle("foo_example_com-1") |
| 635 |
/// .status("active") |
| 636 |
/// // ... |
| 637 |
/// .build(); |
| 638 |
/// ``` |
| 639 |
#[builder(entry = "idn", visibility = "pub")] |
| 640 |
fn new_idn<T: Into<String>>( |
| 641 |
ldh_name: Option<String>, |
| 642 |
unicode_name: T, |
| 643 |
nameservers: Vec<Nameserver>, |
| 644 |
handle: Option<String>, |
| 645 |
remarks: Vec<Remark>, |
| 646 |
links: Vec<Link>, |
| 647 |
events: Vec<Event>, |
| 648 |
statuses: Vec<String>, |
| 649 |
port_43: Option<Port43>, |
| 650 |
entities: Vec<Entity>, |
| 651 |
public_ids: Vec<PublicId>, |
| 652 |
secure_dns: Option<SecureDns>, |
| 653 |
variants: Vec<Variant>, |
| 654 |
network: Option<Network>, |
| 655 |
ttl0_data: Option<Ttl0Data>, |
| 656 |
) -> Self { |
| 657 |
Self { |
| 658 |
common: Common::builder().build(), |
| 659 |
object_common: ObjectCommon::domain() |
| 660 |
.and_handle(handle) |
| 661 |
.and_remarks(to_opt_vec(remarks)) |
| 662 |
.and_links(to_opt_vec(links)) |
| 663 |
.and_events(to_opt_vec(events)) |
| 664 |
.status(statuses) |
| 665 |
.and_port_43(port_43) |
| 666 |
.and_entities(to_opt_vec(entities)) |
| 667 |
.build(), |
| 668 |
ldh_name, |
| 669 |
unicode_name: Some(unicode_name.into()), |
| 670 |
variants: to_opt_vec(variants), |
| 671 |
secure_dns, |
| 672 |
nameservers: to_opt_vec(nameservers), |
| 673 |
public_ids: to_opt_vec(public_ids), |
| 674 |
network, |
| 675 |
ttl0_data, |
| 676 |
} |
| 677 |
} |
| 678 |
|
| 679 |
/// Builds an IDN object for a response. |
| 680 |
/// |
| 681 |
/// ```rust |
| 682 |
/// use icann_rdap_common::prelude::*; |
| 683 |
/// |
| 684 |
/// let domain = Domain::idn_response_obj() |
| 685 |
/// .unicode_name("foo.example.com") // required for this builder |
| 686 |
/// .handle("foo_example_com-1") |
| 687 |
/// .status("active") |
| 688 |
/// .extension(ExtensionId::IcannRdapResponseProfile1.as_ref()) |
| 689 |
/// .extension(ExtensionId::IcannRdapTechnicalImplementationGuide1.as_ref()) |
| 690 |
/// .notice(Notice::builder().title("test").build()) |
| 691 |
/// // ... |
| 692 |
/// .build(); |
| 693 |
/// ``` |
| 694 |
#[builder(entry = "idn_response_obj", visibility = "pub")] |
| 695 |
fn new_idn_response_obj<T: Into<String>>( |
| 696 |
ldh_name: Option<String>, |
| 697 |
unicode_name: T, |
| 698 |
nameservers: Vec<Nameserver>, |
| 699 |
handle: Option<String>, |
| 700 |
remarks: Vec<Remark>, |
| 701 |
links: Vec<Link>, |
| 702 |
events: Vec<Event>, |
| 703 |
statuses: Vec<String>, |
| 704 |
port_43: Option<Port43>, |
| 705 |
entities: Vec<Entity>, |
| 706 |
notices: Vec<Notice>, |
| 707 |
public_ids: Vec<PublicId>, |
| 708 |
secure_dns: Option<SecureDns>, |
| 709 |
variants: Vec<Variant>, |
| 710 |
network: Option<Network>, |
| 711 |
ttl0_data: Option<Ttl0Data>, |
| 712 |
extensions: Vec<Extension>, |
| 713 |
) -> Self { |
| 714 |
let common = Common::level0() |
| 715 |
.extensions(extensions) |
| 716 |
.and_notices(to_opt_vec(notices)) |
| 717 |
.build(); |
| 718 |
let mut idn = Domain::idn() |
| 719 |
.and_ldh_name(ldh_name) |
| 720 |
.unicode_name(unicode_name) |
| 721 |
.nameservers(nameservers) |
| 722 |
.and_handle(handle) |
| 723 |
.remarks(remarks) |
| 724 |
.links(links) |
| 725 |
.events(events) |
| 726 |
.statuses(statuses) |
| 727 |
.and_port_43(port_43) |
| 728 |
.entities(entities) |
| 729 |
.public_ids(public_ids) |
| 730 |
.and_secure_dns(secure_dns) |
| 731 |
.variants(variants) |
| 732 |
.and_network(network) |
| 733 |
.and_ttl0_data(ttl0_data) |
| 734 |
.build(); |
| 735 |
idn.common = common; |
| 736 |
idn |
| 737 |
} |
| 738 |
|
| 739 |
/// Getter for variants. |
| 740 |
pub fn variants(&self) -> &[Variant] { |
| 741 |
self.variants.as_deref().unwrap_or_default() |
| 742 |
} |
| 743 |
|
| 744 |
/// Getter for the publicIds. |
| 745 |
pub fn public_ids(&self) -> &[PublicId] { |
| 746 |
self.public_ids.as_deref().unwrap_or_default() |
| 747 |
} |
| 748 |
|
| 749 |
/// Getter for the nameservers. |
| 750 |
pub fn nameservers(&self) -> &[Nameserver] { |
| 751 |
self.nameservers.as_deref().unwrap_or_default() |
| 752 |
} |
| 753 |
|
| 754 |
/// Getter for ldhName. |
| 755 |
pub fn ldh_name(&self) -> Option<&str> { |
| 756 |
self.ldh_name.as_deref() |
| 757 |
} |
| 758 |
|
| 759 |
/// Getter for unicodeName. |
| 760 |
pub fn unicode_name(&self) -> Option<&str> { |
| 761 |
self.unicode_name.as_deref() |
| 762 |
} |
| 763 |
|
| 764 |
/// Getter for secureDNS. |
| 765 |
pub fn secure_dns(&self) -> Option<&SecureDns> { |
| 766 |
self.secure_dns.as_ref() |
| 767 |
} |
| 768 |
|
| 769 |
/// Getter for network. |
| 770 |
pub fn network(&self) -> Option<&Network> { |
| 771 |
self.network.as_ref() |
| 772 |
} |
| 773 |
|
| 774 |
/// Getter for the ttl0 data. |
| 775 |
pub fn ttl0_data(&self) -> Option<&Ttl0Data> { |
| 776 |
self.ttl0_data.as_ref() |
| 777 |
} |
| 778 |
} |
| 779 |
|
| 780 |
impl ToResponse for Domain { |
| 781 |
fn to_response(self) -> super::RdapResponse { |
| 782 |
super::RdapResponse::Domain(Box::new(self)) |
| 783 |
} |
| 784 |
} |
| 785 |
|
| 786 |
impl GetSelfLink for Domain { |
| 787 |
fn self_link(&self) -> Option<&Link> { |
| 788 |
self.object_common.self_link() |
| 789 |
} |
| 790 |
} |
| 791 |
|
| 792 |
impl SelfLink for Domain { |
| 793 |
fn with_self_link(mut self, link: Link) -> Self { |
| 794 |
self.object_common = self.object_common.with_self_link(link); |
| 795 |
self |
| 796 |
} |
| 797 |
} |
| 798 |
|
| 799 |
impl ToChild for Domain { |
| 800 |
fn to_child(mut self) -> Self { |
| 801 |
self.common = Common { |
| 802 |
rdap_conformance: None, |
| 803 |
notices: None, |
| 804 |
}; |
| 805 |
self |
| 806 |
} |
| 807 |
} |
| 808 |
|
| 809 |
impl CommonFields for Domain { |
| 810 |
fn common(&self) -> &Common { |
| 811 |
&self.common |
| 812 |
} |
| 813 |
} |
| 814 |
|
| 815 |
impl ObjectCommonFields for Domain { |
| 816 |
fn object_common(&self) -> &ObjectCommon { |
| 817 |
&self.object_common |
| 818 |
} |
| 819 |
} |
| 820 |
|
| 821 |
impl ContentExtensions for Domain { |
| 822 |
fn content_extensions(&self) -> std::collections::HashSet<super::ExtensionId> { |
| 823 |
let mut exts = HashSet::new(); |
| 824 |
exts.extend(self.common().content_extensions()); |
| 825 |
exts.extend(self.object_common().content_extensions()); |
| 826 |
exts |
| 827 |
} |
| 828 |
} |
| 829 |
|
| 830 |
#[cfg(test)] |
| 831 |
#[allow(non_snake_case)] |
| 832 |
mod tests { |
| 833 |
use crate::response::{SelfLink, types::Link}; |
| 834 |
|
| 835 |
use super::Domain; |
| 836 |
|
| 837 |
#[test] |
| 838 |
fn GIVEN_domain_WHEN_deserialize_THEN_success() { |
| 839 |
// GIVEN |
| 840 |
let expected = r#" |
| 841 |
{ |
| 842 |
"objectClassName" : "domain", |
| 843 |
"handle" : "XXXX", |
| 844 |
"ldhName" : "xn--fo-5ja.example", |
| 845 |
"unicodeName" : "fóo.example", |
| 846 |
"variants" : |
| 847 |
[ |
| 848 |
{ |
| 849 |
"relation" : [ "registered", "conjoined" ], |
| 850 |
"variantNames" : |
| 851 |
[ |
| 852 |
{ |
| 853 |
"ldhName" : "xn--fo-cka.example", |
| 854 |
"unicodeName" : "fõo.example" |
| 855 |
}, |
| 856 |
{ |
| 857 |
"ldhName" : "xn--fo-fka.example", |
| 858 |
"unicodeName" : "föo.example" |
| 859 |
} |
| 860 |
] |
| 861 |
}, |
| 862 |
{ |
| 863 |
"relation" : [ "unregistered", "registration restricted" ], |
| 864 |
"idnTable": ".EXAMPLE Swedish", |
| 865 |
"variantNames" : |
| 866 |
[ |
| 867 |
{ |
| 868 |
"ldhName": "xn--fo-8ja.example", |
| 869 |
"unicodeName" : "fôo.example" |
| 870 |
} |
| 871 |
] |
| 872 |
|
| 873 |
} |
| 874 |
], |
| 875 |
"status" : [ "locked", "transfer prohibited" ], |
| 876 |
"publicIds":[ |
| 877 |
{ |
| 878 |
"type":"ENS_Auth ID", |
| 879 |
"identifier":"1234567890" |
| 880 |
} |
| 881 |
], |
| 882 |
"nameservers" : |
| 883 |
[ |
| 884 |
{ |
| 885 |
"objectClassName" : "nameserver", |
| 886 |
"handle" : "XXXX", |
| 887 |
"ldhName" : "ns1.example.com", |
| 888 |
"status" : [ "active" ], |
| 889 |
"ipAddresses" : |
| 890 |
{ |
| 891 |
"v6": [ "2001:db8::123", "2001:db8::124" ], |
| 892 |
"v4": [ "192.0.2.1", "192.0.2.2" ] |
| 893 |
}, |
| 894 |
"remarks" : |
| 895 |
[ |
| 896 |
{ |
| 897 |
"description" : |
| 898 |
[ |
| 899 |
"She sells sea shells down by the sea shore.", |
| 900 |
"Originally written by Terry Sullivan." |
| 901 |
] |
| 902 |
} |
| 903 |
], |
| 904 |
"links" : |
| 905 |
[ |
| 906 |
{ |
| 907 |
"value" : "https://example.net/nameserver/ns1.example.com", |
| 908 |
"rel" : "self", |
| 909 |
"href" : "https://example.net/nameserver/ns1.example.com", |
| 910 |
"type" : "application/rdap+json" |
| 911 |
} |
| 912 |
], |
| 913 |
"events" : |
| 914 |
[ |
| 915 |
{ |
| 916 |
"eventAction" : "registration", |
| 917 |
"eventDate" : "1990-12-31T23:59:59Z" |
| 918 |
}, |
| 919 |
{ |
| 920 |
"eventAction" : "last changed", |
| 921 |
"eventDate" : "1991-12-31T23:59:59Z" |
| 922 |
} |
| 923 |
] |
| 924 |
}, |
| 925 |
{ |
| 926 |
"objectClassName" : "nameserver", |
| 927 |
"handle" : "XXXX", |
| 928 |
"ldhName" : "ns2.example.com", |
| 929 |
"status" : [ "active" ], |
| 930 |
"ipAddresses" : |
| 931 |
{ |
| 932 |
"v6" : [ "2001:db8::125", "2001:db8::126" ], |
| 933 |
"v4" : [ "192.0.2.3", "192.0.2.4" ] |
| 934 |
}, |
| 935 |
"remarks" : |
| 936 |
[ |
| 937 |
{ |
| 938 |
"description" : |
| 939 |
[ |
| 940 |
"She sells sea shells down by the sea shore.", |
| 941 |
"Originally written by Terry Sullivan." |
| 942 |
] |
| 943 |
} |
| 944 |
], |
| 945 |
"links" : |
| 946 |
[ |
| 947 |
{ |
| 948 |
"value" : "https://example.net/nameserver/ns2.example.com", |
| 949 |
"rel" : "self", |
| 950 |
"href" : "https://example.net/nameserver/ns2.example.com", |
| 951 |
"type" : "application/rdap+json" |
| 952 |
} |
| 953 |
], |
| 954 |
"events" : |
| 955 |
[ |
| 956 |
{ |
| 957 |
"eventAction" : "registration", |
| 958 |
"eventDate" : "1990-12-31T23:59:59Z" |
| 959 |
}, |
| 960 |
{ |
| 961 |
"eventAction" : "last changed", |
| 962 |
"eventDate" : "1991-12-31T23:59:59Z" |
| 963 |
} |
| 964 |
] |
| 965 |
} |
| 966 |
], |
| 967 |
"secureDNS": |
| 968 |
{ |
| 969 |
|
| 970 |
"zoneSigned": true, |
| 971 |
"delegationSigned": true, |
| 972 |
"maxSigLife": 604800, |
| 973 |
"keyData": |
| 974 |
[ |
| 975 |
{ |
| 976 |
"flags": 257, |
| 977 |
"protocol": 3, |
| 978 |
"algorithm": 8, |
| 979 |
"publicKey": "AwEAAa6eDzronzjEDbT...Jg1M5N rBSPkuXpdFE=", |
| 980 |
"events": |
| 981 |
[ |
| 982 |
{ |
| 983 |
"eventAction": "last changed", |
| 984 |
"eventDate": "2012-07-23T05:15:47Z" |
| 985 |
} |
| 986 |
] |
| 987 |
} |
| 988 |
] |
| 989 |
}, |
| 990 |
"remarks" : |
| 991 |
[ |
| 992 |
{ |
| 993 |
"description" : |
| 994 |
[ |
| 995 |
"She sells sea shells down by the sea shore.", |
| 996 |
"Originally written by Terry Sullivan." |
| 997 |
] |
| 998 |
} |
| 999 |
], |
| 1000 |
"links" : |
| 1001 |
[ |
| 1002 |
{ |
| 1003 |
"value": "https://example.net/domain/xn--fo-5ja.example", |
| 1004 |
"rel" : "self", |
| 1005 |
"href" : "https://example.net/domain/xn--fo-5ja.example", |
| 1006 |
"type" : "application/rdap+json" |
| 1007 |
} |
| 1008 |
], |
| 1009 |
"port43" : "whois.example.net", |
| 1010 |
"events" : |
| 1011 |
[ |
| 1012 |
{ |
| 1013 |
"eventAction" : "registration", |
| 1014 |
"eventDate" : "1990-12-31T23:59:59Z" |
| 1015 |
}, |
| 1016 |
{ |
| 1017 |
"eventAction" : "last changed", |
| 1018 |
"eventDate" : "1991-12-31T23:59:59Z", |
| 1019 |
"eventActor" : "[email protected]" |
| 1020 |
}, |
| 1021 |
{ |
| 1022 |
"eventAction" : "transfer", |
| 1023 |
"eventDate" : "1991-12-31T23:59:59Z", |
| 1024 |
"eventActor" : "[email protected]" |
| 1025 |
}, |
| 1026 |
{ |
| 1027 |
"eventAction" : "expiration", |
| 1028 |
"eventDate" : "2016-12-31T23:59:59Z", |
| 1029 |
"eventActor" : "[email protected]" |
| 1030 |
} |
| 1031 |
], |
| 1032 |
"entities" : |
| 1033 |
[ |
| 1034 |
{ |
| 1035 |
"objectClassName" : "entity", |
| 1036 |
"handle" : "XXXX", |
| 1037 |
"vcardArray":[ |
| 1038 |
"vcard", |
| 1039 |
[ |
| 1040 |
["version", {}, "text", "4.0"], |
| 1041 |
["fn", {}, "text", "Joe User"], |
| 1042 |
["kind", {}, "text", "individual"], |
| 1043 |
["lang", { |
| 1044 |
"pref":"1" |
| 1045 |
}, "language-tag", "fr"], |
| 1046 |
["lang", { |
| 1047 |
"pref":"2" |
| 1048 |
}, "language-tag", "en"], |
| 1049 |
["org", { |
| 1050 |
"type":"work" |
| 1051 |
}, "text", "Example"], |
| 1052 |
["title", {}, "text", "Research Scientist"], |
| 1053 |
["role", {}, "text", "Project Lead"], |
| 1054 |
["adr", |
| 1055 |
{ "type":"work" }, |
| 1056 |
"text", |
| 1057 |
[ |
| 1058 |
"", |
| 1059 |
"Suite 1234", |
| 1060 |
"4321 Rue Somewhere", |
| 1061 |
"Quebec", |
| 1062 |
"QC", |
| 1063 |
"G1V 2M2", |
| 1064 |
"Canada" |
| 1065 |
] |
| 1066 |
|
| 1067 |
], |
| 1068 |
["tel", |
| 1069 |
{ "type":["work", "voice"], "pref":"1" }, |
| 1070 |
"uri", "tel:+1-555-555-1234;ext=102" |
| 1071 |
], |
| 1072 |
["email", |
| 1073 |
{ "type":"work" }, |
| 1074 |
"text", "[email protected]" |
| 1075 |
] |
| 1076 |
] |
| 1077 |
], |
| 1078 |
"status" : [ "validated", "locked" ], |
| 1079 |
"roles" : [ "registrant" ], |
| 1080 |
"remarks" : |
| 1081 |
[ |
| 1082 |
{ |
| 1083 |
"description" : |
| 1084 |
[ |
| 1085 |
"She sells sea shells down by the sea shore.", |
| 1086 |
"Originally written by Terry Sullivan." |
| 1087 |
] |
| 1088 |
} |
| 1089 |
], |
| 1090 |
"links" : |
| 1091 |
[ |
| 1092 |
{ |
| 1093 |
"value" : "https://example.net/entity/XXXX", |
| 1094 |
"rel" : "self", |
| 1095 |
"href" : "https://example.net/entity/XXXX", |
| 1096 |
"type" : "application/rdap+json" |
| 1097 |
} |
| 1098 |
], |
| 1099 |
"events" : |
| 1100 |
[ |
| 1101 |
{ |
| 1102 |
"eventAction" : "registration", |
| 1103 |
"eventDate" : "1990-12-31T23:59:59Z" |
| 1104 |
}, |
| 1105 |
{ |
| 1106 |
"eventAction" : "last changed", |
| 1107 |
"eventDate" : "1991-12-31T23:59:59Z" |
| 1108 |
} |
| 1109 |
] |
| 1110 |
} |
| 1111 |
] |
| 1112 |
} |
| 1113 |
"#; |
| 1114 |
|
| 1115 |
// WHEN |
| 1116 |
let actual = serde_json::from_str::<Domain>(expected); |
| 1117 |
|
| 1118 |
// THEN |
| 1119 |
let actual = actual.unwrap(); |
| 1120 |
assert_eq!(actual.object_common.object_class_name, "domain"); |
| 1121 |
assert!(actual.object_common.handle.is_some()); |
| 1122 |
assert!(actual.ldh_name.is_some()); |
| 1123 |
assert!(actual.unicode_name.is_some()); |
| 1124 |
assert!(actual.variants.is_some()); |
| 1125 |
assert!(actual.public_ids.is_some()); |
| 1126 |
assert!(actual.object_common.remarks.is_some()); |
| 1127 |
assert!(actual.object_common.links.is_some()); |
| 1128 |
assert!(actual.object_common.events.is_some()); |
| 1129 |
assert!(actual.object_common.port_43.is_some()); |
| 1130 |
assert!(actual.object_common.entities.is_some()); |
| 1131 |
assert!(actual.secure_dns.is_some()); |
| 1132 |
} |
| 1133 |
|
| 1134 |
#[test] |
| 1135 |
fn GIVEN_no_self_links_WHEN_set_self_link_THEN_link_is_only_one() { |
| 1136 |
// GIVEN |
| 1137 |
let mut domain = Domain::builder() |
| 1138 |
.ldh_name("foo.example") |
| 1139 |
.link( |
| 1140 |
Link::builder() |
| 1141 |
.href("http://bar.example") |
| 1142 |
.value("http://bar.example") |
| 1143 |
.rel("unknown") |
| 1144 |
.build(), |
| 1145 |
) |
| 1146 |
.build(); |
| 1147 |
|
| 1148 |
// WHEN |
| 1149 |
domain = domain.with_self_link( |
| 1150 |
Link::builder() |
| 1151 |
.href("http://foo.example") |
| 1152 |
.value("http://foo.example") |
| 1153 |
.rel("unknown") |
| 1154 |
.build(), |
| 1155 |
); |
| 1156 |
|
| 1157 |
// THEN |
| 1158 |
assert_eq!( |
| 1159 |
domain |
| 1160 |
.object_common |
| 1161 |
.links |
| 1162 |
.expect("links are empty") |
| 1163 |
.iter() |
| 1164 |
.filter(|link| link.is_relation("self")) |
| 1165 |
.count(), |
| 1166 |
1 |
| 1167 |
); |
| 1168 |
} |
| 1169 |
} |