Loading tests/src/Functional/TfaLoginTest.php +10 −6 Original line number Diff line number Diff line Loading @@ -49,9 +49,10 @@ class TfaLoginTest extends TfaTestBase { $edit = [ 'tfa_required_roles[' . $web_user_roles[0] . ']' => TRUE, ]; $this->drupalPostForm('admin/config/people/tfa', $edit, 'Save configuration'); $this->drupalGet('admin/config/people/tfa'); $this->submitForm($edit, 'Save configuration'); $assert_session->statusCodeEquals(200); $this->assertText('The configuration options have been saved.'); $this->assertSession()->pageTextContains('The configuration options have been saved.'); // Check that tfa is presented. $this->drupalLogout(); Loading @@ -59,7 +60,8 @@ class TfaLoginTest extends TfaTestBase { 'name' => $this->webUser->getAccountName(), 'pass' => $this->webUser->passRaw, ]; $this->drupalPostForm('user/login', $edit, 'Log in'); $this->drupalGet('user/login'); $this->submitForm($edit, 'Log in'); $assert_session->statusCodeEquals(200); $assert_session->addressMatches('/\/tfa\/' . $this->webUser->id() . '/'); Loading @@ -73,9 +75,10 @@ class TfaLoginTest extends TfaTestBase { $edit['tfa_required_roles[' . $role_id . ']'] = FALSE; } $edit['tfa_required_roles[authenticated]'] = FALSE; $this->drupalPostForm('admin/config/people/tfa', $edit, 'Save configuration'); $this->drupalGet('admin/config/people/tfa'); $this->submitForm($edit, 'Save configuration'); $assert_session->statusCodeEquals(200); $this->assertText('The configuration options have been saved.'); $this->assertSession()->pageTextContains('The configuration options have been saved.'); // Enable tfa for a single user. $this->drupalLogin($this->webUser); $this->drupalGet('user/' . $this->webUser->id() . '/security/tfa'); Loading Loading @@ -104,7 +107,8 @@ class TfaLoginTest extends TfaTestBase { 'name' => $this->webUser->getAccountName(), 'pass' => $this->webUser->passRaw, ]; $this->drupalPostForm('user/login', $edit, 'Log in'); $this->drupalGet('user/login'); $this->submitForm($edit, 'Log in'); $assert_session->statusCodeEquals(200); $assert_session->addressMatches('/\/tfa\/' . $this->webUser->id() . '/'); } Loading tests/src/Functional/TfaRecoveryCodePluginTest.php +6 −4 Original line number Diff line number Diff line Loading @@ -125,7 +125,7 @@ class TfaRecoveryCodePluginTest extends TfaTestBase { // Make sure codes were saved to the account. $codes = $this->validationPlugin->getCodes(); $assert->assert(!empty($codes), 'No codes saved to the account data.'); $this->assertTrue(!empty($codes), 'No codes saved to the account data.'); // Now the user should be able to see their existing codes. Let's test that. $assert->linkExists('Show codes'); Loading Loading @@ -155,7 +155,8 @@ class TfaRecoveryCodePluginTest extends TfaTestBase { 'name' => $this->userAccount->getAccountName(), 'pass' => $this->userAccount->passRaw, ]; $this->drupalPostForm('user/login', $edit, 'Log in'); $this->drupalGet('user/login'); $this->submitForm($edit, 'Log in'); $assert->statusCodeEquals(200); $assert->pageTextContains('Enter one of your recovery codes'); Loading @@ -170,7 +171,7 @@ class TfaRecoveryCodePluginTest extends TfaTestBase { $this->submitForm($edit, 'Verify'); $assert->statusCodeEquals(200); $assert->pageTextContains($this->userAccount->getDisplayName()); $assert->assert($this->userAccount->isAuthenticated(), 'User is logged in.'); $this->assertTrue($this->userAccount->isAuthenticated(), 'User is logged in.'); // Try replay attack with a valid code that has already been used. $this->drupalLogout(); Loading @@ -178,7 +179,8 @@ class TfaRecoveryCodePluginTest extends TfaTestBase { 'name' => $this->userAccount->getAccountName(), 'pass' => $this->userAccount->passRaw, ]; $this->drupalPostForm('user/login', $edit, 'Log in'); $this->drupalGet('user/login'); $this->submitForm($edit, 'Log in'); $assert->statusCodeEquals(200); $assert->pageTextContains('Enter one of your recovery codes'); Loading tests/src/Functional/TfaTestBase.php +1 −1 Original line number Diff line number Diff line Loading @@ -115,7 +115,7 @@ abstract class TfaTestBase extends BrowserTestBase { $select_field_id = 'edit-tfa-validate'; $option_field = $assert->optionExists($select_field_id, $validation_plugin_id); $result = $option_field->hasAttribute('selected'); $assert->assert($result, "Option {$validation_plugin_id} for field {$select_field_id} is selected."); $this->assertTrue($result, "Option {$validation_plugin_id} for field {$select_field_id} is selected."); } } tests/src/Unit/Plugin/TfaValidation/TfaRecoveryCodeTest.php +2 −0 Original line number Diff line number Diff line Loading @@ -2,6 +2,7 @@ namespace Drupal\Tests\tfa\Unit\Plugin\TfaValidation; use Prophecy\PhpUnit\ProphecyTrait; use Drupal\Core\Config\ConfigFactoryInterface; use Drupal\Core\Config\ImmutableConfig; use Drupal\Core\DependencyInjection\ContainerBuilder; Loading @@ -19,6 +20,7 @@ use Drupal\user\UserDataInterface; * @group tfa */ class TfaRecoveryCodeTest extends UnitTestCase { use ProphecyTrait; /** * Mocked user data service. Loading tests/src/Unit/TfaContextTest.php +2 −0 Original line number Diff line number Diff line Loading @@ -2,6 +2,7 @@ namespace Drupal\Tests\tfa\Unit; use Prophecy\PhpUnit\ProphecyTrait; use Drupal\Core\Config\ConfigFactoryInterface; use Drupal\Core\Config\ImmutableConfig; use Drupal\Tests\UnitTestCase; Loading @@ -19,6 +20,7 @@ use Symfony\Component\HttpFoundation\Request; * @group tfa */ class TfaContextTest extends UnitTestCase { use ProphecyTrait; /** * Validation plugin manager. Loading Loading
tests/src/Functional/TfaLoginTest.php +10 −6 Original line number Diff line number Diff line Loading @@ -49,9 +49,10 @@ class TfaLoginTest extends TfaTestBase { $edit = [ 'tfa_required_roles[' . $web_user_roles[0] . ']' => TRUE, ]; $this->drupalPostForm('admin/config/people/tfa', $edit, 'Save configuration'); $this->drupalGet('admin/config/people/tfa'); $this->submitForm($edit, 'Save configuration'); $assert_session->statusCodeEquals(200); $this->assertText('The configuration options have been saved.'); $this->assertSession()->pageTextContains('The configuration options have been saved.'); // Check that tfa is presented. $this->drupalLogout(); Loading @@ -59,7 +60,8 @@ class TfaLoginTest extends TfaTestBase { 'name' => $this->webUser->getAccountName(), 'pass' => $this->webUser->passRaw, ]; $this->drupalPostForm('user/login', $edit, 'Log in'); $this->drupalGet('user/login'); $this->submitForm($edit, 'Log in'); $assert_session->statusCodeEquals(200); $assert_session->addressMatches('/\/tfa\/' . $this->webUser->id() . '/'); Loading @@ -73,9 +75,10 @@ class TfaLoginTest extends TfaTestBase { $edit['tfa_required_roles[' . $role_id . ']'] = FALSE; } $edit['tfa_required_roles[authenticated]'] = FALSE; $this->drupalPostForm('admin/config/people/tfa', $edit, 'Save configuration'); $this->drupalGet('admin/config/people/tfa'); $this->submitForm($edit, 'Save configuration'); $assert_session->statusCodeEquals(200); $this->assertText('The configuration options have been saved.'); $this->assertSession()->pageTextContains('The configuration options have been saved.'); // Enable tfa for a single user. $this->drupalLogin($this->webUser); $this->drupalGet('user/' . $this->webUser->id() . '/security/tfa'); Loading Loading @@ -104,7 +107,8 @@ class TfaLoginTest extends TfaTestBase { 'name' => $this->webUser->getAccountName(), 'pass' => $this->webUser->passRaw, ]; $this->drupalPostForm('user/login', $edit, 'Log in'); $this->drupalGet('user/login'); $this->submitForm($edit, 'Log in'); $assert_session->statusCodeEquals(200); $assert_session->addressMatches('/\/tfa\/' . $this->webUser->id() . '/'); } Loading
tests/src/Functional/TfaRecoveryCodePluginTest.php +6 −4 Original line number Diff line number Diff line Loading @@ -125,7 +125,7 @@ class TfaRecoveryCodePluginTest extends TfaTestBase { // Make sure codes were saved to the account. $codes = $this->validationPlugin->getCodes(); $assert->assert(!empty($codes), 'No codes saved to the account data.'); $this->assertTrue(!empty($codes), 'No codes saved to the account data.'); // Now the user should be able to see their existing codes. Let's test that. $assert->linkExists('Show codes'); Loading Loading @@ -155,7 +155,8 @@ class TfaRecoveryCodePluginTest extends TfaTestBase { 'name' => $this->userAccount->getAccountName(), 'pass' => $this->userAccount->passRaw, ]; $this->drupalPostForm('user/login', $edit, 'Log in'); $this->drupalGet('user/login'); $this->submitForm($edit, 'Log in'); $assert->statusCodeEquals(200); $assert->pageTextContains('Enter one of your recovery codes'); Loading @@ -170,7 +171,7 @@ class TfaRecoveryCodePluginTest extends TfaTestBase { $this->submitForm($edit, 'Verify'); $assert->statusCodeEquals(200); $assert->pageTextContains($this->userAccount->getDisplayName()); $assert->assert($this->userAccount->isAuthenticated(), 'User is logged in.'); $this->assertTrue($this->userAccount->isAuthenticated(), 'User is logged in.'); // Try replay attack with a valid code that has already been used. $this->drupalLogout(); Loading @@ -178,7 +179,8 @@ class TfaRecoveryCodePluginTest extends TfaTestBase { 'name' => $this->userAccount->getAccountName(), 'pass' => $this->userAccount->passRaw, ]; $this->drupalPostForm('user/login', $edit, 'Log in'); $this->drupalGet('user/login'); $this->submitForm($edit, 'Log in'); $assert->statusCodeEquals(200); $assert->pageTextContains('Enter one of your recovery codes'); Loading
tests/src/Functional/TfaTestBase.php +1 −1 Original line number Diff line number Diff line Loading @@ -115,7 +115,7 @@ abstract class TfaTestBase extends BrowserTestBase { $select_field_id = 'edit-tfa-validate'; $option_field = $assert->optionExists($select_field_id, $validation_plugin_id); $result = $option_field->hasAttribute('selected'); $assert->assert($result, "Option {$validation_plugin_id} for field {$select_field_id} is selected."); $this->assertTrue($result, "Option {$validation_plugin_id} for field {$select_field_id} is selected."); } }
tests/src/Unit/Plugin/TfaValidation/TfaRecoveryCodeTest.php +2 −0 Original line number Diff line number Diff line Loading @@ -2,6 +2,7 @@ namespace Drupal\Tests\tfa\Unit\Plugin\TfaValidation; use Prophecy\PhpUnit\ProphecyTrait; use Drupal\Core\Config\ConfigFactoryInterface; use Drupal\Core\Config\ImmutableConfig; use Drupal\Core\DependencyInjection\ContainerBuilder; Loading @@ -19,6 +20,7 @@ use Drupal\user\UserDataInterface; * @group tfa */ class TfaRecoveryCodeTest extends UnitTestCase { use ProphecyTrait; /** * Mocked user data service. Loading
tests/src/Unit/TfaContextTest.php +2 −0 Original line number Diff line number Diff line Loading @@ -2,6 +2,7 @@ namespace Drupal\Tests\tfa\Unit; use Prophecy\PhpUnit\ProphecyTrait; use Drupal\Core\Config\ConfigFactoryInterface; use Drupal\Core\Config\ImmutableConfig; use Drupal\Tests\UnitTestCase; Loading @@ -19,6 +20,7 @@ use Symfony\Component\HttpFoundation\Request; * @group tfa */ class TfaContextTest extends UnitTestCase { use ProphecyTrait; /** * Validation plugin manager. Loading