blob: 998d806b353e7b366ac03f95612cd7e1cb3831b0 [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';
12 }
Joffrey Jaffeux9d140752012-06-06 01:40:18 +020013
Andrey Andreevc1862882012-06-09 23:16:58 +030014 // --------------------------------------------------------------------
Joffrey Jaffeux9d140752012-06-06 01:40:18 +020015
Andrey Andreevc1862882012-06-09 23:16:58 +030016 public function test_encode()
17 {
18 $this->assertNotEquals($this->msg, $this->encrypt->encode($this->msg));
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_decode()
24 {
25 $encoded_msg = $this->encrypt->encode($this->msg);
26 $this->assertEquals($this->msg, $this->encrypt->decode($encoded_msg));
27 }
Joffrey Jaffeux9d140752012-06-06 01:40:18 +020028
Andrey Andreevc1862882012-06-09 23:16:58 +030029 // --------------------------------------------------------------------
Joffrey Jaffeux9d140752012-06-06 01:40:18 +020030
Andrey Andreevc1862882012-06-09 23:16:58 +030031 public function test_optional_key()
32 {
33 $key = 'Ohai!ù0129°03182%HD1892P0';
34 $encoded_msg = $this->encrypt->encode($this->msg, $key);
35 $this->assertEquals($this->msg, $this->encrypt->decode($encoded_msg, $key));
36 }
Joffrey Jaffeux9d140752012-06-06 01:40:18 +020037
Andrey Andreevc1862882012-06-09 23:16:58 +030038 // --------------------------------------------------------------------
Joffrey Jaffeux9d140752012-06-06 01:40:18 +020039
Andrey Andreevc1862882012-06-09 23:16:58 +030040 public function test_default_cipher()
41 {
42 $this->assertEquals('rijndael-256', $this->encrypt->get_cipher());
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
Joffrey Jaffeux9d140752012-06-06 01:40:18 +020047
Andrey Andreevc1862882012-06-09 23:16:58 +030048 public function test_set_cipher()
49 {
50 $this->encrypt->set_cipher(MCRYPT_BLOWFISH);
51 $this->assertEquals('blowfish', $this->encrypt->get_cipher());
52 }
Joffrey Jaffeux9d140752012-06-06 01:40:18 +020053
Andrey Andreevc1862882012-06-09 23:16:58 +030054 // --------------------------------------------------------------------
Joffrey Jaffeux9d140752012-06-06 01:40:18 +020055
Andrey Andreevc1862882012-06-09 23:16:58 +030056 public function test_default_mode()
57 {
58 $this->assertEquals('cbc', $this->encrypt->get_mode());
59 }
60
61 // --------------------------------------------------------------------
62
63 public function test_set_mode()
64 {
65 $this->encrypt->set_mode(MCRYPT_MODE_CFB);
66 $this->assertEquals('cfb', $this->encrypt->get_mode());
67 }
Joffrey Jaffeux9d140752012-06-06 01:40:18 +020068
69}