Distribute serialization tests over command modules

This commit is contained in:
Dirkjan Ochtman 2021-12-07 10:32:06 +01:00 committed by masalachai
parent cf44a81991
commit 8490eefc59
28 changed files with 657 additions and 681 deletions

View File

@ -96,7 +96,16 @@ mod tests {
use crate::tests::{get_xml, CLTRID, SUCCESS_MSG, SVTRID};
#[test]
fn contact_check() {
fn command() {
let xml = get_xml("request/contact/check.xml").unwrap();
let object = ContactCheck::new(&["eppdev-contact-1", "eppdev-contact-2"]);
let serialized = object.serialize_request(None, CLTRID).unwrap();
assert_eq!(xml, serialized);
}
#[test]
fn response() {
let xml = get_xml("response/contact/check.xml").unwrap();
let object = ContactCheck::deserialize_response(xml.as_str()).unwrap();

View File

@ -100,12 +100,39 @@ pub struct ContactCreateResponse {
#[cfg(test)]
mod tests {
use super::ContactCreate;
use super::{ContactCreate, Phone, PostalInfo};
use crate::common::Address;
use crate::request::Transaction;
use crate::tests::{get_xml, CLTRID, SUCCESS_MSG, SVTRID};
#[test]
fn contact_create() {
fn command() {
let xml = get_xml("request/contact/create.xml").unwrap();
let street = &["58", "Orchid Road"];
let address = Address::new(street, "Paris", "Paris", "392374", "FR".parse().unwrap());
let postal_info = PostalInfo::new("int", "John Doe", "Acme Widgets", address);
let mut voice = Phone::new("+33.47237942");
voice.set_extension("123");
let mut fax = Phone::new("+33.86698799");
fax.set_extension("677");
let mut object = ContactCreate::new(
"eppdev-contact-3",
"contact@eppdev.net",
postal_info,
voice,
"eppdev-387323",
);
object.set_fax(fax);
let serialized = object.serialize_request(None, CLTRID).unwrap();
assert_eq!(xml, serialized);
}
#[test]
fn response() {
let xml = get_xml("response/contact/create.xml").unwrap();
let object = ContactCreate::deserialize_response(xml.as_str()).unwrap();

View File

@ -49,7 +49,18 @@ mod tests {
use crate::tests::{get_xml, CLTRID, SUCCESS_MSG, SVTRID};
#[test]
fn contact_delete() {
fn command() {
let xml = get_xml("request/contact/delete.xml").unwrap();
let object = ContactDelete::new("eppdev-contact-3");
let serialized = object.serialize_request(None, CLTRID).unwrap();
assert_eq!(xml, serialized);
}
#[test]
fn response() {
let xml = get_xml("response/contact/delete.xml").unwrap();
let object = ContactDelete::deserialize_response(xml.as_str()).unwrap();

View File

@ -107,7 +107,18 @@ mod tests {
use crate::tests::{get_xml, CLTRID, SUCCESS_MSG, SVTRID};
#[test]
fn contact_info() {
fn command() {
let xml = get_xml("request/contact/info.xml").unwrap();
let object = ContactInfo::new("eppdev-contact-3", "eppdev-387323");
let serialized = object.serialize_request(None, CLTRID).unwrap();
assert_eq!(xml, serialized);
}
#[test]
fn response() {
let xml = get_xml("response/contact/info.xml").unwrap();
let object = ContactInfo::deserialize_response(xml.as_str()).unwrap();

View File

@ -108,9 +108,36 @@ pub struct ContactUpdate {
#[cfg(test)]
mod tests {
use super::ContactUpdate;
use crate::common::{Address, ContactStatus, Phone, PostalInfo};
use crate::request::Transaction;
use crate::tests::{get_xml, CLTRID, SUCCESS_MSG, SVTRID};
#[test]
fn command() {
let xml = get_xml("request/contact/update.xml").unwrap();
let mut object = ContactUpdate::new("eppdev-contact-3");
let street = &["58", "Orchid Road"];
let address = Address::new(street, "Paris", "Paris", "392374", "FR".parse().unwrap());
let postal_info = PostalInfo::new("loc", "John Doe", "Acme Widgets", address);
let voice = Phone::new("+33.47237942");
object.set_info("newemail@eppdev.net", postal_info, voice, "eppdev-387323");
let add_statuses = vec![ContactStatus {
status: "clientTransferProhibited".to_string(),
}];
object.add(add_statuses);
let remove_statuses = vec![ContactStatus {
status: "clientDeleteProhibited".to_string(),
}];
object.remove(remove_statuses);
let serialized = object.serialize_request(None, CLTRID).unwrap();
assert_eq!(xml, serialized);
}
#[test]
fn contact_update() {
let xml = get_xml("response/contact/update.xml").unwrap();

View File

@ -94,7 +94,20 @@ mod tests {
use crate::tests::{get_xml, CLTRID, SUCCESS_MSG, SVTRID};
#[test]
fn domain_check() {
fn command() {
let xml = get_xml("request/domain/check.xml").unwrap();
let object = DomainCheck::new(vec!["eppdev.com", "eppdev.net"]);
let serialized =
<DomainCheck as Transaction<NoExtension>>::serialize_request(object, None, CLTRID)
.unwrap();
assert_eq!(xml, serialized);
}
#[test]
fn response() {
let xml = get_xml("response/domain/check.xml").unwrap();
let object =
<DomainCheck as Transaction<NoExtension>>::deserialize_response(xml.as_str()).unwrap();

View File

@ -103,11 +103,131 @@ pub struct DomainCreateResponse {
#[cfg(test)]
mod tests {
use super::DomainCreate;
use crate::common::{DomainContact, HostAddr, HostAttr, HostAttrList, HostList, HostObjList};
use crate::request::Transaction;
use crate::tests::{get_xml, CLTRID, SUCCESS_MSG, SVTRID};
#[test]
fn domain_create() {
fn command() {
let xml = get_xml("request/domain/create.xml").unwrap();
let contacts = vec![
DomainContact {
contact_type: "admin".to_string(),
id: "eppdev-contact-3".to_string(),
},
DomainContact {
contact_type: "tech".to_string(),
id: "eppdev-contact-3".to_string(),
},
DomainContact {
contact_type: "billing".to_string(),
id: "eppdev-contact-3".to_string(),
},
];
let object = DomainCreate::new(
"eppdev-1.com",
1,
None,
Some("eppdev-contact-3"),
"epP4uthd#v",
Some(contacts),
);
let serialized = object.serialize_request(None, CLTRID).unwrap();
assert_eq!(xml, serialized);
}
#[test]
fn command_with_host_obj() {
let xml = get_xml("request/domain/create_with_host_obj.xml").unwrap();
let contacts = vec![
DomainContact {
contact_type: "admin".to_string(),
id: "eppdev-contact-3".to_string(),
},
DomainContact {
contact_type: "tech".to_string(),
id: "eppdev-contact-3".to_string(),
},
DomainContact {
contact_type: "billing".to_string(),
id: "eppdev-contact-3".to_string(),
},
];
let ns = Some(HostList::HostObjList(HostObjList {
hosts: vec!["ns1.test.com".into(), "ns2.test.com".into()],
}));
let object = DomainCreate::new(
"eppdev-1.com",
1,
ns,
Some("eppdev-contact-3"),
"epP4uthd#v",
Some(contacts),
);
let serialized = object.serialize_request(None, CLTRID).unwrap();
assert_eq!(xml, serialized);
}
#[test]
fn command_with_host_attr() {
let xml = get_xml("request/domain/create_with_host_attr.xml").unwrap();
let contacts = vec![
DomainContact {
contact_type: "admin".to_string(),
id: "eppdev-contact-3".to_string(),
},
DomainContact {
contact_type: "tech".to_string(),
id: "eppdev-contact-3".to_string(),
},
DomainContact {
contact_type: "billing".to_string(),
id: "eppdev-contact-3".to_string(),
},
];
let host_attr = HostList::HostAttrList(HostAttrList {
hosts: vec![
HostAttr {
name: "ns1.eppdev-1.com".into(),
addresses: None,
},
HostAttr {
name: "ns2.eppdev-1.com".into(),
addresses: Some(vec![
HostAddr::new_v4("177.232.12.58"),
HostAddr::new_v6("2404:6800:4001:801::200e"),
]),
},
],
});
let object = DomainCreate::new(
"eppdev-2.com",
1,
Some(host_attr),
Some("eppdev-contact-3"),
"epP4uthd#v",
Some(contacts),
);
let serialized = object.serialize_request(None, CLTRID).unwrap();
assert_eq!(xml, serialized);
}
#[test]
fn response() {
let xml = get_xml("response/domain/create.xml").unwrap();
let object = DomainCreate::deserialize_response(xml.as_str()).unwrap();

View File

@ -49,7 +49,18 @@ mod tests {
use crate::tests::{get_xml, CLTRID, SUCCESS_MSG, SVTRID};
#[test]
fn domain_delete() {
fn command() {
let xml = get_xml("request/domain/delete.xml").unwrap();
let object = DomainDelete::new("eppdev.com");
let serialized = object.serialize_request(None, CLTRID).unwrap();
assert_eq!(xml, serialized);
}
#[test]
fn response() {
let xml = get_xml("response/domain/delete.xml").unwrap();
let object = DomainDelete::deserialize_response(xml.as_str()).unwrap();

View File

@ -141,7 +141,20 @@ mod tests {
use crate::tests::{get_xml, CLTRID, SUCCESS_MSG, SVTRID};
#[test]
fn domain_info() {
fn command() {
let xml = get_xml("request/domain/info.xml").unwrap();
let object = DomainInfo::new("eppdev.com", Some("2fooBAR"));
let serialized =
<DomainInfo as Transaction<NoExtension>>::serialize_request(object, None, CLTRID)
.unwrap();
assert_eq!(xml, serialized);
}
#[test]
fn response() {
let xml = get_xml("response/domain/info.xml").unwrap();
let object =
<DomainInfo as Transaction<NoExtension>>::deserialize_response(xml.as_str()).unwrap();
@ -199,7 +212,7 @@ mod tests {
}
#[test]
fn domain_info_alt() {
fn response_alt() {
let xml = get_xml("response/domain/info_alt.xml").unwrap();
<DomainInfo as Transaction<NoExtension>>::deserialize_response(xml.as_str()).unwrap();
}

View File

@ -79,9 +79,22 @@ mod tests {
use super::DomainRenew;
use crate::request::Transaction;
use crate::tests::{get_xml, CLTRID, SUCCESS_MSG, SVTRID};
use chrono::NaiveDate;
#[test]
fn domain_renew() {
fn command() {
let xml = get_xml("request/domain/renew.xml").unwrap();
let exp_date = NaiveDate::from_ymd(2022, 7, 23);
let object = DomainRenew::new("eppdev.com", exp_date, 1);
let serialized = object.serialize_request(None, CLTRID).unwrap();
assert_eq!(xml, serialized);
}
#[test]
fn response() {
let xml = get_xml("response/domain/renew.xml").unwrap();
let object = DomainRenew::deserialize_response(xml.as_str()).unwrap();

View File

@ -149,7 +149,62 @@ mod tests {
use crate::tests::{get_xml, CLTRID, SUCCESS_MSG, SVTRID};
#[test]
fn domain_transfer_request() {
fn request_command() {
let xml = get_xml("request/domain/transfer_request.xml").unwrap();
let object = DomainTransfer::new("testing.com", Some(1), "epP4uthd#v");
let serialized = object.serialize_request(None, CLTRID).unwrap();
assert_eq!(xml, serialized);
}
#[test]
fn approve_command() {
let xml = get_xml("request/domain/transfer_approve.xml").unwrap();
let object = DomainTransfer::approve("testing.com");
let serialized = object.serialize_request(None, CLTRID).unwrap();
assert_eq!(xml, serialized);
}
#[test]
fn reject_command() {
let xml = get_xml("request/domain/transfer_reject.xml").unwrap();
let object = DomainTransfer::reject("testing.com");
let serialized = object.serialize_request(None, CLTRID).unwrap();
assert_eq!(xml, serialized);
}
#[test]
fn cancel_command() {
let xml = get_xml("request/domain/transfer_cancel.xml").unwrap();
let object = DomainTransfer::cancel("testing.com");
let serialized = object.serialize_request(None, CLTRID).unwrap();
assert_eq!(xml, serialized);
}
#[test]
fn query_command() {
let xml = get_xml("request/domain/transfer_query.xml").unwrap();
let object = DomainTransfer::query("testing.com", "epP4uthd#v");
let serialized = object.serialize_request(None, CLTRID).unwrap();
assert_eq!(xml, serialized);
}
#[test]
fn request_response() {
let xml = get_xml("response/domain/transfer_request.xml").unwrap();
let object = DomainTransfer::deserialize_response(xml.as_str()).unwrap();
@ -178,7 +233,7 @@ mod tests {
}
#[test]
fn domain_transfer_approve() {
fn approve_response() {
let xml = get_xml("response/domain/transfer_approve.xml").unwrap();
let object = DomainTransfer::deserialize_response(xml.as_str()).unwrap();
@ -189,7 +244,7 @@ mod tests {
}
#[test]
fn domain_transfer_reject() {
fn reject_response() {
let xml = get_xml("response/domain/transfer_reject.xml").unwrap();
let object = DomainTransfer::deserialize_response(xml.as_str()).unwrap();
@ -200,7 +255,7 @@ mod tests {
}
#[test]
fn domain_transfer_cancel() {
fn cancel_response() {
let xml = get_xml("response/domain/transfer_cancel.xml").unwrap();
let object = DomainTransfer::deserialize_response(xml.as_str()).unwrap();
@ -211,7 +266,7 @@ mod tests {
}
#[test]
fn domain_transfer_query() {
fn query_response() {
let xml = get_xml("response/domain/transfer_query.xml").unwrap();
let object = DomainTransfer::deserialize_response(xml.as_str()).unwrap();

View File

@ -102,13 +102,52 @@ pub struct DomainUpdate {
#[cfg(test)]
mod tests {
use super::DomainUpdate;
use crate::common::NoExtension;
use super::{DomainAddRemove, DomainChangeInfo, DomainUpdate};
use crate::common::{DomainAuthInfo, DomainContact, DomainStatus, NoExtension};
use crate::request::Transaction;
use crate::tests::{get_xml, CLTRID, SUCCESS_MSG, SVTRID};
#[test]
fn domain_update() {
fn command() {
let xml = get_xml("request/domain/update.xml").unwrap();
let mut object = DomainUpdate::new("eppdev.com");
let add = DomainAddRemove {
ns: None,
contacts: None,
statuses: Some(vec![DomainStatus {
status: "clientDeleteProhibited".to_string(),
}]),
};
let remove = DomainAddRemove {
ns: None,
contacts: Some(vec![DomainContact {
contact_type: "billing".to_string(),
id: "eppdev-contact-2".to_string(),
}]),
statuses: None,
};
let change_info = DomainChangeInfo {
registrant: None,
auth_info: Some(DomainAuthInfo::new("epP5uthd#v")),
};
object.add(add);
object.remove(remove);
object.info(change_info);
let serialized =
<DomainUpdate as Transaction<NoExtension>>::serialize_request(object, None, CLTRID)
.unwrap();
assert_eq!(xml, serialized);
}
#[test]
fn response() {
let xml = get_xml("response/domain/update.xml").unwrap();
let object =
<DomainUpdate as Transaction<NoExtension>>::deserialize_response(xml.as_str()).unwrap();

View File

@ -86,3 +86,36 @@ pub struct UpdateData {
#[serde(rename = "sync:expMonthDay", alias = "sync")]
pub exp: StringValue,
}
#[cfg(test)]
mod tests {
use super::{GMonthDay, Update};
use crate::domain::update::{DomainChangeInfo, DomainUpdate};
use crate::request::Transaction;
use crate::tests::{get_xml, CLTRID};
#[test]
fn command() {
let xml = get_xml("request/extensions/consolidate.xml").unwrap();
let exp = GMonthDay::new(5, 31, None).unwrap();
let consolidate_ext = Update::new(exp);
let mut object = DomainUpdate::new("eppdev.com");
object.info(DomainChangeInfo {
registrant: None,
auth_info: None,
});
let serialized = <DomainUpdate as Transaction<Update>>::serialize_request(
object,
Some(consolidate_ext),
CLTRID,
)
.unwrap();
assert_eq!(xml, serialized);
}
}

View File

@ -49,10 +49,28 @@ mod tests {
use super::NameStore;
use crate::domain::check::DomainCheck;
use crate::request::Transaction;
use crate::tests::get_xml;
use crate::tests::{get_xml, CLTRID};
#[test]
fn namestore() {
fn command() {
let xml = get_xml("request/extensions/namestore.xml").unwrap();
let namestore_ext = NameStore::new("com");
let object = DomainCheck::new(vec!["example1.com", "example2.com", "example3.com"]);
let serialized = <DomainCheck as Transaction<NameStore>>::serialize_request(
object,
Some(namestore_ext),
CLTRID,
)
.unwrap();
assert_eq!(xml, serialized);
}
#[test]
fn response() {
let xml = get_xml("response/extensions/namestore.xml").unwrap();
let object =

View File

@ -95,3 +95,61 @@ pub struct RgpRestoreReport {
#[serde(rename = "rgp:restore", alias = "restore")]
restore: RgpRestoreReportSection,
}
#[cfg(test)]
mod tests {
use std::str::FromStr;
use chrono::DateTime;
use super::{RgpRestoreReport, Update};
use crate::domain::update::{DomainChangeInfo, DomainUpdate};
use crate::request::Transaction;
use crate::tests::{get_xml, CLTRID};
#[test]
fn command() {
let xml = get_xml("request/extensions/rgp_restore_report.xml").unwrap();
let pre_data =
"Pre-delete registration data goes here. Both XML and free text are allowed.";
let post_data =
"Post-restore registration data goes here. Both XML and free text are allowed.";
let deleted_at = DateTime::from_str("2021-07-10T22:00:00.0Z").unwrap();
let restored_at = DateTime::from_str("2021-07-20T22:00:00.0Z").unwrap();
let restore_reason = "Registrant error.";
let statements = &[
"This registrar has not restored the Registered Name in order to assume the rights to use or sell the Registered Name for itself or for any third party.",
"The information in this report is true to best of this registrar's knowledge, and this registrar acknowledges that intentionally supplying false information in this report shall constitute an incurable material breach of the Registry-Registrar Agreement.",
];
let other = "Supporting information goes here.";
let domain_restore_report = Update {
data: RgpRestoreReport::new(
pre_data,
post_data,
deleted_at,
restored_at,
restore_reason,
statements,
other,
),
};
let mut object = DomainUpdate::new("eppdev.com");
object.info(DomainChangeInfo {
registrant: None,
auth_info: None,
});
let serialized =
<DomainUpdate as Transaction<Update<RgpRestoreReport>>>::serialize_request(
object,
Some(domain_restore_report),
CLTRID,
)
.unwrap();
assert_eq!(xml, serialized);
}
}

View File

@ -71,12 +71,40 @@ pub struct RgpRequestResponse {
mod tests {
use super::{RgpRestoreRequest, Update};
use crate::domain::info::DomainInfo;
use crate::domain::update::DomainUpdate;
use crate::domain::update::{DomainChangeInfo, DomainUpdate};
use crate::request::Transaction;
use crate::tests::{get_xml, SUCCESS_MSG, SVTRID};
use crate::tests::{get_xml, CLTRID, SUCCESS_MSG, SVTRID};
#[test]
fn rgp_restore_request() {
fn request_command() {
let xml = get_xml("request/extensions/rgp_restore_request.xml").unwrap();
let domain_restore_request = Update {
data: RgpRestoreRequest::default(),
};
let mut object = DomainUpdate::new("eppdev.com");
let change_info = DomainChangeInfo {
registrant: None,
auth_info: None,
};
object.info(change_info);
let serialized =
<DomainUpdate as Transaction<Update<RgpRestoreRequest>>>::serialize_request(
object,
Some(domain_restore_request),
CLTRID,
)
.unwrap();
assert_eq!(xml, serialized);
}
#[test]
fn request_response() {
let xml = get_xml("response/extensions/rgp_restore.xml").unwrap();
let object =
<DomainUpdate as Transaction<Update<RgpRestoreRequest>>>::deserialize_response(
@ -93,7 +121,7 @@ mod tests {
}
#[test]
fn rgp_restore_domain_info_response() {
fn domain_info_request_response() {
let xml = get_xml("response/extensions/domain_info_rgp.xml").unwrap();
let object = <DomainInfo as Transaction<Update<RgpRestoreRequest>>>::deserialize_response(
xml.as_str(),

View File

@ -305,10 +305,18 @@ impl EppXml for GreetingDocument {}
#[cfg(test)]
mod tests {
use super::{ExpiryType, GreetingDocument, Relative};
use super::{ExpiryType, GreetingDocument, HelloDocument, Relative};
use crate::tests::get_xml;
use crate::xml::EppXml;
#[test]
fn hello() {
let xml = get_xml("request/hello.xml").unwrap();
let serialized = HelloDocument::default().serialize().unwrap();
assert_eq!(xml, serialized);
}
#[test]
fn greeting() {
let xml = get_xml("response/greeting.xml").unwrap();

View File

@ -94,7 +94,18 @@ mod tests {
use crate::tests::{get_xml, CLTRID, SUCCESS_MSG, SVTRID};
#[test]
fn host_check() {
fn command() {
let xml = get_xml("request/host/check.xml").unwrap();
let object = HostCheck::new(&["ns1.eppdev-1.com", "host1.eppdev-1.com"]);
let serialized = object.serialize_request(None, CLTRID).unwrap();
assert_eq!(xml, serialized);
}
#[test]
fn response() {
let xml = get_xml("response/host/check.xml").unwrap();
let object = HostCheck::deserialize_response(xml.as_str()).unwrap();

View File

@ -71,11 +71,28 @@ pub struct HostCreateResponse {
#[cfg(test)]
mod tests {
use super::HostCreate;
use crate::common::HostAddr;
use crate::request::Transaction;
use crate::tests::{get_xml, CLTRID, SUCCESS_MSG, SVTRID};
#[test]
fn host_create() {
fn command() {
let xml = get_xml("request/host/create.xml").unwrap();
let addresses = vec![
HostAddr::new("v4", "29.245.122.14"),
HostAddr::new("v6", "2404:6800:4001:801::200e"),
];
let object = HostCreate::new("host1.eppdev-1.com", addresses);
let serialized = object.serialize_request(None, CLTRID).unwrap();
assert_eq!(xml, serialized);
}
#[test]
fn response() {
let xml = get_xml("response/host/create.xml").unwrap();
let object = HostCreate::deserialize_response(xml.as_str()).unwrap();

View File

@ -49,7 +49,18 @@ mod tests {
use crate::tests::{get_xml, CLTRID, SUCCESS_MSG, SVTRID};
#[test]
fn host_delete() {
fn command() {
let xml = get_xml("request/host/delete.xml").unwrap();
let object = HostDelete::new("ns1.eppdev-1.com");
let serialized = object.serialize_request(None, CLTRID).unwrap();
assert_eq!(xml, serialized);
}
#[test]
fn response() {
let xml = get_xml("response/host/delete.xml").unwrap();
let object = HostDelete::deserialize_response(xml.as_str()).unwrap();

View File

@ -94,7 +94,18 @@ mod tests {
use crate::tests::{get_xml, CLTRID, SUCCESS_MSG, SVTRID};
#[test]
fn host_info() {
fn command() {
let xml = get_xml("request/host/info.xml").unwrap();
let object = HostInfo::new("ns1.eppdev-1.com");
let serialized = object.serialize_request(None, CLTRID).unwrap();
assert_eq!(xml, serialized);
}
#[test]
fn response() {
let xml = get_xml("response/host/info.xml").unwrap();
let object = HostInfo::deserialize_response(xml.as_str()).unwrap();

View File

@ -90,12 +90,44 @@ pub struct HostUpdate {
#[cfg(test)]
mod tests {
use super::HostUpdate;
use super::{HostAddRemove, HostChangeInfo, HostUpdate};
use crate::common::{HostAddr, HostStatus};
use crate::request::Transaction;
use crate::tests::{get_xml, CLTRID, SUCCESS_MSG, SVTRID};
#[test]
fn host_update() {
fn command() {
let xml = get_xml("request/host/update.xml").unwrap();
let addr = vec![HostAddr::new("v6", "2404:6800:4001:801::200e")];
let add = HostAddRemove {
addresses: Some(addr),
statuses: None,
};
let remove = HostAddRemove {
addresses: None,
statuses: Some(vec![HostStatus {
status: "clientDeleteProhibited".to_string(),
}]),
};
let mut object = HostUpdate::new("host1.eppdev-1.com");
object.add(add);
object.remove(remove);
object.info(HostChangeInfo {
name: "host2.eppdev-1.com".into(),
});
let serialized = object.serialize_request(None, CLTRID).unwrap();
assert_eq!(xml, serialized);
}
#[test]
fn response() {
let xml = get_xml("response/host/update.xml").unwrap();
let object = HostUpdate::deserialize_response(xml.as_str()).unwrap();

View File

@ -71,7 +71,20 @@ mod tests {
use crate::tests::{get_xml, CLTRID, SUCCESS_MSG, SVTRID};
#[test]
fn login() {
fn command() {
let ext_uris = Some(vec![
"http://schema.ispapi.net/epp/xml/keyvalue-1.0".to_string()
]);
let xml = get_xml("request/login.xml").unwrap();
let object = Login::new("username", "password", ext_uris);
let serialized = object.serialize_request(None, CLTRID).unwrap();
assert_eq!(xml, serialized);
}
#[test]
fn response() {
let xml = get_xml("response/login.xml").unwrap();
let object = Login::deserialize_response(xml.as_str()).unwrap();

View File

@ -25,7 +25,16 @@ mod tests {
use crate::tests::{get_xml, CLTRID, SVTRID};
#[test]
fn logout() {
fn command() {
let xml = get_xml("request/logout.xml").unwrap();
let object = Logout;
let serialized = object.serialize_request(None, CLTRID).unwrap();
assert_eq!(xml, serialized);
}
#[test]
fn response() {
let xml = get_xml("response/logout.xml").unwrap();
let object = Logout::deserialize_response(xml.as_str()).unwrap();

View File

@ -35,10 +35,21 @@ impl MessageAck {
mod tests {
use super::MessageAck;
use crate::request::Transaction;
use crate::tests::{get_xml, SUCCESS_MSG, SVTRID};
use crate::tests::{get_xml, CLTRID, SUCCESS_MSG, SVTRID};
#[test]
fn message_ack() {
fn command() {
let xml = get_xml("request/message/ack.xml").unwrap();
let object = MessageAck::new(12345);
let serialized = object.serialize_request(None, CLTRID).unwrap();
assert_eq!(xml, serialized);
}
#[test]
fn response() {
let xml = get_xml("response/message/ack.xml").unwrap();
let object = MessageAck::deserialize_response(xml.as_str()).unwrap();

View File

@ -70,7 +70,18 @@ mod tests {
use crate::tests::{get_xml, CLTRID, SVTRID};
#[test]
fn message_poll() {
fn command() {
let xml = get_xml("request/message/poll.xml").unwrap();
let object = MessagePoll::default();
let serialized = object.serialize_request(None, CLTRID).unwrap();
assert_eq!(xml, serialized);
}
#[test]
fn response() {
let xml = get_xml("response/message/poll.xml").unwrap();
let object = MessagePoll::deserialize_response(xml.as_str()).unwrap();

View File

@ -1,7 +1,5 @@
//! Module for automated tests
pub mod se;
use regex::Regex;
use std::{error::Error, fs::File, io::Read};

View File

@ -1,642 +0,0 @@
//! `EppObject` to EPP XML serialization tests
mod request {
use super::super::get_xml;
use super::super::CLTRID;
use crate::common::HostAttrList;
use crate::common::HostList;
use crate::common::HostObjList;
use crate::common::NoExtension;
use crate::common::{
Address, ContactStatus, DomainAuthInfo, DomainContact, DomainStatus, HostAddr, HostAttr,
HostStatus, Phone, PostalInfo,
};
use crate::contact::check::ContactCheck;
use crate::contact::create::ContactCreate;
use crate::contact::delete::ContactDelete;
use crate::contact::info::ContactInfo;
use crate::contact::update::ContactUpdate;
use crate::domain::check::DomainCheck;
use crate::domain::create::DomainCreate;
use crate::domain::delete::DomainDelete;
use crate::domain::info::DomainInfo;
use crate::domain::renew::DomainRenew;
use crate::domain::transfer::DomainTransfer;
use crate::domain::update::DomainAddRemove;
use crate::domain::update::DomainChangeInfo;
use crate::domain::update::DomainUpdate;
use crate::extensions::consolidate;
use crate::extensions::consolidate::GMonthDay;
use crate::extensions::namestore::NameStore;
use crate::extensions::rgp::{self, report::RgpRestoreReport, request::RgpRestoreRequest};
use crate::hello::HelloDocument;
use crate::host::check::HostCheck;
use crate::host::create::HostCreate;
use crate::host::delete::HostDelete;
use crate::host::info::HostInfo;
use crate::host::update::HostAddRemove;
use crate::host::update::HostChangeInfo;
use crate::host::update::HostUpdate;
use crate::login::Login;
use crate::logout::Logout;
use crate::message::ack::MessageAck;
use crate::message::poll::MessagePoll;
use crate::request::Transaction;
use crate::xml::EppXml;
use chrono::{DateTime, NaiveDate};
use std::str::FromStr;
#[test]
fn hello() {
let xml = get_xml("request/hello.xml").unwrap();
let serialized = HelloDocument::default().serialize().unwrap();
assert_eq!(xml, serialized);
}
#[test]
fn login() {
let ext_uris = Some(vec![
"http://schema.ispapi.net/epp/xml/keyvalue-1.0".to_string()
]);
let xml = get_xml("request/login.xml").unwrap();
let object = Login::new("username", "password", ext_uris);
let serialized = object.serialize_request(None, CLTRID).unwrap();
assert_eq!(xml, serialized);
}
#[test]
fn logout() {
let xml = get_xml("request/logout.xml").unwrap();
let object = Logout;
let serialized = object.serialize_request(None, CLTRID).unwrap();
assert_eq!(xml, serialized);
}
#[test]
fn contact_check() {
let xml = get_xml("request/contact/check.xml").unwrap();
let object = ContactCheck::new(&["eppdev-contact-1", "eppdev-contact-2"]);
let serialized = object.serialize_request(None, CLTRID).unwrap();
assert_eq!(xml, serialized);
}
#[test]
fn contact_create() {
let xml = get_xml("request/contact/create.xml").unwrap();
let street = &["58", "Orchid Road"];
let address = Address::new(street, "Paris", "Paris", "392374", "FR".parse().unwrap());
let postal_info = PostalInfo::new("int", "John Doe", "Acme Widgets", address);
let mut voice = Phone::new("+33.47237942");
voice.set_extension("123");
let mut fax = Phone::new("+33.86698799");
fax.set_extension("677");
let mut object = ContactCreate::new(
"eppdev-contact-3",
"contact@eppdev.net",
postal_info,
voice,
"eppdev-387323",
);
object.set_fax(fax);
let serialized = object.serialize_request(None, CLTRID).unwrap();
assert_eq!(xml, serialized);
}
#[test]
fn contact_info() {
let xml = get_xml("request/contact/info.xml").unwrap();
let object = ContactInfo::new("eppdev-contact-3", "eppdev-387323");
let serialized = object.serialize_request(None, CLTRID).unwrap();
assert_eq!(xml, serialized);
}
#[test]
fn contact_update() {
let xml = get_xml("request/contact/update.xml").unwrap();
let mut object = ContactUpdate::new("eppdev-contact-3");
let street = &["58", "Orchid Road"];
let address = Address::new(street, "Paris", "Paris", "392374", "FR".parse().unwrap());
let postal_info = PostalInfo::new("loc", "John Doe", "Acme Widgets", address);
let voice = Phone::new("+33.47237942");
object.set_info("newemail@eppdev.net", postal_info, voice, "eppdev-387323");
let add_statuses = vec![ContactStatus {
status: "clientTransferProhibited".to_string(),
}];
object.add(add_statuses);
let remove_statuses = vec![ContactStatus {
status: "clientDeleteProhibited".to_string(),
}];
object.remove(remove_statuses);
let serialized = object.serialize_request(None, CLTRID).unwrap();
assert_eq!(xml, serialized);
}
#[test]
fn contact_delete() {
let xml = get_xml("request/contact/delete.xml").unwrap();
let object = ContactDelete::new("eppdev-contact-3");
let serialized = object.serialize_request(None, CLTRID).unwrap();
assert_eq!(xml, serialized);
}
#[test]
fn domain_check() {
let xml = get_xml("request/domain/check.xml").unwrap();
let object = DomainCheck::new(vec!["eppdev.com", "eppdev.net"]);
let serialized =
<DomainCheck as Transaction<NoExtension>>::serialize_request(object, None, CLTRID)
.unwrap();
assert_eq!(xml, serialized);
}
#[test]
fn domain_create() {
let xml = get_xml("request/domain/create.xml").unwrap();
let contacts = vec![
DomainContact {
contact_type: "admin".to_string(),
id: "eppdev-contact-3".to_string(),
},
DomainContact {
contact_type: "tech".to_string(),
id: "eppdev-contact-3".to_string(),
},
DomainContact {
contact_type: "billing".to_string(),
id: "eppdev-contact-3".to_string(),
},
];
let object = DomainCreate::new(
"eppdev-1.com",
1,
None,
Some("eppdev-contact-3"),
"epP4uthd#v",
Some(contacts),
);
let serialized = object.serialize_request(None, CLTRID).unwrap();
assert_eq!(xml, serialized);
}
#[test]
fn domain_create_with_host_obj() {
let xml = get_xml("request/domain/create_with_host_obj.xml").unwrap();
let contacts = vec![
DomainContact {
contact_type: "admin".to_string(),
id: "eppdev-contact-3".to_string(),
},
DomainContact {
contact_type: "tech".to_string(),
id: "eppdev-contact-3".to_string(),
},
DomainContact {
contact_type: "billing".to_string(),
id: "eppdev-contact-3".to_string(),
},
];
let ns = Some(HostList::HostObjList(HostObjList {
hosts: vec!["ns1.test.com".into(), "ns2.test.com".into()],
}));
let object = DomainCreate::new(
"eppdev-1.com",
1,
ns,
Some("eppdev-contact-3"),
"epP4uthd#v",
Some(contacts),
);
let serialized = object.serialize_request(None, CLTRID).unwrap();
assert_eq!(xml, serialized);
}
#[test]
fn domain_create_with_host_attr() {
let xml = get_xml("request/domain/create_with_host_attr.xml").unwrap();
let contacts = vec![
DomainContact {
contact_type: "admin".to_string(),
id: "eppdev-contact-3".to_string(),
},
DomainContact {
contact_type: "tech".to_string(),
id: "eppdev-contact-3".to_string(),
},
DomainContact {
contact_type: "billing".to_string(),
id: "eppdev-contact-3".to_string(),
},
];
let host_attr = HostList::HostAttrList(HostAttrList {
hosts: vec![
HostAttr {
name: "ns1.eppdev-1.com".into(),
addresses: None,
},
HostAttr {
name: "ns2.eppdev-1.com".into(),
addresses: Some(vec![
HostAddr::new_v4("177.232.12.58"),
HostAddr::new_v6("2404:6800:4001:801::200e"),
]),
},
],
});
let object = DomainCreate::new(
"eppdev-2.com",
1,
Some(host_attr),
Some("eppdev-contact-3"),
"epP4uthd#v",
Some(contacts),
);
let serialized = object.serialize_request(None, CLTRID).unwrap();
assert_eq!(xml, serialized);
}
#[test]
fn domain_info() {
let xml = get_xml("request/domain/info.xml").unwrap();
let object = DomainInfo::new("eppdev.com", Some("2fooBAR"));
let serialized =
<DomainInfo as Transaction<NoExtension>>::serialize_request(object, None, CLTRID)
.unwrap();
assert_eq!(xml, serialized);
}
#[test]
fn domain_update() {
let xml = get_xml("request/domain/update.xml").unwrap();
let mut object = DomainUpdate::new("eppdev.com");
let add = DomainAddRemove {
ns: None,
contacts: None,
statuses: Some(vec![DomainStatus {
status: "clientDeleteProhibited".to_string(),
}]),
};
let remove = DomainAddRemove {
ns: None,
contacts: Some(vec![DomainContact {
contact_type: "billing".to_string(),
id: "eppdev-contact-2".to_string(),
}]),
statuses: None,
};
let change_info = DomainChangeInfo {
registrant: None,
auth_info: Some(DomainAuthInfo::new("epP5uthd#v")),
};
object.add(add);
object.remove(remove);
object.info(change_info);
let serialized =
<DomainUpdate as Transaction<NoExtension>>::serialize_request(object, None, CLTRID)
.unwrap();
assert_eq!(xml, serialized);
}
#[test]
fn domain_delete() {
let xml = get_xml("request/domain/delete.xml").unwrap();
let object = DomainDelete::new("eppdev.com");
let serialized = object.serialize_request(None, CLTRID).unwrap();
assert_eq!(xml, serialized);
}
#[test]
fn domain_renew() {
let xml = get_xml("request/domain/renew.xml").unwrap();
let exp_date = NaiveDate::from_ymd(2022, 7, 23);
let object = DomainRenew::new("eppdev.com", exp_date, 1);
let serialized = object.serialize_request(None, CLTRID).unwrap();
assert_eq!(xml, serialized);
}
#[test]
fn domain_transfer_request() {
let xml = get_xml("request/domain/transfer_request.xml").unwrap();
let object = DomainTransfer::new("testing.com", Some(1), "epP4uthd#v");
let serialized = object.serialize_request(None, CLTRID).unwrap();
assert_eq!(xml, serialized);
}
#[test]
fn domain_transfer_approve() {
let xml = get_xml("request/domain/transfer_approve.xml").unwrap();
let object = DomainTransfer::approve("testing.com");
let serialized = object.serialize_request(None, CLTRID).unwrap();
assert_eq!(xml, serialized);
}
#[test]
fn domain_transfer_reject() {
let xml = get_xml("request/domain/transfer_reject.xml").unwrap();
let object = DomainTransfer::reject("testing.com");
let serialized = object.serialize_request(None, CLTRID).unwrap();
assert_eq!(xml, serialized);
}
#[test]
fn domain_transfer_cancel() {
let xml = get_xml("request/domain/transfer_cancel.xml").unwrap();
let object = DomainTransfer::cancel("testing.com");
let serialized = object.serialize_request(None, CLTRID).unwrap();
assert_eq!(xml, serialized);
}
#[test]
fn domain_transfer_query() {
let xml = get_xml("request/domain/transfer_query.xml").unwrap();
let object = DomainTransfer::query("testing.com", "epP4uthd#v");
let serialized = object.serialize_request(None, CLTRID).unwrap();
assert_eq!(xml, serialized);
}
#[test]
fn host_check() {
let xml = get_xml("request/host/check.xml").unwrap();
let object = HostCheck::new(&["ns1.eppdev-1.com", "host1.eppdev-1.com"]);
let serialized = object.serialize_request(None, CLTRID).unwrap();
assert_eq!(xml, serialized);
}
#[test]
fn host_create() {
let xml = get_xml("request/host/create.xml").unwrap();
let addresses = vec![
HostAddr::new("v4", "29.245.122.14"),
HostAddr::new("v6", "2404:6800:4001:801::200e"),
];
let object = HostCreate::new("host1.eppdev-1.com", addresses);
let serialized = object.serialize_request(None, CLTRID).unwrap();
assert_eq!(xml, serialized);
}
#[test]
fn host_info() {
let xml = get_xml("request/host/info.xml").unwrap();
let object = HostInfo::new("ns1.eppdev-1.com");
let serialized = object.serialize_request(None, CLTRID).unwrap();
assert_eq!(xml, serialized);
}
#[test]
fn host_update() {
let xml = get_xml("request/host/update.xml").unwrap();
let addr = vec![HostAddr::new("v6", "2404:6800:4001:801::200e")];
let add = HostAddRemove {
addresses: Some(addr),
statuses: None,
};
let remove = HostAddRemove {
addresses: None,
statuses: Some(vec![HostStatus {
status: "clientDeleteProhibited".to_string(),
}]),
};
let mut object = HostUpdate::new("host1.eppdev-1.com");
object.add(add);
object.remove(remove);
object.info(HostChangeInfo {
name: "host2.eppdev-1.com".into(),
});
let serialized = object.serialize_request(None, CLTRID).unwrap();
assert_eq!(xml, serialized);
}
#[test]
fn host_delete() {
let xml = get_xml("request/host/delete.xml").unwrap();
let object = HostDelete::new("ns1.eppdev-1.com");
let serialized = object.serialize_request(None, CLTRID).unwrap();
assert_eq!(xml, serialized);
}
#[test]
fn message_poll() {
let xml = get_xml("request/message/poll.xml").unwrap();
let object = MessagePoll::default();
let serialized = object.serialize_request(None, CLTRID).unwrap();
assert_eq!(xml, serialized);
}
#[test]
fn message_ack() {
let xml = get_xml("request/message/ack.xml").unwrap();
let object = MessageAck::new(12345);
let serialized = object.serialize_request(None, CLTRID).unwrap();
assert_eq!(xml, serialized);
}
#[test]
fn rgp_restore_request() {
let xml = get_xml("request/extensions/rgp_restore_request.xml").unwrap();
let domain_restore_request = rgp::Update {
data: RgpRestoreRequest::default(),
};
let mut object = DomainUpdate::new("eppdev.com");
let change_info = DomainChangeInfo {
registrant: None,
auth_info: None,
};
object.info(change_info);
let serialized =
<DomainUpdate as Transaction<rgp::Update<RgpRestoreRequest>>>::serialize_request(
object,
Some(domain_restore_request),
CLTRID,
)
.unwrap();
assert_eq!(xml, serialized);
}
#[test]
fn rgp_restore_report() {
let xml = get_xml("request/extensions/rgp_restore_report.xml").unwrap();
let pre_data =
"Pre-delete registration data goes here. Both XML and free text are allowed.";
let post_data =
"Post-restore registration data goes here. Both XML and free text are allowed.";
let deleted_at = DateTime::from_str("2021-07-10T22:00:00.0Z").unwrap();
let restored_at = DateTime::from_str("2021-07-20T22:00:00.0Z").unwrap();
let restore_reason = "Registrant error.";
let statements = &[
"This registrar has not restored the Registered Name in order to assume the rights to use or sell the Registered Name for itself or for any third party.",
"The information in this report is true to best of this registrar's knowledge, and this registrar acknowledges that intentionally supplying false information in this report shall constitute an incurable material breach of the Registry-Registrar Agreement.",
];
let other = "Supporting information goes here.";
let domain_restore_report = rgp::Update {
data: RgpRestoreReport::new(
pre_data,
post_data,
deleted_at,
restored_at,
restore_reason,
statements,
other,
),
};
let mut object = DomainUpdate::new("eppdev.com");
object.info(DomainChangeInfo {
registrant: None,
auth_info: None,
});
let serialized =
<DomainUpdate as Transaction<rgp::Update<RgpRestoreReport>>>::serialize_request(
object,
Some(domain_restore_report),
CLTRID,
)
.unwrap();
assert_eq!(xml, serialized);
}
#[test]
fn namestore() {
let xml = get_xml("request/extensions/namestore.xml").unwrap();
let namestore_ext = NameStore::new("com");
let object = DomainCheck::new(vec!["example1.com", "example2.com", "example3.com"]);
let serialized = <DomainCheck as Transaction<NameStore>>::serialize_request(
object,
Some(namestore_ext),
CLTRID,
)
.unwrap();
assert_eq!(xml, serialized);
}
#[test]
fn consolidate() {
let xml = get_xml("request/extensions/consolidate.xml").unwrap();
let exp = GMonthDay::new(5, 31, None).unwrap();
let consolidate_ext = consolidate::Update::new(exp);
let mut object = DomainUpdate::new("eppdev.com");
object.info(DomainChangeInfo {
registrant: None,
auth_info: None,
});
let serialized = <DomainUpdate as Transaction<consolidate::Update>>::serialize_request(
object,
Some(consolidate_ext),
CLTRID,
)
.unwrap();
assert_eq!(xml, serialized);
}
}