feat: add flagged remote user icon upload

This commit is contained in:
2026-08-06 15:43:44 +00:00
parent 234ec919bc
commit b095fb4bf1
7 changed files with 249 additions and 5 deletions
+45
View File
@@ -0,0 +1,45 @@
<?php
use PHPUnit\Framework\TestCase;
use sammo\RemoteUserIconUploadClient;
require_once dirname(__DIR__) . '/src/sammo/RemoteUserIconUploadClient.php';
final class RemoteUserIconUploadClientTest extends TestCase
{
public function testBuildRequestBindsExpiryPathContentTypeAndBody(): void
{
$secret = str_repeat('u', 32);
$body = "\x89PNG\r\n\x1a\nbody";
$url = 'https://sam-image.hided.net/v1/uploads/user-icons/core/' . str_repeat('a', 32) . '.png';
$request = RemoteUserIconUploadClient::buildRequest(
$url,
'core',
$secret,
'image/png',
$body,
1786012860,
'core-upload-1234'
);
$expected = hash_hmac(
'sha256',
'1786012860.core-upload-1234./v1/uploads/user-icons/core/' . str_repeat('a', 32)
. '.png.image/png.' . hash('sha256', $body),
$secret
);
self::assertStringContainsString("X-Image-Signature: {$expected}", implode("\n", $request['headers']));
self::assertStringNotContainsString($secret, implode("\n", $request['headers']));
}
public function testBuildRequestRejectsAPathOutsideTheCallerScope(): void
{
$this->expectException(InvalidArgumentException::class);
RemoteUserIconUploadClient::buildRequest(
'https://sam-image.hided.net/v1/uploads/user-icons/core2026/' . str_repeat('a', 32) . '.png',
'core',
str_repeat('u', 32),
'image/png',
'body'
);
}
}