Skip to content

Commit 1a07c55

Browse files
authored
Merge pull request #53918 from nextcloud/revert-53141-perf/files/setup-fs-basic-auth-request
2 parents cf3ffb3 + 2b50d9b commit 1a07c55

File tree

24 files changed

+937
-51
lines changed

24 files changed

+937
-51
lines changed

apps/dav/appinfo/v1/caldav.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
* SPDX-License-Identifier: AGPL-3.0-only
77
*/
88
// Backends
9-
use OC\Files\SetupManager;
109
use OC\KnownUser\KnownUserService;
1110
use OCA\DAV\CalDAV\CalDavBackend;
1211
use OCA\DAV\CalDAV\CalendarRoot;
@@ -41,7 +40,6 @@
4140
Server::get(IRequest::class),
4241
Server::get(\OC\Authentication\TwoFactorAuth\Manager::class),
4342
Server::get(IThrottler::class),
44-
Server::get(SetupManager::class),
4543
'principals/'
4644
);
4745
$principalBackend = new Principal(

apps/dav/appinfo/v1/carddav.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
* SPDX-License-Identifier: AGPL-3.0-only
77
*/
88
// Backends
9-
use OC\Files\SetupManager;
109
use OC\KnownUser\KnownUserService;
1110
use OCA\DAV\AppInfo\PluginManager;
1211
use OCA\DAV\CalDAV\Proxy\ProxyMapper;
@@ -42,7 +41,6 @@
4241
Server::get(IRequest::class),
4342
Server::get(\OC\Authentication\TwoFactorAuth\Manager::class),
4443
Server::get(IThrottler::class),
45-
Server::get(SetupManager::class),
4644
'principals/'
4745
);
4846
$principalBackend = new Principal(

apps/dav/appinfo/v1/webdav.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
* SPDX-License-Identifier: AGPL-3.0-only
77
*/
88
use OC\Files\Filesystem;
9-
use OC\Files\SetupManager;
109
use OCA\DAV\Connector\Sabre\Auth;
1110
use OCA\DAV\Connector\Sabre\BearerAuth;
1211
use OCA\DAV\Connector\Sabre\ServerFactory;
@@ -56,7 +55,6 @@
5655
Server::get(IRequest::class),
5756
Server::get(\OC\Authentication\TwoFactorAuth\Manager::class),
5857
Server::get(IThrottler::class),
59-
Server::get(SetupManager::class),
6058
'principals/'
6159
);
6260
$authPlugin = new \Sabre\DAV\Auth\Plugin($authBackend);

apps/dav/lib/Connector/Sabre/Auth.php

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
use Exception;
1111
use OC\Authentication\Exceptions\PasswordLoginForbiddenException;
1212
use OC\Authentication\TwoFactorAuth\Manager;
13-
use OC\Files\SetupManager;
1413
use OC\User\Session;
1514
use OCA\DAV\Connector\Sabre\Exception\PasswordLoginForbidden;
1615
use OCA\DAV\Connector\Sabre\Exception\TooManyRequests;
@@ -38,7 +37,6 @@ public function __construct(
3837
private IRequest $request,
3938
private Manager $twoFactorManager,
4039
private IThrottler $throttler,
41-
private SetupManager $setupManager,
4240
string $principalPrefix = 'principals/users/',
4341
) {
4442
$this->principalPrefix = $principalPrefix;
@@ -185,13 +183,10 @@ private function auth(RequestInterface $request, ResponseInterface $response): a
185183
|| ($this->userSession->isLoggedIn() && $this->session->get(self::DAV_AUTHENTICATED) === $this->userSession->getUser()->getUID() && empty($request->getHeader('Authorization')))
186184
|| \OC_User::handleApacheAuth()
187185
) {
188-
$user = $this->userSession->getUser();
189-
$this->setupManager->setupForUser($user);
190-
191-
$uid = $user->getUID();
192-
$this->currentUser = $uid;
186+
$user = $this->userSession->getUser()->getUID();
187+
$this->currentUser = $user;
193188
$this->session->close();
194-
return [true, $this->principalPrefix . $uid];
189+
return [true, $this->principalPrefix . $user];
195190
}
196191
}
197192

@@ -206,12 +201,6 @@ private function auth(RequestInterface $request, ResponseInterface $response): a
206201
$response->setStatus(Http::STATUS_UNAUTHORIZED);
207202
throw new \Sabre\DAV\Exception\NotAuthenticated('Cannot authenticate over ajax calls');
208203
}
209-
210-
$user = $this->userSession->getUser();
211-
if ($user !== null) {
212-
$this->setupManager->setupForUser($user);
213-
}
214-
215204
return $data;
216205
}
217206
}

apps/dav/lib/Server.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
namespace OCA\DAV;
99

1010
use OC\Files\Filesystem;
11-
use OC\Files\SetupManager;
1211
use OCA\DAV\AppInfo\PluginManager;
1312
use OCA\DAV\BulkUpload\BulkUploadPlugin;
1413
use OCA\DAV\CalDAV\BirthdayCalendar\EnablePlugin;
@@ -133,8 +132,7 @@ public function __construct(
133132
\OCP\Server::get(IUserSession::class),
134133
\OCP\Server::get(IRequest::class),
135134
\OCP\Server::get(\OC\Authentication\TwoFactorAuth\Manager::class),
136-
\OCP\Server::get(IThrottler::class),
137-
\OCP\Server::get(SetupManager::class),
135+
\OCP\Server::get(IThrottler::class)
138136
);
139137

140138
// Set URL explicitly due to reverse-proxy situations

apps/dav/tests/unit/Connector/Sabre/AuthTest.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
use OC\Authentication\Exceptions\PasswordLoginForbiddenException;
1212
use OC\Authentication\TwoFactorAuth\Manager;
13-
use OC\Files\SetupManager;
1413
use OC\User\Session;
1514
use OCA\DAV\Connector\Sabre\Auth;
1615
use OCA\DAV\Connector\Sabre\Exception\PasswordLoginForbidden;
@@ -36,7 +35,6 @@ class AuthTest extends TestCase {
3635
private IRequest&MockObject $request;
3736
private Manager&MockObject $twoFactorManager;
3837
private IThrottler&MockObject $throttler;
39-
private SetupManager&MockObject $setupManager;
4038
private Auth $auth;
4139

4240
protected function setUp(): void {
@@ -46,14 +44,12 @@ protected function setUp(): void {
4644
$this->request = $this->createMock(IRequest::class);
4745
$this->twoFactorManager = $this->createMock(Manager::class);
4846
$this->throttler = $this->createMock(IThrottler::class);
49-
$this->setupManager = $this->createMock(SetupManager::class);
5047
$this->auth = new Auth(
5148
$this->session,
5249
$this->userSession,
5350
$this->request,
5451
$this->twoFactorManager,
55-
$this->throttler,
56-
$this->setupManager,
52+
$this->throttler
5753
);
5854
}
5955

@@ -583,7 +579,7 @@ public function testAuthenticateValidCredentials(): void {
583579
->method('getUID')
584580
->willReturn('MyTestUser');
585581
$this->userSession
586-
->expects($this->exactly(4))
582+
->expects($this->exactly(3))
587583
->method('getUser')
588584
->willReturn($user);
589585
$response = $this->auth->check($server->httpRequest, $server->httpResponse);

apps/settings/src/components/PersonalInfo/AvatarSection.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,8 @@ export default {
182182
if (data.status === 'success') {
183183
this.handleAvatarUpdate(false)
184184
} else if (data.data === 'notsquare') {
185-
this.$refs.cropper.replace(data.image)
185+
const tempAvatar = generateUrl('/avatar/tmp') + '?requesttoken=' + encodeURIComponent(OC.requestToken) + '#' + Math.floor(Math.random() * 1000)
186+
this.$refs.cropper.replace(tempAvatar)
186187
this.showCropper = true
187188
} else {
188189
showError(data.data.message)
2.39 KB
Loading
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors
2+
SPDX-License-Identifier: AGPL-3.0-or-later

build/integration/features/avatar.feature

Lines changed: 123 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,32 @@ Feature: avatar
2121
And last avatar is a square of size 512
2222
And last avatar is not a single color
2323

24+
25+
26+
Scenario: get temporary non-square user avatar before cropping it
27+
Given Logging in using web as "user0"
28+
And logged in user posts temporary avatar from file "data/coloured-pattern-non-square.png"
29+
When logged in user gets temporary avatar
30+
Then The following headers should be set
31+
| Content-Type | image/png |
32+
# "last avatar" also includes the last temporary avatar
33+
And last avatar is not a square
34+
And last avatar is not a single color
35+
36+
Scenario: get non-square user avatar before cropping it
37+
Given Logging in using web as "user0"
38+
And logged in user posts temporary avatar from file "data/coloured-pattern-non-square.png"
39+
# Avatar needs to be cropped to finish setting it
40+
When user "user0" gets avatar for user "user0"
41+
Then The following headers should be set
42+
| Content-Type | image/png |
43+
| X-NC-IsCustomAvatar | 0 |
44+
And last avatar is a square of size 512
45+
And last avatar is not a single color
46+
2447
Scenario: set square user avatar from file
2548
Given Logging in using web as "user0"
26-
When logged in user posts avatar from file "data/green-square-256.png"
49+
When logged in user posts temporary avatar from file "data/green-square-256.png"
2750
And user "user0" gets avatar for user "user0"
2851
And The following headers should be set
2952
| Content-Type | image/png |
@@ -41,7 +64,7 @@ Feature: avatar
4164
Scenario: set square user avatar from internal path
4265
Given user "user0" uploads file "data/green-square-256.png" to "/internal-green-square-256.png"
4366
And Logging in using web as "user0"
44-
When logged in user posts avatar from internal path "internal-green-square-256.png"
67+
When logged in user posts temporary avatar from internal path "internal-green-square-256.png"
4568
And user "user0" gets avatar for user "user0" with size "64"
4669
And The following headers should be set
4770
| Content-Type | image/png |
@@ -55,21 +78,82 @@ Feature: avatar
5578
And last avatar is a square of size 64
5679
And last avatar is a single "#00FF00" color
5780

58-
Scenario: delete user avatar
81+
Scenario: set non-square user avatar from file
5982
Given Logging in using web as "user0"
60-
And logged in user posts avatar from file "data/green-square-256.png"
83+
When logged in user posts temporary avatar from file "data/coloured-pattern-non-square.png"
84+
And logged in user crops temporary avatar
85+
| x | 384 |
86+
| y | 256 |
87+
| w | 128 |
88+
| h | 128 |
89+
Then logged in user gets temporary avatar with 404
6190
And user "user0" gets avatar for user "user0"
6291
And The following headers should be set
6392
| Content-Type | image/png |
6493
| X-NC-IsCustomAvatar | 1 |
6594
And last avatar is a square of size 512
66-
And last avatar is a single "#00FF00" color
95+
And last avatar is a single "#FF0000" color
6796
And user "anonymous" gets avatar for user "user0"
6897
And The following headers should be set
6998
| Content-Type | image/png |
7099
| X-NC-IsCustomAvatar | 1 |
71100
And last avatar is a square of size 512
101+
And last avatar is a single "#FF0000" color
102+
103+
Scenario: set non-square user avatar from internal path
104+
Given user "user0" uploads file "data/coloured-pattern-non-square.png" to "/internal-coloured-pattern-non-square.png"
105+
And Logging in using web as "user0"
106+
When logged in user posts temporary avatar from internal path "internal-coloured-pattern-non-square.png"
107+
And logged in user crops temporary avatar
108+
| x | 704 |
109+
| y | 320 |
110+
| w | 64 |
111+
| h | 64 |
112+
Then logged in user gets temporary avatar with 404
113+
And user "user0" gets avatar for user "user0" with size "64"
114+
And The following headers should be set
115+
| Content-Type | image/png |
116+
| X-NC-IsCustomAvatar | 1 |
117+
And last avatar is a square of size 64
72118
And last avatar is a single "#00FF00" color
119+
And user "anonymous" gets avatar for user "user0" with size "64"
120+
And The following headers should be set
121+
| Content-Type | image/png |
122+
| X-NC-IsCustomAvatar | 1 |
123+
And last avatar is a square of size 64
124+
And last avatar is a single "#00FF00" color
125+
126+
Scenario: cropped user avatar needs to be squared
127+
Given Logging in using web as "user0"
128+
And logged in user posts temporary avatar from file "data/coloured-pattern-non-square.png"
129+
When logged in user crops temporary avatar with 400
130+
| x | 384 |
131+
| y | 256 |
132+
| w | 192 |
133+
| h | 128 |
134+
135+
136+
137+
Scenario: delete user avatar
138+
Given Logging in using web as "user0"
139+
And logged in user posts temporary avatar from file "data/coloured-pattern-non-square.png"
140+
And logged in user crops temporary avatar
141+
| x | 384 |
142+
| y | 256 |
143+
| w | 128 |
144+
| h | 128 |
145+
And user "user0" gets avatar for user "user0"
146+
And The following headers should be set
147+
| Content-Type | image/png |
148+
| X-NC-IsCustomAvatar | 1 |
149+
And last avatar is a square of size 512
150+
And last avatar is a single "#FF0000" color
151+
And user "anonymous" gets avatar for user "user0"
152+
And The following headers should be set
153+
| Content-Type | image/png |
154+
| X-NC-IsCustomAvatar | 1 |
155+
And last avatar is a square of size 512
156+
And last avatar is a single "#FF0000" color
73157
When logged in user deletes the user avatar
74158
Then user "user0" gets avatar for user "user0"
75159
And The following headers should be set
@@ -84,6 +168,40 @@ Feature: avatar
84168
And last avatar is a square of size 512
85169
And last avatar is not a single color
86170

171+
172+
173+
Scenario: get user avatar with a larger size than the original one
174+
Given Logging in using web as "user0"
175+
And logged in user posts temporary avatar from file "data/coloured-pattern-non-square.png"
176+
And logged in user crops temporary avatar
177+
| x | 384 |
178+
| y | 256 |
179+
| w | 128 |
180+
| h | 128 |
181+
When user "user0" gets avatar for user "user0" with size "192"
182+
Then The following headers should be set
183+
| Content-Type | image/png |
184+
| X-NC-IsCustomAvatar | 1 |
185+
And last avatar is a square of size 512
186+
And last avatar is a single "#FF0000" color
187+
188+
Scenario: get user avatar with a smaller size than the original one
189+
Given Logging in using web as "user0"
190+
And logged in user posts temporary avatar from file "data/coloured-pattern-non-square.png"
191+
And logged in user crops temporary avatar
192+
| x | 384 |
193+
| y | 256 |
194+
| w | 128 |
195+
| h | 128 |
196+
When user "user0" gets avatar for user "user0" with size "96"
197+
Then The following headers should be set
198+
| Content-Type | image/png |
199+
| X-NC-IsCustomAvatar | 1 |
200+
And last avatar is a square of size 512
201+
And last avatar is a single "#FF0000" color
202+
203+
204+
87205
Scenario: get default guest avatar
88206
When user "user0" gets avatar for guest "guest0"
89207
Then The following headers should be set

0 commit comments

Comments
 (0)