mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2026-07-23 17:51:39 +00:00
Merge pull request #5370 from mikiher/fix/root-user-delete-protection
Prevent admin users from deleting the root account
This commit is contained in:
commit
2d9f63963e
3 changed files with 40 additions and 6 deletions
26
test/server/controllers/UserController.test.js
Normal file
26
test/server/controllers/UserController.test.js
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
const { expect } = require('chai')
|
||||
const sinon = require('sinon')
|
||||
|
||||
const UserController = require('../../../server/controllers/UserController')
|
||||
const Logger = require('../../../server/Logger')
|
||||
|
||||
describe('UserController - delete', () => {
|
||||
beforeEach(() => {
|
||||
sinon.stub(Logger, 'error')
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
sinon.restore()
|
||||
})
|
||||
|
||||
it('rejects deleting the root user by UUID', async () => {
|
||||
const rootUser = { id: 'root-uuid', isRoot: true, username: 'root' }
|
||||
const adminUser = { id: 'admin-uuid', isRoot: false, username: 'admin' }
|
||||
const fakeRes = { sendStatus: sinon.spy(), json: sinon.spy() }
|
||||
|
||||
await UserController.delete({ user: adminUser, reqUser: rootUser, params: { id: rootUser.id } }, fakeRes)
|
||||
|
||||
expect(fakeRes.sendStatus.calledWith(403)).to.be.true
|
||||
expect(fakeRes.json.called).to.be.false
|
||||
})
|
||||
})
|
||||
Loading…
Add table
Add a link
Reference in a new issue