feat(api): advance capability and secure operations slices
This commit is contained in:
@@ -1,7 +1,35 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
import { SafeUpstreamGateway } from './safe-upstream-gateway.js';
|
||||
|
||||
describe('SafeUpstreamGateway', () => {
|
||||
it('dispatches only the audited zero-body network registration operation through pinned POST', async () => {
|
||||
const calls: unknown[] = [];
|
||||
const gateway = new SafeUpstreamGateway({
|
||||
transport: {
|
||||
get: async () => ({ status: 200, headers: {}, body: '' }),
|
||||
post: async (url, headers, body) => {
|
||||
calls.push({ url, headers, body });
|
||||
return { status: 204, headers: {}, body: '' };
|
||||
},
|
||||
},
|
||||
});
|
||||
const response = await gateway.postNetworkRegisterAuto('http://192.168.1.20:8080');
|
||||
expect(response.status).toBe(204);
|
||||
expect(calls).toEqual([
|
||||
{ url: 'http://192.168.1.20:8080/api/network/register-auto', headers: {}, body: '' },
|
||||
]);
|
||||
});
|
||||
|
||||
it('rejects malformed operation origins before calling transport', async () => {
|
||||
const post = vi.fn(async () => ({ status: 204, headers: {}, body: '' }));
|
||||
const gateway = new SafeUpstreamGateway({
|
||||
transport: { get: async () => ({ status: 200, headers: {}, body: '' }), post },
|
||||
});
|
||||
await expect(
|
||||
gateway.postNetworkRegisterAuto('http://192.168.1.20/base?next=x'),
|
||||
).rejects.toMatchObject({ code: 'UPSTREAM_REQUEST_INVALID', dispatched: false });
|
||||
expect(post).not.toHaveBeenCalled();
|
||||
});
|
||||
it('sends login password only as JSON through the pinned POST transport', async () => {
|
||||
const calls: unknown[] = [];
|
||||
const gateway = new SafeUpstreamGateway({
|
||||
|
||||
Reference in New Issue
Block a user