/* * 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: DomainInfoTest.cpp 901 2007-03-08 21:07:01Z eduardo $ */ #include #include "libepp_nicbr.H" #include "DomainInfoTest.H" #include "DomainInfo.H" #include "FileUtil.H" #include "IoException.H" #include "XmlException.H" using std::auto_ptr; #include using namespace std; LIBEPP_NICBR_NS_USE CPPUNIT_TEST_SUITE_REGISTRATION(DomainInfoTest); DomainInfoTest::DomainInfoTest() {} DomainInfoTest::~DomainInfoTest() {} void DomainInfoTest::setUp() {} void DomainInfoTest::tearDown() {} void DomainInfoTest::set_xml_template_test() { string to_be_parsed = "" "" "" "" "$(name)$" "$(auth_info)$" "" "" "$(clTRID)$" ""; DomainInfo domain_info; DomainInfoCmd* 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); domain_info.get_command()->set_clTRID("ABC-12345"); domain_info.set_xml_template(to_be_parsed); string expected = "" "" "" "EmmaWatsonIsCharming.com" "" "abc123" "" "" "" "ABC-12345" ""; CPPUNIT_ASSERT_EQUAL(expected, domain_info.get_xml()); // tests reset method domain_info_cmd = domain_info.get_command(); domain_info_cmd->reset(); CPPUNIT_ASSERT(domain_info_cmd->get_name() == ""); CPPUNIT_ASSERT(domain_info_cmd->get_hosts_control() == "all"); CPPUNIT_ASSERT(domain_info_cmd->get_authInfo().get_pw() == ""); CPPUNIT_ASSERT(domain_info_cmd->get_authInfo().get_roid() == ""); // parent attribute CPPUNIT_ASSERT(domain_info_cmd->get_clTRID() == ""); } void DomainInfoTest::command_test() { DomainInfo domain_info; DomainInfoCmd *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/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 DomainInfoTest::response_test() { response_test(true); response_test(false); } void DomainInfoTest::response_test(bool withDNSSECExtension) { string expected = "" "" "" "" "Command completed successfully" "" "" "" "EmmaWatsonIsCharming.org" "YADAYADAYADA-ABC" "" "" "SH8013-REP" "Voldemort" "Dumbledore" "" "" "ns1.EmmaWatsonIsCharming.org" "" "192.168.0.1" "" "" "ns1.granger.com" "" "" "MrPotter" "Weasley" "1999-04-03T22:00:00.0Z" "Sirius" "2002-12-12T22:00:00.0Z" "2001-04-03T22:00:00.0Z" "2005-01-03T22:00:00.0Z" "" "FooBar321" "" "" ""; if (withDNSSECExtension) { expected += "" "" "" "12345" "3" "1" "49FD46E6C4B45C55D4AC" "604800" "" "256" "3" "1" "AQPJ////4Q==" "" "" "" "12345" "3" "1" "49FD46E6C4B45C55D4AC" "" "" ""; } expected += "" "ABC-12345" "54321-XYZ" "" "" ""; DomParser parser; parser.enable_validation("../docs/schemas"); DomainInfo domain_info; CPPUNIT_ASSERT_NO_THROW(domain_info.set_response(expected, &parser)); DomainInfoRsp* domain_info_rsp = domain_info.get_response(); CPPUNIT_ASSERT(domain_info_rsp != 0); string result_code = "1000"; 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 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_registrant response += "" + domain_info_rsp->get_registrant() + ""; //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 //get_exDate //get_trDate response += "" + domain_info_rsp->get_upDate() + "" "" + domain_info_rsp->get_exDate() + "" "" + domain_info_rsp->get_trDate() + ""; //get_pw response += "" "" + domain_info_rsp->get_authInfo().get_pw() + "" ""; response += "" ""; // secDNS extension list dsInfoList = domain_info_rsp->get_dsInfo(); if (!dsInfoList.empty()) { response += ""; 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 += ""; response += ""; } 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()); }