Add HostInfoResponseData to list of support message poll response types

This commit is contained in:
Nicholas Rempel 2022-01-05 12:31:50 -08:00 committed by masalachai
parent 4f112469ce
commit 569bd86bae
3 changed files with 96 additions and 12 deletions

View File

@ -1,5 +1,6 @@
use crate::common::NoExtension; use crate::common::NoExtension;
use crate::domain::transfer::DomainTransferResponseData; use crate::domain::transfer::DomainTransferResponseData;
use crate::host::info::HostInfoResponseData;
use crate::request::{Command, Transaction}; use crate::request::{Command, Transaction};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
@ -34,13 +35,16 @@ pub enum MessageData {
/// Data under the <domain:trnData> tag /// Data under the <domain:trnData> tag
#[serde(rename = "domain:trnData")] #[serde(rename = "domain:trnData")]
DomainTransfer(DomainTransferResponseData), DomainTransfer(DomainTransferResponseData),
/// Data under the <host:infData> tag
#[serde(rename = "host:infData")]
HostInfo(HostInfoResponseData),
} }
/// Type that represents the <resData> tag for message poll response /// Type that represents the <resData> tag for message poll response
#[derive(Deserialize, Debug)] #[derive(Deserialize, Debug)]
pub struct MessagePollResponse { pub struct MessagePollResponse {
/// Data under the <trnData> tag /// Data under the <trnData> tag
#[serde(alias = "trnData")] #[serde(alias = "trnData", alias = "infData")]
pub message_data: MessageData, pub message_data: MessageData,
} }
@ -63,8 +67,8 @@ mod tests {
} }
#[test] #[test]
fn response() { fn domain_transfer_response() {
let xml = get_xml("response/message/poll.xml").unwrap(); let xml = get_xml("response/message/poll_domain_transfer.xml").unwrap();
let object = MessagePoll::deserialize_response(xml.as_str()).unwrap(); let object = MessagePoll::deserialize_response(xml.as_str()).unwrap();
let result = object.res_data().unwrap(); let result = object.res_data().unwrap();
@ -86,18 +90,60 @@ mod tests {
"Transfer requested.".into() "Transfer requested.".into()
); );
let MessageData::DomainTransfer(data) = &result.message_data; if let MessageData::DomainTransfer(tr) = &result.message_data {
assert_eq!(tr.name, "eppdev-transfer.com".into());
assert_eq!(tr.transfer_status, "pending".into());
assert_eq!(tr.requester_id, "eppdev".into());
assert_eq!(tr.requested_at, "2021-07-23T15:31:21.0Z".into());
assert_eq!(tr.ack_id, "ClientY".into());
assert_eq!(tr.ack_by, "2021-07-28T15:31:21.0Z".into());
assert_eq!(
*tr.expiring_at.as_ref().unwrap(),
"2022-07-02T14:53:19.0Z".into()
);
} else {
panic!("Wrong type");
}
assert_eq!(data.name, "eppdev-transfer.com".into()); assert_eq!(object.tr_ids.client_tr_id.unwrap(), CLTRID.into());
assert_eq!(data.transfer_status, "pending".into()); assert_eq!(object.tr_ids.server_tr_id, SVTRID.into());
assert_eq!(data.requester_id, "eppdev".into()); }
assert_eq!(data.requested_at, "2021-07-23T15:31:21.0Z".into());
assert_eq!(data.ack_id, "ClientY".into()); #[test]
assert_eq!(data.ack_by, "2021-07-28T15:31:21.0Z".into()); fn host_info_response() {
let xml = get_xml("response/message/poll_host_info.xml").unwrap();
let object = MessagePoll::deserialize_response(xml.as_str()).unwrap();
let result = object.res_data().unwrap();
let msg = object.message_queue().unwrap();
assert_eq!(object.result.code, 1301);
assert_eq!( assert_eq!(
*data.expiring_at.as_ref().unwrap(), object.result.message,
"2022-07-02T14:53:19.0Z".into() "Command completed successfully; ack to dequeue".into()
); );
assert_eq!(msg.count, 4);
assert_eq!(msg.id, "12345".to_string());
assert_eq!(*(msg.date.as_ref().unwrap()), "2022-01-02T11:30:45Z".into());
assert_eq!(
*(msg.message.as_ref().unwrap()),
"Unused objects policy".into()
);
if let MessageData::HostInfo(host) = &result.message_data {
assert_eq!(host.name, "ns.test.com".into());
assert_eq!(host.roid, "1234".into());
assert!(host.statuses.iter().any(|s| s.status == "ok"));
assert!(host.addresses.iter().any(|a| a.address == *"1.1.1.1"));
assert_eq!(host.client_id, "1234".into());
assert_eq!(host.creator_id, "user".into());
assert_eq!(host.created_at, "2021-12-01T22:40:48Z".into());
assert_eq!(host.updater_id, Some("user".into()));
assert_eq!(host.updated_at, Some("2021-12-01T22:40:48Z".into()));
} else {
panic!("Wrong type");
}
assert_eq!(object.tr_ids.client_tr_id.unwrap(), CLTRID.into()); assert_eq!(object.tr_ids.client_tr_id.unwrap(), CLTRID.into());
assert_eq!(object.tr_ids.server_tr_id, SVTRID.into()); assert_eq!(object.tr_ids.server_tr_id, SVTRID.into());

View File

@ -0,0 +1,38 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
<response>
<result code="1301">
<msg>Command completed successfully; ack to dequeue</msg>
</result>
<msgQ count="4" id="12345">
<qDate>2022-01-02T11:30:45Z</qDate>
<msg>Unused objects policy</msg>
</msgQ>
<resData>
<host:infData xmlns:host="urn:ietf:params:xml:ns:host-1.0">
<host:name>ns.test.com</host:name>
<host:roid>1234</host:roid>
<host:status s="ok"/>
<host:addr ip="v4">1.1.1.1</host:addr>
<host:clID>1234</host:clID>
<host:crID>user</host:crID>
<host:crDate>2021-12-01T22:40:48Z</host:crDate>
<host:upID>user</host:upID>
<host:upDate>2021-12-01T22:40:48Z</host:upDate>
</host:infData>
</resData>
<extension>
<changePoll:changeData state="before" xmlns:changePoll="urn:ietf:params:xml:ns:changePoll-1.0">
<changePoll:operation op="purge">delete</changePoll:operation>
<changePoll:date>2022-01-02T11:30:45Z</changePoll:date>
<changePoll:svTRID>1234</changePoll:svTRID>
<changePoll:who>regy_batch</changePoll:who>
<changePoll:reason>Unused objects policy</changePoll:reason>
</changePoll:changeData>
</extension>
<trID>
<clTRID>cltrid:1626454866</clTRID>
<svTRID>RO-6879-1627224678242975</svTRID>
</trID>
</response>
</epp>