From 96f022be85067fb419c23c7f0c1f242c939dc429 Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Fri, 5 Feb 2010 01:15:31 +0000 Subject: [PATCH] MINOR Fixed unit tests after change Member->checkPassword() to return ValidationResult instead of boolean (see r98268) git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/branches/2.4@98274 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- security/MemberAuthenticator.php | 2 +- tests/security/MemberAuthenticatorTest.php | 6 ++++-- tests/security/MemberTest.php | 6 ++++-- tests/security/SecurityTest.php | 5 +++-- tests/tasks/EncryptAllPasswordsTaskTest.php | 3 ++- 5 files changed, 14 insertions(+), 8 deletions(-) diff --git a/security/MemberAuthenticator.php b/security/MemberAuthenticator.php index d63363bf8..6c30c8c12 100755 --- a/security/MemberAuthenticator.php +++ b/security/MemberAuthenticator.php @@ -42,7 +42,7 @@ class MemberAuthenticator extends Authenticator { "Member", "\"" . Member::get_unique_identifier_field() . "\" = '$SQL_user' AND \"Password\" IS NOT NULL" ); - $result = $member->checkPassword($RAW_data['Password']); + $result = ($member) ? $member->checkPassword($RAW_data['Password']) : false; if($member && !$result->valid()) { $member->registerFailedLogin(); diff --git a/tests/security/MemberAuthenticatorTest.php b/tests/security/MemberAuthenticatorTest.php index 2204b7aa1..a296315f4 100644 --- a/tests/security/MemberAuthenticatorTest.php +++ b/tests/security/MemberAuthenticatorTest.php @@ -22,7 +22,8 @@ class MemberAuthenticatorTest extends SapphireTest { $member = DataObject::get_by_id('Member', $member->ID); $this->assertEquals($member->PasswordEncryption, "sha1_v2.4"); - $this->assertTrue($member->checkPassword('mypassword')); + $result = $member->checkPassword('mypassword'); + $this->assertTrue($result->valid()); } function testNoLegacyPasswordHashMigrationOnIncompatibleAlgorithm() { @@ -44,7 +45,8 @@ class MemberAuthenticatorTest extends SapphireTest { $member = DataObject::get_by_id('Member', $member->ID); $this->assertEquals($member->PasswordEncryption, "crc32"); - $this->assertTrue($member->checkPassword('mypassword')); + $result = $member->checkPassword('mypassword'); + $this->assertTrue($result->valid()); } function testCustomIdentifierField(){ diff --git a/tests/security/MemberTest.php b/tests/security/MemberTest.php index 2fc0047f4..190f66b9a 100644 --- a/tests/security/MemberTest.php +++ b/tests/security/MemberTest.php @@ -38,14 +38,16 @@ class MemberTest extends FunctionalTest { $member->PasswordEncryption, 'sha1_v2.4' ); - $this->assertTrue($member->checkPassword("mynewpassword")); + $result = $member->checkPassword('mynewpassword'); + $this->assertTrue($result->valid()); } function testSetPassword() { $member = $this->objFromFixture('Member', 'test'); $member->Password = "test1"; $member->write(); - $this->assertTrue($member->checkPassword("test1")); + $result = $member->checkPassword('test1'); + $this->assertTrue($result->valid()); } /** diff --git a/tests/security/SecurityTest.php b/tests/security/SecurityTest.php index 37d7ef7e7..00ef762a2 100644 --- a/tests/security/SecurityTest.php +++ b/tests/security/SecurityTest.php @@ -154,7 +154,7 @@ class SecurityTest extends FunctionalTest { /* THE FIRST 4 TIMES, THE MEMBER SHOULDN'T BE LOCKED OUT */ if($i < 5) { $this->assertNull($member->LockedOutUntil); - $this->assertTrue(false !== stripos($this->loginErrorMessage(), _t('Member.ERRORWRONGCRED'))); + $this->assertContains($this->loginErrorMessage(), _t('Member.ERRORWRONGCRED')); } /* AFTER THAT THE USER IS LOCKED OUT FOR 15 MINUTES */ @@ -165,7 +165,8 @@ class SecurityTest extends FunctionalTest { } if($i > 5) { - $this->assertTrue(false !== stripos($this->loginErrorMessage(), _t('Member.ERRORLOCKEDOUT'))); + $this->assertContains(_t('Member.ERRORLOCKEDOUT'), $this->loginErrorMessage()); + // $this->assertTrue(false !== stripos($this->loginErrorMessage(), _t('Member.ERRORLOCKEDOUT'))); } } diff --git a/tests/tasks/EncryptAllPasswordsTaskTest.php b/tests/tasks/EncryptAllPasswordsTaskTest.php index 310205fbe..714cd4d80 100644 --- a/tests/tasks/EncryptAllPasswordsTaskTest.php +++ b/tests/tasks/EncryptAllPasswordsTaskTest.php @@ -16,6 +16,7 @@ class EncryptAllPasswordsTaskTest extends SapphireTest { $m = DataObject::get_by_id('Member', $m->ID); $this->assertEquals($m->PasswordEncryption, 'sha1_v2.4'); $this->assertNotEquals($m->Password, 'plain'); - $this->assertTrue($m->checkPassword('plain')); + $result = $m->checkPassword('plain'); + $this->assertTrue($result->valid()); } }