using Bit.Api.AdminConsole.Controllers; using Bit.Api.AdminConsole.Models.Request; using Bit.Core.Context; using Bit.Test.Common.AutoFixture; using Bit.Test.Common.AutoFixture.Attributes; using NSubstitute; using Xunit; namespace Bit.Api.Test.AdminConsole.Controllers; [ControllerCustomize(typeof(OrganizationAuthRequestsController))] [SutProviderCustomize] public class OrganizationAuthRequestsControllerTests { [Theory] [BitAutoData] public async Task ValidateAdminRequest_UserDoesNotHaveManageResetPasswordPermissions_ThrowsUnauthorized( SutProvider sutProvider, Guid organizationId ) { sutProvider.GetDependency().ManageResetPassword(organizationId).Returns(false); await Assert.ThrowsAsync(() => sutProvider.Sut.ValidateAdminRequest(organizationId)); } [Theory] [BitAutoData] public async Task ValidateAdminRequest_UserHasManageResetPasswordPermissions_DoesNotThrow( SutProvider sutProvider, Guid organizationId ) { sutProvider.GetDependency().ManageResetPassword(organizationId).Returns(true); await sutProvider.Sut.ValidateAdminRequest(organizationId); } [Theory] [BitAutoData] public async Task UpdateManyAuthRequests_ValidInput_DoesNotThrow( SutProvider sutProvider, IEnumerable request, Guid organizationId ) { sutProvider.GetDependency().ManageResetPassword(organizationId).Returns(true); await sutProvider.Sut.UpdateManyAuthRequests(organizationId, request); } [Theory] [BitAutoData] public async Task UpdateManyAuthRequests_NotPermissioned_ThrowsUnauthorized( SutProvider sutProvider, IEnumerable request, Guid organizationId ) { sutProvider.GetDependency().ManageResetPassword(organizationId).Returns(false); await Assert.ThrowsAsync(() => sutProvider.Sut.UpdateManyAuthRequests(organizationId, request)); } }