Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DEP Deprecate API that will be removed or renamed #11401

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/Security/Member.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
use Symfony\Component\Mime\Exception\RfcComplianceException;
use Closure;
use RuntimeException;
use SilverStripe\Dev\Deprecation;

/**
* The member class which represents the users of the system
Expand Down Expand Up @@ -396,7 +397,7 @@ public static function set_password_validator(PasswordValidator $validator = nul
public static function password_validator()
{
if (Injector::inst()->has(PasswordValidator::class)) {
return Injector::inst()->get(PasswordValidator::class);
return Deprecation::withSuppressedNotice(fn() => Injector::inst()->get(PasswordValidator::class));
}
return null;
}
Expand Down
12 changes: 12 additions & 0 deletions src/Security/PasswordValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use SilverStripe\Core\Config\Configurable;
use SilverStripe\Core\Extensible;
use SilverStripe\Core\Injector\Injectable;
use SilverStripe\Dev\Deprecation;
use SilverStripe\ORM\ValidationResult;

/**
Expand All @@ -19,6 +20,8 @@
*
* Member::set_password_validator($pwdValidator);
* </code>
*
* @deprecated 5.4.0 Will be renamed to SilverStripe\Security\Validation\RulesPasswordValidator
*/
class PasswordValidator
{
Expand Down Expand Up @@ -75,6 +78,15 @@ class PasswordValidator
*/
protected $historicalPasswordCount = null;

public function __construct()
{
Deprecation::notice(
'5.4.0',
'Will be renamed to SilverStripe\Security\Validation\RulesPasswordValidator',
Deprecation::SCOPE_CLASS
);
}

/**
* @return int
*/
Expand Down
7 changes: 5 additions & 2 deletions tests/php/Forms/ConfirmedPasswordFieldTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use SilverStripe\Security\PasswordValidator;
use SilverStripe\View\SSViewer;
use Closure;
use SilverStripe\Dev\Deprecation;

class ConfirmedPasswordFieldTest extends SapphireTest
{
Expand All @@ -23,9 +24,11 @@ protected function setUp(): void
{
parent::setUp();

PasswordValidator::singleton()
Deprecation::withSuppressedNotice(
fn() => PasswordValidator::singleton()
->setMinLength(0)
->setTestNames([]);
->setTestNames([])
);
}

public function testSetValue()
Expand Down
7 changes: 5 additions & 2 deletions tests/php/Security/MemberAuthenticatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use SilverStripe\Control\NullHTTPRequest;
use SilverStripe\Core\Config\Config;
use SilverStripe\Core\Injector\Injector;
use SilverStripe\Dev\Deprecation;
use SilverStripe\Dev\SapphireTest;
use SilverStripe\ORM\FieldType\DBDatetime;
use SilverStripe\ORM\ValidationResult;
Expand Down Expand Up @@ -44,9 +45,11 @@ protected function setUp(): void
DefaultAdminService::setDefaultAdmin('admin', 'password');

// Enforce dummy validation (this can otherwise be influenced by recipe config)
PasswordValidator::singleton()
Deprecation::withSuppressedNotice(
fn() => PasswordValidator::singleton()
->setMinLength(0)
->setTestNames([]);
->setTestNames([])
);
}

protected function tearDown(): void
Expand Down
7 changes: 5 additions & 2 deletions tests/php/Security/MemberCsvBulkLoaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace SilverStripe\Security\Tests;

use SilverStripe\Dev\Deprecation;
use SilverStripe\ORM\DataObject;
use SilverStripe\Security\Group;
use SilverStripe\Security\MemberCsvBulkLoader;
Expand All @@ -19,9 +20,11 @@ protected function setUp(): void
{
parent::setUp();

PasswordValidator::singleton()
Deprecation::withSuppressedNotice(
fn() => PasswordValidator::singleton()
->setMinLength(0)
->setTestNames([]);
->setTestNames([])
);
}

public function testNewImport()
Expand Down
13 changes: 8 additions & 5 deletions tests/php/Security/MemberTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use SilverStripe\Core\Config\Config;
use SilverStripe\Core\Convert;
use SilverStripe\Core\Injector\Injector;
use SilverStripe\Dev\Deprecation;
use SilverStripe\Dev\FunctionalTest;
use SilverStripe\Forms\CheckboxField;
use SilverStripe\Forms\FieldList;
Expand Down Expand Up @@ -72,9 +73,11 @@ protected function setUp(): void

Member::config()->set('unique_identifier_field', 'Email');

PasswordValidator::singleton()
Deprecation::withSuppressedNotice(
fn() => PasswordValidator::singleton()
->setMinLength(0)
->setTestNames([]);
->setTestNames([])
);

i18n::set_locale('en_US');
}
Expand Down Expand Up @@ -1742,7 +1745,7 @@ public function testNewMembersReceiveTheDefaultLocale()
public function testChangePasswordOnlyValidatesPlaintext()
{
// This validator requires passwords to be 17 characters long
Member::set_password_validator(new MemberTest\VerySpecificPasswordValidator());
Member::set_password_validator(Deprecation::withSuppressedNotice(fn() => new MemberTest\VerySpecificPasswordValidator()));

// This algorithm will never return a 17 character hash
Security::config()->set('password_encryption_algorithm', 'blowfish');
Expand Down Expand Up @@ -1771,7 +1774,7 @@ public function testEmailIsTrimmed()

public function testChangePasswordToBlankIsValidated()
{
Member::set_password_validator(new PasswordValidator());
Member::set_password_validator(Deprecation::withSuppressedNotice(fn() => new PasswordValidator()));
// override setup() function which setMinLength(0)
PasswordValidator::singleton()->setMinLength(8);
// 'test' member has a password defined in yml
Expand Down Expand Up @@ -1909,7 +1912,7 @@ public function testGenerateRandomPassword()
$password = $member->generateRandomPassword();
$this->assertSame(20, strlen($password));
// password validator
$validator = new PasswordValidator();
$validator = Deprecation::withSuppressedNotice(fn() => new PasswordValidator());
Member::set_password_validator($validator);
// Password length of 20 even if validator minLength is less than 20
$validator->setMinLength(10);
Expand Down
11 changes: 6 additions & 5 deletions tests/php/Security/PasswordValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace SilverStripe\Security\Tests;

use SilverStripe\Dev\Deprecation;
use SilverStripe\Dev\SapphireTest;
use SilverStripe\Security\Member;
use SilverStripe\Security\PasswordValidator;
Expand All @@ -26,7 +27,7 @@ protected function setUp(): void

public function testValidate()
{
$v = new PasswordValidator();
$v = Deprecation::withSuppressedNotice(fn() => new PasswordValidator());
$r = $v->validate('', new Member());
$this->assertTrue($r->isValid(), 'Empty password is valid by default');

Expand All @@ -36,7 +37,7 @@ public function testValidate()

public function testValidateMinLength()
{
$v = new PasswordValidator();
$v = Deprecation::withSuppressedNotice(fn() => new PasswordValidator());

$v->setMinLength(4);
$r = $v->validate('123', new Member());
Expand All @@ -50,7 +51,7 @@ public function testValidateMinLength()
public function testValidateMinScore()
{
// Set both score and set of tests
$v = new PasswordValidator();
$v = Deprecation::withSuppressedNotice(fn() => new PasswordValidator());
$v->setMinTestScore(3);
$v->setTestNames(["lowercase", "uppercase", "digits", "punctuation"]);

Expand All @@ -61,7 +62,7 @@ public function testValidateMinScore()
$this->assertTrue($r->isValid(), 'Passing enough tests');

// Ensure min score without tests works (uses default tests)
$v = new PasswordValidator();
$v = Deprecation::withSuppressedNotice(fn() => new PasswordValidator());
$v->setMinTestScore(3);

$r = $v->validate('aA', new Member());
Expand All @@ -81,7 +82,7 @@ public function testValidateMinScore()
*/
public function testHistoricalPasswordCount()
{
$validator = new PasswordValidator;
$validator = Deprecation::withSuppressedNotice(fn() => new PasswordValidator);
$validator->setHistoricCount(3);
Member::set_password_validator($validator);

Expand Down
7 changes: 5 additions & 2 deletions tests/php/Security/VersionedMemberAuthenticatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use SilverStripe\Control\NullHTTPRequest;
use SilverStripe\Core\Config\Config;
use SilverStripe\Core\Injector\Injector;
use SilverStripe\Dev\Deprecation;
use SilverStripe\Dev\SapphireTest;
use SilverStripe\ORM\FieldType\DBDatetime;
use SilverStripe\ORM\ValidationResult;
Expand Down Expand Up @@ -43,9 +44,11 @@ protected function setUp(): void
}

// Enforce dummy validation (this can otherwise be influenced by recipe config)
PasswordValidator::singleton()
Deprecation::withSuppressedNotice(
fn() => PasswordValidator::singleton()
->setMinLength(0)
->setTestNames([]);
->setTestNames([])
);
}

protected function tearDown(): void
Expand Down
Loading