Passed
Push — monitor-3.0.x ( f85cdc...51d4ea )
by Tim
03:29
created

Negotiate   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 24
c 0
b 0
f 0
dl 0
loc 54
rs 10
wmc 8

2 Methods

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