1
0
mirror of https://github.com/bitwarden/server.git synced 2024-12-05 14:23:30 +01:00
bitwarden-server/test/Core.Test/Services/LicensingServiceTests.cs
Thomas Rittson 9021236d61
AC Team code ownership moves: Organization pt. 1 (#3472)
* move Organization.cs files to AC Team code ownership
2023-11-28 17:18:08 -06:00

61 lines
1.9 KiB
C#

using System.Text.Json;
using AutoFixture;
using Bit.Core.AdminConsole.Entities;
using Bit.Core.Models.Business;
using Bit.Core.Services;
using Bit.Core.Settings;
using Bit.Core.Test.AutoFixture;
using Bit.Test.Common.AutoFixture;
using Bit.Test.Common.AutoFixture.Attributes;
using Xunit;
namespace Bit.Core.Test.Services;
[SutProviderCustomize]
public class LicensingServiceTests
{
private static string licenseFilePath(Guid orgId) =>
Path.Combine(OrganizationLicenseDirectory.Value, $"{orgId}.json");
private static string LicenseDirectory => Path.GetDirectoryName(OrganizationLicenseDirectory.Value);
private static Lazy<string> OrganizationLicenseDirectory => new(() =>
{
var directory = Path.Combine(Path.GetTempPath(), "organization");
if (!Directory.Exists(directory))
{
Directory.CreateDirectory(directory);
}
return directory;
});
public static SutProvider<LicensingService> GetSutProvider()
{
var fixture = new Fixture().WithAutoNSubstitutions();
var settings = fixture.Create<IGlobalSettings>();
settings.LicenseDirectory = LicenseDirectory;
settings.SelfHosted = true;
return new SutProvider<LicensingService>(fixture)
.SetDependency(settings)
.Create();
}
[Theory, BitAutoData, OrganizationLicenseCustomize]
public async Task ReadOrganizationLicense(Organization organization, OrganizationLicense license)
{
var sutProvider = GetSutProvider();
File.WriteAllText(licenseFilePath(organization.Id), JsonSerializer.Serialize(license));
var actual = await sutProvider.Sut.ReadOrganizationLicenseAsync(organization);
try
{
Assert.Equal(JsonSerializer.Serialize(license), JsonSerializer.Serialize(actual));
}
finally
{
Directory.Delete(OrganizationLicenseDirectory.Value, true);
}
}
}