2024-08-13 18:54:24 +00:00
|
|
|
<?php
|
|
|
|
// HmacVerificationTest.php
|
|
|
|
// Created: 2024-08-13
|
2024-11-13 23:17:29 +00:00
|
|
|
// Updated: 2024-11-13
|
2024-08-13 18:54:24 +00:00
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
use PHPUnit\Framework\Attributes\CoversClass;
|
2024-11-13 23:17:29 +00:00
|
|
|
use RPCii\HmacVerificationProvider;
|
2024-08-13 18:54:24 +00:00
|
|
|
|
|
|
|
#[CoversClass(HmacVerificationProvider::class)]
|
|
|
|
final class HmacVerificationTest extends TestCase {
|
2024-11-13 23:17:29 +00:00
|
|
|
public function testActionEnforce(): void {
|
2024-08-13 18:54:24 +00:00
|
|
|
$provider = new HmacVerificationProvider(fn() => 'meow');
|
2024-11-13 23:17:29 +00:00
|
|
|
$procedure = 'test';
|
2024-08-13 18:54:24 +00:00
|
|
|
$params = 'meow=cool&the=bean';
|
|
|
|
|
2024-11-13 23:17:29 +00:00
|
|
|
$queryToken = $provider->sign(false, $procedure, $params);
|
|
|
|
$this->assertTrue($provider->verify($queryToken, false, $procedure, $params));
|
|
|
|
$this->assertFalse($provider->verify($queryToken, true, $procedure, $params));
|
2024-08-13 18:54:24 +00:00
|
|
|
|
2024-11-13 23:17:29 +00:00
|
|
|
$actionToken = $provider->sign(true, $procedure, $params);
|
|
|
|
$this->assertTrue($provider->verify($actionToken, true, $procedure, $params));
|
|
|
|
$this->assertFalse($provider->verify($actionToken, false, $procedure, $params));
|
2024-08-13 18:54:24 +00:00
|
|
|
}
|
|
|
|
}
|