1 | <?php |
||
10 | // We're cheating here, because this TestCase doesn't decent from Cert, like Data and File do. |
||
11 | final class Remote extends \SimpleSAML\Module\monitor\TestCaseFactory |
||
12 | { |
||
13 | /* |
||
14 | * @var string|null |
||
15 | */ |
||
16 | private $connectString = null; |
||
17 | |||
18 | /* |
||
19 | * @var resource|null |
||
20 | */ |
||
21 | private $context = null; |
||
22 | |||
23 | /* |
||
24 | * @param TestData $testData |
||
25 | */ |
||
26 | protected function initialize($testData) |
||
27 | { |
||
28 | $hostname = $testData->getInput('hostname'); |
||
29 | $port = $testData->getInput('port'); |
||
30 | $this->setCategory($testData->getInput('category')); |
||
31 | $this->connectString = 'ssl://' . $hostname . ':' . $port; |
||
32 | $this->context = stream_context_create([ |
||
33 | "ssl" => array( |
||
34 | "capture_peer_cert" => true, |
||
35 | "verify_peer" => false, |
||
36 | "verify_peer_name" => false |
||
37 | ) |
||
38 | ]); |
||
39 | |||
40 | parent::initialize($testData); |
||
41 | } |
||
42 | |||
43 | protected function invokeTest() |
||
44 | { |
||
45 | $testsuite = $this->getTestSuite(); |
||
46 | $testResult = new TestResult(); |
||
47 | |||
48 | $testData = new TestData([ |
||
49 | 'uri' => $this->connectString, |
||
50 | 'context' => $this->context |
||
51 | ]); |
||
52 | $connTest = new TestCase\Network\ConnectUri( |
||
53 | $testsuite, |
||
54 | $testData |
||
55 | ); |
||
56 | $connTestResult = $connTest->getTestResult(); |
||
57 | |||
58 | $connState = $testResult->getState(); |
||
59 | |||
60 | if ($connState === State::OK) { // Connection OK |
||
61 | $connection = $connTestResult->getOutput('connection'); |
||
62 | $certData = $connTestResult->getOutput('certData'); |
||
63 | |||
64 | if ($certData !== null) { |
||
65 | $testData = new TestData([ |
||
66 | 'certData' => $certData, |
||
67 | 'category' => $this->getCategory() |
||
68 | ]); |
||
69 | |||
70 | $certTest = new TestCase\Cert\Data( |
||
71 | $testsuite, |
||
72 | $testData |
||
73 | ); |
||
74 | $certTestResult = $certTest->getTestResult(); |
||
75 | $testResult->setState($certTestResult->getState()); |
||
76 | $testResult->setMessage($certTestResult->getMessage()); |
||
77 | } else { |
||
78 | $testResult->setState(State::SKIPPED); |
||
79 | $testResult->setMessage(State::SKIPPED, $this->getCategory(), $this->getSubject(), 'Unable to capture peer certificate'); |
||
80 | } |
||
81 | } else { |
||
82 | $testResult->setState(State::FATAL); |
||
83 | $testResult->setMessage($connTestResult->getMessage()); |
||
84 | } |
||
85 | $this->setTestResult($testResult); |
||
90 |