mirror of
https://github.com/Budibase/budibase.git
synced 2026-09-01 15:11:45 +08:00
Merge pull request #18990 from Budibase/user-update-checks
tighten user update check
This commit is contained in:
@@ -109,6 +109,10 @@ export const save = async (ctx: UserCtx<UnsavedUser, SaveUserResponse>) => {
|
||||
export const changeTenantOwnerEmail = async (
|
||||
ctx: Ctx<ChangeTenantOwnerEmailRequest, void>
|
||||
) => {
|
||||
if (!ctx.internal) {
|
||||
ctx.throw(403, "Unauthorized")
|
||||
}
|
||||
|
||||
const { newAccountEmail, originalEmail, tenantIds } = ctx.request.body
|
||||
try {
|
||||
for (const tenantId of tenantIds) {
|
||||
|
||||
@@ -1528,5 +1528,43 @@ describe("/api/global/users", () => {
|
||||
.set(config.defaultHeaders())
|
||||
.expect(403)
|
||||
})
|
||||
|
||||
it("should reject authenticated users on self-hosted", async () => {
|
||||
const originalEmail = `original-${structures.uuid()}@example.com`
|
||||
const newEmail = `new-${structures.uuid()}@example.com`
|
||||
const tenantId = config.getTenantId()
|
||||
|
||||
const tenantUser = await config.doInTenant(async () => {
|
||||
return await userSdk.db.save(
|
||||
structures.users.user({
|
||||
email: originalEmail,
|
||||
tenantId,
|
||||
roles: {},
|
||||
}),
|
||||
{ requirePassword: false, isAccountHolder: true }
|
||||
)
|
||||
})
|
||||
|
||||
config.selfHosted()
|
||||
try {
|
||||
await config.request
|
||||
.put(`/api/global/users/tenant/owner`)
|
||||
.send({
|
||||
newAccountEmail: newEmail,
|
||||
originalEmail,
|
||||
tenantIds: [tenantId],
|
||||
})
|
||||
.set(config.defaultHeaders())
|
||||
.expect(403)
|
||||
} finally {
|
||||
config.cloudHosted()
|
||||
}
|
||||
|
||||
const unchangedUser = await config.doInTenant(async () => {
|
||||
return await userSdk.db.getUser(tenantUser._id!)
|
||||
})
|
||||
|
||||
expect(unchangedUser!.email).toBe(originalEmail)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user