Externalize handling of command serialization

This commit is contained in:
Dirkjan Ochtman 2022-03-10 12:50:09 +01:00 committed by masalachai
parent dd3c60f50e
commit dd07ecc4b8
28 changed files with 110 additions and 293 deletions

View File

@ -126,11 +126,11 @@ impl<C: Connector> EppClient<C> {
Ext: Extension + 'e, Ext: Extension + 'e,
{ {
let data = data.into(); let data = data.into();
let epp_xml = let document = <Cmd as Transaction<Ext>>::command(data.command, data.extension, id);
<Cmd as Transaction<Ext>>::serialize_request(data.command, data.extension, id)?; let xml = document.serialize()?;
debug!("{}: request: {}", self.connection.registry, &epp_xml); debug!("{}: request: {}", self.connection.registry, &xml);
let response = self.connection.transact(&epp_xml)?.await?; let response = self.connection.transact(&xml)?.await?;
debug!("{}: response: {}", self.connection.registry, &response); debug!("{}: response: {}", self.connection.registry, &response);
match Cmd::deserialize_response(&response) { match Cmd::deserialize_response(&response) {
@ -169,8 +169,8 @@ impl<C: Connector> EppClient<C> {
#[derive(Debug)] #[derive(Debug)]
pub struct RequestData<'c, 'e, C, E> { pub struct RequestData<'c, 'e, C, E> {
command: &'c C, pub(crate) command: &'c C,
extension: Option<&'e E>, pub(crate) extension: Option<&'e E>,
} }
impl<'c, C: Command> From<&'c C> for RequestData<'c, 'static, C, NoExtension> { impl<'c, C: Command> From<&'c C> for RequestData<'c, 'static, C, NoExtension> {

View File

@ -58,19 +58,14 @@ mod tests {
use crate::common::NoExtension; use crate::common::NoExtension;
use crate::request::Transaction; use crate::request::Transaction;
use crate::response::ResultCode; use crate::response::ResultCode;
use crate::tests::{get_xml, CLTRID, SUCCESS_MSG, SVTRID}; use crate::tests::{assert_serialized, get_xml, CLTRID, SUCCESS_MSG, SVTRID};
#[test] #[test]
fn command() { fn command() {
let xml = get_xml("request/contact/check.xml").unwrap();
let object = ContactCheck { let object = ContactCheck {
contact_ids: &["eppdev-contact-1", "eppdev-contact-2"], contact_ids: &["eppdev-contact-1", "eppdev-contact-2"],
}; };
let serialized = assert_serialized("request/contact/check.xml", &object);
<ContactCheck as Transaction<NoExtension>>::serialize_request(&object, None, CLTRID)
.unwrap();
assert_eq!(xml, serialized);
} }
#[test] #[test]

View File

@ -106,12 +106,10 @@ mod tests {
use crate::contact::Address; use crate::contact::Address;
use crate::request::Transaction; use crate::request::Transaction;
use crate::response::ResultCode; use crate::response::ResultCode;
use crate::tests::{get_xml, CLTRID, SUCCESS_MSG, SVTRID}; use crate::tests::{assert_serialized, get_xml, CLTRID, SUCCESS_MSG, SVTRID};
#[test] #[test]
fn command() { fn command() {
let xml = get_xml("request/contact/create.xml").unwrap();
let street = &["58", "Orchid Road"]; let street = &["58", "Orchid Road"];
let address = Address::new(street, "Paris", "Paris", "392374", "FR".parse().unwrap()); let address = Address::new(street, "Paris", "Paris", "392374", "FR".parse().unwrap());
let postal_info = PostalInfo::new("int", "John Doe", "Acme Widgets", address); let postal_info = PostalInfo::new("int", "John Doe", "Acme Widgets", address);
@ -129,11 +127,7 @@ mod tests {
); );
object.set_fax(fax); object.set_fax(fax);
let serialized = assert_serialized("request/contact/create.xml", &object);
<ContactCreate as Transaction<NoExtension>>::serialize_request(&object, None, CLTRID)
.unwrap();
assert_eq!(xml, serialized);
} }
#[test] #[test]

View File

@ -48,19 +48,12 @@ mod tests {
use crate::common::NoExtension; use crate::common::NoExtension;
use crate::request::Transaction; use crate::request::Transaction;
use crate::response::ResultCode; use crate::response::ResultCode;
use crate::tests::{get_xml, CLTRID, SUCCESS_MSG, SVTRID}; use crate::tests::{assert_serialized, get_xml, CLTRID, SUCCESS_MSG, SVTRID};
#[test] #[test]
fn command() { fn command() {
let xml = get_xml("request/contact/delete.xml").unwrap();
let object = ContactDelete::new("eppdev-contact-3"); let object = ContactDelete::new("eppdev-contact-3");
assert_serialized("request/contact/delete.xml", &object);
let serialized =
<ContactDelete as Transaction<NoExtension>>::serialize_request(&object, None, CLTRID)
.unwrap();
assert_eq!(xml, serialized);
} }
#[test] #[test]

View File

@ -110,19 +110,12 @@ mod tests {
use crate::common::NoExtension; use crate::common::NoExtension;
use crate::request::Transaction; use crate::request::Transaction;
use crate::response::ResultCode; use crate::response::ResultCode;
use crate::tests::{get_xml, CLTRID, SUCCESS_MSG, SVTRID}; use crate::tests::{assert_serialized, get_xml, CLTRID, SUCCESS_MSG, SVTRID};
#[test] #[test]
fn command() { fn command() {
let xml = get_xml("request/contact/info.xml").unwrap();
let object = ContactInfo::new("eppdev-contact-3", "eppdev-387323"); let object = ContactInfo::new("eppdev-contact-3", "eppdev-387323");
assert_serialized("request/contact/info.xml", &object);
let serialized =
<ContactInfo as Transaction<NoExtension>>::serialize_request(&object, None, CLTRID)
.unwrap();
assert_eq!(xml, serialized);
} }
#[test] #[test]

View File

@ -112,12 +112,10 @@ mod tests {
use crate::contact::Address; use crate::contact::Address;
use crate::request::Transaction; use crate::request::Transaction;
use crate::response::ResultCode; use crate::response::ResultCode;
use crate::tests::{get_xml, CLTRID, SUCCESS_MSG, SVTRID}; use crate::tests::{assert_serialized, get_xml, CLTRID, SUCCESS_MSG, SVTRID};
#[test] #[test]
fn command() { fn command() {
let xml = get_xml("request/contact/update.xml").unwrap();
let mut object = ContactUpdate::new("eppdev-contact-3"); let mut object = ContactUpdate::new("eppdev-contact-3");
let street = &["58", "Orchid Road"]; let street = &["58", "Orchid Road"];
@ -135,11 +133,7 @@ mod tests {
}]; }];
object.remove(remove_statuses); object.remove(remove_statuses);
let serialized = assert_serialized("request/contact/update.xml", &object);
<ContactUpdate as Transaction<NoExtension>>::serialize_request(&object, None, CLTRID)
.unwrap();
assert_eq!(xml, serialized);
} }
#[test] #[test]

View File

@ -56,21 +56,14 @@ mod tests {
use crate::common::NoExtension; use crate::common::NoExtension;
use crate::request::Transaction; use crate::request::Transaction;
use crate::response::ResultCode; use crate::response::ResultCode;
use crate::tests::{get_xml, CLTRID, SUCCESS_MSG, SVTRID}; use crate::tests::{assert_serialized, get_xml, CLTRID, SUCCESS_MSG, SVTRID};
#[test] #[test]
fn command() { fn command() {
let xml = get_xml("request/domain/check.xml").unwrap();
let object = DomainCheck { let object = DomainCheck {
domains: &["eppdev.com", "eppdev.net"], domains: &["eppdev.com", "eppdev.net"],
}; };
assert_serialized("request/domain/check.xml", &object);
let serialized =
<DomainCheck as Transaction<NoExtension>>::serialize_request(&object, None, CLTRID)
.unwrap();
assert_eq!(xml, serialized);
} }
#[test] #[test]

View File

@ -113,12 +113,10 @@ mod tests {
use crate::domain::{HostAttr, HostAttrList, HostObjList}; use crate::domain::{HostAttr, HostAttrList, HostObjList};
use crate::request::Transaction; use crate::request::Transaction;
use crate::response::ResultCode; use crate::response::ResultCode;
use crate::tests::{get_xml, CLTRID, SUCCESS_MSG, SVTRID}; use crate::tests::{assert_serialized, get_xml, CLTRID, SUCCESS_MSG, SVTRID};
#[test] #[test]
fn command() { fn command() {
let xml = get_xml("request/domain/create.xml").unwrap();
let contacts = &[ let contacts = &[
DomainContact { DomainContact {
contact_type: "admin".into(), contact_type: "admin".into(),
@ -143,17 +141,11 @@ mod tests {
Some(contacts), Some(contacts),
); );
let serialized = assert_serialized("request/domain/create.xml", &object);
<DomainCreate as Transaction<NoExtension>>::serialize_request(&object, None, CLTRID)
.unwrap();
assert_eq!(xml, serialized);
} }
#[test] #[test]
fn command_with_host_obj() { fn command_with_host_obj() {
let xml = get_xml("request/domain/create_with_host_obj.xml").unwrap();
let contacts = &[ let contacts = &[
DomainContact { DomainContact {
contact_type: "admin".into(), contact_type: "admin".into(),
@ -179,17 +171,11 @@ mod tests {
Some(contacts), Some(contacts),
); );
let serialized = assert_serialized("request/domain/create_with_host_obj.xml", &object);
<DomainCreate as Transaction<NoExtension>>::serialize_request(&object, None, CLTRID)
.unwrap();
assert_eq!(xml, serialized);
} }
#[test] #[test]
fn command_with_host_attr() { fn command_with_host_attr() {
let xml = get_xml("request/domain/create_with_host_attr.xml").unwrap();
let contacts = &[ let contacts = &[
DomainContact { DomainContact {
contact_type: "admin".into(), contact_type: "admin".into(),
@ -228,11 +214,7 @@ mod tests {
Some(contacts), Some(contacts),
); );
let serialized = assert_serialized("request/domain/create_with_host_attr.xml", &object);
<DomainCreate as Transaction<NoExtension>>::serialize_request(&object, None, CLTRID)
.unwrap();
assert_eq!(xml, serialized);
} }
#[test] #[test]

View File

@ -48,19 +48,12 @@ mod tests {
use crate::common::NoExtension; use crate::common::NoExtension;
use crate::request::Transaction; use crate::request::Transaction;
use crate::response::ResultCode; use crate::response::ResultCode;
use crate::tests::{get_xml, CLTRID, SUCCESS_MSG, SVTRID}; use crate::tests::{assert_serialized, get_xml, CLTRID, SUCCESS_MSG, SVTRID};
#[test] #[test]
fn command() { fn command() {
let xml = get_xml("request/domain/delete.xml").unwrap();
let object = DomainDelete::new("eppdev.com"); let object = DomainDelete::new("eppdev.com");
assert_serialized("request/domain/delete.xml", &object);
let serialized =
<DomainDelete as Transaction<NoExtension>>::serialize_request(&object, None, CLTRID)
.unwrap();
assert_eq!(xml, serialized);
} }
#[test] #[test]

View File

@ -136,20 +136,13 @@ mod tests {
use crate::common::NoExtension; use crate::common::NoExtension;
use crate::request::Transaction; use crate::request::Transaction;
use crate::response::ResultCode; use crate::response::ResultCode;
use crate::tests::{get_xml, CLTRID, SUCCESS_MSG, SVTRID}; use crate::tests::{assert_serialized, get_xml, CLTRID, SUCCESS_MSG, SVTRID};
use chrono::{TimeZone, Utc}; use chrono::{TimeZone, Utc};
#[test] #[test]
fn command() { fn command() {
let xml = get_xml("request/domain/info.xml").unwrap();
let object = DomainInfo::new("eppdev.com", Some("2fooBAR")); let object = DomainInfo::new("eppdev.com", Some("2fooBAR"));
assert_serialized("request/domain/info.xml", &object);
let serialized =
<DomainInfo as Transaction<NoExtension>>::serialize_request(&object, None, CLTRID)
.unwrap();
assert_eq!(xml, serialized);
} }
#[test] #[test]

View File

@ -81,22 +81,15 @@ mod tests {
use crate::common::NoExtension; use crate::common::NoExtension;
use crate::request::Transaction; use crate::request::Transaction;
use crate::response::ResultCode; use crate::response::ResultCode;
use crate::tests::{get_xml, CLTRID, SUCCESS_MSG, SVTRID}; use crate::tests::{assert_serialized, get_xml, CLTRID, SUCCESS_MSG, SVTRID};
use chrono::{NaiveDate, TimeZone, Utc}; use chrono::{NaiveDate, TimeZone, Utc};
#[test] #[test]
fn command() { fn command() {
let xml = get_xml("request/domain/renew.xml").unwrap();
let exp_date = NaiveDate::from_ymd(2022, 7, 23); let exp_date = NaiveDate::from_ymd(2022, 7, 23);
let object = DomainRenew::new("eppdev.com", exp_date, Period::years(1).unwrap()); let object = DomainRenew::new("eppdev.com", exp_date, Period::years(1).unwrap());
assert_serialized("request/domain/renew.xml", &object);
let serialized =
<DomainRenew as Transaction<NoExtension>>::serialize_request(&object, None, CLTRID)
.unwrap();
assert_eq!(xml, serialized);
} }
#[test] #[test]

View File

@ -139,72 +139,37 @@ mod tests {
use crate::common::NoExtension; use crate::common::NoExtension;
use crate::request::Transaction; use crate::request::Transaction;
use crate::response::ResultCode; use crate::response::ResultCode;
use crate::tests::{get_xml, CLTRID, SUCCESS_MSG, SVTRID}; use crate::tests::{assert_serialized, get_xml, CLTRID, SUCCESS_MSG, SVTRID};
#[test] #[test]
fn request_command() { fn request_command() {
let xml = get_xml("request/domain/transfer_request.xml").unwrap();
let object = let object =
DomainTransfer::new("testing.com", Some(Period::years(1).unwrap()), "epP4uthd#v"); DomainTransfer::new("testing.com", Some(Period::years(1).unwrap()), "epP4uthd#v");
assert_serialized("request/domain/transfer_request.xml", &object);
let serialized =
<DomainTransfer as Transaction<NoExtension>>::serialize_request(&object, None, CLTRID)
.unwrap();
assert_eq!(xml, serialized);
} }
#[test] #[test]
fn approve_command() { fn approve_command() {
let xml = get_xml("request/domain/transfer_approve.xml").unwrap();
let object = DomainTransfer::approve("testing.com"); let object = DomainTransfer::approve("testing.com");
assert_serialized("request/domain/transfer_approve.xml", &object);
let serialized =
<DomainTransfer as Transaction<NoExtension>>::serialize_request(&object, None, CLTRID)
.unwrap();
assert_eq!(xml, serialized);
} }
#[test] #[test]
fn reject_command() { fn reject_command() {
let xml = get_xml("request/domain/transfer_reject.xml").unwrap();
let object = DomainTransfer::reject("testing.com"); let object = DomainTransfer::reject("testing.com");
assert_serialized("request/domain/transfer_reject.xml", &object);
let serialized =
<DomainTransfer as Transaction<NoExtension>>::serialize_request(&object, None, CLTRID)
.unwrap();
assert_eq!(xml, serialized);
} }
#[test] #[test]
fn cancel_command() { fn cancel_command() {
let xml = get_xml("request/domain/transfer_cancel.xml").unwrap();
let object = DomainTransfer::cancel("testing.com"); let object = DomainTransfer::cancel("testing.com");
assert_serialized("request/domain/transfer_cancel.xml", &object);
let serialized =
<DomainTransfer as Transaction<NoExtension>>::serialize_request(&object, None, CLTRID)
.unwrap();
assert_eq!(xml, serialized);
} }
#[test] #[test]
fn query_command() { fn query_command() {
let xml = get_xml("request/domain/transfer_query.xml").unwrap();
let object = DomainTransfer::query("testing.com", "epP4uthd#v"); let object = DomainTransfer::query("testing.com", "epP4uthd#v");
assert_serialized("request/domain/transfer_query.xml", &object);
let serialized =
<DomainTransfer as Transaction<NoExtension>>::serialize_request(&object, None, CLTRID)
.unwrap();
assert_eq!(xml, serialized);
} }
#[test] #[test]

View File

@ -105,12 +105,10 @@ mod tests {
use crate::common::{NoExtension, ObjectStatus}; use crate::common::{NoExtension, ObjectStatus};
use crate::request::Transaction; use crate::request::Transaction;
use crate::response::ResultCode; use crate::response::ResultCode;
use crate::tests::{get_xml, CLTRID, SUCCESS_MSG, SVTRID}; use crate::tests::{assert_serialized, get_xml, CLTRID, SUCCESS_MSG, SVTRID};
#[test] #[test]
fn command() { fn command() {
let xml = get_xml("request/domain/update.xml").unwrap();
let mut object = DomainUpdate::new("eppdev.com"); let mut object = DomainUpdate::new("eppdev.com");
let statuses = &[ObjectStatus { let statuses = &[ObjectStatus {
@ -142,12 +140,7 @@ mod tests {
object.add(add); object.add(add);
object.remove(remove); object.remove(remove);
object.info(change_info); object.info(change_info);
assert_serialized("request/domain/update.xml", &object);
let serialized =
<DomainUpdate as Transaction<NoExtension>>::serialize_request(&object, None, CLTRID)
.unwrap();
assert_eq!(xml, serialized);
} }
#[test] #[test]

View File

@ -118,13 +118,10 @@ mod tests {
use super::{GMonthDay, Update}; use super::{GMonthDay, Update};
use crate::domain::update::{DomainChangeInfo, DomainUpdate}; use crate::domain::update::{DomainChangeInfo, DomainUpdate};
use crate::extensions::consolidate::UpdateWithNameStore; use crate::extensions::consolidate::UpdateWithNameStore;
use crate::request::Transaction; use crate::tests::assert_serialized;
use crate::tests::{get_xml, CLTRID};
#[test] #[test]
fn command() { fn command() {
let xml = get_xml("request/extensions/consolidate.xml").unwrap();
let exp = GMonthDay::new(5, 31, None).unwrap(); let exp = GMonthDay::new(5, 31, None).unwrap();
let consolidate_ext = Update::new(exp); let consolidate_ext = Update::new(exp);
@ -136,20 +133,14 @@ mod tests {
auth_info: None, auth_info: None,
}); });
let serialized = <DomainUpdate as Transaction<Update>>::serialize_request( assert_serialized(
&object, "request/extensions/consolidate.xml",
Some(&consolidate_ext), (&object, &consolidate_ext),
CLTRID, );
)
.unwrap();
assert_eq!(xml, serialized);
} }
#[test] #[test]
fn command_with_namestore() { fn command_with_namestore() {
let xml = get_xml("request/extensions/consolidate_namestore.xml").unwrap();
let exp = GMonthDay::new(5, 31, None).unwrap(); let exp = GMonthDay::new(5, 31, None).unwrap();
let consolidate_ext = UpdateWithNameStore::new(exp, "com"); let consolidate_ext = UpdateWithNameStore::new(exp, "com");
@ -161,13 +152,9 @@ mod tests {
auth_info: None, auth_info: None,
}); });
let serialized = <DomainUpdate as Transaction<UpdateWithNameStore>>::serialize_request( assert_serialized(
&object, "request/extensions/consolidate_namestore.xml",
Some(&consolidate_ext), (&object, &consolidate_ext),
CLTRID, );
)
.unwrap();
assert_eq!(xml, serialized);
} }
} }

View File

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

View File

@ -104,13 +104,10 @@ mod tests {
use super::{RgpRestoreReport, Update}; use super::{RgpRestoreReport, Update};
use crate::domain::update::{DomainChangeInfo, DomainUpdate}; use crate::domain::update::{DomainChangeInfo, DomainUpdate};
use crate::request::Transaction; use crate::tests::assert_serialized;
use crate::tests::{get_xml, CLTRID};
#[test] #[test]
fn command() { fn command() {
let xml = get_xml("request/extensions/rgp_restore_report.xml").unwrap();
let pre_data = let pre_data =
"Pre-delete registration data goes here. Both XML and free text are allowed."; "Pre-delete registration data goes here. Both XML and free text are allowed.";
let post_data = let post_data =
@ -142,14 +139,9 @@ mod tests {
auth_info: None, auth_info: None,
}); });
let serialized = assert_serialized(
<DomainUpdate as Transaction<Update<RgpRestoreReport>>>::serialize_request( "request/extensions/rgp_restore_report.xml",
&object, (&object, &domain_restore_report),
Some(&domain_restore_report), );
CLTRID,
)
.unwrap();
assert_eq!(xml, serialized);
} }
} }

View File

@ -72,12 +72,10 @@ mod tests {
use crate::domain::update::{DomainChangeInfo, DomainUpdate}; use crate::domain::update::{DomainChangeInfo, DomainUpdate};
use crate::request::Transaction; use crate::request::Transaction;
use crate::response::ResultCode; use crate::response::ResultCode;
use crate::tests::{get_xml, CLTRID, SUCCESS_MSG, SVTRID}; use crate::tests::{assert_serialized, get_xml, SUCCESS_MSG, SVTRID};
#[test] #[test]
fn request_command() { fn request_command() {
let xml = get_xml("request/extensions/rgp_restore_request.xml").unwrap();
let domain_restore_request = Update { let domain_restore_request = Update {
data: RgpRestoreRequest::default(), data: RgpRestoreRequest::default(),
}; };
@ -91,15 +89,10 @@ mod tests {
object.info(change_info); object.info(change_info);
let serialized = assert_serialized(
<DomainUpdate as Transaction<Update<RgpRestoreRequest>>>::serialize_request( "request/extensions/rgp_restore_request.xml",
&object, (&object, &domain_restore_request),
Some(&domain_restore_request), );
CLTRID,
)
.unwrap();
assert_eq!(xml, serialized);
} }
#[test] #[test]

View File

@ -60,21 +60,14 @@ mod tests {
use crate::common::NoExtension; use crate::common::NoExtension;
use crate::request::Transaction; use crate::request::Transaction;
use crate::response::ResultCode; use crate::response::ResultCode;
use crate::tests::{get_xml, CLTRID, SUCCESS_MSG, SVTRID}; use crate::tests::{assert_serialized, get_xml, CLTRID, SUCCESS_MSG, SVTRID};
#[test] #[test]
fn command() { fn command() {
let xml = get_xml("request/host/check.xml").unwrap();
let object = HostCheck { let object = HostCheck {
hosts: &["ns1.eppdev-1.com", "host1.eppdev-1.com"], hosts: &["ns1.eppdev-1.com", "host1.eppdev-1.com"],
}; };
assert_serialized("request/host/check.xml", &object);
let serialized =
<HostCheck as Transaction<NoExtension>>::serialize_request(&object, None, CLTRID)
.unwrap();
assert_eq!(xml, serialized);
} }
#[test] #[test]

View File

@ -80,24 +80,17 @@ mod tests {
use crate::common::NoExtension; use crate::common::NoExtension;
use crate::request::Transaction; use crate::request::Transaction;
use crate::response::ResultCode; use crate::response::ResultCode;
use crate::tests::{get_xml, CLTRID, SUCCESS_MSG, SVTRID}; use crate::tests::{assert_serialized, get_xml, CLTRID, SUCCESS_MSG, SVTRID};
#[test] #[test]
fn command() { fn command() {
let xml = get_xml("request/host/create.xml").unwrap();
let addresses = &[ let addresses = &[
IpAddr::from([29, 245, 122, 14]), IpAddr::from([29, 245, 122, 14]),
IpAddr::from([0x2404, 0x6800, 0x4001, 0x801, 0, 0, 0, 0x200e]), IpAddr::from([0x2404, 0x6800, 0x4001, 0x801, 0, 0, 0, 0x200e]),
]; ];
let object = HostCreate::new("host1.eppdev-1.com", Some(addresses)); let object = HostCreate::new("host1.eppdev-1.com", Some(addresses));
assert_serialized("request/host/create.xml", &object);
let serialized =
<HostCreate as Transaction<NoExtension>>::serialize_request(&object, None, CLTRID)
.unwrap();
assert_eq!(xml, serialized);
} }
#[test] #[test]

View File

@ -48,19 +48,12 @@ mod tests {
use crate::common::NoExtension; use crate::common::NoExtension;
use crate::request::Transaction; use crate::request::Transaction;
use crate::response::ResultCode; use crate::response::ResultCode;
use crate::tests::{get_xml, CLTRID, SUCCESS_MSG, SVTRID}; use crate::tests::{assert_serialized, get_xml, CLTRID, SUCCESS_MSG, SVTRID};
#[test] #[test]
fn command() { fn command() {
let xml = get_xml("request/host/delete.xml").unwrap();
let object = HostDelete::new("ns1.eppdev-1.com"); let object = HostDelete::new("ns1.eppdev-1.com");
assert_serialized("request/host/delete.xml", &object);
let serialized =
<HostDelete as Transaction<NoExtension>>::serialize_request(&object, None, CLTRID)
.unwrap();
assert_eq!(xml, serialized);
} }
#[test] #[test]

View File

@ -112,19 +112,12 @@ mod tests {
use crate::common::NoExtension; use crate::common::NoExtension;
use crate::request::Transaction; use crate::request::Transaction;
use crate::response::ResultCode; use crate::response::ResultCode;
use crate::tests::{get_xml, CLTRID, SUCCESS_MSG, SVTRID}; use crate::tests::{assert_serialized, get_xml, CLTRID, SUCCESS_MSG, SVTRID};
#[test] #[test]
fn command() { fn command() {
let xml = get_xml("request/host/info.xml").unwrap();
let object = HostInfo::new("ns1.eppdev-1.com"); let object = HostInfo::new("ns1.eppdev-1.com");
assert_serialized("request/host/info.xml", &object);
let serialized =
<HostInfo as Transaction<NoExtension>>::serialize_request(&object, None, CLTRID)
.unwrap();
assert_eq!(xml, serialized);
} }
#[test] #[test]

View File

@ -97,12 +97,10 @@ mod tests {
use crate::common::{NoExtension, ObjectStatus}; use crate::common::{NoExtension, ObjectStatus};
use crate::request::Transaction; use crate::request::Transaction;
use crate::response::ResultCode; use crate::response::ResultCode;
use crate::tests::{get_xml, CLTRID, SUCCESS_MSG, SVTRID}; use crate::tests::{assert_serialized, get_xml, CLTRID, SUCCESS_MSG, SVTRID};
#[test] #[test]
fn command() { fn command() {
let xml = get_xml("request/host/update.xml").unwrap();
let addr = &[IpAddr::from([ let addr = &[IpAddr::from([
0x2404, 0x6800, 0x4001, 0x801, 0, 0, 0, 0x200e, 0x2404, 0x6800, 0x4001, 0x801, 0, 0, 0, 0x200e,
])]; ])];
@ -129,11 +127,7 @@ mod tests {
name: "host2.eppdev-1.com".into(), name: "host2.eppdev-1.com".into(),
}); });
let serialized = assert_serialized("request/host/update.xml", &object);
<HostUpdate as Transaction<NoExtension>>::serialize_request(&object, None, CLTRID)
.unwrap();
assert_eq!(xml, serialized);
} }
#[test] #[test]

View File

@ -69,17 +69,13 @@ mod tests {
use super::Login; use super::Login;
use crate::request::Transaction; use crate::request::Transaction;
use crate::response::ResultCode; use crate::response::ResultCode;
use crate::tests::{get_xml, CLTRID, SUCCESS_MSG, SVTRID}; use crate::tests::{assert_serialized, get_xml, CLTRID, SUCCESS_MSG, SVTRID};
#[test] #[test]
fn command() { fn command() {
let ext_uris = Some(&["http://schema.ispapi.net/epp/xml/keyvalue-1.0"][..]); let ext_uris = Some(&["http://schema.ispapi.net/epp/xml/keyvalue-1.0"][..]);
let xml = get_xml("request/login.xml").unwrap();
let object = Login::new("username", "password", ext_uris); let object = Login::new("username", "password", ext_uris);
let serialized = object.serialize_request(None, CLTRID).unwrap(); assert_serialized("request/login.xml", &object);
assert_eq!(xml, serialized);
} }
#[test] #[test]

View File

@ -23,15 +23,12 @@ mod tests {
use super::Logout; use super::Logout;
use crate::request::Transaction; use crate::request::Transaction;
use crate::response::ResultCode; use crate::response::ResultCode;
use crate::tests::{get_xml, CLTRID, SVTRID}; use crate::tests::{assert_serialized, get_xml, CLTRID, SVTRID};
#[test] #[test]
fn command() { fn command() {
let xml = get_xml("request/logout.xml").unwrap();
let object = Logout; let object = Logout;
let serialized = object.serialize_request(None, CLTRID).unwrap(); assert_serialized("request/logout.xml", &object);
assert_eq!(xml, serialized);
} }
#[test] #[test]

View File

@ -36,17 +36,12 @@ mod tests {
use super::MessageAck; use super::MessageAck;
use crate::request::Transaction; use crate::request::Transaction;
use crate::response::ResultCode; use crate::response::ResultCode;
use crate::tests::{get_xml, CLTRID, SUCCESS_MSG, SVTRID}; use crate::tests::{assert_serialized, get_xml, SUCCESS_MSG, SVTRID};
#[test] #[test]
fn command() { fn command() {
let xml = get_xml("request/message/ack.xml").unwrap();
let object = MessageAck::new(12345); let object = MessageAck::new(12345);
assert_serialized("request/message/ack.xml", &object);
let serialized = object.serialize_request(None, CLTRID).unwrap();
assert_eq!(xml, serialized);
} }
#[test] #[test]

View File

@ -54,20 +54,15 @@ mod tests {
use crate::message::poll::MessageData; use crate::message::poll::MessageData;
use crate::request::Transaction; use crate::request::Transaction;
use crate::response::ResultCode; use crate::response::ResultCode;
use crate::tests::{get_xml, CLTRID, SVTRID}; use crate::tests::{assert_serialized, get_xml, CLTRID, SVTRID};
use chrono::{TimeZone, Utc}; use chrono::{TimeZone, Utc};
use std::net::IpAddr; use std::net::IpAddr;
#[test] #[test]
fn command() { fn command() {
let xml = get_xml("request/message/poll.xml").unwrap();
let object = MessagePoll::default(); let object = MessagePoll::default();
assert_serialized("request/message/poll.xml", &object);
let serialized = object.serialize_request(None, CLTRID).unwrap();
assert_eq!(xml, serialized);
} }
#[test] #[test]

View File

@ -15,17 +15,17 @@ pub const EPP_LANG: &str = "en";
/// Trait to set correct value for xml tags when tags are being generated from generic types /// Trait to set correct value for xml tags when tags are being generated from generic types
pub trait Transaction<Ext: Extension>: Command + Sized { pub trait Transaction<Ext: Extension>: Command + Sized {
fn serialize_request( fn command<'c, 'e: 'c, 'i: 'c>(
&self, &'c self,
extension: Option<&Ext>, extension: Option<&'e Ext>,
client_tr_id: &str, client_tr_id: &'i str,
) -> Result<String, Error> { ) -> CommandDocument<'c, Self, Ext> {
<CommandDocument<Self, Ext> as EppXml>::serialize(&CommandDocument::new(CommandWrapper { CommandDocument::new(CommandWrapper {
command: Self::COMMAND, command: Self::COMMAND,
data: self, data: self,
extension, extension,
client_tr_id: client_tr_id.into(), client_tr_id: client_tr_id.into(),
})) })
} }
fn deserialize_response( fn deserialize_response(

View File

@ -1,8 +1,15 @@
//! Module for automated tests //! Module for automated tests
use regex::Regex;
use std::{error::Error, fs::File, io::Read}; use std::{error::Error, fs::File, io::Read};
use regex::Regex;
use crate::{
client::RequestData,
request::{Command, Extension, Transaction},
xml::EppXml,
};
pub(crate) const RESOURCES_DIR: &str = "./tests/resources"; pub(crate) const RESOURCES_DIR: &str = "./tests/resources";
pub(crate) const CLTRID: &str = "cltrid:1626454866"; pub(crate) const CLTRID: &str = "cltrid:1626454866";
pub(crate) const SVTRID: &str = "RO-6879-1627224678242975"; pub(crate) const SVTRID: &str = "RO-6879-1627224678242975";
@ -27,3 +34,17 @@ pub(crate) fn get_xml(path: &str) -> Result<String, Box<dyn Error>> {
} }
Ok(buf) Ok(buf)
} }
pub(crate) fn assert_serialized<'c, 'e, Cmd, Ext>(
path: &str,
req: impl Into<RequestData<'c, 'e, Cmd, Ext>>,
) where
Cmd: Transaction<Ext> + Command + 'c,
Ext: Extension + 'e,
{
let expected = get_xml(path).unwrap();
let req = req.into();
let document = <Cmd as Transaction<Ext>>::command(req.command, req.extension, CLTRID);
let actual = EppXml::serialize(&document).unwrap();
assert_eq!(expected, actual);
}