blob: a08db8ed073395ab0fcb3e07ec3b17d7e68f0e6e [file] [log] [blame]
Joffrey Jaffeux9d140752012-06-06 01:40:18 +02001<?php
2
3class Encrypt_test extends CI_TestCase {
4
Andrey Andreevc1862882012-06-09 23:16:58 +03005 public function set_up()
6 {
dchill427ecc5cd2012-10-12 16:25:51 -04007 $this->encrypt = new Mock_Libraries_Encrypt();
8 $this->ci_instance_var('encrypt', $this->encrypt);
Joffrey Jaffeux9d140752012-06-06 01:40:18 +02009
Andrey Andreevc1862882012-06-09 23:16:58 +030010 $this->ci_set_config('encryption_key', "Encryptin'glike@boss!");
11 $this->msg = 'My secret message';
Andrey Andreevd98785a2012-10-24 15:33:35 +030012 $this->mcrypt = extension_loaded('mcrypt');
Andrey Andreevc1862882012-06-09 23:16:58 +030013 }
Joffrey Jaffeux9d140752012-06-06 01:40:18 +020014
Andrey Andreevc1862882012-06-09 23:16:58 +030015 // --------------------------------------------------------------------
Joffrey Jaffeux9d140752012-06-06 01:40:18 +020016
Andrey Andreevc1862882012-06-09 23:16:58 +030017 public function test_encode()
18 {
19 $this->assertNotEquals($this->msg, $this->encrypt->encode($this->msg));
20 }
Joffrey Jaffeux9d140752012-06-06 01:40:18 +020021
Andrey Andreevc1862882012-06-09 23:16:58 +030022 // --------------------------------------------------------------------
Joffrey Jaffeux9d140752012-06-06 01:40:18 +020023
Andrey Andreevc1862882012-06-09 23:16:58 +030024 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 Jaffeux9d140752012-06-06 01:40:18 +020029
Andrey Andreevc1862882012-06-09 23:16:58 +030030 // --------------------------------------------------------------------
Joffrey Jaffeux9d140752012-06-06 01:40:18 +020031
Andrey Andreevc1862882012-06-09 23:16:58 +030032 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 Jaffeux9d140752012-06-06 01:40:18 +020038
Andrey Andreevc1862882012-06-09 23:16:58 +030039 // --------------------------------------------------------------------
Joffrey Jaffeux9d140752012-06-06 01:40:18 +020040
Andrey Andreevc1862882012-06-09 23:16:58 +030041 public function test_default_cipher()
42 {
Andrey Andreevd98785a2012-10-24 15:33:35 +030043 if ( ! $this->mcrypt)
44 {
45 $this->markTestSkipped('MCrypt not available');
46 return;
47 }
48
Andrey Andreevc1862882012-06-09 23:16:58 +030049 $this->assertEquals('rijndael-256', $this->encrypt->get_cipher());
50 }
Joffrey Jaffeux9d140752012-06-06 01:40:18 +020051
Andrey Andreevc1862882012-06-09 23:16:58 +030052 // --------------------------------------------------------------------
Joffrey Jaffeux9d140752012-06-06 01:40:18 +020053
Andrey Andreevc1862882012-06-09 23:16:58 +030054 public function test_set_cipher()
55 {
Andrey Andreevd98785a2012-10-24 15:33:35 +030056 if ( ! $this->mcrypt)
57 {
58 $this->markTestSkipped('MCrypt not available');
59 return;
60 }
61
Andrey Andreevc1862882012-06-09 23:16:58 +030062 $this->encrypt->set_cipher(MCRYPT_BLOWFISH);
63 $this->assertEquals('blowfish', $this->encrypt->get_cipher());
64 }
Joffrey Jaffeux9d140752012-06-06 01:40:18 +020065
Andrey Andreevc1862882012-06-09 23:16:58 +030066 // --------------------------------------------------------------------
Joffrey Jaffeux9d140752012-06-06 01:40:18 +020067
Andrey Andreevc1862882012-06-09 23:16:58 +030068 public function test_default_mode()
69 {
Andrey Andreevd98785a2012-10-24 15:33:35 +030070 if ( ! $this->mcrypt)
71 {
72 $this->markTestSkipped('MCrypt not available');
73 return;
74 }
75
Andrey Andreevc1862882012-06-09 23:16:58 +030076 $this->assertEquals('cbc', $this->encrypt->get_mode());
77 }
78
79 // --------------------------------------------------------------------
80
81 public function test_set_mode()
82 {
Andrey Andreevd98785a2012-10-24 15:33:35 +030083 if ( ! $this->mcrypt)
84 {
85 $this->markTestSkipped('MCrypt not available');
86 return;
87 }
88
Andrey Andreevc1862882012-06-09 23:16:58 +030089 $this->encrypt->set_mode(MCRYPT_MODE_CFB);
90 $this->assertEquals('cfb', $this->encrypt->get_mode());
91 }
Joffrey Jaffeux9d140752012-06-06 01:40:18 +020092
93}