From 31f0539dc0b4bc2588802f983531d95794b47474 Mon Sep 17 00:00:00 2001 From: "J. King" Date: Thu, 31 Dec 2020 17:03:08 -0500 Subject: [PATCH] Implement Miniflux user deletion --- lib/REST/Miniflux/V1.php | 9 +++++++++ tests/cases/REST/Miniflux/TestV1.php | 28 ++++++++++++++++++++++++++-- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/lib/REST/Miniflux/V1.php b/lib/REST/Miniflux/V1.php index 94cdab0e..12f509a3 100644 --- a/lib/REST/Miniflux/V1.php +++ b/lib/REST/Miniflux/V1.php @@ -480,6 +480,15 @@ class V1 extends \JKingWeb\Arsse\REST\AbstractHandler { return new Response($out); } + protected function deleteUserByNum(array $path): ResponseInterface { + try { + Arsse::$user->remove(Arsse::$user->lookup((int) $path[1])); + } catch (ExceptionConflict $e) { + return new ErrorResponse("404", 404); + } + return new EmptyResponse(204); + } + protected function getCategories(): ResponseInterface { $out = []; $meta = Arsse::$user->propertiesGet(Arsse::$user->id, false); diff --git a/tests/cases/REST/Miniflux/TestV1.php b/tests/cases/REST/Miniflux/TestV1.php index 94fad0d8..3851ab32 100644 --- a/tests/cases/REST/Miniflux/TestV1.php +++ b/tests/cases/REST/Miniflux/TestV1.php @@ -371,11 +371,35 @@ class TestV1 extends \JKingWeb\Arsse\Test\AbstractTest { } public function testAddAUserWithoutAuthority(): void { - Arsse::$user = $this->createMock(User::class); - Arsse::$user->method("propertiesGet")->willReturn(['num' => 1, 'admin' => false]); $this->assertMessage(new ErrorResponse("403", 403), $this->req("POST", "/users", [])); } + public function testDeleteAUser(): void { + Arsse::$user = $this->createMock(User::class); + Arsse::$user->method("propertiesGet")->willReturn(['admin' => true]); + Arsse::$user->method("lookup")->willReturn("john.doe@example.com"); + Arsse::$user->method("remove")->willReturn(true); + Arsse::$user->expects($this->exactly(1))->method("lookup")->with(2112); + Arsse::$user->expects($this->exactly(1))->method("remove")->with("john.doe@example.com"); + $this->assertMessage(new EmptyResponse(204), $this->req("DELETE", "/users/2112")); + } + + public function testDeleteAMissingUser(): void { + Arsse::$user = $this->createMock(User::class); + Arsse::$user->method("propertiesGet")->willReturn(['admin' => true]); + Arsse::$user->method("lookup")->willThrowException(new ExceptionConflict("doesNotExist")); + Arsse::$user->method("remove")->willReturn(true); + Arsse::$user->expects($this->exactly(1))->method("lookup")->with(2112); + Arsse::$user->expects($this->exactly(0))->method("remove"); + $this->assertMessage(new ErrorResponse("404", 404), $this->req("DELETE", "/users/2112")); + } + + public function testDeleteAUserWithoutAuthority(): void { + Arsse::$user->expects($this->exactly(0))->method("lookup"); + Arsse::$user->expects($this->exactly(0))->method("remove"); + $this->assertMessage(new ErrorResponse("403", 403), $this->req("DELETE", "/users/2112")); + } + public function testListCategories(): void { \Phake::when(Arsse::$db)->folderList->thenReturn(new Result($this->v([ ['id' => 1, 'name' => "Science"],