-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSimpleCryptTest.php
More file actions
81 lines (63 loc) · 2.08 KB
/
SimpleCryptTest.php
File metadata and controls
81 lines (63 loc) · 2.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<?php
namespace Neuron\Tests;
use PHPUnit\Framework\TestCase;
use Neuron\Encryption\SimpleCrypt;
class SimpleCryptTest extends TestCase
{
public function testEncryptDecrypt ()
{
$crypt = new SimpleCrypt ('test_password');
$original = 'Hello World!';
$encrypted = $crypt->encrypt ($original);
$this->assertNotEquals ($original, $encrypted);
$decrypted = $crypt->decrypt ($encrypted);
$this->assertEquals ($original, $decrypted);
}
public function testDifferentPasswordsFail ()
{
$crypt1 = new SimpleCrypt ('password1');
$crypt2 = new SimpleCrypt ('password2');
$encrypted = $crypt1->encrypt ('secret');
$decrypted = $crypt2->decrypt ($encrypted);
$this->assertNotEquals ('secret', $decrypted);
}
public function testEncryptProducesDifferentOutput ()
{
$crypt = new SimpleCrypt ('password');
$encrypted1 = $crypt->encrypt ('same text');
$encrypted2 = $crypt->encrypt ('same text');
// Due to random salt, encrypted values should differ
$this->assertNotEquals ($encrypted1, $encrypted2);
}
public function testEncryptDecryptEmptyString ()
{
$crypt = new SimpleCrypt ('password');
$encrypted = $crypt->encrypt ('');
$decrypted = $crypt->decrypt ($encrypted);
$this->assertEquals ('', $decrypted);
}
public function testEncryptDecryptSpecialCharacters ()
{
$crypt = new SimpleCrypt ('password');
$original = "Special chars: !@#\$%^&*()_+-=[]{}|;':\",./<>?";
$encrypted = $crypt->encrypt ($original);
$decrypted = $crypt->decrypt ($encrypted);
$this->assertEquals ($original, $decrypted);
}
public function testEncryptDecryptUTF8 ()
{
$crypt = new SimpleCrypt ('password');
$original = 'Héllo Wörld 日本語';
$encrypted = $crypt->encrypt ($original);
$decrypted = $crypt->decrypt ($encrypted);
$this->assertEquals ($original, $decrypted);
}
public function testEncryptDecryptWithSaltMarkerInContent ()
{
$crypt = new SimpleCrypt ('password');
$original = 'Text with |||CWSALT inside it';
$encrypted = $crypt->encrypt ($original);
$decrypted = $crypt->decrypt ($encrypted);
$this->assertEquals ($original, $decrypted);
}
}