1
|
|
|
<?php |
2
|
|
|
namespace coossionstest; |
3
|
|
|
|
4
|
|
|
use PHPUnit\Framework\TestCase; |
5
|
|
|
use coossions\crypt\Encryptor; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Class EncryptorTest |
9
|
|
|
* @package coossionstest |
10
|
|
|
* |
11
|
|
|
* @property Encryptor encryptor |
12
|
|
|
*/ |
13
|
|
|
final class EncryptorTest extends TestCase |
14
|
|
|
{ |
15
|
|
|
private $encryptor = null; |
16
|
|
|
private $sid = 'sid'; |
17
|
|
|
private $secret = 'secret'; |
18
|
|
|
|
19
|
|
|
public function setUp() |
20
|
|
|
{ |
21
|
|
|
$this->encryptor = new Encryptor('secret'); |
22
|
|
|
$this->sid = md5($this->sid); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
public function testEncryption() |
26
|
|
|
{ |
27
|
|
|
$msg = 'foo bar baz'; |
28
|
|
|
$encryptedStr = $this->encryptor->encryptString($msg, $this->secret, $this->sid); |
29
|
|
|
$this->assertEquals($this->encryptor->decryptString($encryptedStr, $this->secret, $this->sid), $msg); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
public function testSetGetDigestAlgo() |
33
|
|
|
{ |
34
|
|
|
$sha128 = 'sha128'; |
35
|
|
|
$this->encryptor->setDigestAlgo($sha128); |
36
|
|
|
$this->assertEquals($sha128, $this->encryptor->getDigestAlgo()); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
public function testSetGetCipherAlgo() |
40
|
|
|
{ |
41
|
|
|
$aes128 = 'aes-512-ctr'; |
42
|
|
|
$this->encryptor->setCipherAlgo($aes128); |
43
|
|
|
$this->assertEquals($aes128, $this->encryptor->getCipherAlgo()); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
public function testSetGetCipherIvLen() |
47
|
|
|
{ |
48
|
|
|
$ivLen32 = 32; |
49
|
|
|
$this->encryptor->setCipherIvLen($ivLen32); |
50
|
|
|
$this->assertEquals($ivLen32, $this->encryptor->getCipherIvLen()); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
public function testSetGetExpires() |
54
|
|
|
{ |
55
|
|
|
$expire = 360; |
56
|
|
|
$this->encryptor->setExpire($expire); |
57
|
|
|
$this->assertEquals($expire, $this->encryptor->getExpire()); |
58
|
|
|
} |
59
|
|
|
} |