mirror of
http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore.git
synced 2026-01-15 06:55:06 +08:00
51 lines
1.5 KiB
PHP
51 lines
1.5 KiB
PHP
<?php
|
|
/**
|
|
* OssServiceTest.php@HDK-Core
|
|
*
|
|
* @author 李东云 <Dongyun.Li@LuxCreo.Ai>
|
|
* Powered by PhpStorm
|
|
* Created on 2023/1/9
|
|
*/
|
|
|
|
use Hyperf\Utils\Codec\Json;
|
|
use Singularity\HDK\Core\Service\OssService;
|
|
|
|
use function Spatie\PestPluginTestTime\testTime;
|
|
|
|
it('asserts oss policy can be generated', function ($setDir, $isImage, $maxSize) {
|
|
testTime()->freeze();
|
|
$oss = new OssService(
|
|
'{MOCK_ACCESS_KEY_ID}',
|
|
'{MOCK_ACCESS_KEY_SECRET}',
|
|
'{MOCK_HOST}',
|
|
'{MOCK_CALLBACK_URL}',
|
|
30,
|
|
);
|
|
|
|
[
|
|
'accessid' => $accessId,
|
|
'host' => $host,
|
|
'policy' => $policy,
|
|
'signature' => $signature,
|
|
'expire' => $expire,
|
|
'dir' => $dir,
|
|
'callback' => $callback,
|
|
] = $oss->generatePolicy($setDir, $isImage, $maxSize);
|
|
|
|
$sign = base64_encode(hash_hmac('sha1', $policy, '{MOCK_ACCESS_KEY_SECRET}', true));
|
|
$policy = Json::decode(base64_decode($policy));
|
|
$callback = Json::decode(base64_decode($callback));
|
|
|
|
expect($accessId)->toBe('{MOCK_ACCESS_KEY_ID}')
|
|
->and($host)->toBe('{MOCK_HOST}')
|
|
->and($dir)->toBe($setDir)
|
|
->and($setDir)->toBe($policy['conditions'][1][2])
|
|
->and($expire)->toBe(testTime()->addSeconds(30)->unix())
|
|
->and($policy['expiration'])->toBe(testTime()->setMilli(0)->toIso8601ZuluString('m'))
|
|
->and($maxSize)->toBe($policy['conditions'][0][2])
|
|
->and($callback['callbackUrl'])->toBe('{MOCK_CALLBACK_URL}')
|
|
->and($signature)->toBe($sign);
|
|
})->with([
|
|
['uploaded', true, 1048576000],
|
|
]);
|