Completed
Push — master ( 336397...b90ae0 )
by Simon
01:36
created

YubiAuthenticatorTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 71
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 10

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 11 1
A tearDown() 0 4 1
A testNoYubikey() 0 10 1
A testNoYubikeyLockout() 0 13 1
A testYubikey() 0 17 1
1
<?php
2
3
namespace Firesphere\YubiAuth\Tests;
4
5
use Authenticator;
6
use Config;
7
use Firesphere\YubiAuth\YubikeyAuthenticator;
8
use Firesphere\YubiAuth\YubikeyLoginForm;
9
use Injector;
10
use Member;
11
use PHPUnit_Framework_TestCase;
12
use SapphireTest;
13
use Security;
14
15
/**
16
 * Class YubiAuthenticatorTest
17
 *
18
 * @mixin PHPUnit_Framework_TestCase
19
 */
20
class YubiAuthenticatorTest extends SapphireTest
21
{
22
23
    protected static $fixture_file = '../fixtures/Member.yml';
24
25
    /**
26
     * @var YubikeyLoginForm
27
     */
28
    protected $form;
29
30
    public function setUp()
31
    {
32
        parent::setUp();
33
        $this->objFromFixture('Member', 'admin');
34
        $controller = Security::create();
35
        /** @var YubikeyLoginForm $form */
36
        $this->form = YubikeyLoginForm::create($controller, 'Form', null, null);
37
        Authenticator::register_authenticator('Firesphere\\YubiAuth\\YubikeyAuthenticator');
38
        $validator = new MockYubiValidate('apikey', '1234');
39
        Injector::inst()->registerService($validator, 'Yubikey\\Validate');
0 ignored issues
show
Documentation introduced by
$validator is of type object<Firesphere\YubiAu...Tests\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...
40
    }
41
42
    public function tearDown()
43
    {
44
        parent::tearDown(); // TODO: Change the autogenerated stub
45
    }
46
47
    public function testNoYubikey()
48
    {
49
        $member = YubikeyAuthenticator::authenticate(array(
50
            'Email' => '[email protected]',
51
            'Password' => 'password',
52
            'Yubikey' => ''
53
        ), $this->form);
54
        $this->assertGreaterThan(0, $member->NoYubikeyCount);
0 ignored issues
show
Bug introduced by
The method assertGreaterThan() does not seem to exist on object<Firesphere\YubiAu...\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...
55
        $this->assertEquals(null, $member->Yubikey);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<Firesphere\YubiAu...\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...
56
    }
57
58
    public function testNoYubikeyLockout()
59
    {
60
        Config::inst()->update('Firesphere\\YubiAuth\\YubikeyAuthenticator', 'MaxNoYubiLogin', 5);
61
        $member = Member::get()->filter(array('Email' => '[email protected]'))->first();
62
        $member->NoYubikeyCount = 5;
63
        $member->write();
64
        $result = YubikeyAuthenticator::authenticate(array(
65
            'Email' => '[email protected]',
66
            'Password' => 'password',
67
            'Yubikey' => ''
68
        ), $this->form);
69
        $this->assertEquals(null, $result);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<Firesphere\YubiAu...\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...
70
    }
71
72
    public function testYubikey()
73
    {
74
        $result = YubikeyAuthenticator::authenticate(array(
75
            'Email' => '[email protected]',
76
            'Password' => 'password',
77
            'Yubikey' => 'jjjjjjucbuipyhde.cybcpnbiixcjkbbyd.ydenhnjkn' // This OTP is _not_ valid in real situations
78
        ), $this->form);
79
        $this->assertEquals('Member', $result->ClassName);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<Firesphere\YubiAu...\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...
80
        $this->assertEquals('ccccccfinfgr', $result->Yubikey);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<Firesphere\YubiAu...\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...
81
        $this->assertEquals(true, $result->YubiAuthEnabled);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<Firesphere\YubiAu...\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...
82
        $resultNoYubi = YubikeyAuthenticator::authenticate(array(
83
            'Email' => '[email protected]',
84
            'Password' => 'password',
85
            'Yubikey' => ''
86
        ), $this->form);
87
        $this->assertEquals(null, $resultNoYubi);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<Firesphere\YubiAu...\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...
88
    }
89
90
}