blob: 21ac85f03a0bd896ecade151c3c78a4548be4ff2 [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
Joffrey Jaffeux9d140752012-06-06 01:40:18 +020054
Andrey Andreevc1862882012-06-09 23:16:58 +030055 public function test_set_cipher()
56 {
Andrey Andreevd98785a2012-10-24 15:33:35 +030057 if ( ! $this->mcrypt)
58 {
59 $this->markTestSkipped('MCrypt not available');
60 return;
61 }
62
Andrey Andreevc1862882012-06-09 23:16:58 +030063 $this->encrypt->set_cipher(MCRYPT_BLOWFISH);
64 $this->assertEquals('blowfish', $this->encrypt->get_cipher());
65 }
Joffrey Jaffeux9d140752012-06-06 01:40:18 +020066
Andrey Andreevc1862882012-06-09 23:16:58 +030067 // --------------------------------------------------------------------
Joffrey Jaffeux9d140752012-06-06 01:40:18 +020068
Andrey Andreevc1862882012-06-09 23:16:58 +030069 public function test_default_mode()
70 {
Andrey Andreevd98785a2012-10-24 15:33:35 +030071 if ( ! $this->mcrypt)
72 {
73 $this->markTestSkipped('MCrypt not available');
74 return;
75 }
76
Andrey Andreevc1862882012-06-09 23:16:58 +030077 $this->assertEquals('cbc', $this->encrypt->get_mode());
78 }
79
80 // --------------------------------------------------------------------
81
82 public function test_set_mode()
83 {
Andrey Andreevd98785a2012-10-24 15:33:35 +030084 if ( ! $this->mcrypt)
85 {
86 $this->markTestSkipped('MCrypt not available');
87 return;
88 }
89
Andrey Andreevc1862882012-06-09 23:16:58 +030090 $this->encrypt->set_mode(MCRYPT_MODE_CFB);
91 $this->assertEquals('cfb', $this->encrypt->get_mode());
92 }
Joffrey Jaffeux9d140752012-06-06 01:40:18 +020093
94}