b8d31e3dc4
- Modules\Shared\Bnfexpress\BnfexpressAdminClient: HMAC-signed HTTP client for bnfexpress's admin API (EV FAQs, agent instructions, chat history), with a bnfexpress:smoke-test command and full unit coverage. - New ai-agent module: Filament pages to manage EV FAQs, publish/roll back agent instruction versions, and browse EV chat history + transcripts. - New manage_ai_agent permission (super_admin/admin). - Recorded .ai/rules for the client's auth scheme and non-Resource Filament page/table testing gotchas.
47 lines
1.5 KiB
PHP
47 lines
1.5 KiB
PHP
<?php
|
|
|
|
use Modules\Shared\Bnfexpress\Support\BnfexpressSignature;
|
|
|
|
test('headers computes the hex HMAC-SHA256 over METHOD\PATH\TIMESTAMP\RAW_BODY joined by newlines', function () {
|
|
$headers = BnfexpressSignature::headers(
|
|
method: 'post',
|
|
path: '/admin/faqs',
|
|
rawBody: '{"content":"hi"}',
|
|
clientId: 'ev_admin',
|
|
secret: 'shared-secret',
|
|
timestamp: 1_700_000_000,
|
|
);
|
|
|
|
$expected = hash_hmac('sha256', "POST\n/admin/faqs\n1700000000\n{\"content\":\"hi\"}", 'shared-secret');
|
|
|
|
expect($headers)->toBe([
|
|
'X-Client-Id' => 'ev_admin',
|
|
'X-Timestamp' => '1700000000',
|
|
'X-Signature' => $expected,
|
|
]);
|
|
});
|
|
|
|
test('headers signs an empty raw body for a bodyless request', function () {
|
|
$headers = BnfexpressSignature::headers(
|
|
method: 'GET',
|
|
path: '/admin/faqs/1',
|
|
rawBody: '',
|
|
clientId: 'ev_admin',
|
|
secret: 'shared-secret',
|
|
timestamp: 1_700_000_000,
|
|
);
|
|
|
|
$expected = hash_hmac('sha256', "GET\n/admin/faqs/1\n1700000000\n", 'shared-secret');
|
|
|
|
expect($headers['X-Signature'])->toBe($expected);
|
|
});
|
|
|
|
test('headers generates a fresh timestamp per call when none is given', function () {
|
|
$before = time();
|
|
|
|
$headers = BnfexpressSignature::headers('GET', '/admin/faqs', '', 'ev_admin', 'secret');
|
|
|
|
expect((int) $headers['X-Timestamp'])->toBeGreaterThanOrEqual($before)
|
|
->and((int) $headers['X-Timestamp'])->toBeLessThanOrEqual(time());
|
|
});
|