. */ namespace SP\Tests\Core\Crypt; use Defuse\Crypto\Exception\CryptoException; use PHPUnit\Framework\TestCase; use SP\Core\Crypt\Crypt; /** * Class CryptTest * * Tests unitarios para comprobar el funcionamiento de la clase SP\Core\Crypt\Crypt * * @package SP\Tests */ class CryptTest extends TestCase { const PASSWORD = 'test_password'; /** * Comprobar la generación de una llave de cifrado * * @throws CryptoException */ public function testMakeSecuredKey() { $this->assertTrue(true); return Crypt::makeSecuredKey(self::PASSWORD); } /** * Comprobar el desbloqueo de una llave de cifrado * * @depends testMakeSecuredKey * * @param string $key LLave de cifrado * * @throws CryptoException */ public function testUnlockSecuredKey($key) { $this->assertTrue(true); Crypt::unlockSecuredKey($key, self::PASSWORD); } /** * Comprobar el desbloqueo de una llave de cifrado * * @depends testMakeSecuredKey * * @param string $key LLave de cifrado * * @throws CryptoException */ public function testUnlockSecuredKeyWithWrongPassword($key) { $this->expectException(CryptoException::class); Crypt::unlockSecuredKey($key, 'test'); } /** * Comprobar la encriptación y desencriptado de datos * * @depends testMakeSecuredKey * * @param string $key LLave de cifrado * * @throws CryptoException */ public function testEncryptAndDecrypt($key) { $data = Crypt::encrypt('prueba', $key, self::PASSWORD); $this->assertSame('prueba', Crypt::decrypt($data, $key, self::PASSWORD)); } /** * Comprobar la encriptación y desencriptado de datos * * @depends testMakeSecuredKey * * @param string $key LLave de cifrado * * @throws CryptoException */ public function testEncryptAndDecryptWithDifferentPassword($key) { $data = Crypt::encrypt('prueba', $key, self::PASSWORD); $this->expectException(CryptoException::class); $this->assertSame('prueba', Crypt::decrypt($data, $key, 'test')); } }