97 lines
3.4 KiB
PHP
97 lines
3.4 KiB
PHP
<?php
|
|
|
|
use App\Models\ProviderConnection;
|
|
use App\Models\ProviderCredential;
|
|
use App\Services\Graph\GraphClientInterface;
|
|
use App\Services\Graph\GraphResponse;
|
|
use App\Services\Providers\CredentialManager;
|
|
use App\Services\Providers\ProviderGateway;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
|
|
uses(RefreshDatabase::class);
|
|
|
|
it('builds per-request graph context from a provider connection + credentials', function (): void {
|
|
$connection = ProviderConnection::factory()->create([
|
|
'entra_tenant_id' => 'entra-tenant-id',
|
|
]);
|
|
|
|
ProviderCredential::factory()->create([
|
|
'provider_connection_id' => $connection->getKey(),
|
|
'payload' => [
|
|
'client_id' => 'client-id',
|
|
'client_secret' => 'client-secret',
|
|
],
|
|
]);
|
|
|
|
$graph = new class implements GraphClientInterface
|
|
{
|
|
public array $calls = [];
|
|
|
|
public function listPolicies(string $policyType, array $options = []): GraphResponse
|
|
{
|
|
$this->calls[] = ['fn' => 'listPolicies', 'policyType' => $policyType, 'options' => $options];
|
|
|
|
return new GraphResponse(true);
|
|
}
|
|
|
|
public function getPolicy(string $policyType, string $policyId, array $options = []): GraphResponse
|
|
{
|
|
$this->calls[] = ['fn' => 'getPolicy', 'policyType' => $policyType, 'policyId' => $policyId, 'options' => $options];
|
|
|
|
return new GraphResponse(true);
|
|
}
|
|
|
|
public function getOrganization(array $options = []): GraphResponse
|
|
{
|
|
$this->calls[] = ['fn' => 'getOrganization', 'options' => $options];
|
|
|
|
return new GraphResponse(true);
|
|
}
|
|
|
|
public function applyPolicy(string $policyType, string $policyId, array $payload, array $options = []): GraphResponse
|
|
{
|
|
$this->calls[] = ['fn' => 'applyPolicy', 'policyType' => $policyType, 'policyId' => $policyId, 'payload' => $payload, 'options' => $options];
|
|
|
|
return new GraphResponse(true);
|
|
}
|
|
|
|
public function getServicePrincipalPermissions(array $options = []): GraphResponse
|
|
{
|
|
$this->calls[] = ['fn' => 'getServicePrincipalPermissions', 'options' => $options];
|
|
|
|
return new GraphResponse(true);
|
|
}
|
|
|
|
public function request(string $method, string $path, array $options = []): GraphResponse
|
|
{
|
|
$this->calls[] = ['fn' => 'request', 'method' => $method, 'path' => $path, 'options' => $options];
|
|
|
|
return new GraphResponse(true);
|
|
}
|
|
};
|
|
|
|
$gateway = new ProviderGateway(
|
|
graph: $graph,
|
|
credentials: app(CredentialManager::class),
|
|
);
|
|
|
|
$gateway->getOrganization($connection);
|
|
$gateway->request($connection, 'GET', 'organization', ['query' => ['a' => 'b']]);
|
|
|
|
expect($graph->calls)->toHaveCount(2);
|
|
|
|
$first = $graph->calls[0]['options'];
|
|
$second = $graph->calls[1]['options'];
|
|
|
|
expect($first['tenant'])->toBe('entra-tenant-id');
|
|
expect($first['client_id'])->toBe('client-id');
|
|
expect($first['client_secret'])->toBe('client-secret');
|
|
expect($first['client_request_id'])->toBeString()->not->toBeEmpty();
|
|
|
|
expect($second['tenant'])->toBe('entra-tenant-id');
|
|
expect($second['client_id'])->toBe('client-id');
|
|
expect($second['client_secret'])->toBe('client-secret');
|
|
expect($second['client_request_id'])->toBeString()->not->toBeEmpty();
|
|
expect($second['query'])->toBe(['a' => 'b']);
|
|
});
|