Skip to content

Commit 47ca6cb

Browse files
committed
fix: PR feedback
Signed-off-by: Peter Ringelmann <peter.ringelmann@nextcloud.com>
1 parent c389568 commit 47ca6cb

4 files changed

Lines changed: 23 additions & 21 deletions

File tree

apps/settings/appinfo/routes.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
['name' => 'AuthSettings#create', 'url' => '/settings/personal/authtokens', 'verb' => 'POST' , 'root' => ''],
1515
['name' => 'AuthSettings#update', 'url' => '/settings/personal/authtokens/{id}', 'verb' => 'PUT' , 'root' => ''],
16-
['name' => 'AuthSettings#destroyAll', 'url' => '/settings/personal/authtokens', 'verb' => 'DELETE' , 'root' => ''],
16+
['name' => 'AuthSettings#destroyOthers', 'url' => '/settings/personal/authtokens', 'verb' => 'DELETE' , 'root' => ''],
1717
['name' => 'AuthSettings#destroy', 'url' => '/settings/personal/authtokens/{id}', 'verb' => 'DELETE' , 'root' => ''],
1818
['name' => 'AuthSettings#wipe', 'url' => '/settings/personal/authtokens/wipe/{id}', 'verb' => 'POST' , 'root' => ''],
1919

apps/settings/lib/Controller/AuthSettingsController.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -189,13 +189,15 @@ public function destroy(int $id): JSONResponse {
189189
}
190190

191191
/**
192-
* Wipe-pending tokens are kept: revoking one cancels its pending wipe, so that
193-
* stays a per-token decision.
192+
* Revoke the tokens of the current user other than the session's own.
193+
*
194+
* Wipe-pending tokens are kept too: revoking one cancels its pending wipe, so
195+
* that stays a per-token decision.
194196
*/
195197
#[NoSubAdminRequired]
196198
#[NoAdminRequired]
197199
#[PasswordConfirmationRequired(strict: true)]
198-
public function destroyAll(): JSONResponse {
200+
public function destroyOthers(): JSONResponse {
199201
if ($this->checkAppToken()) {
200202
return new JSONResponse([], Http::STATUS_BAD_REQUEST);
201203
}

apps/settings/src/store/authtoken.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export const useAuthTokenStore = defineStore('auth-token', {
6262
},
6363
getters: {
6464
/**
65-
* Must stay in step with `destroyAll()` server side, or the confirmation
65+
* Must stay in step with `destroyOthers()` server side, or the confirmation
6666
* count disagrees with what actually gets revoked.
6767
*
6868
* @param state Current store state

apps/settings/tests/Controller/AuthSettingsControllerTest.php

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ public function testDestroyWipePendingEmitsCancelledSubject(): void {
272272
$this->assertEquals([], $this->controller->destroy($tokenId)->getData());
273273
}
274274

275-
public function testDestroyAllRevokesEveryTokenButTheCurrent(): void {
275+
public function testDestroyOthersRevokesEveryTokenButTheCurrent(): void {
276276
$currentToken = $this->mockAuthToken(10);
277277
$otherToken = $this->mockAuthToken(11);
278278
$appPassword = $this->mockAuthToken(12);
@@ -297,13 +297,13 @@ public function testDestroyAllRevokesEveryTokenButTheCurrent(): void {
297297

298298
$this->mockActivityManager();
299299

300-
$response = $this->controller->destroyAll();
300+
$response = $this->controller->destroyOthers();
301301

302302
$this->assertSame([11, 12], $revokedIds, 'the current session token must not be revoked');
303303
$this->assertSame(['revoked' => [11, 12]], $response->getData());
304304
}
305305

306-
public function testDestroyAllKeepsWipePendingTokens(): void {
306+
public function testDestroyOthersKeepsWipePendingTokens(): void {
307307
$currentToken = $this->mockAuthToken(10);
308308
$otherToken = $this->mockAuthToken(11);
309309
$wipingToken = $this->mockAuthToken(12, IToken::WIPE_TOKEN);
@@ -318,10 +318,10 @@ public function testDestroyAllKeepsWipePendingTokens(): void {
318318

319319
$this->mockActivityManager();
320320

321-
$this->assertSame(['revoked' => [11]], $this->controller->destroyAll()->getData());
321+
$this->assertSame(['revoked' => [11]], $this->controller->destroyOthers()->getData());
322322
}
323323

324-
public function testDestroyAllPublishesOneAggregateActivity(): void {
324+
public function testDestroyOthersPublishesOneAggregateActivity(): void {
325325
$currentToken = $this->mockAuthToken(10);
326326

327327
$this->session->method('getId')->willReturn('sessionid');
@@ -348,10 +348,10 @@ public function testDestroyAllPublishesOneAggregateActivity(): void {
348348
$this->activityManager->expects($this->once())
349349
->method('publish');
350350

351-
$this->controller->destroyAll();
351+
$this->controller->destroyOthers();
352352
}
353353

354-
public function testDestroyAllWithNothingToRevokePublishesNoActivity(): void {
354+
public function testDestroyOthersWithNothingToRevokePublishesNoActivity(): void {
355355
$currentToken = $this->mockAuthToken(10);
356356

357357
$this->session->method('getId')->willReturn('sessionid');
@@ -361,48 +361,48 @@ public function testDestroyAllWithNothingToRevokePublishesNoActivity(): void {
361361
$this->tokenProvider->expects($this->never())->method('invalidateTokenById');
362362
$this->activityManager->expects($this->never())->method('publish');
363363

364-
$this->assertSame(['revoked' => []], $this->controller->destroyAll()->getData());
364+
$this->assertSame(['revoked' => []], $this->controller->destroyOthers()->getData());
365365
}
366366

367-
public function testDestroyAllWithAppPassword(): void {
367+
public function testDestroyOthersWithAppPassword(): void {
368368
$this->session->expects($this->once())
369369
->method('exists')
370370
->with('app_password')
371371
->willReturn(true);
372372

373373
$this->tokenProvider->expects($this->never())->method('invalidateTokenById');
374374

375-
$response = $this->controller->destroyAll();
375+
$response = $this->controller->destroyOthers();
376376
$this->assertSame(Http::STATUS_BAD_REQUEST, $response->getStatus());
377377
}
378378

379-
public function testDestroyAllWhileImpersonating(): void {
379+
public function testDestroyOthersWhileImpersonating(): void {
380380
$this->userSession->method('getImpersonatingUserID')->willReturn('admin');
381381

382382
$this->tokenProvider->expects($this->never())->method('invalidateTokenById');
383383

384-
$response = $this->controller->destroyAll();
384+
$response = $this->controller->destroyOthers();
385385
$this->assertSame(Http::STATUS_SERVICE_UNAVAILABLE, $response->getStatus());
386386
}
387387

388-
public function testDestroyAllSessionNotAvailable(): void {
388+
public function testDestroyOthersSessionNotAvailable(): void {
389389
$this->session->method('getId')
390390
->willThrowException(new SessionNotAvailableException());
391391

392392
$this->tokenProvider->expects($this->never())->method('invalidateTokenById');
393393

394-
$response = $this->controller->destroyAll();
394+
$response = $this->controller->destroyOthers();
395395
$this->assertSame(Http::STATUS_SERVICE_UNAVAILABLE, $response->getStatus());
396396
}
397397

398-
public function testDestroyAllInvalidSessionToken(): void {
398+
public function testDestroyOthersInvalidSessionToken(): void {
399399
$this->session->method('getId')->willReturn('sessionid');
400400
$this->tokenProvider->method('getToken')
401401
->willThrowException(new InvalidTokenException('Token does not exist'));
402402

403403
$this->tokenProvider->expects($this->never())->method('invalidateTokenById');
404404

405-
$response = $this->controller->destroyAll();
405+
$response = $this->controller->destroyOthers();
406406
$this->assertSame(Http::STATUS_SERVICE_UNAVAILABLE, $response->getStatus());
407407
}
408408

0 commit comments

Comments
 (0)