Completed
Branch develop (5d5be1)
by Simon
01:59
created

YubiAuthenticatorTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 10

Importance

Changes 0
Metric Value
wmc 5
c 0
b 0
f 0
lcom 1
cbo 10
dl 0
loc 68
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 9 1
A tearDown() 0 4 1
A testNoYubikey() 0 10 1
A testNoYubikeyLockout() 0 13 1
A testYubikey() 0 19 1
1
<?php
2
3
use Firesphere\YubiAuth\YubikeyAuthenticator;
4
use Firesphere\YubiAuth\YubikeyLoginForm;
5
6
class YubiAuthenticatorTest extends SapphireTest
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
7
{
8
9
    protected static $fixture_file = '../fixtures/Member.yml';
10
11
    protected $form;
12
13
    public function setUp()
14
    {
15
        parent::setUp();
16
        $this->objFromFixture('Member', 'admin');
17
        $controller = Security::create();
18
        /** @var YubikeyLoginForm $form */
19
        $this->form = YubikeyLoginForm::create($controller, 'Form', null, null);
20
        Authenticator::register_authenticator('Firesphere\\YubiAuth\\YubikeyAuthenticator');
21
    }
22
23
    public function tearDown()
24
    {
25
        parent::tearDown(); // TODO: Change the autogenerated stub
26
    }
27
28
    public function testNoYubikey()
29
    {
30
        $member = YubikeyAuthenticator::authenticate(array(
31
            'Email' => '[email protected]',
32
            'Password' => 'password',
33
            'Yubikey' => ''
34
        ), $this->form);
35
        $this->assertGreaterThan(0, $member->NoYubikeyCount);
0 ignored issues
show
Bug introduced by
The method assertGreaterThan() does not seem to exist on object<YubiAuthenticatorTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
36
        $this->assertEquals(null, $member->Yubikey);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<YubiAuthenticatorTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
37
    }
38
39
    public function testNoYubikeyLockout()
40
    {
41
        Config::inst()->update('Firesphere\\YubiAuth\\YubikeyAuthenticator', 'MaxNoYubiLogin', 5);
42
        $member = Member::get()->filter(array('Email' => '[email protected]'))->first();
43
        $member->NoYubikeyCount = 5;
44
        $member->write();
45
        $result = YubikeyAuthenticator::authenticate(array(
46
            'Email' => '[email protected]',
47
            'Password' => 'password',
48
            'Yubikey' => ''
49
        ), $this->form);
50
        $this->assertEquals(null, $result);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<YubiAuthenticatorTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
51
    }
52
53
    public function testYubikey()
54
    {
55
        $validator = new MockYubiValidate('apikey', '1234');
56
        Injector::inst()->registerService($validator, 'Yubikey\\Validate');
0 ignored issues
show
Documentation introduced by
$validator is of type object<MockYubiValidate>, but the function expects a object<stdClass>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
57
        $result = YubikeyAuthenticator::authenticate(array(
58
            'Email' => '[email protected]',
59
            'Password' => 'password',
60
            'Yubikey' => 'jjjjjjucbuipyhde.cybcpnbiixcjkbbyd.ydenhnjkn'
61
        ), $this->form);
62
        $this->assertEquals('Member', $result->ClassName);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<YubiAuthenticatorTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
63
        $this->assertEquals('ccccccfinfgr', $result->Yubikey);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<YubiAuthenticatorTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
64
        $this->assertEquals(true, $result->YubiAuthEnabled);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<YubiAuthenticatorTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
65
        $resultNoYubi = YubikeyAuthenticator::authenticate(array(
66
            'Email' => '[email protected]',
67
            'Password' => 'password',
68
            'Yubikey' => ''
69
        ), $this->form);
70
        $this->assertEquals(null, $resultNoYubi);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<YubiAuthenticatorTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
71
    }
72
73
}