/* * Copyright (C) 2006 Registro.br. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * 1. Redistribution of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY REGISTRO.BR ``AS IS AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIE OF FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO * EVENT SHALL REGISTRO.BR BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH * DAMAGE. */ /* $Id: BrDomainInfoTest.cpp 901 2007-03-08 21:07:01Z eduardo $ */ #include #include #include "libepp_nicbr.H" #include "StrUtil.H" #include "BrDomainInfoTest.H" #include "BrDomainInfo.H" #include "FileUtil.H" #include "IoException.H" #include "XmlException.H" using std::auto_ptr; using std::cout; using std::endl; LIBEPP_NICBR_NS_USE CPPUNIT_TEST_SUITE_REGISTRATION(BrDomainInfoTest); BrDomainInfoTest::BrDomainInfoTest() {} BrDomainInfoTest::~BrDomainInfoTest() {} void BrDomainInfoTest::setUp() {} void BrDomainInfoTest::tearDown() {} void BrDomainInfoTest::set_xml_template_test() { string to_be_parsed = "" "" "" "" "" "$(name)$" "$(auth_info)$" "" "" "$(extension)$" "$(clTRID)$" "" ""; string expected = "" "" "" "" "" "example.com.br" "" "" "" "" "123456" "" "" "ABC-12345" "" ""; BrDomainInfo br_domain_info; BrDomainInfoCmd* br_domain_info_cmd = br_domain_info.get_command(); br_domain_info_cmd->set_name("example.com.br"); br_domain_info_cmd->set_hosts_control("all"); br_domain_info_cmd->set_ticketNumber(123456); br_domain_info.get_command()->set_clTRID("ABC-12345"); br_domain_info.set_xml_template(to_be_parsed); CPPUNIT_ASSERT_EQUAL(expected, br_domain_info.get_xml()); // tests reset method br_domain_info_cmd->reset(); //parent attributes CPPUNIT_ASSERT(br_domain_info_cmd->get_name() == ""); CPPUNIT_ASSERT(br_domain_info_cmd->get_hosts_control() == "all"); CPPUNIT_ASSERT(br_domain_info_cmd->get_authInfo().get_pw() == ""); CPPUNIT_ASSERT(br_domain_info_cmd->get_authInfo().get_roid() == ""); //BrDomainInfo specific CPPUNIT_ASSERT_EQUAL(0, br_domain_info_cmd->get_ticketNumber()); } void BrDomainInfoTest::command_test() { BrDomainInfo domain_info; BrDomainInfoCmd *domain_info_cmd = domain_info.get_command(); domain_info_cmd->set_name("EmmaWatsonIsCharming.com"); domain_info_cmd->set_hosts_control("sub"); AuthInfo auth; auth.set_roid("SH8013-REP"); auth.set_pw("abc123"); domain_info_cmd->set_authInfo(auth); bool exception_caught = false; try { string xml_template = FileUtil::read_file("../docs/templates/br_domain_info.xml"); domain_info.get_command()->set_clTRID("ABC-12345"); domain_info.set_xml_template(xml_template); DomParser parser; parser.enable_validation("../docs/schemas"); parser.parse_command(domain_info.get_xml()); } catch (const IoException &e) { exception_caught = true; printf("\nIO Exception: code [%d] message [%s]", e.get_code(), e.get_msg().c_str()); } catch (const XmlException &e) { exception_caught = true; printf("\nXml Exception: code [%d] message [%s] low level message [%s]\n", e.get_code(), e.get_msg().c_str(), e.get_low_level_msg().c_str()); } CPPUNIT_ASSERT(!exception_caught); } void BrDomainInfoTest::response_test() { response_test(true); response_test(false); } void BrDomainInfoTest::response_test(bool withDNSSECExtension) { string expected = "" "" "" "" "Command completed successfully" "" "" "" "example.com.br" "EXAMPLE1-REP" "" "fan" "fan" "fan" "" "" "ns1.example.net.br" "" "" "ns1.example.com.br" "192.0.2.1" "" "" "ClientX" "ClientX" "2006-01-30T22:00:00.0Z" "ClientX" "2006-01-31T09:00:00.0Z" "" "" ""; if (withDNSSECExtension) { expected += "" "" "12345" "3" "1" "49FD46E6C4B45C55D4AC" "604800" "" "256" "3" "1" "AQPJ////4Q==" "" "" "" "12345" "3" "1" "49FD46E6C4B45C55D4AC" "" ""; } expected += "" "123456" "" "005.506.560/0001-36" "" "" "" "" "CNPJ" "2006-03-01T22:00:00.0Z" "" "Cadastro Nacional da Pessoa Jurídica" "" "" "" "" "ns1.example.com.br" "" "2006-02-13T22:00:00.0Z" "" "" "2006-02-13T22:00:00.0Z" "" "" "2006-02-01T22:00:00.0Z" "" "" "" "123451" "" "" "123455" "" "" "" "" "ABC-12345" "54322-XYZ" "" "" ""; string utf8_expected; StrUtil::iso88591_to_utf8(expected, utf8_expected); DomParser parser; parser.enable_validation("../docs/schemas"); BrDomainInfo domain_info; bool exception_caught = false; try { domain_info.set_response(utf8_expected, &parser); } catch (const XmlException &e) { exception_caught = true; printf("\nXml Exception: code [%d] message [%s] low level message [%s]\n", e.get_code(), e.get_msg().c_str(), e.get_low_level_msg().c_str()); cout << endl << domain_info.get_xml() << endl; } CPPUNIT_ASSERT(!exception_caught); BrDomainInfoRsp* domain_info_rsp = domain_info.get_response(); CPPUNIT_ASSERT(domain_info_rsp != 0); map results; map ::const_iterator r_it; results = domain_info_rsp->get_result_list(); r_it = results.begin(); CPPUNIT_ASSERT(r_it != results.end()); CPPUNIT_ASSERT_EQUAL(Response::OK, r_it->first); string result_code = StrUtil::to_string("%d", (int)r_it->first); string response = "" "" "" "" "get_result_lang(); if (result_lang != "en") { response += " lang='" + result_lang + "'"; } response += ">" + r_it->second.msg + "" "" "" ""; //get_name //get_roid response += "" + domain_info_rsp->get_name() + "" "" + domain_info_rsp->get_roid() + ""; //get_status_set set status_set = domain_info_rsp->get_status_set(); set::const_iterator it; for (it = status_set.begin(); it != status_set.end(); it++) { response += ""; } //get_contacts map< string, string, less > contacts = domain_info_rsp->get_contacts(); map< string, string, less >::const_iterator it_map; for (it_map = contacts.begin(); it_map != contacts.end(); it_map++) { response += "" + (*it_map).second + ""; } //get_nameservers response += ""; vector nameservers = domain_info_rsp->get_nameservers(); vector::const_iterator it_ns; set::const_iterator it_ip; for (it_ns = nameservers.begin(); it_ns != nameservers.end(); it_ns++) { response += "" ; response += "" + it_ns->name + ""; for (it_ip = it_ns->ips.begin(); it_ip != it_ns->ips.end(); it_ip++) { response += ""; } response += ""; } response += ""; //get_clID response += "" + domain_info_rsp->get_clID() + ""; //get_crID //get_crDate response += "" + domain_info_rsp->get_crID() + "" "" + domain_info_rsp->get_crDate() + ""; //get_upID response += "" + domain_info_rsp->get_upID() + ""; //get_upDate response += "" + domain_info_rsp->get_upDate() + ""; response += "" ""; response += ""; // secDNS extension list dsInfoList = domain_info_rsp->get_dsInfo(); if (!dsInfoList.empty()) { response += ""; list::iterator ds_it; for (ds_it = dsInfoList.begin(); ds_it != dsInfoList.end(); ds_it++) { response += "" "" + StrUtil::to_string("%d", (*ds_it).get_key_tag()) + "" "" + StrUtil::to_string("%d", (*ds_it).get_algo()) + "" "" + StrUtil::to_string("%d", (*ds_it).get_digest_type()) + "" "" + (*ds_it).get_digest() + ""; unsigned int maxSigLife = (*ds_it).get_max_sig_life(); if (maxSigLife > 0) { response += "" + StrUtil::to_string("%d", maxSigLife) + ""; } if ((*ds_it).hasKeyData()) { DSInfo::KeyData kd = (*ds_it).get_key_data(); response += "" "" + StrUtil::to_string("%d", kd._flags) + "" "" + StrUtil::to_string("%d", kd._protocol) + "" "" + StrUtil::to_string("%d", kd._algorithm) + "" "" + kd._pub_key + "" ""; } response += ""; } response += ""; } // brdomain extension response += "" "" + StrUtil::to_string("%d", domain_info_rsp->get_ticketNumber()) + "" "" + domain_info_rsp->get_organization() + ""; // Release Process Flags struct ReleaseProcessFlags rpf = domain_info_rsp->get_releaseProcessFlags(); if (rpf.flag1 == 1 || rpf.flag2 == 1 || rpf.flag3 == 1) { response += " doc_pendings = domain_info_rsp->get_doc_pendings(); PENDING_CONTAINER::const_iterator doc_it; for (doc_it = doc_pendings.begin(); doc_it != doc_pendings.end(); doc_it++) { response += "" "" + (*doc_it).docType + "" "" + (*doc_it).limit + "" "" ""; } PENDING_CONTAINER dns_pendings = domain_info_rsp->get_dns_pendings(); PENDING_CONTAINER::const_iterator dns_it; for (dns_it = dns_pendings.begin(); dns_it != dns_pendings.end(); dns_it++) { response += ""; if ((*dns_it).hostName != "") { response += "" + (*dns_it).hostName + ""; } response += "" + (*dns_it).limit + "" ""; } struct PendingReleaseProc rel_pending = domain_info_rsp->get_rel_pending(); if (rel_pending.status != "") { response += "" "" + rel_pending.limit + "" ""; } response += ""; set concurrent_tickets = domain_info_rsp->get_concurrent_tickets(); set::const_iterator tkt_it; for (tkt_it = concurrent_tickets.begin(); tkt_it != concurrent_tickets.end(); tkt_it++) { response += "" + StrUtil::to_string("%d", (*tkt_it)) + ""; } response += "" "" "" "" + domain_info_rsp->get_clTRID() + "" "" + domain_info_rsp->get_svTRID() + "" "" "" ""; CPPUNIT_ASSERT_EQUAL(expected, response); // tests reset method domain_info_rsp->reset(); CPPUNIT_ASSERT_EQUAL((const string)"", domain_info_rsp->get_name()); CPPUNIT_ASSERT_EQUAL((const string)"", domain_info_rsp->get_roid()); CPPUNIT_ASSERT(domain_info_rsp->get_status_set().empty()); CPPUNIT_ASSERT_EQUAL((const string)"", domain_info_rsp->get_registrant()); CPPUNIT_ASSERT(domain_info_rsp->get_contacts().empty()); CPPUNIT_ASSERT(domain_info_rsp->get_nameservers().empty()); CPPUNIT_ASSERT_EQUAL((const string)"", domain_info_rsp->get_clID()); CPPUNIT_ASSERT_EQUAL((const string)"", domain_info_rsp->get_crID()); CPPUNIT_ASSERT_EQUAL((const string)"", domain_info_rsp->get_crDate()); CPPUNIT_ASSERT_EQUAL((const string)"", domain_info_rsp->get_upID()); CPPUNIT_ASSERT_EQUAL((const string)"", domain_info_rsp->get_exDate()); CPPUNIT_ASSERT_EQUAL((const string)"", domain_info_rsp->get_upDate()); CPPUNIT_ASSERT_EQUAL((const string)"", domain_info_rsp->get_trDate()); CPPUNIT_ASSERT_EQUAL((const string)"", domain_info_rsp->get_authInfo().get_roid()); CPPUNIT_ASSERT_EQUAL((const string)"", domain_info_rsp->get_authInfo().get_pw()); // BrDomainInfoRsp specific attributes CPPUNIT_ASSERT_EQUAL(0, domain_info_rsp->get_ticketNumber()); CPPUNIT_ASSERT_EQUAL((string)"", domain_info_rsp->get_organization()); rpf = domain_info_rsp->get_releaseProcessFlags(); CPPUNIT_ASSERT_EQUAL(0, rpf.flag1 + rpf.flag2 + rpf.flag3); CPPUNIT_ASSERT_EQUAL(true, domain_info_rsp->get_doc_pendings().empty()); CPPUNIT_ASSERT_EQUAL(true, domain_info_rsp->get_dns_pendings().empty()); CPPUNIT_ASSERT_EQUAL((string)"", domain_info_rsp->get_rel_pending().status); CPPUNIT_ASSERT_EQUAL((string)"", domain_info_rsp->get_rel_pending().limit); CPPUNIT_ASSERT_EQUAL(true, domain_info_rsp->get_concurrent_tickets().empty()); } void BrDomainInfoTest::response_test2() { string expected = "" "" "" "" "Command completed successfully" "" "" "" "example.com.br" "EXAMPLE1-REP" "" "fan" "fan" "fan" "" "" "ns1.example.com.br" "192.0.2.1" "" "" "ns1.example.net.br" "" "" "ClientX" "ClientX" "2006-01-30T22:00:00.0Z" "ClientX" "2006-01-31T09:00:00.0Z" "" "" "" "" "" "005.506.560/0001-36" "" "" "billing" "dns" "" "" "" "" "" "ABC-12345" "54322-XYZ" "" "" ""; string utf8_expected; StrUtil::iso88591_to_utf8(expected, utf8_expected); DomParser parser; parser.enable_validation("../docs/schemas"); BrDomainInfo domain_info; bool exception_caught = false; try { domain_info.set_response(utf8_expected, &parser); } catch (const XmlException &e) { exception_caught = true; printf("\nXml Exception: code [%d] message [%s] low level message [%s]\n", e.get_code(), e.get_msg().c_str(), e.get_low_level_msg().c_str()); cout << endl << domain_info.get_xml() << endl; } CPPUNIT_ASSERT(!exception_caught); BrDomainInfoRsp* domain_info_rsp = domain_info.get_response(); CPPUNIT_ASSERT(domain_info_rsp != 0); map results; map ::const_iterator r_it; results = domain_info_rsp->get_result_list(); r_it = results.begin(); CPPUNIT_ASSERT(r_it != results.end()); CPPUNIT_ASSERT_EQUAL(Response::OK, r_it->first); string result_code = StrUtil::to_string("%d", (int)r_it->first); string response = "" "" "" "" "get_result_lang(); if (result_lang != "en") { response += " lang='" + result_lang + "'"; } response += ">" + r_it->second.msg + "" "" "" ""; //get_name //get_roid response += "" + domain_info_rsp->get_name() + "" "" + domain_info_rsp->get_roid() + ""; //get_status_set set status_set = domain_info_rsp->get_status_set(); set::const_iterator it; for (it = status_set.begin(); it != status_set.end(); it++) { response += ""; } //get_contacts map< string, string, less > contacts = domain_info_rsp->get_contacts(); map< string, string, less >::const_iterator it_map; for (it_map = contacts.begin(); it_map != contacts.end(); it_map++) { response += "" + (*it_map).second + ""; } //get_nameservers response += ""; vector nameservers = domain_info_rsp->get_nameservers(); vector::const_iterator it_ns; set::const_iterator it_ip; for (it_ns = nameservers.begin(); it_ns != nameservers.end(); it_ns++) { response += "" ; response += "" + it_ns->name + ""; for (it_ip = it_ns->ips.begin(); it_ip != it_ns->ips.end(); it_ip++) { response += ""; } response += ""; } response += ""; //get_clID response += "" + domain_info_rsp->get_clID() + ""; //get_crID //get_crDate response += "" + domain_info_rsp->get_crID() + "" "" + domain_info_rsp->get_crDate() + ""; //get_upID response += "" + domain_info_rsp->get_upID() + ""; //get_upDate response += "" + domain_info_rsp->get_upDate() + ""; response += "" ""; response += "" "" "" + domain_info_rsp->get_organization() + ""; string publicationFlag = domain_info_rsp->get_publication_flag(); response += ""; set onhold_reasons = domain_info_rsp->get_onhold_reasons(); set::const_iterator tkt_it; for (tkt_it = onhold_reasons.begin(); tkt_it != onhold_reasons.end(); tkt_it++) { response += "" + (*tkt_it) + ""; } response += "get_auto_renew()) + "\"/>" "" "" "" + domain_info_rsp->get_clTRID() + "" "" + domain_info_rsp->get_svTRID() + "" "" "" ""; CPPUNIT_ASSERT_EQUAL(expected, response); // tests reset method domain_info_rsp->reset(); CPPUNIT_ASSERT_EQUAL((const string)"", domain_info_rsp->get_name()); CPPUNIT_ASSERT_EQUAL((const string)"", domain_info_rsp->get_roid()); CPPUNIT_ASSERT(domain_info_rsp->get_status_set().empty()); CPPUNIT_ASSERT_EQUAL((const string)"", domain_info_rsp->get_registrant()); CPPUNIT_ASSERT(domain_info_rsp->get_contacts().empty()); CPPUNIT_ASSERT(domain_info_rsp->get_nameservers().empty()); CPPUNIT_ASSERT_EQUAL((const string)"", domain_info_rsp->get_clID()); CPPUNIT_ASSERT_EQUAL((const string)"", domain_info_rsp->get_crID()); CPPUNIT_ASSERT_EQUAL((const string)"", domain_info_rsp->get_crDate()); CPPUNIT_ASSERT_EQUAL((const string)"", domain_info_rsp->get_upID()); CPPUNIT_ASSERT_EQUAL((const string)"", domain_info_rsp->get_exDate()); CPPUNIT_ASSERT_EQUAL((const string)"", domain_info_rsp->get_upDate()); CPPUNIT_ASSERT_EQUAL((const string)"", domain_info_rsp->get_trDate()); CPPUNIT_ASSERT_EQUAL((const string)"", domain_info_rsp->get_authInfo().get_roid()); CPPUNIT_ASSERT_EQUAL((const string)"", domain_info_rsp->get_authInfo().get_pw()); // BrDomainInfoRsp specific attributes CPPUNIT_ASSERT_EQUAL((string)"", domain_info_rsp->get_organization()); CPPUNIT_ASSERT_EQUAL((string)"", domain_info_rsp->get_publication_flag()); CPPUNIT_ASSERT_EQUAL(true, domain_info_rsp->get_onhold_reasons().empty()); CPPUNIT_ASSERT_EQUAL(-1, domain_info_rsp->get_auto_renew()); }