mirror of
https://github.com/bitwarden/server.git
synced 2026-02-08 09:53:14 +08:00
* Split OrganizationSponsorshipService into commands * Use tokenable for token validation * Use interfaces to set up for DI * Use commands over services * Move service tests to command tests * Value types can't be null * Run dotnet format * Update src/Core/OrganizationFeatures/OrganizationSponsorships/FamiliesForEnterprise/CancelSponsorshipCommand.cs Co-authored-by: Justin Baur <admin@justinbaur.com> * Fix controller tests * Split create and send sponsorships * Split up create sponsorship * Add self hosted commands to dependency injection * Add field to store cloud billing sync key on self host instances * Fix typo * Fix data protector purpose of sponsorship offers * Split cloud and selfhosted sponsorship offer tokenable * Generate offer from self hosted with all necessary auth data * Add Required properties to constructor * Split up cancel sponsorship command * Split revoke sponsorship command between cloud and self hosted * Fix/f4e multiple sponsorships (#1838) * Use sponosorship from validate to redeem * Update tests * Format * Remove sponsorship service * Run dotnet format * Fix self hosted only controller attribute * Clean up file structure and fixes * Remove unneeded tokenables * Remove obsolete commands * Do not require file/class prefix if unnecessary * Update Organizaiton sprocs * Remove unnecessary models * Fix tests * Generalize LicenseService path calculation Use async file read and deserialization * Use interfaces for testability * Remove unused usings * Correct test direction * Test license reading * remove unused usings * Format Co-authored-by: Justin Baur <admin@justinbaur.com>
65 lines
2.1 KiB
C#
65 lines
2.1 KiB
C#
using System;
|
|
using System.IO;
|
|
using System.Text.Json;
|
|
using System.Threading.Tasks;
|
|
using AutoFixture;
|
|
using Bit.Core.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.ReadOrganizationLicense(organization);
|
|
try
|
|
{
|
|
Assert.Equal(JsonSerializer.Serialize(license), JsonSerializer.Serialize(actual));
|
|
}
|
|
finally
|
|
{
|
|
Directory.Delete(OrganizationLicenseDirectory.Value, true);
|
|
}
|
|
}
|
|
}
|
|
}
|