/** * Execute the given command request * * @param tx_caretakerinstance_CommandRequest $commandRequest * @return tx_caretakerinstance_CommandResult */ public function executeRequest($commandRequest) { $httpRequestResult = $this->executeHttpRequest($commandRequest->getServerUrl(), array('st' => $commandRequest->getSessionToken(), 'd' => $commandRequest->getData(), 's' => $commandRequest->getSignature())); if (is_array($httpRequestResult)) { if ($httpRequestResult['info']['http_code'] === 200) { $json = $this->securityManager->decodeResult($httpRequestResult['response']); // TODO: check if valid json if ($json) { return tx_caretakerinstance_CommandResult::fromJson($json); } else { if (!empty($httpRequestResult['response'])) { $json = json_decode($httpRequestResult['response'], TRUE); if ($json && $json['status'] == -1) { return $this->getCommandResult(tx_caretakerinstance_CommandResult::status_undefined, NULL, 'Error while executing remote command: ' . $json['message'] . ' (' . $json['exception']['code'] . ')'); } } return $this->getCommandResult(tx_caretakerinstance_CommandResult::status_undefined, NULL, 'Cant decode remote command result'); } } else { if ($httpRequestResult['info']['http_code'] === 0) { // seems to be a timeout return $this->getCommandResult(tx_caretakerinstance_CommandResult::status_undefined, NULL, 'No Response/Timeout (Total-Time: ' . $httpRequestResult['info']['total_time'] . ')'); } else { return $this->getCommandResult(tx_caretakerinstance_CommandResult::status_error, NULL, 'Invalid result: ' . $httpRequestResult['response'] . chr(10) . 'CURL Info: ' . var_export($httpRequestResult['info'], true)); } } } else { return $this->getCommandResult(tx_caretakerinstance_CommandResult::status_error, NULL, 'Invalid result request could not be executed' . chr(10) . 'CURL Info: ' . var_export($httpRequestResult['info'], true)); } }
function testEncodeResultDecodesStringWithPrivateKey() { $this->cryptoManager->expects($this->once())->method('decrypt')->with($this->equalTo('Encoded result'), $this->equalTo('FakePrivateKey'))->will($this->returnValue('My result data')); $encodedResult = $this->securityManager->decodeResult('Encoded result'); $this->assertEquals('My result data', $encodedResult); }