mirror of
https://github.com/bitwarden/server.git
synced 2025-06-30 07:36:14 -05:00
SqlServer split manage collection permission (#1594)
* SqlServer split manage collection permission * Clarify names * Test claims generation * Test permission serialization * Simplify claims building * Use new collections permissions * Throw on use of deprecated permissions * Lower case all claims * Remove todos * Clean nonexistent project from test solution * JsonIgnore for both system and newtonsoft json * Make migrations more robust to multiple runs * remove duplicate usings * Remove obsolete permissions * Test solutions separately to detect failures * Handle dos line endings * Fix collections create/update permissions * Change restore cipher to edit permissions * Improve formatting * Simplify map * Refactor test
This commit is contained in:
56
test/Core.Test/Models/PermissionsTests.cs
Normal file
56
test/Core.Test/Models/PermissionsTests.cs
Normal file
@ -0,0 +1,56 @@
|
||||
using System;
|
||||
using System.Text.Json;
|
||||
using AutoFixture.Xunit2;
|
||||
using Bit.Core.Models.Data;
|
||||
using Bit.Core.Models.Table;
|
||||
using Bit.Core.Utilities;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Serialization;
|
||||
using Xunit;
|
||||
|
||||
namespace Bit.Core.Test.Models
|
||||
{
|
||||
public class PermissionsTests
|
||||
{
|
||||
private static readonly string _exampleSerializedPermissions = string.Concat(
|
||||
"{",
|
||||
"\"accessBusinessPortal\": false,",
|
||||
"\"accessEventLogs\": false,",
|
||||
"\"accessImportExport\": false,",
|
||||
"\"accessReports\": false,",
|
||||
"\"manageAllCollections\": true,", // exists for backwards compatibility
|
||||
"\"createNewCollections\": true,",
|
||||
"\"editAnyCollection\": true,",
|
||||
"\"deleteAnyCollection\": true,",
|
||||
"\"manageAssignedCollections\": false,", // exists for backwards compatibility
|
||||
"\"editAssignedCollections\": false,",
|
||||
"\"deleteAssignedCollections\": false,",
|
||||
"\"manageGroups\": false,",
|
||||
"\"managePolicies\": false,",
|
||||
"\"manageSso\": false,",
|
||||
"\"manageUsers\": false,",
|
||||
"\"manageResetPassword\": false",
|
||||
"}");
|
||||
|
||||
[Fact]
|
||||
public void Serialization_Success()
|
||||
{
|
||||
// minify expected json
|
||||
var expected = JsonConvert.SerializeObject(JsonConvert.DeserializeObject(_exampleSerializedPermissions));
|
||||
|
||||
DefaultContractResolver contractResolver = new DefaultContractResolver
|
||||
{
|
||||
NamingStrategy = new CamelCaseNamingStrategy()
|
||||
};
|
||||
|
||||
var actual = JsonConvert.SerializeObject(
|
||||
CoreHelpers.LoadClassFromJsonData<Permissions>(_exampleSerializedPermissions), new JsonSerializerSettings
|
||||
{
|
||||
ContractResolver = contractResolver,
|
||||
});
|
||||
|
||||
Console.WriteLine(actual);
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user