1
0
Fork 0
mirror of https://github.com/wallabag/wallabag.git synced 2025-09-15 18:57:05 +00:00

Use Graby's http headers configuration for the authentication request

This commit is contained in:
Adrien ERAUD 2025-02-18 11:49:46 +01:00
parent b905a2c856
commit d58549472c
No known key found for this signature in database
GPG key ID: A201CDCF5C64EA53
5 changed files with 96 additions and 1 deletions

View file

@ -183,4 +183,62 @@ class LoginFormAuthenticatorTest extends TestCase
$this->assertTrue($loginRequired);
}
public function testLoginPostWithUserAgentHeaderWithData()
{
$siteConfig = new SiteConfig([
'host' => 'nextinpact.com',
'loginUri' => 'https://compte.nextinpact.com/Account/Login',
'usernameField' => 'UserName',
'passwordField' => 'Password',
'username' => 'johndoe',
'password' => 'unkn0wn',
'httpHeaders' => [
'user-agent' => 'Wallabag (Guzzle/5)',
],
]);
$browserResponse = new MockResponse('<html></html>', ['http_code' => 200, 'response_headers' => ['content-type' => 'text/html']]);
$browserClient = new MockHttpClient([$browserResponse]);
$browser = $this->getMockBuilder(HttpBrowser::class)
->setConstructorArgs([$browserClient])
->getMock();
$browser->expects($this->any())
->method('request')
->with(
$this->equalTo('POST'),
$this->equalTo('https://compte.nextinpact.com/Account/Login'),
$this->equalTo([
'UserName' => 'johndoe',
'Password' => 'unkn0wn',
]),
$this->equalTo([]),
$this->equalTo([
'HTTP_user-agent' => 'Wallabag (Guzzle/5)',
]),
)
;
$requestHtmlFunctionResponse = $this->getMockBuilder(ResponseInterface::class)->getMock();
$requestHtmlFunctionResponse->expects($this->any())
->method('getContent')
->willReturn(file_get_contents(__DIR__ . '/../fixtures/nextinpact-login.html'))
;
$requestHtmlFunctionClient = $this->getMockBuilder(HttpClientInterface::class)->getMock();
$requestHtmlFunctionClient->expects($this->any())
->method('request')
->with(
$this->equalTo('GET'),
$this->equalTo('https://nextinpact.com/'),
)
->willReturn($requestHtmlFunctionResponse)
;
$authenticatorProvider = new AuthenticatorProvider($requestHtmlFunctionClient);
$auth = new LoginFormAuthenticator($browser, $authenticatorProvider);
$res = $auth->login($siteConfig);
$this->assertInstanceOf(LoginFormAuthenticator::class, $res);
}
}