2009-11-06 03:23:30 +01:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* @package sapphire
|
|
|
|
* @subpackage tests
|
|
|
|
*/
|
|
|
|
class MemberAuthenticatorTest extends SapphireTest {
|
2009-11-30 02:56:05 +01:00
|
|
|
|
|
|
|
protected $usesDatabase = true;
|
|
|
|
|
2009-11-06 03:23:30 +01:00
|
|
|
function testLegacyPasswordHashMigrationUponLogin() {
|
|
|
|
$member = new Member();
|
|
|
|
$member->Email = 'test@test.com';
|
|
|
|
$member->PasswordEncryption = "sha1";
|
|
|
|
$member->Password = "mypassword";
|
|
|
|
$member->write();
|
|
|
|
|
|
|
|
$data = array(
|
|
|
|
'Email' => $member->Email,
|
|
|
|
'Password' => 'mypassword'
|
|
|
|
);
|
|
|
|
MemberAuthenticator::authenticate($data);
|
|
|
|
|
|
|
|
$member = DataObject::get_by_id('Member', $member->ID);
|
|
|
|
$this->assertEquals($member->PasswordEncryption, "sha1_v2.4");
|
2010-02-23 05:05:34 +01:00
|
|
|
$result = $member->checkPassword('mypassword');
|
|
|
|
$this->assertTrue($result->valid());
|
2009-11-06 03:23:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function testNoLegacyPasswordHashMigrationOnIncompatibleAlgorithm() {
|
|
|
|
PasswordEncryptor::register('crc32', 'PasswordEncryptor_PHPHash("crc32")');
|
|
|
|
|
|
|
|
$member = new Member();
|
|
|
|
$member->Email = 'test@test.com';
|
|
|
|
$member->PasswordEncryption = "crc32";
|
|
|
|
$member->Password = "mypassword";
|
|
|
|
$member->write();
|
|
|
|
|
|
|
|
$data = array(
|
|
|
|
'Email' => $member->Email,
|
|
|
|
'Password' => 'mypassword'
|
|
|
|
);
|
|
|
|
MemberAuthenticator::authenticate($data);
|
|
|
|
|
|
|
|
$member = DataObject::get_by_id('Member', $member->ID);
|
|
|
|
$this->assertEquals($member->PasswordEncryption, "crc32");
|
2010-02-23 05:05:34 +01:00
|
|
|
$result = $member->checkPassword('mypassword');
|
|
|
|
$this->assertTrue($result->valid());
|
2009-11-06 03:23:30 +01:00
|
|
|
}
|
|
|
|
}
|