#include "xml/XMLParser.hpp" #include "common/init.hpp" #include "common/Test.hpp" #include "session/Timer.hpp" #include "SecDNSDSData.hpp" #include "SecDNSKeyData.hpp" #include "SecDNSDSOrKeyType.hpp" #include "DomainSecDNSUpdateCommandExtension.hpp" #include "se/DomainUpdateCommand.hpp" #include "se/CLTRID.hpp" using namespace std; void testSecDNSAddFieldsUrgent() { Timer::setTime("20140101.010101"); CLTRID::setClID("ACTKUTST"); string passwd = "jtkUT3st"; string registrantID = "JTKCON"; DomainUpdateCommand updateCommand("ACTKUTST.mop.biz", &passwd, NULL, NULL, ®istrantID); auto_ptr dsData(new SecDNSDSData(12345, 3, 1, "49FD46E6C4B45C55D4AC")); auto_ptr keyData(new SecDNSKeyData(256, 3, 1, "AQPJ////4Q==")); dsData->setKeyData(keyData.release()); auto_ptr addData(new SecDNSDSOrKeyType()); auto_ptr maxSigLife(new SecDNSMaxSigLifeType(604800)); addData->setMaxSigLife(maxSigLife.release()); addData->addToDSData(dsData.release()); DomainSecDNSUpdateCommandExtension extension; extension.setUrgent(true); extension.setAddData(addData.release()); updateCommand.appendExtension(extension); const string xml = updateCommand.toXML(); ASSERT_EQ(xml, "ACTKUTST.mop.bizJTKCONjtkUT3st604800123453149FD46E6C4B45C55D4AC25631AQPJ////4Q==ACTKUTST.20140101.010101.0" ); } void testSecDNSRemoveFieldsNotUrgent() { Timer::setTime("20140101.010101"); CLTRID::setClID("ACTKUTST"); string passwd = "jtkUT3st"; string registrantID = "JTKCON"; DomainUpdateCommand updateCommand("ACTKUTST.mop.biz", &passwd, NULL, NULL, ®istrantID); auto_ptr dsData(new SecDNSDSData(65535, 255, 255, "49FD46E6C4B45C55D4AC")); auto_ptr keyData(new SecDNSKeyData(65535, 255, 255, "AQPJ////4Q==")); dsData->setKeyData(keyData.release()); auto_ptr remData(new SecDNSRemType()); remData->addToDSData(dsData.release()); DomainSecDNSUpdateCommandExtension extension; extension.setUrgent(false); extension.setRemData(remData.release()); updateCommand.appendExtension(extension); const string xml = updateCommand.toXML(); ASSERT_EQ(xml, "ACTKUTST.mop.bizJTKCONjtkUT3st6553525525549FD46E6C4B45C55D4AC65535255255AQPJ////4Q==ACTKUTST.20140101.010101.0" ); } void testSecDNSRemoveAll() { Timer::setTime("20140101.010101"); CLTRID::setClID("ACTKUTST"); string passwd = "jtkUT3st"; string registrantID = "JTKCON"; DomainUpdateCommand updateCommand("ACTKUTST.mop.biz", &passwd, NULL, NULL, ®istrantID); auto_ptr remData(new SecDNSRemType()); remData->setRemoveAll(true); DomainSecDNSUpdateCommandExtension extension; extension.setUrgent(true); extension.setRemData(remData.release()); updateCommand.appendExtension(extension); const string xml = updateCommand.toXML(); ASSERT_EQ(xml, "ACTKUTST.mop.bizJTKCONjtkUT3sttrueACTKUTST.20140101.010101.0" ); } void testSecDNSRemoveAllAndAddDsData() { Timer::setTime("20140101.010101"); CLTRID::setClID("ACTKUTST"); string passwd = "jtkUT3st"; string registrantID = "JTKCON"; DomainUpdateCommand updateCommand("ACTKUTST.mop.biz", &passwd, NULL, NULL, ®istrantID); auto_ptr remData(new SecDNSRemType()); remData->setRemoveAll(true); DomainSecDNSUpdateCommandExtension extension; extension.setUrgent(true); extension.setRemData(remData.release()); auto_ptr dsData(new SecDNSDSData(65535, 255, 255, "49FD46E6C4B45C55D4AC")); auto_ptr addData(new SecDNSDSOrKeyType()); addData->addToDSData(dsData.release()); extension.setAddData(addData.release()); updateCommand.appendExtension(extension); const string xml = updateCommand.toXML(); ASSERT_EQ(xml, "ACTKUTST.mop.bizJTKCONjtkUT3sttrue6553525525549FD46E6C4B45C55D4ACACTKUTST.20140101.010101.0" ); } void testSecDNSRemoveAllAndAddKeyData() { Timer::setTime("20140101.010101"); CLTRID::setClID("ACTKUTST"); string passwd = "jtkUT3st"; string registrantID = "JTKCON"; DomainUpdateCommand updateCommand("ACTKUTST.mop.biz", &passwd, NULL, NULL, ®istrantID); auto_ptr remData(new SecDNSRemType()); remData->setRemoveAll(true); DomainSecDNSUpdateCommandExtension extension; extension.setUrgent(true); extension.setRemData(remData.release()); auto_ptr keyData(new SecDNSKeyData(65535, 255, 255, "AQPJ////4Q==")); auto_ptr addData(new SecDNSDSOrKeyType()); addData->addToKeyData(keyData.release()); extension.setAddData(addData.release()); updateCommand.appendExtension(extension); const string xml = updateCommand.toXML(); ASSERT_EQ(xml, "ACTKUTST.mop.bizJTKCONjtkUT3sttrue65535255255AQPJ////4Q==ACTKUTST.20140101.010101.0" ); } void testSecDNSRemoveAllAndAddKeyDataAndChangeMaxSigLife() { Timer::setTime("20140101.010101"); CLTRID::setClID("ACTKUTST"); string passwd = "jtkUT3st"; string registrantID = "JTKCON"; DomainUpdateCommand updateCommand("ACTKUTST.mop.biz", &passwd, NULL, NULL, ®istrantID); auto_ptr remData(new SecDNSRemType()); remData->setRemoveAll(true); DomainSecDNSUpdateCommandExtension extension; extension.setUrgent(true); extension.setRemData(remData.release()); auto_ptr keyData(new SecDNSKeyData(65535, 255, 255, "AQPJ////4Q==")); auto_ptr addData(new SecDNSDSOrKeyType()); addData->addToKeyData(keyData.release()); extension.setAddData(addData.release()); auto_ptr chgData(new SecDNSChgType()); auto_ptr maxSigLifeType(new SecDNSMaxSigLifeType(604800)); chgData->setMaxSigLife(maxSigLifeType.release()); extension.setChgData(chgData.release()); updateCommand.appendExtension(extension); const string xml = updateCommand.toXML(); ASSERT_EQ(xml, "ACTKUTST.mop.bizJTKCONjtkUT3sttrue65535255255AQPJ////4Q==604800ACTKUTST.20140101.010101.0" ); } int main(int argc, char* argv[]) { init("./etc/toolkit2.conf"); TEST_run(testSecDNSAddFieldsUrgent); TEST_run(testSecDNSRemoveFieldsNotUrgent); TEST_run(testSecDNSRemoveAll); TEST_run(testSecDNSRemoveAllAndAddDsData); TEST_run(testSecDNSRemoveAllAndAddKeyData); TEST_run(testSecDNSRemoveAllAndAddKeyDataAndChangeMaxSigLife); return TEST_errorCount(); }