/** * @param string $value * @param string $expected * * @dataProvider decryptDataProvider */ public function testDecrypt($value, $expected) { $crypt = $this->getMock('Magento\\Framework\\Encryption\\Crypt', array(), array(), '', false); $this->_cryptFactory->expects($this->once())->method('create')->will($this->returnValue($crypt)); $crypt->expects($this->once())->method('decrypt')->with($expected)->will($this->returnValue($expected)); $actual = $this->_model->decrypt($value); $this->assertEquals($expected, $actual); }
public function testDecrypt() { // sample data to encrypt $data = '0:2:z3a4ACpkU35W6pV692U4ueCVQP0m0v0p:' . '7ZPIIRZzQrgQH+csfF3fyxYNwbzPTwegncnoTxvI3OZyqKGYlOCTSx5i1KRqNemCC8kuCiOAttLpAymXhzjhNQ=='; $actual = $this->_model->decrypt($data); // Extract the initialization vector and encrypted data $parts = explode(':', $data, 4); list(, , $iv, $encrypted) = $parts; // Decrypt returned data with RIJNDAEL_256 cipher, cbc mode $crypt = new Crypt('cryptKey', MCRYPT_RIJNDAEL_256, MCRYPT_MODE_CBC, $iv); // Verify decrypted matches original data $this->assertEquals($encrypted, base64_encode($crypt->encrypt($actual))); }
public function testEncryptDecryptNewKeyAdded() { $deploymentConfigMock = $this->getMock('\\Magento\\Framework\\App\\DeploymentConfig', [], [], '', false); $deploymentConfigMock->expects($this->at(0))->method('get')->with(Encryptor::PARAM_CRYPT_KEY)->will($this->returnValue("cryptKey1")); $deploymentConfigMock->expects($this->at(1))->method('get')->with(Encryptor::PARAM_CRYPT_KEY)->will($this->returnValue("cryptKey1\ncryptKey2")); $model1 = new Encryptor($this->_randomGenerator, $deploymentConfigMock); // simulate an encryption key is being added $model2 = new Encryptor($this->_randomGenerator, $deploymentConfigMock); // sample data to encrypt $data = 'Mares eat oats and does eat oats, but little lambs eat ivy.'; // encrypt with old key $encryptedData = $model1->encrypt($data); $decryptedData = $model2->decrypt($encryptedData); $this->assertSame($data, $decryptedData, 'Encryptor failed to decrypt data encrypted by old keys.'); }
public function testEncryptDecrypt() { $this->assertEquals('', $this->_model->decrypt($this->_model->encrypt(''))); $this->assertEquals('test', $this->_model->decrypt($this->_model->encrypt('test'))); }