From 1ac36611a6cfac8ed08e183068fc89fc5ec34f44 Mon Sep 17 00:00:00 2001 From: Robbie Averill Date: Sun, 2 Dec 2018 23:04:34 +0000 Subject: [PATCH] Update tests to pass in CWP kitchen sink context --- .../php/Forms/ConfirmedPasswordFieldTest.php | 4 +++- .../php/Security/MemberAuthenticatorTest.php | 5 +++++ .../php/Security/MemberCsvBulkLoaderTest.php | 10 ++++++++++ tests/php/Security/MemberTest.php | 4 +++- tests/php/Security/PasswordValidatorTest.php | 4 ++-- tests/php/Security/SecurityTest.php | 20 +++++++++++++------ 6 files changed, 37 insertions(+), 10 deletions(-) diff --git a/tests/php/Forms/ConfirmedPasswordFieldTest.php b/tests/php/Forms/ConfirmedPasswordFieldTest.php index 0df22d4a8..55389ce1d 100644 --- a/tests/php/Forms/ConfirmedPasswordFieldTest.php +++ b/tests/php/Forms/ConfirmedPasswordFieldTest.php @@ -19,7 +19,9 @@ class ConfirmedPasswordFieldTest extends SapphireTest { parent::setUp(); - PasswordValidator::singleton()->setMinLength(0); + PasswordValidator::singleton() + ->setMinLength(0) + ->setTestNames([]); } public function testSetValue() diff --git a/tests/php/Security/MemberAuthenticatorTest.php b/tests/php/Security/MemberAuthenticatorTest.php index 4314cf558..b8758140c 100644 --- a/tests/php/Security/MemberAuthenticatorTest.php +++ b/tests/php/Security/MemberAuthenticatorTest.php @@ -18,6 +18,7 @@ use SilverStripe\Security\MemberAuthenticator\CMSMemberAuthenticator; use SilverStripe\Security\MemberAuthenticator\CMSMemberLoginForm; use SilverStripe\Security\MemberAuthenticator\MemberAuthenticator; use SilverStripe\Security\MemberAuthenticator\MemberLoginForm; +use SilverStripe\Security\PasswordValidator; use SilverStripe\Security\Security; /** @@ -44,6 +45,10 @@ class MemberAuthenticatorTest extends SapphireTest $this->defaultPassword = null; } DefaultAdminService::setDefaultAdmin('admin', 'password'); + + PasswordValidator::singleton() + ->setMinLength(0) + ->setTestNames([]); } protected function tearDown() diff --git a/tests/php/Security/MemberCsvBulkLoaderTest.php b/tests/php/Security/MemberCsvBulkLoaderTest.php index 03c50c9a3..75f62c732 100644 --- a/tests/php/Security/MemberCsvBulkLoaderTest.php +++ b/tests/php/Security/MemberCsvBulkLoaderTest.php @@ -6,6 +6,7 @@ use SilverStripe\ORM\DataObject; use SilverStripe\Security\Group; use SilverStripe\Security\MemberCsvBulkLoader; use SilverStripe\Security\Member; +use SilverStripe\Security\PasswordValidator; use SilverStripe\Security\Security; use SilverStripe\Dev\SapphireTest; @@ -13,6 +14,15 @@ class MemberCsvBulkLoaderTest extends SapphireTest { protected static $fixture_file = 'MemberCsvBulkLoaderTest.yml'; + protected function setUp() + { + parent::setUp(); + + PasswordValidator::singleton() + ->setMinLength(0) + ->setTestNames([]); + } + public function testNewImport() { $loader = new MemberCsvBulkLoader(); diff --git a/tests/php/Security/MemberTest.php b/tests/php/Security/MemberTest.php index 6817246f8..9cd7e67b1 100644 --- a/tests/php/Security/MemberTest.php +++ b/tests/php/Security/MemberTest.php @@ -57,7 +57,9 @@ class MemberTest extends FunctionalTest Member::config()->set('unique_identifier_field', 'Email'); - PasswordValidator::singleton()->setMinLength(0); + PasswordValidator::singleton() + ->setMinLength(0) + ->setTestNames([]); i18n::set_locale('en_US'); } diff --git a/tests/php/Security/PasswordValidatorTest.php b/tests/php/Security/PasswordValidatorTest.php index 7fa5637ab..071e50760 100644 --- a/tests/php/Security/PasswordValidatorTest.php +++ b/tests/php/Security/PasswordValidatorTest.php @@ -18,10 +18,10 @@ class PasswordValidatorTest extends SapphireTest { parent::setUp(); - // Unset framework default values PasswordValidator::config() ->remove('min_length') - ->remove('historic_count'); + ->remove('historic_count') + ->set('min_test_score', 0); } public function testValidate() diff --git a/tests/php/Security/SecurityTest.php b/tests/php/Security/SecurityTest.php index 9ac158758..b75be724c 100644 --- a/tests/php/Security/SecurityTest.php +++ b/tests/php/Security/SecurityTest.php @@ -21,6 +21,7 @@ use SilverStripe\ORM\ValidationResult; use SilverStripe\Security\LoginAttempt; use SilverStripe\Security\Member; use SilverStripe\Security\MemberAuthenticator\MemberAuthenticator; +use SilverStripe\Security\PasswordValidator; use SilverStripe\Security\Security; use SilverStripe\Security\SecurityToken; @@ -51,6 +52,13 @@ class SecurityTest extends FunctionalTest */ Member::config()->set('unique_identifier_field', 'Email'); + PasswordValidator::config() + ->remove('min_length') + ->remove('historic_count') + ->remove('min_test_score'); + + Member::set_password_validator(null); + parent::setUp(); Director::config()->set('alternate_base_url', '/'); @@ -388,7 +396,7 @@ class SecurityTest extends FunctionalTest // Test external redirection on ChangePasswordForm $this->get('Security/changepassword?BackURL=http://myspoofedhost.com'); - $changedResponse = $this->doTestChangepasswordForm('1nitialPassword', 'changedPassword'); + $changedResponse = $this->doTestChangepasswordForm('1nitialPassword', 'changedPassword#123'); $this->assertNotRegExp( '/^' . preg_quote('http://myspoofedhost.com', '/') . '/', (string)$changedResponse->getHeader('Location'), @@ -435,7 +443,7 @@ class SecurityTest extends FunctionalTest // Make sure it redirects correctly after the password has been changed $this->mainSession->followRedirection(); - $changedResponse = $this->doTestChangepasswordForm('1nitialPassword', 'changedPassword'); + $changedResponse = $this->doTestChangepasswordForm('1nitialPassword', 'changedPassword#123'); $this->assertEquals(302, $changedResponse->getStatusCode()); $this->assertEquals( Controller::join_links(Director::absoluteBaseURL(), 'test/link'), @@ -449,7 +457,7 @@ class SecurityTest extends FunctionalTest // Change the password $this->get('Security/changepassword?BackURL=test/back'); - $changedResponse = $this->doTestChangepasswordForm('1nitialPassword', 'changedPassword'); + $changedResponse = $this->doTestChangepasswordForm('1nitialPassword', 'changedPassword#123'); $this->assertEquals(302, $changedResponse->getStatusCode()); $this->assertEquals( Controller::join_links(Director::absoluteBaseURL(), 'test/back'), @@ -459,7 +467,7 @@ class SecurityTest extends FunctionalTest // Check if we can login with the new password $this->logOut(); - $goodResponse = $this->doTestLoginForm('testuser@example.com', 'changedPassword'); + $goodResponse = $this->doTestLoginForm('testuser@example.com', 'changedPassword#123'); $this->assertEquals(302, $goodResponse->getStatusCode()); $this->assertEquals( Controller::join_links(Director::absoluteBaseURL(), 'test/link'), @@ -501,12 +509,12 @@ class SecurityTest extends FunctionalTest // Follow redirection to form without hash in GET parameter $this->get('Security/changepassword'); - $this->doTestChangepasswordForm('1nitialPassword', 'changedPassword'); + $this->doTestChangepasswordForm('1nitialPassword', 'changedPassword#123'); $this->assertEquals($this->idFromFixture(Member::class, 'test'), $this->session()->get('loggedInAs')); // Check if we can login with the new password $this->logOut(); - $goodResponse = $this->doTestLoginForm('testuser@example.com', 'changedPassword'); + $goodResponse = $this->doTestLoginForm('testuser@example.com', 'changedPassword#123'); $this->assertEquals(302, $goodResponse->getStatusCode()); $this->assertEquals($this->idFromFixture(Member::class, 'test'), $this->session()->get('loggedInAs'));