Skip to content

Commit

Permalink
Merge pull request #13 from humhub/enh/add-tests-email-code
Browse files Browse the repository at this point in the history
Test verifying code from email
  • Loading branch information
luke- authored Feb 9, 2021
2 parents 5cd08b6 + 7c35e59 commit 5d5e94b
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
12 changes: 12 additions & 0 deletions tests/codeception/_support/FunctionalTester.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

namespace twofa;

use humhub\modules\twofa\helpers\TwofaHelper;

/**
* Inherited Methods
* @method void wantToTest($text)
Expand All @@ -29,4 +31,14 @@ class FunctionalTester extends \FunctionalTester
/**
* Define custom actions here
*/

/**
* @return string
*/
public function fetchCodeFromLastEmail()
{
return preg_match('/Code: ([' . preg_quote(TwofaHelper::CODE_CHARS) . ']+)/', $this->grapLastEmailText(), $codeMatch)
? $codeMatch[1]
: '';
}
}
23 changes: 23 additions & 0 deletions tests/codeception/functional/TwofaCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,27 @@ public function testCheckWrongVerifyingCode(FunctionalTester $I)
$I->expectTo('see wrong verifying code');
$I->see('Verifying code is not valid!');
}

public function testVerifyCodeFromEmail(FunctionalTester $I)
{
$I->wantTo('verify code from email');
$loginPage = LoginPage::openBy($I);
$I->amGoingTo('try to login with admin credentials');
$loginPage->login('Admin', 'test');
$I->expectTo('See Two Factor Auth');
$I->see('Two-factor authentication');

$adminMail = $I->grabLastSentEmail();
if(!array_key_exists('admin@example.com', $adminMail->getTo())) {
$I->see('admin@example.com not in mails');
}

$I->assertEqualsLastEmailSubject('Your login verification code');
$code = $I->fetchCodeFromLastEmail();

$twofaAuthPage = TwofaAuthPage::openBy($I);
$twofaAuthPage->verify($code);
$I->expectTo('see dashboard');
$I->see('Dashboard');
}
}

0 comments on commit 5d5e94b

Please sign in to comment.