silverstripe-framework/tests/security/MemberAuthenticatorTest.php

67 lines
1.8 KiB
PHP
Raw Normal View History

<?php
/**
* @package framework
* @subpackage tests
*/
class MemberAuthenticatorTest extends SapphireTest {
2014-08-15 08:53:05 +02:00
protected $usesDatabase = true;
2014-08-15 08:53:05 +02:00
public function testLegacyPasswordHashMigrationUponLogin() {
$member = new Member();
2014-08-15 08:53:05 +02:00
$field=Member::config()->unique_identifier_field;
2014-08-15 08:53:05 +02:00
$member->$field = 'test1@test.com';
$member->PasswordEncryption = "sha1";
$member->Password = "mypassword";
$member->write();
2014-08-15 08:53:05 +02:00
$data = array(
'Email' => $member->$field,
'Password' => 'mypassword'
);
MemberAuthenticator::authenticate($data);
2014-08-15 08:53:05 +02:00
$member = DataObject::get_by_id('Member', $member->ID);
$this->assertEquals($member->PasswordEncryption, "sha1_v2.4");
$result = $member->checkPassword('mypassword');
$this->assertTrue($result->valid());
}
2014-08-15 08:53:05 +02:00
public function testNoLegacyPasswordHashMigrationOnIncompatibleAlgorithm() {
Config::inst()->update('PasswordEncryptor', 'encryptors',
array('crc32'=>array('PasswordEncryptor_PHPHash'=>'crc32')));
$field=Member::config()->unique_identifier_field;
2014-08-15 08:53:05 +02:00
$member = new Member();
$member->$field = 'test2@test.com';
$member->PasswordEncryption = "crc32";
$member->Password = "mypassword";
$member->write();
2014-08-15 08:53:05 +02:00
$data = array(
'Email' => $member->$field,
'Password' => 'mypassword'
);
MemberAuthenticator::authenticate($data);
2014-08-15 08:53:05 +02:00
$member = DataObject::get_by_id('Member', $member->ID);
$this->assertEquals($member->PasswordEncryption, "crc32");
$result = $member->checkPassword('mypassword');
$this->assertTrue($result->valid());
}
2014-08-15 08:53:05 +02:00
public function testCustomIdentifierField(){
2014-08-15 08:53:05 +02:00
$origField = Member::config()->unique_identifier_field;
Member::config()->unique_identifier_field = 'Username';
$label=singleton('Member')->fieldLabel(Member::config()->unique_identifier_field);
2014-08-15 08:53:05 +02:00
$this->assertEquals($label, 'Username');
2014-08-15 08:53:05 +02:00
Member::config()->unique_identifier_field = $origField;
}
}