public function testInstantiation() { $exception = new InternalServerError(9, [1, 2, 3]); $this->assertEquals('Internal Server Error', $exception->getMessage()); $this->assertEquals(500, $exception->getStatusCode()); $this->assertEquals(9, $exception->getCode()); $this->assertEquals([1, 2, 3], $exception->getDetails()); }
function saveAuthData($configHash, $ServerId, $transactionId, $auid, $username, $authInfos, $now) { $saved = $this->save(array('serverId' => $ServerId, 'configHash' => $configHash, 'transactionId' => $transactionId, 'auid' => $auid, 'username' => $username, 'authInfos' => $authInfos, 'startTime' => $now, 'firstUse' => '1'), 'oa_voters'); if (!$saved) { InternalServerError::throwException(3010, 'internal server error; auth infos not saved', 'config hash: ' . $electionId . ', username: ' . $username); } return $saved; }
function newElection($electionId, $checkTokenUrl) { $exists = $this->load(array('electionId' => $electionId), 'xt_config', 'electionId'); if (isset($exists[0])) { WrongRequestException::throwException(3000, 'election ID already used', $electionId); } $saved = $this->save(array('electionId' => $electionId, 'checkTokenUrl' => $checkTokenUrl), 'xt_config'); if (!$saved) { InternalServerError::throwException(3001, 'internal server error; election not saved', $electionId); } return $saved; }
function newElection($electionId, $secret) { $exists = $this->load(array('electionId' => $electionId), 'sp_credentials', 'electionId'); if (isset($exists[0])) { WrongRequestException::throwException(3000, 'election ID already used', $electionId); } $saved = $this->save(array('electionId' => $electionId, 'sp_credentials' => $secret), 'sp_credentials'); if (!$saved) { InternalServerError::throwException(3001, 'internal server error; election not saved', $electionId); } return $saved; }
static function excuteAction($url) { try { $found = false; foreach (self::$controllers as $ctr) { if (preg_match($ctr['pattern'], $url)) { $c = new $ctr['cls'](); $c->render($url); $found = true; break; } } if (!$found) { throw new NotFound(); } } catch (HttpException $h) { $h->render(); } catch (Exception $e) { $e = new InternalServerError($e); $e->render(); } }
/** * * @param unknown $electionId * @param unknown $req : $$req['sharedPassw'] */ function handleNewElectionReq($electionId, $req) { $authConfig = parent::handleNewElectionReq($electionId, $req); if (isset($electionId) && isset($req['sharedPassw']) && gettype($electionId) == 'string' && gettype($req['sharedPassw']) == 'string') { $ok = $this->newElection($electionId, $req['sharedPassw']); if (!$ok) { InternalServerError::throwException(2710, 'Internal server error: error saving election auth information', "request received: \n" . print_r($req, true)); } return $authConfig; } else { WrongRequestException::throwException(2000, 'ElectionId or shared password not set or of wrong type', "request received: \n" . print_r($req, true)); } }
function checkPhase($phase) { switch ($phase) { case 'registering': $starttag = 'RegistrationStartDate'; $endtag = 'RegistrationEndDate'; $errnoAdd = 0; break; case 'voting': $starttag = 'VotingStart'; $endtag = 'VotingEnd'; $errnoAdd = 2; break; case 'getResult': $starttag = 'VotingEnd'; $endtag = false; // after end of voting always allow getting the result $errnoAdd = 4; break; default: InternalServerError::throwException(47563523, 'checkcredentials: not supported phase', print_r($phase, true)); break; } if (isset($this->authConfig[$starttag])) { $startdate = strtotime($this->authConfig[$starttag]); } else { $startdate = strtotime('2000-01-01T00:00Z'); } if ($endtag !== false && isset($this->authConfig[$endtag])) { $enddate = strtotime($this->authConfig[$endtag]); } else { $enddate = strtotime('2038-01-01T00:00Z'); } // TODO use DateTime() which supports 64bit $now = time(); $ret = $startdate <= $now && $enddate >= $now; if ($ret !== true) { if ($startdate > $now) { WrongRequestException::throwException(3 + $errnoAdd, "The phase /{$phase}/ is yet to begin", $startdate); } if ($enddate < $now) { WrongRequestException::throwException(4 + $errnoAdd, "The phase /{$phase}/ already ended", $enddate); } } return $ret; }
/** * * @param unknown $electionId * @param unknown $req : $req['externalToken'] */ function handleNewElectionReq($electionId, $req) { $ret = parent::handleNewElectionReq($electionId, $req); if (!isset($electionId)) { WrongRequestException::throwException(2340, 'ElectionId not set', "request received: \n" . print_r($req, true)); } if (gettype($electionId) != 'string') { WrongRequestException::throwException(2345, 'ElectionId is not of type /string/', "request received: \n" . print_r($req, true)); } if (isset($req['configId']) && gettype($req['configId']) == 'string') { $ret['configId'] = $req['configId']; return $ret; } else { if (isset($req['checkTokenUrl']) && gettype($req['checkTokenUrl']) == 'string') { $ok = $this->newElection($electionId, $req['checkTokenUrl']); if (!$ok) { InternalServerError::throwException(2710, 'Internal server error: error saving election auth information', "request received: \n" . print_r($req, true)); } return $ret; } else { WrongRequestException::throwException(2350, 'neither chekTokenUrl nor configId is set', "request received: \n" . print_r($req, true)); } } }
/** * * @param unknown $electionId * @param unknown $req : $req['listId'] * @return auth config data to be saved with the election config because the client need to know it for obtaining voting permission */ function handleNewElectionReq($electionId, $req) { $authconfig = parent::handleNewElectionReq($electionId, $req); if (!isset($req["serverId"]) || !is_string($req['serverId'])) { WrongRequestException::throwException(12001, 'Missing /listId/ in election config', "request received: \n" . print_r($req, true)); } if (!isset($req["listId"]) || !is_string($req['listId'])) { WrongRequestException::throwException(12001, 'Missing /listId/ in election config', "request received: \n" . print_r($req, true)); } if (!isset($req["nested_groups"]) || !is_array($req['nested_groups'])) { WrongRequestException::throwException(12002, 'Missing /nested_groups/ in election config', "request received: \n" . print_r($req, true)); } if (!isset($req["verified"]) || !is_bool($req['verified'])) { WrongRequestException::throwException(12003, 'Missing /verified/ in election config', "request received: \n" . print_r($req, true)); } if (!isset($req["eligible"]) || !is_bool($req['eligible'])) { WrongRequestException::throwException(12004, 'Missing /eligible/ in election config', "request received: \n" . print_r($req, true)); } if (!isset($electionId) || !is_string($electionId)) { WrongRequestException::throwException(12005, '/ElectionId/ not set or of wrong type', "request received: \n" . print_r($req, true)); } $authconfig['serverId'] = $req['serverId']; $authconfig['listId'] = $req["listId"]; $authconfig['nested_groups'] = $req["nested_groups"]; $authconfig['verified'] = $req["verified"]; $authconfig['eligible'] = $req["eligible"]; // TODO don't save any data until everything is completed (no error occured in the further steps) // TODO don't save any public config data in separate data base - just use the config $ok = $this->newElection($electionId, $req['serverId'], $authconfig); // TODO think about taking serverId always from election-config if (!$ok) { InternalServerError::throwException(12020, 'Internal server error: error saving election auth information', "request received: \n" . print_r($req, true)); } return $authconfig; }