Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions apps/dav/appinfo/v1/caldav.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* SPDX-License-Identifier: AGPL-3.0-only
*/
// Backends
use OC\Files\SetupManager;
use OC\KnownUser\KnownUserService;
use OCA\DAV\CalDAV\CalDavBackend;
use OCA\DAV\CalDAV\CalendarRoot;
Expand Down Expand Up @@ -40,6 +41,7 @@
Server::get(IRequest::class),
Server::get(\OC\Authentication\TwoFactorAuth\Manager::class),
Server::get(IThrottler::class),
Server::get(SetupManager::class),
'principals/'
);
$principalBackend = new Principal(
Expand Down
2 changes: 2 additions & 0 deletions apps/dav/appinfo/v1/carddav.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* SPDX-License-Identifier: AGPL-3.0-only
*/
// Backends
use OC\Files\SetupManager;
use OC\KnownUser\KnownUserService;
use OCA\DAV\AppInfo\PluginManager;
use OCA\DAV\CalDAV\Proxy\ProxyMapper;
Expand Down Expand Up @@ -41,6 +42,7 @@
Server::get(IRequest::class),
Server::get(\OC\Authentication\TwoFactorAuth\Manager::class),
Server::get(IThrottler::class),
Server::get(SetupManager::class),
'principals/'
);
$principalBackend = new Principal(
Expand Down
2 changes: 2 additions & 0 deletions apps/dav/appinfo/v1/webdav.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* SPDX-License-Identifier: AGPL-3.0-only
*/
use OC\Files\Filesystem;
use OC\Files\SetupManager;
use OCA\DAV\Connector\Sabre\Auth;
use OCA\DAV\Connector\Sabre\BearerAuth;
use OCA\DAV\Connector\Sabre\ServerFactory;
Expand Down Expand Up @@ -55,6 +56,7 @@
Server::get(IRequest::class),
Server::get(\OC\Authentication\TwoFactorAuth\Manager::class),
Server::get(IThrottler::class),
Server::get(SetupManager::class),
'principals/'
);
$authPlugin = new \Sabre\DAV\Auth\Plugin($authBackend);
Expand Down
17 changes: 14 additions & 3 deletions apps/dav/lib/Connector/Sabre/Auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Exception;
use OC\Authentication\Exceptions\PasswordLoginForbiddenException;
use OC\Authentication\TwoFactorAuth\Manager;
use OC\Files\SetupManager;
use OC\User\Session;
use OCA\DAV\Connector\Sabre\Exception\PasswordLoginForbidden;
use OCA\DAV\Connector\Sabre\Exception\TooManyRequests;
Expand Down Expand Up @@ -37,6 +38,7 @@ public function __construct(
private IRequest $request,
private Manager $twoFactorManager,
private IThrottler $throttler,
private SetupManager $setupManager,
string $principalPrefix = 'principals/users/',
) {
$this->principalPrefix = $principalPrefix;
Expand Down Expand Up @@ -183,10 +185,13 @@ private function auth(RequestInterface $request, ResponseInterface $response): a
|| ($this->userSession->isLoggedIn() && $this->session->get(self::DAV_AUTHENTICATED) === $this->userSession->getUser()->getUID() && empty($request->getHeader('Authorization')))
|| \OC_User::handleApacheAuth()
) {
$user = $this->userSession->getUser()->getUID();
$this->currentUser = $user;
$user = $this->userSession->getUser();
$this->setupManager->setupForUser($user);

$uid = $user->getUID();
$this->currentUser = $uid;
$this->session->close();
return [true, $this->principalPrefix . $user];
return [true, $this->principalPrefix . $uid];
}
}

Expand All @@ -201,6 +206,12 @@ private function auth(RequestInterface $request, ResponseInterface $response): a
$response->setStatus(Http::STATUS_UNAUTHORIZED);
throw new \Sabre\DAV\Exception\NotAuthenticated('Cannot authenticate over ajax calls');
}

$user = $this->userSession->getUser();
if ($user !== null) {
$this->setupManager->setupForUser($user);
}

return $data;
}
}
4 changes: 3 additions & 1 deletion apps/dav/lib/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
namespace OCA\DAV;

use OC\Files\Filesystem;
use OC\Files\SetupManager;
use OCA\DAV\AppInfo\PluginManager;
use OCA\DAV\BulkUpload\BulkUploadPlugin;
use OCA\DAV\CalDAV\BirthdayCalendar\EnablePlugin;
Expand Down Expand Up @@ -132,7 +133,8 @@ public function __construct(
\OCP\Server::get(IUserSession::class),
\OCP\Server::get(IRequest::class),
\OCP\Server::get(\OC\Authentication\TwoFactorAuth\Manager::class),
\OCP\Server::get(IThrottler::class)
\OCP\Server::get(IThrottler::class),
\OCP\Server::get(SetupManager::class),
);

// Set URL explicitly due to reverse-proxy situations
Expand Down
8 changes: 6 additions & 2 deletions apps/dav/tests/unit/Connector/Sabre/AuthTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

use OC\Authentication\Exceptions\PasswordLoginForbiddenException;
use OC\Authentication\TwoFactorAuth\Manager;
use OC\Files\SetupManager;
use OC\User\Session;
use OCA\DAV\Connector\Sabre\Auth;
use OCA\DAV\Connector\Sabre\Exception\PasswordLoginForbidden;
Expand All @@ -35,6 +36,7 @@ class AuthTest extends TestCase {
private IRequest&MockObject $request;
private Manager&MockObject $twoFactorManager;
private IThrottler&MockObject $throttler;
private SetupManager&MockObject $setupManager;
private Auth $auth;

protected function setUp(): void {
Expand All @@ -44,12 +46,14 @@ protected function setUp(): void {
$this->request = $this->createMock(IRequest::class);
$this->twoFactorManager = $this->createMock(Manager::class);
$this->throttler = $this->createMock(IThrottler::class);
$this->setupManager = $this->createMock(SetupManager::class);
$this->auth = new Auth(
$this->session,
$this->userSession,
$this->request,
$this->twoFactorManager,
$this->throttler
$this->throttler,
$this->setupManager,
);
}

Expand Down Expand Up @@ -579,7 +583,7 @@ public function testAuthenticateValidCredentials(): void {
->method('getUID')
->willReturn('MyTestUser');
$this->userSession
->expects($this->exactly(3))
->expects($this->exactly(4))
->method('getUser')
->willReturn($user);
$response = $this->auth->check($server->httpRequest, $server->httpResponse);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,7 @@ export default {
if (data.status === 'success') {
this.handleAvatarUpdate(false)
} else if (data.data === 'notsquare') {
const tempAvatar = generateUrl('/avatar/tmp') + '?requesttoken=' + encodeURIComponent(OC.requestToken) + '#' + Math.floor(Math.random() * 1000)
this.$refs.cropper.replace(tempAvatar)
this.$refs.cropper.replace(data.image)
this.showCropper = true
} else {
showError(data.data.message)
Expand Down
Binary file not shown.

This file was deleted.

128 changes: 5 additions & 123 deletions build/integration/features/avatar.feature
Original file line number Diff line number Diff line change
Expand Up @@ -21,32 +21,9 @@ Feature: avatar
And last avatar is a square of size 512
And last avatar is not a single color



Scenario: get temporary non-square user avatar before cropping it
Given Logging in using web as "user0"
And logged in user posts temporary avatar from file "data/coloured-pattern-non-square.png"
When logged in user gets temporary avatar
Then The following headers should be set
| Content-Type | image/png |
# "last avatar" also includes the last temporary avatar
And last avatar is not a square
And last avatar is not a single color

Scenario: get non-square user avatar before cropping it
Given Logging in using web as "user0"
And logged in user posts temporary avatar from file "data/coloured-pattern-non-square.png"
# Avatar needs to be cropped to finish setting it
When user "user0" gets avatar for user "user0"
Then The following headers should be set
| Content-Type | image/png |
| X-NC-IsCustomAvatar | 0 |
And last avatar is a square of size 512
And last avatar is not a single color

Scenario: set square user avatar from file
Given Logging in using web as "user0"
When logged in user posts temporary avatar from file "data/green-square-256.png"
When logged in user posts avatar from file "data/green-square-256.png"
And user "user0" gets avatar for user "user0"
And The following headers should be set
| Content-Type | image/png |
Expand All @@ -64,7 +41,7 @@ Feature: avatar
Scenario: set square user avatar from internal path
Given user "user0" uploads file "data/green-square-256.png" to "/internal-green-square-256.png"
And Logging in using web as "user0"
When logged in user posts temporary avatar from internal path "internal-green-square-256.png"
When logged in user posts avatar from internal path "internal-green-square-256.png"
And user "user0" gets avatar for user "user0" with size "64"
And The following headers should be set
| Content-Type | image/png |
Expand All @@ -78,82 +55,21 @@ Feature: avatar
And last avatar is a square of size 64
And last avatar is a single "#00FF00" color

Scenario: set non-square user avatar from file
Given Logging in using web as "user0"
When logged in user posts temporary avatar from file "data/coloured-pattern-non-square.png"
And logged in user crops temporary avatar
| x | 384 |
| y | 256 |
| w | 128 |
| h | 128 |
Then logged in user gets temporary avatar with 404
And user "user0" gets avatar for user "user0"
And The following headers should be set
| Content-Type | image/png |
| X-NC-IsCustomAvatar | 1 |
And last avatar is a square of size 512
And last avatar is a single "#FF0000" color
And user "anonymous" gets avatar for user "user0"
And The following headers should be set
| Content-Type | image/png |
| X-NC-IsCustomAvatar | 1 |
And last avatar is a square of size 512
And last avatar is a single "#FF0000" color

Scenario: set non-square user avatar from internal path
Given user "user0" uploads file "data/coloured-pattern-non-square.png" to "/internal-coloured-pattern-non-square.png"
And Logging in using web as "user0"
When logged in user posts temporary avatar from internal path "internal-coloured-pattern-non-square.png"
And logged in user crops temporary avatar
| x | 704 |
| y | 320 |
| w | 64 |
| h | 64 |
Then logged in user gets temporary avatar with 404
And user "user0" gets avatar for user "user0" with size "64"
And The following headers should be set
| Content-Type | image/png |
| X-NC-IsCustomAvatar | 1 |
And last avatar is a square of size 64
And last avatar is a single "#00FF00" color
And user "anonymous" gets avatar for user "user0" with size "64"
And The following headers should be set
| Content-Type | image/png |
| X-NC-IsCustomAvatar | 1 |
And last avatar is a square of size 64
And last avatar is a single "#00FF00" color

Scenario: cropped user avatar needs to be squared
Given Logging in using web as "user0"
And logged in user posts temporary avatar from file "data/coloured-pattern-non-square.png"
When logged in user crops temporary avatar with 400
| x | 384 |
| y | 256 |
| w | 192 |
| h | 128 |



Scenario: delete user avatar
Given Logging in using web as "user0"
And logged in user posts temporary avatar from file "data/coloured-pattern-non-square.png"
And logged in user crops temporary avatar
| x | 384 |
| y | 256 |
| w | 128 |
| h | 128 |
And logged in user posts avatar from file "data/green-square-256.png"
And user "user0" gets avatar for user "user0"
And The following headers should be set
| Content-Type | image/png |
| X-NC-IsCustomAvatar | 1 |
And last avatar is a square of size 512
And last avatar is a single "#FF0000" color
And last avatar is a single "#00FF00" color
And user "anonymous" gets avatar for user "user0"
And The following headers should be set
| Content-Type | image/png |
| X-NC-IsCustomAvatar | 1 |
And last avatar is a square of size 512
And last avatar is a single "#FF0000" color
And last avatar is a single "#00FF00" color
When logged in user deletes the user avatar
Then user "user0" gets avatar for user "user0"
And The following headers should be set
Expand All @@ -168,40 +84,6 @@ Feature: avatar
And last avatar is a square of size 512
And last avatar is not a single color



Scenario: get user avatar with a larger size than the original one
Given Logging in using web as "user0"
And logged in user posts temporary avatar from file "data/coloured-pattern-non-square.png"
And logged in user crops temporary avatar
| x | 384 |
| y | 256 |
| w | 128 |
| h | 128 |
When user "user0" gets avatar for user "user0" with size "192"
Then The following headers should be set
| Content-Type | image/png |
| X-NC-IsCustomAvatar | 1 |
And last avatar is a square of size 512
And last avatar is a single "#FF0000" color

Scenario: get user avatar with a smaller size than the original one
Given Logging in using web as "user0"
And logged in user posts temporary avatar from file "data/coloured-pattern-non-square.png"
And logged in user crops temporary avatar
| x | 384 |
| y | 256 |
| w | 128 |
| h | 128 |
When user "user0" gets avatar for user "user0" with size "96"
Then The following headers should be set
| Content-Type | image/png |
| X-NC-IsCustomAvatar | 1 |
And last avatar is a square of size 512
And last avatar is a single "#FF0000" color



Scenario: get default guest avatar
When user "user0" gets avatar for guest "guest0"
Then The following headers should be set
Expand Down
Loading
Loading