mirror of
https://github.com/nextcloud/server.git
synced 2024-07-28 20:16:02 +02:00
Fix undefined HTTP_USER_AGENT
This commit is contained in:
parent
e8661a6b56
commit
358858c9e3
@ -674,6 +674,9 @@ class Request implements \ArrayAccess, \Countable, IRequest {
|
||||
* @return bool true if at least one of the given agent matches, false otherwise
|
||||
*/
|
||||
public function isUserAgent(array $agent) {
|
||||
if (!isset($this->server['HTTP_USER_AGENT'])) {
|
||||
return false;
|
||||
}
|
||||
foreach ($agent as $regex) {
|
||||
if (preg_match($regex, $this->server['HTTP_USER_AGENT'])) {
|
||||
return true;
|
||||
|
@ -693,19 +693,36 @@ class RequestTest extends \Test\TestCase {
|
||||
*/
|
||||
public function testUserAgent($testAgent, $userAgent, $matches) {
|
||||
$request = new Request(
|
||||
[
|
||||
'server' => [
|
||||
'HTTP_USER_AGENT' => $testAgent,
|
||||
]
|
||||
],
|
||||
$this->secureRandom,
|
||||
$this->config,
|
||||
$this->stream
|
||||
[
|
||||
'server' => [
|
||||
'HTTP_USER_AGENT' => $testAgent,
|
||||
]
|
||||
],
|
||||
$this->secureRandom,
|
||||
$this->config,
|
||||
$this->stream
|
||||
);
|
||||
|
||||
$this->assertSame($matches, $request->isUserAgent($userAgent));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider userAgentProvider
|
||||
* @param string $testAgent
|
||||
* @param array $userAgent
|
||||
* @param bool $matches
|
||||
*/
|
||||
public function testUndefinedUserAgent($testAgent, $userAgent, $matches) {
|
||||
$request = new Request(
|
||||
[],
|
||||
$this->secureRandom,
|
||||
$this->config,
|
||||
$this->stream
|
||||
);
|
||||
|
||||
$this->assertFalse($request->isUserAgent($userAgent));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user