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

Bind   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 57
rs 10
c 1
b 0
f 0
wmc 3
lcom 1
cbo 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A invokeTest() 0 17 2
A initialize() 0 12 1
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