From cb5c04dcb12a5d01de4c8e673520aff09833bf03 Mon Sep 17 00:00:00 2001 From: Vitor Mattos Date: Mon, 9 Dec 2024 12:25:06 -0300 Subject: [PATCH] fix: integration and unit tests Signed-off-by: Vitor Mattos --- tests/Api/ApiTestCase.php | 4 +-- .../Api/Controller/AccountControllerTest.php | 14 +++++----- tests/Api/Controller/AdminControllerTest.php | 6 ++--- tests/Api/Controller/FileControllerTest.php | 12 ++++----- .../Controller/FileElementControllerTest.php | 6 ++--- tests/Api/Controller/NotifyControllerTest.php | 4 +-- .../RequestSignatureControllerTest.php | 8 +++--- .../Api/Controller/SettingControllerTest.php | 2 +- .../Api/Controller/SignFileControllerTest.php | 26 +++++++++---------- 9 files changed, 41 insertions(+), 41 deletions(-) diff --git a/tests/Api/ApiTestCase.php b/tests/Api/ApiTestCase.php index 9727e49db8..345ef92c61 100644 --- a/tests/Api/ApiTestCase.php +++ b/tests/Api/ApiTestCase.php @@ -40,7 +40,7 @@ class ApiTestCase extends TestCase { public function setUp(): void { parent::setUp(); $data = json_decode(file_get_contents('openapi-full.json'), true); - $data['servers'][] = ['url' => '/ocs/v2.php/ocsapp/apps/libresign/api/v1']; + $data['servers'][] = ['url' => '/ocs/v2.php/ocsapp/apps/libresign']; $data = $this->removeBasePath($data); /** @var OpenApiSchema */ $schema = \ByJG\ApiTools\Base\Schema::getInstance($data); @@ -61,7 +61,7 @@ public function setUp(): void { private function removeBasePath(array $data): array { $cleaned = []; foreach ($data['paths'] as $key => $value) { - $key = preg_replace('~^' . '/ocs/v2.php/apps/libresign/api/{apiVersion}' . '~', '', $key); + $key = preg_replace('~^/ocs/v2.php/apps/libresign~', '', $key); $cleaned[$key] = $value; } $data['paths'] = $cleaned; diff --git a/tests/Api/Controller/AccountControllerTest.php b/tests/Api/Controller/AccountControllerTest.php index 6e2accd89c..e4d0593988 100644 --- a/tests/Api/Controller/AccountControllerTest.php +++ b/tests/Api/Controller/AccountControllerTest.php @@ -31,7 +31,7 @@ public function testAccountCreateWithInvalidUuid():void { 'password' => 'secret', 'signPassword' => 'secretToSign' ]) - ->withPath('/account/create/1234564789') + ->withPath('/api/v1/account/create/1234564789') ->assertResponseCode(422); $response = $this->assertRequest(); @@ -84,7 +84,7 @@ public function testAccountCreateWithSuccess():void { 'password' => 'secret', 'signPassword' => 'secretToSign' ]) - ->withPath('/account/create/' . $signers[0]->getUuid()); + ->withPath('/api/v1/account/create/' . $signers[0]->getUuid()); $this->markUserExists('guest-user@test.coop'); $this->assertRequest(); @@ -112,7 +112,7 @@ public function testPostProfileFilesWithInvalidData():void { ] ] ]) - ->withPath('/account/files') + ->withPath('/api/v1/account/files') ->assertResponseCode(401); $this->assertRequest(); @@ -140,7 +140,7 @@ public function testPostAccountAddFilesWithSuccess():void { ] ] ]) - ->withPath('/account/files'); + ->withPath('/api/v1/account/files'); $this->assertRequest(); } @@ -150,7 +150,7 @@ public function testPostAccountAddFilesWithSuccess():void { */ public function testMeWithoutAuthenticatedUser():void { $this->request - ->withPath('/account/me') + ->withPath('/api/v1/account/me') ->assertResponseCode(404); $this->assertRequest(); @@ -162,7 +162,7 @@ public function testMeWithoutAuthenticatedUser():void { public function testMeWithAuthenticatedUser():void { $this->createAccount('username', 'password'); $this->request - ->withPath('/account/me') + ->withPath('/api/v1/account/me') ->withRequestHeader([ 'Authorization' => 'Basic ' . base64_encode('username:password') ]); @@ -181,7 +181,7 @@ public function testApprovalListWithSuccess():void { ]); $this->request - ->withPath('/account/files/approval/list') + ->withPath('/api/v1/account/files/approval/list') ->withRequestHeader([ 'Authorization' => 'Basic ' . base64_encode('allowapprove:password') ]); diff --git a/tests/Api/Controller/AdminControllerTest.php b/tests/Api/Controller/AdminControllerTest.php index 441d8a06e0..201683b523 100644 --- a/tests/Api/Controller/AdminControllerTest.php +++ b/tests/Api/Controller/AdminControllerTest.php @@ -25,7 +25,7 @@ public function testLoadCertificate():void { ->withRequestHeader([ 'Authorization' => 'Basic ' . base64_encode('admintest:password') ]) - ->withPath('/admin/certificate'); + ->withPath('/api/v1/admin/certificate'); $this->assertRequest(); } @@ -65,7 +65,7 @@ public function testGenerateCertificateWithSuccess():void { 'Authorization' => 'Basic ' . base64_encode('admintest:password'), 'Content-Type' => 'application/json' ]) - ->withPath('/admin/certificate/cfssl') + ->withPath('/api/v1/admin/certificate/cfssl') ->withRequestBody($cfsslConfig); // Make and test request mach with schema @@ -103,7 +103,7 @@ public function testGenerateCertificateWithFailure():void { 'Authorization' => 'Basic ' . base64_encode('admintest:password'), 'Content-Type' => 'application/json' ]) - ->withPath('/admin/certificate/openssl') + ->withPath('/api/v1/admin/certificate/openssl') ->withRequestBody([ 'rootCert' => [ 'commonName' => 'CommonName', diff --git a/tests/Api/Controller/FileControllerTest.php b/tests/Api/Controller/FileControllerTest.php index 8a54b82682..7c371f1283 100644 --- a/tests/Api/Controller/FileControllerTest.php +++ b/tests/Api/Controller/FileControllerTest.php @@ -22,7 +22,7 @@ public function testValidateUsignUuidWithInvalidData():void { $this->mockAppConfig([]); $this->request - ->withPath('/file/validate/uuid/invalid') + ->withPath('/api/v1/file/validate/uuid/invalid') ->assertResponseCode(404); $response = $this->assertRequest(); @@ -35,7 +35,7 @@ public function testValidateUsignUuidWithInvalidData():void { */ public function testValidateUsignFileIdWithInvalidData():void { $this->request - ->withPath('/file/validate/file_id/171') + ->withPath('/api/v1/file/validate/file_id/171') ->assertResponseCode(404); $response = $this->assertRequest(); @@ -64,7 +64,7 @@ public function testValidateWithSuccessUsingUnloggedUser():void { ]); $this->request - ->withPath('/file/validate/uuid/' . $file->getUuid()); + ->withPath('/api/v1/file/validate/uuid/' . $file->getUuid()); $response = $this->assertRequest(); $body = json_decode($response->getBody()->getContents(), true); @@ -106,7 +106,7 @@ public function testValidateWithSuccessUsingSigner():void { ->withRequestHeader([ 'Authorization' => 'Basic ' . base64_encode('username:password') ]) - ->withPath('/file/validate/uuid/' . $file->getUuid()); + ->withPath('/api/v1/file/validate/uuid/' . $file->getUuid()); $response = $this->assertRequest(); $body = json_decode($response->getBody()->getContents(), true); @@ -124,7 +124,7 @@ public function testControllerListWithEmptyData():void { ->withRequestHeader([ 'Authorization' => 'Basic ' . base64_encode('username:password') ]) - ->withPath('/file/list'); + ->withPath('/api/v1/file/list'); $response = $this->assertRequest(); $body = json_decode($response->getBody()->getContents(), true); @@ -144,7 +144,7 @@ public function testSendNewFile():void { 'Authorization' => 'Basic ' . base64_encode('allowrequestsign:password'), 'Content-Type' => 'application/json', ]) - ->withPath('/file') + ->withPath('/api/v1/file') ->withMethod('POST') ->withRequestBody([ 'name' => 'test', diff --git a/tests/Api/Controller/FileElementControllerTest.php b/tests/Api/Controller/FileElementControllerTest.php index d899e51c1f..3436bbbf68 100644 --- a/tests/Api/Controller/FileElementControllerTest.php +++ b/tests/Api/Controller/FileElementControllerTest.php @@ -38,7 +38,7 @@ public function testPostSuccess():array { $this->mockAppConfig([]); $this->request - ->withPath('/file-element/' . $file->getUuid()) + ->withPath('/api/v1/file-element/' . $file->getUuid()) ->withMethod('POST') ->withRequestHeader([ 'Authorization' => 'Basic ' . base64_encode('username:password'), @@ -72,7 +72,7 @@ public function testPatchSuccess($params):array { extract($params); $signers = $this->getSignersFromFileId($file->getId()); $this->request - ->withPath('/file-element/' . $file->getUuid() . '/' . $fileElementId) + ->withPath('/api/v1/file-element/' . $file->getUuid() . '/' . $fileElementId) ->withMethod('PATCH') ->withRequestHeader([ 'Authorization' => 'Basic ' . base64_encode('username:password'), @@ -106,7 +106,7 @@ public function testDeleteSuccess($params):void { $this->createAccount('username', 'password'); extract($params); $this->request - ->withPath('/file-element/' . $file->getUuid() . '/' . $fileElementId) + ->withPath('/api/v1/file-element/' . $file->getUuid() . '/' . $fileElementId) ->withMethod('DELETE') ->withRequestHeader([ 'Authorization' => 'Basic ' . base64_encode('username:password'), diff --git a/tests/Api/Controller/NotifyControllerTest.php b/tests/Api/Controller/NotifyControllerTest.php index e80a6d87cf..f1627a5126 100644 --- a/tests/Api/Controller/NotifyControllerTest.php +++ b/tests/Api/Controller/NotifyControllerTest.php @@ -33,7 +33,7 @@ public function testNotifySignersWithError():void { ] ] ]) - ->withPath('/notify/signers') + ->withPath('/api/v1/notify/signers') ->assertResponseCode(401); $this->assertRequest(); @@ -74,7 +74,7 @@ public function testNotifySignersWithSuccess():void { ] ] ]) - ->withPath('/notify/signers'); + ->withPath('/api/v1/notify/signers'); $this->assertRequest(); } diff --git a/tests/Api/Controller/RequestSignatureControllerTest.php b/tests/Api/Controller/RequestSignatureControllerTest.php index 0fd4b9de87..45766ee368 100644 --- a/tests/Api/Controller/RequestSignatureControllerTest.php +++ b/tests/Api/Controller/RequestSignatureControllerTest.php @@ -21,7 +21,7 @@ public function testPostRegisterWithValidationFailure():void { $this->createAccount('username', 'password'); $this->request ->withMethod('POST') - ->withPath('/request-signature') + ->withPath('/api/v1/request-signature') ->withRequestHeader([ 'Authorization' => 'Basic ' . base64_encode('username:password'), 'Content-Type' => 'application/json' @@ -51,7 +51,7 @@ public function testPostRegisterWithSuccess():void { $this->request ->withMethod('POST') - ->withPath('/request-signature') + ->withPath('/api/v1/request-signature') ->withRequestHeader([ 'Authorization' => 'Basic ' . base64_encode('allowrequestsign:password'), 'Content-Type' => 'application/json' @@ -82,7 +82,7 @@ public function testPatchRegisterWithValidationFailure():void { $this->createAccount('username', 'password'); $this->request ->withMethod('PATCH') - ->withPath('/request-signature') + ->withPath('/api/v1/request-signature') ->withRequestHeader([ 'Authorization' => 'Basic ' . base64_encode('username:password'), 'Content-Type' => 'application/json' @@ -125,7 +125,7 @@ public function testPatchRegisterWithSuccess():void { $this->request ->withMethod('PATCH') - ->withPath('/request-signature') + ->withPath('/api/v1/request-signature') ->withRequestHeader([ 'Authorization' => 'Basic ' . base64_encode('allowrequestsign:password'), 'Content-Type' => 'application/json' diff --git a/tests/Api/Controller/SettingControllerTest.php b/tests/Api/Controller/SettingControllerTest.php index 41a5e21ba0..4c26fdaed4 100644 --- a/tests/Api/Controller/SettingControllerTest.php +++ b/tests/Api/Controller/SettingControllerTest.php @@ -23,7 +23,7 @@ public function testHasRootCertReturnSuccess():void { ->withRequestHeader([ 'Authorization' => 'Basic ' . base64_encode('username:password') ]) - ->withPath('/setting/has-root-cert'); + ->withPath('/api/v1/setting/has-root-cert'); $this->assertRequest(); } diff --git a/tests/Api/Controller/SignFileControllerTest.php b/tests/Api/Controller/SignFileControllerTest.php index 260679143b..873e1532fe 100644 --- a/tests/Api/Controller/SignFileControllerTest.php +++ b/tests/Api/Controller/SignFileControllerTest.php @@ -31,7 +31,7 @@ public function testSignUsingFileIdWithInvalidFileToSign():void { 'Authorization' => 'Basic ' . base64_encode('allowrequestsign:password'), 'Content-Type' => 'application/json' ]) - ->withPath('/sign/file_id/171') + ->withPath('/api/v1/sign/file_id/171') ->withRequestBody([ 'identifyValue' => 'secretPassword', 'method' => 'password', @@ -54,7 +54,7 @@ public function testSignUsingFileIdWithInvalidUuidToSign():void { 'Authorization' => 'Basic ' . base64_encode('username:password'), 'Content-Type' => 'application/json' ]) - ->withPath('/sign/uuid/invalid') + ->withPath('/api/v1/sign/uuid/invalid') ->withRequestBody([ 'identifyValue' => 'secretPassword', 'method' => 'password', @@ -96,7 +96,7 @@ public function testSignUsingFileIdWithAlreadySignedFile():void { 'Authorization' => 'Basic ' . base64_encode('username:password'), 'Content-Type' => 'application/json' ]) - ->withPath('/sign/uuid/' . $signers[0]->getUuid()) + ->withPath('/api/v1/sign/uuid/' . $signers[0]->getUuid()) ->withRequestBody([ 'identifyValue' => 'secretPassword', 'method' => 'password', @@ -139,7 +139,7 @@ public function testSignUsingFileIdWithNotFoundFile():void { 'Authorization' => 'Basic ' . base64_encode('username:password'), 'Content-Type' => 'application/json' ]) - ->withPath('/sign/uuid/' . $signers[0]->getUuid()) + ->withPath('/api/v1/sign/uuid/' . $signers[0]->getUuid()) ->withRequestBody([ 'identifyValue' => 'secretPassword', 'method' => 'password', @@ -179,7 +179,7 @@ public function testSignUsingFileIdWithoutPfx():void { 'Authorization' => 'Basic ' . base64_encode('username:password'), 'Content-Type' => 'application/json' ]) - ->withPath('/sign/uuid/' . $signers[0]->getUuid()) + ->withPath('/api/v1/sign/uuid/' . $signers[0]->getUuid()) ->withRequestBody([ 'password' => '' ]) @@ -240,7 +240,7 @@ public function testSignUsingFileIdWithEmptyCertificatePassword():void { 'Authorization' => 'Basic ' . base64_encode('username:password'), 'Content-Type' => 'application/json' ]) - ->withPath('/sign/uuid/' . $signers[0]->getUuid()) + ->withPath('/api/v1/sign/uuid/' . $signers[0]->getUuid()) ->withRequestBody([ 'password' => '' ]) @@ -308,7 +308,7 @@ public function testSignUsingFileIdWithSuccess():void { 'Authorization' => 'Basic ' . base64_encode('username:password'), 'Content-Type' => 'application/json' ]) - ->withPath('/sign/uuid/' . $signers[0]->getUuid()) + ->withPath('/api/v1/sign/uuid/' . $signers[0]->getUuid()) ->withRequestBody([ 'identifyValue' => 'secretPassword', 'method' => 'password', @@ -354,7 +354,7 @@ public function testAccountSignatureEndpointWithSuccess():void { ->withRequestBody([ 'signPassword' => 'password' ]) - ->withPath('/account/signature'); + ->withPath('/api/v1/account/signature'); $home = $user->getHome(); $this->assertFileDoesNotExist($home . '/files/LibreSign/signature.pfx'); @@ -377,7 +377,7 @@ public function testAccountSignatureEndpointWithFailure():void { ->withRequestBody([ 'signPassword' => '' ]) - ->withPath('/account/signature') + ->withPath('/api/v1/account/signature') ->assertResponseCode(401); $this->assertRequest(); @@ -411,7 +411,7 @@ public function testDeleteSignFileIdSignRequestIdWithSuccess():void { ->withRequestHeader([ 'Authorization' => 'Basic ' . base64_encode('allowrequestsign:password') ]) - ->withPath('/sign/file_id/' . $file->getNodeId() . '/' . $signers[0]->getId()); + ->withPath('/api/v1/sign/file_id/' . $file->getNodeId() . '/' . $signers[0]->getId()); $this->assertRequest(); } @@ -427,7 +427,7 @@ public function testDeleteSignFileIdSignRequestIdWithError():void { ->withRequestHeader([ 'Authorization' => 'Basic ' . base64_encode('username:password') ]) - ->withPath('/sign/file_id/171/171') + ->withPath('/api/v1/sign/file_id/171/171') ->assertResponseCode(422); $this->assertRequest(); @@ -460,7 +460,7 @@ public function testDeleteUsingSignFileIdWithSuccess():void { ->withRequestHeader([ 'Authorization' => 'Basic ' . base64_encode('allowrequestsign:password') ]) - ->withPath('/sign/file_id/' . $file->getNodeId()); + ->withPath('/api/v1/sign/file_id/' . $file->getNodeId()); $this->assertRequest(); } @@ -476,7 +476,7 @@ public function testDeleteUsingSignFileIdWithError():void { ->withRequestHeader([ 'Authorization' => 'Basic ' . base64_encode('username:password') ]) - ->withPath('/sign/file_id/171') + ->withPath('/api/v1/sign/file_id/171') ->assertResponseCode(422); $this->assertRequest();