Initial import of verae-staff-iam from zapier monorepo
This commit is contained in:
commit
84fd73fe95
14 changed files with 969 additions and 0 deletions
31
test/roles.test.js
Normal file
31
test/roles.test.js
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
import { test } from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { expandRoles, allows, ROLES } from '../src/roles.js';
|
||||
import { StaffIam } from '../src/store.js';
|
||||
import { verifyPassword } from '../src/passwords.js';
|
||||
|
||||
test('owner expands to all permissions', () => {
|
||||
assert.deepEqual(expandRoles(['owner']), ['*']);
|
||||
assert.equal(allows(['*'], 'cs.credit'), true);
|
||||
assert.equal(allows(expandRoles(['cs']), 'cs.credit'), true);
|
||||
assert.equal(allows(expandRoles(['cs']), 'accounting.export'), false);
|
||||
assert.ok(ROLES.sales);
|
||||
});
|
||||
|
||||
test('sessions persist in dump/load', () => {
|
||||
const iam = new StaffIam().seed();
|
||||
const u = iam.findByUsername('cs');
|
||||
const tok = iam.issueSession(u.id);
|
||||
const raw = iam.dump();
|
||||
const b = new StaffIam().load(raw);
|
||||
assert.equal(b.getSession(tok).userId, u.id);
|
||||
});
|
||||
|
||||
test('cannot deactivate last owner; passwords hash', () => {
|
||||
const iam = new StaffIam().seed();
|
||||
const owner = iam.findByUsername('admin');
|
||||
assert.ok(verifyPassword(process.env.ADMIN_KEY || 'admin-dev-key', owner.passwordHash));
|
||||
assert.throws(() => iam.update('admin', { active: false }, 'admin'), /last owner/);
|
||||
const cs = iam.create({ username: 'anna', password: 'anna-pass-1', name: 'Anna', roles: ['cs'], actor: 'admin' });
|
||||
assert.deepEqual(cs.roles, ['cs']);
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue