Initial commit: Any-LLM Gateway with Laravel Admin Interface

- Any-LLM Gateway setup with Docker Compose
- Laravel 11 admin interface with Livewire
- Dashboard with usage statistics and charts
- Gateway Users management with budget tracking
- API Keys management with revocation
- Budget templates with assignment
- Usage Logs with filtering and CSV export
- Model Pricing management with calculator
- PostgreSQL database integration
- Complete authentication system for admins
This commit is contained in:
wtrinkl
2025-11-16 12:38:05 +01:00
commit b1363aeab9
148 changed files with 23995 additions and 0 deletions

View File

@@ -0,0 +1,86 @@
<?php
namespace Tests\Feature\Auth;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Livewire\Volt\Volt;
use Tests\TestCase;
class AuthenticationTest extends TestCase
{
use RefreshDatabase;
public function test_login_screen_can_be_rendered(): void
{
$response = $this->get('/login');
$response
->assertOk()
->assertSeeVolt('pages.auth.login');
}
public function test_users_can_authenticate_using_the_login_screen(): void
{
$user = User::factory()->create();
$component = Volt::test('pages.auth.login')
->set('form.email', $user->email)
->set('form.password', 'password');
$component->call('login');
$component
->assertHasNoErrors()
->assertRedirect(route('dashboard', absolute: false));
$this->assertAuthenticated();
}
public function test_users_can_not_authenticate_with_invalid_password(): void
{
$user = User::factory()->create();
$component = Volt::test('pages.auth.login')
->set('form.email', $user->email)
->set('form.password', 'wrong-password');
$component->call('login');
$component
->assertHasErrors()
->assertNoRedirect();
$this->assertGuest();
}
public function test_navigation_menu_can_be_rendered(): void
{
$user = User::factory()->create();
$this->actingAs($user);
$response = $this->get('/dashboard');
$response
->assertOk()
->assertSeeVolt('layout.navigation');
}
public function test_users_can_logout(): void
{
$user = User::factory()->create();
$this->actingAs($user);
$component = Volt::test('layout.navigation');
$component->call('logout');
$component
->assertHasNoErrors()
->assertRedirect('/');
$this->assertGuest();
}
}

View File

@@ -0,0 +1,60 @@
<?php
namespace Tests\Feature\Auth;
use App\Models\User;
use Illuminate\Auth\Events\Verified;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Event;
use Illuminate\Support\Facades\URL;
use Tests\TestCase;
class EmailVerificationTest extends TestCase
{
use RefreshDatabase;
public function test_email_verification_screen_can_be_rendered(): void
{
$user = User::factory()->unverified()->create();
$response = $this->actingAs($user)->get('/verify-email');
$response
->assertSeeVolt('pages.auth.verify-email')
->assertStatus(200);
}
public function test_email_can_be_verified(): void
{
$user = User::factory()->unverified()->create();
Event::fake();
$verificationUrl = URL::temporarySignedRoute(
'verification.verify',
now()->addMinutes(60),
['id' => $user->id, 'hash' => sha1($user->email)]
);
$response = $this->actingAs($user)->get($verificationUrl);
Event::assertDispatched(Verified::class);
$this->assertTrue($user->fresh()->hasVerifiedEmail());
$response->assertRedirect(route('dashboard', absolute: false).'?verified=1');
}
public function test_email_is_not_verified_with_invalid_hash(): void
{
$user = User::factory()->unverified()->create();
$verificationUrl = URL::temporarySignedRoute(
'verification.verify',
now()->addMinutes(60),
['id' => $user->id, 'hash' => sha1('wrong-email')]
);
$this->actingAs($user)->get($verificationUrl);
$this->assertFalse($user->fresh()->hasVerifiedEmail());
}
}

View File

@@ -0,0 +1,56 @@
<?php
namespace Tests\Feature\Auth;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Livewire\Volt\Volt;
use Tests\TestCase;
class PasswordConfirmationTest extends TestCase
{
use RefreshDatabase;
public function test_confirm_password_screen_can_be_rendered(): void
{
$user = User::factory()->create();
$response = $this->actingAs($user)->get('/confirm-password');
$response
->assertSeeVolt('pages.auth.confirm-password')
->assertStatus(200);
}
public function test_password_can_be_confirmed(): void
{
$user = User::factory()->create();
$this->actingAs($user);
$component = Volt::test('pages.auth.confirm-password')
->set('password', 'password');
$component->call('confirmPassword');
$component
->assertRedirect('/dashboard')
->assertHasNoErrors();
}
public function test_password_is_not_confirmed_with_invalid_password(): void
{
$user = User::factory()->create();
$this->actingAs($user);
$component = Volt::test('pages.auth.confirm-password')
->set('password', 'wrong-password');
$component->call('confirmPassword');
$component
->assertNoRedirect()
->assertHasErrors('password');
}
}

View File

@@ -0,0 +1,84 @@
<?php
namespace Tests\Feature\Auth;
use App\Models\User;
use Illuminate\Auth\Notifications\ResetPassword;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Notification;
use Livewire\Volt\Volt;
use Tests\TestCase;
class PasswordResetTest extends TestCase
{
use RefreshDatabase;
public function test_reset_password_link_screen_can_be_rendered(): void
{
$response = $this->get('/forgot-password');
$response
->assertSeeVolt('pages.auth.forgot-password')
->assertStatus(200);
}
public function test_reset_password_link_can_be_requested(): void
{
Notification::fake();
$user = User::factory()->create();
Volt::test('pages.auth.forgot-password')
->set('email', $user->email)
->call('sendPasswordResetLink');
Notification::assertSentTo($user, ResetPassword::class);
}
public function test_reset_password_screen_can_be_rendered(): void
{
Notification::fake();
$user = User::factory()->create();
Volt::test('pages.auth.forgot-password')
->set('email', $user->email)
->call('sendPasswordResetLink');
Notification::assertSentTo($user, ResetPassword::class, function ($notification) {
$response = $this->get('/reset-password/'.$notification->token);
$response
->assertSeeVolt('pages.auth.reset-password')
->assertStatus(200);
return true;
});
}
public function test_password_can_be_reset_with_valid_token(): void
{
Notification::fake();
$user = User::factory()->create();
Volt::test('pages.auth.forgot-password')
->set('email', $user->email)
->call('sendPasswordResetLink');
Notification::assertSentTo($user, ResetPassword::class, function ($notification) use ($user) {
$component = Volt::test('pages.auth.reset-password', ['token' => $notification->token])
->set('email', $user->email)
->set('password', 'password')
->set('password_confirmation', 'password');
$component->call('resetPassword');
$component
->assertRedirect('/login')
->assertHasNoErrors();
return true;
});
}
}

View File

@@ -0,0 +1,50 @@
<?php
namespace Tests\Feature\Auth;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Hash;
use Livewire\Volt\Volt;
use Tests\TestCase;
class PasswordUpdateTest extends TestCase
{
use RefreshDatabase;
public function test_password_can_be_updated(): void
{
$user = User::factory()->create();
$this->actingAs($user);
$component = Volt::test('profile.update-password-form')
->set('current_password', 'password')
->set('password', 'new-password')
->set('password_confirmation', 'new-password')
->call('updatePassword');
$component
->assertHasNoErrors()
->assertNoRedirect();
$this->assertTrue(Hash::check('new-password', $user->refresh()->password));
}
public function test_correct_password_must_be_provided_to_update_password(): void
{
$user = User::factory()->create();
$this->actingAs($user);
$component = Volt::test('profile.update-password-form')
->set('current_password', 'wrong-password')
->set('password', 'new-password')
->set('password_confirmation', 'new-password')
->call('updatePassword');
$component
->assertHasErrors(['current_password'])
->assertNoRedirect();
}
}

View File

@@ -0,0 +1,36 @@
<?php
namespace Tests\Feature\Auth;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Livewire\Volt\Volt;
use Tests\TestCase;
class RegistrationTest extends TestCase
{
use RefreshDatabase;
public function test_registration_screen_can_be_rendered(): void
{
$response = $this->get('/register');
$response
->assertOk()
->assertSeeVolt('pages.auth.register');
}
public function test_new_users_can_register(): void
{
$component = Volt::test('pages.auth.register')
->set('name', 'Test User')
->set('email', 'test@example.com')
->set('password', 'password')
->set('password_confirmation', 'password');
$component->call('register');
$component->assertRedirect(route('dashboard', absolute: false));
$this->assertAuthenticated();
}
}

View File

@@ -0,0 +1,19 @@
<?php
namespace Tests\Feature;
// use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class ExampleTest extends TestCase
{
/**
* A basic test example.
*/
public function test_the_application_returns_a_successful_response(): void
{
$response = $this->get('/');
$response->assertStatus(200);
}
}

View File

@@ -0,0 +1,101 @@
<?php
namespace Tests\Feature;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Livewire\Volt\Volt;
use Tests\TestCase;
class ProfileTest extends TestCase
{
use RefreshDatabase;
public function test_profile_page_is_displayed(): void
{
$user = User::factory()->create();
$response = $this->actingAs($user)->get('/profile');
$response
->assertOk()
->assertSeeVolt('profile.update-profile-information-form')
->assertSeeVolt('profile.update-password-form')
->assertSeeVolt('profile.delete-user-form');
}
public function test_profile_information_can_be_updated(): void
{
$user = User::factory()->create();
$this->actingAs($user);
$component = Volt::test('profile.update-profile-information-form')
->set('name', 'Test User')
->set('email', 'test@example.com')
->call('updateProfileInformation');
$component
->assertHasNoErrors()
->assertNoRedirect();
$user->refresh();
$this->assertSame('Test User', $user->name);
$this->assertSame('test@example.com', $user->email);
$this->assertNull($user->email_verified_at);
}
public function test_email_verification_status_is_unchanged_when_the_email_address_is_unchanged(): void
{
$user = User::factory()->create();
$this->actingAs($user);
$component = Volt::test('profile.update-profile-information-form')
->set('name', 'Test User')
->set('email', $user->email)
->call('updateProfileInformation');
$component
->assertHasNoErrors()
->assertNoRedirect();
$this->assertNotNull($user->refresh()->email_verified_at);
}
public function test_user_can_delete_their_account(): void
{
$user = User::factory()->create();
$this->actingAs($user);
$component = Volt::test('profile.delete-user-form')
->set('password', 'password')
->call('deleteUser');
$component
->assertHasNoErrors()
->assertRedirect('/');
$this->assertGuest();
$this->assertNull($user->fresh());
}
public function test_correct_password_must_be_provided_to_delete_account(): void
{
$user = User::factory()->create();
$this->actingAs($user);
$component = Volt::test('profile.delete-user-form')
->set('password', 'wrong-password')
->call('deleteUser');
$component
->assertHasErrors('password')
->assertNoRedirect();
$this->assertNotNull($user->fresh());
}
}

View File

@@ -0,0 +1,10 @@
<?php
namespace Tests;
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
abstract class TestCase extends BaseTestCase
{
//
}

View File

@@ -0,0 +1,16 @@
<?php
namespace Tests\Unit;
use PHPUnit\Framework\TestCase;
class ExampleTest extends TestCase
{
/**
* A basic test example.
*/
public function test_that_true_is_true(): void
{
$this->assertTrue(true);
}
}