Browse Source
* Fix parameter name to match entity * Deserialize policy data in object * Add policy with config type to fixtures * Return policy with deserialized config * Use CoreHelper serializers * Add master password reset on accept request * Simplify policy data parsing * Linterpull/2041/head
18 changed files with 182 additions and 39 deletions
@ -0,0 +1,6 @@
@@ -0,0 +1,6 @@
|
||||
namespace Bit.Core.Models.Data.Organizations.Policies |
||||
{ |
||||
public interface IPolicyDataModel |
||||
{ |
||||
} |
||||
} |
||||
@ -1,8 +1,8 @@
@@ -1,8 +1,8 @@
|
||||
using System.ComponentModel.DataAnnotations; |
||||
|
||||
namespace Bit.Core.Models.Data |
||||
namespace Bit.Core.Models.Data.Organizations.Policies |
||||
{ |
||||
public class ResetPasswordDataModel |
||||
public class ResetPasswordDataModel : IPolicyDataModel |
||||
{ |
||||
[Display(Name = "ResetPasswordAutoEnrollCheckbox")] |
||||
public bool AutoEnrollEnabled { get; set; } |
||||
@ -1,8 +1,8 @@
@@ -1,8 +1,8 @@
|
||||
using System.ComponentModel.DataAnnotations; |
||||
|
||||
namespace Bit.Core.Models.Data |
||||
namespace Bit.Core.Models.Data.Organizations.Policies |
||||
{ |
||||
public class SendOptionsPolicyData |
||||
public class SendOptionsPolicyData : IPolicyDataModel |
||||
{ |
||||
[Display(Name = "DisableHideEmail")] |
||||
public bool DisableHideEmail { get; set; } |
||||
@ -0,0 +1,68 @@
@@ -0,0 +1,68 @@
|
||||
using System; |
||||
using System.Threading.Tasks; |
||||
using Bit.Api.Controllers; |
||||
using Bit.Api.Models.Request.Organizations; |
||||
using Bit.Api.Test.AutoFixture.Attributes; |
||||
using Bit.Core.Entities; |
||||
using Bit.Core.Models.Data.Organizations.Policies; |
||||
using Bit.Core.Repositories; |
||||
using Bit.Core.Services; |
||||
using Bit.Test.Common.AutoFixture; |
||||
using Bit.Test.Common.AutoFixture.Attributes; |
||||
using NSubstitute; |
||||
using Xunit; |
||||
|
||||
namespace Bit.Api.Test.Controllers |
||||
{ |
||||
[ControllerCustomize(typeof(OrganizationUsersController))] |
||||
[SutProviderCustomize] |
||||
public class OrganizationUsersControllerTests |
||||
{ |
||||
[Theory] |
||||
[BitAutoData] |
||||
public async Task Accept_RequiresKnownUser(Guid orgId, Guid orgUserId, OrganizationUserAcceptRequestModel model, |
||||
SutProvider<OrganizationUsersController> sutProvider) |
||||
{ |
||||
sutProvider.GetDependency<IUserService>().GetUserByPrincipalAsync(default).ReturnsForAnyArgs((User)null); |
||||
|
||||
await Assert.ThrowsAsync<UnauthorizedAccessException>(() => sutProvider.Sut.Accept(orgId, orgUserId, model)); |
||||
} |
||||
|
||||
[Theory] |
||||
[BitAutoData] |
||||
public async Task Accept_NoMasterPasswordReset(Guid orgId, Guid orgUserId, |
||||
OrganizationUserAcceptRequestModel model, User user, SutProvider<OrganizationUsersController> sutProvider) |
||||
{ |
||||
sutProvider.GetDependency<IUserService>().GetUserByPrincipalAsync(default).ReturnsForAnyArgs(user); |
||||
|
||||
await sutProvider.Sut.Accept(orgId, orgUserId, model); |
||||
|
||||
await sutProvider.GetDependency<IOrganizationService>().Received(1) |
||||
.AcceptUserAsync(orgUserId, user, model.Token, sutProvider.GetDependency<IUserService>()); |
||||
await sutProvider.GetDependency<IOrganizationService>().DidNotReceiveWithAnyArgs() |
||||
.UpdateUserResetPasswordEnrollmentAsync(default, default, default, default); |
||||
} |
||||
|
||||
[Theory] |
||||
[BitAutoData] |
||||
public async Task Accept_RequireMasterPasswordReset(Guid orgId, Guid orgUserId, |
||||
OrganizationUserAcceptRequestModel model, User user, SutProvider<OrganizationUsersController> sutProvider) |
||||
{ |
||||
var policy = new Policy<ResetPasswordDataModel> |
||||
{ |
||||
Enabled = true, |
||||
DataModel = new ResetPasswordDataModel { AutoEnrollEnabled = true, }, |
||||
}; |
||||
sutProvider.GetDependency<IUserService>().GetUserByPrincipalAsync(default).ReturnsForAnyArgs(user); |
||||
sutProvider.GetDependency<IPolicyRepository>().GetByOrganizationIdTypeAsync<ResetPasswordDataModel>(orgId, |
||||
Core.Enums.PolicyType.MasterPassword).Returns(policy); |
||||
|
||||
await sutProvider.Sut.Accept(orgId, orgUserId, model); |
||||
|
||||
await sutProvider.GetDependency<IOrganizationService>().Received(1) |
||||
.AcceptUserAsync(orgUserId, user, model.Token, sutProvider.GetDependency<IUserService>()); |
||||
await sutProvider.GetDependency<IOrganizationService>().Received(1) |
||||
.UpdateUserResetPasswordEnrollmentAsync(orgId, user.Id, model.ResetPasswordKey, user.Id); |
||||
} |
||||
} |
||||
} |
||||
Loading…
Reference in new issue