aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag
diff options
context:
space:
mode:
authorJeremy Benoist <jeremy.benoist@gmail.com>2019-04-24 15:28:15 +0200
committerJeremy Benoist <jeremy.benoist@gmail.com>2019-04-24 15:28:15 +0200
commit35359bd3c67e5b6c6371e2e547a3411ca0a8027b (patch)
tree7f9fee18f321bef35ed845ce0f921dab2bddc72b /src/Wallabag
parentff8f338dc2cf73b310626d9f4b41efc1d352e182 (diff)
downloadwallabag-35359bd3c67e5b6c6371e2e547a3411ca0a8027b.tar.gz
wallabag-35359bd3c67e5b6c6371e2e547a3411ca0a8027b.tar.zst
wallabag-35359bd3c67e5b6c6371e2e547a3411ca0a8027b.zip
Adding more tests to cover different scenario
Diffstat (limited to 'src/Wallabag')
-rw-r--r--src/Wallabag/CoreBundle/DataFixtures/ORM/LoadSiteCredentialData.php27
-rw-r--r--src/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilder.php27
2 files changed, 38 insertions, 16 deletions
diff --git a/src/Wallabag/CoreBundle/DataFixtures/ORM/LoadSiteCredentialData.php b/src/Wallabag/CoreBundle/DataFixtures/ORM/LoadSiteCredentialData.php
index 866f55a4..faf29da6 100644
--- a/src/Wallabag/CoreBundle/DataFixtures/ORM/LoadSiteCredentialData.php
+++ b/src/Wallabag/CoreBundle/DataFixtures/ORM/LoadSiteCredentialData.php
@@ -5,19 +5,38 @@ namespace Wallabag\CoreBundle\DataFixtures\ORM;
5use Doctrine\Common\DataFixtures\AbstractFixture; 5use Doctrine\Common\DataFixtures\AbstractFixture;
6use Doctrine\Common\DataFixtures\OrderedFixtureInterface; 6use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
7use Doctrine\Common\Persistence\ObjectManager; 7use Doctrine\Common\Persistence\ObjectManager;
8use Symfony\Component\DependencyInjection\ContainerAwareInterface;
9use Symfony\Component\DependencyInjection\ContainerInterface;
8use Wallabag\CoreBundle\Entity\SiteCredential; 10use Wallabag\CoreBundle\Entity\SiteCredential;
9 11
10class LoadSiteCredentialData extends AbstractFixture implements OrderedFixtureInterface 12class LoadSiteCredentialData extends AbstractFixture implements OrderedFixtureInterface, ContainerAwareInterface
11{ 13{
12 /** 14 /**
15 * @var ContainerInterface
16 */
17 private $container;
18
19 public function setContainer(ContainerInterface $container = null)
20 {
21 $this->container = $container;
22 }
23
24 /**
13 * {@inheritdoc} 25 * {@inheritdoc}
14 */ 26 */
15 public function load(ObjectManager $manager) 27 public function load(ObjectManager $manager)
16 { 28 {
17 $credential = new SiteCredential($this->getReference('admin-user')); 29 $credential = new SiteCredential($this->getReference('admin-user'));
18 $credential->setHost('example.com'); 30 $credential->setHost('.super.com');
19 $credential->setUsername('foo'); 31 $credential->setUsername($this->container->get('wallabag_core.helper.crypto_proxy')->crypt('.super'));
20 $credential->setPassword('bar'); 32 $credential->setPassword($this->container->get('wallabag_core.helper.crypto_proxy')->crypt('bar'));
33
34 $manager->persist($credential);
35
36 $credential = new SiteCredential($this->getReference('admin-user'));
37 $credential->setHost('paywall.example.com');
38 $credential->setUsername($this->container->get('wallabag_core.helper.crypto_proxy')->crypt('paywall.example'));
39 $credential->setPassword($this->container->get('wallabag_core.helper.crypto_proxy')->crypt('bar'));
21 40
22 $manager->persist($credential); 41 $manager->persist($credential);
23 42
diff --git a/src/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilder.php b/src/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilder.php
index 718441bd..c7502bac 100644
--- a/src/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilder.php
+++ b/src/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilder.php
@@ -62,21 +62,24 @@ class GrabySiteConfigBuilder implements SiteConfigBuilder
62 $host = substr($host, 4); 62 $host = substr($host, 4);
63 } 63 }
64 64
65 $credentials = null; 65 if (!$this->currentUser) {
66 if ($this->currentUser) { 66 $this->logger->debug('Auth: no current user defined.');
67 $hosts = [$host]; 67
68 // will try to see for a host without the first subdomain (fr.example.org & .example.org) 68 return false;
69 $split = explode('.', $host); 69 }
70 70
71 if (\count($split) > 1) { 71 $hosts = [$host];
72 // remove first subdomain 72 // will try to see for a host without the first subdomain (fr.example.org & .example.org)
73 array_shift($split); 73 $split = explode('.', $host);
74 $hosts[] = '.' . implode('.', $split);
75 }
76 74
77 $credentials = $this->credentialRepository->findOneByHostsAndUser($hosts, $this->currentUser->getId()); 75 if (\count($split) > 1) {
76 // remove first subdomain
77 array_shift($split);
78 $hosts[] = '.' . implode('.', $split);
78 } 79 }
79 80
81 $credentials = $this->credentialRepository->findOneByHostsAndUser($hosts, $this->currentUser->getId());
82
80 if (null === $credentials) { 83 if (null === $credentials) {
81 $this->logger->debug('Auth: no credentials available for host.', ['host' => $host]); 84 $this->logger->debug('Auth: no credentials available for host.', ['host' => $host]);
82 85