1
0
Fork 0
mirror of https://github.com/wallabag/wallabag.git synced 2025-08-01 17:38:38 +00:00

Add ability to match many domains for credentials

Instead of fetching one domain, we use the same method as in site config (to retrieve the matching file) and handle api.example.org, example.org, .org (yes the last one isn’t useful).
If one of these match, we got it and use it.
This commit is contained in:
Jeremy Benoist 2019-04-23 22:28:36 +02:00
parent bfd69c74e5
commit f45496336f
No known key found for this signature in database
GPG key ID: BCA73962457ACC3C
15 changed files with 36 additions and 26 deletions

View file

@ -24,7 +24,7 @@ class GrabySiteConfigBuilderTest extends TestCase
$grabySiteConfig = new GrabySiteConfig();
$grabySiteConfig->requires_login = true;
$grabySiteConfig->login_uri = 'http://www.example.com/login';
$grabySiteConfig->login_uri = 'http://api.example.com/login';
$grabySiteConfig->login_username_field = 'login';
$grabySiteConfig->login_password_field = 'password';
$grabySiteConfig->login_extra_fields = ['field=value'];
@ -32,7 +32,7 @@ class GrabySiteConfigBuilderTest extends TestCase
$grabyConfigBuilderMock
->method('buildForHost')
->with('example.com')
->with('api.example.com')
->will($this->returnValue($grabySiteConfig));
$logger = new Logger('foo');
@ -43,8 +43,8 @@ class GrabySiteConfigBuilderTest extends TestCase
->disableOriginalConstructor()
->getMock();
$siteCrentialRepo->expects($this->once())
->method('findOneByHostAndUser')
->with('example.com', 1)
->method('findOneByHostsAndUser')
->with(['api.example.com', '.example.com'], 1)
->willReturn(['username' => 'foo', 'password' => 'bar']);
$user = $this->getMockBuilder('Wallabag\UserBundle\Entity\User')
@ -66,11 +66,11 @@ class GrabySiteConfigBuilderTest extends TestCase
$logger
);
$config = $this->builder->buildForHost('www.example.com');
$config = $this->builder->buildForHost('api.example.com');
$this->assertSame('example.com', $config->getHost());
$this->assertSame('api.example.com', $config->getHost());
$this->assertTrue($config->requiresLogin());
$this->assertSame('http://www.example.com/login', $config->getLoginUri());
$this->assertSame('http://api.example.com/login', $config->getLoginUri());
$this->assertSame('login', $config->getUsernameField());
$this->assertSame('password', $config->getPasswordField());
$this->assertSame(['field' => 'value'], $config->getExtraFields());
@ -103,8 +103,8 @@ class GrabySiteConfigBuilderTest extends TestCase
->disableOriginalConstructor()
->getMock();
$siteCrentialRepo->expects($this->once())
->method('findOneByHostAndUser')
->with('unknown.com', 1)
->method('findOneByHostsAndUser')
->with(['unknown.com', '.com'], 1)
->willReturn(null);
$user = $this->getMockBuilder('Wallabag\UserBundle\Entity\User')