Skip to content

Commit

Permalink
Merge pull request #48946 from nextcloud/fix/stable28-uploader
Browse files Browse the repository at this point in the history
[stable28] chore(deps): Update `@nextcloud/upload` to at least 1.5.0
  • Loading branch information
susnux authored Oct 30, 2024
2 parents cb8ce13 + 1efc3ef commit c1febd3
Show file tree
Hide file tree
Showing 125 changed files with 327 additions and 328 deletions.
12 changes: 12 additions & 0 deletions __mocks__/@nextcloud/axios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,20 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

import type { AxiosInterceptorManager, AxiosResponse, InternalAxiosRequestConfig } from 'axios'

export default {
get: async () => ({ status: 200, data: {} }),
delete: async () => ({ status: 200, data: {} }),
post: async () => ({ status: 200, data: {} }),

interceptors: {
request: {
use: () => {},
} as AxiosInterceptorManager<InternalAxiosRequestConfig>,
response: {
use: () => {},
} as AxiosInterceptorManager<AxiosResponse>,
}
}
12 changes: 5 additions & 7 deletions apps/dav/lib/Connector/Sabre/Auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -221,18 +221,16 @@ private function auth(RequestInterface $request, ResponseInterface $response): a
}
}

if (!$this->userSession->isLoggedIn() && in_array('XMLHttpRequest', explode(',', $request->getHeader('X-Requested-With') ?? ''))) {
// do not re-authenticate over ajax, use dummy auth name to prevent browser popup
$response->addHeader('WWW-Authenticate', 'DummyBasic realm="' . $this->realm . '"');
$response->setStatus(401);
throw new \Sabre\DAV\Exception\NotAuthenticated('Cannot authenticate over ajax calls');
}

$data = parent::check($request, $response);
if ($data[0] === true) {
$startPos = strrpos($data[1], '/') + 1;
$user = $this->userSession->getUser()->getUID();
$data[1] = substr_replace($data[1], $user, $startPos);
} elseif (in_array('XMLHttpRequest', explode(',', $request->getHeader('X-Requested-With') ?? ''))) {
// For ajax requests use dummy auth name to prevent browser popup in case of invalid creditials
$response->addHeader('WWW-Authenticate', 'DummyBasic realm="' . $this->realm . '"');
$response->setStatus(401);
throw new \Sabre\DAV\Exception\NotAuthenticated('Cannot authenticate over ajax calls');
}
return $data;
}
Expand Down
93 changes: 67 additions & 26 deletions apps/dav/tests/unit/Connector/Sabre/AuthTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
use OCP\ISession;
use OCP\IUser;
use OCP\Security\Bruteforce\IThrottler;
use PHPUnit\Framework\MockObject\MockObject;
use Sabre\DAV\Server;
use Sabre\HTTP\RequestInterface;
use Sabre\HTTP\ResponseInterface;
Expand All @@ -47,17 +48,17 @@
* @group DB
*/
class AuthTest extends TestCase {
/** @var ISession */
/** @var ISession&MockObject */
private $session;
/** @var \OCA\DAV\Connector\Sabre\Auth */
private $auth;
/** @var Session */
/** @var Session&MockObject */
private $userSession;
/** @var IRequest */
/** @var IRequest&MockObject */
private $request;
/** @var Manager */
/** @var Manager&MockObject */
private $twoFactorManager;
/** @var IThrottler */
/** @var IThrottler&MockObject */
private $throttler;

protected function setUp(): void {
Expand Down Expand Up @@ -549,11 +550,11 @@ public function testAuthenticateNoBasicAuthenticateHeadersProvidedWithAjax(): vo
$this->expectException(\Sabre\DAV\Exception\NotAuthenticated::class);
$this->expectExceptionMessage('Cannot authenticate over ajax calls');

/** @var \Sabre\HTTP\RequestInterface $httpRequest */
/** @var \Sabre\HTTP\RequestInterface&MockObject $httpRequest */
$httpRequest = $this->getMockBuilder(RequestInterface::class)
->disableOriginalConstructor()
->getMock();
/** @var \Sabre\HTTP\ResponseInterface $httpResponse */
/** @var \Sabre\HTTP\ResponseInterface&MockObject $httpResponse */
$httpResponse = $this->getMockBuilder(ResponseInterface::class)
->disableOriginalConstructor()
->getMock();
Expand All @@ -562,10 +563,59 @@ public function testAuthenticateNoBasicAuthenticateHeadersProvidedWithAjax(): vo
->method('isLoggedIn')
->willReturn(false);
$httpRequest
->expects($this->exactly(2))
->method('getHeader')
->willReturnMap([
['X-Requested-With', 'XMLHttpRequest'],
['Authorization', null],
]);

$this->auth->check($httpRequest, $httpResponse);
}

public function testAuthenticateWithBasicAuthenticateHeadersProvidedWithAjax(): void {
// No CSRF
$this->request
->expects($this->once())
->method('passesCSRFCheck')
->willReturn(false);

/** @var \Sabre\HTTP\RequestInterface&MockObject $httpRequest */
$httpRequest = $this->getMockBuilder(RequestInterface::class)
->disableOriginalConstructor()
->getMock();
/** @var \Sabre\HTTP\ResponseInterface&MockObject $httpResponse */
$httpResponse = $this->getMockBuilder(ResponseInterface::class)
->disableOriginalConstructor()
->getMock();
$httpRequest
->expects($this->any())
->method('getHeader')
->with('X-Requested-With')
->willReturn('XMLHttpRequest');
->willReturnMap([
['X-Requested-With', 'XMLHttpRequest'],
['Authorization', 'basic dXNlcm5hbWU6cGFzc3dvcmQ='],
]);

$user = $this->getMockBuilder(IUser::class)
->disableOriginalConstructor()
->getMock();
$user->expects($this->any())
->method('getUID')
->willReturn('MyDavUser');
$this->userSession
->expects($this->any())
->method('isLoggedIn')
->willReturn(false);
$this->userSession
->expects($this->once())
->method('logClientIn')
->with('username', 'password')
->willReturn(true);
$this->userSession
->expects($this->any())
->method('getUser')
->willReturn($user);

$this->auth->check($httpRequest, $httpResponse);
}

Expand Down Expand Up @@ -619,16 +669,11 @@ public function testAuthenticateValidCredentials(): void {
->disableOriginalConstructor()
->getMock();
$server->httpRequest
->expects($this->exactly(2))
->expects($this->once())
->method('getHeader')
->withConsecutive(
['X-Requested-With'],
['Authorization'],
)
->willReturnOnConsecutiveCalls(
null,
'basic dXNlcm5hbWU6cGFzc3dvcmQ=',
);
->with('Authorization')
->willReturn('basic dXNlcm5hbWU6cGFzc3dvcmQ=');

$server->httpResponse = $this->getMockBuilder(ResponseInterface::class)
->disableOriginalConstructor()
->getMock();
Expand Down Expand Up @@ -661,14 +706,10 @@ public function testAuthenticateInvalidCredentials(): void {
$server->httpRequest
->expects($this->exactly(2))
->method('getHeader')
->withConsecutive(
['X-Requested-With'],
['Authorization'],
)
->willReturnOnConsecutiveCalls(
null,
'basic dXNlcm5hbWU6cGFzc3dvcmQ=',
);
->willReturnMap([
['Authorization', 'basic dXNlcm5hbWU6cGFzc3dvcmQ='],
['X-Requested-With', null],
]);
$server->httpResponse = $this->getMockBuilder(ResponseInterface::class)
->disableOriginalConstructor()
->getMock();
Expand Down
2 changes: 0 additions & 2 deletions dist/1165-1165.js

This file was deleted.

1 change: 0 additions & 1 deletion dist/1165-1165.js.map

This file was deleted.

2 changes: 2 additions & 0 deletions dist/1957-1957.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions dist/1957-1957.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/3412-3412.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/3412-3412.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/4473-4473.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/4473-4473.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions dist/6013-6013.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions dist/6013-6013.js.map

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions dist/6075-6075.js

This file was deleted.

1 change: 0 additions & 1 deletion dist/6075-6075.js.map

This file was deleted.

Loading

0 comments on commit c1febd3

Please sign in to comment.