/* * 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: BrDomainCreateTest.cpp 897 2007-03-08 20:29:05Z eduardo $ */ #include #include #include "libepp_nicbr.H" #include "StrUtil.H" #include "BrDomainCreateTest.H" #include "BrDomainCreate.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(BrDomainCreateTest); BrDomainCreateTest::BrDomainCreateTest() {} BrDomainCreateTest::~BrDomainCreateTest() {} void BrDomainCreateTest::setUp() {} void BrDomainCreateTest::tearDown() {} void BrDomainCreateTest::set_xml_template_test() { set_xml_template_test(true); set_xml_template_test(false); } void BrDomainCreateTest::set_xml_template_test(bool withDNSSECExtension) { string to_be_parsed = "" "" "" "" "" "$(name)$" "$(period)$" "$(nameservers)$" "$(registrant)$" "$(other_contacts)$" "$(auth_info)$" "" "$(ext_begin)$" "$(ds_ext)$" "$(br_ext)$" "$(ext_end)$" "" "$(clTRID)$" "" ""; string expected = "" "" "" "" "" "example.com.br" "" "" "ns1.example.com.br" "192.0.2.1" "" "" "ns1.example.net.br" "" "" "fan" "fan" "fan" "" "2fooBAR" "" "" ""; if (withDNSSECExtension) { expected += "" "" "12345" "3" "1" "49FD46E6C4B45C55D4AC" "86400" "" ""; } expected += "" "" "005.506.560/0001-36" "" "" "" "" "" "" "ABC-12345" "" ""; //parent information BrDomainCreate brdcreate; BrDomainCreateCmd* cmd = brdcreate.get_command(); cmd->set_name("example.com.br"); struct NameServer ns; struct NSIPAddr ip; ns.name = "ns1.example.com.br"; ip.version = "v4"; ip.addr = "192.0.2.1"; ns.ips.insert(ip); cmd->insert_nameserver(ns); ns.name = "ns1.example.net.br"; ns.ips.clear(); cmd->insert_nameserver(ns); cmd->insert_contact("admin", "fan"); cmd->insert_contact("tech", "fan"); cmd->insert_contact("billing", "fan"); AuthInfo ai; ai.set_pw("2fooBAR"); cmd->set_authInfo(ai); if (withDNSSECExtension) { //DS information DSInfo ds; ds.set_key_tag(12345); ds.set_algo(3); ds.set_digest_type(1); ds.set_digest("49FD46E6C4B45C55D4AC"); ds.set_max_sig_life(86400); cmd->add_dsInfo(ds); } //BrDomainCreate specific information cmd->set_organization("005.506.560/0001-36"); struct ReleaseProcessFlags rpf; rpf.flag1 = 1; cmd->set_releaseProcessFlags(rpf); cmd->set_auto_renew(1); //set_xml_template/get_xml cmd->set_clTRID("ABC-12345"); brdcreate.set_xml_template(to_be_parsed); CPPUNIT_ASSERT_EQUAL(expected, brdcreate.get_xml()); //tests reset method cmd->reset(); //parent information CPPUNIT_ASSERT_EQUAL((string)"", cmd->get_name()); CPPUNIT_ASSERT(cmd->get_nameservers().empty()); CPPUNIT_ASSERT(cmd->get_contacts().empty()); CPPUNIT_ASSERT_EQUAL((string)"", cmd->get_authInfo().get_pw()); CPPUNIT_ASSERT_EQUAL((string)"", cmd->get_authInfo().get_roid()); //BrDomainCreate specific information CPPUNIT_ASSERT_EQUAL((string)"", cmd->get_organization()); CPPUNIT_ASSERT(cmd->get_releaseProcessFlags().flag1 == 0); CPPUNIT_ASSERT(cmd->get_releaseProcessFlags().flag2 == 0); CPPUNIT_ASSERT(cmd->get_releaseProcessFlags().flag3 == 0); CPPUNIT_ASSERT(cmd->get_auto_renew() == -1); } void BrDomainCreateTest::command_test() { BrDomainCreate domain_create; BrDomainCreateCmd *cmd = domain_create.get_command(); //parent information cmd->set_name("asultimasnuvensazuisnoceudaalamedaprincipal.org.br"); cmd->set_period(12, "m"); struct NameServer ns; struct NSIPAddr ip; ns.name = "ns1.nuvens.org"; cmd->insert_nameserver(ns); ns.name = "ns0.nuvens.org"; cmd->insert_nameserver(ns); ns.name = "ns3.nuvens.org"; ip.addr = "192.168.0.1"; ns.ips.insert(ip); cmd->insert_nameserver(ns); cmd->set_registrant("João Basílio 1º"); cmd->insert_contact("tech", "EDS279"); cmd->insert_contact("billing", "XXX"); cmd->insert_contact("admin", "HKK"); AuthInfo authInfo; authInfo.set_roid(""); authInfo.set_pw("abc123"); cmd->set_authInfo(authInfo); //BrDomainCreateCmd specific information cmd->set_organization("005.506.560/0001-36"); struct ReleaseProcessFlags rpf; rpf.flag1 = 1; cmd->set_releaseProcessFlags(rpf); bool exception_caught = false; try { string xml_template = FileUtil::read_file("../docs/templates/br_domain_create.xml"); domain_create.get_command()->set_clTRID("ABC-12345"); domain_create.set_xml_template(xml_template); DomParser parser; //parser.enable_validation("../docs/schemas"); parser.parse_command(domain_create.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()); cout << endl << domain_create.get_xml() << endl; } CPPUNIT_ASSERT(!exception_caught); } void BrDomainCreateTest::response_test() { string expected = "" "" "" "" "Command completed successfully; action pending" "" "" "" "example.com.br" "2006-01-30T22:00:00.0Z" "" "" "" "" "123456" "" "" "CNPJ" "2006-03-01T22:00:00.0Z" "" "Cadastro Nacional da Pessoa Juridica" "" "" "" "" "ns1.example.com.br" "" "2006-02-13T22:00:00.0Z" "" "" "" "123451" "" "" "123455" "" "" "" "" "ABC-12345" "54321-XYZ" "" "" ""; DomParser parser; parser.enable_validation("../docs/schemas"); BrDomainCreate domain_create; bool exception_caught = false; try { domain_create.set_response(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_create.get_xml() << endl; } CPPUNIT_ASSERT(!exception_caught); BrDomainCreateRsp* rsp = domain_create.get_response(); map results; map ::const_iterator r_it; results = rsp->get_result_list(); r_it = results.begin(); CPPUNIT_ASSERT(r_it != results.end()); CPPUNIT_ASSERT_EQUAL(Response::OK_ACTION_PENDING, 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 + "" "" "" "" "" + rsp->get_name() + "" "" + rsp->get_crDate() + ""; if (rsp->get_exDate() != "") { response += "" + rsp->get_exDate() + ""; } response += "" ""; //BrDomainCreate specific information response += "" ""; response += "" + StrUtil::to_string("%d", rsp->get_ticketNumber()) + "" ""; PENDING_CONTAINER doc_pendings = 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 = rsp->get_dns_pendings(); PENDING_CONTAINER::const_iterator dns_it; for (dns_it = dns_pendings.begin(); dns_it != dns_pendings.end(); dns_it++) { response += "" "" + (*dns_it).hostName + "" "" + (*dns_it).limit + "" ""; } struct PendingReleaseProc rel_pending = rsp->get_rel_pending(); if (rel_pending.status != "") { response += "" "" + rel_pending.limit + "" ""; } response += ""; set concurrent_tickets = 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 += "" "" "" "" + rsp->get_clTRID() + "" "" + rsp->get_svTRID() + "" "" "" ""; CPPUNIT_ASSERT_EQUAL(expected, response); //tests reset method rsp->reset(); //parent specific CPPUNIT_ASSERT_EQUAL((const string)"", rsp->get_name()); CPPUNIT_ASSERT_EQUAL((const string)"", rsp->get_crDate()); CPPUNIT_ASSERT_EQUAL((const string)"", rsp->get_exDate()); //BrDomainCreate CPPUNIT_ASSERT_EQUAL(0, rsp->get_ticketNumber()); CPPUNIT_ASSERT(rsp->get_doc_pendings().empty()); CPPUNIT_ASSERT(rsp->get_dns_pendings().empty()); CPPUNIT_ASSERT_EQUAL((const string) "", rsp->get_rel_pending().status); CPPUNIT_ASSERT_EQUAL((const string) "", rsp->get_rel_pending().limit); }