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