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

TestNegotiateTest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 76
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 43
c 0
b 0
f 0
dl 0
loc 76
rs 10
wmc 6

6 Methods

Rating   Name   Duplication   Size   Complexity  
A testNegotiateError() 0 14 1
A testNegotiateNoAuthorzation() 0 13 1
A testNegotiateSuccess() 0 16 1
A tearDownAfterClass() 0 3 1
A setUpBeforeClass() 0 3 1
A testNegotiateException() 0 15 1
1
<?php
2
3
namespace SimpleSAML\Module\monitor\Test;
4
5
use KRB5NegotiateAuth;
6
use SimpleSAML\Configuration;
7
use SimpleSAML\Module\monitor\TestCase;
8
use SimpleSAML\Module\monitor\TestData;
9
use SimpleSAML\Module\monitor\State;
10
11
/**
12
 * Tests for TestCase\Negotiate
13
 */
14
class TestNegotiateTest extends \PHPUnit\Framework\TestCase
15
{
16
    public static function setUpBeforeClass(): void
17
    {
18
        $_SERVER['SERVER_NAME'] = 'localhost';
19
    }
20
21
    public static function tearDownAfterClass(): void
22
    {
23
        unset($_SERVER['SERVER_NAME']);
24
    }
25
26
    public function testNegotiateException(): void
27
    {
28
        $KRB5NegotiateAuthMock = $this->getMockBuilder(KRB5NegotiateAuth::class)->onlyMethods(
29
            ['doAuthentication', 'getAuthenticatedUser']
30
        )->disableOriginalConstructor()->getMock();
31
        $KRB5NegotiateAuthMock->expects($this->any())->method('doAuthentication')->will(
32
            $this->throwException(new \Exception('Generic exception message'))
33
        );
34
        $testData = new TestData([
35
            'handle' => $KRB5NegotiateAuthMock,
36
        ]);
37
38
        $confTest = new TestCase\AuthSource\Negotiate($testData);
39
        $testResult = $confTest->getTestResult();
40
        $this->assertEquals(State::WARNING, $testResult->getState());
41
    }
42
43
    public function testNegotiateSuccess(): void
44
    {
45
        $KRB5NegotiateAuthMock = $this->getMockBuilder(KRB5NegotiateAuth::class)->onlyMethods(
46
            ['doAuthentication', 'getAuthenticatedUser']
47
        )->disableOriginalConstructor()->getMock();
48
        $KRB5NegotiateAuthMock->expects($this->any())->method('doAuthentication')->will($this->returnValue(true));
49
        $KRB5NegotiateAuthMock->expects($this->any())->method('getAuthenticatedUser')->will(
50
            $this->returnValue('[email protected]')
51
        );
52
        $testData = new TestData([
53
            'handle' => $KRB5NegotiateAuthMock,
54
        ]);
55
56
        $confTest = new TestCase\AuthSource\Negotiate($testData);
57
        $testResult = $confTest->getTestResult();
58
        $this->assertEquals(State::OK, $testResult->getState());
59
    }
60
61
    public function testNegotiateNoAuthorzation(): void
62
    {
63
        $KRB5NegotiateAuthMock = $this->getMockBuilder(KRB5NegotiateAuth::class)->onlyMethods(
64
            ['doAuthentication', 'getAuthenticatedUser']
65
        )->disableOriginalConstructor()->getMock();
66
        $KRB5NegotiateAuthMock->expects($this->any())->method('doAuthentication')->will($this->returnValue(false));
67
        $testData = new TestData([
68
            'handle' => $KRB5NegotiateAuthMock,
69
        ]);
70
71
        $confTest = new TestCase\AuthSource\Negotiate($testData);
72
        $testResult = $confTest->getTestResult();
73
        $this->assertEquals(State::SKIPPED, $testResult->getState());
74
    }
75
76
    public function testNegotiateError(): void
77
    {
78
        $KRB5NegotiateAuthMock = $this->getMockBuilder(KRB5NegotiateAuth::class)->onlyMethods(
79
            ['doAuthentication', 'getAuthenticatedUser']
80
        )->disableOriginalConstructor()->getMock();
81
        $KRB5NegotiateAuthMock->expects($this->any())->method('doAuthentication')->will($this->returnValue(false));
82
        $testData = new TestData([
83
            'handle' => $KRB5NegotiateAuthMock,
84
            'authorization' => 'test',
85
        ]);
86
87
        $confTest = new TestCase\AuthSource\Negotiate($testData);
88
        $testResult = $confTest->getTestResult();
89
        $this->assertEquals(State::WARNING, $testResult->getState());
90
    }
91
}
92