mirror of
https://github.com/bitwarden/server.git
synced 2024-11-22 12:15:36 +01:00
bd297fb7a2
* SqlServer split manage collection permission * Clarify names * Test claims generation * Test permission serialization * Simplify claims building * Use new collections permissions * Throw on use of deprecated permissions * Lower case all claims * Remove todos * Clean nonexistent project from test solution * JsonIgnore for both system and newtonsoft json * Make migrations more robust to multiple runs * remove duplicate usings * Remove obsolete permissions * Test solutions separately to detect failures * Handle dos line endings * Fix collections create/update permissions * Change restore cipher to edit permissions * Improve formatting * Simplify map * Refactor test
85 lines
3.0 KiB
C#
85 lines
3.0 KiB
C#
using AutoFixture;
|
|
using TableModel = Bit.Core.Models.Table;
|
|
using Bit.Core.Test.AutoFixture.Attributes;
|
|
using Bit.Core.Test.AutoFixture.GlobalSettingsFixtures;
|
|
using Bit.Core.Models;
|
|
using System.Collections.Generic;
|
|
using Bit.Core.Enums;
|
|
using AutoFixture.Kernel;
|
|
using System;
|
|
using Bit.Core.Test.AutoFixture.OrganizationFixtures;
|
|
using Bit.Core.Repositories.EntityFramework;
|
|
using Bit.Core.Test.AutoFixture.EntityFrameworkRepositoryFixtures;
|
|
|
|
namespace Bit.Core.Test.AutoFixture.UserFixtures
|
|
{
|
|
internal class UserBuilder : ISpecimenBuilder
|
|
{
|
|
public object Create(object request, ISpecimenContext context)
|
|
{
|
|
if (context == null)
|
|
{
|
|
throw new ArgumentNullException(nameof(context));
|
|
}
|
|
|
|
var type = request as Type;
|
|
if (type == typeof(TableModel.User))
|
|
{
|
|
var fixture = new Fixture();
|
|
var providers = fixture.Create<Dictionary<TwoFactorProviderType, TwoFactorProvider>>();
|
|
var user = fixture.WithAutoNSubstitutions().Create<TableModel.User>();
|
|
user.SetTwoFactorProviders(providers);
|
|
return user;
|
|
}
|
|
else if (type == typeof(List<TableModel.User>))
|
|
{
|
|
var fixture = new Fixture();
|
|
var users = fixture.WithAutoNSubstitutions().CreateMany<TableModel.User>(2);
|
|
foreach (var user in users)
|
|
{
|
|
var providers = fixture.Create<Dictionary<TwoFactorProviderType, TwoFactorProvider>>();
|
|
user.SetTwoFactorProviders(providers);
|
|
}
|
|
return users;
|
|
}
|
|
|
|
return new NoSpecimen();
|
|
}
|
|
}
|
|
|
|
internal class UserFixture : ICustomization
|
|
{
|
|
public virtual void Customize(IFixture fixture)
|
|
{
|
|
fixture.Customizations.Add(new IgnoreVirtualMembersCustomization());
|
|
fixture.Customizations.Add(new GlobalSettingsBuilder());
|
|
fixture.Customizations.Add(new UserBuilder());
|
|
fixture.Customizations.Add(new OrganizationBuilder());
|
|
}
|
|
}
|
|
|
|
internal class EfUser : UserFixture
|
|
{
|
|
public override void Customize(IFixture fixture)
|
|
{
|
|
base.Customize(fixture);
|
|
fixture.Customizations.Add(new EfRepositoryListBuilder<UserRepository>());
|
|
fixture.Customizations.Add(new EfRepositoryListBuilder<SsoUserRepository>());
|
|
fixture.Customizations.Add(new EfRepositoryListBuilder<OrganizationRepository>());
|
|
}
|
|
}
|
|
|
|
internal class EfUserAutoDataAttribute : CustomAutoDataAttribute
|
|
{
|
|
public EfUserAutoDataAttribute() : base(new SutProviderCustomization(), new EfUser())
|
|
{ }
|
|
}
|
|
|
|
internal class InlineEfUserAutoDataAttribute : InlineCustomAutoDataAttribute
|
|
{
|
|
public InlineEfUserAutoDataAttribute(params object[] values) : base(new[] { typeof(SutProviderCustomization),
|
|
typeof(EfUser) }, values)
|
|
{ }
|
|
}
|
|
}
|