From eafbe4c647b144bb98036b9212c43b9ee2a23062 Mon Sep 17 00:00:00 2001 From: Ritesh Chitlangi Date: Mon, 26 Jul 2021 02:26:02 +0800 Subject: [PATCH] added some response deserialization tests --- epp-client/examples/client.rs | 14 +- epp-client/src/connection/client.rs | 10 +- epp-client/src/connection/registry.rs | 6 +- epp-client/src/epp/object/data.rs | 20 +- epp-client/src/epp/response.rs | 17 +- epp-client/src/epp/response/contact/check.rs | 5 +- epp-client/src/epp/response/contact/create.rs | 4 +- epp-client/src/epp/response/contact/info.rs | 5 +- epp-client/src/epp/response/domain/check.rs | 4 + epp-client/src/epp/response/domain/create.rs | 2 + epp-client/src/epp/response/domain/info.rs | 2 + epp-client/src/epp/response/domain/renew.rs | 2 + .../src/epp/response/domain/transfer.rs | 2 + epp-client/src/epp/xml.rs | 3 + epp-client/src/lib.rs | 485 +----------------- epp-client/src/tests/de.rs | 312 +++++++++++ epp-client/src/tests/mod.rs | 27 + epp-client/src/tests/se.rs | 485 ++++++++++++++++++ .../test/resources/response/contact/check.xml | 22 + .../resources/response/contact/create.xml | 18 + .../resources/response/contact/delete.xml | 18 + .../test/resources/response/contact/info.xml | 42 ++ .../resources/response/contact/update.xml | 18 + .../test/resources/response/domain/check.xml | 22 + .../test/resources/response/domain/create.xml | 25 + .../test/resources/response/domain/delete.xml | 18 + epp-client/test/resources/response/error.xml | 18 + .../test/resources/response/greeting.xml | 40 ++ epp-client/test/resources/response/login.xml | 12 + epp-client/test/resources/response/logout.xml | 12 + 30 files changed, 1155 insertions(+), 515 deletions(-) create mode 100644 epp-client/src/tests/de.rs create mode 100644 epp-client/src/tests/mod.rs create mode 100644 epp-client/src/tests/se.rs create mode 100644 epp-client/test/resources/response/contact/check.xml create mode 100644 epp-client/test/resources/response/contact/create.xml create mode 100644 epp-client/test/resources/response/contact/delete.xml create mode 100644 epp-client/test/resources/response/contact/info.xml create mode 100644 epp-client/test/resources/response/contact/update.xml create mode 100644 epp-client/test/resources/response/domain/check.xml create mode 100644 epp-client/test/resources/response/domain/create.xml create mode 100644 epp-client/test/resources/response/domain/delete.xml create mode 100644 epp-client/test/resources/response/error.xml create mode 100644 epp-client/test/resources/response/greeting.xml create mode 100644 epp-client/test/resources/response/login.xml create mode 100644 epp-client/test/resources/response/logout.xml diff --git a/epp-client/examples/client.rs b/epp-client/examples/client.rs index fb3e35e..17a1433 100644 --- a/epp-client/examples/client.rs +++ b/epp-client/examples/client.rs @@ -39,7 +39,7 @@ async fn create_contact(client: &mut EppClient) { let mut fax = Phone::new("+47.86698799"); fax.set_extension("677"); - let mut contact_create = EppContactCreate::new("eppdev-contact-3", "contact@eppdev.net", postal_info, voice, "eppdev-387323", gen_client_tr_id("eppdev").unwrap().as_str()); + let mut contact_create = EppContactCreate::new("eppdev-contact-4", "contact@eppdev.net", postal_info, voice, "eppdev-387323", gen_client_tr_id("eppdev").unwrap().as_str()); contact_create.set_fax(fax); client.transact::<_, EppContactCreateResponse>(&contact_create).await.unwrap(); @@ -59,13 +59,13 @@ async fn update_contact(client: &mut EppClient) { } async fn query_contact(client: &mut EppClient) { - let mut contact_info = EppContactInfo::new("eppdev-contact-2", "eppdev-387323", gen_client_tr_id("eppdev").unwrap().as_str()); + let mut contact_info = EppContactInfo::new("eppdev-contact-11", "eppdev-387323", gen_client_tr_id("eppdev").unwrap().as_str()); client.transact::<_, EppContactInfoResponse>(&contact_info).await.unwrap(); } async fn delete_contact(client: &mut EppClient) { - let contact_delete = EppContactDelete::new("eppdev-contact-1", gen_client_tr_id("eppdev").unwrap().as_str()); + let contact_delete = EppContactDelete::new("eppdev-contact-4", gen_client_tr_id("eppdev").unwrap().as_str()); client.transact::<_, EppContactDeleteResponse>(&contact_delete).await.unwrap(); } @@ -87,7 +87,7 @@ async fn create_domain(client: &mut EppClient) { ]; // let domain_create = EppDomainCreate::new_with_ns("eppdev.com", 1, vec!["ns1.test.com", "ns2.test.com"], "eppdev-contact-1", "eppdevauth123", contacts, gen_client_tr_id("eppdev").unwrap().as_str()); - let domain_create = EppDomainCreate::new("eppdev-1.com", 1, "eppdev-contact-2", "epP4uthd#v", contacts, gen_client_tr_id("eppdev").unwrap().as_str()); + let domain_create = EppDomainCreate::new("eppdev-2.com", 1, "eppdev-contact-2", "epP4uthd#v", contacts, gen_client_tr_id("eppdev").unwrap().as_str()); client.transact::<_, EppDomainCreateResponse>(&domain_create).await.unwrap(); } @@ -144,7 +144,7 @@ async fn update_domain(client: &mut EppClient) { } async fn delete_domain(client: &mut EppClient) { - let domain_delete = EppDomainDelete::new("eppdev.com", gen_client_tr_id("eppdev").unwrap().as_str()); + let domain_delete = EppDomainDelete::new("eppdev-2.com", gen_client_tr_id("eppdev").unwrap().as_str()); client.transact::<_, EppDomainDeleteResponse>(&domain_delete).await.unwrap(); } @@ -280,7 +280,7 @@ async fn main() { // hello(&mut client).await; - check_domains(&mut client).await; + // check_domains(&mut client).await; // check_contacts(&mut client).await; @@ -298,7 +298,7 @@ async fn main() { // update_domain(&mut client).await; - // delete_domain(&mut client).await; + delete_domain(&mut client).await; // renew_domain(&mut client).await; diff --git a/epp-client/src/connection/client.rs b/epp-client/src/connection/client.rs index 46b7937..1b1263c 100644 --- a/epp-client/src/connection/client.rs +++ b/epp-client/src/connection/client.rs @@ -37,7 +37,7 @@ use crate::config::CONFIG; use crate::connection::registry::{epp_connect, EppConnection}; use crate::error; use crate::epp::request::{generate_client_tr_id, EppHello, EppLogin, EppLogout}; -use crate::epp::response::{EppGreeting, EppCommandResponseStatus, EppCommandResponse, EppCommandResponseError}; +use crate::epp::response::{EppGreeting, EppCommandResponse, EppLoginResponse, EppLogoutResponse, EppCommandResponseError}; use crate::epp::xml::EppXml; /// Connects to the registry and returns an logged-in instance of EppClient for further transactions @@ -128,7 +128,7 @@ impl EppClient { let client_tr_id = generate_client_tr_id(&client.credentials.0)?; let login_request = EppLogin::new(&client.credentials.0, &client.credentials.1, &client.ext_uris, client_tr_id.as_str()); - client.transact::<_, EppCommandResponse>(&login_request).await?; + client.transact::<_, EppLoginResponse>(&login_request).await?; Ok(client) } @@ -150,7 +150,7 @@ impl EppClient { let response = self.connection.transact(&epp_xml).await?; - let status = EppCommandResponseStatus::deserialize(&response)?; + let status = EppCommandResponse::deserialize(&response)?; if status.data.result.code < 2000 { let response = E::deserialize(&response)?; @@ -178,11 +178,11 @@ impl EppClient { } /// Sends the EPP Logout command to log out of the EPP session - pub async fn logout(&mut self) -> Result { + pub async fn logout(&mut self) -> Result { let client_tr_id = generate_client_tr_id(&self.credentials.0).unwrap(); let epp_logout = EppLogout::new(client_tr_id.as_str()); - self.transact::<_, EppCommandResponse>(&epp_logout).await + self.transact::<_, EppLogoutResponse>(&epp_logout).await } } diff --git a/epp-client/src/connection/registry.rs b/epp-client/src/connection/registry.rs index acd504a..bad8e3d 100644 --- a/epp-client/src/connection/registry.rs +++ b/epp-client/src/connection/registry.rs @@ -32,7 +32,9 @@ impl EppConnection { mut stream: ConnectionStream) -> Result> { let mut buf = vec![0u8; 4096]; stream.reader.read(&mut buf).await?; - let greeting = str::from_utf8(&buf)?.to_string(); + let greeting = str::from_utf8(&buf[4..])?.to_string(); + + debug!("{}: greeting: {}", registry, greeting); Ok(EppConnection { registry: registry, @@ -113,7 +115,7 @@ impl EppConnection { self.send_epp_request(&content).await?; let response = self.get_epp_response().await?; - debug!("{}: request: {}", self.registry, response); + debug!("{}: response: {}", self.registry, response); Ok(response) } diff --git a/epp-client/src/epp/object/data.rs b/epp-client/src/epp/object/data.rs index 45667ab..c865784 100644 --- a/epp-client/src/epp/object/data.rs +++ b/epp-client/src/epp/object/data.rs @@ -139,25 +139,25 @@ pub struct Phone { pub number: String, /// The value of the 'x' attr on and tags #[serde(rename = "x")] - extension: Option, + pub extension: Option, } /// The type on contact transactions #[derive(Serialize, Deserialize, Debug, Clone)] pub struct Address { /// The tags under - street: Vec, + pub street: Vec, /// The tag under - city: StringValue, + pub city: StringValue, /// The tag under #[serde(rename = "sp")] - province: StringValue, + pub province: StringValue, /// The tag under #[serde(rename = "pc")] - postal_code: StringValue, + pub postal_code: StringValue, /// The tag under #[serde(rename = "cc")] - country_code: StringValue, + pub country_code: StringValue, } /// The type on contact transactions @@ -165,15 +165,15 @@ pub struct Address { pub struct PostalInfo { /// The 'type' attr on #[serde(rename = "type")] - info_type: String, + pub info_type: String, /// The tag under - name: StringValue, + pub name: StringValue, /// The tag under #[serde(rename = "org")] - organization: StringValue, + pub organization: StringValue, /// The tag under #[serde(rename = "addr")] - address: Address, + pub address: Address, } /// The tag for domain and contact transactions diff --git a/epp-client/src/epp/response.rs b/epp-client/src/epp/response.rs index 55084a0..2a53029 100644 --- a/epp-client/src/epp/response.rs +++ b/epp-client/src/epp/response.rs @@ -11,10 +11,10 @@ use crate::epp::object::{ }; pub type EppGreeting = EppObject; -pub type EppCommandResponseStatus = EppObject; -type CommandResponseError = CommandResponseStatus; -pub type EppCommandResponseError = EppObject; -pub type EppCommandResponse = EppObject>; +pub type EppCommandResponse = EppObject; +pub type EppCommandResponseError = EppCommandResponse; +pub type EppLoginResponse = EppCommandResponse; +pub type EppLogoutResponse = EppCommandResponse; #[derive(Serialize, Debug, PartialEq)] pub struct ServiceMenu { @@ -183,3 +183,12 @@ pub struct CommandResponseStatus { #[serde(rename = "trID")] pub tr_ids: ResponseTRID, } + +impl CommandResponse { + pub fn results(&self) -> Option<&T> { + match &self.res_data { + Some(res_data) => Some(&res_data), + None => None, + } + } +} diff --git a/epp-client/src/epp/response/contact/check.rs b/epp-client/src/epp/response/contact/check.rs index 82d6d5d..6e048be 100644 --- a/epp-client/src/epp/response/contact/check.rs +++ b/epp-client/src/epp/response/contact/check.rs @@ -15,7 +15,8 @@ pub struct ContactCheck { #[derive(Serialize, Deserialize, Debug)] pub struct ContactCheckDataItem { - pub id: ContactCheck, + #[serde(rename = "id")] + pub contact: ContactCheck, pub reason: Option, } @@ -23,6 +24,8 @@ pub struct ContactCheckDataItem { pub struct ContactCheckData { #[serde(rename = "xmlns:contact")] xmlns: String, + #[serde(rename = "xsi:schemaLocation")] + schema_location: String, #[serde(rename = "cd")] pub contact_list: Vec, } diff --git a/epp-client/src/epp/response/contact/create.rs b/epp-client/src/epp/response/contact/create.rs index 62f2d27..919b328 100644 --- a/epp-client/src/epp/response/contact/create.rs +++ b/epp-client/src/epp/response/contact/create.rs @@ -9,6 +9,8 @@ pub type EppContactCreateResponse = EppObject>; pub struct ContactInfoData { #[serde(rename = "xmlns:contact")] xmlns: String, + #[serde(rename = "xsi:schemaLocation")] + schema_location: String, pub id: StringValue, pub roid: StringValue, - pub status: Vec, + #[serde(rename = "status")] + pub statuses: Vec, #[serde(rename = "postalInfo")] pub postal_info: PostalInfo, pub voice: Phone, diff --git a/epp-client/src/epp/response/domain/check.rs b/epp-client/src/epp/response/domain/check.rs index 9b2ebf8..1a1fdb3 100644 --- a/epp-client/src/epp/response/domain/check.rs +++ b/epp-client/src/epp/response/domain/check.rs @@ -22,6 +22,10 @@ pub struct DomainCheckDataItem { #[derive(Serialize, Deserialize, Debug)] pub struct DomainCheckData { + #[serde(rename = "xmlns:domain")] + xmlns: String, + #[serde(rename = "xsi:schemaLocation")] + schema_location: String, #[serde(rename = "cd")] pub domain_list: Vec, } diff --git a/epp-client/src/epp/response/domain/create.rs b/epp-client/src/epp/response/domain/create.rs index b3a433c..473d833 100644 --- a/epp-client/src/epp/response/domain/create.rs +++ b/epp-client/src/epp/response/domain/create.rs @@ -9,6 +9,8 @@ pub type EppDomainCreateResponse = EppObject pub struct DomainCreateData { #[serde(rename = "xmlns:domain")] xmlns: String, + #[serde(rename = "xsi:schemaLocation")] + schema_location: String, pub name: StringValue, #[serde(rename = "crDate")] pub created_at: StringValue, diff --git a/epp-client/src/epp/response/domain/info.rs b/epp-client/src/epp/response/domain/info.rs index b2aa44d..55546bd 100644 --- a/epp-client/src/epp/response/domain/info.rs +++ b/epp-client/src/epp/response/domain/info.rs @@ -24,6 +24,8 @@ pub struct DomainCheckDataItem { pub struct DomainInfoData { #[serde(rename = "xmlns:domain")] xmlns: String, + #[serde(rename = "xsi:schemaLocation")] + schema_location: String, pub name: StringValue, pub roid: StringValue, pub status: Vec, diff --git a/epp-client/src/epp/response/domain/renew.rs b/epp-client/src/epp/response/domain/renew.rs index 8e2bc0d..2c225d9 100644 --- a/epp-client/src/epp/response/domain/renew.rs +++ b/epp-client/src/epp/response/domain/renew.rs @@ -9,6 +9,8 @@ pub type EppDomainRenewResponse = EppObject>; pub struct DomainRenewData { #[serde(rename = "xmlns:domain")] xmlns: String, + #[serde(rename = "xsi:schemaLocation")] + schema_location: String, pub name: StringValue, #[serde(rename = "exDate")] pub expiry_date: StringValue, diff --git a/epp-client/src/epp/response/domain/transfer.rs b/epp-client/src/epp/response/domain/transfer.rs index 58e029e..8bdb3cd 100644 --- a/epp-client/src/epp/response/domain/transfer.rs +++ b/epp-client/src/epp/response/domain/transfer.rs @@ -14,6 +14,8 @@ pub type EppDomainTransferQueryResponse = EppObject Result> { - let ws_regex = Regex::new(r"[\s]{2,}")?; - - let mut f = File::open(format!("{}/{}", RESOURCES_DIR, path))?; - let mut buf = String::new(); - - f.read_to_string(&mut buf)?; - if buf.len() > 0 { - let mat = Regex::new(r"\?>").unwrap().find(&buf.as_str()).unwrap(); - let start = mat.end(); - buf = format!("{}\r\n{}", &buf[..start], ws_regex.replace_all(&buf[start..], "")); - } - Ok(buf) - } - - mod se { - mod request { - use chrono::NaiveDate; - use crate::tests::get_xml; - use crate::epp::object::StringValueTrait; - use crate::epp::object::data::{ - Phone, Address, PostalInfo, ContactStatus, DomainContact, HostAttr, HostAddr, - DomainStatus, AuthInfo, Host, HostStatus - }; - use crate::epp::request::{EppHello, EppLogin, EppLogout}; - use crate::epp::xml::EppXml; - use crate::epp::*; - - const CLTRID: &str = "cltrid:1626454866"; - - #[test] - fn hello() { - let xml = get_xml("request/hello.xml").unwrap(); - let object = EppHello::new(); - let serialized = object.serialize().unwrap(); - - assert_eq!(xml, serialized); - } - - #[test] - fn login() { - let ext_uris = Some(vec![ - "http://schema.ispapi.net/epp/xml/keyvalue-1.0".to_string() - ]); - - let xml = get_xml("request/login.xml").unwrap(); - let object = EppLogin::new("username", "password", &ext_uris, CLTRID); - let serialized = object.serialize().unwrap(); - - assert_eq!(xml, serialized); - } - - #[test] - fn logout() { - let xml = get_xml("request/logout.xml").unwrap(); - let object = EppLogout::new(CLTRID); - let serialized = object.serialize().unwrap(); - - assert_eq!(xml, serialized); - } - - #[test] - fn contact_check() { - let xml = get_xml("request/contact/check.xml").unwrap(); - let object = EppContactCheck::new(vec!["eppdev-contact-1", "eppdev-contact-2"], CLTRID); - let serialized = object.serialize().unwrap(); - - assert_eq!(xml, serialized); - } - - #[test] - fn contact_create() { - let xml = get_xml("request/contact/create.xml").unwrap(); - - let street = vec!["58", "Orchid Road"]; - let address = Address::new(street, "Paris", "Paris", "392374", "FR"); - let postal_info = PostalInfo::new("int", "John Doe", "Acme Widgets", address); - let mut voice = Phone::new("+33.47237942"); - voice.set_extension("123"); - let mut fax = Phone::new("+33.86698799"); - fax.set_extension("677"); - - let mut object = EppContactCreate::new("eppdev-contact-3", "contact@eppdev.net", postal_info, voice, "eppdev-387323", CLTRID); - object.set_fax(fax); - - let serialized = object.serialize().unwrap(); - - assert_eq!(xml, serialized); - } - - #[test] - fn contact_info() { - let xml = get_xml("request/contact/info.xml").unwrap(); - - let object = EppContactInfo::new("eppdev-contact-3", "eppdev-387323", CLTRID); - - let serialized = object.serialize().unwrap(); - - assert_eq!(xml, serialized); - } - - #[test] - fn contact_update() { - let xml = get_xml("request/contact/update.xml").unwrap(); - - let mut object = EppContactUpdate::new("eppdev-contact-3", CLTRID); - - let street = vec!["58", "Orchid Road"]; - let address = Address::new(street, "Paris", "Paris", "392374", "FR"); - let postal_info = PostalInfo::new("loc", "John Doe", "Acme Widgets", address); - let voice = Phone::new("+33.47237942"); - - object.set_info("newemail@eppdev.net", postal_info, voice, "eppdev-387323"); - let add_statuses = vec![ContactStatus { status: "clientTransferProhibited".to_string() }]; - object.add_statuses(add_statuses); - let remove_statuses = vec![ContactStatus { status: "clientDeleteProhibited".to_string() }]; - object.remove_statuses(remove_statuses); - - let serialized = object.serialize().unwrap(); - - assert_eq!(xml, serialized); - } - - #[test] - fn contact_delete() { - let xml = get_xml("request/contact/delete.xml").unwrap(); - - let object = EppContactDelete::new("eppdev-contact-3", CLTRID); - - let serialized = object.serialize().unwrap(); - - assert_eq!(xml, serialized); - } - - #[test] - fn domain_check() { - let xml = get_xml("request/domain/check.xml").unwrap(); - - let object = EppDomainCheck::new(vec!["eppdev.com", "eppdev.net"], CLTRID); - - let serialized = object.serialize().unwrap(); - - assert_eq!(xml, serialized); - } - - #[test] - fn domain_create() { - let xml = get_xml("request/domain/create.xml").unwrap(); - - let contacts = vec![ - DomainContact { - contact_type: "admin".to_string(), - id: "eppdev-contact-3".to_string() - }, - DomainContact { - contact_type: "tech".to_string(), - id: "eppdev-contact-3".to_string() - }, - DomainContact { - contact_type: "billing".to_string(), - id: "eppdev-contact-3".to_string() - } - ]; - - let object = EppDomainCreate::new("eppdev-1.com", 1, "eppdev-contact-3", "epP4uthd#v", contacts, CLTRID); - - let serialized = object.serialize().unwrap(); - - assert_eq!(xml, serialized); - } - - #[test] - fn domain_create_with_host_obj() { - let xml = get_xml("request/domain/create_with_host_obj.xml").unwrap(); - - let contacts = vec![ - DomainContact { - contact_type: "admin".to_string(), - id: "eppdev-contact-3".to_string() - }, - DomainContact { - contact_type: "tech".to_string(), - id: "eppdev-contact-3".to_string() - }, - DomainContact { - contact_type: "billing".to_string(), - id: "eppdev-contact-3".to_string() - } - ]; - - let object = EppDomainCreate::new_with_ns("eppdev-1.com", 1, vec!["ns1.test.com", "ns2.test.com"], "eppdev-contact-3", "epP4uthd#v", contacts, CLTRID); - - let serialized = object.serialize().unwrap(); - - assert_eq!(xml, serialized); - } - - #[test] - fn domain_create_with_host_attr() { - let xml = get_xml("request/domain/create_with_host_attr.xml").unwrap(); - - let contacts = vec![ - DomainContact { - contact_type: "admin".to_string(), - id: "eppdev-contact-3".to_string() - }, - DomainContact { - contact_type: "tech".to_string(), - id: "eppdev-contact-3".to_string() - }, - DomainContact { - contact_type: "billing".to_string(), - id: "eppdev-contact-3".to_string() - } - ]; - - let host_attr = vec![ - HostAttr { - name: "ns1.eppdev-1.com".to_string_value(), - addresses: None, - }, - HostAttr { - name: "ns2.eppdev-1.com".to_string_value(), - addresses: Some(vec![ - HostAddr::new_v4("177.232.12.58"), - HostAddr::new_v6("2404:6800:4001:801::200e"), - ]) - } - ]; - - let object = EppDomainCreate::new_with_host_attr("eppdev-2.com", 1, host_attr, "eppdev-contact-3", "epP4uthd#v", contacts, CLTRID); - - let serialized = object.serialize().unwrap(); - - assert_eq!(xml, serialized); - } - - #[test] - fn domain_info() { - let xml = get_xml("request/domain/info.xml").unwrap(); - - let object = EppDomainInfo::new("eppdev.com", CLTRID); - - let serialized = object.serialize().unwrap(); - - assert_eq!(xml, serialized); - } - - #[test] - fn domain_update() { - let xml = get_xml("request/domain/update.xml").unwrap(); - - let mut object = EppDomainUpdate::new("eppdev.com", CLTRID); - - let add = DomainAddRemove { - ns: None, - contacts: None, - statuses: Some(vec![ - DomainStatus { - status: "clientDeleteProhibited".to_string() - } - ]) - }; - - let remove = DomainAddRemove { - ns: None, - contacts: Some(vec![ - DomainContact { - contact_type: "billing".to_string(), - id: "eppdev-contact-2".to_string() - } - ]), - statuses: None, - }; - - let change_info = DomainChangeInfo { - registrant: None, - auth_info: Some(AuthInfo::new("epP5uthd#v")), - }; - - object.add(add); - object.remove(remove); - object.info(change_info); - - let serialized = object.serialize().unwrap(); - - assert_eq!(xml, serialized); - } - - #[test] - fn domain_delete() { - let xml = get_xml("request/domain/delete.xml").unwrap(); - - let object = EppDomainDelete::new("eppdev.com", CLTRID); - - let serialized = object.serialize().unwrap(); - - assert_eq!(xml, serialized); - } - - #[test] - fn domain_renew() { - let xml = get_xml("request/domain/renew.xml").unwrap(); - - let exp_date = NaiveDate::from_ymd(2022, 7, 23); - let object = EppDomainRenew::new("eppdev.com", exp_date, 1, CLTRID); - - let serialized = object.serialize().unwrap(); - - assert_eq!(xml, serialized); - } - - #[test] - fn domain_transfer_request() { - let xml = get_xml("request/domain/transfer_request.xml").unwrap(); - - let object = EppDomainTransferRequest::request("testing.com", 1, "epP4uthd#v", CLTRID); - - let serialized = object.serialize().unwrap(); - - assert_eq!(xml, serialized); - } - - #[test] - fn domain_transfer_approve() { - let xml = get_xml("request/domain/transfer_approve.xml").unwrap(); - - let object = EppDomainTransferApprove::approve("testing.com", CLTRID); - - let serialized = object.serialize().unwrap(); - - assert_eq!(xml, serialized); - } - - #[test] - fn domain_transfer_reject() { - let xml = get_xml("request/domain/transfer_reject.xml").unwrap(); - - let object = EppDomainTransferReject::reject("testing.com", CLTRID); - - let serialized = object.serialize().unwrap(); - - assert_eq!(xml, serialized); - } - - #[test] - fn domain_transfer_cancel() { - let xml = get_xml("request/domain/transfer_cancel.xml").unwrap(); - - let object = EppDomainTransferCancel::cancel("testing.com", CLTRID); - - let serialized = object.serialize().unwrap(); - - assert_eq!(xml, serialized); - } - - #[test] - fn domain_transfer_query() { - let xml = get_xml("request/domain/transfer_query.xml").unwrap(); - - let object = EppDomainTransferQuery::query("testing.com", "epP4uthd#v", CLTRID); - - let serialized = object.serialize().unwrap(); - - assert_eq!(xml, serialized); - } - - #[test] - fn host_check() { - let xml = get_xml("request/host/check.xml").unwrap(); - - let object = EppHostCheck::new(vec!["ns1.eppdev-1.com", "host1.eppdev-1.com"], CLTRID); - - let serialized = object.serialize().unwrap(); - - assert_eq!(xml, serialized); - } - - #[test] - fn host_create() { - let xml = get_xml("request/host/create.xml").unwrap(); - - let host = Host { - name: "host1.eppdev-1.com".to_string_value(), - addresses: Some(vec![ - HostAddr::new("v4", "29.245.122.14"), - HostAddr::new("v6", "2404:6800:4001:801::200e"), - ]) - }; - - let object = EppHostCreate::new(host, CLTRID); - - let serialized = object.serialize().unwrap(); - - assert_eq!(xml, serialized); - } - - #[test] - fn host_info() { - let xml = get_xml("request/host/info.xml").unwrap(); - - let object = EppHostInfo::new("ns1.eppdev-1.com", CLTRID); - - let serialized = object.serialize().unwrap(); - - assert_eq!(xml, serialized); - } - - #[test] - fn host_update() { - let xml = get_xml("request/host/update.xml").unwrap(); - - let addr = vec![ - HostAddr::new("v6", "2404:6800:4001:801::200e"), - ]; - - let add = HostAddRemove { - addresses: Some(addr), - statuses: None, - }; - - let remove = HostAddRemove { - addresses: None, - statuses: Some(vec![ - HostStatus { - status: "clientDeleteProhibited".to_string() - } - ]), - }; - - let mut object = EppHostUpdate::new("host1.eppdev-1.com", CLTRID); - - object.add(add); - object.remove(remove); - object.info(HostChangeInfo { name: "host2.eppdev-1.com".to_string_value() }); - - let serialized = object.serialize().unwrap(); - - assert_eq!(xml, serialized); - } - - #[test] - fn host_delete() { - let xml = get_xml("request/host/delete.xml").unwrap(); - - let object = EppHostDelete::new("ns1.eppdev-1.com", CLTRID); - - let serialized = object.serialize().unwrap(); - - assert_eq!(xml, serialized); - } - - #[test] - fn message_poll() { - let xml = get_xml("request/message/poll.xml").unwrap(); - - let object = EppMessagePoll::new(CLTRID); - - let serialized = object.serialize().unwrap(); - - assert_eq!(xml, serialized); - } - - #[test] - fn message_ack() { - let xml = get_xml("request/message/ack.xml").unwrap(); - - let object = EppMessageAck::new(12345, CLTRID); - - let serialized = object.serialize().unwrap(); - - assert_eq!(xml, serialized); - } - } - } -} +pub mod tests; diff --git a/epp-client/src/tests/de.rs b/epp-client/src/tests/de.rs new file mode 100644 index 0000000..dbd0342 --- /dev/null +++ b/epp-client/src/tests/de.rs @@ -0,0 +1,312 @@ +mod response { + use super::super::get_xml; + use super::super::CLTRID; + use crate::epp::object::StringValueTrait; + use crate::epp::response::{ + EppCommandResponse, EppCommandResponseError, EppGreeting, EppLoginResponse, + EppLogoutResponse, + }; + use crate::epp::xml::EppXml; + use crate::epp::*; + + 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 = EppGreeting::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".to_string_value() + ); + assert_eq!(object.data.svc_menu.options.lang, "en".to_string_value()); + 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 + ); + } + + #[test] + fn error() { + let xml = get_xml("response/error.xml").unwrap(); + let object = EppCommandResponseError::deserialize(xml.as_str()).unwrap(); + + assert_eq!(object.data.result.code, 2303); + assert_eq!( + object.data.result.message, + "Object does not exist".to_string_value() + ); + assert_eq!( + object.data.result.ext_value.unwrap().reason, + "545 Object not found".to_string_value() + ); + assert_eq!( + object.data.tr_ids.client_tr_id.unwrap(), + CLTRID.to_string_value() + ); + assert_eq!(object.data.tr_ids.server_tr_id, SVTRID.to_string_value()); + } + + #[test] + fn login() { + let xml = get_xml("response/login.xml").unwrap(); + let object = EppLoginResponse::deserialize(xml.as_str()).unwrap(); + + assert_eq!(object.data.result.code, 1000); + assert_eq!(object.data.result.message, SUCCESS_MSG.to_string_value()); + assert_eq!( + object.data.tr_ids.client_tr_id.unwrap(), + CLTRID.to_string_value() + ); + assert_eq!(object.data.tr_ids.server_tr_id, SVTRID.to_string_value()); + } + + #[test] + fn logout() { + let xml = get_xml("response/logout.xml").unwrap(); + let object = EppLogoutResponse::deserialize(xml.as_str()).unwrap(); + + assert_eq!(object.data.result.code, 1500); + assert_eq!( + object.data.result.message, + "Command completed successfully; ending session".to_string_value() + ); + assert_eq!( + object.data.tr_ids.client_tr_id.unwrap(), + CLTRID.to_string_value() + ); + assert_eq!(object.data.tr_ids.server_tr_id, SVTRID.to_string_value()); + } + + #[test] + fn contact_check() { + let xml = get_xml("response/contact/check.xml").unwrap(); + let object = EppContactCheckResponse::deserialize(xml.as_str()).unwrap(); + + let results = object.data.results().unwrap(); + + assert_eq!(object.data.result.code, 1000); + assert_eq!(object.data.result.message, SUCCESS_MSG.to_string_value()); + assert_eq!( + results.check_data.contact_list[0].contact.id, + "eppdev-contact-1".to_string_value() + ); + assert_eq!(results.check_data.contact_list[0].contact.available, 0); + assert_eq!( + results.check_data.contact_list[1].contact.id, + "eppdev-contact-2".to_string_value() + ); + assert_eq!(results.check_data.contact_list[1].contact.available, 1); + assert_eq!( + object.data.tr_ids.client_tr_id.unwrap(), + CLTRID.to_string_value() + ); + assert_eq!(object.data.tr_ids.server_tr_id, SVTRID.to_string_value()); + } + + #[test] + fn contact_create() { + let xml = get_xml("response/contact/create.xml").unwrap(); + let object = EppContactCreateResponse::deserialize(xml.as_str()).unwrap(); + + let results = object.data.results().unwrap(); + + assert_eq!(object.data.result.code, 1000); + assert_eq!(object.data.result.message, SUCCESS_MSG.to_string_value()); + assert_eq!(results.create_data.id, "eppdev-contact-4".to_string_value()); + assert_eq!( + results.create_data.created_at, + "2021-07-25T16:05:32.0Z".to_string_value() + ); + assert_eq!( + object.data.tr_ids.client_tr_id.unwrap(), + CLTRID.to_string_value() + ); + assert_eq!(object.data.tr_ids.server_tr_id, SVTRID.to_string_value()); + } + + #[test] + fn contact_delete() { + let xml = get_xml("response/contact/delete.xml").unwrap(); + let object = EppContactDeleteResponse::deserialize(xml.as_str()).unwrap(); + + assert_eq!(object.data.result.code, 1000); + assert_eq!(object.data.result.message, SUCCESS_MSG.to_string_value()); + assert_eq!( + object.data.tr_ids.client_tr_id.unwrap(), + CLTRID.to_string_value() + ); + assert_eq!(object.data.tr_ids.server_tr_id, SVTRID.to_string_value()); + } + + #[test] + fn contact_info() { + let xml = get_xml("response/contact/info.xml").unwrap(); + let object = EppContactInfoResponse::deserialize(xml.as_str()).unwrap(); + + let result = object.data.results().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.data.result.code, 1000); + assert_eq!(object.data.result.message, SUCCESS_MSG.to_string_value()); + assert_eq!(result.info_data.id, "eppdev-contact-3".to_string_value()); + assert_eq!(result.info_data.roid, "UNDEF-ROID".to_string_value()); + 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".to_string_value() + ); + assert_eq!( + result.info_data.postal_info.organization, + "Acme Widgets".to_string_value() + ); + assert_eq!( + result.info_data.postal_info.address.street[0], + "58".to_string_value() + ); + assert_eq!( + result.info_data.postal_info.address.street[1], + "Orchid Road".to_string_value() + ); + assert_eq!( + result.info_data.postal_info.address.city, + "Paris".to_string_value() + ); + assert_eq!( + result.info_data.postal_info.address.province, + "Paris".to_string_value() + ); + assert_eq!( + result.info_data.postal_info.address.postal_code, + "392374".to_string_value() + ); + assert_eq!( + result.info_data.postal_info.address.country_code, + "FR".to_string_value() + ); + 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".to_string_value() + ); + assert_eq!(result.info_data.client_id, "eppdev".to_string_value()); + assert_eq!(result.info_data.creator_id, "SYSTEM".to_string_value()); + assert_eq!( + result.info_data.created_at, + "2021-07-23T13:09:09.0Z".to_string_value() + ); + assert_eq!( + *(result.info_data.updater_id.as_ref().unwrap()), + "SYSTEM".to_string_value() + ); + assert_eq!( + *(result.info_data.updated_at.as_ref().unwrap()), + "2021-07-23T13:09:09.0Z".to_string_value() + ); + assert_eq!((*auth_info).password, "eppdev-387323".to_string_value()); + assert_eq!( + object.data.tr_ids.client_tr_id.unwrap(), + CLTRID.to_string_value() + ); + assert_eq!(object.data.tr_ids.server_tr_id, SVTRID.to_string_value()); + } + + #[test] + fn contact_update() { + let xml = get_xml("response/contact/update.xml").unwrap(); + let object = EppContactUpdateResponse::deserialize(xml.as_str()).unwrap(); + + assert_eq!(object.data.result.code, 1000); + assert_eq!(object.data.result.message, SUCCESS_MSG.to_string_value()); + assert_eq!( + object.data.tr_ids.client_tr_id.unwrap(), + CLTRID.to_string_value() + ); + assert_eq!(object.data.tr_ids.server_tr_id, SVTRID.to_string_value()); + } + + #[test] + fn domain_check() { + let xml = get_xml("response/domain/check.xml").unwrap(); + let object = EppDomainCheckResponse::deserialize(xml.as_str()).unwrap(); + + let result = object.data.results().unwrap(); + + assert_eq!(object.data.result.code, 1000); + assert_eq!(object.data.result.message, SUCCESS_MSG.to_string_value()); + assert_eq!( + result.check_data.domain_list[0].domain.name, + "eppdev.com".to_string_value() + ); + assert_eq!(result.check_data.domain_list[0].domain.available, 1); + assert_eq!( + result.check_data.domain_list[1].domain.name, + "eppdev.net".to_string_value() + ); + assert_eq!(result.check_data.domain_list[1].domain.available, 0); + assert_eq!( + object.data.tr_ids.client_tr_id.unwrap(), + CLTRID.to_string_value() + ); + assert_eq!(object.data.tr_ids.server_tr_id, SVTRID.to_string_value()); + } + + #[test] + fn domain_create() { + let xml = get_xml("response/domain/create.xml").unwrap(); + let object = EppDomainCreateResponse::deserialize(xml.as_str()).unwrap(); + + let result = object.data.results().unwrap(); + + assert_eq!(object.data.result.code, 1000); + assert_eq!(object.data.result.message, SUCCESS_MSG.to_string_value()); + assert_eq!(result.create_data.name, "eppdev-2.com".to_string_value()); + assert_eq!( + result.create_data.created_at, + "2021-07-25T18:11:35.0Z".to_string_value() + ); + assert_eq!( + result.create_data.expiry_date, + "2022-07-25T18:11:34.0Z".to_string_value() + ); + assert_eq!( + object.data.tr_ids.client_tr_id.unwrap(), + CLTRID.to_string_value() + ); + assert_eq!(object.data.tr_ids.server_tr_id, SVTRID.to_string_value()); + } + + #[test] + fn domain_delete() { + let xml = get_xml("response/domain/delete.xml").unwrap(); + let object = EppDomainDeleteResponse::deserialize(xml.as_str()).unwrap(); + + assert_eq!(object.data.result.code, 1000); + assert_eq!(object.data.result.message, SUCCESS_MSG.to_string_value()); + assert_eq!( + object.data.tr_ids.client_tr_id.unwrap(), + CLTRID.to_string_value() + ); + assert_eq!(object.data.tr_ids.server_tr_id, SVTRID.to_string_value()); + } +} diff --git a/epp-client/src/tests/mod.rs b/epp-client/src/tests/mod.rs new file mode 100644 index 0000000..3849286 --- /dev/null +++ b/epp-client/src/tests/mod.rs @@ -0,0 +1,27 @@ +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"; + +fn get_xml(path: &str) -> Result> { + let ws_regex = Regex::new(r"[\s]{2,}")?; + + let mut f = File::open(format!("{}/{}", RESOURCES_DIR, path))?; + let mut buf = String::new(); + + f.read_to_string(&mut buf)?; + if buf.len() > 0 { + let mat = Regex::new(r"\?>").unwrap().find(&buf.as_str()).unwrap(); + let start = mat.end(); + buf = format!( + "{}\r\n{}", + &buf[..start], + ws_regex.replace_all(&buf[start..], "") + ); + } + Ok(buf) +} diff --git a/epp-client/src/tests/se.rs b/epp-client/src/tests/se.rs new file mode 100644 index 0000000..4f495b8 --- /dev/null +++ b/epp-client/src/tests/se.rs @@ -0,0 +1,485 @@ +mod request { + use super::super::get_xml; + use super::super::CLTRID; + use crate::epp::object::data::{ + Address, AuthInfo, ContactStatus, DomainContact, DomainStatus, Host, HostAddr, HostAttr, + HostStatus, Phone, PostalInfo, + }; + use crate::epp::object::StringValueTrait; + use crate::epp::request::{EppHello, EppLogin, EppLogout}; + use crate::epp::xml::EppXml; + use crate::epp::*; + use chrono::NaiveDate; + + #[test] + fn hello() { + let xml = get_xml("request/hello.xml").unwrap(); + let object = EppHello::new(); + let serialized = object.serialize().unwrap(); + + assert_eq!(xml, serialized); + } + + #[test] + fn login() { + let ext_uris = Some(vec![ + "http://schema.ispapi.net/epp/xml/keyvalue-1.0".to_string() + ]); + + let xml = get_xml("request/login.xml").unwrap(); + let object = EppLogin::new("username", "password", &ext_uris, CLTRID); + let serialized = object.serialize().unwrap(); + + assert_eq!(xml, serialized); + } + + #[test] + fn logout() { + let xml = get_xml("request/logout.xml").unwrap(); + let object = EppLogout::new(CLTRID); + let serialized = object.serialize().unwrap(); + + assert_eq!(xml, serialized); + } + + #[test] + fn contact_check() { + let xml = get_xml("request/contact/check.xml").unwrap(); + let object = EppContactCheck::new(vec!["eppdev-contact-1", "eppdev-contact-2"], CLTRID); + let serialized = object.serialize().unwrap(); + + assert_eq!(xml, serialized); + } + + #[test] + fn contact_create() { + let xml = get_xml("request/contact/create.xml").unwrap(); + + let street = vec!["58", "Orchid Road"]; + let address = Address::new(street, "Paris", "Paris", "392374", "FR"); + let postal_info = PostalInfo::new("int", "John Doe", "Acme Widgets", address); + let mut voice = Phone::new("+33.47237942"); + voice.set_extension("123"); + let mut fax = Phone::new("+33.86698799"); + fax.set_extension("677"); + + let mut object = EppContactCreate::new( + "eppdev-contact-3", + "contact@eppdev.net", + postal_info, + voice, + "eppdev-387323", + CLTRID, + ); + object.set_fax(fax); + + let serialized = object.serialize().unwrap(); + + assert_eq!(xml, serialized); + } + + #[test] + fn contact_info() { + let xml = get_xml("request/contact/info.xml").unwrap(); + + let object = EppContactInfo::new("eppdev-contact-3", "eppdev-387323", CLTRID); + + let serialized = object.serialize().unwrap(); + + assert_eq!(xml, serialized); + } + + #[test] + fn contact_update() { + let xml = get_xml("request/contact/update.xml").unwrap(); + + let mut object = EppContactUpdate::new("eppdev-contact-3", CLTRID); + + let street = vec!["58", "Orchid Road"]; + let address = Address::new(street, "Paris", "Paris", "392374", "FR"); + let postal_info = PostalInfo::new("loc", "John Doe", "Acme Widgets", address); + let voice = Phone::new("+33.47237942"); + + object.set_info("newemail@eppdev.net", postal_info, voice, "eppdev-387323"); + let add_statuses = vec![ContactStatus { + status: "clientTransferProhibited".to_string(), + }]; + object.add_statuses(add_statuses); + let remove_statuses = vec![ContactStatus { + status: "clientDeleteProhibited".to_string(), + }]; + object.remove_statuses(remove_statuses); + + let serialized = object.serialize().unwrap(); + + assert_eq!(xml, serialized); + } + + #[test] + fn contact_delete() { + let xml = get_xml("request/contact/delete.xml").unwrap(); + + let object = EppContactDelete::new("eppdev-contact-3", CLTRID); + + let serialized = object.serialize().unwrap(); + + assert_eq!(xml, serialized); + } + + #[test] + fn domain_check() { + let xml = get_xml("request/domain/check.xml").unwrap(); + + let object = EppDomainCheck::new(vec!["eppdev.com", "eppdev.net"], CLTRID); + + let serialized = object.serialize().unwrap(); + + assert_eq!(xml, serialized); + } + + #[test] + fn domain_create() { + let xml = get_xml("request/domain/create.xml").unwrap(); + + let contacts = vec![ + DomainContact { + contact_type: "admin".to_string(), + id: "eppdev-contact-3".to_string(), + }, + DomainContact { + contact_type: "tech".to_string(), + id: "eppdev-contact-3".to_string(), + }, + DomainContact { + contact_type: "billing".to_string(), + id: "eppdev-contact-3".to_string(), + }, + ]; + + let object = EppDomainCreate::new( + "eppdev-1.com", + 1, + "eppdev-contact-3", + "epP4uthd#v", + contacts, + CLTRID, + ); + + let serialized = object.serialize().unwrap(); + + assert_eq!(xml, serialized); + } + + #[test] + fn domain_create_with_host_obj() { + let xml = get_xml("request/domain/create_with_host_obj.xml").unwrap(); + + let contacts = vec![ + DomainContact { + contact_type: "admin".to_string(), + id: "eppdev-contact-3".to_string(), + }, + DomainContact { + contact_type: "tech".to_string(), + id: "eppdev-contact-3".to_string(), + }, + DomainContact { + contact_type: "billing".to_string(), + id: "eppdev-contact-3".to_string(), + }, + ]; + + let object = EppDomainCreate::new_with_ns( + "eppdev-1.com", + 1, + vec!["ns1.test.com", "ns2.test.com"], + "eppdev-contact-3", + "epP4uthd#v", + contacts, + CLTRID, + ); + + let serialized = object.serialize().unwrap(); + + assert_eq!(xml, serialized); + } + + #[test] + fn domain_create_with_host_attr() { + let xml = get_xml("request/domain/create_with_host_attr.xml").unwrap(); + + let contacts = vec![ + DomainContact { + contact_type: "admin".to_string(), + id: "eppdev-contact-3".to_string(), + }, + DomainContact { + contact_type: "tech".to_string(), + id: "eppdev-contact-3".to_string(), + }, + DomainContact { + contact_type: "billing".to_string(), + id: "eppdev-contact-3".to_string(), + }, + ]; + + let host_attr = vec![ + HostAttr { + name: "ns1.eppdev-1.com".to_string_value(), + addresses: None, + }, + HostAttr { + name: "ns2.eppdev-1.com".to_string_value(), + addresses: Some(vec![ + HostAddr::new_v4("177.232.12.58"), + HostAddr::new_v6("2404:6800:4001:801::200e"), + ]), + }, + ]; + + let object = EppDomainCreate::new_with_host_attr( + "eppdev-2.com", + 1, + host_attr, + "eppdev-contact-3", + "epP4uthd#v", + contacts, + CLTRID, + ); + + let serialized = object.serialize().unwrap(); + + assert_eq!(xml, serialized); + } + + #[test] + fn domain_info() { + let xml = get_xml("request/domain/info.xml").unwrap(); + + let object = EppDomainInfo::new("eppdev.com", CLTRID); + + let serialized = object.serialize().unwrap(); + + assert_eq!(xml, serialized); + } + + #[test] + fn domain_update() { + let xml = get_xml("request/domain/update.xml").unwrap(); + + let mut object = EppDomainUpdate::new("eppdev.com", CLTRID); + + let add = DomainAddRemove { + ns: None, + contacts: None, + statuses: Some(vec![DomainStatus { + status: "clientDeleteProhibited".to_string(), + }]), + }; + + let remove = DomainAddRemove { + ns: None, + contacts: Some(vec![DomainContact { + contact_type: "billing".to_string(), + id: "eppdev-contact-2".to_string(), + }]), + statuses: None, + }; + + let change_info = DomainChangeInfo { + registrant: None, + auth_info: Some(AuthInfo::new("epP5uthd#v")), + }; + + object.add(add); + object.remove(remove); + object.info(change_info); + + let serialized = object.serialize().unwrap(); + + assert_eq!(xml, serialized); + } + + #[test] + fn domain_delete() { + let xml = get_xml("request/domain/delete.xml").unwrap(); + + let object = EppDomainDelete::new("eppdev.com", CLTRID); + + let serialized = object.serialize().unwrap(); + + assert_eq!(xml, serialized); + } + + #[test] + fn domain_renew() { + let xml = get_xml("request/domain/renew.xml").unwrap(); + + let exp_date = NaiveDate::from_ymd(2022, 7, 23); + let object = EppDomainRenew::new("eppdev.com", exp_date, 1, CLTRID); + + let serialized = object.serialize().unwrap(); + + assert_eq!(xml, serialized); + } + + #[test] + fn domain_transfer_request() { + let xml = get_xml("request/domain/transfer_request.xml").unwrap(); + + let object = EppDomainTransferRequest::request("testing.com", 1, "epP4uthd#v", CLTRID); + + let serialized = object.serialize().unwrap(); + + assert_eq!(xml, serialized); + } + + #[test] + fn domain_transfer_approve() { + let xml = get_xml("request/domain/transfer_approve.xml").unwrap(); + + let object = EppDomainTransferApprove::approve("testing.com", CLTRID); + + let serialized = object.serialize().unwrap(); + + assert_eq!(xml, serialized); + } + + #[test] + fn domain_transfer_reject() { + let xml = get_xml("request/domain/transfer_reject.xml").unwrap(); + + let object = EppDomainTransferReject::reject("testing.com", CLTRID); + + let serialized = object.serialize().unwrap(); + + assert_eq!(xml, serialized); + } + + #[test] + fn domain_transfer_cancel() { + let xml = get_xml("request/domain/transfer_cancel.xml").unwrap(); + + let object = EppDomainTransferCancel::cancel("testing.com", CLTRID); + + let serialized = object.serialize().unwrap(); + + assert_eq!(xml, serialized); + } + + #[test] + fn domain_transfer_query() { + let xml = get_xml("request/domain/transfer_query.xml").unwrap(); + + let object = EppDomainTransferQuery::query("testing.com", "epP4uthd#v", CLTRID); + + let serialized = object.serialize().unwrap(); + + assert_eq!(xml, serialized); + } + + #[test] + fn host_check() { + let xml = get_xml("request/host/check.xml").unwrap(); + + let object = EppHostCheck::new(vec!["ns1.eppdev-1.com", "host1.eppdev-1.com"], CLTRID); + + let serialized = object.serialize().unwrap(); + + assert_eq!(xml, serialized); + } + + #[test] + fn host_create() { + let xml = get_xml("request/host/create.xml").unwrap(); + + let host = Host { + name: "host1.eppdev-1.com".to_string_value(), + addresses: Some(vec![ + HostAddr::new("v4", "29.245.122.14"), + HostAddr::new("v6", "2404:6800:4001:801::200e"), + ]), + }; + + let object = EppHostCreate::new(host, CLTRID); + + let serialized = object.serialize().unwrap(); + + assert_eq!(xml, serialized); + } + + #[test] + fn host_info() { + let xml = get_xml("request/host/info.xml").unwrap(); + + let object = EppHostInfo::new("ns1.eppdev-1.com", CLTRID); + + let serialized = object.serialize().unwrap(); + + assert_eq!(xml, serialized); + } + + #[test] + fn host_update() { + let xml = get_xml("request/host/update.xml").unwrap(); + + let addr = vec![HostAddr::new("v6", "2404:6800:4001:801::200e")]; + + let add = HostAddRemove { + addresses: Some(addr), + statuses: None, + }; + + let remove = HostAddRemove { + addresses: None, + statuses: Some(vec![HostStatus { + status: "clientDeleteProhibited".to_string(), + }]), + }; + + let mut object = EppHostUpdate::new("host1.eppdev-1.com", CLTRID); + + object.add(add); + object.remove(remove); + object.info(HostChangeInfo { + name: "host2.eppdev-1.com".to_string_value(), + }); + + let serialized = object.serialize().unwrap(); + + assert_eq!(xml, serialized); + } + + #[test] + fn host_delete() { + let xml = get_xml("request/host/delete.xml").unwrap(); + + let object = EppHostDelete::new("ns1.eppdev-1.com", CLTRID); + + let serialized = object.serialize().unwrap(); + + assert_eq!(xml, serialized); + } + + #[test] + fn message_poll() { + let xml = get_xml("request/message/poll.xml").unwrap(); + + let object = EppMessagePoll::new(CLTRID); + + let serialized = object.serialize().unwrap(); + + assert_eq!(xml, serialized); + } + + #[test] + fn message_ack() { + let xml = get_xml("request/message/ack.xml").unwrap(); + + let object = EppMessageAck::new(12345, CLTRID); + + let serialized = object.serialize().unwrap(); + + assert_eq!(xml, serialized); + } +} diff --git a/epp-client/test/resources/response/contact/check.xml b/epp-client/test/resources/response/contact/check.xml new file mode 100644 index 0000000..336dcac --- /dev/null +++ b/epp-client/test/resources/response/contact/check.xml @@ -0,0 +1,22 @@ + + + + + Command completed successfully + + + + + eppdev-contact-1 + + + eppdev-contact-2 + + + + + cltrid:1626454866 + RO-6879-1627224678242975 + + + \ No newline at end of file diff --git a/epp-client/test/resources/response/contact/create.xml b/epp-client/test/resources/response/contact/create.xml new file mode 100644 index 0000000..a517874 --- /dev/null +++ b/epp-client/test/resources/response/contact/create.xml @@ -0,0 +1,18 @@ + + + + + Command completed successfully + + + + eppdev-contact-4 + 2021-07-25T16:05:32.0Z + + + + cltrid:1626454866 + RO-6879-1627224678242975 + + + \ No newline at end of file diff --git a/epp-client/test/resources/response/contact/delete.xml b/epp-client/test/resources/response/contact/delete.xml new file mode 100644 index 0000000..2c631a2 --- /dev/null +++ b/epp-client/test/resources/response/contact/delete.xml @@ -0,0 +1,18 @@ + + + + + Command completed successfully + + + + + 200 Command completed successfully + + + + cltrid:1626454866 + RO-6879-1627224678242975 + + + \ No newline at end of file diff --git a/epp-client/test/resources/response/contact/info.xml b/epp-client/test/resources/response/contact/info.xml new file mode 100644 index 0000000..fef0f22 --- /dev/null +++ b/epp-client/test/resources/response/contact/info.xml @@ -0,0 +1,42 @@ + + + + + Command completed successfully + + + + eppdev-contact-3 + UNDEF-ROID + + + John Doe + Acme Widgets + + 58 + Orchid Road + Paris + Paris + 392374 + FR + + + +33.47237942 + +33.86698799 + contact@eppdev.net + eppdev + SYSTEM + 2021-07-23T13:09:09.0Z + SYSTEM + 2021-07-23T13:09:09.0Z + + eppdev-387323 + + + + + cltrid:1626454866 + RO-6879-1627224678242975 + + + \ No newline at end of file diff --git a/epp-client/test/resources/response/contact/update.xml b/epp-client/test/resources/response/contact/update.xml new file mode 100644 index 0000000..2c631a2 --- /dev/null +++ b/epp-client/test/resources/response/contact/update.xml @@ -0,0 +1,18 @@ + + + + + Command completed successfully + + + + + 200 Command completed successfully + + + + cltrid:1626454866 + RO-6879-1627224678242975 + + + \ No newline at end of file diff --git a/epp-client/test/resources/response/domain/check.xml b/epp-client/test/resources/response/domain/check.xml new file mode 100644 index 0000000..d103ba8 --- /dev/null +++ b/epp-client/test/resources/response/domain/check.xml @@ -0,0 +1,22 @@ + + + + + Command completed successfully + + + + + eppdev.com + + + eppdev.net + + + + + cltrid:1626454866 + RO-6879-1627224678242975 + + + \ No newline at end of file diff --git a/epp-client/test/resources/response/domain/create.xml b/epp-client/test/resources/response/domain/create.xml new file mode 100644 index 0000000..a7a425a --- /dev/null +++ b/epp-client/test/resources/response/domain/create.xml @@ -0,0 +1,25 @@ + + + + + Command completed successfully + + + + + 200 Command completed successfully + + + + + eppdev-2.com + 2021-07-25T18:11:35.0Z + 2022-07-25T18:11:34.0Z + + + + cltrid:1626454866 + RO-6879-1627224678242975 + + + \ No newline at end of file diff --git a/epp-client/test/resources/response/domain/delete.xml b/epp-client/test/resources/response/domain/delete.xml new file mode 100644 index 0000000..2c631a2 --- /dev/null +++ b/epp-client/test/resources/response/domain/delete.xml @@ -0,0 +1,18 @@ + + + + + Command completed successfully + + + + + 200 Command completed successfully + + + + cltrid:1626454866 + RO-6879-1627224678242975 + + + \ No newline at end of file diff --git a/epp-client/test/resources/response/error.xml b/epp-client/test/resources/response/error.xml new file mode 100644 index 0000000..75e3848 --- /dev/null +++ b/epp-client/test/resources/response/error.xml @@ -0,0 +1,18 @@ + + + + + Object does not exist + + + + + 545 Object not found + + + + cltrid:1626454866 + RO-6879-1627224678242975 + + + \ No newline at end of file diff --git a/epp-client/test/resources/response/greeting.xml b/epp-client/test/resources/response/greeting.xml new file mode 100644 index 0000000..cd37cc8 --- /dev/null +++ b/epp-client/test/resources/response/greeting.xml @@ -0,0 +1,40 @@ + + + + ISPAPI EPP Server + 2021-07-25T14:51:17.0Z + + 1.0 + en + urn:ietf:params:xml:ns:host-1.0 + urn:ietf:params:xml:ns:domain-1.0 + urn:ietf:params:xml:ns:contact-1.0 + http://schema.ispapi.net/epp/xml/keyvalue-1.0 + + urn:ietf:params:xml:ns:secDNS-1.1 + urn:ietf:params:xml:ns:secDNS-1.0 + urn:ietf:params:xml:ns:rgp-1.0 + urn:ietf:params:xml:ns:fee-0.7 + http://schema.ispapi.net/epp/xml/keyvalue-1.0 + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/epp-client/test/resources/response/login.xml b/epp-client/test/resources/response/login.xml new file mode 100644 index 0000000..cd66da1 --- /dev/null +++ b/epp-client/test/resources/response/login.xml @@ -0,0 +1,12 @@ + + + + + Command completed successfully + + + cltrid:1626454866 + RO-6879-1627224678242975 + + + \ No newline at end of file diff --git a/epp-client/test/resources/response/logout.xml b/epp-client/test/resources/response/logout.xml new file mode 100644 index 0000000..2247095 --- /dev/null +++ b/epp-client/test/resources/response/logout.xml @@ -0,0 +1,12 @@ + + + + + Command completed successfully; ending session + + + cltrid:1626454866 + RO-6879-1627224678242975 + + + \ No newline at end of file