Passed
Branch monitor-2.5.x (577716)
by Tim
01:35
created

TestNegotiateTest::testNegotiateSuccess()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

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