Passed
Push — master ( 23587f...1016f0 )
by Jan
04:38 queued 10s
created

testTFARedirectNeeded()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 25
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 13
c 1
b 0
f 1
nc 1
nop 0
dl 0
loc 25
rs 9.8333
1
<?php
2
/**
3
 * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
4
 *
5
 * Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
6
 *
7
 * This program is free software; you can redistribute it and/or
8
 * modify it under the terms of the GNU General Public License
9
 * as published by the Free Software Foundation; either version 2
10
 * of the License, or (at your option) any later version.
11
 *
12
 * This program is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 * GNU General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU General Public License
18
 * along with this program; if not, write to the Free Software
19
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
20
 */
21
22
namespace App\Tests\EventSubscriber;
23
24
use App\Entity\UserSystem\Group;
25
use App\Entity\UserSystem\U2FKey;
26
use App\Entity\UserSystem\User;
27
use App\EventSubscriber\PasswordChangeNeededSubscriber;
28
use PHPUnit\Framework\TestCase;
0 ignored issues
show
Bug introduced by
The type PHPUnit\Framework\TestCase was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
29
30
class PasswordChangeNeededSubscriberTest extends TestCase
31
{
32
33
    public function testTFARedirectNeeded()
34
    {
35
        $user = new User();
36
        $group = new Group();
37
38
        //A user without a group must not redirect
39
        $user->setGroup(null);
40
        $this->assertFalse(PasswordChangeNeededSubscriber::TFARedirectNeeded($user));
41
42
        //When the group does not enforce the redirect the user must not be redirected
43
        $user->setGroup($group);
44
        $this->assertFalse(PasswordChangeNeededSubscriber::TFARedirectNeeded($user));
45
46
        //The user must be redirected if the group enforces 2FA and it does not have a method
47
        $group->setEnforce2FA(true);
48
        $this->assertTrue(PasswordChangeNeededSubscriber::TFARedirectNeeded($user));
49
50
        //User must not be redirect if google authenticator is setup
51
        $user->setGoogleAuthenticatorSecret('abcd');
52
        $this->assertFalse(PasswordChangeNeededSubscriber::TFARedirectNeeded($user));
53
54
        //User must not be redirect if 2FA is setup
55
        $user->setGoogleAuthenticatorSecret(null);
56
        $user->addU2FKey(new U2FKey());
57
        $this->assertFalse(PasswordChangeNeededSubscriber::TFARedirectNeeded($user));
58
59
    }
60
}
61