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\Console; |
11
|
|
|
|
12
|
|
|
use Xigen\ComodoDecodeCSR; |
13
|
|
|
use Xigen\Tests\XigenUnit; |
14
|
|
|
use Xigen\Console\Check; |
15
|
|
|
use Symfony\Component\Console\Tester\CommandTester; |
16
|
|
|
|
17
|
|
|
class CheckTest extends XigenUnit |
18
|
|
|
{ |
19
|
|
|
protected $ComodoDecodeCSR; |
20
|
|
|
|
21
|
|
|
public function setUp() |
22
|
|
|
{ |
23
|
|
|
register_shutdown_function(function () { |
24
|
|
|
if (file_exists('test.csr')) { |
25
|
|
|
unlink('test.csr'); |
26
|
|
|
} |
27
|
|
|
}); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
View Code Duplication |
public function testNoCSR() |
31
|
|
|
{ |
32
|
|
|
$command = new Check(); |
33
|
|
|
$tester = new CommandTester($command); |
34
|
|
|
|
35
|
|
|
try { |
36
|
|
|
$tester->execute([]); |
37
|
|
|
} catch (\Exception $e) { |
38
|
|
|
$this->assertEmpty($tester->getDisplay(), "Message wan't empty"); |
39
|
|
|
$this->assertSame($e->getMessage(), 'Not enough arguments (missing: "csr").'); |
40
|
|
|
} |
41
|
|
|
} |
42
|
|
|
|
43
|
|
View Code Duplication |
public function testWithInvalidCSR() |
44
|
|
|
{ |
45
|
|
|
$command = new Check(); |
46
|
|
|
$tester = new CommandTester($command); |
47
|
|
|
|
48
|
|
|
//Create an empty |
49
|
|
|
file_put_contents('test.csr', '', FILE_APPEND | LOCK_EX); |
50
|
|
|
|
51
|
|
|
$tester->execute([ |
52
|
|
|
'csr' => 'test.csr' |
53
|
|
|
]); |
54
|
|
|
|
55
|
|
|
$this->assertSame($tester->getStatusCode(), (int) 3); |
56
|
|
|
$this->assertRegExp('/Error!/', $tester->getDisplay()); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
View Code Duplication |
public function testWithBadCSR() |
60
|
|
|
{ |
61
|
|
|
$command = new Check(); |
62
|
|
|
$tester = new CommandTester($command); |
63
|
|
|
|
64
|
|
|
//Create an empty |
65
|
|
|
file_put_contents('test.csr', ' ' . $this->createFakeCSR(), FILE_APPEND | LOCK_EX); |
66
|
|
|
|
67
|
|
|
$tester->execute([ |
68
|
|
|
'csr' => 'test.csr' |
69
|
|
|
]); |
70
|
|
|
|
71
|
|
|
$this->assertSame($tester->getStatusCode(), (int) 3); |
72
|
|
|
$this->assertRegExp('/Error!/', $tester->getDisplay()); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
View Code Duplication |
public function testWithCorrectCSR() |
76
|
|
|
{ |
77
|
|
|
$command = new Check(); |
78
|
|
|
$tester = new CommandTester($command); |
79
|
|
|
$tester->execute([ |
80
|
|
|
'csr' => 'certificate/test.csr' |
81
|
|
|
]); |
82
|
|
|
|
83
|
|
|
$this->assertSame($tester->getStatusCode(), (int) 0); |
84
|
|
|
$this->assertRegExp('/Success!/', $tester->getDisplay()); |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|