Files
KanbanGit/tests/Feature/Models/UserApplicationTest.php
T
Twyco bf0e50464a
linter / quality (pull_request) Successful in 1m19s
tests / ci (8.4) (pull_request) Successful in 1m32s
Add application API keys
2026-04-20 19:58:24 +02:00

41 lines
1.2 KiB
PHP

<?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,
]);
}
}