1
0
mirror of https://github.com/bitwarden/server.git synced 2024-11-25 12:45:18 +01:00
bitwarden-server/test/Api.Test/Utilities/ApiHelpersTests.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

27 lines
1.6 KiB
C#
Raw Normal View History

using System.Text;
using Bit.Api.Utilities;
using Bit.Core.Models.Business;
using Microsoft.AspNetCore.Http;
using NSubstitute;
using Xunit;
namespace Bit.Api.Test.Utilities;
2022-08-29 22:06:55 +02:00
public class ApiHelpersTests
{
2022-08-29 22:06:55 +02:00
[Fact]
public async Task ReadJsonFileFromBody_Success()
{
var context = Substitute.For<HttpContext>();
context.Request.ContentLength.Returns(200);
var bytes = Encoding.UTF8.GetBytes(testFile);
var formFile = new FormFile(new MemoryStream(bytes), 0, bytes.Length, "bitwarden_organization_license", "bitwarden_organization_license.json");
2022-08-29 20:53:16 +02:00
var license = await ApiHelpers.ReadJsonFileFromBody<OrganizationLicense>(context, formFile);
Assert.Equal(8, license.Version);
}
2022-08-29 22:06:55 +02:00
const string testFile = "{\"licenseKey\": \"licenseKey\", \"installationId\": \"6285f891-b2ec-4047-84c5-2eb7f7747e74\", \"id\": \"1065216d-5854-4326-838d-635487f30b43\",\"name\": \"Test Org\",\"billingEmail\": \"test@email.com\",\"businessName\": null,\"enabled\": true, \"plan\": \"Enterprise (Annually)\",\"planType\": 11,\"seats\": 6,\"maxCollections\": null,\"usePolicies\": true,\"useSso\": true,\"useKeyConnector\": false,\"useGroups\": true,\"useEvents\": true,\"useDirectory\": true,\"useTotp\": true,\"use2fa\": true,\"useApi\": true,\"useResetPassword\": true,\"maxStorageGb\": 1,\"selfHost\": true,\"usersGetPremium\": true,\"version\": 8,\"issued\": \"2022-01-25T21:58:38.9454581Z\",\"refresh\": \"2022-01-28T14:26:31Z\",\"expires\": \"2022-01-28T14:26:31Z\",\"trial\": true,\"hash\": \"testvalue\",\"signature\": \"signature\"}";
}