Add test coverage for auth failure after TempID expires.

This commit is contained in:
Garion Herman 2017-05-22 13:54:57 +12:00 committed by Daniel Hensby
parent 4ca96eae48
commit 6ad19495a2
No known key found for this signature in database
GPG Key ID: B00D1E9767F0B06E

View File

@ -137,6 +137,44 @@ class MemberAuthenticatorTest extends SapphireTest {
$this->assertEquals('bad', $form->MessageType());
}
public function testExpiredTempID()
{
//store original default admin as we'll need to clear it
$adminUser = Security::default_admin_username();
$adminPass = Security::default_admin_password();
// Make member with expired TempID
$member = new Member();
$member->Email = 'test1@test.com';
$member->PasswordEncryption = "sha1";
$member->Password = "mypassword";
$member->TempIDExpired = '2016-05-22 00:00:00';
$member->write();
$member->logIn(true);
$tempID = $member->TempIDHash;
// Make form
$controller = new Security();
$form = new Form($controller, 'Form', new FieldList(), new FieldList());
SS_Datetime::set_mock_now('2016-05-29 00:00:00');
Security::clear_default_admin();
$this->assertNotEmpty($tempID);
$this->assertFalse(Security::has_default_admin());
$result = MemberAuthenticator::authenticate(array(
'tempid' => $tempID,
'Password' => 'notmypassword'
), $form);
$this->assertEmpty($result);
if (!is_null($adminUser) || !is_null($adminPass)) {
Security::setDefaultAdmin($adminUser, $adminPass);
}
}
/**
* Test that the default admin can be authenticated
*/