Add application API keys
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Models;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Models\UserApplication;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
class UserApplicationTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_application_keys_are_hashed_and_hidden(): void
|
||||
{
|
||||
$plainTextKey = UserApplication::generatePlainTextKey();
|
||||
$keyHash = UserApplication::hashKey($plainTextKey);
|
||||
|
||||
$this->assertStringStartsWith('kg_app_', $plainTextKey);
|
||||
$this->assertNotSame($plainTextKey, $keyHash);
|
||||
$this->assertSame(64, strlen($keyHash));
|
||||
$this->assertSame($keyHash, UserApplication::hashKey($plainTextKey));
|
||||
|
||||
$application = UserApplication::query()->create([
|
||||
'key_hash' => $keyHash,
|
||||
'name' => 'Claude Desktop',
|
||||
'user_id' => User::factory()->create()->id,
|
||||
]);
|
||||
|
||||
$this->assertArrayNotHasKey('key_hash', $application->toArray());
|
||||
$this->assertDatabaseHas('user_applications', [
|
||||
'id' => $application->id,
|
||||
'key_hash' => $keyHash,
|
||||
]);
|
||||
$this->assertDatabaseMissing('user_applications', [
|
||||
'id' => $application->id,
|
||||
'key_hash' => $plainTextKey,
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user