first work
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
<?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, 0, $iv);
|
||||
|
||||
return base64_encode($iv).'.'.$encrypted;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user