mirror of
https://github.com/bitwarden/server.git
synced 2024-11-25 12:45:18 +01:00
a07aa8330c
* Fix assigning Manage access to default collection The previous implementation did not work when creating an org as a provider because the ownerId is null in OrganizationService.SignUp. Added a null check and handled assigning access in ProviderService instead. * Tweaks
67 lines
2.2 KiB
C#
67 lines
2.2 KiB
C#
using Bit.Core.AdminConsole.Entities;
|
|
using Bit.Core.Entities;
|
|
using Bit.Core.Enums;
|
|
using Bit.Core.Models.Business;
|
|
using Bit.Core.Repositories;
|
|
using Bit.Core.Services;
|
|
using Bit.IntegrationTestCommon.Factories;
|
|
|
|
namespace Bit.Api.IntegrationTest.Helpers;
|
|
|
|
public static class OrganizationTestHelpers
|
|
{
|
|
public static async Task<Tuple<Organization, OrganizationUser>> SignUpAsync<T>(WebApplicationFactoryBase<T> factory,
|
|
PlanType plan = PlanType.Free,
|
|
string ownerEmail = "integration-test@bitwarden.com",
|
|
string name = "Integration Test Org",
|
|
string billingEmail = "integration-test@bitwarden.com",
|
|
string ownerKey = "test-key") where T : class
|
|
{
|
|
var userRepository = factory.GetService<IUserRepository>();
|
|
var organizationService = factory.GetService<IOrganizationService>();
|
|
|
|
var owner = await userRepository.GetByEmailAsync(ownerEmail);
|
|
|
|
var signUpResult = await organizationService.SignUpAsync(new OrganizationSignup
|
|
{
|
|
Name = name,
|
|
BillingEmail = billingEmail,
|
|
Plan = plan,
|
|
OwnerKey = ownerKey,
|
|
Owner = owner,
|
|
});
|
|
|
|
return new Tuple<Organization, OrganizationUser>(signUpResult.organization, signUpResult.organizationUser);
|
|
}
|
|
|
|
public static async Task<OrganizationUser> CreateUserAsync<T>(
|
|
WebApplicationFactoryBase<T> factory,
|
|
Guid organizationId,
|
|
string userEmail,
|
|
OrganizationUserType type,
|
|
bool accessSecretsManager = false
|
|
) where T : class
|
|
{
|
|
var userRepository = factory.GetService<IUserRepository>();
|
|
var organizationUserRepository = factory.GetService<IOrganizationUserRepository>();
|
|
|
|
var user = await userRepository.GetByEmailAsync(userEmail);
|
|
|
|
var orgUser = new OrganizationUser
|
|
{
|
|
OrganizationId = organizationId,
|
|
UserId = user.Id,
|
|
Key = null,
|
|
Type = type,
|
|
Status = OrganizationUserStatusType.Confirmed,
|
|
AccessAll = false,
|
|
ExternalId = null,
|
|
AccessSecretsManager = accessSecretsManager,
|
|
};
|
|
|
|
await organizationUserRepository.CreateAsync(orgUser);
|
|
|
|
return orgUser;
|
|
}
|
|
}
|