Passed
Push — master ( 64d02f...fbdc2d )
by Tim
03:59
created

Configuration::invokeTest()   B

Complexity

Conditions 4
Paths 6

Size

Total Lines 50
Code Lines 28

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 28
nc 6
nop 0
dl 0
loc 50
rs 8.8571
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\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
        $this->setCategory('Configuration');
39
40
        parent::__construct($configuration);
41
    }
42
43
    /**
44
     * @return void
45
     */
46
    public function invokeTest()
47
    {
48
        // Check network connection to full public URL
49
        $input = [
50
            'connectString' => 'ssl://'.$this->serverName.':'.$this->serverPort,
51
            'context' => stream_context_create([
52
                "ssl" => [
53
                    "capture_peer_cert" => true,
54
                    "verify_peer" => false,
55
                    "verify_peer_name" => false
56
                ]
57
            ]),
58
        ];
59
60
        $connTest = new TestCase\Network\ConnectUri($this, new TestData($input));
61
        $connTestResult = $connTest->getTestResult();
62
63
        $this->addTestResult($connTest->getTestResult());
64
65
        if ($connTestResult->getState() === State::OK) {
0 ignored issues
show
Bug introduced by
The type SimpleSAML\Module\monitor\TestSuite\State was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
66
            // We were able to connect
67
            if (Utils\HTTP::isHTTPS()) {
68
                // Check Service Communications Certificate
69
                $certData = $connTestResult->getOutput('certData');
70
71
                $input = [
72
                    'category' => 'Service Communications Certificate',
73
                    'certData' => $certData,
74
                ];
75
76
                $certTest = new TestCase\Cert\Data($this, new TestData($input));
77
                $this->addTestResult($certTest->getTestResult());
78
            }
79
        }
80
81
        // Check metadata signing certificate when available
82
        if (is_string($this->metadataCert)) {
83
            $input = array(
84
                'certFile' => Utils\Config::getCertPath($this->metadataCert),
85
                'category' => 'Metadata Signing Certificate'
86
            );
87
            $testData = new TestData($input);
88
89
            $test = new TestCase\Cert\File($this, $testData);
90
            $this->addTestResult($test->getTestResult());
91
        }
92
93
        $testResult = new TestResult('Configuration', '');
0 ignored issues
show
Bug introduced by
The type SimpleSAML\Module\monitor\TestSuite\TestResult was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
94
        $testResult->setState($this->calculateState());
95
        $this->setTestResult($testResult);
96
    }
97
}
98