[MM-28533] [MM-28532] [MM-28531] Fixes several bugs with sysconsole_write_usermanagement (#15559)

* MM-28533 Fix incorrect permission check for reset password

* Allow write users to edit other users, promote and demote guests

* Update ancillary perms for PERMISSION_SYSCONSOLE_WRITE_USERMANAGEMENT_USER

* MM-28532

* Dont allow non sysadmin to update passwords / reset passwords / patch user on sysadmins

* MM-28532: Updates test.

* MM-28533: Merge fix.

* MM-28533: Adds ability for new roles to activate/deactivate non-system-admin users.

Co-authored-by: Martin Kraft <martin@upspin.org>
Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
Farhan Munshi
2020-10-07 19:41:46 -04:00
коммит произвёл GitHub
родитель 7f85991009
Коммит 6766853f8a
4 изменённых файлов: 84 добавлений и 4 удалений

Просмотреть файл

@@ -1599,7 +1599,7 @@ func TestUpdateUser(t *testing.T) {
th.Client.Login(user.Email, user.Password)
user.Nickname = "Joram Wilander"
user.Roles = model.SYSTEM_ADMIN_ROLE_ID
user.Roles = model.SYSTEM_USER_ROLE_ID
user.LastPasswordUpdate = 123
ruser, resp := th.Client.UpdateUser(user)
@@ -5208,3 +5208,28 @@ func TestMigrateAuthToSAML(t *testing.T) {
CheckNotImplementedStatus(t, err)
})
}
func TestUpdatePassword(t *testing.T) {
th := Setup(t)
defer th.TearDown()
t.Run("Forbidden when request performed by system user on a system admin", func(t *testing.T) {
res := th.Client.UpdatePassword(th.SystemAdminUser.Id, "Pa$$word11", "foobar")
CheckForbiddenStatus(t, res)
})
t.Run("OK when request performed by system user with requisite system permission, except if requested user is system admin", func(t *testing.T) {
th.AddPermissionToRole(model.PERMISSION_SYSCONSOLE_WRITE_USERMANAGEMENT_USERS.Id, model.SYSTEM_USER_ROLE_ID)
defer th.RemovePermissionFromRole(model.PERMISSION_SYSCONSOLE_WRITE_USERMANAGEMENT_USERS.Id, model.SYSTEM_USER_ROLE_ID)
res := th.Client.UpdatePassword(th.TeamAdminUser.Id, "Pa$$word11", "foobar")
CheckOKStatus(t, res)
res = th.Client.UpdatePassword(th.SystemAdminUser.Id, "Pa$$word11", "foobar")
CheckForbiddenStatus(t, res)
})
t.Run("OK when request performed by system admin, even if requested user is system admin", func(t *testing.T) {
res := th.SystemAdminClient.UpdatePassword(th.SystemAdminUser.Id, "Pa$$word11", "foobar")
CheckOKStatus(t, res)
})
}