mirror of
https://github.com/wallabag/wallabag.git
synced 2026-11-12 01:32:16 +01:00
Add the environment-first CAPTCHA switch, extend the FOS registration form through Symfony form inheritance, and render a dedicated public-registration challenge only when enabled. This is the first complete consumer of the CAPTCHA infrastructure: default registration remains unchanged, while the enabled flow proves a session-backed answer can create a user. The public session key is isolated so later administrator coverage cannot rotate this challenge.
110 lines
3.5 KiB
PHP
110 lines
3.5 KiB
PHP
<?php
|
|
|
|
namespace Wallabag\Tests\Functional\Controller;
|
|
|
|
use Doctrine\ORM\EntityManagerInterface;
|
|
use Wallabag\Entity\User;
|
|
use Wallabag\Tests\Functional\WallabagTestCase;
|
|
|
|
class SecurityControllerTest extends WallabagTestCase
|
|
{
|
|
public function testLoginWithEmail(): void
|
|
{
|
|
$this->logInAsUsingHttp('bigboss@wallabag.org');
|
|
$client = $this->getTestClient();
|
|
$client->followRedirects();
|
|
|
|
$crawler = $client->request('GET', '/config');
|
|
$this->assertStringContainsString('config.form_feed.description', $crawler->filter('body')->extract(['_text'])[0]);
|
|
}
|
|
|
|
public function testLoginWithout2Factor(): void
|
|
{
|
|
$this->logInAs('admin');
|
|
$client = $this->getTestClient();
|
|
$client->followRedirects();
|
|
|
|
$crawler = $client->request('GET', '/config');
|
|
$this->assertStringContainsString('config.form_feed.description', $crawler->filter('body')->extract(['_text'])[0]);
|
|
}
|
|
|
|
public function testLoginWith2FactorEmail(): void
|
|
{
|
|
$client = $this->getTestClient();
|
|
|
|
$client->followRedirects();
|
|
|
|
$em = $client->getContainer()->get(EntityManagerInterface::class);
|
|
$user = $em
|
|
->getRepository(User::class)
|
|
->findOneByUsername('admin');
|
|
$user->setEmailTwoFactor(true);
|
|
$em->persist($user);
|
|
$em->flush();
|
|
|
|
$this->logInAsUsingHttp('admin');
|
|
$crawler = $client->request('GET', '/config');
|
|
$this->assertStringContainsString('trusted', $crawler->filter('body')->extract(['_text'])[0]);
|
|
|
|
// restore user
|
|
$user = $em
|
|
->getRepository(User::class)
|
|
->findOneByUsername('admin');
|
|
$user->setEmailTwoFactor(false);
|
|
$em->persist($user);
|
|
$em->flush();
|
|
}
|
|
|
|
public function testLoginWith2FactorGoogle(): void
|
|
{
|
|
$client = $this->getTestClient();
|
|
|
|
$client->followRedirects();
|
|
|
|
$em = $client->getContainer()->get(EntityManagerInterface::class);
|
|
$user = $em
|
|
->getRepository(User::class)
|
|
->findOneByUsername('admin');
|
|
$user->setGoogleAuthenticatorSecret('26LDIHYGHNELOQEM');
|
|
$user->setGoogleAuthenticator(true);
|
|
$em->persist($user);
|
|
$em->flush();
|
|
|
|
$this->logInAsUsingHttp('admin');
|
|
$crawler = $client->request('GET', '/config');
|
|
$this->assertStringContainsString('trusted', $crawler->filter('body')->extract(['_text'])[0]);
|
|
|
|
// restore user
|
|
$user = $em
|
|
->getRepository(User::class)
|
|
->findOneByUsername('admin');
|
|
$user->setGoogleAuthenticatorSecret(null);
|
|
$user->setGoogleAuthenticator(false);
|
|
$em->persist($user);
|
|
$em->flush();
|
|
}
|
|
|
|
public function testEnabledRegistration(): void
|
|
{
|
|
$client = $this->getTestClient();
|
|
$registrationEnabled = filter_var($_ENV['WALLABAG_REGISTRATION_ENABLED'] ?? '0', \FILTER_VALIDATE_BOOL);
|
|
|
|
if (!$registrationEnabled) {
|
|
$this->markTestSkipped('fosuser_registration is not enabled.');
|
|
}
|
|
|
|
$client->followRedirects();
|
|
$client->request('GET', '/register');
|
|
$this->assertStringContainsString('registration.submit', $client->getResponse()->getContent());
|
|
}
|
|
|
|
public function testRegistrationDoesNotRenderCaptchaWhenDisabled(): void
|
|
{
|
|
$client = $this->getTestClient();
|
|
|
|
$crawler = $client->request('GET', '/register/');
|
|
|
|
$this->assertCount(0, $crawler->filter('input[name="fos_user_registration[captcha]"]'));
|
|
}
|
|
}
|