Passed
Branch master (4b23d6)
by Tim
04:40
created

TestNegotiateTest::testNegotiateError()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

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