2010-10-15 05:03:19 +02:00
|
|
|
<?php
|
2016-06-23 01:37:22 +02:00
|
|
|
|
2016-10-14 03:30:05 +02:00
|
|
|
namespace SilverStripe\Security\Tests;
|
|
|
|
|
2016-06-23 01:37:22 +02:00
|
|
|
use SilverStripe\Security\PasswordValidator;
|
|
|
|
use SilverStripe\Security\Member;
|
2016-08-19 00:51:35 +02:00
|
|
|
use SilverStripe\Dev\SapphireTest;
|
|
|
|
|
2010-10-15 05:03:19 +02:00
|
|
|
class PasswordValidatorTest extends SapphireTest {
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function testValidate() {
|
2010-10-15 05:03:19 +02:00
|
|
|
$v = new PasswordValidator();
|
|
|
|
$r = $v->validate('', new Member());
|
|
|
|
$this->assertTrue($r->valid(), 'Empty password is valid by default');
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2010-10-15 05:03:19 +02:00
|
|
|
$r = $v->validate('mypassword', new Member());
|
|
|
|
$this->assertTrue($r->valid(), 'Non-Empty password is valid by default');
|
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function testValidateMinLength() {
|
2010-10-15 05:03:19 +02:00
|
|
|
$v = new PasswordValidator();
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2010-10-15 05:03:19 +02:00
|
|
|
$v->minLength(4);
|
|
|
|
$r = $v->validate('123', new Member());
|
|
|
|
$this->assertFalse($r->valid(), 'Password too short');
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2010-10-15 05:03:19 +02:00
|
|
|
$v->minLength(4);
|
|
|
|
$r = $v->validate('1234', new Member());
|
|
|
|
$this->assertTrue($r->valid(), 'Password long enough');
|
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function testValidateMinScore() {
|
2010-10-15 05:03:19 +02:00
|
|
|
$v = new PasswordValidator();
|
|
|
|
$v->characterStrength(3, array("lowercase", "uppercase", "digits", "punctuation"));
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2010-10-15 05:03:19 +02:00
|
|
|
$r = $v->validate('aA', new Member());
|
|
|
|
$this->assertFalse($r->valid(), 'Passing too few tests');
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2010-10-15 05:03:19 +02:00
|
|
|
$r = $v->validate('aA1', new Member());
|
|
|
|
$this->assertTrue($r->valid(), 'Passing enough tests');
|
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function testHistoricalPasswordCount() {
|
2012-11-23 14:55:19 +01:00
|
|
|
$this->markTestIncomplete();
|
2010-10-15 05:03:19 +02:00
|
|
|
}
|
2012-03-24 04:04:52 +01:00
|
|
|
}
|