public function TfaBasicTestCase::testRequired in TFA Basic plugins 7
File
- tests/
tfa_basic.test, line 278 - tfa_basic.test. Drupal test cases for TFA basic plugins.
Class
- TfaBasicTestCase
- Tests the functionality of the TFA basic plugins.
Code
public function testRequired() {
variable_set('tfa_enabled', TRUE);
variable_set('tfa_validate_plugin', 'tfa_basic_totp');
$account = $this
->drupalCreateUser(array(
'access content',
'setup own tfa',
));
$edit = array(
'name' => $account->name,
'pass' => $account->pass_raw,
);
$this
->drupalPost('user/login', $edit, 'Log in');
// Set up application.
$this
->drupalGet('user/' . $account->uid . '/security/tfa/app-setup');
$pass_form = array(
'current_pass' => $account->pass_raw,
);
$this
->drupalPost(NULL, $pass_form, 'Confirm');
$result = $this
->xpath('//input[@name="seed"]');
if (empty($result)) {
$this
->fail('Unable to extract seed from page. Aborting test.');
return;
}
$element = $result[0];
$this->seed = (string) $element['value'];
// Submit valid code.
$code_form = array(
'code' => $this->ga
->getCode($this->seed),
);
$this
->drupalPost(NULL, $code_form, 'Verify and save');
// Set required for authenticated and confirm messages.
variable_set('tfa_basic_roles_require', array(
DRUPAL_AUTHENTICATED_RID => DRUPAL_AUTHENTICATED_RID,
));
$this
->drupalGet('user/' . $account->uid . '/security/tfa/disable');
$this
->assertText($this
->uiStrings('disable-required'));
// Disable TFA.
$this
->drupalPost(NULL, $pass_form, 'Disable');
$this
->drupalGet('user/logout');
// Confirm cannot log in.
$this
->drupalPost('user/login', $edit, 'Log in');
$this
->assertNoLink('Log out', 'Not authenticated');
$this
->assertText($this
->uiStrings('required'), 'Required text shows');
}