function testDecodeRequest() { $this->cryptoManager->expects($this->once())->method('decrypt')->with($this->equalTo('xxer4rt34x'), $this->equalTo('FakePrivateKey'))->will($this->returnValue('{"secret": "top-secret"}')); $this->assertTrue($this->securityManager->decodeRequest($this->commandRequest)); $data = $this->commandRequest->getData(); $this->assertEquals($data['foo'], 'bar', 'Plain JSON data was decoded'); $this->assertEquals($data['secret'], 'top-secret', 'Encrypted JSON data was decoded'); }
/** * Decrypt and merge encrypted data for the command request * * @param tx_caretakerinstance_CommandRequest $commandRequest * @return boolean TRUE if the command request could be decrypted */ public function decodeRequest(tx_caretakerinstance_CommandRequest $commandRequest) { $data = json_decode($commandRequest->getRawData(), TRUE); $commandRequest->mergeData($data); if (strlen($commandRequest->getData('encrypted'))) { $raw = $this->cryptoManager->decrypt($commandRequest->getData('encrypted'), $this->privateKey); if (!$raw) { // Decryption failed return FALSE; } $data = json_decode($raw, TRUE); // merge decrypted data into raw data $commandRequest->mergeData($data); } return TRUE; }
/** * Get a signature for the given command request * * @param tx_caretakerinstance_CommandRequest $commandRequest * @return string */ public function getRequestSignature($commandRequest) { return $this->cryptoManager->createSignature($commandRequest->getDataForSignature(), $this->securityManager->getPrivateKey()); }