Joffrey Jaffeux | 9d14075 | 2012-06-06 01:40:18 +0200 | [diff] [blame] | 1 | <?php |
Andrey Andreev | 43090cc | 2014-08-14 12:22:07 +0300 | [diff] [blame] | 2 | /** |
| 3 | * @requires extension mcrypt |
| 4 | */ |
Joffrey Jaffeux | 9d14075 | 2012-06-06 01:40:18 +0200 | [diff] [blame] | 5 | class Encrypt_test extends CI_TestCase { |
| 6 | |
Andrey Andreev | c186288 | 2012-06-09 23:16:58 +0300 | [diff] [blame] | 7 | public function set_up() |
| 8 | { |
Andrey Andreev | 43090cc | 2014-08-14 12:22:07 +0300 | [diff] [blame] | 9 | if ( ! extension_loaded('mcrypt')) |
| 10 | { |
| 11 | return; |
| 12 | } |
Andrey Andreev | c95df51 | 2016-08-22 13:19:24 +0300 | [diff] [blame] | 13 | elseif (version_compare(PHP_VERSION, '7.1.0-alpha', '>=')) |
| 14 | { |
| 15 | return $this->markTestSkipped('ext/mcrypt is deprecated since PHP 7.1 and will generate notices here.'); |
| 16 | } |
Andrey Andreev | 43090cc | 2014-08-14 12:22:07 +0300 | [diff] [blame] | 17 | |
dchill42 | 7ecc5cd | 2012-10-12 16:25:51 -0400 | [diff] [blame] | 18 | $this->encrypt = new Mock_Libraries_Encrypt(); |
| 19 | $this->ci_instance_var('encrypt', $this->encrypt); |
Joffrey Jaffeux | 9d14075 | 2012-06-06 01:40:18 +0200 | [diff] [blame] | 20 | |
Andrey Andreev | c186288 | 2012-06-09 23:16:58 +0300 | [diff] [blame] | 21 | $this->ci_set_config('encryption_key', "Encryptin'glike@boss!"); |
| 22 | $this->msg = 'My secret message'; |
| 23 | } |
Joffrey Jaffeux | 9d14075 | 2012-06-06 01:40:18 +0200 | [diff] [blame] | 24 | |
Andrey Andreev | c186288 | 2012-06-09 23:16:58 +0300 | [diff] [blame] | 25 | // -------------------------------------------------------------------- |
Joffrey Jaffeux | 9d14075 | 2012-06-06 01:40:18 +0200 | [diff] [blame] | 26 | |
Andrey Andreev | c186288 | 2012-06-09 23:16:58 +0300 | [diff] [blame] | 27 | public function test_encode() |
| 28 | { |
| 29 | $this->assertNotEquals($this->msg, $this->encrypt->encode($this->msg)); |
| 30 | } |
Joffrey Jaffeux | 9d14075 | 2012-06-06 01:40:18 +0200 | [diff] [blame] | 31 | |
Andrey Andreev | c186288 | 2012-06-09 23:16:58 +0300 | [diff] [blame] | 32 | // -------------------------------------------------------------------- |
Joffrey Jaffeux | 9d14075 | 2012-06-06 01:40:18 +0200 | [diff] [blame] | 33 | |
Andrey Andreev | c186288 | 2012-06-09 23:16:58 +0300 | [diff] [blame] | 34 | public function test_decode() |
| 35 | { |
| 36 | $encoded_msg = $this->encrypt->encode($this->msg); |
| 37 | $this->assertEquals($this->msg, $this->encrypt->decode($encoded_msg)); |
| 38 | } |
Joffrey Jaffeux | 9d14075 | 2012-06-06 01:40:18 +0200 | [diff] [blame] | 39 | |
Andrey Andreev | c186288 | 2012-06-09 23:16:58 +0300 | [diff] [blame] | 40 | // -------------------------------------------------------------------- |
Joffrey Jaffeux | 9d14075 | 2012-06-06 01:40:18 +0200 | [diff] [blame] | 41 | |
Andrey Andreev | c186288 | 2012-06-09 23:16:58 +0300 | [diff] [blame] | 42 | public function test_optional_key() |
| 43 | { |
| 44 | $key = 'Ohai!ù0129°03182%HD1892P0'; |
| 45 | $encoded_msg = $this->encrypt->encode($this->msg, $key); |
| 46 | $this->assertEquals($this->msg, $this->encrypt->decode($encoded_msg, $key)); |
| 47 | } |
Joffrey Jaffeux | 9d14075 | 2012-06-06 01:40:18 +0200 | [diff] [blame] | 48 | |
Andrey Andreev | c186288 | 2012-06-09 23:16:58 +0300 | [diff] [blame] | 49 | // -------------------------------------------------------------------- |
Joffrey Jaffeux | 9d14075 | 2012-06-06 01:40:18 +0200 | [diff] [blame] | 50 | |
Andrey Andreev | c186288 | 2012-06-09 23:16:58 +0300 | [diff] [blame] | 51 | public function test_default_cipher() |
| 52 | { |
| 53 | $this->assertEquals('rijndael-256', $this->encrypt->get_cipher()); |
| 54 | } |
Joffrey Jaffeux | 9d14075 | 2012-06-06 01:40:18 +0200 | [diff] [blame] | 55 | |
Andrey Andreev | c186288 | 2012-06-09 23:16:58 +0300 | [diff] [blame] | 56 | // -------------------------------------------------------------------- |
Joffrey Jaffeux | 9d14075 | 2012-06-06 01:40:18 +0200 | [diff] [blame] | 57 | |
Andrey Andreev | c186288 | 2012-06-09 23:16:58 +0300 | [diff] [blame] | 58 | public function test_set_cipher() |
| 59 | { |
| 60 | $this->encrypt->set_cipher(MCRYPT_BLOWFISH); |
| 61 | $this->assertEquals('blowfish', $this->encrypt->get_cipher()); |
| 62 | } |
Joffrey Jaffeux | 9d14075 | 2012-06-06 01:40:18 +0200 | [diff] [blame] | 63 | |
Andrey Andreev | c186288 | 2012-06-09 23:16:58 +0300 | [diff] [blame] | 64 | // -------------------------------------------------------------------- |
Joffrey Jaffeux | 9d14075 | 2012-06-06 01:40:18 +0200 | [diff] [blame] | 65 | |
Andrey Andreev | c186288 | 2012-06-09 23:16:58 +0300 | [diff] [blame] | 66 | public function test_default_mode() |
| 67 | { |
| 68 | $this->assertEquals('cbc', $this->encrypt->get_mode()); |
| 69 | } |
| 70 | |
| 71 | // -------------------------------------------------------------------- |
| 72 | |
| 73 | public function test_set_mode() |
| 74 | { |
| 75 | $this->encrypt->set_mode(MCRYPT_MODE_CFB); |
| 76 | $this->assertEquals('cfb', $this->encrypt->get_mode()); |
| 77 | } |
Joffrey Jaffeux | 9d14075 | 2012-06-06 01:40:18 +0200 | [diff] [blame] | 78 | |
Andrey Andreev | c95df51 | 2016-08-22 13:19:24 +0300 | [diff] [blame] | 79 | } |