Test for loops in role save API.
This commit is contained in:
parent
171ffd8aa3
commit
189b176060
|
@ -81,7 +81,10 @@ export async function save(ctx: UserCtx<SaveRoleRequest, SaveRoleResponse>) {
|
||||||
_id = dbCore.prefixRoleID(_id)
|
_id = dbCore.prefixRoleID(_id)
|
||||||
}
|
}
|
||||||
|
|
||||||
const allRoles = await roles.getAllRoles()
|
const allRoles = (await roles.getAllRoles()).map(role => ({
|
||||||
|
...role,
|
||||||
|
_id: dbCore.prefixRoleID(role._id!),
|
||||||
|
}))
|
||||||
let dbRole: Role | undefined
|
let dbRole: Role | undefined
|
||||||
if (!isCreate && _id?.startsWith(DocumentType.ROLE)) {
|
if (!isCreate && _id?.startsWith(DocumentType.ROLE)) {
|
||||||
dbRole = allRoles.find(role => role._id === _id)
|
dbRole = allRoles.find(role => role._id === _id)
|
||||||
|
|
|
@ -47,6 +47,25 @@ describe("/roles", () => {
|
||||||
expect(events.role.updated).toHaveBeenCalledTimes(1)
|
expect(events.role.updated).toHaveBeenCalledTimes(1)
|
||||||
expect(events.role.updated).toHaveBeenCalledWith(res)
|
expect(events.role.updated).toHaveBeenCalledWith(res)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it("disallow loops", async () => {
|
||||||
|
let role1 = basicRole()
|
||||||
|
role1 = await config.api.roles.save(role1, {
|
||||||
|
status: 200,
|
||||||
|
})
|
||||||
|
let role2 = basicRole()
|
||||||
|
role2.inherits = [role1._id!]
|
||||||
|
role2 = await config.api.roles.save(role2, {
|
||||||
|
status: 200,
|
||||||
|
})
|
||||||
|
role1.inherits = [role2._id!]
|
||||||
|
await config.api.roles.save(role1, {
|
||||||
|
status: 400,
|
||||||
|
body: {
|
||||||
|
message: "Role inheritance contains a loop, this is not supported",
|
||||||
|
},
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe("fetch", () => {
|
describe("fetch", () => {
|
||||||
|
|
Loading…
Reference in New Issue