(t *testing.T)
| 1656 | } |
| 1657 | |
| 1658 | func TestPutUserSuspend(t *testing.T) { |
| 1659 | t.Parallel() |
| 1660 | |
| 1661 | t.Run("SuspendAnOwner", func(t *testing.T) { |
| 1662 | t.Parallel() |
| 1663 | client := coderdtest.New(t, nil) |
| 1664 | me := coderdtest.CreateFirstUser(t, client) |
| 1665 | _, user := coderdtest.CreateAnotherUser(t, client, me.OrganizationID, rbac.RoleOwner()) |
| 1666 | |
| 1667 | ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong) |
| 1668 | defer cancel() |
| 1669 | |
| 1670 | _, err := client.UpdateUserStatus(ctx, user.Username, codersdk.UserStatusSuspended) |
| 1671 | require.Error(t, err, "cannot suspend owners") |
| 1672 | }) |
| 1673 | |
| 1674 | t.Run("SuspendAnotherUser", func(t *testing.T) { |
| 1675 | t.Parallel() |
| 1676 | auditor := audit.NewMock() |
| 1677 | client := coderdtest.New(t, &coderdtest.Options{Auditor: auditor}) |
| 1678 | numLogs := len(auditor.AuditLogs()) |
| 1679 | |
| 1680 | me := coderdtest.CreateFirstUser(t, client) |
| 1681 | numLogs++ // add an audit log for user create |
| 1682 | numLogs++ // add an audit log for login |
| 1683 | |
| 1684 | _, user := coderdtest.CreateAnotherUser(t, client, me.OrganizationID) |
| 1685 | numLogs++ // add an audit log for user create |
| 1686 | |
| 1687 | ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong) |
| 1688 | defer cancel() |
| 1689 | |
| 1690 | user, err := client.UpdateUserStatus(ctx, user.Username, codersdk.UserStatusSuspended) |
| 1691 | require.NoError(t, err) |
| 1692 | require.Equal(t, user.Status, codersdk.UserStatusSuspended) |
| 1693 | numLogs++ // add an audit log for user update |
| 1694 | |
| 1695 | require.Len(t, auditor.AuditLogs(), numLogs) |
| 1696 | require.Equal(t, database.AuditActionWrite, auditor.AuditLogs()[numLogs-1].Action) |
| 1697 | }) |
| 1698 | |
| 1699 | t.Run("SuspendItSelf", func(t *testing.T) { |
| 1700 | t.Parallel() |
| 1701 | client := coderdtest.New(t, nil) |
| 1702 | coderdtest.CreateFirstUser(t, client) |
| 1703 | |
| 1704 | ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong) |
| 1705 | defer cancel() |
| 1706 | |
| 1707 | client.User(ctx, codersdk.Me) |
| 1708 | _, err := client.UpdateUserStatus(ctx, codersdk.Me, codersdk.UserStatusSuspended) |
| 1709 | |
| 1710 | require.ErrorContains(t, err, "suspend yourself", "cannot suspend yourself") |
| 1711 | }) |
| 1712 | } |
| 1713 | |
| 1714 | func TestActivateDormantUser(t *testing.T) { |
| 1715 | t.Parallel() |
nothing calls this directly
no test coverage detected