From 99f90f3c080eae35800338d1615e6bd82a16ac33 Mon Sep 17 00:00:00 2001 From: Nicholas Rempel Date: Tue, 7 Dec 2021 10:19:05 -0800 Subject: [PATCH] Complete Transaction impl coverage for NameStore extension --- epp-client/src/client.rs | 20 +++++----- epp-client/src/contact/check.rs | 8 +++- epp-client/src/contact/create.rs | 10 +++-- epp-client/src/contact/delete.rs | 9 ++++- epp-client/src/contact/info.rs | 8 +++- epp-client/src/contact/update.rs | 10 +++-- epp-client/src/domain/check.rs | 2 +- epp-client/src/domain/create.rs | 19 +++++++--- epp-client/src/domain/delete.rs | 8 +++- epp-client/src/domain/info.rs | 2 +- epp-client/src/domain/renew.rs | 8 +++- epp-client/src/domain/transfer.rs | 41 ++++++++++++++++----- epp-client/src/domain/update.rs | 2 +- epp-client/src/extensions/consolidate.rs | 4 +- epp-client/src/extensions/namestore.rs | 47 +++++++++++++++++++++--- epp-client/src/extensions/rgp/report.rs | 4 +- epp-client/src/extensions/rgp/request.rs | 4 +- epp-client/src/host/check.rs | 8 +++- epp-client/src/host/create.rs | 9 +++-- epp-client/src/host/delete.rs | 8 +++- epp-client/src/host/info.rs | 8 +++- epp-client/src/host/update.rs | 9 +++-- epp-client/src/lib.rs | 6 +-- epp-client/src/request.rs | 24 ++++++------ 24 files changed, 196 insertions(+), 82 deletions(-) diff --git a/epp-client/src/client.rs b/epp-client/src/client.rs index c5f654c..648dd26 100644 --- a/epp-client/src/client.rs +++ b/epp-client/src/client.rs @@ -37,7 +37,7 @@ //! //! // Execute an EPP Command against the registry with distinct request and response objects //! let domain_check = DomainCheck::new(vec!["eppdev.com", "eppdev.net"]); -//! let response = client.transact(domain_check, "transaction-id").await.unwrap(); +//! let response = client.transact(&domain_check, "transaction-id").await.unwrap(); //! println!("{:?}", response); //! //! } @@ -88,9 +88,9 @@ impl EppClient { Ok(GreetingDocument::deserialize(&response)?.data) } - pub async fn transact( + pub async fn transact<'a, C: 'a, E: 'a>( &mut self, - data: impl Into>, + data: impl Into> + 'a, id: &str, ) -> Result, error::Error> where @@ -122,13 +122,13 @@ impl EppClient { } } -pub struct RequestData { - command: C, - extension: Option, +pub struct RequestData<'a, C, E> { + command: &'a C, + extension: Option<&'a E>, } -impl From for RequestData { - fn from(command: C) -> Self { +impl<'a, C: Command> From<&'a C> for RequestData<'a, C, NoExtension> { + fn from(command: &'a C) -> Self { Self { command, extension: None, @@ -136,8 +136,8 @@ impl From for RequestData { } } -impl From<(C, E)> for RequestData { - fn from((command, extension): (C, E)) -> Self { +impl<'a, C: Command, E: Extension> From<(&'a C, &'a E)> for RequestData<'a, C, E> { + fn from((command, extension): (&'a C, &'a E)) -> Self { Self { command, extension: Some(extension), diff --git a/epp-client/src/contact/check.rs b/epp-client/src/contact/check.rs index 666466f..d61b483 100644 --- a/epp-client/src/contact/check.rs +++ b/epp-client/src/contact/check.rs @@ -92,6 +92,7 @@ pub struct ContactCheckResponse { #[cfg(test)] mod tests { use super::ContactCheck; + use crate::common::NoExtension; use crate::request::Transaction; use crate::tests::{get_xml, CLTRID, SUCCESS_MSG, SVTRID}; @@ -99,7 +100,9 @@ mod tests { 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(); + let serialized = + >::serialize_request(&object, None, CLTRID) + .unwrap(); assert_eq!(xml, serialized); } @@ -107,7 +110,8 @@ mod tests { #[test] fn response() { let xml = get_xml("response/contact/check.xml").unwrap(); - let object = ContactCheck::deserialize_response(xml.as_str()).unwrap(); + let object = + >::deserialize_response(xml.as_str()).unwrap(); let results = object.res_data().unwrap(); diff --git a/epp-client/src/contact/create.rs b/epp-client/src/contact/create.rs index 75dda5b..743c241 100644 --- a/epp-client/src/contact/create.rs +++ b/epp-client/src/contact/create.rs @@ -101,7 +101,7 @@ pub struct ContactCreateResponse { #[cfg(test)] mod tests { use super::{ContactCreate, Phone, PostalInfo}; - use crate::common::Address; + use crate::common::{Address, NoExtension}; use crate::request::Transaction; use crate::tests::{get_xml, CLTRID, SUCCESS_MSG, SVTRID}; @@ -126,7 +126,9 @@ mod tests { ); object.set_fax(fax); - let serialized = object.serialize_request(None, CLTRID).unwrap(); + let serialized = + >::serialize_request(&object, None, CLTRID) + .unwrap(); assert_eq!(xml, serialized); } @@ -134,7 +136,9 @@ mod tests { #[test] fn response() { let xml = get_xml("response/contact/create.xml").unwrap(); - let object = ContactCreate::deserialize_response(xml.as_str()).unwrap(); + let object = + >::deserialize_response(xml.as_str()) + .unwrap(); let results = object.res_data().unwrap(); diff --git a/epp-client/src/contact/delete.rs b/epp-client/src/contact/delete.rs index 798b15c..731d093 100644 --- a/epp-client/src/contact/delete.rs +++ b/epp-client/src/contact/delete.rs @@ -45,6 +45,7 @@ impl ContactDelete { #[cfg(test)] mod tests { use super::ContactDelete; + use crate::common::NoExtension; use crate::request::Transaction; use crate::tests::{get_xml, CLTRID, SUCCESS_MSG, SVTRID}; @@ -54,7 +55,9 @@ mod tests { let object = ContactDelete::new("eppdev-contact-3"); - let serialized = object.serialize_request(None, CLTRID).unwrap(); + let serialized = + >::serialize_request(&object, None, CLTRID) + .unwrap(); assert_eq!(xml, serialized); } @@ -62,7 +65,9 @@ mod tests { #[test] fn response() { let xml = get_xml("response/contact/delete.xml").unwrap(); - let object = ContactDelete::deserialize_response(xml.as_str()).unwrap(); + let object = + >::deserialize_response(xml.as_str()) + .unwrap(); assert_eq!(object.result.code, 1000); assert_eq!(object.result.message, SUCCESS_MSG.into()); diff --git a/epp-client/src/contact/info.rs b/epp-client/src/contact/info.rs index b1b9b0e..a83c28d 100644 --- a/epp-client/src/contact/info.rs +++ b/epp-client/src/contact/info.rs @@ -103,6 +103,7 @@ pub struct ContactInfoResponse { #[cfg(test)] mod tests { use super::ContactInfo; + use crate::common::NoExtension; use crate::request::Transaction; use crate::tests::{get_xml, CLTRID, SUCCESS_MSG, SVTRID}; @@ -112,7 +113,9 @@ mod tests { let object = ContactInfo::new("eppdev-contact-3", "eppdev-387323"); - let serialized = object.serialize_request(None, CLTRID).unwrap(); + let serialized = + >::serialize_request(&object, None, CLTRID) + .unwrap(); assert_eq!(xml, serialized); } @@ -120,7 +123,8 @@ mod tests { #[test] fn response() { let xml = get_xml("response/contact/info.xml").unwrap(); - let object = ContactInfo::deserialize_response(xml.as_str()).unwrap(); + let object = + >::deserialize_response(xml.as_str()).unwrap(); let result = object.res_data().unwrap(); let fax = result.info_data.fax.as_ref().unwrap(); diff --git a/epp-client/src/contact/update.rs b/epp-client/src/contact/update.rs index 519750a..b9df755 100644 --- a/epp-client/src/contact/update.rs +++ b/epp-client/src/contact/update.rs @@ -108,7 +108,7 @@ pub struct ContactUpdate { #[cfg(test)] mod tests { use super::ContactUpdate; - use crate::common::{Address, ContactStatus, Phone, PostalInfo}; + use crate::common::{Address, ContactStatus, NoExtension, Phone, PostalInfo}; use crate::request::Transaction; use crate::tests::{get_xml, CLTRID, SUCCESS_MSG, SVTRID}; @@ -133,7 +133,9 @@ mod tests { }]; object.remove(remove_statuses); - let serialized = object.serialize_request(None, CLTRID).unwrap(); + let serialized = + >::serialize_request(&object, None, CLTRID) + .unwrap(); assert_eq!(xml, serialized); } @@ -141,7 +143,9 @@ mod tests { #[test] fn contact_update() { let xml = get_xml("response/contact/update.xml").unwrap(); - let object = ContactUpdate::deserialize_response(xml.as_str()).unwrap(); + let object = + >::deserialize_response(xml.as_str()) + .unwrap(); assert_eq!(object.result.code, 1000); assert_eq!(object.result.message, SUCCESS_MSG.into()); diff --git a/epp-client/src/domain/check.rs b/epp-client/src/domain/check.rs index c7e5f26..79e7485 100644 --- a/epp-client/src/domain/check.rs +++ b/epp-client/src/domain/check.rs @@ -100,7 +100,7 @@ mod tests { let object = DomainCheck::new(vec!["eppdev.com", "eppdev.net"]); let serialized = - >::serialize_request(object, None, CLTRID) + >::serialize_request(&object, None, CLTRID) .unwrap(); assert_eq!(xml, serialized); diff --git a/epp-client/src/domain/create.rs b/epp-client/src/domain/create.rs index 8d446b6..186bf90 100644 --- a/epp-client/src/domain/create.rs +++ b/epp-client/src/domain/create.rs @@ -103,7 +103,9 @@ pub struct DomainCreateResponse { #[cfg(test)] mod tests { use super::DomainCreate; - use crate::common::{DomainContact, HostAddr, HostAttr, HostAttrList, HostList, HostObjList}; + use crate::common::{ + DomainContact, HostAddr, HostAttr, HostAttrList, HostList, HostObjList, NoExtension, + }; use crate::request::Transaction; use crate::tests::{get_xml, CLTRID, SUCCESS_MSG, SVTRID}; @@ -135,7 +137,9 @@ mod tests { Some(contacts), ); - let serialized = object.serialize_request(None, CLTRID).unwrap(); + let serialized = + >::serialize_request(&object, None, CLTRID) + .unwrap(); assert_eq!(xml, serialized); } @@ -172,7 +176,9 @@ mod tests { Some(contacts), ); - let serialized = object.serialize_request(None, CLTRID).unwrap(); + let serialized = + >::serialize_request(&object, None, CLTRID) + .unwrap(); assert_eq!(xml, serialized); } @@ -221,7 +227,9 @@ mod tests { Some(contacts), ); - let serialized = object.serialize_request(None, CLTRID).unwrap(); + let serialized = + >::serialize_request(&object, None, CLTRID) + .unwrap(); assert_eq!(xml, serialized); } @@ -229,7 +237,8 @@ mod tests { #[test] fn response() { let xml = get_xml("response/domain/create.xml").unwrap(); - let object = DomainCreate::deserialize_response(xml.as_str()).unwrap(); + let object = + >::deserialize_response(xml.as_str()).unwrap(); let result = object.res_data().unwrap(); diff --git a/epp-client/src/domain/delete.rs b/epp-client/src/domain/delete.rs index 42ec77f..965a882 100644 --- a/epp-client/src/domain/delete.rs +++ b/epp-client/src/domain/delete.rs @@ -45,6 +45,7 @@ pub struct DomainDelete { #[cfg(test)] mod tests { use super::DomainDelete; + use crate::common::NoExtension; use crate::request::Transaction; use crate::tests::{get_xml, CLTRID, SUCCESS_MSG, SVTRID}; @@ -54,7 +55,9 @@ mod tests { let object = DomainDelete::new("eppdev.com"); - let serialized = object.serialize_request(None, CLTRID).unwrap(); + let serialized = + >::serialize_request(&object, None, CLTRID) + .unwrap(); assert_eq!(xml, serialized); } @@ -62,7 +65,8 @@ mod tests { #[test] fn response() { let xml = get_xml("response/domain/delete.xml").unwrap(); - let object = DomainDelete::deserialize_response(xml.as_str()).unwrap(); + let object = + >::deserialize_response(xml.as_str()).unwrap(); assert_eq!(object.result.code, 1000); assert_eq!(object.result.message, SUCCESS_MSG.into()); diff --git a/epp-client/src/domain/info.rs b/epp-client/src/domain/info.rs index dc54792..edc403d 100644 --- a/epp-client/src/domain/info.rs +++ b/epp-client/src/domain/info.rs @@ -147,7 +147,7 @@ mod tests { let object = DomainInfo::new("eppdev.com", Some("2fooBAR")); let serialized = - >::serialize_request(object, None, CLTRID) + >::serialize_request(&object, None, CLTRID) .unwrap(); assert_eq!(xml, serialized); diff --git a/epp-client/src/domain/renew.rs b/epp-client/src/domain/renew.rs index 921e275..0f34531 100644 --- a/epp-client/src/domain/renew.rs +++ b/epp-client/src/domain/renew.rs @@ -77,6 +77,7 @@ pub struct DomainRenewResponse { #[cfg(test)] mod tests { use super::DomainRenew; + use crate::common::NoExtension; use crate::request::Transaction; use crate::tests::{get_xml, CLTRID, SUCCESS_MSG, SVTRID}; use chrono::NaiveDate; @@ -88,7 +89,9 @@ mod tests { 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(); + let serialized = + >::serialize_request(&object, None, CLTRID) + .unwrap(); assert_eq!(xml, serialized); } @@ -96,7 +99,8 @@ mod tests { #[test] fn response() { let xml = get_xml("response/domain/renew.xml").unwrap(); - let object = DomainRenew::deserialize_response(xml.as_str()).unwrap(); + let object = + >::deserialize_response(xml.as_str()).unwrap(); let result = object.res_data().unwrap(); diff --git a/epp-client/src/domain/transfer.rs b/epp-client/src/domain/transfer.rs index 39e4947..9276a7b 100644 --- a/epp-client/src/domain/transfer.rs +++ b/epp-client/src/domain/transfer.rs @@ -145,6 +145,7 @@ pub struct DomainTransferResponse { #[cfg(test)] mod tests { use super::DomainTransfer; + use crate::common::NoExtension; use crate::request::Transaction; use crate::tests::{get_xml, CLTRID, SUCCESS_MSG, SVTRID}; @@ -154,7 +155,9 @@ mod tests { let object = DomainTransfer::new("testing.com", Some(1), "epP4uthd#v"); - let serialized = object.serialize_request(None, CLTRID).unwrap(); + let serialized = + >::serialize_request(&object, None, CLTRID) + .unwrap(); assert_eq!(xml, serialized); } @@ -165,7 +168,9 @@ mod tests { let object = DomainTransfer::approve("testing.com"); - let serialized = object.serialize_request(None, CLTRID).unwrap(); + let serialized = + >::serialize_request(&object, None, CLTRID) + .unwrap(); assert_eq!(xml, serialized); } @@ -176,7 +181,9 @@ mod tests { let object = DomainTransfer::reject("testing.com"); - let serialized = object.serialize_request(None, CLTRID).unwrap(); + let serialized = + >::serialize_request(&object, None, CLTRID) + .unwrap(); assert_eq!(xml, serialized); } @@ -187,7 +194,9 @@ mod tests { let object = DomainTransfer::cancel("testing.com"); - let serialized = object.serialize_request(None, CLTRID).unwrap(); + let serialized = + >::serialize_request(&object, None, CLTRID) + .unwrap(); assert_eq!(xml, serialized); } @@ -198,7 +207,9 @@ mod tests { let object = DomainTransfer::query("testing.com", "epP4uthd#v"); - let serialized = object.serialize_request(None, CLTRID).unwrap(); + let serialized = + >::serialize_request(&object, None, CLTRID) + .unwrap(); assert_eq!(xml, serialized); } @@ -206,7 +217,9 @@ mod tests { #[test] fn request_response() { let xml = get_xml("response/domain/transfer_request.xml").unwrap(); - let object = DomainTransfer::deserialize_response(xml.as_str()).unwrap(); + let object = + >::deserialize_response(xml.as_str()) + .unwrap(); let result = object.res_data().unwrap(); @@ -235,7 +248,9 @@ mod tests { #[test] fn approve_response() { let xml = get_xml("response/domain/transfer_approve.xml").unwrap(); - let object = DomainTransfer::deserialize_response(xml.as_str()).unwrap(); + let object = + >::deserialize_response(xml.as_str()) + .unwrap(); assert_eq!(object.result.code, 1000); assert_eq!(object.result.message, SUCCESS_MSG.into()); @@ -246,7 +261,9 @@ mod tests { #[test] fn reject_response() { let xml = get_xml("response/domain/transfer_reject.xml").unwrap(); - let object = DomainTransfer::deserialize_response(xml.as_str()).unwrap(); + let object = + >::deserialize_response(xml.as_str()) + .unwrap(); assert_eq!(object.result.code, 1000); assert_eq!(object.result.message, SUCCESS_MSG.into()); @@ -257,7 +274,9 @@ mod tests { #[test] fn cancel_response() { let xml = get_xml("response/domain/transfer_cancel.xml").unwrap(); - let object = DomainTransfer::deserialize_response(xml.as_str()).unwrap(); + let object = + >::deserialize_response(xml.as_str()) + .unwrap(); assert_eq!(object.result.code, 1000); assert_eq!(object.result.message, SUCCESS_MSG.into()); @@ -268,7 +287,9 @@ mod tests { #[test] fn query_response() { let xml = get_xml("response/domain/transfer_query.xml").unwrap(); - let object = DomainTransfer::deserialize_response(xml.as_str()).unwrap(); + let object = + >::deserialize_response(xml.as_str()) + .unwrap(); let result = object.res_data().unwrap(); diff --git a/epp-client/src/domain/update.rs b/epp-client/src/domain/update.rs index b6195e6..719166f 100644 --- a/epp-client/src/domain/update.rs +++ b/epp-client/src/domain/update.rs @@ -140,7 +140,7 @@ mod tests { object.info(change_info); let serialized = - >::serialize_request(object, None, CLTRID) + >::serialize_request(&object, None, CLTRID) .unwrap(); assert_eq!(xml, serialized); diff --git a/epp-client/src/extensions/consolidate.rs b/epp-client/src/extensions/consolidate.rs index 9c9255d..a317492 100644 --- a/epp-client/src/extensions/consolidate.rs +++ b/epp-client/src/extensions/consolidate.rs @@ -110,8 +110,8 @@ mod tests { }); let serialized = >::serialize_request( - object, - Some(consolidate_ext), + &object, + Some(&consolidate_ext), CLTRID, ) .unwrap(); diff --git a/epp-client/src/extensions/namestore.rs b/epp-client/src/extensions/namestore.rs index d3e4ed7..3ca651c 100644 --- a/epp-client/src/extensions/namestore.rs +++ b/epp-client/src/extensions/namestore.rs @@ -2,13 +2,50 @@ use serde::{Deserialize, Serialize}; -use crate::common::StringValue; -use crate::domain::check::DomainCheck; -use crate::request::{Extension, Transaction}; +use crate::{ + common::StringValue, + contact::{ + check::ContactCheck, create::ContactCreate, delete::ContactDelete, info::ContactInfo, + update::ContactUpdate, + }, + domain::{ + check::DomainCheck, create::DomainCreate, delete::DomainDelete, info::DomainInfo, + renew::DomainRenew, transfer::DomainTransfer, update::DomainUpdate, + }, + host::{ + check::HostCheck, create::HostCreate, delete::HostDelete, info::HostInfo, + update::HostUpdate, + }, + request::{Extension, Transaction}, +}; pub const XMLNS: &str = "http://www.verisign-grs.com/epp/namestoreExt-1.1"; +// Contact + +impl Transaction for ContactCheck {} +impl Transaction for ContactCreate {} +impl Transaction for ContactDelete {} +impl Transaction for ContactInfo {} +impl Transaction for ContactUpdate {} + +// Domain + impl Transaction for DomainCheck {} +impl Transaction for DomainCreate {} +impl Transaction for DomainDelete {} +impl Transaction for DomainInfo {} +impl Transaction for DomainRenew {} +impl Transaction for DomainTransfer {} +impl Transaction for DomainUpdate {} + +// Host + +impl Transaction for HostCheck {} +impl Transaction for HostCreate {} +impl Transaction for HostDelete {} +impl Transaction for HostInfo {} +impl Transaction for HostUpdate {} impl NameStore { /// Create a new RGP restore report request @@ -60,8 +97,8 @@ mod tests { let object = DomainCheck::new(vec!["example1.com", "example2.com", "example3.com"]); let serialized = >::serialize_request( - object, - Some(namestore_ext), + &object, + Some(&namestore_ext), CLTRID, ) .unwrap(); diff --git a/epp-client/src/extensions/rgp/report.rs b/epp-client/src/extensions/rgp/report.rs index 0bf8493..3410152 100644 --- a/epp-client/src/extensions/rgp/report.rs +++ b/epp-client/src/extensions/rgp/report.rs @@ -144,8 +144,8 @@ mod tests { let serialized = >>::serialize_request( - object, - Some(domain_restore_report), + &object, + Some(&domain_restore_report), CLTRID, ) .unwrap(); diff --git a/epp-client/src/extensions/rgp/request.rs b/epp-client/src/extensions/rgp/request.rs index 06efe10..a0bf5d7 100644 --- a/epp-client/src/extensions/rgp/request.rs +++ b/epp-client/src/extensions/rgp/request.rs @@ -94,8 +94,8 @@ mod tests { let serialized = >>::serialize_request( - object, - Some(domain_restore_request), + &object, + Some(&domain_restore_request), CLTRID, ) .unwrap(); diff --git a/epp-client/src/host/check.rs b/epp-client/src/host/check.rs index c9481d9..dc79c08 100644 --- a/epp-client/src/host/check.rs +++ b/epp-client/src/host/check.rs @@ -90,6 +90,7 @@ pub struct HostCheckResponse { #[cfg(test)] mod tests { use super::HostCheck; + use crate::common::NoExtension; use crate::request::Transaction; use crate::tests::{get_xml, CLTRID, SUCCESS_MSG, SVTRID}; @@ -99,7 +100,9 @@ mod tests { let object = HostCheck::new(&["ns1.eppdev-1.com", "host1.eppdev-1.com"]); - let serialized = object.serialize_request(None, CLTRID).unwrap(); + let serialized = + >::serialize_request(&object, None, CLTRID) + .unwrap(); assert_eq!(xml, serialized); } @@ -107,7 +110,8 @@ mod tests { #[test] fn response() { let xml = get_xml("response/host/check.xml").unwrap(); - let object = HostCheck::deserialize_response(xml.as_str()).unwrap(); + let object = + >::deserialize_response(xml.as_str()).unwrap(); let result = object.res_data().unwrap(); diff --git a/epp-client/src/host/create.rs b/epp-client/src/host/create.rs index 6f9f00f..fe0c4d5 100644 --- a/epp-client/src/host/create.rs +++ b/epp-client/src/host/create.rs @@ -71,7 +71,7 @@ pub struct HostCreateResponse { #[cfg(test)] mod tests { use super::HostCreate; - use crate::common::HostAddr; + use crate::common::{HostAddr, NoExtension}; use crate::request::Transaction; use crate::tests::{get_xml, CLTRID, SUCCESS_MSG, SVTRID}; @@ -86,7 +86,9 @@ mod tests { let object = HostCreate::new("host1.eppdev-1.com", addresses); - let serialized = object.serialize_request(None, CLTRID).unwrap(); + let serialized = + >::serialize_request(&object, None, CLTRID) + .unwrap(); assert_eq!(xml, serialized); } @@ -94,7 +96,8 @@ mod tests { #[test] fn response() { let xml = get_xml("response/host/create.xml").unwrap(); - let object = HostCreate::deserialize_response(xml.as_str()).unwrap(); + let object = + >::deserialize_response(xml.as_str()).unwrap(); let result = object.res_data().unwrap(); diff --git a/epp-client/src/host/delete.rs b/epp-client/src/host/delete.rs index 374cb8c..cf7d0fe 100644 --- a/epp-client/src/host/delete.rs +++ b/epp-client/src/host/delete.rs @@ -45,6 +45,7 @@ pub struct HostDelete { #[cfg(test)] mod tests { use super::HostDelete; + use crate::common::NoExtension; use crate::request::Transaction; use crate::tests::{get_xml, CLTRID, SUCCESS_MSG, SVTRID}; @@ -54,7 +55,9 @@ mod tests { let object = HostDelete::new("ns1.eppdev-1.com"); - let serialized = object.serialize_request(None, CLTRID).unwrap(); + let serialized = + >::serialize_request(&object, None, CLTRID) + .unwrap(); assert_eq!(xml, serialized); } @@ -62,7 +65,8 @@ mod tests { #[test] fn response() { let xml = get_xml("response/host/delete.xml").unwrap(); - let object = HostDelete::deserialize_response(xml.as_str()).unwrap(); + let object = + >::deserialize_response(xml.as_str()).unwrap(); assert_eq!(object.result.code, 1000); assert_eq!(object.result.message, SUCCESS_MSG.into()); diff --git a/epp-client/src/host/info.rs b/epp-client/src/host/info.rs index e747774..be38072 100644 --- a/epp-client/src/host/info.rs +++ b/epp-client/src/host/info.rs @@ -90,6 +90,7 @@ pub struct HostInfoResponse { #[cfg(test)] mod tests { use super::HostInfo; + use crate::common::NoExtension; use crate::request::Transaction; use crate::tests::{get_xml, CLTRID, SUCCESS_MSG, SVTRID}; @@ -99,7 +100,9 @@ mod tests { let object = HostInfo::new("ns1.eppdev-1.com"); - let serialized = object.serialize_request(None, CLTRID).unwrap(); + let serialized = + >::serialize_request(&object, None, CLTRID) + .unwrap(); assert_eq!(xml, serialized); } @@ -107,7 +110,8 @@ mod tests { #[test] fn response() { let xml = get_xml("response/host/info.xml").unwrap(); - let object = HostInfo::deserialize_response(xml.as_str()).unwrap(); + let object = + >::deserialize_response(xml.as_str()).unwrap(); let result = object.res_data().unwrap(); diff --git a/epp-client/src/host/update.rs b/epp-client/src/host/update.rs index 8fafac6..87ca5b9 100644 --- a/epp-client/src/host/update.rs +++ b/epp-client/src/host/update.rs @@ -91,7 +91,7 @@ pub struct HostUpdate { #[cfg(test)] mod tests { use super::{HostAddRemove, HostChangeInfo, HostUpdate}; - use crate::common::{HostAddr, HostStatus}; + use crate::common::{HostAddr, HostStatus, NoExtension}; use crate::request::Transaction; use crate::tests::{get_xml, CLTRID, SUCCESS_MSG, SVTRID}; @@ -121,7 +121,9 @@ mod tests { name: "host2.eppdev-1.com".into(), }); - let serialized = object.serialize_request(None, CLTRID).unwrap(); + let serialized = + >::serialize_request(&object, None, CLTRID) + .unwrap(); assert_eq!(xml, serialized); } @@ -129,7 +131,8 @@ mod tests { #[test] fn response() { let xml = get_xml("response/host/update.xml").unwrap(); - let object = HostUpdate::deserialize_response(xml.as_str()).unwrap(); + let object = + >::deserialize_response(xml.as_str()).unwrap(); assert_eq!(object.result.code, 1000); assert_eq!(object.result.message, SUCCESS_MSG.into()); diff --git a/epp-client/src/lib.rs b/epp-client/src/lib.rs index 971d8e0..a2f658c 100644 --- a/epp-client/src/lib.rs +++ b/epp-client/src/lib.rs @@ -70,7 +70,7 @@ //! }; //! //! let login = Login::new("username", "password", None); -//! client.transact(login, "transaction-id").await.unwrap(); +//! client.transact(&login, "transaction-id").await.unwrap(); //! //! // Make a domain check call, which returns an object of type EppDomainCheckResponse //! // that contains the result of the call @@ -78,7 +78,7 @@ //! vec!["eppdev.com", "eppdev.net"], //! ); //! -//! let response = client.transact(domain_check, "transaction-id").await.unwrap(); +//! let response = client.transact(&domain_check, "transaction-id").await.unwrap(); //! //! // print the availability results //! response.res_data.unwrap().check_data.domain_list @@ -86,7 +86,7 @@ //! .for_each(|chk| println!("Domain: {}, Available: {}", chk.domain.name, chk.domain.available)); //! //! // Close the connection -//! client.transact(Logout, "transaction-id").await.unwrap(); +//! client.transact(&Logout, "transaction-id").await.unwrap(); //! } //! ``` //! diff --git a/epp-client/src/request.rs b/epp-client/src/request.rs index 84241ab..eaa3dbe 100644 --- a/epp-client/src/request.rs +++ b/epp-client/src/request.rs @@ -15,8 +15,8 @@ pub const EPP_LANG: &str = "en"; /// Trait to set correct value for xml tags when tags are being generated from generic types pub trait Transaction: Command + Sized { fn serialize_request( - self, - extension: Option, + &self, + extension: Option<&Ext>, client_tr_id: &str, ) -> Result> { as EppXml>::serialize(&CommandDocument::new(CommandWrapper { @@ -54,23 +54,23 @@ pub trait Extension: Serialize + Debug { #[derive(Debug, PartialEq)] /// Type corresponding to the <command> tag in an EPP XML request /// with an <extension> tag -pub struct CommandWrapper { +pub struct CommandWrapper<'a, D, E> { pub command: &'static str, /// The instance that will be used to populate the <command> tag - pub data: D, + pub data: &'a D, /// The client TRID - pub extension: Option, + pub extension: Option<&'a E>, pub client_tr_id: StringValue, } -impl Serialize for CommandWrapper { +impl<'a, D: Serialize, E: Serialize> Serialize for CommandWrapper<'a, D, E> { /// Serializes the generic type T to the proper XML tag (set by the `#[element_name(name = )]` attribute) for the request fn serialize(&self, serializer: S) -> Result where S: Serializer, { let mut state = serializer.serialize_struct("command", 3)?; - state.serialize_field(self.command, &self.data)?; + state.serialize_field(self.command, self.data)?; state.serialize_field("extension", &self.extension)?; state.serialize_field("clTRID", &self.client_tr_id)?; state.end() @@ -79,13 +79,13 @@ impl Serialize for CommandWrapper { #[derive(Debug, PartialEq, Serialize)] #[serde(rename = "epp")] -pub struct CommandDocument { +pub struct CommandDocument<'a, D, E> { xmlns: &'static str, - command: CommandWrapper, + command: CommandWrapper<'a, D, E>, } -impl CommandDocument { - pub fn new(command: CommandWrapper) -> Self { +impl<'a, D, E> CommandDocument<'a, D, E> { + pub fn new(command: CommandWrapper<'a, D, E>) -> Self { Self { xmlns: EPP_XMLNS, command, @@ -93,4 +93,4 @@ impl CommandDocument { } } -impl EppXml for CommandDocument {} +impl<'a, D: Serialize, E: Serialize> EppXml for CommandDocument<'a, D, E> {}