Joffrey Jaffeux | 9d14075 | 2012-06-06 01:40:18 +0200 | [diff] [blame] | 1 | <?php |
| 2 | |
| 3 | class Encrypt_test extends CI_TestCase { |
| 4 | |
Andrey Andreev | c186288 | 2012-06-09 23:16:58 +0300 | [diff] [blame] | 5 | public function set_up() |
| 6 | { |
dchill42 | 7ecc5cd | 2012-10-12 16:25:51 -0400 | [diff] [blame] | 7 | $this->encrypt = new Mock_Libraries_Encrypt(); |
| 8 | $this->ci_instance_var('encrypt', $this->encrypt); |
Joffrey Jaffeux | 9d14075 | 2012-06-06 01:40:18 +0200 | [diff] [blame] | 9 | |
Andrey Andreev | c186288 | 2012-06-09 23:16:58 +0300 | [diff] [blame] | 10 | $this->ci_set_config('encryption_key', "Encryptin'glike@boss!"); |
| 11 | $this->msg = 'My secret message'; |
Andrey Andreev | d98785a | 2012-10-24 15:33:35 +0300 | [diff] [blame] | 12 | $this->mcrypt = extension_loaded('mcrypt'); |
Andrey Andreev | c186288 | 2012-06-09 23:16:58 +0300 | [diff] [blame] | 13 | } |
Joffrey Jaffeux | 9d14075 | 2012-06-06 01:40:18 +0200 | [diff] [blame] | 14 | |
Andrey Andreev | c186288 | 2012-06-09 23:16:58 +0300 | [diff] [blame] | 15 | // -------------------------------------------------------------------- |
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 | public function test_encode() |
| 18 | { |
| 19 | $this->assertNotEquals($this->msg, $this->encrypt->encode($this->msg)); |
| 20 | } |
Joffrey Jaffeux | 9d14075 | 2012-06-06 01:40:18 +0200 | [diff] [blame] | 21 | |
Andrey Andreev | c186288 | 2012-06-09 23:16:58 +0300 | [diff] [blame] | 22 | // -------------------------------------------------------------------- |
Joffrey Jaffeux | 9d14075 | 2012-06-06 01:40:18 +0200 | [diff] [blame] | 23 | |
Andrey Andreev | c186288 | 2012-06-09 23:16:58 +0300 | [diff] [blame] | 24 | public function test_decode() |
| 25 | { |
| 26 | $encoded_msg = $this->encrypt->encode($this->msg); |
| 27 | $this->assertEquals($this->msg, $this->encrypt->decode($encoded_msg)); |
| 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 | // -------------------------------------------------------------------- |
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 | public function test_optional_key() |
| 33 | { |
| 34 | $key = 'Ohai!ù0129°03182%HD1892P0'; |
| 35 | $encoded_msg = $this->encrypt->encode($this->msg, $key); |
| 36 | $this->assertEquals($this->msg, $this->encrypt->decode($encoded_msg, $key)); |
| 37 | } |
Joffrey Jaffeux | 9d14075 | 2012-06-06 01:40:18 +0200 | [diff] [blame] | 38 | |
Andrey Andreev | c186288 | 2012-06-09 23:16:58 +0300 | [diff] [blame] | 39 | // -------------------------------------------------------------------- |
Joffrey Jaffeux | 9d14075 | 2012-06-06 01:40:18 +0200 | [diff] [blame] | 40 | |
Andrey Andreev | c186288 | 2012-06-09 23:16:58 +0300 | [diff] [blame] | 41 | public function test_default_cipher() |
| 42 | { |
Andrey Andreev | d98785a | 2012-10-24 15:33:35 +0300 | [diff] [blame] | 43 | if ( ! $this->mcrypt) |
| 44 | { |
| 45 | $this->markTestSkipped('MCrypt not available'); |
| 46 | return; |
| 47 | } |
| 48 | |
Andrey Andreev | c186288 | 2012-06-09 23:16:58 +0300 | [diff] [blame] | 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 | |
Joffrey Jaffeux | 9d14075 | 2012-06-06 01:40:18 +0200 | [diff] [blame] | 54 | |
Andrey Andreev | c186288 | 2012-06-09 23:16:58 +0300 | [diff] [blame] | 55 | public function test_set_cipher() |
| 56 | { |
Andrey Andreev | d98785a | 2012-10-24 15:33:35 +0300 | [diff] [blame] | 57 | if ( ! $this->mcrypt) |
| 58 | { |
| 59 | $this->markTestSkipped('MCrypt not available'); |
| 60 | return; |
| 61 | } |
| 62 | |
Andrey Andreev | c186288 | 2012-06-09 23:16:58 +0300 | [diff] [blame] | 63 | $this->encrypt->set_cipher(MCRYPT_BLOWFISH); |
| 64 | $this->assertEquals('blowfish', $this->encrypt->get_cipher()); |
| 65 | } |
Joffrey Jaffeux | 9d14075 | 2012-06-06 01:40:18 +0200 | [diff] [blame] | 66 | |
Andrey Andreev | c186288 | 2012-06-09 23:16:58 +0300 | [diff] [blame] | 67 | // -------------------------------------------------------------------- |
Joffrey Jaffeux | 9d14075 | 2012-06-06 01:40:18 +0200 | [diff] [blame] | 68 | |
Andrey Andreev | c186288 | 2012-06-09 23:16:58 +0300 | [diff] [blame] | 69 | public function test_default_mode() |
| 70 | { |
Andrey Andreev | d98785a | 2012-10-24 15:33:35 +0300 | [diff] [blame] | 71 | if ( ! $this->mcrypt) |
| 72 | { |
| 73 | $this->markTestSkipped('MCrypt not available'); |
| 74 | return; |
| 75 | } |
| 76 | |
Andrey Andreev | c186288 | 2012-06-09 23:16:58 +0300 | [diff] [blame] | 77 | $this->assertEquals('cbc', $this->encrypt->get_mode()); |
| 78 | } |
| 79 | |
| 80 | // -------------------------------------------------------------------- |
| 81 | |
| 82 | public function test_set_mode() |
| 83 | { |
Andrey Andreev | d98785a | 2012-10-24 15:33:35 +0300 | [diff] [blame] | 84 | if ( ! $this->mcrypt) |
| 85 | { |
| 86 | $this->markTestSkipped('MCrypt not available'); |
| 87 | return; |
| 88 | } |
| 89 | |
Andrey Andreev | c186288 | 2012-06-09 23:16:58 +0300 | [diff] [blame] | 90 | $this->encrypt->set_mode(MCRYPT_MODE_CFB); |
| 91 | $this->assertEquals('cfb', $this->encrypt->get_mode()); |
| 92 | } |
Joffrey Jaffeux | 9d14075 | 2012-06-06 01:40:18 +0200 | [diff] [blame] | 93 | |
| 94 | } |