1
0
mirror of https://github.com/bitwarden/server.git synced 2024-12-11 15:17:44 +01:00
bitwarden-server/test/Core.Test/Models/PermissionsTests.cs

59 lines
1.8 KiB
C#
Raw Normal View History

using System.Text.Json;
using Bit.Core.Models.Data;
using Bit.Core.Utilities;
using Xunit;
2022-08-29 22:06:55 +02:00
namespace Bit.Core.Test.Models;
public class PermissionsTests
{
2022-08-29 22:06:55 +02:00
private static readonly string _exampleSerializedPermissions = string.Concat(
"{",
"\"accessEventLogs\": false,",
"\"accessImportExport\": false,",
"\"accessReports\": false,",
"\"createNewCollections\": true,",
"\"editAnyCollection\": true,",
"\"deleteAnyCollection\": true,",
"\"editAssignedCollections\": false,",
"\"deleteAssignedCollections\": false,",
"\"manageGroups\": false,",
"\"managePolicies\": false,",
"\"manageSso\": false,",
"\"manageUsers\": false,",
"\"manageResetPassword\": false,",
"\"manageScim\": false",
"}");
2022-08-29 22:06:55 +02:00
[Fact]
public void Serialization_Success()
{
var permissions = new Permissions
{
2022-08-29 22:06:55 +02:00
AccessEventLogs = false,
AccessImportExport = false,
AccessReports = false,
CreateNewCollections = true,
EditAnyCollection = true,
DeleteAnyCollection = true,
EditAssignedCollections = false,
DeleteAssignedCollections = false,
ManageGroups = false,
ManagePolicies = false,
ManageSso = false,
ManageUsers = false,
ManageResetPassword = false,
ManageScim = false,
};
2022-08-29 22:06:55 +02:00
// minify expected json
var expected = JsonSerializer.Serialize(permissions, JsonHelpers.CamelCase);
2022-08-29 22:06:55 +02:00
var actual = JsonSerializer.Serialize(
JsonHelpers.DeserializeOrNew<Permissions>(_exampleSerializedPermissions, JsonHelpers.CamelCase),
JsonHelpers.CamelCase);
2022-08-29 22:06:55 +02:00
Assert.Equal(expected, actual);
}
}