47 lines
1.5 KiB
PHP
47 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace Rodev\DelegateAuth\Tests;
|
|
|
|
use Orchestra\Testbench\TestCase as OrchestraTestCase;
|
|
use Rodev\DelegateAuth\DelegateAuthServiceProvider;
|
|
use Rodev\DelegateAuth\Tests\Fixtures\User;
|
|
|
|
abstract class TestCase extends OrchestraTestCase
|
|
{
|
|
protected function getPackageProviders($app): array
|
|
{
|
|
return [DelegateAuthServiceProvider::class];
|
|
}
|
|
|
|
protected function defineEnvironment($app): void
|
|
{
|
|
$app['config']->set('app.key', 'base64:'.base64_encode(str_repeat('a', 32)));
|
|
|
|
$app['config']->set('database.default', 'testing');
|
|
$app['config']->set('database.connections.testing', [
|
|
'driver' => 'sqlite',
|
|
'database' => ':memory:',
|
|
]);
|
|
|
|
$app['config']->set('auth.providers.users.model', User::class);
|
|
|
|
$app['config']->set('delegate-auth.encrypt_key', 'test-secret-key');
|
|
$app['config']->set('delegate-auth.redirect_after_login', '/dashboard');
|
|
$app['config']->set('delegate-auth.redirect_after_logout', '/');
|
|
}
|
|
|
|
protected function defineDatabaseMigrations(): void
|
|
{
|
|
$this->loadMigrationsFrom(__DIR__.'/database/migrations');
|
|
}
|
|
|
|
protected function makeToken(array $payload): string
|
|
{
|
|
$key = substr(hash('sha256', config('delegate-auth.encrypt_key'), binary: true), 0, 32);
|
|
$iv = random_bytes(16);
|
|
$encrypted = openssl_encrypt(json_encode($payload), 'AES-256-CBC', $key, OPENSSL_RAW_DATA, $iv);
|
|
|
|
return base64_encode($iv.$encrypted);
|
|
}
|
|
}
|