Cancelled
Branch master (244451)
by Tim
10:31
created

Configuration::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 7
nc 1
nop 1
dl 0
loc 11
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace SimpleSAML\Module\monitor\TestSuite;
4
5
use \SimpleSAML\Module\monitor\TestConfiguration as TestConfiguration;
6
use \SimpleSAML\Module\monitor\TestCase as TestCase;
7
use \SimpleSAML\Module\monitor\TestData as TestData;
8
use \SimpleSAML\Module\monitor\TestResult as TestResult;
9
use \SimpleSAML\Module\monitor\State as State;
10
use \SimpleSAML\Utils as Utils;
11
12
final class Configuration extends \SimpleSAML\Module\monitor\TestSuiteFactory
13
{
14
    /**
15
     * @param string|null
16
     */
17
    private $metadataCert = null;
18
19
    /**
20
     * @param string|null;
21
     */
22
    private $serverName = null;
23
24
    /**
25
     * @param integer|null;
26
     */
27
    private $serverPort = null;
28
29
    /**
30
     * @param TestConfiguration $configuration
31
     */
32
    public function __construct($configuration)
33
    {
34
        $globalConfig = $configuration->getGlobalConfig();
35
        $serverVars = $configuration->getServerVars();
36
37
        $this->metadataCert = $globalConfig->getString('metadata.sign.certificate', null);
38
        $this->serverName = $serverVars->get('SERVER_NAME');
39
        $this->serverPort = $serverVars->get('SERVER_PORT');
40
        $this->setCategory('Configuration');
41
42
        parent::__construct($configuration);
43
    }
44
45
    /**
46
     * @return void
47
     */
48
    public function invokeTest()
49
    {
50
        // Check network connection to full public URL
51
        $input = [
52
            'connectString' => 'ssl://'.$this->serverName.':'.$this->serverPort,
53
            'context' => stream_context_create([
54
                "ssl" => [
55
                    "capture_peer_cert" => true,
56
                    "verify_peer" => false,
57
                    "verify_peer_name" => false
58
                ]
59
            ]),
60
        ];
61
62
        $connTest = new TestCase\Network\ConnectUri($this, new TestData($input));
63
        $connTestResult = $connTest->getTestResult();
64
65
        $this->addTestResult($connTest->getTestResult());
66
67
        if ($connTestResult->getState() === State::OK) {
68
            // We were able to connect
69
            if (Utils\HTTP::isHTTPS()) {
70
                // Check Service Communications Certificate
71
                $certData = $connTestResult->getOutput('certData');
72
73
                $input = [
74
                    'category' => 'Service Communications Certificate',
75
                    'certData' => $certData,
76
                ];
77
78
                $certTest = new TestCase\Cert\Data($this, new TestData($input));
79
                $this->addTestResult($certTest->getTestResult());
80
            }
81
        }
82
83
        // Check metadata signing certificate when available
84
        if (is_string($this->metadataCert)) {
85
            $input = array(
86
                'certFile' => Utils\Config::getCertPath($this->metadataCert),
87
                'category' => 'Metadata Signing Certificate'
88
            );
89
            $testData = new TestData($input);
90
91
            $test = new TestCase\Cert\File($this, $testData);
92
            $this->addTestResult($test->getTestResult());
93
        }
94
95
        $testResult = new TestResult('Configuration', '');
96
        $testResult->setState($this->calculateState());
97
        $this->setTestResult($testResult);
98
    }
99
}
100