public function TfaBasicTestCase::_testAppAndRecoverySetup in TFA Basic plugins 7
1 call to TfaBasicTestCase::_testAppAndRecoverySetup()
- TfaBasicTestCase::testTfaBasic in tests/tfa_basic.test
File
- tests/tfa_basic.test, line 62
- tfa_basic.test.
Drupal test cases for TFA basic plugins.
Class
- TfaBasicTestCase
- Tests the functionality of the TFA basic plugins.
Code
public function _testAppAndRecoverySetup() {
variable_set('tfa_enabled', FALSE);
$account = $this->web_user;
$this
->drupalLogin($account);
variable_set('tfa_enabled', TRUE);
variable_set('tfa_validate_plugin', 'tfa_basic_totp');
variable_set('tfa_fallback_plugins', array(
'tfa_basic_recovery_code',
));
$this
->drupalGet('user/' . $account->uid . '/security/tfa');
$this
->assertLink($this
->uiStrings('setup-app'));
$this
->drupalGet('user/' . $account->uid . '/security/tfa/app-setup');
$this
->assertText($this
->uiStrings('password-request'));
$edit = array(
'current_pass' => $this
->randomName(),
);
$this
->drupalPost(NULL, $edit, 'Confirm');
$this
->assertText($this
->uiStrings('pass-error'));
$edit = array(
'current_pass' => $account->pass_raw,
);
$this
->drupalPost(NULL, $edit, 'Confirm');
$this
->assertText($this
->uiStrings('app-step1'));
$this
->assertFieldById('edit-seed', '', 'Seed input appears');
$this
->assertFieldById('edit-code', '', 'Code input appears');
$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'];
$edit = array(
'code' => $this
->randomName(),
);
$this
->drupalPost(NULL, $edit, 'Verify and save');
$this
->assertText($this
->uiStrings('invalid-code-retry'));
$edit = array(
'code' => $this->ga
->getCode($this->seed),
);
$this
->drupalPost(NULL, $edit, 'Verify and save');
$this
->assertText($this
->uiStrings('set-recovery-codes'));
$result = $this
->xpath('//li');
while (list(, $node) = each($result)) {
$this->recoveryCodes[] = (string) $node;
}
$this
->drupalPost(NULL, array(), 'Save');
$this
->assertText($this
->uiStrings('setup-complete'));
$this
->drupalGet('user/logout');
$edit = array(
'name' => $account->name,
'pass' => $account->pass_raw,
);
$this
->drupalPost('user/login', $edit, 'Log in');
$url_parts = explode('/', $this->url);
$login_hash = array_pop($url_parts);
$edit = array(
'code' => $this
->randomName(),
);
$this
->drupalPost('system/tfa/' . $account->uid . '/' . $login_hash, $edit, 'Verify');
$this
->assertText($this
->uiStrings('invalid-code-retry'));
$edit = array(
'code' => $this->ga
->getCode($this->seed),
);
$this
->drupalPost('system/tfa/' . $account->uid . '/' . $login_hash, $edit, 'Verify');
$this
->assertText('My account');
$this
->drupalGet('user/logout');
$edit = array(
'name' => $account->name,
'pass' => $account->pass_raw,
);
$this
->drupalPost('user/login', $edit, 'Log in');
$url_parts = explode('/', $this->url);
$login_hash = array_pop($url_parts);
$this
->drupalPost('system/tfa/' . $account->uid . '/' . $login_hash, array(), $this
->uiStrings('fallback-button'));
$this
->assertText($this
->uiStrings('recovery-prompt'));
$edit = array(
'recover' => $this
->randomName(),
);
$this
->drupalPost('system/tfa/' . $account->uid . '/' . $login_hash, $edit, 'Verify');
$this
->assertText($this
->uiStrings('invalid-recovery-code'));
$edit = array(
'recover' => array_pop($this->recoveryCodes),
);
$this
->drupalPost('system/tfa/' . $account->uid . '/' . $login_hash, $edit, 'Verify');
$this
->assertText('My account');
}