feat: agent token, auth.agent middleware, /mcp route with HadoServer skeleton
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BCrwHHnGCB5XH968Nxokqw
This commit is contained in:
45
core/tests/Feature/AgentTokenCommandTest.php
Normal file
45
core/tests/Feature/AgentTokenCommandTest.php
Normal file
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\AgentToken;
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
class AgentTokenCommandTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_issues_token_creating_user_if_needed(): void
|
||||
{
|
||||
$this->artisan('hado:agent:token', ['login' => 'nikita'])
|
||||
->expectsOutputToContain('Token: hado_agent_')
|
||||
->assertSuccessful();
|
||||
|
||||
$user = User::where('login', 'nikita')->sole();
|
||||
$this->assertSame(64, strlen(AgentToken::where('user_id', $user->id)->sole()->token_hash));
|
||||
}
|
||||
|
||||
public function test_reissue_replaces_the_old_token(): void
|
||||
{
|
||||
$this->artisan('hado:agent:token', ['login' => 'nikita'])->assertSuccessful();
|
||||
$old = AgentToken::sole()->token_hash;
|
||||
|
||||
$this->artisan('hado:agent:token', ['login' => 'nikita'])
|
||||
->expectsOutputToContain('перевыпущен')
|
||||
->assertSuccessful();
|
||||
|
||||
$this->assertSame(1, AgentToken::count());
|
||||
$this->assertNotSame($old, AgentToken::sole()->token_hash);
|
||||
}
|
||||
|
||||
public function test_revoke_deletes_the_token(): void
|
||||
{
|
||||
$this->artisan('hado:agent:token', ['login' => 'nikita'])->assertSuccessful();
|
||||
|
||||
$this->artisan('hado:agent:token', ['login' => 'nikita', '--revoke' => true])->assertSuccessful();
|
||||
|
||||
$this->assertSame(0, AgentToken::count());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user