1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @author Chris Hilsdon <[email protected]> |
4
|
|
|
* @package ComodoDecodeCSR |
5
|
|
|
* @copyright 2016 Xigen |
6
|
|
|
* @license GNU General Public License v3 |
7
|
|
|
* @link https://github.com/XigenChris/ComodoDecodeCSR |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace Xigen\Tests; |
11
|
|
|
|
12
|
|
|
use Xigen\ComodoDecodeCSR; |
13
|
|
|
|
14
|
|
|
class ComodoDecodeCSRTest extends XigenUnit |
15
|
|
|
{ |
16
|
|
|
protected $ComodoDecodeCSR; |
17
|
|
|
|
18
|
5 |
|
public function setUp() |
19
|
|
|
{ |
20
|
5 |
|
$this->ComodoDecodeCSR = new ComodoDecodeCSR(); |
21
|
5 |
|
} |
22
|
|
|
|
23
|
1 |
|
private function createFakeCSR() |
24
|
|
|
{ |
25
|
|
|
$dn = array( |
26
|
1 |
|
"countryName" => "NA", |
27
|
1 |
|
"stateOrProvinceName" => "NA", |
28
|
1 |
|
"localityName" => "NA", |
29
|
1 |
|
"organizationName" => "NA", |
30
|
1 |
|
"organizationalUnitName" => "NA", |
31
|
1 |
|
"commonName" => "httpbin.org", |
32
|
|
|
"emailAddress" => "NA" |
33
|
1 |
|
); |
34
|
|
|
|
35
|
|
|
// Generate a new private (and public) key pair |
36
|
1 |
|
$privkey = openssl_pkey_new(); |
37
|
|
|
|
38
|
|
|
// Generate a certificate signing request |
39
|
1 |
|
return openssl_csr_new($dn, $privkey); |
40
|
|
|
} |
41
|
|
|
|
42
|
5 |
|
public function testSettingCSR() |
43
|
|
|
{ |
44
|
|
|
//Load the test CSR |
45
|
5 |
|
$csr = $this->loadTestCSR(); |
46
|
1 |
|
$this->ComodoDecodeCSR->setCSR($csr); |
47
|
1 |
|
$this->assertSame( |
48
|
1 |
|
$csr, |
49
|
1 |
|
$this->ComodoDecodeCSR->getCSR(), |
50
|
|
|
"Unable to set the CSR via ->setCSR()" |
51
|
1 |
|
); |
52
|
1 |
|
} |
53
|
|
|
|
54
|
1 |
|
public function testGettingHashes() |
55
|
|
|
{ |
56
|
1 |
|
$this->ComodoDecodeCSR->setCSR($this->loadTestCSR()); |
57
|
1 |
|
$Hashes = $this->ComodoDecodeCSR->fetchHashes(); |
58
|
|
|
|
59
|
1 |
|
$this->assertSame($this->validMD5, $Hashes["md5"], "md5 didn't match the correct value"); |
60
|
1 |
|
$this->assertSame($this->validMD5, $this->ComodoDecodeCSR->getMD5(), "md5 didn't match the correct value"); |
61
|
|
|
|
62
|
1 |
|
$this->assertSame($this->validSHA1, $Hashes["sha1"], "sha1 didn't match the correct value"); |
63
|
1 |
|
$this->assertSame($this->validSHA1, $this->ComodoDecodeCSR->getSHA1(), "sha1 didn't match the correct value"); |
64
|
1 |
|
} |
65
|
|
|
|
66
|
2 |
|
public function testGettingHashesFromInvalidCSR() |
67
|
|
|
{ |
68
|
2 |
|
$Hashes = $this->ComodoDecodeCSR->fetchHashes(); |
69
|
|
|
|
70
|
1 |
|
$this->assertSame($Hashes["md5"], '', "a md5 was set"); |
71
|
1 |
|
$this->assertSame($Hashes["sha1"], '', "a sha1 was set"); |
72
|
1 |
|
} |
73
|
|
|
|
74
|
1 |
|
public function testCheckingInstalled() |
75
|
|
|
{ |
76
|
1 |
|
$csr = $this->loadTestCSR(); |
77
|
1 |
|
$this->ComodoDecodeCSR->setCSR($csr); |
78
|
1 |
|
$this->ComodoDecodeCSR->fetchHashes(); |
79
|
1 |
|
$Installed = $this->ComodoDecodeCSR->checkInstalled(); |
80
|
|
|
|
81
|
1 |
|
$this->assertTrue($Installed); |
82
|
1 |
|
} |
83
|
|
|
|
84
|
1 |
|
public function testCheckInstalledFail() |
85
|
|
|
{ |
86
|
1 |
|
$csr = $this->createFakeCSR(); |
87
|
1 |
|
$this->ComodoDecodeCSR->setCSR($csr); |
88
|
1 |
|
$this->ComodoDecodeCSR->fetchHashes(); |
89
|
1 |
|
$Installed = $this->ComodoDecodeCSR->checkInstalled(); |
90
|
|
|
|
91
|
1 |
|
$this->assertFalse($Installed); |
92
|
1 |
|
} |
93
|
|
|
} |
94
|
|
|
|