Completed
Push — master ( e93afc...77b90b )
by Tim
15:46 queued 14:18
created

Bind::invokeTest()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 17
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 12
nc 2
nop 0
dl 0
loc 17
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace SimpleSAML\Module\monitor\TestCase\AuthSource\Ldap;
4
5
use \SimpleSAML\Module\monitor\State as State;
6
use \SimpleSAML\Module\monitor\TestData as TestData;
7
use \SimpleSAML\Module\monitor\TestSuite as TestSuite;
8
9
final class Bind extends \SimpleSAML\Module\monitor\TestCaseFactory
10
{
11
    /*
12
     * @var \SimpleSAML_Auth_LDAP|null
13
     */
14
    private $connection = null;
15
16
    /*
17
     * @var string|null
18
     */
19
    private $username = null;
20
21
    /*
22
     * @var string|null
23
     */
24
25
    private $password = null;
26
27
    /*
28
     * @param TestData $testData
29
     *
30
     * @return void
31
     */
32
    protected function initialize($testData)
33
    {
34
        $this->connection = $testData->getInput('connection');
35
        $authSource = $testData->getInput('authSource');
36
37
        $this->username = $authSource['search.username'];
38
        $this->password = $authSource['search.password'];
39
40
        $this->setSubject($this->username);
41
42
        parent::initialize($testData);
43
    }
44
45
    /*
46
     * @return void
47
     */
48
    protected function invokeTest()
49
    {
50
        $connection = $this->connection;
51
        $subject = $this->getSubject();
52
53
        try {
54
            $connection->bind($this->username, $this->password);
55
        } catch (\Exception $e) {
56
            $msg = str_replace('Library - LDAP bind(): ', '', $e->getMessage());
57
            $this->setState(State::ERROR);
58
            $this->addMessage(State::ERROR, 'LDAP Bind', $subject, $msg);
59
            return;
60
        }
61
62
        $this->setState(State::OK);
63
        $this->addMessage(State::OK, 'LDAP Bind', $subject, 'Bind succesful');
64
    }
65
}
66