2009-11-06 03:23:30 +01:00
|
|
|
<?php
|
|
|
|
/**
|
2012-04-12 08:02:46 +02:00
|
|
|
* @package framework
|
2009-11-06 03:23:30 +01:00
|
|
|
* @subpackage tests
|
|
|
|
*/
|
|
|
|
class MemberAuthenticatorTest extends SapphireTest {
|
2009-11-30 02:56:05 +01:00
|
|
|
|
|
|
|
protected $usesDatabase = true;
|
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function testLegacyPasswordHashMigrationUponLogin() {
|
2009-11-06 03:23:30 +01:00
|
|
|
$member = new Member();
|
2010-04-12 07:01:31 +02:00
|
|
|
|
|
|
|
$field=Member::get_unique_identifier_field();
|
|
|
|
|
2010-05-25 06:24:53 +02:00
|
|
|
$member->$field = 'test1@test.com';
|
2009-11-06 03:23:30 +01:00
|
|
|
$member->PasswordEncryption = "sha1";
|
|
|
|
$member->Password = "mypassword";
|
|
|
|
$member->write();
|
|
|
|
|
|
|
|
$data = array(
|
2010-04-12 07:01:31 +02:00
|
|
|
'Email' => $member->$field,
|
2009-11-06 03:23:30 +01:00
|
|
|
'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
|
|
|
}
|
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function testNoLegacyPasswordHashMigrationOnIncompatibleAlgorithm() {
|
2012-09-26 23:34:00 +02:00
|
|
|
Config::inst()->update('PasswordEncryptor', 'encryptors',
|
|
|
|
array('crc32'=>array('PasswordEncryptor_PHPHash'=>'crc32')));
|
2010-04-12 07:01:31 +02:00
|
|
|
$field=Member::get_unique_identifier_field();
|
|
|
|
|
2009-11-06 03:23:30 +01:00
|
|
|
$member = new Member();
|
2010-05-25 06:24:53 +02:00
|
|
|
$member->$field = 'test2@test.com';
|
2009-11-06 03:23:30 +01:00
|
|
|
$member->PasswordEncryption = "crc32";
|
|
|
|
$member->Password = "mypassword";
|
|
|
|
$member->write();
|
|
|
|
|
|
|
|
$data = array(
|
2010-04-12 07:01:31 +02:00
|
|
|
'Email' => $member->$field,
|
2009-11-06 03:23:30 +01:00
|
|
|
'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
|
|
|
}
|
2010-04-12 07:01:31 +02:00
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function testCustomIdentifierField(){
|
2010-04-12 07:01:31 +02:00
|
|
|
|
2010-04-12 07:01:48 +02:00
|
|
|
$origField = Member::get_unique_identifier_field();
|
2010-04-12 07:01:31 +02:00
|
|
|
Member::set_unique_identifier_field('Username');
|
2010-04-12 07:01:48 +02:00
|
|
|
|
2010-04-12 07:01:31 +02:00
|
|
|
$label=singleton('Member')->fieldLabel(Member::get_unique_identifier_field());
|
|
|
|
|
|
|
|
$this->assertEquals($label, 'Username');
|
|
|
|
|
2010-04-12 07:01:48 +02:00
|
|
|
Member::set_unique_identifier_field($origField);
|
2010-04-12 07:01:31 +02:00
|
|
|
}
|
2012-03-24 04:04:52 +01:00
|
|
|
}
|