rpcii-php/tests/HmacVerificationTest.php

28 lines
999 B
PHP
Raw Normal View History

2024-08-13 18:54:24 +00:00
<?php
// HmacVerificationTest.php
// Created: 2024-08-13
// 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;
use RPCii\HmacVerificationProvider;
2024-08-13 18:54:24 +00:00
#[CoversClass(HmacVerificationProvider::class)]
final class HmacVerificationTest extends TestCase {
public function testActionEnforce(): void {
2024-08-13 18:54:24 +00:00
$provider = new HmacVerificationProvider(fn() => 'meow');
$procedure = 'test';
2024-08-13 18:54:24 +00:00
$params = 'meow=cool&the=bean';
$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
$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
}
}