mirror of
https://github.com/bitwarden/server.git
synced 2026-01-31 14:13:18 +08:00
* Initial implementation of new policy query * Remove unused using * Adjusts method name to better match repository method * Correct namespace * Initial refactor of policy loading * Add xml doc, incorporate shim data model * Updates usages to reflect new shim model * Prune extranneous data from policy detail response model, format code * Fix broken test, delete inapplicable test * Adds test cases covering query * Adjust codebase to use new PolicyQueryçˆ * Format code * Fix incorrect mock on test * Fix formatting * Adjust method name * More naming adjustments * Add PolicyData constructor, update test usages * Rename PolicyData -> PolicyStatus * Remove unused using
59 lines
1.6 KiB
C#
59 lines
1.6 KiB
C#
using System.Reflection;
|
|
using AutoFixture;
|
|
using AutoFixture.Xunit2;
|
|
using Bit.Core.AdminConsole.Entities;
|
|
using Bit.Core.AdminConsole.Enums;
|
|
using Bit.Core.AdminConsole.Models.Data.Organizations.Policies;
|
|
|
|
namespace Bit.Core.Test.AdminConsole.AutoFixture;
|
|
|
|
internal class PolicyCustomization : ICustomization
|
|
{
|
|
public PolicyType Type { get; set; }
|
|
public bool Enabled { get; set; }
|
|
public string? Data { get; set; }
|
|
|
|
public PolicyCustomization(PolicyType type, bool enabled, string? data)
|
|
{
|
|
Type = type;
|
|
Enabled = enabled;
|
|
Data = data;
|
|
}
|
|
|
|
public void Customize(IFixture fixture)
|
|
{
|
|
var orgId = Guid.NewGuid();
|
|
|
|
fixture.Customize<Policy>(composer => composer
|
|
.With(o => o.OrganizationId, orgId)
|
|
.With(o => o.Type, Type)
|
|
.With(o => o.Enabled, Enabled)
|
|
.With(o => o.Data, Data));
|
|
|
|
fixture.Customize<PolicyStatus>(composer => composer
|
|
.With(o => o.OrganizationId, orgId)
|
|
.With(o => o.Type, Type)
|
|
.With(o => o.Enabled, Enabled)
|
|
.With(o => o.Data, Data));
|
|
}
|
|
}
|
|
|
|
public class PolicyAttribute : CustomizeAttribute
|
|
{
|
|
private readonly PolicyType _type;
|
|
private readonly bool _enabled;
|
|
private readonly string? _data;
|
|
|
|
public PolicyAttribute(PolicyType type, bool enabled = true, string? data = null)
|
|
{
|
|
_type = type;
|
|
_enabled = enabled;
|
|
_data = data;
|
|
}
|
|
|
|
public override ICustomization GetCustomization(ParameterInfo parameter)
|
|
{
|
|
return new PolicyCustomization(_type, _enabled, _data);
|
|
}
|
|
}
|