diff options
author | Joas Schilling <213943+nickvergessen@users.noreply.github.com> | 2023-05-05 14:59:18 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-05 14:59:18 +0200 |
commit | 49fb966d70c29e6573885998935de7d1a3d6b2e9 (patch) | |
tree | 06c10a54045ed5dfe70764919b90882fb64a577f /tests | |
parent | 3bf69154b8656db29559cfc0adb14fb0d9c60435 (diff) | |
parent | bd57c47c0bcb740cc9d2c67b5143fc0df0cab7db (diff) |
Merge pull request #9456 from nextcloud/techdebt/noid/make-checksum-verification-generic
techdebt(api): Make the checksum verification generic so it can be re…
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); + } + } } |