Skip to content

Commit

Permalink
Add google2fa test
Browse files Browse the repository at this point in the history
  • Loading branch information
antonioribeiro authored and ifox committed Nov 18, 2019
1 parent 094a9fa commit 2819959
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
27 changes: 27 additions & 0 deletions tests/integration/LoginTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

namespace A17\Twill\Tests\Integration;

use A17\Twill\Models\User;
use PragmaRX\Google2FA\Google2FA;

class LoginTest extends TestCase
{
public function testCanRedirectToLogin()
Expand Down Expand Up @@ -43,4 +46,28 @@ public function testCanLogout()
$crawler->getContent()
);
}

public function testGoogle2FA()
{
$user = User::where('email', $this->getSuperAdmin()->email)->first();

$user->generate2faSecretKey();

$user->update(['google_2fa_enabled' => true]);

$crawler = $this->login();

$this->assertStringContainsString(
'One-time password',
$crawler->getContent()
);

$crawler = $this->followingRedirects()->call('POST', '/twill/login', [
'verify-code' => (new Google2FA())->getCurrentOtp(
$user->google_2fa_secret
),
]);

$crawler->assertStatus(200);
}
}
1 change: 1 addition & 0 deletions tests/integration/RoutesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class RoutesTest extends TestCase
'twill/file-library/files/{file}',
'twill/file-library/sign-s3-upload',
'twill/login',
'twill/login-2fa',
'twill/logout',
'twill/media-library/medias',
'twill/media-library/medias/bulk-delete',
Expand Down
1 change: 1 addition & 0 deletions tests/integration/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ private function configTwill($app)
$app['config']->set('twill.admin_app_url', '');
$app['config']->set('twill.admin_app_path', 'twill');
$app['config']->set('twill.auth_login_redirect_path', '/twill');
$app['config']->set('twill.enabled.users-2fa', true);
}

/**
Expand Down

0 comments on commit 2819959

Please sign in to comment.