@vensofts-integration-testkit/authz-core
v0.1.4
Published
Authorization Contract SDK core: independent contract AST and evaluator, explain traces, witness obligation planning, HTTP/in-process execution with controls and effect evidence.
Downloads
589
Maintainers
Readme
@vensofts-integration-testkit/authz-core
Authorization testing that does not trust your own code. Most access-control tests reuse the app's own permission logic, so a bug in that logic passes its own tests. Here you write an independent authorization contract, and the SDK checks your real app against it: every route, every tenant boundary, every role. MIT.
The open core of the NodeSDK Authorization Contract SDK. Node.js 22 or newer. For the command line,
see @vensofts-integration-testkit/authz-cli.
Install
npm install --save-dev @vensofts-integration-testkit/authz-coreWhat it does
You write a contract: default deny, forbid always wins, roles with inheritance that count only
through active memberships, and grants with half-open [from, until) windows. The SDK then:
- Evaluates and explains any decision (
decide,formatExplanation). An independent reference interpreter is differentially tested against it on ≥ 10,000 generated cases. - Compiles a plan (
compilePlan) from the contract, a world of facts, and bindings from operations to HTTP surfaces: detail, mutation, collection, count, search, batch, content scope, field-level and existence probes. Every allow, deny and forbid witness becomes an obligation. Any obligation without a concrete witness is reported asunsatisfied, never silently dropped. - Runs the plan (
runPlan) against your real app. Each deny case is paired with an identity control and an allow control, so a broken login cannot pass as "denied". Mutations are checked by observers and forbidden-write probes in the database, not only by the status code. - Classifies failures into stable signatures, redacts secrets, and reports in JSON.
Example: decide and explain
import assert from 'node:assert/strict';
import { decide, defineContract, formatExplanation } from '@vensofts-integration-testkit/authz-core';
const contract = defineContract({
id: 'docs',
version: 1,
roles: { viewer: [], editor: ['viewer'] },
resources: { document: { states: ['active', 'archived'] } },
operations: {
'document.update': {
resource: 'document',
kind: 'update',
expect: { allow: { status: [200] }, deny: { semantics: '404' } },
},
},
rules: [
{
id: 'editors-update-active',
effect: 'allow',
operations: ['document.update'],
when: {
all: [{ sameTenant: true }, { hasRole: { role: 'editor' } }, { state: { in: ['active'] } }],
},
},
],
});
const editor = {
id: 'u1',
state: 'active',
memberships: [{ tenant: 'orgA', roles: ['editor'], state: 'active' as const }],
attributes: {},
};
const doc = {
type: 'document',
id: 'd1',
exists: true,
tenant: 'orgA',
owner: null,
state: 'active',
grants: [],
attributes: {},
};
const time = '2026-01-15T12:00:00.000Z';
const ok = decide(contract, { operation: 'document.update', actor: editor, resource: doc, time });
assert.equal(ok.decision, 'allow');
const archived = decide(contract, {
operation: 'document.update',
actor: editor,
resource: { ...doc, state: 'archived' },
time,
});
assert.equal(archived.decision, 'deny');
console.log(formatExplanation(archived)); // shows which condition failed: resource.state=archivedUse it in your test runner
authzSuite(plan, runtime, { describe, it }) from @vensofts-integration-testkit/authz-core/testing registers one
test per case with your test runner's describe and it (Vitest, Jest, Mocha or node:test). An
incomplete plan cannot pass.
import { describe, it } from 'vitest';
import { authzSuite } from '@vensofts-integration-testkit/authz-core/testing';
authzSuite(plan, async () => runtime, { describe, it });What finds real bugs
The test suite of this SDK includes a demo app with 16 deliberately injected authorization faults (missing tenant filters, count leaks, mass assignment, existence oracles, stale sessions and more). Each one is detected, and the correct app passes.
Pro features
HTML, JUnit, SARIF and Markdown reports, lifecycle scenarios, contract sensitivity analysis and
contract review are in @vensofts-integration-testkit/authz-pro
under a commercial license: a free 14-day trial, then USD 299 per year per organization; see the price table. Contact
[email protected].
