- Removed legacy Outlook integration, including views, controllers, and models. - Introduced Microsoft Entra ID OAuth flows with enhanced permission checks and token management. - Migrated database structure: replaced `outlook_tokens` table with `oauth_tokens` table for multi-provider support. - Added comprehensive tests for Entra ID federation, including connection flow, token refresh, and permission checks. - Standardized OAuth implementation using `EntraController` and consolidated token models into `OauthToken`.
108 lines
3.7 KiB
PHP
108 lines
3.7 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
use App\Models\{ConnectedApp, ConnectionProtocol, ConnectionProvider, ConnectionStatus, User};
|
|
use App\Services\UserAppAccessService;
|
|
use Livewire\Livewire;
|
|
|
|
beforeEach(function (): void {
|
|
$this->seed(Database\Seeders\ConnectionProtocolSeeder::class);
|
|
$this->seed(Database\Seeders\ConnectionProviderSeeder::class);
|
|
$this->seed(Database\Seeders\ConnectionStatusSeeder::class);
|
|
|
|
$this->urlProtocol = ConnectionProtocol::query()->where('name', 'url')->firstOrFail();
|
|
$this->provider = ConnectionProvider::query()->where('slug', 'azure-fd')->firstOrFail();
|
|
$this->status = ConnectionStatus::query()->where('name', 'connected')->firstOrFail();
|
|
});
|
|
|
|
it('successfully creates a connected app with URL protocol', function (): void {
|
|
$admin = User::factory()->create();
|
|
$admin->assignRole(App\Models\Role::findOrCreate('Admin'));
|
|
|
|
$this->actingAs($admin);
|
|
|
|
Livewire::test('pages::connected-apps.create')
|
|
->set('form.name', 'Azure Portal')
|
|
->set('form.protocolId', $this->urlProtocol->id)
|
|
->set('form.providerId', $this->provider->id)
|
|
->set('form.statusId', $this->status->id)
|
|
->call('save');
|
|
|
|
$this->assertDatabaseHas('connected_apps', [
|
|
'name' => 'Azure Portal',
|
|
'connection_protocol_id' => $this->urlProtocol->id,
|
|
]);
|
|
});
|
|
|
|
it('successfully edits a connected app with URL protocol', function (): void {
|
|
$admin = User::factory()->create();
|
|
$admin->assignRole(App\Models\Role::findOrCreate('Admin'));
|
|
|
|
$this->actingAs($admin);
|
|
|
|
$app = ConnectedApp::query()->create([
|
|
'name' => 'Azure Portal',
|
|
'slug' => 'azure-portal',
|
|
'connection_protocol_id' => $this->urlProtocol->id,
|
|
'connection_provider_id' => $this->provider->id,
|
|
'connection_status_id' => $this->status->id,
|
|
]);
|
|
|
|
Livewire::test('pages::connected-apps.edit', ['id' => $app->id])
|
|
->set('form.name', 'Updated Azure Portal')
|
|
->call('save');
|
|
|
|
$app->refresh();
|
|
expect($app->name)->toBe('Updated Azure Portal');
|
|
});
|
|
|
|
it('maps URL protocol to ServiceAppDto in UserAppAccessService', function (): void {
|
|
$user = User::factory()->create();
|
|
|
|
$app = ConnectedApp::query()->create([
|
|
'name' => 'Azure Portal',
|
|
'slug' => 'azure-portal',
|
|
'connection_protocol_id' => $this->urlProtocol->id,
|
|
'connection_provider_id' => $this->provider->id,
|
|
'connection_status_id' => $this->status->id,
|
|
]);
|
|
|
|
$role = App\Models\Role::findOrCreate('Standard User');
|
|
$role->update(['priority' => 10]);
|
|
$role->apps()->attach($app->id, ['duration' => now()->addYear()->toDateTimeString()]);
|
|
|
|
$user->assignRole($role);
|
|
|
|
$service = app(UserAppAccessService::class);
|
|
$activeServices = $service->getActiveServices($user);
|
|
|
|
expect($activeServices->count())->toBe(1);
|
|
|
|
$dto = $activeServices->first();
|
|
expect($dto->protocol_name)->toBe('url')
|
|
->and($dto->provider_slug)->toBe('azure-fd');
|
|
});
|
|
|
|
it('shows newly created connected apps with no roles in searchAppsForSelect dropdown', function (): void {
|
|
$admin = User::factory()->create();
|
|
$role = App\Models\Role::findOrCreate('Admin');
|
|
$role->update(['priority' => 1]);
|
|
$admin->assignRole($role);
|
|
|
|
$this->actingAs($admin);
|
|
|
|
$app = ConnectedApp::query()->create([
|
|
'name' => 'Brand New App',
|
|
'slug' => 'brand-new-app',
|
|
'connection_protocol_id' => $this->urlProtocol->id,
|
|
'connection_provider_id' => $this->provider->id,
|
|
'connection_status_id' => $this->status->id,
|
|
]);
|
|
|
|
$appRoleService = app(App\Services\AppRoleService::class);
|
|
$apps = $appRoleService->searchAppsForSelect('');
|
|
|
|
expect($apps->pluck('id')->toArray())->toContain($app->id);
|
|
});
|