Odyssey
sharedHcuCuFuncTest.php
1 <?php
2 
3 use PHPUnit\Framework\TestCase;
4 
5 require_once 'cu_func.i';
6 
7 /**
8  * Test hcu_encrypturl and hcu_decrypturl encryption functions
9  * migration from MCRYPT to OPENSSL.
10  *
11  */
12 class HcuUrlEncryptionTest extends TestCase {
13  function setUp() {
14  $this->Cu = "SCRUBCU";
15  $this->key_suffix = sha1($this->Cu.":urlTestKey");
16  $this->url_data = "https://ashishsharma.com?x=a&y=b";
17  }
18 
19  function test_default_url_encryptions() {
20  // test mcrypt based encryption, if present
21  if(function_exists("hcu_encrypturl_mcrypt") && function_exists("hcu_decrypturl_mcrypt")) {
22 
23  $ciphertext = hcu_encrypturl_mcrypt($this->url_data, $this->key_suffix);
24 
25  $obtained_decrypted_text = hcu_decrypturl_mcrypt($ciphertext,
26  $this->key_suffix);
27 
28  $this->assertEquals($obtained_decrypted_text, $this->url_data);
29  }
30 
31  // test openssl based url encryption
32  $ciphertext_openssl = hcu_encrypturl($this->url_data,
33  $this->key_suffix);
34 
35  $obtained_decrypted_text_openssl = hcu_decrypturl($ciphertext_openssl,
36  $this->key_suffix);
37 
38  $this->assertEquals($obtained_decrypted_text_openssl, $this->url_data);
39 
40  }
41 
42  function test_urls_encryption_mcrypt_comptability() {
43  // encrypt with mcrypt based encryption function
44  if(function_exists("hcu_encrypturl_mcrypt")) {
45 
46  $ciphertext = hcu_encrypturl_mcrypt($this->url_data,
47  $this->key_suffix);
48  } else {
49  $ciphertext = hcu_encrypturl($this->url_data,
50  $this->key_suffix);
51  }
52  // decryption function should be able to decrypt the data
53  // regardless of the library used for encryption
54  $obtained_decrypted_text = hcu_decrypturl($ciphertext,
55  $this->key_suffix);
56 
57  $this->assertEquals($obtained_decrypted_text, $this->url_data);
58  }
59 
60  function tearDown() {
61 
62  }
63 }
64 
65 
66 ?>