added some response deserialization tests

This commit is contained in:
Ritesh Chitlangi 2021-07-26 02:26:02 +08:00
parent 198c92c40f
commit eafbe4c647
30 changed files with 1155 additions and 515 deletions

View File

@ -39,7 +39,7 @@ async fn create_contact(client: &mut EppClient) {
let mut fax = Phone::new("+47.86698799"); let mut fax = Phone::new("+47.86698799");
fax.set_extension("677"); 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); contact_create.set_fax(fax);
client.transact::<_, EppContactCreateResponse>(&contact_create).await.unwrap(); 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) { 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(); client.transact::<_, EppContactInfoResponse>(&contact_info).await.unwrap();
} }
async fn delete_contact(client: &mut EppClient) { 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(); 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_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(); 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) { 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(); client.transact::<_, EppDomainDeleteResponse>(&domain_delete).await.unwrap();
} }
@ -280,7 +280,7 @@ async fn main() {
// hello(&mut client).await; // hello(&mut client).await;
check_domains(&mut client).await; // check_domains(&mut client).await;
// check_contacts(&mut client).await; // check_contacts(&mut client).await;
@ -298,7 +298,7 @@ async fn main() {
// update_domain(&mut client).await; // update_domain(&mut client).await;
// delete_domain(&mut client).await; delete_domain(&mut client).await;
// renew_domain(&mut client).await; // renew_domain(&mut client).await;

View File

@ -37,7 +37,7 @@ use crate::config::CONFIG;
use crate::connection::registry::{epp_connect, EppConnection}; use crate::connection::registry::{epp_connect, EppConnection};
use crate::error; use crate::error;
use crate::epp::request::{generate_client_tr_id, EppHello, EppLogin, EppLogout}; 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; use crate::epp::xml::EppXml;
/// Connects to the registry and returns an logged-in instance of EppClient for further transactions /// 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 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()); 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) Ok(client)
} }
@ -150,7 +150,7 @@ impl EppClient {
let response = self.connection.transact(&epp_xml).await?; let response = self.connection.transact(&epp_xml).await?;
let status = EppCommandResponseStatus::deserialize(&response)?; let status = EppCommandResponse::deserialize(&response)?;
if status.data.result.code < 2000 { if status.data.result.code < 2000 {
let response = E::deserialize(&response)?; let response = E::deserialize(&response)?;
@ -178,11 +178,11 @@ impl EppClient {
} }
/// Sends the EPP Logout command to log out of the EPP session /// Sends the EPP Logout command to log out of the EPP session
pub async fn logout(&mut self) -> Result<EppCommandResponse, error::Error> { pub async fn logout(&mut self) -> Result<EppLogoutResponse, error::Error> {
let client_tr_id = generate_client_tr_id(&self.credentials.0).unwrap(); let client_tr_id = generate_client_tr_id(&self.credentials.0).unwrap();
let epp_logout = EppLogout::new(client_tr_id.as_str()); let epp_logout = EppLogout::new(client_tr_id.as_str());
self.transact::<_, EppCommandResponse>(&epp_logout).await self.transact::<_, EppLogoutResponse>(&epp_logout).await
} }
} }

View File

@ -32,7 +32,9 @@ impl EppConnection {
mut stream: ConnectionStream) -> Result<EppConnection, Box<dyn Error>> { mut stream: ConnectionStream) -> Result<EppConnection, Box<dyn Error>> {
let mut buf = vec![0u8; 4096]; let mut buf = vec![0u8; 4096];
stream.reader.read(&mut buf).await?; 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 { Ok(EppConnection {
registry: registry, registry: registry,
@ -113,7 +115,7 @@ impl EppConnection {
self.send_epp_request(&content).await?; self.send_epp_request(&content).await?;
let response = self.get_epp_response().await?; let response = self.get_epp_response().await?;
debug!("{}: request: {}", self.registry, response); debug!("{}: response: {}", self.registry, response);
Ok(response) Ok(response)
} }

View File

@ -139,25 +139,25 @@ pub struct Phone {
pub number: String, pub number: String,
/// The value of the 'x' attr on <voice> and <fax> tags /// The value of the 'x' attr on <voice> and <fax> tags
#[serde(rename = "x")] #[serde(rename = "x")]
extension: Option<String>, pub extension: Option<String>,
} }
/// The <addr> type on contact transactions /// The <addr> type on contact transactions
#[derive(Serialize, Deserialize, Debug, Clone)] #[derive(Serialize, Deserialize, Debug, Clone)]
pub struct Address { pub struct Address {
/// The <street> tags under <addr> /// The <street> tags under <addr>
street: Vec<StringValue>, pub street: Vec<StringValue>,
/// The <city> tag under <addr> /// The <city> tag under <addr>
city: StringValue, pub city: StringValue,
/// The <sp> tag under <addr> /// The <sp> tag under <addr>
#[serde(rename = "sp")] #[serde(rename = "sp")]
province: StringValue, pub province: StringValue,
/// The <pc> tag under <addr> /// The <pc> tag under <addr>
#[serde(rename = "pc")] #[serde(rename = "pc")]
postal_code: StringValue, pub postal_code: StringValue,
/// The <cc> tag under <addr> /// The <cc> tag under <addr>
#[serde(rename = "cc")] #[serde(rename = "cc")]
country_code: StringValue, pub country_code: StringValue,
} }
/// The <postalInfo> type on contact transactions /// The <postalInfo> type on contact transactions
@ -165,15 +165,15 @@ pub struct Address {
pub struct PostalInfo { pub struct PostalInfo {
/// The 'type' attr on <postalInfo> /// The 'type' attr on <postalInfo>
#[serde(rename = "type")] #[serde(rename = "type")]
info_type: String, pub info_type: String,
/// The <name> tag under <postalInfo> /// The <name> tag under <postalInfo>
name: StringValue, pub name: StringValue,
/// The <org> tag under <postalInfo> /// The <org> tag under <postalInfo>
#[serde(rename = "org")] #[serde(rename = "org")]
organization: StringValue, pub organization: StringValue,
/// The <addr> tag under <postalInfo> /// The <addr> tag under <postalInfo>
#[serde(rename = "addr")] #[serde(rename = "addr")]
address: Address, pub address: Address,
} }
/// The <authInfo> tag for domain and contact transactions /// The <authInfo> tag for domain and contact transactions

View File

@ -11,10 +11,10 @@ use crate::epp::object::{
}; };
pub type EppGreeting = EppObject<Greeting>; pub type EppGreeting = EppObject<Greeting>;
pub type EppCommandResponseStatus = EppObject<CommandResponseStatus>; pub type EppCommandResponse = EppObject<CommandResponseStatus>;
type CommandResponseError = CommandResponseStatus; pub type EppCommandResponseError = EppCommandResponse;
pub type EppCommandResponseError = EppObject<CommandResponseError>; pub type EppLoginResponse = EppCommandResponse;
pub type EppCommandResponse = EppObject<CommandResponse<String>>; pub type EppLogoutResponse = EppCommandResponse;
#[derive(Serialize, Debug, PartialEq)] #[derive(Serialize, Debug, PartialEq)]
pub struct ServiceMenu { pub struct ServiceMenu {
@ -183,3 +183,12 @@ pub struct CommandResponseStatus {
#[serde(rename = "trID")] #[serde(rename = "trID")]
pub tr_ids: ResponseTRID, pub tr_ids: ResponseTRID,
} }
impl<T> CommandResponse<T> {
pub fn results(&self) -> Option<&T> {
match &self.res_data {
Some(res_data) => Some(&res_data),
None => None,
}
}
}

View File

@ -15,7 +15,8 @@ pub struct ContactCheck {
#[derive(Serialize, Deserialize, Debug)] #[derive(Serialize, Deserialize, Debug)]
pub struct ContactCheckDataItem { pub struct ContactCheckDataItem {
pub id: ContactCheck, #[serde(rename = "id")]
pub contact: ContactCheck,
pub reason: Option<StringValue>, pub reason: Option<StringValue>,
} }
@ -23,6 +24,8 @@ pub struct ContactCheckDataItem {
pub struct ContactCheckData { pub struct ContactCheckData {
#[serde(rename = "xmlns:contact")] #[serde(rename = "xmlns:contact")]
xmlns: String, xmlns: String,
#[serde(rename = "xsi:schemaLocation")]
schema_location: String,
#[serde(rename = "cd")] #[serde(rename = "cd")]
pub contact_list: Vec<ContactCheckDataItem>, pub contact_list: Vec<ContactCheckDataItem>,
} }

View File

@ -9,6 +9,8 @@ pub type EppContactCreateResponse = EppObject<CommandResponse<ContactCreateResul
pub struct ContactCreateData { pub struct ContactCreateData {
#[serde(rename = "xmlns:contact")] #[serde(rename = "xmlns:contact")]
xmlns: String, xmlns: String,
#[serde(rename = "xsi:schemaLocation")]
schema_location: String,
pub id: StringValue, pub id: StringValue,
#[serde(rename = "crDate")] #[serde(rename = "crDate")]
pub created_at: StringValue, pub created_at: StringValue,
@ -17,5 +19,5 @@ pub struct ContactCreateData {
#[derive(Serialize, Deserialize, Debug)] #[derive(Serialize, Deserialize, Debug)]
pub struct ContactCreateResult { pub struct ContactCreateResult {
#[serde(rename = "creData")] #[serde(rename = "creData")]
pub check_data: ContactCreateData, pub create_data: ContactCreateData,
} }

View File

@ -10,9 +10,12 @@ pub type EppContactInfoResponse = EppObject<CommandResponse<ContactInfoResult>>;
pub struct ContactInfoData { pub struct ContactInfoData {
#[serde(rename = "xmlns:contact")] #[serde(rename = "xmlns:contact")]
xmlns: String, xmlns: String,
#[serde(rename = "xsi:schemaLocation")]
schema_location: String,
pub id: StringValue, pub id: StringValue,
pub roid: StringValue, pub roid: StringValue,
pub status: Vec<ContactStatus>, #[serde(rename = "status")]
pub statuses: Vec<ContactStatus>,
#[serde(rename = "postalInfo")] #[serde(rename = "postalInfo")]
pub postal_info: PostalInfo, pub postal_info: PostalInfo,
pub voice: Phone, pub voice: Phone,

View File

@ -22,6 +22,10 @@ pub struct DomainCheckDataItem {
#[derive(Serialize, Deserialize, Debug)] #[derive(Serialize, Deserialize, Debug)]
pub struct DomainCheckData { pub struct DomainCheckData {
#[serde(rename = "xmlns:domain")]
xmlns: String,
#[serde(rename = "xsi:schemaLocation")]
schema_location: String,
#[serde(rename = "cd")] #[serde(rename = "cd")]
pub domain_list: Vec<DomainCheckDataItem>, pub domain_list: Vec<DomainCheckDataItem>,
} }

View File

@ -9,6 +9,8 @@ pub type EppDomainCreateResponse = EppObject<CommandResponse<DomainCreateResult>
pub struct DomainCreateData { pub struct DomainCreateData {
#[serde(rename = "xmlns:domain")] #[serde(rename = "xmlns:domain")]
xmlns: String, xmlns: String,
#[serde(rename = "xsi:schemaLocation")]
schema_location: String,
pub name: StringValue, pub name: StringValue,
#[serde(rename = "crDate")] #[serde(rename = "crDate")]
pub created_at: StringValue, pub created_at: StringValue,

View File

@ -24,6 +24,8 @@ pub struct DomainCheckDataItem {
pub struct DomainInfoData { pub struct DomainInfoData {
#[serde(rename = "xmlns:domain")] #[serde(rename = "xmlns:domain")]
xmlns: String, xmlns: String,
#[serde(rename = "xsi:schemaLocation")]
schema_location: String,
pub name: StringValue, pub name: StringValue,
pub roid: StringValue, pub roid: StringValue,
pub status: Vec<DomainStatus>, pub status: Vec<DomainStatus>,

View File

@ -9,6 +9,8 @@ pub type EppDomainRenewResponse = EppObject<CommandResponse<DomainRenewResult>>;
pub struct DomainRenewData { pub struct DomainRenewData {
#[serde(rename = "xmlns:domain")] #[serde(rename = "xmlns:domain")]
xmlns: String, xmlns: String,
#[serde(rename = "xsi:schemaLocation")]
schema_location: String,
pub name: StringValue, pub name: StringValue,
#[serde(rename = "exDate")] #[serde(rename = "exDate")]
pub expiry_date: StringValue, pub expiry_date: StringValue,

View File

@ -14,6 +14,8 @@ pub type EppDomainTransferQueryResponse = EppObject<CommandResponse<DomainTransf
pub struct DomainTransferData { pub struct DomainTransferData {
#[serde(rename = "xmlns:domain")] #[serde(rename = "xmlns:domain")]
xmlns: String, xmlns: String,
#[serde(rename = "xsi:schemaLocation")]
schema_location: String,
pub name: StringValue, pub name: StringValue,
#[serde(rename = "trStatus")] #[serde(rename = "trStatus")]
pub transfer_status: StringValue, pub transfer_status: StringValue,

View File

@ -13,6 +13,9 @@ pub const EPP_DOMAIN_XMLNS: &str = "urn:ietf:params:xml:ns:domain-1.0";
pub const EPP_CONTACT_XMLNS: &str = "urn:ietf:params:xml:ns:contact-1.0"; pub const EPP_CONTACT_XMLNS: &str = "urn:ietf:params:xml:ns:contact-1.0";
pub const EPP_HOST_XMLNS: &str = "urn:ietf:params:xml:ns:host-1.0"; pub const EPP_HOST_XMLNS: &str = "urn:ietf:params:xml:ns:host-1.0";
pub const EPP_CONTACT_SCHEMA_LOCATION: &str = "urn:ietf:params:xml:ns:contact-1.0 contact-1.0.xsd";
pub const EPP_DOMAIN_SCHEMA_LOCATION: &str = "urn:ietf:params:xml:ns:domain-1.0 domain-1.0.xsd";
pub const EPP_VERSION: &str = "1.0"; pub const EPP_VERSION: &str = "1.0";
pub const EPP_LANG: &str = "en"; pub const EPP_LANG: &str = "en";

View File

@ -85,495 +85,12 @@
#[macro_use] #[macro_use]
extern crate log; extern crate log;
extern crate epp_client_macros;
pub mod config; pub mod config;
pub mod connection; pub mod connection;
pub mod epp; pub mod epp;
pub mod error; pub mod error;
pub use connection::client::EppClient; pub use connection::client::EppClient;
#[cfg(test)] #[cfg(test)]
mod tests { pub mod tests;
use std::{fs::File, io::Read, error::Error};
use regex::Regex;
const RESOURCES_DIR: &str = "./test/resources";
fn get_xml(path: &str) -> Result<String, Box<dyn Error>> {
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);
}
}
}
}

312
epp-client/src/tests/de.rs Normal file
View File

@ -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());
}
}

View File

@ -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<String, Box<dyn Error>> {
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)
}

485
epp-client/src/tests/se.rs Normal file
View File

@ -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);
}
}

View File

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:ietf:params:xml:ns:epp-1.0 epp-1.0.xsd">
<response>
<result code="1000">
<msg>Command completed successfully</msg>
</result>
<resData>
<contact:chkData xmlns:contact="urn:ietf:params:xml:ns:contact-1.0" xsi:schemaLocation="urn:ietf:params:xml:ns:contact-1.0 contact-1.0.xsd">
<contact:cd>
<contact:id avail="0">eppdev-contact-1</contact:id>
</contact:cd>
<contact:cd>
<contact:id avail="1">eppdev-contact-2</contact:id>
</contact:cd>
</contact:chkData>
</resData>
<trID>
<clTRID>cltrid:1626454866</clTRID>
<svTRID>RO-6879-1627224678242975</svTRID>
</trID>
</response>
</epp>

View File

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:ietf:params:xml:ns:epp-1.0 epp-1.0.xsd">
<response>
<result code="1000">
<msg>Command completed successfully</msg>
</result>
<resData>
<contact:creData xmlns:contact="urn:ietf:params:xml:ns:contact-1.0" xsi:schemaLocation="urn:ietf:params:xml:ns:contact-1.0 contact-1.0.xsd">
<contact:id>eppdev-contact-4</contact:id>
<contact:crDate>2021-07-25T16:05:32.0Z</contact:crDate>
</contact:creData>
</resData>
<trID>
<clTRID>cltrid:1626454866</clTRID>
<svTRID>RO-6879-1627224678242975</svTRID>
</trID>
</response>
</epp>

View File

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:ietf:params:xml:ns:epp-1.0 epp-1.0.xsd">
<response>
<result code="1000">
<msg>Command completed successfully</msg>
<extValue>
<value xmlns:epp="urn:ietf:params:xml:ns:epp-1.0">
<epp:undef/>
</value>
<reason>200 Command completed successfully</reason>
</extValue>
</result>
<trID>
<clTRID>cltrid:1626454866</clTRID>
<svTRID>RO-6879-1627224678242975</svTRID>
</trID>
</response>
</epp>

View File

@ -0,0 +1,42 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:ietf:params:xml:ns:epp-1.0 epp-1.0.xsd">
<response>
<result code="1000">
<msg>Command completed successfully</msg>
</result>
<resData>
<contact:infData xmlns:contact="urn:ietf:params:xml:ns:contact-1.0" xsi:schemaLocation="urn:ietf:params:xml:ns:contact-1.0 contact-1.0.xsd">
<contact:id>eppdev-contact-3</contact:id>
<contact:roid>UNDEF-ROID</contact:roid>
<contact:status s="ok"/>
<contact:postalInfo type="loc">
<contact:name>John Doe</contact:name>
<contact:org>Acme Widgets</contact:org>
<contact:addr>
<contact:street>58</contact:street>
<contact:street>Orchid Road</contact:street>
<contact:city>Paris</contact:city>
<contact:sp>Paris</contact:sp>
<contact:pc>392374</contact:pc>
<contact:cc>FR</contact:cc>
</contact:addr>
</contact:postalInfo>
<contact:voice x="123">+33.47237942</contact:voice>
<contact:fax x="243">+33.86698799</contact:fax>
<contact:email>contact@eppdev.net</contact:email>
<contact:clID>eppdev</contact:clID>
<contact:crID>SYSTEM</contact:crID>
<contact:crDate>2021-07-23T13:09:09.0Z</contact:crDate>
<contact:upID>SYSTEM</contact:upID>
<contact:upDate>2021-07-23T13:09:09.0Z</contact:upDate>
<contact:authInfo>
<contact:pw>eppdev-387323</contact:pw>
</contact:authInfo>
</contact:infData>
</resData>
<trID>
<clTRID>cltrid:1626454866</clTRID>
<svTRID>RO-6879-1627224678242975</svTRID>
</trID>
</response>
</epp>

View File

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:ietf:params:xml:ns:epp-1.0 epp-1.0.xsd">
<response>
<result code="1000">
<msg>Command completed successfully</msg>
<extValue>
<value xmlns:epp="urn:ietf:params:xml:ns:epp-1.0">
<epp:undef/>
</value>
<reason>200 Command completed successfully</reason>
</extValue>
</result>
<trID>
<clTRID>cltrid:1626454866</clTRID>
<svTRID>RO-6879-1627224678242975</svTRID>
</trID>
</response>
</epp>

View File

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:ietf:params:xml:ns:epp-1.0 epp-1.0.xsd">
<response>
<result code="1000">
<msg>Command completed successfully</msg>
</result>
<resData>
<domain:chkData xmlns:domain="urn:ietf:params:xml:ns:domain-1.0" xsi:schemaLocation="urn:ietf:params:xml:ns:domain-1.0 domain-1.0.xsd">
<domain:cd>
<domain:name avail="1">eppdev.com</domain:name>
</domain:cd>
<domain:cd>
<domain:name avail="0">eppdev.net</domain:name>
</domain:cd>
</domain:chkData>
</resData>
<trID>
<clTRID>cltrid:1626454866</clTRID>
<svTRID>RO-6879-1627224678242975</svTRID>
</trID>
</response>
</epp>

View File

@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:ietf:params:xml:ns:epp-1.0 epp-1.0.xsd">
<response>
<result code="1000">
<msg>Command completed successfully</msg>
<extValue>
<value xmlns:epp="urn:ietf:params:xml:ns:epp-1.0">
<epp:undef/>
</value>
<reason>200 Command completed successfully</reason>
</extValue>
</result>
<resData>
<domain:creData xmlns:domain="urn:ietf:params:xml:ns:domain-1.0" xsi:schemaLocation="urn:ietf:params:xml:ns:domain-1.0 domain-1.0.xsd">
<domain:name>eppdev-2.com</domain:name>
<domain:crDate>2021-07-25T18:11:35.0Z</domain:crDate>
<domain:exDate>2022-07-25T18:11:34.0Z</domain:exDate>
</domain:creData>
</resData>
<trID>
<clTRID>cltrid:1626454866</clTRID>
<svTRID>RO-6879-1627224678242975</svTRID>
</trID>
</response>
</epp>

View File

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:ietf:params:xml:ns:epp-1.0 epp-1.0.xsd">
<response>
<result code="1000">
<msg>Command completed successfully</msg>
<extValue>
<value xmlns:epp="urn:ietf:params:xml:ns:epp-1.0">
<epp:undef/>
</value>
<reason>200 Command completed successfully</reason>
</extValue>
</result>
<trID>
<clTRID>cltrid:1626454866</clTRID>
<svTRID>RO-6879-1627224678242975</svTRID>
</trID>
</response>
</epp>

View File

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:ietf:params:xml:ns:epp-1.0 epp-1.0.xsd">
<response>
<result code="2303">
<msg>Object does not exist</msg>
<extValue>
<value xmlns:epp="urn:ietf:params:xml:ns:epp-1.0">
<epp:undef/>
</value>
<reason>545 Object not found</reason>
</extValue>
</result>
<trID>
<clTRID>cltrid:1626454866</clTRID>
<svTRID>RO-6879-1627224678242975</svTRID>
</trID>
</response>
</epp>

View File

@ -0,0 +1,40 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:ietf:params:xml:ns:epp-1.0 epp-1.0.xsd">
<greeting>
<svID>ISPAPI EPP Server</svID>
<svDate>2021-07-25T14:51:17.0Z</svDate>
<svcMenu>
<version>1.0</version>
<lang>en</lang>
<objURI>urn:ietf:params:xml:ns:host-1.0</objURI>
<objURI>urn:ietf:params:xml:ns:domain-1.0</objURI>
<objURI>urn:ietf:params:xml:ns:contact-1.0</objURI>
<objURI>http://schema.ispapi.net/epp/xml/keyvalue-1.0</objURI>
<svcExtension>
<extURI>urn:ietf:params:xml:ns:secDNS-1.1</extURI>
<extURI>urn:ietf:params:xml:ns:secDNS-1.0</extURI>
<extURI>urn:ietf:params:xml:ns:rgp-1.0</extURI>
<extURI>urn:ietf:params:xml:ns:fee-0.7</extURI>
<extURI>http://schema.ispapi.net/epp/xml/keyvalue-1.0</extURI>
</svcExtension>
</svcMenu>
<dcp>
<access>
<all/>
</access>
<statement>
<purpose>
<admin/>
<prov/>
</purpose>
<recipient>
<ours/>
<public/>
</recipient>
<retention>
<stated/>
</retention>
</statement>
</dcp>
</greeting>
</epp>

View File

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:ietf:params:xml:ns:epp-1.0 epp-1.0.xsd">
<response>
<result code="1000">
<msg>Command completed successfully</msg>
</result>
<trID>
<clTRID>cltrid:1626454866</clTRID>
<svTRID>RO-6879-1627224678242975</svTRID>
</trID>
</response>
</epp>

View File

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:ietf:params:xml:ns:epp-1.0 epp-1.0.xsd">
<response>
<result code="1500">
<msg>Command completed successfully; ending session</msg>
</result>
<trID>
<clTRID>cltrid:1626454866</clTRID>
<svTRID>RO-6879-1627224678242975</svTRID>
</trID>
</response>
</epp>