summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2023-05-04 21:39:22 +0200
committerJoas Schilling <coding@schilljs.com>2023-05-04 21:39:22 +0200
commit6d7b2db9135336386a1d96b9a43b415b1aafdaae (patch)
tree63ce4968c3fe0ea9a2a061925f5394f08568614d /tests
parentcb67aaadedb7263d7a7e771a8457fd62b8f80ef7 (diff)
techdebt(api): Make the checksum verification generic so it can be reused
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/php/Service/ChecksumVerificationServiceTest.php (renamed from tests/php/Service/SIPBridgeServiceTest.php)41
1 files changed, 20 insertions, 21 deletions
diff --git a/tests/php/Service/SIPBridgeServiceTest.php b/tests/php/Service/ChecksumVerificationServiceTest.php
index 59f4b681e..be09ffa77 100644
--- a/tests/php/Service/SIPBridgeServiceTest.php
+++ b/tests/php/Service/ChecksumVerificationServiceTest.php
@@ -26,35 +26,20 @@ declare(strict_types=1);
namespace OCA\Talk\Tests\php\Service;
use OCA\Talk\Exceptions\UnauthorizedException;
-use OCA\Talk\Service\SIPBridgeService;
+use OCA\Talk\Service\ChecksumVerificationService;
use Test\TestCase;
-class SIPBridgeServiceTest extends TestCase {
- /** @var SIPBridgeService */
- protected $SIPBridgeService;
+class ChecksumVerificationServiceTest extends TestCase {
+ protected ChecksumVerificationService $service;
public function setUp(): void {
parent::setUp();
- $this->SIPBridgeService = new SIPBridgeService();
+ $this->service = new ChecksumVerificationService();
}
- /**
- * @dataProvider dataValidateSIPBridgeRequest
- */
- public function testValidateSIPBridgeRequest(string $random, string $checksum, string $secret, string $token, string $exceptionMessage, bool $expectedReturn): void {
- if ($exceptionMessage) {
- $this->expectException(UnauthorizedException::class);
- $this->expectExceptionMessage($exceptionMessage);
- }
- $actual = $this->SIPBridgeService->validateSIPBridgeRequest($random, $checksum, $secret, $token);
- if (!$exceptionMessage) {
- $this->assertEquals($expectedReturn, $actual);
- }
- }
-
- public function dataValidateSIPBridgeRequest(): array {
- $validRandom = md5((string) rand());
+ public function dataValidateRequest(): array {
+ $validRandom = md5(random_bytes(15));
$fakeData = json_encode(['fake' => 'data']);
$validSecret = 'valid secret';
$validChecksum = hash_hmac('sha256', $validRandom . $fakeData, $validSecret);
@@ -67,4 +52,18 @@ class SIPBridgeServiceTest extends TestCase {
[$validRandom, $validChecksum, $validSecret, $fakeData, '', true],
];
}
+
+ /**
+ * @dataProvider dataValidateRequest
+ */
+ public function testValidateRequest(string $random, string $checksum, string $secret, string $token, string $exceptionMessage, bool $expectedReturn): void {
+ if ($exceptionMessage) {
+ $this->expectException(UnauthorizedException::class);
+ $this->expectExceptionMessage($exceptionMessage);
+ }
+ $actual = $this->service->validateRequest($random, $checksum, $secret, $token);
+ if (!$exceptionMessage) {
+ $this->assertEquals($expectedReturn, $actual);
+ }
+ }
}