mirror of
https://github.com/Studio-Saelix/sencho.git
synced 2026-08-28 11:17:07 +00:00
fix(rbac): enforce admin seat cap on promotion and harden last-admin and audit paths (#1266)
Promoting a user to admin now respects the per-tier admin seat limit the same way user creation does, closing a path that let an operator exceed the cap by creating an account and then editing its role to admin. The last-admin guard for demote and delete now runs the admin-count re-check and the write in a single transaction, so two concurrent admin changes can no longer race the admin count to zero and lock everyone out. Admin two-factor resets are now recorded once with their own audit summary instead of being mislabeled as a user creation by the audit middleware.
This commit is contained in:
@@ -126,6 +126,19 @@ describe('getAuditSummary()', () => {
|
||||
expect(getAuditSummary('DELETE', '/nodes/5')).toBe('Deleted node: 5');
|
||||
expect(getAuditSummary('DELETE', 'nodes/5')).toBe('Deleted node: 5');
|
||||
});
|
||||
|
||||
it('matches user management routes', () => {
|
||||
expect(getAuditSummary('POST', '/users')).toBe('Created user');
|
||||
expect(getAuditSummary('PUT', '/users/42')).toBe('Updated user: 42');
|
||||
expect(getAuditSummary('DELETE', '/users/42')).toBe('Deleted user: 42');
|
||||
expect(getAuditSummary('POST', '/users/42/roles')).toBe('Assigned role: 42');
|
||||
expect(getAuditSummary('DELETE', '/users/42/roles/7')).toBe('Removed role assignment: 42');
|
||||
});
|
||||
|
||||
it('labels an MFA reset distinctly and never as user creation', () => {
|
||||
expect(getAuditSummary('POST', '/users/42/mfa/reset')).toBe('Reset two-factor authentication: 42');
|
||||
expect(getAuditSummary('POST', '/users/42/mfa/reset')).not.toBe('Created user: 42');
|
||||
});
|
||||
});
|
||||
|
||||
// ---- DatabaseService audit methods ----
|
||||
|
||||
Reference in New Issue
Block a user