Skip to content

Commit

Permalink
Merge branch 'master' of github.com:humhub/humhub-modules-2fa
Browse files Browse the repository at this point in the history
  • Loading branch information
luke- committed Feb 9, 2021
2 parents 7375d22 + e7fabfd commit 5cd08b6
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 5 deletions.
28 changes: 28 additions & 0 deletions tests/codeception/_pages/TwofaAuthPage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace tests\codeception\_pages;

use tests\codeception\_support\BasePage;

/**
* Represents 2FA verifying code page
* @property \AcceptanceTester|\FunctionalTester $actor
*/
class TwofaAuthPage extends BasePage
{

public $route = 'twofa/check';

/**
* @param string $code
*/
public function verify($code)
{
if(method_exists($this->actor, 'waitForText')) {
$this->actor->waitForText('Two-factor authentication');
}
$this->actor->fillField('CheckCode[code]', $code);
$this->actor->click('#verify-button');
}

}
15 changes: 14 additions & 1 deletion tests/codeception/functional/TwofaCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,25 @@

namespace twofa\functional;

use tests\codeception\_pages\LoginPage;
use tests\codeception\_pages\TwofaAuthPage;
use twofa\FunctionalTester;

class TwofaCest
{

public function testSendVerifyingCode(FunctionalTester $I)
public function testCheckWrongVerifyingCode(FunctionalTester $I)
{
$I->wantTo('check wrong verifying code');
$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');

$twofaAuthPage = TwofaAuthPage::openBy($I);
$twofaAuthPage->verify('test code');
$I->expectTo('see wrong verifying code');
$I->see('Verifying code is not valid!');
}
}
9 changes: 6 additions & 3 deletions tests/codeception/unit/TwofaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,12 @@ public function testVerifyCode()
$this->assertTrue(TwofaHelper::enableVerifying());
$this->assertTrue(TwofaHelper::isVerifyingRequired());
$this->assertFalse(TwofaHelper::isValidCode('test'));
}

//$this->becomeUser('User1');
//$this->assertFalse(TwofaHelper::isVerifyingRequired());
//$this->assertFalse(TwofaHelper::isValidCode('test'));
public function testDisableVerifying()
{
$this->becomeUser('Admin');
$this->assertTrue(TwofaHelper::disableVerifying());
$this->assertFalse(TwofaHelper::isVerifyingRequired());
}
}
2 changes: 1 addition & 1 deletion views/check/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@

<br/>

<?= Html::submitButton(Yii::t('TwofaModule.base', 'Verify'), ['class' => 'btn btn-primary', 'data-ui-loader' => ""]); ?>
<?= Html::submitButton(Yii::t('TwofaModule.base', 'Verify'), ['id' => 'verify-button', 'class' => 'btn btn-primary', 'data-ui-loader' => ""]); ?>

<?php ActiveForm::end(); ?>
<?= Html::a(Yii::t('TwofaModule.base', 'Log out'), ['/user/auth/logout'], ['class' => 'pull-right', 'data-pjax' => false]) ?>
Expand Down

0 comments on commit 5cd08b6

Please sign in to comment.