|
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'); |
|
|
|
|
|
|
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); |
|
|
|
|
|
|
55
|
|
|
$this->assertEquals(null, $member->Yubikey); |
|
|
|
|
|
|
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); |
|
|
|
|
|
|
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); |
|
|
|
|
|
|
80
|
|
|
$this->assertEquals('ccccccfinfgr', $result->Yubikey); |
|
|
|
|
|
|
81
|
|
|
$this->assertEquals(true, $result->YubiAuthEnabled); |
|
|
|
|
|
|
82
|
|
|
$resultNoYubi = YubikeyAuthenticator::authenticate(array( |
|
83
|
|
|
'Email' => '[email protected]', |
|
84
|
|
|
'Password' => 'password', |
|
85
|
|
|
'Yubikey' => '' |
|
86
|
|
|
), $this->form); |
|
87
|
|
|
$this->assertEquals(null, $resultNoYubi); |
|
|
|
|
|
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
} |
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: