You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
43 lines
1.3 KiB
43 lines
1.3 KiB
9 months ago
|
<?php
|
||
|
namespace App\Tests;
|
||
|
|
||
|
use ApiPlatform\Symfony\Bundle\Test\ApiTestCase;
|
||
|
use ApiPlatform\Symfony\Bundle\Test\Client;
|
||
|
use Zenstruck\Foundry\Test\Factories;
|
||
|
use Zenstruck\Foundry\Test\ResetDatabase;
|
||
|
use DateTimeZone;
|
||
|
|
||
|
abstract class AbstractTest extends ApiTestCase
|
||
|
{
|
||
|
// This trait provided by Foundry will take care of refreshing the database content to a known state before each test
|
||
|
use ResetDatabase, Factories;
|
||
|
|
||
|
public function setUp(): void
|
||
|
{
|
||
|
self::bootKernel();
|
||
|
}
|
||
|
|
||
|
private static function generateAuthToken(string $authName)
|
||
|
{
|
||
|
$sign_seed = sodium_base642bin($_ENV['AUTH_SEED'], SODIUM_BASE64_VARIANT_ORIGINAL);
|
||
|
$sign_pair = sodium_crypto_sign_seed_keypair($sign_seed);
|
||
|
$sign_secret = sodium_crypto_sign_secretkey($sign_pair);
|
||
|
$now = new \DateTimeImmutable("now", new DateTimeZone("UTC"));
|
||
|
$message = $authName . "|" . $now->format("c");
|
||
|
|
||
|
return sodium_bin2base64(sodium_crypto_sign($message, $sign_secret), SODIUM_BASE64_VARIANT_URLSAFE);
|
||
|
}
|
||
|
|
||
|
protected static function createClientWithToken($authName = null): Client
|
||
|
{
|
||
|
return static::createClient([],
|
||
|
[
|
||
|
'headers' => [
|
||
|
'accept' => 'application/json',
|
||
|
'X-AUTH-TOKEN' => static::generateAuthToken($authName)
|
||
|
]
|
||
|
]);
|
||
|
}
|
||
|
}
|
||
|
|