summaryrefslogtreecommitdiff
path: root/tests/units/Model/UserLockingTest.php
blob: c743f8eb6f145d7d6f7ce46d90d86cbca705e079 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<?php

require_once __DIR__.'/../Base.php';

use Kanboard\Model\UserLocking;

class UserLockingTest extends Base
{
    public function testFailedLogin()
    {
        $u = new UserLocking($this->container);

        $this->assertEquals(0, $u->getFailedLogin('admin'));
        $this->assertEquals(0, $u->getFailedLogin('not_found'));

        $this->assertTrue($u->incrementFailedLogin('admin'));
        $this->assertTrue($u->incrementFailedLogin('admin'));

        $this->assertEquals(2, $u->getFailedLogin('admin'));
        $this->assertTrue($u->resetFailedLogin('admin'));
        $this->assertEquals(0, $u->getFailedLogin('admin'));
    }

    public function testLocking()
    {
        $u = new UserLocking($this->container);

        $this->assertFalse($u->isLocked('admin'));
        $this->assertFalse($u->isLocked('not_found'));
        $this->assertTrue($u->lock('admin', 1));
        $this->assertTrue($u->isLocked('admin'));
    }

    public function testCaptcha()
    {
        $u = new UserLocking($this->container);
        $this->assertTrue($u->incrementFailedLogin('admin'));
        $this->assertFalse($u->hasCaptcha('admin', 2));

        $this->assertTrue($u->incrementFailedLogin('admin'));
        $this->assertTrue($u->hasCaptcha('admin', 2));
    }
}