CI (SIAX Cloud) / integration (push) Skipped
CI (SIAX Cloud) / sonar (push) Skipped
masterplan-lock / check (push) Successful in 10s
CI (SIAX Cloud) / sonar (pull_request) Skipped
Security Scan (SIAX Cloud) / security (push) Successful in 13s
masterplan-lock / check (pull_request) Successful in 7s
CI (SIAX Cloud) / security (push) Successful in 26s
Security Scan (SIAX Cloud) / security (pull_request) Successful in 17s
CI (SIAX Cloud) / security (pull_request) Successful in 19s
CI (SIAX Cloud) / quality (push) Successful in 1m9s
CI (SIAX Cloud) / quality (pull_request) Successful in 2m26s
CI (SIAX Cloud) / integration (pull_request) Successful in 2m33s
- POST /api/0pt/documents/upload: real multipart bytes into DOC0 through the durable attempt journal and the existing coordinator; verified tenant/actor only, project authorization fail-closed. - POST /api/0pt/documents/structure: DOC0 segments -> INF0 -> evidence-bound validation -> optional JSON/CSV export, with credit reserve/settle. - Credits: balance, server-owned price book, Stripe Checkout and idempotent webhook reconciliation via a Stripe re-read of session + payment intent. - /portal/dokument and /portal/krediter: SIAX-styled workspace. - @siax/access: universal, framework-neutral OpenFGA project relationship primitive reusable by DOC0/N0D/other products. - Readiness: real Redis PING probe instead of presence-only; queue is now a live dependency when configured. - Dockerfile: copy every workspace manifest so --frozen-lockfile works. - Format/build hygiene: .prettierignore, .worktrees ignored, valid manifest YAML.
115 lines
3.5 KiB
TypeScript
115 lines
3.5 KiB
TypeScript
import { describe, expect, it } from 'vitest';
|
|
import {
|
|
OpenFgaRelationships,
|
|
isProjectAccessAllowed,
|
|
openFgaFromEnv,
|
|
type ProjectRelationshipScope,
|
|
} from '../../packages/siax-access/src/index';
|
|
|
|
const STORE = '01J8ZQ6K3M9V4T7R2X5C8B1N0A';
|
|
const MODEL = '01J8ZQ6K3M9V4T7R2X5C8B1N0B';
|
|
const TOKEN = 'test-service-token';
|
|
const scope: ProjectRelationshipScope = {
|
|
tenantId: 't_0pt',
|
|
projectId: 'prj_alpha',
|
|
actorId: 'user_123',
|
|
};
|
|
|
|
function client(handler: (url: string, init?: RequestInit) => Response) {
|
|
return new OpenFgaRelationships({
|
|
baseUrl: 'https://fga.siax.io',
|
|
storeId: STORE,
|
|
modelId: MODEL,
|
|
serviceToken: TOKEN,
|
|
fetchImpl: (async (url: string | URL | Request, init?: RequestInit) =>
|
|
handler(String(url), init)) as typeof fetch,
|
|
});
|
|
}
|
|
|
|
function tupleResponse(allowed: boolean): Response {
|
|
return new Response(JSON.stringify({ allowed }), { status: 200 });
|
|
}
|
|
|
|
describe('@siax/access OpenFgaRelationships', () => {
|
|
it('refuses non-https configuration and non-ULID ids', () => {
|
|
expect(
|
|
() =>
|
|
new OpenFgaRelationships({
|
|
baseUrl: 'http://fga.siax.io',
|
|
storeId: STORE,
|
|
modelId: MODEL,
|
|
serviceToken: TOKEN,
|
|
}),
|
|
).toThrow();
|
|
expect(
|
|
() =>
|
|
new OpenFgaRelationships({
|
|
baseUrl: 'https://fga.siax.io',
|
|
storeId: 'not-a-ulid',
|
|
modelId: MODEL,
|
|
serviceToken: TOKEN,
|
|
}),
|
|
).toThrow();
|
|
});
|
|
|
|
it('requires both the tenant membership and the project parent tuple', async () => {
|
|
const seen: string[] = [];
|
|
const c = client((_url, init) => {
|
|
const body = JSON.parse(String(init?.body)) as {
|
|
tuple_key: { relation: string };
|
|
};
|
|
seen.push(body.tuple_key.relation);
|
|
return tupleResponse(true);
|
|
});
|
|
await expect(c.checkProject(scope)).resolves.toBe('relationships_match');
|
|
expect(seen).toEqual(['member', 'tenant']);
|
|
});
|
|
|
|
it('denies the project when membership is denied even if the parent tuple allows', async () => {
|
|
let call = 0;
|
|
const c = client(() => tupleResponse(call++ === 1));
|
|
await expect(c.checkProject(scope)).resolves.toBe('denied');
|
|
});
|
|
|
|
it('reports unavailable (never allowed) when OpenFGA fails', async () => {
|
|
const c = client(() => new Response('boom', { status: 503 }));
|
|
await expect(c.checkProject(scope)).resolves.toBe('unavailable');
|
|
await expect(isProjectAccessAllowed(scope, { relationships: c })).resolves.toBe(false);
|
|
});
|
|
|
|
it('rejects malformed scope values before any request', async () => {
|
|
let called = false;
|
|
const c = client(() => {
|
|
called = true;
|
|
return tupleResponse(true);
|
|
});
|
|
await expect(c.checkProject({ tenantId: 't/../x', projectId: 'p', actorId: 'a' })).resolves.toBe(
|
|
'denied',
|
|
);
|
|
expect(called).toBe(false);
|
|
});
|
|
|
|
it('fails closed when OpenFGA is not configured', async () => {
|
|
await expect(isProjectAccessAllowed(scope, { relationships: undefined })).resolves.toBe(false);
|
|
expect(openFgaFromEnv({} as NodeJS.ProcessEnv)).toBeUndefined();
|
|
});
|
|
|
|
it('applies the additional policy only after a relationship match', async () => {
|
|
const c = client(() => tupleResponse(true));
|
|
await expect(
|
|
isProjectAccessAllowed(scope, {
|
|
relationships: c,
|
|
additionalPolicy: () => false,
|
|
}),
|
|
).resolves.toBe(false);
|
|
await expect(
|
|
isProjectAccessAllowed(scope, {
|
|
relationships: c,
|
|
additionalPolicy: () => {
|
|
throw new Error('policy store down');
|
|
},
|
|
}),
|
|
).resolves.toBe(false);
|
|
});
|
|
});
|