diff --git a/AusRegCliever/include/AC_OTE.h b/AusRegCliever/include/AC_OTE.h index 26db396..81afb44 100644 --- a/AusRegCliever/include/AC_OTE.h +++ b/AusRegCliever/include/AC_OTE.h @@ -15,14 +15,17 @@ typedef auto_ptr AC_SESSION; static AC_SESSION ac_sess; - static int nCases; + int nCases,thisCase; testCases theseCases; testFuncs theseFuncs; - bool acTkInitialised = false, fatal = false, done = false, transferGainer; - const char *thisRegistry="Unknown", *thatAccount="Unknown", *thisAccount="Unknown"; - char *thisName; + + bool acTkInitialised = false, fatal = false, done = false, transferGainer, + bindError; + + char *thisName = "registrar.ote"; + string thisRegistry("Unknown"), thatAccount("Unknown"), thisAccount("Unknown"),shitName(thisName); int cmd=0,debug=1000; string op("newInstance"); @@ -53,42 +56,95 @@ typedef auto_ptr AC_SESSION; ctcCrib,ctcCity,ctcProv,ctcPC,ctcGuo); LPCrtCmdExtension crtE1( &claims ), crtE2( &dpml ); - Transaction *thisTest; + + inline bool checkNameOK() { + + if (!parms[thisCase].isMember("name")) { + theseLogs->logN(1,"(%d) no 'name' field",cmd); + ACPRODINOTE::bindError = true; + return false; + } + + shitName = parms[thisCase]["name"].asString(); + thisName = (char *)shitName.c_str(); + return true; + + } + + inline bool checkContOK() { + + if (!parms[thisCase].isMember("cont_id")) { + ACPRODINOTE::bindError = true; + + theseLogs->logN(1,"(%d) no 'cont_id' field",cmd); + return false; + + } + + return true; + + } + + inline bool checkPWDOK(Json::Value thisPW) { + + if (thisPW.isNull() || !thisPW.asString().compare("auth.error")) { + + theseLogs->logN(1,"(%d) no 'cont_pw' field",cmd); + return false; + + } + + return true; + + } void check() { - DomainCheckCommand *c = new DomainCheckCommand(thisName); - DomainCheckResponse *r = new DomainCheckResponse(); + if (checkNameOK()) { - theseLogs->logN(2,"Queue (%d) Unextended check of %s",cmd++,thisName); - acq.push( new Transaction(c, r) ); + DomainCheckCommand *c = new DomainCheckCommand(thisName); + DomainCheckResponse *r = new DomainCheckResponse(); + + theseLogs->logN(2,"(%d) Queue Unextended check of %s",cmd++,thisName); + acq.push( new Transaction(c, r) ); + + } } void checkClaims() { - DomainCheckCommand *c = new DomainCheckCommand(thisName); - LPChkCmdExtension chkE(&claims); - c->appendExtension(chkE); - DomainCheckResponse *r = new DomainCheckResponse(); - LPChkRespExtension chkRspE; - r->registerExtension(&chkRspE); + if (checkNameOK()) { - theseLogs->logN(2,"(%d) Queue Claims type Check of %s",cmd++,thisName); - acq.push(new Transaction(c, r)); + DomainCheckCommand *c = new DomainCheckCommand(thisName); + LPChkCmdExtension chkE(&claims); + c->appendExtension(chkE); + DomainCheckResponse *r = new DomainCheckResponse(); + LPChkRespExtension chkRspE; + r->registerExtension(&chkRspE); + + theseLogs->logN(2,"(%d) Queue Claims type Check of %s",cmd++,thisName); + acq.push(new Transaction(c, r)); + + } } void create() { - theseLogs->logN(3,"(%d) Queue normal create of %s ( %s ).",cmd++, thisName, thisAccount); - DomainCreateCommand *c = new DomainCreateCommand(thisName,pw,&RID, &tech, &ns, &admin, &billing); + if (checkNameOK() && checkContOK()) + { + + DomainCreateCommand *c = new DomainCreateCommand(shitName,pw,&RID, &tech, &ns, &admin, &billing); DomainCreateResponse *r = new DomainCreateResponse(); + theseLogs->logN(3,"(%d) Queue normal create of %s ( %s ).",cmd++, thisName, thisAccount.c_str()); acq.push(new Transaction(c, r)); + } + } string noticeID("d85159710000000000000008692"), @@ -96,61 +152,80 @@ typedef auto_ptr AC_SESSION; void createClaimOverride() { + if (checkNameOK()) { DomainCreateCommand *c = new DomainCreateCommand(thisName,pw,&RID, &tech, &ns, &admin, &billing); crtE1.setNoticeID(noticeID, notAfter, acceptedDate); c->appendExtension(crtE1); DomainCreateResponse *r; - theseLogs->logN(2,"(%d)Queue create %s w Notice ID test data (TCN).",++cmd,thisName); + theseLogs->logN(2,"(%d) Queue create %s w Notice ID test data (TCN).",++cmd,thisName); acq.push(new Transaction(c, r)); + + } } void createContact() { - theseLogs->logN(2,"(%d)Queue create contact %s.",++cmd,ctc.c_str()); - ContactCreateCommand *c = new ContactCreateCommand(ctc,ctcPW,&ctcPO,ctcEmail); - ContactCreateResponse *r = new ContactCreateResponse(); + ContactCreateCommand *c = new ContactCreateCommand(ctc,ctcPW,&ctcPO,ctcEmail); + ContactCreateResponse *r = new ContactCreateResponse(); - theseLogs->logN(2,"(%d)Queue create contact %s.",++cmd,ctc.c_str()); - acq.push(new Transaction(c, r)); + theseLogs->logN(2,"(%d) Queue create contact %s.",++cmd,ctc.c_str()); + acq.push(new Transaction(c, r)); } - void dpmlCreate() { std::string dpmlName("face.dpml.zone"); + void dpmlCreate() { - DomainCreateCommand *c = new DomainCreateCommand(dpmlName,pw,&RID, &tech, &ns, &admin, &billing); - crtE2.setSMD(); - c->appendExtension(crtE2); - DomainCreateResponse *r = new DomainCreateResponse(); - theseLogs->logN(2,"(%d) Queue DPML block create %s w boitedetest.smd data.",++cmd,dpmlName.c_str()); - acq.push(new Transaction(c, r)); + if (checkNameOK()) { + + DomainCreateCommand *c = new DomainCreateCommand(thisName,pw,&RID, &tech, &ns, &admin, &billing); + crtE2.setSMD(); + c->appendExtension(crtE2); + DomainCreateResponse *r = new DomainCreateResponse(); + + theseLogs->logN(2,"(%d) Queue DPML block create %s w boitedetest.smd data.",++cmd,thisName); + acq.push(new Transaction(c, r)); + + } } void sunriseCreate() { + if (checkNameOK()) { + DomainCreateCommand *c = new DomainCreateCommand(thisName,pw,&RID, &tech, &ns, &admin, &billing); c->appendExtension(crtE1); DomainCreateResponse *r = new DomainCreateResponse(); - theseLogs->logN(2,"(%d)Queue Sunrise create %s with ICANN SMD test data.",++cmd,thisName); + theseLogs->logN(2,"(%d) Queue Sunrise create %s with ICANN SMD test data.",++cmd,thisName); acq.push(new Transaction(c, r)); + } + } void transfer() { + if (checkNameOK()) { + + Transaction *thisTest; + DomainTransferRequestCommand *c0 = new DomainTransferRequestCommand(thisName,ctcPW); DomainTransferApproveCommand *c1 = new DomainTransferApproveCommand(thisName,ctcPW); DomainTransferResponse *r = new DomainTransferResponse(); thisTest = transferGainer ? new Transaction(c0, r) : new Transaction(c1, r) ; - theseLogs->logN(4,"Queue %s (%d) %s -> %s.", (transferGainer ? "Request" : "Approve") ,cmd++, thisName,thatAccount); + theseLogs->logN(4,"(%d) Queue %s %s -> %s.", (transferGainer ? "Request" : "Approve") ,cmd++, + thisName,thatAccount.c_str()); + acq.push(thisTest); + } + } // transfer int setFuncs() { diff --git a/AusRegCliever/include/mdJSON.hpp b/AusRegCliever/include/mdJSON.hpp index 6ac7731..1d9392c 100644 --- a/AusRegCliever/include/mdJSON.hpp +++ b/AusRegCliever/include/mdJSON.hpp @@ -11,9 +11,10 @@ typedef void (*caseBody)(void); typedef struct { + string desc; const char *caseName; caseBody fBody; - const void *parms; // JSON Value + int parms; // Index of JSON Value in testSuite00 } testCase; namespace ACPRODINOTE { diff --git a/AusRegCliever/include/mdcommon.h b/AusRegCliever/include/mdcommon.h index 7b03d62..5b4d82e 100644 --- a/AusRegCliever/include/mdcommon.h +++ b/AusRegCliever/include/mdcommon.h @@ -54,7 +54,7 @@ #ifndef MD_COMMON #define MD_COMMON - +#define ACTK_CFG_PATH "./etc/toolkit2.conf" #ifndef SANS_BOOST #include #include @@ -65,6 +65,7 @@ using namespace std; using boost::asio::ip::udp; #endif +#define MAX_OTE_CASE 256 #define MAX_SCENARIO 4 // defined by increasing assumption of control from TK #define MAX_AC 1 #define MAX_CLIENTS 1 diff --git a/AusRegCliever/server/masterDaemon.cpp b/AusRegCliever/server/masterDaemon.cpp index a0457f9..34e78f1 100644 --- a/AusRegCliever/server/masterDaemon.cpp +++ b/AusRegCliever/server/masterDaemon.cpp @@ -128,7 +128,7 @@ int masterDaemon::initAusRegTK(void) { int rc=OK; const std::string cfg(thisConfig->cfg_path.empty() ? - "/home/jdaugherty/etc/toolkit2.conf" : thisConfig->cfg_path ); + ACTK_CFG_PATH : thisConfig->cfg_path ); try { diff --git a/AusRegCliever/server/mdAusReg.cpp b/AusRegCliever/server/mdAusReg.cpp index 483bbd7..8b7776d 100644 --- a/AusRegCliever/server/mdAusReg.cpp +++ b/AusRegCliever/server/mdAusReg.cpp @@ -27,6 +27,9 @@ #include #include "mdJSON.hpp" + Json::Value parms[MAX_OTE_CASE]; + bool JSONBatchInProgress = false; + namespace ACPRODINOTE { typedef boost::heap::priority_queue ACWQ; @@ -143,9 +146,9 @@ void ausRegEPPTK::registryXOTE() { // PROD in OTE return; } - theseLogs->logN(0,"Monitoring ./json for changes."); + theseLogs->logN(0,"Monitoring /json for changes."); - wd = inotify_add_watch( fd, "./json", IN_MODIFY | IN_CREATE | IN_DELETE ); + wd = inotify_add_watch( fd, "/json", IN_MODIFY | IN_CREATE | IN_DELETE ); length = read( fd, buffer, BUF_LEN ); if ( length < 0 ) { @@ -186,24 +189,32 @@ void ausRegEPPTK::registryXOTE() { // PROD in OTE } } + if (actionableFileEvent) { char wxyz[100]; sprintf(wxyz,"/json/%s",event->name); + + while (JSONBatchInProgress) { + theseLogs->logN(0, "Waiting for pending batch to complete." ); + sleep(2); + } + JSONBatchInProgress = true; - if (actionableFileEvent) { char wxyz[100]; sprintf(wxyz,"./json/%s",event->name); mdJSON scriptor; scriptor.setPath(wxyz); if (!scriptor.parse()) { didDie = false; - if (!scriptor.run()) { + if (scriptor.run()) { if (didDie) { monitoring = false; - theseLogs->logN(1, "Run of %s fatal error. ./json monitoring stops.", event->name ); + theseLogs->logN(1, "Run of %s fatal error. /json monitoring stops.", event->name ); theseLogs->logN(0, "Restart process to resume JSON monitoring operations." ); } else { - theseLogs->logN(1, "Run of %s has errors ./json monitoring continues.", event->name ); + theseLogs->logN(1, "Run of %s has errors /json monitoring continues.", event->name ); + JSONBatchInProgress = false; } } else - theseLogs->logN(1, " %s completed OK. ./json monitoring continues.", event->name ); + theseLogs->logN(1, " %s preprocessed OK. /json monitoring continues.", event->name ); } else { - theseLogs->logN(1, "Parse of %s failed. ./json monitoring continues.", event->name ); + theseLogs->logN(1, "Parse of %s failed. /json monitoring continues.", event->name ); + JSONBatchInProgress = false; } } } @@ -215,7 +226,7 @@ void ausRegEPPTK::registryXOTE() { // PROD in OTE length = read( fd, &buffer[i], (BUF_LEN - j) ); } if (monitoring) - theseLogs->logN(2,"JSON monitoring unexpected end: %d %d.",i,length); + theseLogs->logN(2,"JSON monitoring unexpected end: %d %d.",i,length); done: ( void ) inotify_rm_watch( fd, wd ); ( void ) close( fd ); @@ -245,7 +256,7 @@ void ausRegEPPTK::doPROD() manager->run(); sess->open(); // ac_mgr = manager; -// ac_sess = sess; +// ac_sess = sess; while ((1440 - minutes) > EODMARGIN) { @@ -255,23 +266,27 @@ void ausRegEPPTK::doPROD() if (debug > 999) theseLogs->logN(3,"Tx dequeued @ minute %d second %d (%d waiting).",minutes,seconds,acq.size()-1); - manager->execute(*tx); + //manager->execute(*tx); if (debug > 999) theseLogs->logN(2,"Tx completed @ minute %d second %d.",minutes,seconds); idleSeconds = 0; + if (!acq.size()) + JSONBatchInProgress = false; acq.pop(); delete tx; } if (!lastPolicyHandshake || (seconds - lastPolicyHandshake >= (REGISTRY_HANDSHAKE - 5))) - {idleSeconds = 0; + {lastPolicyHandshake = 1; goto skipHandshake; + idleSeconds = 0; if (debug > 99) theseLogs->logN(3,"AC-Registry Policy Handshake %d:%d:%d.",hours-1,minutes,seconds); lastPolicyHandshake = seconds; sess->writeXML(TEST_SE); sess->read(); + skipHandshake: ; } sleep(PRODINOTESLEEP); @@ -286,7 +301,7 @@ void ausRegEPPTK::doPROD() lastMinutes = minutes; } - if (debug > 9999 && !(seconds % 30)) + if (debug > 9999 && !(seconds % 120)) theseLogs->logN(3,"AC Production %d:%d:%d.",hours-1,minutes,seconds); } diff --git a/AusRegCliever/server/mdJSON.cpp b/AusRegCliever/server/mdJSON.cpp index b46a869..1d930ef 100644 --- a/AusRegCliever/server/mdJSON.cpp +++ b/AusRegCliever/server/mdJSON.cpp @@ -11,10 +11,17 @@ #include #include "mdJSON.hpp" + extern bool JSONBatchInProgresse; + + extern Json::Value parms[MAX_OTE_CASE]; + namespace ACPRODINOTE { - extern testCases theseCases; - extern testFuncs theseFuncs; + extern string thisRegistry, thisAccount, thatAccount; + extern testCases theseCases; + extern testFuncs theseFuncs; + extern int cmd,thisCase; + extern bool bindError; } using namespace std; @@ -40,36 +47,54 @@ readInputTestFile( const char *path ) bool mdJSON::run() { - bool done=false; - int i=0, nCases =0, nThings = 0, debug=1000; + bool lastMemberWasString=false,parseError=false,done=false; + int i=0, nCases =0, nThings = 0, debug=1000; - const Json::Value suite = root["testSuite00"]; + const Json::Value suite = root["testSuiteAC"]; if (!suite) { - theseLogs->logN(0,"No 'testSuite00' suite root, can't run."); + theseLogs->logN(0,"No 'testSuiteAC' suite root, can't run."); return true; } if (!suite.isObject()) { - theseLogs->logN(0,"'testSuite00' isn't an object, can't run."); + theseLogs->logN(0,"'testSuiteAC' isn't an object, can't run."); return true; } if (suite.empty()) { - theseLogs->logN(0,"'testSuite00' contains nothing, can't run."); + theseLogs->logN(0,"'testSuiteAC' contains nothing, can't run."); return true; } - theseLogs->logN(1,"'testSuite00' - binding %d fields and case objects.",suite.size()); + theseLogs->logN(1,"'testSuiteAC' - binding %d fields and case objects.",suite.size()); Json::Value::Members itemNames = suite.getMemberNames(); + string thisTestCase(""), thisTestCaseDesc(""); + + ACPRODINOTE::thisRegistry = string(""); + ACPRODINOTE::thisAccount = string(""); + ACPRODINOTE::thatAccount = string(""); for ( i = 0; i < itemNames.size(); ++i ) { const char *thisItem; try { thisItem = itemNames[i].c_str(); + Json::Value thisMember = suite.get(thisItem,root); if (debug > 100000) theseLogs->logN(1,"item %s.",thisItem); - if (!stricmp(thisItem,"registry")) { - + if (!stricmp(thisItem,"registry") && thisMember.isString()) { + theseLogs->logN(1,"The primary name provider is '%s'",thisMember.asString().c_str()); + ACPRODINOTE::thisRegistry = thisMember.asString(); + continue; + } + if (!stricmp(thisItem,"accounta") && thisMember.isString()) { + theseLogs->logN(1,"The first OTE account is '%s'",thisMember.asString().c_str()); + ACPRODINOTE::thisAccount = thisMember.asString(); + continue; + } + if (!stricmp(thisItem,"accountb") && thisMember.isString()) { + theseLogs->logN(1,"The second OTE account is '%s'",thisMember.asString().c_str()); + ACPRODINOTE::thatAccount = thisMember.asString(); + continue; } if (strncmp(thisItem,"case",4)) continue; if (strlen(thisItem) != 6) continue; @@ -79,27 +104,53 @@ bool mdJSON::run() theseLogs->logN(1,"No logic to bind to '%s', need it.",thisItem); return false; } - //if (!suite[i].isObject()) { - // theseLogs->logN(1,"'%s' isn't an object, can't use.",thisItem); - // continue; - //} - ACPRODINOTE::theseCases[nCases].parms = NULL; + if (thisMember != root && thisMember.isString()) { + thisTestCase = string(thisItem); + if (!lastMemberWasString) + {thisTestCaseDesc = thisMember.asString(); lastMemberWasString = true;} + else { + parseError = true; + theseLogs->logN(0,"Invalid consecutive strings in outer test suite."); + theseLogs->logN(0,"Must be descriptive comment then test object it describes."); + } + lastMemberWasString = true; + continue; + } + if (thisMember != root && thisMember.isObject()) { + parms[nCases] = suite.get(thisItem,root); ACPRODINOTE::theseCases[nCases].fBody = ACPRODINOTE::theseFuncs[thisItem]; ACPRODINOTE::theseCases[nCases++].caseName = thisItem; + lastMemberWasString = false; + ACPRODINOTE::theseCases[nCases++].desc = thisTestCaseDesc; + } } catch (...) { - theseLogs->logN(1,"Test case binding exception: %s ",thisItem ); + theseLogs->logN(1,"Test case parse exception: %s ",thisItem ); } } - theseLogs->logN(1,"%d cases bound, beginning execution.",nCases); + if (ACPRODINOTE::thisRegistry.empty()) { + theseLogs->logN(0,"No primary name provider."); parseError = true; } - for (i=0;ilogN(0,"At least one account must be specified."); parseError = true; } + + if (parseError) { + theseLogs->logN(0,"parse errors, script cannot be run"); + return true; + } + + ACPRODINOTE::bindError = false; + theseLogs->logN(1,"%d cases parsed, bind and queueing begins.",nCases); + + for (i=0;ilogN(2,"%d Begin setup of %s ",i+1,ACPRODINOTE::theseCases[i].caseName ); + theseLogs->logN(2,"%d Setup %s ...",i+1,ACPRODINOTE::theseCases[i].caseName ); + ACPRODINOTE::thisCase = ACPRODINOTE::theseCases[i].parms; ACPRODINOTE::theseCases[i].fBody(); - theseLogs->logN(2,"%d End setup of %s ",i+1,ACPRODINOTE::theseCases[i].caseName ); + theseLogs->logN(3,"%d ... %s %d parameter(s) ",i+1,ACPRODINOTE::theseCases[i].caseName,parms[i].size() ); } catch (exception e) { @@ -108,11 +159,18 @@ bool mdJSON::run() catch (...) { theseLogs->logN(1,"Unknown test case fault in %s ",ACPRODINOTE::theseCases[i].caseName ); - } + } } - theseLogs->logN(0,"Suite 'testSuite00' end execution."); -} + if (ACPRODINOTE::bindError) { + theseLogs->logN(0,"binding errors, script cannot be run"); + return true; + } + else + theseLogs->logN(0,"Suite 'testSuiteAC' end bind and queue for execution."); + return done; // Should be false if no error. + +} static bool parseValueTree( const std::string &input, const std::string &kind, Json::Value &root, const Json::Features &features) { diff --git a/json/OTEC.json b/json/OTEC.json index e939df4..83123d5 100644 --- a/json/OTEC.json +++ b/json/OTEC.json @@ -7,58 +7,14 @@ "testSuites": "Outer block of a set of inputs to mdJSON.cpp to be run by ausRegTK::registryXOTE()", "testSuites": "Repeat case name casexx as needed, to run needs logic bound in RegistryXOTE.h", - "testSuite00" : { + "testSuiteAC" : { "Registry" : "Donuts", "AccountA" : "secura1-ote", "AccountB" : "secura2-ote2", "case00" : "Create a contact", - "case-00" : { - - "cont_id": "renjuan", - "cont_pw": "Ab9dW@rd", - "cont_email": "juan@acm.org", - "cont-name": "Ren Ren-Juan", - "cont-city": "Niagara Falls", - "cont_street1": "2926 2nd Street", - "cont-province": "NY", - "cont-postal-code": "14305", - "cont-guo": "US", - "cont-org": "American Kybernetik" - - }, - - "case01" : "Conventional / Standard/ Unextended Check", - "case-01" : { - - "name" : "bestever.camera" - - }, - - "case02" : "Check with Claims Extension", - "case-02" : { - - "name" : "unicycles.bike" - }, - - "case03" : "Conventional / Standard / Unextended Create", - "case-03" : { - - "name" : "greedy.ventures" - - }, - - "case04" : "DPML Create", - "case-04" : { - - "name" : "face.dpml.zone", - "smd-data" : "./smd/face-test.smd" - - }, - - "case00" : "Create another contact", - "case-00" : { + "case00" : { "cont_id": "renjuan2", "cont_pw": "Ab9dW@rd", @@ -73,8 +29,52 @@ }, + "case01" : "Conventional / Standard/ Unextended Check", + "case01" : { + + "name" : "bestever.camera" + + }, + + "case02" : "Check with Claims Extension", + "case02" : { + + "name" : "unicycles.bike" + }, + + "case03" : "Conventional / Standard / Unextended Create", + "case03" : { + + "name" : "greedy.ventures" + + }, + "case04" : "DPML Create", - "case-04" : { + "case04" : { + + "name" : "face.dpml.zone", + "smd-data" : "./smd/face-test.smd" + + }, + + "case00" : "Create another contact", + "case00" : { + + "cont_id": "renjuan3", + "cont_pw": "Ab9dW@rd", + "cont_email": "juan@acm.org", + "cont-name": "Ren Ren-Juan", + "cont-city": "Niagara Falls", + "cont_street1": "2926 2nd Street", + "cont-province": "NY", + "cont-postal-code": "14305", + "cont-guo": "US", + "cont-org": "American Kybernetik" + + }, + + "case04" : "DPML Create", + "case04" : { "name" : "secura.dpml.zone", "smd-data" : "./smd/secura-test.smd" @@ -82,7 +82,7 @@ }, "case05" : "Create with TCN Override", - "case-05" : { + "case05" : { "name" : "greedy.ventures", "noticeID" : "", @@ -92,4 +92,4 @@ } } -} \ No newline at end of file +}