From aec8e2605829269ca3edcdc7f3f381a0f4d53296 Mon Sep 17 00:00:00 2001 From: Yassine Guedidi Date: Sat, 23 Nov 2024 11:12:46 +0100 Subject: [PATCH 1/5] Remove unused property in LoginFormAuthenticator --- src/SiteConfig/Authenticator/LoginFormAuthenticator.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/SiteConfig/Authenticator/LoginFormAuthenticator.php b/src/SiteConfig/Authenticator/LoginFormAuthenticator.php index 3292e79c6..8714f1e2a 100644 --- a/src/SiteConfig/Authenticator/LoginFormAuthenticator.php +++ b/src/SiteConfig/Authenticator/LoginFormAuthenticator.php @@ -11,9 +11,6 @@ use Wallabag\SiteConfig\SiteConfig; class LoginFormAuthenticator implements Authenticator { - /** @var \GuzzleHttp\Client */ - protected $guzzle; - /** @var SiteConfig */ private $siteConfig; From 81d269dec1c0c8739c76bcdcde626f9151dcaef9 Mon Sep 17 00:00:00 2001 From: Yassine Guedidi Date: Sat, 23 Nov 2024 11:27:18 +0100 Subject: [PATCH 2/5] Move site config from property to parameter in LoginFormAuthenticator --- src/Guzzle/AuthenticatorSubscriber.php | 12 +++---- .../Authenticator/Authenticator.php | 7 +++-- src/SiteConfig/Authenticator/Factory.php | 4 +-- .../Authenticator/LoginFormAuthenticator.php | 31 +++++++------------ .../LoginFormAuthenticatorTest.php | 24 +++++++------- 5 files changed, 35 insertions(+), 43 deletions(-) diff --git a/src/Guzzle/AuthenticatorSubscriber.php b/src/Guzzle/AuthenticatorSubscriber.php index bbcb31e24..ff4e9acc6 100644 --- a/src/Guzzle/AuthenticatorSubscriber.php +++ b/src/Guzzle/AuthenticatorSubscriber.php @@ -62,14 +62,14 @@ class AuthenticatorSubscriber implements SubscriberInterface, LoggerAwareInterfa } $client = $event->getClient(); - $authenticator = $this->authenticatorFactory->buildFromSiteConfig($config); + $authenticator = $this->authenticatorFactory->buildFromSiteConfig(); - if (!$authenticator->isLoggedIn($client)) { + if (!$authenticator->isLoggedIn($config, $client)) { $this->logger->debug('loginIfRequired> user is not logged in, attach authenticator'); $emitter = $client->getEmitter(); $emitter->detach($this); - $authenticator->login($client); + $authenticator->login($config, $client); $emitter->attach($this); } } @@ -94,8 +94,8 @@ class AuthenticatorSubscriber implements SubscriberInterface, LoggerAwareInterfa return; } - $authenticator = $this->authenticatorFactory->buildFromSiteConfig($config); - $isLoginRequired = $authenticator->isLoginRequired($body); + $authenticator = $this->authenticatorFactory->buildFromSiteConfig(); + $isLoginRequired = $authenticator->isLoginRequired($config, $body); $this->logger->debug('loginIfRequested> retry #' . $this->retries . ' with login ' . ($isLoginRequired ? '' : 'not ') . 'required'); @@ -104,7 +104,7 @@ class AuthenticatorSubscriber implements SubscriberInterface, LoggerAwareInterfa $emitter = $client->getEmitter(); $emitter->detach($this); - $authenticator->login($client); + $authenticator->login($config, $client); $emitter->attach($this); $event->retry(); diff --git a/src/SiteConfig/Authenticator/Authenticator.php b/src/SiteConfig/Authenticator/Authenticator.php index bb919a348..9623e39ab 100644 --- a/src/SiteConfig/Authenticator/Authenticator.php +++ b/src/SiteConfig/Authenticator/Authenticator.php @@ -3,6 +3,7 @@ namespace Wallabag\SiteConfig\Authenticator; use GuzzleHttp\ClientInterface; +use Wallabag\SiteConfig\SiteConfig; interface Authenticator { @@ -11,14 +12,14 @@ interface Authenticator * * @return self */ - public function login(ClientInterface $guzzle); + public function login(SiteConfig $siteConfig, ClientInterface $guzzle); /** * Checks if we are logged into the site, but without calling the server (e.g. do we have a Cookie). * * @return bool */ - public function isLoggedIn(ClientInterface $guzzle); + public function isLoggedIn(SiteConfig $siteConfig, ClientInterface $guzzle); /** * Checks from the HTML of a page if authentication is requested by a grabbed page. @@ -27,5 +28,5 @@ interface Authenticator * * @return bool */ - public function isLoginRequired($html); + public function isLoginRequired(SiteConfig $siteConfig, $html); } diff --git a/src/SiteConfig/Authenticator/Factory.php b/src/SiteConfig/Authenticator/Factory.php index 408690128..cf4267768 100644 --- a/src/SiteConfig/Authenticator/Factory.php +++ b/src/SiteConfig/Authenticator/Factory.php @@ -14,8 +14,8 @@ class Factory * * @throw \OutOfRangeException if there are no credentials for this host */ - public function buildFromSiteConfig(SiteConfig $siteConfig) + public function buildFromSiteConfig() { - return new LoginFormAuthenticator($siteConfig); + return new LoginFormAuthenticator(); } } diff --git a/src/SiteConfig/Authenticator/LoginFormAuthenticator.php b/src/SiteConfig/Authenticator/LoginFormAuthenticator.php index 8714f1e2a..811f98fdd 100644 --- a/src/SiteConfig/Authenticator/LoginFormAuthenticator.php +++ b/src/SiteConfig/Authenticator/LoginFormAuthenticator.php @@ -11,37 +11,28 @@ use Wallabag\SiteConfig\SiteConfig; class LoginFormAuthenticator implements Authenticator { - /** @var SiteConfig */ - private $siteConfig; - - public function __construct(SiteConfig $siteConfig) - { - // @todo OptionResolver - $this->siteConfig = $siteConfig; - } - - public function login(ClientInterface $guzzle) + public function login(SiteConfig $siteConfig, ClientInterface $guzzle) { $postFields = [ - $this->siteConfig->getUsernameField() => $this->siteConfig->getUsername(), - $this->siteConfig->getPasswordField() => $this->siteConfig->getPassword(), + $siteConfig->getUsernameField() => $siteConfig->getUsername(), + $siteConfig->getPasswordField() => $siteConfig->getPassword(), ] + $this->getExtraFields($guzzle); $guzzle->post( - $this->siteConfig->getLoginUri(), + $siteConfig->getLoginUri(), ['body' => $postFields, 'allow_redirects' => true, 'verify' => false] ); return $this; } - public function isLoggedIn(ClientInterface $guzzle) + public function isLoggedIn(SiteConfig $siteConfig, ClientInterface $guzzle) { if (($cookieJar = $guzzle->getDefaultOption('cookies')) instanceof CookieJar) { /** @var \GuzzleHttp\Cookie\SetCookie $cookie */ foreach ($cookieJar as $cookie) { // check required cookies - if ($cookie->getDomain() === $this->siteConfig->getHost()) { + if ($cookie->getDomain() === $siteConfig->getHost()) { return true; } } @@ -50,13 +41,13 @@ class LoginFormAuthenticator implements Authenticator return false; } - public function isLoginRequired($html) + public function isLoginRequired(SiteConfig $siteConfig, $html) { // need to check for the login dom element ($options['not_logged_in_xpath']) in the HTML try { $crawler = new Crawler((string) $html); - $loggedIn = $crawler->evaluate((string) $this->siteConfig->getNotLoggedInXpath()); + $loggedIn = $crawler->evaluate((string) $siteConfig->getNotLoggedInXpath()); } catch (\Throwable $e) { return false; } @@ -70,17 +61,17 @@ class LoginFormAuthenticator implements Authenticator * * @return array */ - private function getExtraFields(ClientInterface $guzzle) + private function getExtraFields(SiteConfig $siteConfig, ClientInterface $guzzle) { $extraFields = []; - foreach ($this->siteConfig->getExtraFields() as $fieldName => $fieldValue) { + foreach ($siteConfig->getExtraFields() as $fieldName => $fieldValue) { if ('@=' === substr($fieldValue, 0, 2)) { $expressionLanguage = $this->getExpressionLanguage($guzzle); $fieldValue = $expressionLanguage->evaluate( substr($fieldValue, 2), [ - 'config' => $this->siteConfig, + 'config' => $siteConfig, ] ); } diff --git a/tests/SiteConfig/Authenticator/LoginFormAuthenticatorTest.php b/tests/SiteConfig/Authenticator/LoginFormAuthenticatorTest.php index 31c979b55..d429b72a0 100644 --- a/tests/SiteConfig/Authenticator/LoginFormAuthenticatorTest.php +++ b/tests/SiteConfig/Authenticator/LoginFormAuthenticatorTest.php @@ -35,8 +35,8 @@ class LoginFormAuthenticatorTest extends TestCase 'password' => 'unkn0wn', ]); - $auth = new LoginFormAuthenticator($siteConfig); - $res = $auth->login($guzzle); + $auth = new LoginFormAuthenticator(); + $res = $auth->login($siteConfig, $guzzle); $this->assertInstanceOf(LoginFormAuthenticator::class, $res); } @@ -65,8 +65,8 @@ class LoginFormAuthenticatorTest extends TestCase 'password' => 'unkn0wn', ]); - $auth = new LoginFormAuthenticator($siteConfig); - $res = $auth->login($guzzle); + $auth = new LoginFormAuthenticator(); + $res = $auth->login($siteConfig, $guzzle); $this->assertInstanceOf(LoginFormAuthenticator::class, $res); } @@ -128,8 +128,8 @@ class LoginFormAuthenticatorTest extends TestCase 'password' => 'unkn0wn', ]); - $auth = new LoginFormAuthenticator($siteConfig); - $res = $auth->login($client); + $auth = new LoginFormAuthenticator(); + $res = $auth->login($siteConfig, $client); $this->assertInstanceOf(LoginFormAuthenticator::class, $res); } @@ -194,8 +194,8 @@ class LoginFormAuthenticatorTest extends TestCase 'password' => 'unkn0wn', ]); - $auth = new LoginFormAuthenticator($siteConfig); - $res = $auth->login($client); + $auth = new LoginFormAuthenticator(); + $res = $auth->login($siteConfig, $client); $this->assertInstanceOf(LoginFormAuthenticator::class, $res); } @@ -210,8 +210,8 @@ class LoginFormAuthenticatorTest extends TestCase 'password' => 'unkn0wn', ]); - $auth = new LoginFormAuthenticator($siteConfig); - $loginRequired = $auth->isLoginRequired(file_get_contents(__DIR__ . '/../../fixtures/nextinpact-login.html')); + $auth = new LoginFormAuthenticator(); + $loginRequired = $auth->isLoginRequired($siteConfig, file_get_contents(__DIR__ . '/../../fixtures/nextinpact-login.html')); $this->assertFalse($loginRequired); } @@ -227,8 +227,8 @@ class LoginFormAuthenticatorTest extends TestCase 'notLoggedInXpath' => '//h2[@class="title_reserve_article"]', ]); - $auth = new LoginFormAuthenticator($siteConfig); - $loginRequired = $auth->isLoginRequired(file_get_contents(__DIR__ . '/../../fixtures/nextinpact-article.html')); + $auth = new LoginFormAuthenticator(); + $loginRequired = $auth->isLoginRequired($siteConfig, file_get_contents(__DIR__ . '/../../fixtures/nextinpact-article.html')); $this->assertTrue($loginRequired); } From 0c49aee192ec710fa135deeecd409be861d67536 Mon Sep 17 00:00:00 2001 From: Yassine Guedidi Date: Sat, 23 Nov 2024 18:47:08 +0100 Subject: [PATCH 3/5] Make LoginFormAuthenticator a service and remove Factory --- src/Guzzle/AuthenticatorSubscriber.php | 20 ++++--- src/SiteConfig/Authenticator/Factory.php | 21 -------- .../Authenticator/LoginFormAuthenticator.php | 2 +- tests/Guzzle/AuthenticatorSubscriberTest.php | 53 +++++++------------ 4 files changed, 30 insertions(+), 66 deletions(-) delete mode 100644 src/SiteConfig/Authenticator/Factory.php diff --git a/src/Guzzle/AuthenticatorSubscriber.php b/src/Guzzle/AuthenticatorSubscriber.php index ff4e9acc6..080512736 100644 --- a/src/Guzzle/AuthenticatorSubscriber.php +++ b/src/Guzzle/AuthenticatorSubscriber.php @@ -9,7 +9,7 @@ use GuzzleHttp\Message\RequestInterface; use Psr\Log\LoggerAwareInterface; use Psr\Log\LoggerInterface; use Psr\Log\NullLogger; -use Wallabag\SiteConfig\Authenticator\Factory; +use Wallabag\SiteConfig\Authenticator\Authenticator; use Wallabag\SiteConfig\SiteConfig; use Wallabag\SiteConfig\SiteConfigBuilder; @@ -23,8 +23,8 @@ class AuthenticatorSubscriber implements SubscriberInterface, LoggerAwareInterfa /** @var SiteConfigBuilder */ private $configBuilder; - /** @var Factory */ - private $authenticatorFactory; + /** @var Authenticator */ + private $authenticator; /** @var LoggerInterface */ private $logger; @@ -32,10 +32,10 @@ class AuthenticatorSubscriber implements SubscriberInterface, LoggerAwareInterfa /** * AuthenticatorSubscriber constructor. */ - public function __construct(SiteConfigBuilder $configBuilder, Factory $authenticatorFactory) + public function __construct(SiteConfigBuilder $configBuilder, Authenticator $authenticator) { $this->configBuilder = $configBuilder; - $this->authenticatorFactory = $authenticatorFactory; + $this->authenticator = $authenticator; $this->logger = new NullLogger(); } @@ -62,14 +62,13 @@ class AuthenticatorSubscriber implements SubscriberInterface, LoggerAwareInterfa } $client = $event->getClient(); - $authenticator = $this->authenticatorFactory->buildFromSiteConfig(); - if (!$authenticator->isLoggedIn($config, $client)) { + if (!$this->authenticator->isLoggedIn($config, $client)) { $this->logger->debug('loginIfRequired> user is not logged in, attach authenticator'); $emitter = $client->getEmitter(); $emitter->detach($this); - $authenticator->login($config, $client); + $this->authenticator->login($config, $client); $emitter->attach($this); } } @@ -94,8 +93,7 @@ class AuthenticatorSubscriber implements SubscriberInterface, LoggerAwareInterfa return; } - $authenticator = $this->authenticatorFactory->buildFromSiteConfig(); - $isLoginRequired = $authenticator->isLoginRequired($config, $body); + $isLoginRequired = $this->authenticator->isLoginRequired($config, $body); $this->logger->debug('loginIfRequested> retry #' . $this->retries . ' with login ' . ($isLoginRequired ? '' : 'not ') . 'required'); @@ -104,7 +102,7 @@ class AuthenticatorSubscriber implements SubscriberInterface, LoggerAwareInterfa $emitter = $client->getEmitter(); $emitter->detach($this); - $authenticator->login($config, $client); + $this->authenticator->login($config, $client); $emitter->attach($this); $event->retry(); diff --git a/src/SiteConfig/Authenticator/Factory.php b/src/SiteConfig/Authenticator/Factory.php deleted file mode 100644 index cf4267768..000000000 --- a/src/SiteConfig/Authenticator/Factory.php +++ /dev/null @@ -1,21 +0,0 @@ -getUsernameField() => $siteConfig->getUsername(), $siteConfig->getPasswordField() => $siteConfig->getPassword(), - ] + $this->getExtraFields($guzzle); + ] + $this->getExtraFields($siteConfig, $guzzle); $guzzle->post( $siteConfig->getLoginUri(), diff --git a/tests/Guzzle/AuthenticatorSubscriberTest.php b/tests/Guzzle/AuthenticatorSubscriberTest.php index 207c9c283..76cfadf32 100644 --- a/tests/Guzzle/AuthenticatorSubscriberTest.php +++ b/tests/Guzzle/AuthenticatorSubscriberTest.php @@ -15,15 +15,18 @@ use PHPUnit\Framework\TestCase; use Wallabag\Guzzle\AuthenticatorSubscriber; use Wallabag\SiteConfig\ArraySiteConfigBuilder; use Wallabag\SiteConfig\Authenticator\Authenticator; -use Wallabag\SiteConfig\Authenticator\Factory; class AuthenticatorSubscriberTest extends TestCase { public function testGetEvents() { + $authenticator = $this->getMockBuilder(Authenticator::class) + ->disableOriginalConstructor() + ->getMock(); + $subscriber = new AuthenticatorSubscriber( new ArraySiteConfigBuilder(), - new Factory() + $authenticator ); $events = $subscriber->getEvents(); @@ -35,8 +38,12 @@ class AuthenticatorSubscriberTest extends TestCase public function testLoginIfRequiredNotRequired() { + $authenticator = $this->getMockBuilder(Authenticator::class) + ->disableOriginalConstructor() + ->getMock(); + $builder = new ArraySiteConfigBuilder(['example.com' => []]); - $subscriber = new AuthenticatorSubscriber($builder, new Factory()); + $subscriber = new AuthenticatorSubscriber($builder, $authenticator); $logger = new Logger('foo'); $handler = new TestHandler(); @@ -75,16 +82,8 @@ class AuthenticatorSubscriberTest extends TestCase $authenticator->expects($this->once()) ->method('login'); - $factory = $this->getMockBuilder(Factory::class) - ->disableOriginalConstructor() - ->getMock(); - - $factory->expects($this->once()) - ->method('buildFromSiteConfig') - ->willReturn($authenticator); - $builder = new ArraySiteConfigBuilder(['example.com' => ['requiresLogin' => true]]); - $subscriber = new AuthenticatorSubscriber($builder, $factory); + $subscriber = new AuthenticatorSubscriber($builder, $authenticator); $logger = new Logger('foo'); $handler = new TestHandler(); @@ -124,8 +123,12 @@ class AuthenticatorSubscriberTest extends TestCase public function testLoginIfRequestedNotRequired() { + $authenticator = $this->getMockBuilder(Authenticator::class) + ->disableOriginalConstructor() + ->getMock(); + $builder = new ArraySiteConfigBuilder(['example.com' => []]); - $subscriber = new AuthenticatorSubscriber($builder, new Factory()); + $subscriber = new AuthenticatorSubscriber($builder, $authenticator); $logger = new Logger('foo'); $handler = new TestHandler(); @@ -161,19 +164,11 @@ class AuthenticatorSubscriberTest extends TestCase ->method('isLoginRequired') ->willReturn(false); - $factory = $this->getMockBuilder(Factory::class) - ->disableOriginalConstructor() - ->getMock(); - - $factory->expects($this->once()) - ->method('buildFromSiteConfig') - ->willReturn($authenticator); - $builder = new ArraySiteConfigBuilder(['example.com' => [ 'requiresLogin' => true, 'notLoggedInXpath' => '//html', ]]); - $subscriber = new AuthenticatorSubscriber($builder, $factory); + $subscriber = new AuthenticatorSubscriber($builder, $authenticator); $logger = new Logger('foo'); $handler = new TestHandler(); @@ -221,19 +216,11 @@ class AuthenticatorSubscriberTest extends TestCase $authenticator->expects($this->once()) ->method('login'); - $factory = $this->getMockBuilder(Factory::class) - ->disableOriginalConstructor() - ->getMock(); - - $factory->expects($this->once()) - ->method('buildFromSiteConfig') - ->willReturn($authenticator); - $builder = new ArraySiteConfigBuilder(['example.com' => [ 'requiresLogin' => true, 'notLoggedInXpath' => '//html', ]]); - $subscriber = new AuthenticatorSubscriber($builder, $factory); + $subscriber = new AuthenticatorSubscriber($builder, $authenticator); $logger = new Logger('foo'); $handler = new TestHandler(); @@ -276,7 +263,7 @@ class AuthenticatorSubscriberTest extends TestCase public function testLoginIfRequestedRedirect() { - $factory = $this->getMockBuilder(Factory::class) + $authenticator = $this->getMockBuilder(Authenticator::class) ->disableOriginalConstructor() ->getMock(); @@ -284,7 +271,7 @@ class AuthenticatorSubscriberTest extends TestCase 'requiresLogin' => true, 'notLoggedInXpath' => '//html', ]]); - $subscriber = new AuthenticatorSubscriber($builder, $factory); + $subscriber = new AuthenticatorSubscriber($builder, $authenticator); $logger = new Logger('foo'); $handler = new TestHandler(); From ac6969f4cc20a56f2b532e9ad47ccaadba3fc999 Mon Sep 17 00:00:00 2001 From: Yassine Guedidi Date: Sat, 23 Nov 2024 19:55:29 +0100 Subject: [PATCH 4/5] Remove site config authenticator extension point --- src/Guzzle/AuthenticatorSubscriber.php | 6 ++-- .../Authenticator/Authenticator.php | 32 ------------------- .../Authenticator/LoginFormAuthenticator.php | 19 ++++++++++- tests/Guzzle/AuthenticatorSubscriberTest.php | 16 +++++----- 4 files changed, 29 insertions(+), 44 deletions(-) delete mode 100644 src/SiteConfig/Authenticator/Authenticator.php diff --git a/src/Guzzle/AuthenticatorSubscriber.php b/src/Guzzle/AuthenticatorSubscriber.php index 080512736..c7a3b1083 100644 --- a/src/Guzzle/AuthenticatorSubscriber.php +++ b/src/Guzzle/AuthenticatorSubscriber.php @@ -9,7 +9,7 @@ use GuzzleHttp\Message\RequestInterface; use Psr\Log\LoggerAwareInterface; use Psr\Log\LoggerInterface; use Psr\Log\NullLogger; -use Wallabag\SiteConfig\Authenticator\Authenticator; +use Wallabag\SiteConfig\Authenticator\LoginFormAuthenticator; use Wallabag\SiteConfig\SiteConfig; use Wallabag\SiteConfig\SiteConfigBuilder; @@ -23,7 +23,7 @@ class AuthenticatorSubscriber implements SubscriberInterface, LoggerAwareInterfa /** @var SiteConfigBuilder */ private $configBuilder; - /** @var Authenticator */ + /** @var LoginFormAuthenticator */ private $authenticator; /** @var LoggerInterface */ @@ -32,7 +32,7 @@ class AuthenticatorSubscriber implements SubscriberInterface, LoggerAwareInterfa /** * AuthenticatorSubscriber constructor. */ - public function __construct(SiteConfigBuilder $configBuilder, Authenticator $authenticator) + public function __construct(SiteConfigBuilder $configBuilder, LoginFormAuthenticator $authenticator) { $this->configBuilder = $configBuilder; $this->authenticator = $authenticator; diff --git a/src/SiteConfig/Authenticator/Authenticator.php b/src/SiteConfig/Authenticator/Authenticator.php deleted file mode 100644 index 9623e39ab..000000000 --- a/src/SiteConfig/Authenticator/Authenticator.php +++ /dev/null @@ -1,32 +0,0 @@ -getDefaultOption('cookies')) instanceof CookieJar) { @@ -41,6 +51,13 @@ class LoginFormAuthenticator implements Authenticator return false; } + /** + * Checks from the HTML of a page if authentication is requested by a grabbed page. + * + * @param string $html + * + * @return bool + */ public function isLoginRequired(SiteConfig $siteConfig, $html) { // need to check for the login dom element ($options['not_logged_in_xpath']) in the HTML diff --git a/tests/Guzzle/AuthenticatorSubscriberTest.php b/tests/Guzzle/AuthenticatorSubscriberTest.php index 76cfadf32..8b1319c37 100644 --- a/tests/Guzzle/AuthenticatorSubscriberTest.php +++ b/tests/Guzzle/AuthenticatorSubscriberTest.php @@ -14,13 +14,13 @@ use Monolog\Logger; use PHPUnit\Framework\TestCase; use Wallabag\Guzzle\AuthenticatorSubscriber; use Wallabag\SiteConfig\ArraySiteConfigBuilder; -use Wallabag\SiteConfig\Authenticator\Authenticator; +use Wallabag\SiteConfig\Authenticator\LoginFormAuthenticator; class AuthenticatorSubscriberTest extends TestCase { public function testGetEvents() { - $authenticator = $this->getMockBuilder(Authenticator::class) + $authenticator = $this->getMockBuilder(LoginFormAuthenticator::class) ->disableOriginalConstructor() ->getMock(); @@ -38,7 +38,7 @@ class AuthenticatorSubscriberTest extends TestCase public function testLoginIfRequiredNotRequired() { - $authenticator = $this->getMockBuilder(Authenticator::class) + $authenticator = $this->getMockBuilder(LoginFormAuthenticator::class) ->disableOriginalConstructor() ->getMock(); @@ -71,7 +71,7 @@ class AuthenticatorSubscriberTest extends TestCase public function testLoginIfRequiredWithNotLoggedInUser() { - $authenticator = $this->getMockBuilder(Authenticator::class) + $authenticator = $this->getMockBuilder(LoginFormAuthenticator::class) ->disableOriginalConstructor() ->getMock(); @@ -123,7 +123,7 @@ class AuthenticatorSubscriberTest extends TestCase public function testLoginIfRequestedNotRequired() { - $authenticator = $this->getMockBuilder(Authenticator::class) + $authenticator = $this->getMockBuilder(LoginFormAuthenticator::class) ->disableOriginalConstructor() ->getMock(); @@ -156,7 +156,7 @@ class AuthenticatorSubscriberTest extends TestCase public function testLoginIfRequestedNotRequested() { - $authenticator = $this->getMockBuilder(Authenticator::class) + $authenticator = $this->getMockBuilder(LoginFormAuthenticator::class) ->disableOriginalConstructor() ->getMock(); @@ -205,7 +205,7 @@ class AuthenticatorSubscriberTest extends TestCase public function testLoginIfRequestedRequested() { - $authenticator = $this->getMockBuilder(Authenticator::class) + $authenticator = $this->getMockBuilder(LoginFormAuthenticator::class) ->disableOriginalConstructor() ->getMock(); @@ -263,7 +263,7 @@ class AuthenticatorSubscriberTest extends TestCase public function testLoginIfRequestedRedirect() { - $authenticator = $this->getMockBuilder(Authenticator::class) + $authenticator = $this->getMockBuilder(LoginFormAuthenticator::class) ->disableOriginalConstructor() ->getMock(); From 0fdcbcf7fbdc14ab8d1422b9a453ae4a4dcdc6e7 Mon Sep 17 00:00:00 2001 From: Yassine Guedidi Date: Sat, 23 Nov 2024 20:07:07 +0100 Subject: [PATCH 5/5] Move LoginFormAuthenticator directly in SiteConfig namespace --- src/Guzzle/AuthenticatorSubscriber.php | 2 +- .../{Authenticator => }/LoginFormAuthenticator.php | 3 +-- tests/Guzzle/AuthenticatorSubscriberTest.php | 2 +- .../LoginFormAuthenticatorTest.php | 12 ++++++------ 4 files changed, 9 insertions(+), 10 deletions(-) rename src/SiteConfig/{Authenticator => }/LoginFormAuthenticator.php (97%) rename tests/SiteConfig/{Authenticator => }/LoginFormAuthenticatorTest.php (94%) diff --git a/src/Guzzle/AuthenticatorSubscriber.php b/src/Guzzle/AuthenticatorSubscriber.php index c7a3b1083..4b565076e 100644 --- a/src/Guzzle/AuthenticatorSubscriber.php +++ b/src/Guzzle/AuthenticatorSubscriber.php @@ -9,7 +9,7 @@ use GuzzleHttp\Message\RequestInterface; use Psr\Log\LoggerAwareInterface; use Psr\Log\LoggerInterface; use Psr\Log\NullLogger; -use Wallabag\SiteConfig\Authenticator\LoginFormAuthenticator; +use Wallabag\SiteConfig\LoginFormAuthenticator; use Wallabag\SiteConfig\SiteConfig; use Wallabag\SiteConfig\SiteConfigBuilder; diff --git a/src/SiteConfig/Authenticator/LoginFormAuthenticator.php b/src/SiteConfig/LoginFormAuthenticator.php similarity index 97% rename from src/SiteConfig/Authenticator/LoginFormAuthenticator.php rename to src/SiteConfig/LoginFormAuthenticator.php index 00f8ab5ee..ab1d83970 100644 --- a/src/SiteConfig/Authenticator/LoginFormAuthenticator.php +++ b/src/SiteConfig/LoginFormAuthenticator.php @@ -1,13 +1,12 @@ expects($this->any()) ->method('getBody') - ->willReturn(file_get_contents(__DIR__ . '/../../fixtures/aoc.media.html')); + ->willReturn(file_get_contents(__DIR__ . '/../fixtures/aoc.media.html')); $response->expects($this->any()) ->method('getStatusCode') @@ -142,7 +142,7 @@ class LoginFormAuthenticatorTest extends TestCase $response->expects($this->any()) ->method('getBody') - ->willReturn(file_get_contents(__DIR__ . '/../../fixtures/nextinpact-login.html')); + ->willReturn(file_get_contents(__DIR__ . '/../fixtures/nextinpact-login.html')); $response->expects($this->any()) ->method('getStatusCode') @@ -211,7 +211,7 @@ class LoginFormAuthenticatorTest extends TestCase ]); $auth = new LoginFormAuthenticator(); - $loginRequired = $auth->isLoginRequired($siteConfig, file_get_contents(__DIR__ . '/../../fixtures/nextinpact-login.html')); + $loginRequired = $auth->isLoginRequired($siteConfig, file_get_contents(__DIR__ . '/../fixtures/nextinpact-login.html')); $this->assertFalse($loginRequired); } @@ -228,7 +228,7 @@ class LoginFormAuthenticatorTest extends TestCase ]); $auth = new LoginFormAuthenticator(); - $loginRequired = $auth->isLoginRequired($siteConfig, file_get_contents(__DIR__ . '/../../fixtures/nextinpact-article.html')); + $loginRequired = $auth->isLoginRequired($siteConfig, file_get_contents(__DIR__ . '/../fixtures/nextinpact-article.html')); $this->assertTrue($loginRequired); }