From cf44a81991411b9f8c7925aab587cd51411cf453 Mon Sep 17 00:00:00 2001 From: Dirkjan Ochtman Date: Tue, 7 Dec 2021 10:04:57 +0100 Subject: [PATCH] Distribute deserialization tests over command modules --- epp-client/src/contact/check.rs | 33 +- epp-client/src/contact/create.rs | 27 +- epp-client/src/contact/delete.rs | 18 + epp-client/src/contact/info.rs | 65 +++ epp-client/src/contact/update.rs | 18 + epp-client/src/domain/check.rs | 32 ++ epp-client/src/domain/create.rs | 29 + epp-client/src/domain/delete.rs | 18 + epp-client/src/domain/info.rs | 72 +++ epp-client/src/domain/renew.rs | 25 + epp-client/src/domain/transfer.rs | 95 ++++ epp-client/src/domain/update.rs | 20 + epp-client/src/extensions/namestore.rs | 20 + epp-client/src/extensions/rgp/request.rs | 40 ++ epp-client/src/hello.rs | 38 ++ epp-client/src/host/check.rs | 30 + epp-client/src/host/create.rs | 25 + epp-client/src/host/delete.rs | 18 + epp-client/src/host/info.rs | 50 ++ epp-client/src/host/update.rs | 18 + epp-client/src/login.rs | 18 + epp-client/src/logout.rs | 21 + epp-client/src/message/ack.rs | 21 + epp-client/src/message/poll.rs | 47 ++ epp-client/src/response.rs | 22 + epp-client/src/tests/de.rs | 674 ----------------------- epp-client/src/tests/mod.rs | 9 +- 27 files changed, 822 insertions(+), 681 deletions(-) delete mode 100644 epp-client/src/tests/de.rs diff --git a/epp-client/src/contact/check.rs b/epp-client/src/contact/check.rs index 8cfa3e6..bfbee9f 100644 --- a/epp-client/src/contact/check.rs +++ b/epp-client/src/contact/check.rs @@ -1,10 +1,9 @@ use std::fmt::Debug; /// Types for EPP contact check request - use super::XMLNS; use crate::common::{NoExtension, StringValue}; -use crate::request::{Transaction, Command}; +use crate::request::{Command, Transaction}; use serde::{Deserialize, Serialize}; impl Transaction for ContactCheck {} @@ -89,3 +88,33 @@ pub struct ContactCheckResponse { #[serde(rename = "chkData")] pub check_data: ContactCheckResponseData, } + +#[cfg(test)] +mod tests { + use super::ContactCheck; + use crate::request::Transaction; + use crate::tests::{get_xml, CLTRID, SUCCESS_MSG, SVTRID}; + + #[test] + fn contact_check() { + let xml = get_xml("response/contact/check.xml").unwrap(); + let object = ContactCheck::deserialize_response(xml.as_str()).unwrap(); + + let results = object.res_data().unwrap(); + + assert_eq!(object.result.code, 1000); + assert_eq!(object.result.message, SUCCESS_MSG.into()); + assert_eq!( + results.check_data.contact_list[0].contact.id, + "eppdev-contact-1".into() + ); + assert_eq!(results.check_data.contact_list[0].contact.available, 0); + assert_eq!( + results.check_data.contact_list[1].contact.id, + "eppdev-contact-2".into() + ); + assert_eq!(results.check_data.contact_list[1].contact.available, 1); + assert_eq!(object.tr_ids.client_tr_id.unwrap(), CLTRID.into()); + assert_eq!(object.tr_ids.server_tr_id, SVTRID.into()); + } +} diff --git a/epp-client/src/contact/create.rs b/epp-client/src/contact/create.rs index 34d0a96..dbc2b64 100644 --- a/epp-client/src/contact/create.rs +++ b/epp-client/src/contact/create.rs @@ -2,7 +2,7 @@ use super::XMLNS; use crate::common::{ContactAuthInfo, NoExtension, Phone, PostalInfo, StringValue}; -use crate::request::{Transaction, Command}; +use crate::request::{Command, Transaction}; use serde::{Deserialize, Serialize}; impl Transaction for ContactCreate {} @@ -97,3 +97,28 @@ pub struct ContactCreateResponse { #[serde(rename = "creData")] pub create_data: ContactCreateData, } + +#[cfg(test)] +mod tests { + use super::ContactCreate; + use crate::request::Transaction; + use crate::tests::{get_xml, CLTRID, SUCCESS_MSG, SVTRID}; + + #[test] + fn contact_create() { + let xml = get_xml("response/contact/create.xml").unwrap(); + let object = ContactCreate::deserialize_response(xml.as_str()).unwrap(); + + let results = object.res_data().unwrap(); + + assert_eq!(object.result.code, 1000); + assert_eq!(object.result.message, SUCCESS_MSG.into()); + assert_eq!(results.create_data.id, "eppdev-contact-4".into()); + assert_eq!( + results.create_data.created_at, + "2021-07-25T16:05:32.0Z".into() + ); + assert_eq!(object.tr_ids.client_tr_id.unwrap(), CLTRID.into()); + assert_eq!(object.tr_ids.server_tr_id, SVTRID.into()); + } +} diff --git a/epp-client/src/contact/delete.rs b/epp-client/src/contact/delete.rs index b1a2e2f..929d580 100644 --- a/epp-client/src/contact/delete.rs +++ b/epp-client/src/contact/delete.rs @@ -41,3 +41,21 @@ impl ContactDelete { } } } + +#[cfg(test)] +mod tests { + use super::ContactDelete; + use crate::request::Transaction; + use crate::tests::{get_xml, CLTRID, SUCCESS_MSG, SVTRID}; + + #[test] + fn contact_delete() { + let xml = get_xml("response/contact/delete.xml").unwrap(); + let object = ContactDelete::deserialize_response(xml.as_str()).unwrap(); + + assert_eq!(object.result.code, 1000); + assert_eq!(object.result.message, SUCCESS_MSG.into()); + assert_eq!(object.tr_ids.client_tr_id.unwrap(), CLTRID.into()); + assert_eq!(object.tr_ids.server_tr_id, SVTRID.into()); + } +} diff --git a/epp-client/src/contact/info.rs b/epp-client/src/contact/info.rs index f956069..e2617eb 100644 --- a/epp-client/src/contact/info.rs +++ b/epp-client/src/contact/info.rs @@ -99,3 +99,68 @@ pub struct ContactInfoResponse { #[serde(rename = "infData")] pub info_data: ContactInfoData, } + +#[cfg(test)] +mod tests { + use super::ContactInfo; + use crate::request::Transaction; + use crate::tests::{get_xml, CLTRID, SUCCESS_MSG, SVTRID}; + + #[test] + fn contact_info() { + let xml = get_xml("response/contact/info.xml").unwrap(); + let object = ContactInfo::deserialize_response(xml.as_str()).unwrap(); + + let result = object.res_data().unwrap(); + let fax = result.info_data.fax.as_ref().unwrap(); + let voice_ext = result.info_data.voice.extension.as_ref().unwrap(); + let fax_ext = fax.extension.as_ref().unwrap(); + let auth_info = result.info_data.auth_info.as_ref().unwrap(); + + assert_eq!(object.result.code, 1000); + assert_eq!(object.result.message, SUCCESS_MSG.into()); + assert_eq!(result.info_data.id, "eppdev-contact-3".into()); + assert_eq!(result.info_data.roid, "UNDEF-ROID".into()); + assert_eq!(result.info_data.statuses[0].status, "ok".to_string()); + assert_eq!(result.info_data.postal_info.info_type, "loc".to_string()); + assert_eq!(result.info_data.postal_info.name, "John Doe".into()); + assert_eq!( + result.info_data.postal_info.organization, + "Acme Widgets".into() + ); + assert_eq!(result.info_data.postal_info.address.street[0], "58".into()); + assert_eq!( + result.info_data.postal_info.address.street[1], + "Orchid Road".into() + ); + assert_eq!(result.info_data.postal_info.address.city, "Paris".into()); + assert_eq!( + result.info_data.postal_info.address.province, + "Paris".into() + ); + assert_eq!( + result.info_data.postal_info.address.postal_code, + "392374".into() + ); + assert_eq!(result.info_data.postal_info.address.country.alpha2, "FR"); + assert_eq!(result.info_data.voice.number, "+33.47237942".to_string()); + assert_eq!(*voice_ext, "123".to_string()); + assert_eq!(fax.number, "+33.86698799".to_string()); + assert_eq!(*fax_ext, "243".to_string()); + assert_eq!(result.info_data.email, "contact@eppdev.net".into()); + assert_eq!(result.info_data.client_id, "eppdev".into()); + assert_eq!(result.info_data.creator_id, "SYSTEM".into()); + assert_eq!(result.info_data.created_at, "2021-07-23T13:09:09.0Z".into()); + assert_eq!( + *(result.info_data.updater_id.as_ref().unwrap()), + "SYSTEM".into() + ); + assert_eq!( + *(result.info_data.updated_at.as_ref().unwrap()), + "2021-07-23T13:09:09.0Z".into() + ); + assert_eq!((*auth_info).password, "eppdev-387323".into()); + assert_eq!(object.tr_ids.client_tr_id.unwrap(), CLTRID.into()); + assert_eq!(object.tr_ids.server_tr_id, SVTRID.into()); + } +} diff --git a/epp-client/src/contact/update.rs b/epp-client/src/contact/update.rs index 70dca32..2cf308d 100644 --- a/epp-client/src/contact/update.rs +++ b/epp-client/src/contact/update.rs @@ -104,3 +104,21 @@ pub struct ContactUpdate { #[serde(rename = "contact:update", alias = "update")] contact: ContactUpdateRequestData, } + +#[cfg(test)] +mod tests { + use super::ContactUpdate; + use crate::request::Transaction; + use crate::tests::{get_xml, CLTRID, SUCCESS_MSG, SVTRID}; + + #[test] + fn contact_update() { + let xml = get_xml("response/contact/update.xml").unwrap(); + let object = ContactUpdate::deserialize_response(xml.as_str()).unwrap(); + + assert_eq!(object.result.code, 1000); + assert_eq!(object.result.message, SUCCESS_MSG.into()); + assert_eq!(object.tr_ids.client_tr_id.unwrap(), CLTRID.into()); + assert_eq!(object.tr_ids.server_tr_id, SVTRID.into()); + } +} diff --git a/epp-client/src/domain/check.rs b/epp-client/src/domain/check.rs index fe16507..5800c6d 100644 --- a/epp-client/src/domain/check.rs +++ b/epp-client/src/domain/check.rs @@ -85,3 +85,35 @@ pub struct DomainCheckResponse { #[serde(rename = "chkData")] pub check_data: DomainCheckResponseData, } + +#[cfg(test)] +mod tests { + use super::DomainCheck; + use crate::common::NoExtension; + use crate::request::Transaction; + use crate::tests::{get_xml, CLTRID, SUCCESS_MSG, SVTRID}; + + #[test] + fn domain_check() { + let xml = get_xml("response/domain/check.xml").unwrap(); + let object = + >::deserialize_response(xml.as_str()).unwrap(); + + let result = object.res_data().unwrap(); + + assert_eq!(object.result.code, 1000); + assert_eq!(object.result.message, SUCCESS_MSG.into()); + assert_eq!( + result.check_data.domain_list[0].domain.name, + "eppdev.com".into() + ); + assert_eq!(result.check_data.domain_list[0].domain.available, 1); + assert_eq!( + result.check_data.domain_list[1].domain.name, + "eppdev.net".into() + ); + assert_eq!(result.check_data.domain_list[1].domain.available, 0); + assert_eq!(object.tr_ids.client_tr_id.unwrap(), CLTRID.into()); + assert_eq!(object.tr_ids.server_tr_id, SVTRID.into()); + } +} diff --git a/epp-client/src/domain/create.rs b/epp-client/src/domain/create.rs index c29511b..c4c0099 100644 --- a/epp-client/src/domain/create.rs +++ b/epp-client/src/domain/create.rs @@ -99,3 +99,32 @@ pub struct DomainCreateResponse { #[serde(rename = "creData")] pub create_data: DomainCreateResponseData, } + +#[cfg(test)] +mod tests { + use super::DomainCreate; + use crate::request::Transaction; + use crate::tests::{get_xml, CLTRID, SUCCESS_MSG, SVTRID}; + + #[test] + fn domain_create() { + let xml = get_xml("response/domain/create.xml").unwrap(); + let object = DomainCreate::deserialize_response(xml.as_str()).unwrap(); + + let result = object.res_data().unwrap(); + + assert_eq!(object.result.code, 1000); + assert_eq!(object.result.message, SUCCESS_MSG.into()); + assert_eq!(result.create_data.name, "eppdev-2.com".into()); + assert_eq!( + result.create_data.created_at, + "2021-07-25T18:11:35.0Z".into() + ); + assert_eq!( + result.create_data.expiring_at, + "2022-07-25T18:11:34.0Z".into() + ); + assert_eq!(object.tr_ids.client_tr_id.unwrap(), CLTRID.into()); + assert_eq!(object.tr_ids.server_tr_id, SVTRID.into()); + } +} diff --git a/epp-client/src/domain/delete.rs b/epp-client/src/domain/delete.rs index 79a9df8..a717d84 100644 --- a/epp-client/src/domain/delete.rs +++ b/epp-client/src/domain/delete.rs @@ -41,3 +41,21 @@ pub struct DomainDelete { #[serde(rename = "domain:delete", alias = "delete")] domain: DomainDeleteRequestData, } + +#[cfg(test)] +mod tests { + use super::DomainDelete; + use crate::request::Transaction; + use crate::tests::{get_xml, CLTRID, SUCCESS_MSG, SVTRID}; + + #[test] + fn domain_delete() { + let xml = get_xml("response/domain/delete.xml").unwrap(); + let object = DomainDelete::deserialize_response(xml.as_str()).unwrap(); + + assert_eq!(object.result.code, 1000); + assert_eq!(object.result.message, SUCCESS_MSG.into()); + assert_eq!(object.tr_ids.client_tr_id.unwrap(), CLTRID.into()); + assert_eq!(object.tr_ids.server_tr_id, SVTRID.into()); + } +} diff --git a/epp-client/src/domain/info.rs b/epp-client/src/domain/info.rs index c301f2b..91f3f7d 100644 --- a/epp-client/src/domain/info.rs +++ b/epp-client/src/domain/info.rs @@ -132,3 +132,75 @@ pub struct DomainInfoResponse { #[serde(rename = "infData")] pub info_data: DomainInfoResponseData, } + +#[cfg(test)] +mod tests { + use super::DomainInfo; + use crate::common::NoExtension; + use crate::request::Transaction; + use crate::tests::{get_xml, CLTRID, SUCCESS_MSG, SVTRID}; + + #[test] + fn domain_info() { + let xml = get_xml("response/domain/info.xml").unwrap(); + let object = + >::deserialize_response(xml.as_str()).unwrap(); + + let result = object.res_data().unwrap(); + let auth_info = result.info_data.auth_info.as_ref().unwrap(); + let ns_list = result.info_data.ns.as_ref().unwrap(); + let ns = (*ns_list).host_obj.as_ref().unwrap(); + let hosts = result.info_data.hosts.as_ref().unwrap(); + let statuses = result.info_data.statuses.as_ref().unwrap(); + let registrant = result.info_data.registrant.as_ref().unwrap(); + let contacts = result.info_data.contacts.as_ref().unwrap(); + + assert_eq!(object.result.code, 1000); + assert_eq!(object.result.message, SUCCESS_MSG.into()); + assert_eq!(result.info_data.name, "eppdev-1.com".into()); + assert_eq!(result.info_data.roid, "125899511_DOMAIN_COM-VRSN".into()); + assert_eq!(statuses[0].status, "ok".to_string()); + assert_eq!(statuses[1].status, "clientTransferProhibited".to_string()); + assert_eq!(*registrant, "eppdev-contact-2".into()); + assert_eq!(contacts[0].id, "eppdev-contact-2".to_string()); + assert_eq!(contacts[0].contact_type, "admin".to_string()); + assert_eq!(contacts[1].id, "eppdev-contact-2".to_string()); + assert_eq!(contacts[1].contact_type, "tech".to_string()); + assert_eq!(contacts[2].id, "eppdev-contact-2".to_string()); + assert_eq!(contacts[2].contact_type, "billing".to_string()); + assert_eq!((*ns)[0], "ns1.eppdev-1.com".into()); + assert_eq!((*ns)[1], "ns2.eppdev-1.com".into()); + assert_eq!((*hosts)[0], "ns1.eppdev-1.com".into()); + assert_eq!((*hosts)[1], "ns2.eppdev-1.com".into()); + assert_eq!(result.info_data.client_id, "eppdev".into()); + assert_eq!( + *result.info_data.creator_id.as_ref().unwrap(), + "SYSTEM".into() + ); + assert_eq!( + *result.info_data.created_at.as_ref().unwrap(), + "2021-07-23T15:31:20.0Z".into() + ); + assert_eq!( + *result.info_data.updater_id.as_ref().unwrap(), + "SYSTEM".into() + ); + assert_eq!( + *result.info_data.updated_at.as_ref().unwrap(), + "2021-07-23T15:31:21.0Z".into() + ); + assert_eq!( + *result.info_data.expiring_at.as_ref().unwrap(), + "2023-07-23T15:31:20.0Z".into() + ); + assert_eq!((*auth_info).password, "epP4uthd#v".into()); + assert_eq!(object.tr_ids.client_tr_id.unwrap(), CLTRID.into()); + assert_eq!(object.tr_ids.server_tr_id, SVTRID.into()); + } + + #[test] + fn domain_info_alt() { + let xml = get_xml("response/domain/info_alt.xml").unwrap(); + >::deserialize_response(xml.as_str()).unwrap(); + } +} diff --git a/epp-client/src/domain/renew.rs b/epp-client/src/domain/renew.rs index 4cf7ced..185ad42 100644 --- a/epp-client/src/domain/renew.rs +++ b/epp-client/src/domain/renew.rs @@ -73,3 +73,28 @@ pub struct DomainRenewResponse { #[serde(rename = "renData")] pub renew_data: DomainRenewResponseData, } + +#[cfg(test)] +mod tests { + use super::DomainRenew; + use crate::request::Transaction; + use crate::tests::{get_xml, CLTRID, SUCCESS_MSG, SVTRID}; + + #[test] + fn domain_renew() { + let xml = get_xml("response/domain/renew.xml").unwrap(); + let object = DomainRenew::deserialize_response(xml.as_str()).unwrap(); + + let result = object.res_data().unwrap(); + + assert_eq!(object.result.code, 1000); + assert_eq!(object.result.message, SUCCESS_MSG.into()); + assert_eq!(result.renew_data.name, "eppdev-1.com".into()); + assert_eq!( + result.renew_data.expiring_at, + "2024-07-23T15:31:20.0Z".into() + ); + assert_eq!(object.tr_ids.client_tr_id.unwrap(), CLTRID.into()); + assert_eq!(object.tr_ids.server_tr_id, SVTRID.into()); + } +} diff --git a/epp-client/src/domain/transfer.rs b/epp-client/src/domain/transfer.rs index 59d5bc8..9682be5 100644 --- a/epp-client/src/domain/transfer.rs +++ b/epp-client/src/domain/transfer.rs @@ -141,3 +141,98 @@ pub struct DomainTransferResponse { #[serde(rename = "trnData")] pub transfer_data: DomainTransferResponseData, } + +#[cfg(test)] +mod tests { + use super::DomainTransfer; + use crate::request::Transaction; + use crate::tests::{get_xml, CLTRID, SUCCESS_MSG, SVTRID}; + + #[test] + fn domain_transfer_request() { + let xml = get_xml("response/domain/transfer_request.xml").unwrap(); + let object = DomainTransfer::deserialize_response(xml.as_str()).unwrap(); + + let result = object.res_data().unwrap(); + + assert_eq!(object.result.code, 1001); + assert_eq!( + object.result.message, + "Command completed successfully; action pending".into() + ); + assert_eq!(result.transfer_data.name, "eppdev-transfer.com".into()); + assert_eq!(result.transfer_data.transfer_status, "pending".into()); + assert_eq!(result.transfer_data.requester_id, "eppdev".into()); + assert_eq!( + result.transfer_data.requested_at, + "2021-07-23T15:31:21.0Z".into() + ); + assert_eq!(result.transfer_data.ack_id, "ClientY".into()); + assert_eq!(result.transfer_data.ack_by, "2021-07-28T15:31:21.0Z".into()); + assert_eq!( + *result.transfer_data.expiring_at.as_ref().unwrap(), + "2022-07-02T14:53:19.0Z".into() + ); + assert_eq!(*object.tr_ids.client_tr_id.as_ref().unwrap(), CLTRID.into()); + assert_eq!(object.tr_ids.server_tr_id, SVTRID.into()); + } + + #[test] + fn domain_transfer_approve() { + let xml = get_xml("response/domain/transfer_approve.xml").unwrap(); + let object = DomainTransfer::deserialize_response(xml.as_str()).unwrap(); + + assert_eq!(object.result.code, 1000); + assert_eq!(object.result.message, SUCCESS_MSG.into()); + assert_eq!(object.tr_ids.client_tr_id.unwrap(), CLTRID.into()); + assert_eq!(object.tr_ids.server_tr_id, SVTRID.into()); + } + + #[test] + fn domain_transfer_reject() { + let xml = get_xml("response/domain/transfer_reject.xml").unwrap(); + let object = DomainTransfer::deserialize_response(xml.as_str()).unwrap(); + + assert_eq!(object.result.code, 1000); + assert_eq!(object.result.message, SUCCESS_MSG.into()); + assert_eq!(object.tr_ids.client_tr_id.unwrap(), CLTRID.into()); + assert_eq!(object.tr_ids.server_tr_id, SVTRID.into()); + } + + #[test] + fn domain_transfer_cancel() { + let xml = get_xml("response/domain/transfer_cancel.xml").unwrap(); + let object = DomainTransfer::deserialize_response(xml.as_str()).unwrap(); + + assert_eq!(object.result.code, 1000); + assert_eq!(object.result.message, SUCCESS_MSG.into()); + assert_eq!(object.tr_ids.client_tr_id.unwrap(), CLTRID.into()); + assert_eq!(object.tr_ids.server_tr_id, SVTRID.into()); + } + + #[test] + fn domain_transfer_query() { + let xml = get_xml("response/domain/transfer_query.xml").unwrap(); + let object = DomainTransfer::deserialize_response(xml.as_str()).unwrap(); + + let result = object.res_data().unwrap(); + + assert_eq!(object.result.code, 1000); + assert_eq!(object.result.message, SUCCESS_MSG.into()); + assert_eq!(result.transfer_data.name, "eppdev-transfer.com".into()); + assert_eq!(result.transfer_data.transfer_status, "pending".into()); + assert_eq!(result.transfer_data.requester_id, "eppdev".into()); + assert_eq!( + result.transfer_data.requested_at, + "2021-07-23T15:31:21.0Z".into() + ); + assert_eq!(result.transfer_data.ack_id, "ClientY".into()); + assert_eq!(result.transfer_data.ack_by, "2021-07-28T15:31:21.0Z".into()); + assert_eq!( + *result.transfer_data.expiring_at.as_ref().unwrap(), + "2022-07-02T14:53:19.0Z".into() + ); + assert_eq!(object.tr_ids.client_tr_id.unwrap(), CLTRID.into()); + assert_eq!(object.tr_ids.server_tr_id, SVTRID.into()); + } +} diff --git a/epp-client/src/domain/update.rs b/epp-client/src/domain/update.rs index 73a61f0..4ef3af1 100644 --- a/epp-client/src/domain/update.rs +++ b/epp-client/src/domain/update.rs @@ -99,3 +99,23 @@ pub struct DomainUpdate { #[serde(rename = "domain:update", alias = "update")] pub domain: DomainUpdateRequestData, } + +#[cfg(test)] +mod tests { + use super::DomainUpdate; + use crate::common::NoExtension; + use crate::request::Transaction; + use crate::tests::{get_xml, CLTRID, SUCCESS_MSG, SVTRID}; + + #[test] + fn domain_update() { + let xml = get_xml("response/domain/update.xml").unwrap(); + let object = + >::deserialize_response(xml.as_str()).unwrap(); + + assert_eq!(object.result.code, 1000); + assert_eq!(object.result.message, SUCCESS_MSG.into()); + assert_eq!(object.tr_ids.client_tr_id.unwrap(), CLTRID.into()); + assert_eq!(object.tr_ids.server_tr_id, SVTRID.into()); + } +} diff --git a/epp-client/src/extensions/namestore.rs b/epp-client/src/extensions/namestore.rs index 945ef5b..adc1cc1 100644 --- a/epp-client/src/extensions/namestore.rs +++ b/epp-client/src/extensions/namestore.rs @@ -43,3 +43,23 @@ pub struct NameStoreData { #[serde(rename = "namestoreExt:subProduct", alias = "subProduct")] pub subproduct: StringValue, } + +#[cfg(test)] +mod tests { + use super::NameStore; + use crate::domain::check::DomainCheck; + use crate::request::Transaction; + use crate::tests::get_xml; + + #[test] + fn namestore() { + let xml = get_xml("response/extensions/namestore.xml").unwrap(); + + let object = + >::deserialize_response(xml.as_str()).unwrap(); + + let ext = object.extension.unwrap(); + + assert_eq!(ext.data.subproduct, "com".into()); + } +} diff --git a/epp-client/src/extensions/rgp/request.rs b/epp-client/src/extensions/rgp/request.rs index c597391..0e7dafc 100644 --- a/epp-client/src/extensions/rgp/request.rs +++ b/epp-client/src/extensions/rgp/request.rs @@ -66,3 +66,43 @@ pub struct RgpRequestResponse { #[serde(rename = "rgpStatus")] pub rgp_status: Vec, } + +#[cfg(test)] +mod tests { + use super::{RgpRestoreRequest, Update}; + use crate::domain::info::DomainInfo; + use crate::domain::update::DomainUpdate; + use crate::request::Transaction; + use crate::tests::{get_xml, SUCCESS_MSG, SVTRID}; + + #[test] + fn rgp_restore_request() { + let xml = get_xml("response/extensions/rgp_restore.xml").unwrap(); + let object = + >>::deserialize_response( + xml.as_str(), + ) + .unwrap(); + + let ext = object.extension.unwrap(); + + assert_eq!(object.result.code, 1000); + assert_eq!(object.result.message, SUCCESS_MSG.into()); + assert_eq!(ext.data.rgp_status[0].status, "pendingRestore".to_string()); + assert_eq!(object.tr_ids.server_tr_id, SVTRID.into()); + } + + #[test] + fn rgp_restore_domain_info_response() { + let xml = get_xml("response/extensions/domain_info_rgp.xml").unwrap(); + let object = >>::deserialize_response( + xml.as_str(), + ) + .unwrap(); + + let ext = object.extension.unwrap(); + + assert_eq!(ext.data.rgp_status[0].status, "addPeriod"); + assert_eq!(ext.data.rgp_status[1].status, "renewPeriod"); + } +} diff --git a/epp-client/src/hello.rs b/epp-client/src/hello.rs index 861b56e..65a2a0f 100644 --- a/epp-client/src/hello.rs +++ b/epp-client/src/hello.rs @@ -302,3 +302,41 @@ pub struct GreetingDocument { } impl EppXml for GreetingDocument {} + +#[cfg(test)] +mod tests { + use super::{ExpiryType, GreetingDocument, Relative}; + use crate::tests::get_xml; + use crate::xml::EppXml; + + #[test] + fn greeting() { + let xml = get_xml("response/greeting.xml").unwrap(); + let object = GreetingDocument::deserialize(xml.as_str()).unwrap(); + + assert_eq!(object.data.service_id, "ISPAPI EPP Server"); + assert_eq!(object.data.service_date, "2021-07-25T14:51:17.0Z"); + assert_eq!(object.data.svc_menu.options.version, "1.0".into()); + assert_eq!(object.data.svc_menu.options.lang, "en".into()); + assert_eq!(object.data.svc_menu.services.obj_uris.len(), 4); + assert_eq!( + object + .data + .svc_menu + .services + .svc_ext + .unwrap() + .ext_uris + .unwrap() + .len(), + 5 + ); + assert_eq!(object.data.dcp.statement.len(), 2); + assert_eq!( + object.data.dcp.expiry.unwrap().ty, + ExpiryType::Relative(Relative { + relative: "P1M".into() + }) + ); + } +} diff --git a/epp-client/src/host/check.rs b/epp-client/src/host/check.rs index d08e278..758d07c 100644 --- a/epp-client/src/host/check.rs +++ b/epp-client/src/host/check.rs @@ -86,3 +86,33 @@ pub struct HostCheckResponse { #[serde(rename = "chkData")] pub check_data: HostCheckData, } + +#[cfg(test)] +mod tests { + use super::HostCheck; + use crate::request::Transaction; + use crate::tests::{get_xml, CLTRID, SUCCESS_MSG, SVTRID}; + + #[test] + fn host_check() { + let xml = get_xml("response/host/check.xml").unwrap(); + let object = HostCheck::deserialize_response(xml.as_str()).unwrap(); + + let result = object.res_data().unwrap(); + + assert_eq!(object.result.code, 1000); + assert_eq!(object.result.message, SUCCESS_MSG.into()); + assert_eq!( + result.check_data.host_list[0].host.name, + "host1.eppdev-1.com".into() + ); + assert_eq!(result.check_data.host_list[0].host.available, 1); + assert_eq!( + result.check_data.host_list[1].host.name, + "ns1.testing.com".into() + ); + assert_eq!(result.check_data.host_list[1].host.available, 0); + assert_eq!(object.tr_ids.client_tr_id.unwrap(), CLTRID.into()); + assert_eq!(object.tr_ids.server_tr_id, SVTRID.into()); + } +} diff --git a/epp-client/src/host/create.rs b/epp-client/src/host/create.rs index c5c66a3..04590c4 100644 --- a/epp-client/src/host/create.rs +++ b/epp-client/src/host/create.rs @@ -67,3 +67,28 @@ pub struct HostCreateResponse { #[serde(rename = "creData")] pub create_data: HostCreateData, } + +#[cfg(test)] +mod tests { + use super::HostCreate; + use crate::request::Transaction; + use crate::tests::{get_xml, CLTRID, SUCCESS_MSG, SVTRID}; + + #[test] + fn host_create() { + let xml = get_xml("response/host/create.xml").unwrap(); + let object = HostCreate::deserialize_response(xml.as_str()).unwrap(); + + let result = object.res_data().unwrap(); + + assert_eq!(object.result.code, 1000); + assert_eq!(object.result.message, SUCCESS_MSG.into()); + assert_eq!(result.create_data.name, "host2.eppdev-1.com".into()); + assert_eq!( + result.create_data.created_at, + "2021-07-26T05:28:55.0Z".into() + ); + assert_eq!(object.tr_ids.client_tr_id.unwrap(), CLTRID.into()); + assert_eq!(object.tr_ids.server_tr_id, SVTRID.into()); + } +} diff --git a/epp-client/src/host/delete.rs b/epp-client/src/host/delete.rs index 4d4c345..1c4a9db 100644 --- a/epp-client/src/host/delete.rs +++ b/epp-client/src/host/delete.rs @@ -41,3 +41,21 @@ pub struct HostDelete { #[serde(rename = "host:delete", alias = "delete")] host: HostDeleteRequestData, } + +#[cfg(test)] +mod tests { + use super::HostDelete; + use crate::request::Transaction; + use crate::tests::{get_xml, CLTRID, SUCCESS_MSG, SVTRID}; + + #[test] + fn host_delete() { + let xml = get_xml("response/host/delete.xml").unwrap(); + let object = HostDelete::deserialize_response(xml.as_str()).unwrap(); + + assert_eq!(object.result.code, 1000); + assert_eq!(object.result.message, SUCCESS_MSG.into()); + assert_eq!(object.tr_ids.client_tr_id.unwrap(), CLTRID.into()); + assert_eq!(object.tr_ids.server_tr_id, SVTRID.into()); + } +} diff --git a/epp-client/src/host/info.rs b/epp-client/src/host/info.rs index 9b36cad..f123f16 100644 --- a/epp-client/src/host/info.rs +++ b/epp-client/src/host/info.rs @@ -86,3 +86,53 @@ pub struct HostInfoResponse { #[serde(rename = "infData")] pub info_data: HostInfoResponseData, } + +#[cfg(test)] +mod tests { + use super::HostInfo; + use crate::request::Transaction; + use crate::tests::{get_xml, CLTRID, SUCCESS_MSG, SVTRID}; + + #[test] + fn host_info() { + let xml = get_xml("response/host/info.xml").unwrap(); + let object = HostInfo::deserialize_response(xml.as_str()).unwrap(); + + let result = object.res_data().unwrap(); + + assert_eq!(object.result.code, 1000); + assert_eq!(object.result.message, SUCCESS_MSG.into()); + assert_eq!(result.info_data.name, "host2.eppdev-1.com".into()); + assert_eq!(result.info_data.roid, "UNDEF-ROID".into()); + assert_eq!(result.info_data.statuses[0].status, "ok".to_string()); + assert_eq!( + *(result.info_data.addresses[0].ip_version.as_ref().unwrap()), + "v4".to_string() + ); + assert_eq!( + result.info_data.addresses[0].address, + "29.245.122.14".to_string() + ); + assert_eq!( + *(result.info_data.addresses[1].ip_version.as_ref().unwrap()), + "v6".to_string() + ); + assert_eq!( + result.info_data.addresses[1].address, + "2404:6800:4001:0801:0000:0000:0000:200e".to_string() + ); + assert_eq!(result.info_data.client_id, "eppdev".into()); + assert_eq!(result.info_data.creator_id, "creator".into()); + assert_eq!(result.info_data.created_at, "2021-07-26T05:28:55.0Z".into()); + assert_eq!( + *(result.info_data.updater_id.as_ref().unwrap()), + "creator".into() + ); + assert_eq!( + *(result.info_data.updated_at.as_ref().unwrap()), + "2021-07-26T05:28:55.0Z".into() + ); + assert_eq!(object.tr_ids.client_tr_id.unwrap(), CLTRID.into()); + assert_eq!(object.tr_ids.server_tr_id, SVTRID.into()); + } +} diff --git a/epp-client/src/host/update.rs b/epp-client/src/host/update.rs index d3d36d4..be9977d 100644 --- a/epp-client/src/host/update.rs +++ b/epp-client/src/host/update.rs @@ -87,3 +87,21 @@ pub struct HostUpdate { #[serde(rename = "host:update", alias = "update")] host: HostUpdateRequestData, } + +#[cfg(test)] +mod tests { + use super::HostUpdate; + use crate::request::Transaction; + use crate::tests::{get_xml, CLTRID, SUCCESS_MSG, SVTRID}; + + #[test] + fn host_update() { + let xml = get_xml("response/host/update.xml").unwrap(); + let object = HostUpdate::deserialize_response(xml.as_str()).unwrap(); + + assert_eq!(object.result.code, 1000); + assert_eq!(object.result.message, SUCCESS_MSG.into()); + assert_eq!(object.tr_ids.client_tr_id.unwrap(), CLTRID.into()); + assert_eq!(object.tr_ids.server_tr_id, SVTRID.into()); + } +} diff --git a/epp-client/src/login.rs b/epp-client/src/login.rs index ab67543..106e45d 100644 --- a/epp-client/src/login.rs +++ b/epp-client/src/login.rs @@ -63,3 +63,21 @@ impl Command for Login { type Response = (); const COMMAND: &'static str = "login"; } + +#[cfg(test)] +mod tests { + use super::Login; + use crate::request::Transaction; + use crate::tests::{get_xml, CLTRID, SUCCESS_MSG, SVTRID}; + + #[test] + fn login() { + let xml = get_xml("response/login.xml").unwrap(); + let object = Login::deserialize_response(xml.as_str()).unwrap(); + + assert_eq!(object.result.code, 1000); + assert_eq!(object.result.message, SUCCESS_MSG.into()); + assert_eq!(object.tr_ids.client_tr_id.unwrap(), CLTRID.into()); + assert_eq!(object.tr_ids.server_tr_id, SVTRID.into()); + } +} diff --git a/epp-client/src/logout.rs b/epp-client/src/logout.rs index 50bdc2c..1cf4311 100644 --- a/epp-client/src/logout.rs +++ b/epp-client/src/logout.rs @@ -17,3 +17,24 @@ impl Command for Logout { #[derive(Serialize, Deserialize, Debug, PartialEq)] /// Type corresponding to the <logout> tag in an EPP XML logout request pub struct Logout; + +#[cfg(test)] +mod tests { + use super::Logout; + use crate::request::Transaction; + use crate::tests::{get_xml, CLTRID, SVTRID}; + + #[test] + fn logout() { + let xml = get_xml("response/logout.xml").unwrap(); + let object = Logout::deserialize_response(xml.as_str()).unwrap(); + + assert_eq!(object.result.code, 1500); + assert_eq!( + object.result.message, + "Command completed successfully; ending session".into() + ); + assert_eq!(object.tr_ids.client_tr_id.unwrap(), CLTRID.into()); + assert_eq!(object.tr_ids.server_tr_id, SVTRID.into()); + } +} diff --git a/epp-client/src/message/ack.rs b/epp-client/src/message/ack.rs index e8540db..5280115 100644 --- a/epp-client/src/message/ack.rs +++ b/epp-client/src/message/ack.rs @@ -30,3 +30,24 @@ impl MessageAck { } } } + +#[cfg(test)] +mod tests { + use super::MessageAck; + use crate::request::Transaction; + use crate::tests::{get_xml, SUCCESS_MSG, SVTRID}; + + #[test] + fn message_ack() { + let xml = get_xml("response/message/ack.xml").unwrap(); + let object = MessageAck::deserialize_response(xml.as_str()).unwrap(); + + let msg = object.message_queue().unwrap(); + + assert_eq!(object.result.code, 1000); + assert_eq!(object.result.message, SUCCESS_MSG.into()); + assert_eq!(msg.count, 4); + assert_eq!(msg.id, "12345".to_string()); + assert_eq!(object.tr_ids.server_tr_id, SVTRID.into()); + } +} diff --git a/epp-client/src/message/poll.rs b/epp-client/src/message/poll.rs index 384c490..be81e5c 100644 --- a/epp-client/src/message/poll.rs +++ b/epp-client/src/message/poll.rs @@ -62,3 +62,50 @@ pub struct MessagePollResponse { #[serde(rename = "domain:trnData", alias = "trnData")] pub message_data: MessageDomainTransferData, } + +#[cfg(test)] +mod tests { + use super::MessagePoll; + use crate::request::Transaction; + use crate::tests::{get_xml, CLTRID, SVTRID}; + + #[test] + fn message_poll() { + let xml = get_xml("response/message/poll.xml").unwrap(); + let object = MessagePoll::deserialize_response(xml.as_str()).unwrap(); + + let result = object.res_data().unwrap(); + let msg = object.message_queue().unwrap(); + + assert_eq!(object.result.code, 1301); + assert_eq!( + object.result.message, + "Command completed successfully; ack to dequeue".into() + ); + assert_eq!(msg.count, 5); + assert_eq!(msg.id, "12345".to_string()); + assert_eq!( + *(msg.date.as_ref().unwrap()), + "2021-07-23T19:12:43.0Z".into() + ); + assert_eq!( + *(msg.message.as_ref().unwrap()), + "Transfer requested.".into() + ); + assert_eq!(result.message_data.name, "eppdev-transfer.com".into()); + assert_eq!(result.message_data.transfer_status, "pending".into()); + assert_eq!(result.message_data.requester_id, "eppdev".into()); + assert_eq!( + result.message_data.requested_at, + "2021-07-23T15:31:21.0Z".into() + ); + assert_eq!(result.message_data.ack_id, "ClientY".into()); + assert_eq!(result.message_data.ack_by, "2021-07-28T15:31:21.0Z".into()); + assert_eq!( + result.message_data.expiring_at, + "2022-07-02T14:53:19.0Z".into() + ); + assert_eq!(object.tr_ids.client_tr_id.unwrap(), CLTRID.into()); + assert_eq!(object.tr_ids.server_tr_id, SVTRID.into()); + } +} diff --git a/epp-client/src/response.rs b/epp-client/src/response.rs index beb4055..2c6e70a 100644 --- a/epp-client/src/response.rs +++ b/epp-client/src/response.rs @@ -132,3 +132,25 @@ impl Response { } } } + +#[cfg(test)] +mod tests { + use super::ResultDocument; + use crate::tests::{get_xml, CLTRID, SVTRID}; + use crate::xml::EppXml; + + #[test] + fn error() { + let xml = get_xml("response/error.xml").unwrap(); + let object = ResultDocument::deserialize(xml.as_str()).unwrap(); + + assert_eq!(object.data.result.code, 2303); + assert_eq!(object.data.result.message, "Object does not exist".into()); + assert_eq!( + object.data.result.ext_value.unwrap().reason, + "545 Object not found".into() + ); + assert_eq!(object.data.tr_ids.client_tr_id.unwrap(), CLTRID.into()); + assert_eq!(object.data.tr_ids.server_tr_id, SVTRID.into()); + } +} diff --git a/epp-client/src/tests/de.rs b/epp-client/src/tests/de.rs deleted file mode 100644 index 717d879..0000000 --- a/epp-client/src/tests/de.rs +++ /dev/null @@ -1,674 +0,0 @@ -//! EPP XML to `EppObject` deserialization tests - -mod response { - use super::super::get_xml; - use super::super::CLTRID; - use crate::common::NoExtension; - 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::DomainUpdate; - use crate::extensions::namestore::NameStore; - use crate::extensions::rgp; - use crate::hello::ExpiryType; - use crate::hello::GreetingDocument; - use crate::hello::Relative; - use crate::host::check::HostCheck; - use crate::host::create::HostCreate; - use crate::host::delete::HostDelete; - use crate::host::info::HostInfo; - 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::response::ResultDocument; - use crate::xml::EppXml; - - const SVTRID: &str = "RO-6879-1627224678242975"; - const SUCCESS_MSG: &str = "Command completed successfully"; - - #[test] - fn greeting() { - let xml = get_xml("response/greeting.xml").unwrap(); - let object = GreetingDocument::deserialize(xml.as_str()).unwrap(); - - assert_eq!(object.data.service_id, "ISPAPI EPP Server"); - assert_eq!(object.data.service_date, "2021-07-25T14:51:17.0Z"); - assert_eq!(object.data.svc_menu.options.version, "1.0".into()); - assert_eq!(object.data.svc_menu.options.lang, "en".into()); - assert_eq!(object.data.svc_menu.services.obj_uris.len(), 4); - assert_eq!( - object - .data - .svc_menu - .services - .svc_ext - .unwrap() - .ext_uris - .unwrap() - .len(), - 5 - ); - assert_eq!(object.data.dcp.statement.len(), 2); - assert_eq!( - object.data.dcp.expiry.unwrap().ty, - ExpiryType::Relative(Relative { - relative: "P1M".into() - }) - ); - } - - #[test] - fn error() { - let xml = get_xml("response/error.xml").unwrap(); - let object = ResultDocument::deserialize(xml.as_str()).unwrap(); - - assert_eq!(object.data.result.code, 2303); - assert_eq!(object.data.result.message, "Object does not exist".into()); - assert_eq!( - object.data.result.ext_value.unwrap().reason, - "545 Object not found".into() - ); - assert_eq!(object.data.tr_ids.client_tr_id.unwrap(), CLTRID.into()); - assert_eq!(object.data.tr_ids.server_tr_id, SVTRID.into()); - } - - #[test] - fn login() { - let xml = get_xml("response/login.xml").unwrap(); - let object = Login::deserialize_response(xml.as_str()).unwrap(); - - assert_eq!(object.result.code, 1000); - assert_eq!(object.result.message, SUCCESS_MSG.into()); - assert_eq!(object.tr_ids.client_tr_id.unwrap(), CLTRID.into()); - assert_eq!(object.tr_ids.server_tr_id, SVTRID.into()); - } - - #[test] - fn logout() { - let xml = get_xml("response/logout.xml").unwrap(); - let object = Logout::deserialize_response(xml.as_str()).unwrap(); - - assert_eq!(object.result.code, 1500); - assert_eq!( - object.result.message, - "Command completed successfully; ending session".into() - ); - assert_eq!(object.tr_ids.client_tr_id.unwrap(), CLTRID.into()); - assert_eq!(object.tr_ids.server_tr_id, SVTRID.into()); - } - - #[test] - fn contact_check() { - let xml = get_xml("response/contact/check.xml").unwrap(); - let object = ContactCheck::deserialize_response(xml.as_str()).unwrap(); - - let results = object.res_data().unwrap(); - - assert_eq!(object.result.code, 1000); - assert_eq!(object.result.message, SUCCESS_MSG.into()); - assert_eq!( - results.check_data.contact_list[0].contact.id, - "eppdev-contact-1".into() - ); - assert_eq!(results.check_data.contact_list[0].contact.available, 0); - assert_eq!( - results.check_data.contact_list[1].contact.id, - "eppdev-contact-2".into() - ); - assert_eq!(results.check_data.contact_list[1].contact.available, 1); - assert_eq!(object.tr_ids.client_tr_id.unwrap(), CLTRID.into()); - assert_eq!(object.tr_ids.server_tr_id, SVTRID.into()); - } - - #[test] - fn contact_create() { - let xml = get_xml("response/contact/create.xml").unwrap(); - let object = ContactCreate::deserialize_response(xml.as_str()).unwrap(); - - let results = object.res_data().unwrap(); - - assert_eq!(object.result.code, 1000); - assert_eq!(object.result.message, SUCCESS_MSG.into()); - assert_eq!(results.create_data.id, "eppdev-contact-4".into()); - assert_eq!( - results.create_data.created_at, - "2021-07-25T16:05:32.0Z".into() - ); - assert_eq!(object.tr_ids.client_tr_id.unwrap(), CLTRID.into()); - assert_eq!(object.tr_ids.server_tr_id, SVTRID.into()); - } - - #[test] - fn contact_delete() { - let xml = get_xml("response/contact/delete.xml").unwrap(); - let object = ContactDelete::deserialize_response(xml.as_str()).unwrap(); - - assert_eq!(object.result.code, 1000); - assert_eq!(object.result.message, SUCCESS_MSG.into()); - assert_eq!(object.tr_ids.client_tr_id.unwrap(), CLTRID.into()); - assert_eq!(object.tr_ids.server_tr_id, SVTRID.into()); - } - - #[test] - fn contact_info() { - let xml = get_xml("response/contact/info.xml").unwrap(); - let object = ContactInfo::deserialize_response(xml.as_str()).unwrap(); - - let result = object.res_data().unwrap(); - let fax = result.info_data.fax.as_ref().unwrap(); - let voice_ext = result.info_data.voice.extension.as_ref().unwrap(); - let fax_ext = fax.extension.as_ref().unwrap(); - let auth_info = result.info_data.auth_info.as_ref().unwrap(); - - assert_eq!(object.result.code, 1000); - assert_eq!(object.result.message, SUCCESS_MSG.into()); - assert_eq!(result.info_data.id, "eppdev-contact-3".into()); - assert_eq!(result.info_data.roid, "UNDEF-ROID".into()); - assert_eq!(result.info_data.statuses[0].status, "ok".to_string()); - assert_eq!(result.info_data.postal_info.info_type, "loc".to_string()); - assert_eq!(result.info_data.postal_info.name, "John Doe".into()); - assert_eq!( - result.info_data.postal_info.organization, - "Acme Widgets".into() - ); - assert_eq!(result.info_data.postal_info.address.street[0], "58".into()); - assert_eq!( - result.info_data.postal_info.address.street[1], - "Orchid Road".into() - ); - assert_eq!(result.info_data.postal_info.address.city, "Paris".into()); - assert_eq!( - result.info_data.postal_info.address.province, - "Paris".into() - ); - assert_eq!( - result.info_data.postal_info.address.postal_code, - "392374".into() - ); - assert_eq!(result.info_data.postal_info.address.country.alpha2, "FR"); - assert_eq!(result.info_data.voice.number, "+33.47237942".to_string()); - assert_eq!(*voice_ext, "123".to_string()); - assert_eq!(fax.number, "+33.86698799".to_string()); - assert_eq!(*fax_ext, "243".to_string()); - assert_eq!(result.info_data.email, "contact@eppdev.net".into()); - assert_eq!(result.info_data.client_id, "eppdev".into()); - assert_eq!(result.info_data.creator_id, "SYSTEM".into()); - assert_eq!(result.info_data.created_at, "2021-07-23T13:09:09.0Z".into()); - assert_eq!( - *(result.info_data.updater_id.as_ref().unwrap()), - "SYSTEM".into() - ); - assert_eq!( - *(result.info_data.updated_at.as_ref().unwrap()), - "2021-07-23T13:09:09.0Z".into() - ); - assert_eq!((*auth_info).password, "eppdev-387323".into()); - assert_eq!(object.tr_ids.client_tr_id.unwrap(), CLTRID.into()); - assert_eq!(object.tr_ids.server_tr_id, SVTRID.into()); - } - - #[test] - fn contact_update() { - let xml = get_xml("response/contact/update.xml").unwrap(); - let object = ContactUpdate::deserialize_response(xml.as_str()).unwrap(); - - assert_eq!(object.result.code, 1000); - assert_eq!(object.result.message, SUCCESS_MSG.into()); - assert_eq!(object.tr_ids.client_tr_id.unwrap(), CLTRID.into()); - assert_eq!(object.tr_ids.server_tr_id, SVTRID.into()); - } - - #[test] - fn domain_check() { - let xml = get_xml("response/domain/check.xml").unwrap(); - let object = - >::deserialize_response(xml.as_str()).unwrap(); - - let result = object.res_data().unwrap(); - - assert_eq!(object.result.code, 1000); - assert_eq!(object.result.message, SUCCESS_MSG.into()); - assert_eq!( - result.check_data.domain_list[0].domain.name, - "eppdev.com".into() - ); - assert_eq!(result.check_data.domain_list[0].domain.available, 1); - assert_eq!( - result.check_data.domain_list[1].domain.name, - "eppdev.net".into() - ); - assert_eq!(result.check_data.domain_list[1].domain.available, 0); - assert_eq!(object.tr_ids.client_tr_id.unwrap(), CLTRID.into()); - assert_eq!(object.tr_ids.server_tr_id, SVTRID.into()); - } - - #[test] - fn domain_create() { - let xml = get_xml("response/domain/create.xml").unwrap(); - let object = DomainCreate::deserialize_response(xml.as_str()).unwrap(); - - let result = object.res_data().unwrap(); - - assert_eq!(object.result.code, 1000); - assert_eq!(object.result.message, SUCCESS_MSG.into()); - assert_eq!(result.create_data.name, "eppdev-2.com".into()); - assert_eq!( - result.create_data.created_at, - "2021-07-25T18:11:35.0Z".into() - ); - assert_eq!( - result.create_data.expiring_at, - "2022-07-25T18:11:34.0Z".into() - ); - assert_eq!(object.tr_ids.client_tr_id.unwrap(), CLTRID.into()); - assert_eq!(object.tr_ids.server_tr_id, SVTRID.into()); - } - - #[test] - fn domain_delete() { - let xml = get_xml("response/domain/delete.xml").unwrap(); - let object = DomainDelete::deserialize_response(xml.as_str()).unwrap(); - - assert_eq!(object.result.code, 1000); - assert_eq!(object.result.message, SUCCESS_MSG.into()); - assert_eq!(object.tr_ids.client_tr_id.unwrap(), CLTRID.into()); - assert_eq!(object.tr_ids.server_tr_id, SVTRID.into()); - } - - #[test] - fn domain_info() { - let xml = get_xml("response/domain/info.xml").unwrap(); - let object = - >::deserialize_response(xml.as_str()).unwrap(); - - let result = object.res_data().unwrap(); - let auth_info = result.info_data.auth_info.as_ref().unwrap(); - let ns_list = result.info_data.ns.as_ref().unwrap(); - let ns = (*ns_list).host_obj.as_ref().unwrap(); - let hosts = result.info_data.hosts.as_ref().unwrap(); - let statuses = result.info_data.statuses.as_ref().unwrap(); - let registrant = result.info_data.registrant.as_ref().unwrap(); - let contacts = result.info_data.contacts.as_ref().unwrap(); - - assert_eq!(object.result.code, 1000); - assert_eq!(object.result.message, SUCCESS_MSG.into()); - assert_eq!(result.info_data.name, "eppdev-1.com".into()); - assert_eq!(result.info_data.roid, "125899511_DOMAIN_COM-VRSN".into()); - assert_eq!(statuses[0].status, "ok".to_string()); - assert_eq!(statuses[1].status, "clientTransferProhibited".to_string()); - assert_eq!(*registrant, "eppdev-contact-2".into()); - assert_eq!(contacts[0].id, "eppdev-contact-2".to_string()); - assert_eq!(contacts[0].contact_type, "admin".to_string()); - assert_eq!(contacts[1].id, "eppdev-contact-2".to_string()); - assert_eq!(contacts[1].contact_type, "tech".to_string()); - assert_eq!(contacts[2].id, "eppdev-contact-2".to_string()); - assert_eq!(contacts[2].contact_type, "billing".to_string()); - assert_eq!((*ns)[0], "ns1.eppdev-1.com".into()); - assert_eq!((*ns)[1], "ns2.eppdev-1.com".into()); - assert_eq!((*hosts)[0], "ns1.eppdev-1.com".into()); - assert_eq!((*hosts)[1], "ns2.eppdev-1.com".into()); - assert_eq!(result.info_data.client_id, "eppdev".into()); - assert_eq!( - *result.info_data.creator_id.as_ref().unwrap(), - "SYSTEM".into() - ); - assert_eq!( - *result.info_data.created_at.as_ref().unwrap(), - "2021-07-23T15:31:20.0Z".into() - ); - assert_eq!( - *result.info_data.updater_id.as_ref().unwrap(), - "SYSTEM".into() - ); - assert_eq!( - *result.info_data.updated_at.as_ref().unwrap(), - "2021-07-23T15:31:21.0Z".into() - ); - assert_eq!( - *result.info_data.expiring_at.as_ref().unwrap(), - "2023-07-23T15:31:20.0Z".into() - ); - assert_eq!((*auth_info).password, "epP4uthd#v".into()); - assert_eq!(object.tr_ids.client_tr_id.unwrap(), CLTRID.into()); - assert_eq!(object.tr_ids.server_tr_id, SVTRID.into()); - } - - #[test] - fn domain_info_alt() { - let xml = get_xml("response/domain/info_alt.xml").unwrap(); - >::deserialize_response(xml.as_str()).unwrap(); - } - - #[test] - fn domain_renew() { - let xml = get_xml("response/domain/renew.xml").unwrap(); - let object = DomainRenew::deserialize_response(xml.as_str()).unwrap(); - - let result = object.res_data().unwrap(); - - assert_eq!(object.result.code, 1000); - assert_eq!(object.result.message, SUCCESS_MSG.into()); - assert_eq!(result.renew_data.name, "eppdev-1.com".into()); - assert_eq!( - result.renew_data.expiring_at, - "2024-07-23T15:31:20.0Z".into() - ); - assert_eq!(object.tr_ids.client_tr_id.unwrap(), CLTRID.into()); - assert_eq!(object.tr_ids.server_tr_id, SVTRID.into()); - } - - #[test] - fn domain_transfer_request() { - let xml = get_xml("response/domain/transfer_request.xml").unwrap(); - let object = DomainTransfer::deserialize_response(xml.as_str()).unwrap(); - - let result = object.res_data().unwrap(); - - assert_eq!(object.result.code, 1001); - assert_eq!( - object.result.message, - "Command completed successfully; action pending".into() - ); - assert_eq!(result.transfer_data.name, "eppdev-transfer.com".into()); - assert_eq!(result.transfer_data.transfer_status, "pending".into()); - assert_eq!(result.transfer_data.requester_id, "eppdev".into()); - assert_eq!( - result.transfer_data.requested_at, - "2021-07-23T15:31:21.0Z".into() - ); - assert_eq!(result.transfer_data.ack_id, "ClientY".into()); - assert_eq!(result.transfer_data.ack_by, "2021-07-28T15:31:21.0Z".into()); - assert_eq!( - *result.transfer_data.expiring_at.as_ref().unwrap(), - "2022-07-02T14:53:19.0Z".into() - ); - assert_eq!(*object.tr_ids.client_tr_id.as_ref().unwrap(), CLTRID.into()); - assert_eq!(object.tr_ids.server_tr_id, SVTRID.into()); - } - - #[test] - fn domain_transfer_approve() { - let xml = get_xml("response/domain/transfer_approve.xml").unwrap(); - let object = DomainTransfer::deserialize_response(xml.as_str()).unwrap(); - - assert_eq!(object.result.code, 1000); - assert_eq!(object.result.message, SUCCESS_MSG.into()); - assert_eq!(object.tr_ids.client_tr_id.unwrap(), CLTRID.into()); - assert_eq!(object.tr_ids.server_tr_id, SVTRID.into()); - } - - #[test] - fn domain_transfer_reject() { - let xml = get_xml("response/domain/transfer_reject.xml").unwrap(); - let object = DomainTransfer::deserialize_response(xml.as_str()).unwrap(); - - assert_eq!(object.result.code, 1000); - assert_eq!(object.result.message, SUCCESS_MSG.into()); - assert_eq!(object.tr_ids.client_tr_id.unwrap(), CLTRID.into()); - assert_eq!(object.tr_ids.server_tr_id, SVTRID.into()); - } - - #[test] - fn domain_transfer_cancel() { - let xml = get_xml("response/domain/transfer_cancel.xml").unwrap(); - let object = DomainTransfer::deserialize_response(xml.as_str()).unwrap(); - - assert_eq!(object.result.code, 1000); - assert_eq!(object.result.message, SUCCESS_MSG.into()); - assert_eq!(object.tr_ids.client_tr_id.unwrap(), CLTRID.into()); - assert_eq!(object.tr_ids.server_tr_id, SVTRID.into()); - } - - #[test] - fn domain_transfer_query() { - let xml = get_xml("response/domain/transfer_query.xml").unwrap(); - let object = DomainTransfer::deserialize_response(xml.as_str()).unwrap(); - - let result = object.res_data().unwrap(); - - assert_eq!(object.result.code, 1000); - assert_eq!(object.result.message, SUCCESS_MSG.into()); - assert_eq!(result.transfer_data.name, "eppdev-transfer.com".into()); - assert_eq!(result.transfer_data.transfer_status, "pending".into()); - assert_eq!(result.transfer_data.requester_id, "eppdev".into()); - assert_eq!( - result.transfer_data.requested_at, - "2021-07-23T15:31:21.0Z".into() - ); - assert_eq!(result.transfer_data.ack_id, "ClientY".into()); - assert_eq!(result.transfer_data.ack_by, "2021-07-28T15:31:21.0Z".into()); - assert_eq!( - *result.transfer_data.expiring_at.as_ref().unwrap(), - "2022-07-02T14:53:19.0Z".into() - ); - assert_eq!(object.tr_ids.client_tr_id.unwrap(), CLTRID.into()); - assert_eq!(object.tr_ids.server_tr_id, SVTRID.into()); - } - - #[test] - fn domain_update() { - let xml = get_xml("response/domain/update.xml").unwrap(); - let object = - >::deserialize_response(xml.as_str()).unwrap(); - - assert_eq!(object.result.code, 1000); - assert_eq!(object.result.message, SUCCESS_MSG.into()); - assert_eq!(object.tr_ids.client_tr_id.unwrap(), CLTRID.into()); - assert_eq!(object.tr_ids.server_tr_id, SVTRID.into()); - } - - #[test] - fn host_check() { - let xml = get_xml("response/host/check.xml").unwrap(); - let object = HostCheck::deserialize_response(xml.as_str()).unwrap(); - - let result = object.res_data().unwrap(); - - assert_eq!(object.result.code, 1000); - assert_eq!(object.result.message, SUCCESS_MSG.into()); - assert_eq!( - result.check_data.host_list[0].host.name, - "host1.eppdev-1.com".into() - ); - assert_eq!(result.check_data.host_list[0].host.available, 1); - assert_eq!( - result.check_data.host_list[1].host.name, - "ns1.testing.com".into() - ); - assert_eq!(result.check_data.host_list[1].host.available, 0); - assert_eq!(object.tr_ids.client_tr_id.unwrap(), CLTRID.into()); - assert_eq!(object.tr_ids.server_tr_id, SVTRID.into()); - } - - #[test] - fn host_create() { - let xml = get_xml("response/host/create.xml").unwrap(); - let object = HostCreate::deserialize_response(xml.as_str()).unwrap(); - - let result = object.res_data().unwrap(); - - assert_eq!(object.result.code, 1000); - assert_eq!(object.result.message, SUCCESS_MSG.into()); - assert_eq!(result.create_data.name, "host2.eppdev-1.com".into()); - assert_eq!( - result.create_data.created_at, - "2021-07-26T05:28:55.0Z".into() - ); - assert_eq!(object.tr_ids.client_tr_id.unwrap(), CLTRID.into()); - assert_eq!(object.tr_ids.server_tr_id, SVTRID.into()); - } - - #[test] - fn host_info() { - let xml = get_xml("response/host/info.xml").unwrap(); - let object = HostInfo::deserialize_response(xml.as_str()).unwrap(); - - let result = object.res_data().unwrap(); - - assert_eq!(object.result.code, 1000); - assert_eq!(object.result.message, SUCCESS_MSG.into()); - assert_eq!(result.info_data.name, "host2.eppdev-1.com".into()); - assert_eq!(result.info_data.roid, "UNDEF-ROID".into()); - assert_eq!(result.info_data.statuses[0].status, "ok".to_string()); - assert_eq!( - *(result.info_data.addresses[0].ip_version.as_ref().unwrap()), - "v4".to_string() - ); - assert_eq!( - result.info_data.addresses[0].address, - "29.245.122.14".to_string() - ); - assert_eq!( - *(result.info_data.addresses[1].ip_version.as_ref().unwrap()), - "v6".to_string() - ); - assert_eq!( - result.info_data.addresses[1].address, - "2404:6800:4001:0801:0000:0000:0000:200e".to_string() - ); - assert_eq!(result.info_data.client_id, "eppdev".into()); - assert_eq!(result.info_data.creator_id, "creator".into()); - assert_eq!(result.info_data.created_at, "2021-07-26T05:28:55.0Z".into()); - assert_eq!( - *(result.info_data.updater_id.as_ref().unwrap()), - "creator".into() - ); - assert_eq!( - *(result.info_data.updated_at.as_ref().unwrap()), - "2021-07-26T05:28:55.0Z".into() - ); - assert_eq!(object.tr_ids.client_tr_id.unwrap(), CLTRID.into()); - assert_eq!(object.tr_ids.server_tr_id, SVTRID.into()); - } - - #[test] - fn host_update() { - let xml = get_xml("response/host/update.xml").unwrap(); - let object = HostUpdate::deserialize_response(xml.as_str()).unwrap(); - - assert_eq!(object.result.code, 1000); - assert_eq!(object.result.message, SUCCESS_MSG.into()); - assert_eq!(object.tr_ids.client_tr_id.unwrap(), CLTRID.into()); - assert_eq!(object.tr_ids.server_tr_id, SVTRID.into()); - } - - #[test] - fn host_delete() { - let xml = get_xml("response/host/delete.xml").unwrap(); - let object = HostDelete::deserialize_response(xml.as_str()).unwrap(); - - assert_eq!(object.result.code, 1000); - assert_eq!(object.result.message, SUCCESS_MSG.into()); - assert_eq!(object.tr_ids.client_tr_id.unwrap(), CLTRID.into()); - assert_eq!(object.tr_ids.server_tr_id, SVTRID.into()); - } - - #[test] - fn message_poll() { - let xml = get_xml("response/message/poll.xml").unwrap(); - let object = MessagePoll::deserialize_response(xml.as_str()).unwrap(); - - let result = object.res_data().unwrap(); - let msg = object.message_queue().unwrap(); - - assert_eq!(object.result.code, 1301); - assert_eq!( - object.result.message, - "Command completed successfully; ack to dequeue".into() - ); - assert_eq!(msg.count, 5); - assert_eq!(msg.id, "12345".to_string()); - assert_eq!( - *(msg.date.as_ref().unwrap()), - "2021-07-23T19:12:43.0Z".into() - ); - assert_eq!( - *(msg.message.as_ref().unwrap()), - "Transfer requested.".into() - ); - assert_eq!(result.message_data.name, "eppdev-transfer.com".into()); - assert_eq!(result.message_data.transfer_status, "pending".into()); - assert_eq!(result.message_data.requester_id, "eppdev".into()); - assert_eq!( - result.message_data.requested_at, - "2021-07-23T15:31:21.0Z".into() - ); - assert_eq!(result.message_data.ack_id, "ClientY".into()); - assert_eq!(result.message_data.ack_by, "2021-07-28T15:31:21.0Z".into()); - assert_eq!( - result.message_data.expiring_at, - "2022-07-02T14:53:19.0Z".into() - ); - assert_eq!(object.tr_ids.client_tr_id.unwrap(), CLTRID.into()); - assert_eq!(object.tr_ids.server_tr_id, SVTRID.into()); - } - - #[test] - fn message_ack() { - let xml = get_xml("response/message/ack.xml").unwrap(); - let object = MessageAck::deserialize_response(xml.as_str()).unwrap(); - - let msg = object.message_queue().unwrap(); - - assert_eq!(object.result.code, 1000); - assert_eq!(object.result.message, SUCCESS_MSG.into()); - assert_eq!(msg.count, 4); - assert_eq!(msg.id, "12345".to_string()); - assert_eq!(object.tr_ids.server_tr_id, SVTRID.into()); - } - - #[test] - fn rgp_restore_response() { - let xml = get_xml("response/extensions/rgp_restore.xml").unwrap(); - let object = - >>::deserialize_response( - xml.as_str(), - ) - .unwrap(); - - let ext = object.extension.unwrap(); - - assert_eq!(object.result.code, 1000); - assert_eq!(object.result.message, SUCCESS_MSG.into()); - assert_eq!(ext.data.rgp_status[0].status, "pendingRestore".to_string()); - assert_eq!(object.tr_ids.server_tr_id, SVTRID.into()); - } - - #[test] - fn rgp_restore_domain_info_response() { - let xml = get_xml("response/extensions/domain_info_rgp.xml").unwrap(); - let object = - >>::deserialize_response( - xml.as_str(), - ) - .unwrap(); - - let ext = object.extension.unwrap(); - - assert_eq!(ext.data.rgp_status[0].status, "addPeriod"); - assert_eq!(ext.data.rgp_status[1].status, "renewPeriod"); - } - - #[test] - fn namestore() { - let xml = get_xml("response/extensions/namestore.xml").unwrap(); - - let object = - >::deserialize_response(xml.as_str()).unwrap(); - - let ext = object.extension.unwrap(); - - assert_eq!(ext.data.subproduct, "com".into()); - } -} diff --git a/epp-client/src/tests/mod.rs b/epp-client/src/tests/mod.rs index 57d9bed..70baa09 100644 --- a/epp-client/src/tests/mod.rs +++ b/epp-client/src/tests/mod.rs @@ -1,16 +1,17 @@ //! Module for automated tests -pub mod de; pub mod se; use regex::Regex; use std::{error::Error, fs::File, io::Read}; -const RESOURCES_DIR: &str = "./test/resources"; -const CLTRID: &str = "cltrid:1626454866"; +pub(crate) const RESOURCES_DIR: &str = "./test/resources"; +pub(crate) const CLTRID: &str = "cltrid:1626454866"; +pub(crate) const SVTRID: &str = "RO-6879-1627224678242975"; +pub(crate) const SUCCESS_MSG: &str = "Command completed successfully"; /// Reads EPP XML requests and responses from the test/resources directory to run tests on -fn get_xml(path: &str) -> Result> { +pub(crate) fn get_xml(path: &str) -> Result> { let ws_regex = Regex::new(r"[\s]{2,}")?; let mut f = File::open(format!("{}/{}", RESOURCES_DIR, path))?;