blob: ced7633017f966c5185589542218334fbb613f38 [file] [log] [blame]
Joffrey Jaffeux9d140752012-06-06 01:40:18 +02001<?php
Andrey Andreev43090cc2014-08-14 12:22:07 +03002/**
3 * @requires extension mcrypt
4 */
Joffrey Jaffeux9d140752012-06-06 01:40:18 +02005class Encrypt_test extends CI_TestCase {
6
Andrey Andreevc1862882012-06-09 23:16:58 +03007 public function set_up()
8 {
Andrey Andreev43090cc2014-08-14 12:22:07 +03009 if ( ! extension_loaded('mcrypt'))
10 {
11 return;
12 }
13
dchill427ecc5cd2012-10-12 16:25:51 -040014 $this->encrypt = new Mock_Libraries_Encrypt();
15 $this->ci_instance_var('encrypt', $this->encrypt);
Joffrey Jaffeux9d140752012-06-06 01:40:18 +020016
Andrey Andreevc1862882012-06-09 23:16:58 +030017 $this->ci_set_config('encryption_key', "Encryptin'glike@boss!");
18 $this->msg = 'My secret message';
19 }
Joffrey Jaffeux9d140752012-06-06 01:40:18 +020020
Andrey Andreevc1862882012-06-09 23:16:58 +030021 // --------------------------------------------------------------------
Joffrey Jaffeux9d140752012-06-06 01:40:18 +020022
Andrey Andreevc1862882012-06-09 23:16:58 +030023 public function test_encode()
24 {
25 $this->assertNotEquals($this->msg, $this->encrypt->encode($this->msg));
26 }
Joffrey Jaffeux9d140752012-06-06 01:40:18 +020027
Andrey Andreevc1862882012-06-09 23:16:58 +030028 // --------------------------------------------------------------------
Joffrey Jaffeux9d140752012-06-06 01:40:18 +020029
Andrey Andreevc1862882012-06-09 23:16:58 +030030 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 Jaffeux9d140752012-06-06 01:40:18 +020035
Andrey Andreevc1862882012-06-09 23:16:58 +030036 // --------------------------------------------------------------------
Joffrey Jaffeux9d140752012-06-06 01:40:18 +020037
Andrey Andreevc1862882012-06-09 23:16:58 +030038 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 Jaffeux9d140752012-06-06 01:40:18 +020044
Andrey Andreevc1862882012-06-09 23:16:58 +030045 // --------------------------------------------------------------------
Joffrey Jaffeux9d140752012-06-06 01:40:18 +020046
Andrey Andreevc1862882012-06-09 23:16:58 +030047 public function test_default_cipher()
48 {
49 $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 {
56 $this->encrypt->set_cipher(MCRYPT_BLOWFISH);
57 $this->assertEquals('blowfish', $this->encrypt->get_cipher());
58 }
Joffrey Jaffeux9d140752012-06-06 01:40:18 +020059
Andrey Andreevc1862882012-06-09 23:16:58 +030060 // --------------------------------------------------------------------
Joffrey Jaffeux9d140752012-06-06 01:40:18 +020061
Andrey Andreevc1862882012-06-09 23:16:58 +030062 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 Jaffeux9d140752012-06-06 01:40:18 +020074
75}