Passed
Push — master ( bb5c60...87d27f )
by Tim
01:35
created

Negotiate::invokeTest()   A

Complexity

Conditions 5
Paths 8

Size

Total Lines 26
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 17
nc 8
nop 0
dl 0
loc 26
rs 9.3888
c 0
b 0
f 0
1
<?php
2
3
namespace SimpleSAML\Modules\Monitor\TestCase\AuthSource;
4
5
use \SimpleSAML\Modules\Monitor\State as State;
0 ignored issues
show
Bug introduced by
The type SimpleSAML\Modules\Monitor\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...
6
use \SimpleSAML\Modules\Monitor\TestData as TestData;
7
use \SimpleSAML\Modules\Monitor\TestResult as TestResult;
8
9
final class Negotiate extends \SimpleSAML\Modules\Monitor\TestCaseFactory
10
{
11
    /**
12
     * @var \KRB5NegotiateAuth
0 ignored issues
show
Bug introduced by
The type KRB5NegotiateAuth 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...
13
     */
14
    private $handle;
15
16
    /**
17
     * @var string|null
18
     */
19
    private $authorization;
20
21
    /*
22
     * @param TestData $testData
23
     *
24
     * @return void
25
     */
26
    protected function initialize($testData)
27
    {
28
        $this->handle = $testData->getInputItem('handle');
29
30
        $authorization = $testData->getInputItem('authorization');
31
        $this->authorization = (is_null($authorization) || empty($authorization)) ? null : $authorization;
32
33
        parent::initialize($testData);
34
    }
35
36
    /*
37
     * @return void
38
     */
39
    public function invokeTest()
40
    {
41
        $testResult = new TestResult('Authentication', 'Kerberos token validation');
42
43
        try {
44
            $reply = @$this->handle->doAuthentication();
45
        } catch (\Exception $error) {
46
            // Fallthru
47
        }
48
49
        if (isSet($error)) {
50
            $testResult->setState(State::WARNING);
51
            $testResult->setMessage($error->getMessage());
52
        } else if ($reply === true) {
53
            $testResult->setState(State::OK);
54
            $testResult->setMessage('Succesfully authenticated as '.$this->handle->getAuthenticatedUser());
55
        } else if (is_null($this->authorization)) {
56
            // Either misconfiguration of the browser, or user not authenticated at a KDC
57
            $testResult->setState(State::SKIPPED);
58
            $testResult->setMessage('Unable to authenticate; no token provided');
59
        } else { // $reply === false
60
            $testResult->setState(State::WARNING);
61
            $testResult->setMessage("Something went wrong and we couldn't tell why");
62
        }
63
64
        $this->setTestResult($testResult);
65
    }
66
}
67