From 2819959f383f288f0af4edd6f5ba32ff824369dc Mon Sep 17 00:00:00 2001 From: Antonio Carlos Ribeiro Date: Thu, 17 Oct 2019 18:18:27 -0300 Subject: [PATCH] Add google2fa test --- tests/integration/LoginTest.php | 27 +++++++++++++++++++++++++++ tests/integration/RoutesTest.php | 1 + tests/integration/TestCase.php | 1 + 3 files changed, 29 insertions(+) diff --git a/tests/integration/LoginTest.php b/tests/integration/LoginTest.php index 82dba0b96..50bf922f7 100644 --- a/tests/integration/LoginTest.php +++ b/tests/integration/LoginTest.php @@ -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() @@ -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); + } } diff --git a/tests/integration/RoutesTest.php b/tests/integration/RoutesTest.php index a875b9eaa..121c2e8f6 100644 --- a/tests/integration/RoutesTest.php +++ b/tests/integration/RoutesTest.php @@ -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', diff --git a/tests/integration/TestCase.php b/tests/integration/TestCase.php index f6d21a9b4..26920a82e 100644 --- a/tests/integration/TestCase.php +++ b/tests/integration/TestCase.php @@ -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); } /**