mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
96f022be85
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/branches/2.4@98274 467b73ca-7a2a-4603-9d3b-597d59a354a9
63 lines
1.7 KiB
PHP
63 lines
1.7 KiB
PHP
<?php
|
|
/**
|
|
* @package sapphire
|
|
* @subpackage tests
|
|
*/
|
|
class MemberAuthenticatorTest extends SapphireTest {
|
|
function testLegacyPasswordHashMigrationUponLogin() {
|
|
$member = new Member();
|
|
|
|
$field=Member::get_unique_identifier_field();
|
|
|
|
$member->$field = 'test@test.com';
|
|
$member->PasswordEncryption = "sha1";
|
|
$member->Password = "mypassword";
|
|
$member->write();
|
|
|
|
$data = array(
|
|
'Email' => $member->$field,
|
|
'Password' => 'mypassword'
|
|
);
|
|
MemberAuthenticator::authenticate($data);
|
|
|
|
$member = DataObject::get_by_id('Member', $member->ID);
|
|
$this->assertEquals($member->PasswordEncryption, "sha1_v2.4");
|
|
$result = $member->checkPassword('mypassword');
|
|
$this->assertTrue($result->valid());
|
|
}
|
|
|
|
function testNoLegacyPasswordHashMigrationOnIncompatibleAlgorithm() {
|
|
PasswordEncryptor::register('crc32', 'PasswordEncryptor_PHPHash("crc32")');
|
|
|
|
$field=Member::get_unique_identifier_field();
|
|
|
|
$member = new Member();
|
|
$member->$field = 'test@test.com';
|
|
$member->PasswordEncryption = "crc32";
|
|
$member->Password = "mypassword";
|
|
$member->write();
|
|
|
|
$data = array(
|
|
'Email' => $member->$field,
|
|
'Password' => 'mypassword'
|
|
);
|
|
MemberAuthenticator::authenticate($data);
|
|
|
|
$member = DataObject::get_by_id('Member', $member->ID);
|
|
$this->assertEquals($member->PasswordEncryption, "crc32");
|
|
$result = $member->checkPassword('mypassword');
|
|
$this->assertTrue($result->valid());
|
|
}
|
|
|
|
function testCustomIdentifierField(){
|
|
|
|
$origField = Member::get_unique_identifier_field();
|
|
Member::set_unique_identifier_field('Username');
|
|
|
|
$label=singleton('Member')->fieldLabel(Member::get_unique_identifier_field());
|
|
|
|
$this->assertEquals($label, 'Username');
|
|
|
|
Member::set_unique_identifier_field($origField);
|
|
}
|
|
} |