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 | } |
| 13 | |
dchill42 | 7ecc5cd | 2012-10-12 16:25:51 -0400 | [diff] [blame] | 14 | $this->encrypt = new Mock_Libraries_Encrypt(); |
| 15 | $this->ci_instance_var('encrypt', $this->encrypt); |
Joffrey Jaffeux | 9d14075 | 2012-06-06 01:40:18 +0200 | [diff] [blame] | 16 | |
Andrey Andreev | c186288 | 2012-06-09 23:16:58 +0300 | [diff] [blame] | 17 | $this->ci_set_config('encryption_key', "Encryptin'glike@boss!"); |
| 18 | $this->msg = 'My secret message'; |
| 19 | } |
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 | // -------------------------------------------------------------------- |
Joffrey Jaffeux | 9d14075 | 2012-06-06 01:40:18 +0200 | [diff] [blame] | 22 | |
Andrey Andreev | c186288 | 2012-06-09 23:16:58 +0300 | [diff] [blame] | 23 | public function test_encode() |
| 24 | { |
| 25 | $this->assertNotEquals($this->msg, $this->encrypt->encode($this->msg)); |
| 26 | } |
Joffrey Jaffeux | 9d14075 | 2012-06-06 01:40:18 +0200 | [diff] [blame] | 27 | |
Andrey Andreev | c186288 | 2012-06-09 23:16:58 +0300 | [diff] [blame] | 28 | // -------------------------------------------------------------------- |
Joffrey Jaffeux | 9d14075 | 2012-06-06 01:40:18 +0200 | [diff] [blame] | 29 | |
Andrey Andreev | c186288 | 2012-06-09 23:16:58 +0300 | [diff] [blame] | 30 | public function test_decode() |
| 31 | { |
| 32 | $encoded_msg = $this->encrypt->encode($this->msg); |
| 33 | $this->assertEquals($this->msg, $this->encrypt->decode($encoded_msg)); |
| 34 | } |
Joffrey Jaffeux | 9d14075 | 2012-06-06 01:40:18 +0200 | [diff] [blame] | 35 | |
Andrey Andreev | c186288 | 2012-06-09 23:16:58 +0300 | [diff] [blame] | 36 | // -------------------------------------------------------------------- |
Joffrey Jaffeux | 9d14075 | 2012-06-06 01:40:18 +0200 | [diff] [blame] | 37 | |
Andrey Andreev | c186288 | 2012-06-09 23:16:58 +0300 | [diff] [blame] | 38 | public function test_optional_key() |
| 39 | { |
| 40 | $key = 'Ohai!ù0129°03182%HD1892P0'; |
| 41 | $encoded_msg = $this->encrypt->encode($this->msg, $key); |
| 42 | $this->assertEquals($this->msg, $this->encrypt->decode($encoded_msg, $key)); |
| 43 | } |
Joffrey Jaffeux | 9d14075 | 2012-06-06 01:40:18 +0200 | [diff] [blame] | 44 | |
Andrey Andreev | c186288 | 2012-06-09 23:16:58 +0300 | [diff] [blame] | 45 | // -------------------------------------------------------------------- |
Joffrey Jaffeux | 9d14075 | 2012-06-06 01:40:18 +0200 | [diff] [blame] | 46 | |
Andrey Andreev | c186288 | 2012-06-09 23:16:58 +0300 | [diff] [blame] | 47 | public function test_default_cipher() |
| 48 | { |
| 49 | $this->assertEquals('rijndael-256', $this->encrypt->get_cipher()); |
| 50 | } |
Joffrey Jaffeux | 9d14075 | 2012-06-06 01:40:18 +0200 | [diff] [blame] | 51 | |
Andrey Andreev | c186288 | 2012-06-09 23:16:58 +0300 | [diff] [blame] | 52 | // -------------------------------------------------------------------- |
Joffrey Jaffeux | 9d14075 | 2012-06-06 01:40:18 +0200 | [diff] [blame] | 53 | |
Andrey Andreev | c186288 | 2012-06-09 23:16:58 +0300 | [diff] [blame] | 54 | public function test_set_cipher() |
| 55 | { |
| 56 | $this->encrypt->set_cipher(MCRYPT_BLOWFISH); |
| 57 | $this->assertEquals('blowfish', $this->encrypt->get_cipher()); |
| 58 | } |
Joffrey Jaffeux | 9d14075 | 2012-06-06 01:40:18 +0200 | [diff] [blame] | 59 | |
Andrey Andreev | c186288 | 2012-06-09 23:16:58 +0300 | [diff] [blame] | 60 | // -------------------------------------------------------------------- |
Joffrey Jaffeux | 9d14075 | 2012-06-06 01:40:18 +0200 | [diff] [blame] | 61 | |
Andrey Andreev | c186288 | 2012-06-09 23:16:58 +0300 | [diff] [blame] | 62 | public function test_default_mode() |
| 63 | { |
| 64 | $this->assertEquals('cbc', $this->encrypt->get_mode()); |
| 65 | } |
| 66 | |
| 67 | // -------------------------------------------------------------------- |
| 68 | |
| 69 | public function test_set_mode() |
| 70 | { |
| 71 | $this->encrypt->set_mode(MCRYPT_MODE_CFB); |
| 72 | $this->assertEquals('cfb', $this->encrypt->get_mode()); |
| 73 | } |
Joffrey Jaffeux | 9d14075 | 2012-06-06 01:40:18 +0200 | [diff] [blame] | 74 | |
| 75 | } |