Completed
Push — master ( 66a6c7...090560 )
by Tim
02:19
created

Configuration   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 71
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 8

Importance

Changes 0
Metric Value
dl 0
loc 71
rs 10
c 0
b 0
f 0
wmc 5
lcom 1
cbo 8
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\Utils as Utils;
9
10
final class Configuration extends \SimpleSAML\Module\monitor\TestSuiteFactory
11
{
12
    /**
13
     * @param string|null
14
     */
15
    private $metadataCert = null;
16
17
    /**
18
     * @param string|null;
19
     */
20
    private $serverName = null;
21
22
    /**
23
     * @param integer|null;
24
     */
25
    private $serverPort = null;
26
27
    /**
28
     * @param TestConfiguration $configuration
29
     */
30
    public function __construct($configuration)
31
    {
32
        $globalConfig = $configuration->getGlobalConfig();
33
        $serverVars = $configuration->getServerVars();
34
35
        $this->metadataCert = $globalConfig->getString('metadata.sign.certificate', null);
36
        $this->serverName = $serverVars->get('SERVER_NAME');
37
        $this->serverPort = $serverVars->get('SERVER_PORT');
38
39
        parent::__construct($configuration);
40
    }
41
42
    /**
43
     * @return void
44
     */
45
    protected function invokeTestSuite()
46
    {
47
        // Check network connection to full public URL
48
        $input = [
49
            'connectString' = 'ssl://'.$hostname.':'.$port,
0 ignored issues
show
Bug introduced by
This code did not parse for me. Apparently, there is an error somewhere around this line:

Syntax error, unexpected '=', expecting ']'
Loading history...
50
            'context' = stream_context_create([
51
                "ssl" => [
52
                    "capture_peer_cert" => true,
53
                    "verify_peer" => false,
54
                    "verify_peer_name" => false
55
                ]
56
            ]),
57
        ];
58
59
        $connTest = new TestCase\Network\ConnectUri($this, new TestData($input));
60
        $connTestResult = $connTest->getTestResult();
61
62
        $this->addTest($connTest);
63
64
        if ($connTestResult->getState() === State::OK) {
65
            // Check Service Communications Certificate
66
            $certData = $connTestResult->getOutput('certData');
67
            
68
            if (Utils\HTTP::isHTTPS() && $certData !== null) {
69
                $input = [
70
                    'category' => 'Service Communications Certificate',
71
                    'certData' => $certData,
72
                ];
73
74
                $certTest = new TestCase\Cert\Data($this, new TestData($input));
75
                $this->addTest($certTest);
76
            }
77
        }
78
79
        // Check metadata signing certificate when available
80
        if (is_string($this->metadataCert)) {
81
            $input = array(
82
                'certFile' => Utils\Config::getCertPath($this->metadataCert),
83
                'category' => 'Metadata Signing Certificate'
84
            );
85
            $testData = new TestData($input);
86
87
            $test = new TestCase\Cert\File($this, $testData);
88
            $this->addTest($test);
89
        }
90
91
        $tests = $this->getTests();
92
        foreach ($tests as $test)
93
        {
94
            $this->addMessages($test->getMessages());
95
        }
96
97
        $this->calculateState();
98
    }
99
}
100