-
-
Notifications
You must be signed in to change notification settings - Fork 111
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Make request values not readonly
Signed-off-by: sagilio <[email protected]>
- Loading branch information
Showing
77 changed files
with
7,020 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,204 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFrameworks>net7.0;net6.0;net5.0;netcoreapp3.1;net461;net452</TargetFrameworks> | ||
<DebugType>full</DebugType> | ||
<IsPackable>false</IsPackable> | ||
<LangVersion>10.0</LangVersion> | ||
<EnforceCodeStyleInBuild>false</EnforceCodeStyleInBuild> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net6|AnyCPU'"> | ||
<Optimize>false</Optimize> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0"/> | ||
<PackageReference Include="xunit" Version="2.4.1"/> | ||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
<PackageReference Include="coverlet.collector" Version="3.1.2"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Casbin\Casbin.csproj"/> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<None Update="Examples\abac_model.conf"> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
</None> | ||
<None Update="Examples\abac_rule_model.conf"> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
</None> | ||
<None Update="Examples\abac_rule_policy.csv"> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
</None> | ||
<None Update="Examples\basic_inverse_policy.csv"> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
</None> | ||
<None Update="Examples\basic_model.conf"> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
</None> | ||
<None Update="Examples\basic_policy.csv"> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
</None> | ||
<None Update="Examples\basic_policy_for_async_adapter_test.csv"> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
</None> | ||
<None Update="Examples\basic_without_resources_model.conf"> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
</None> | ||
<None Update="Examples\basic_without_resources_policy.csv"> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
</None> | ||
<None Update="Examples\basic_without_users_model.conf"> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
</None> | ||
<None Update="Examples\basic_without_users_policy.csv"> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
</None> | ||
<None Update="Examples\basic_with_root_model.conf"> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
</None> | ||
<None Update="Examples\group_with_domain_model.conf"> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
</None> | ||
<None Update="Examples\group_with_domain_policy.csv"> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
</None> | ||
<None Update="Examples\ipmatch_model.conf"> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
</None> | ||
<None Update="Examples\ipmatch_policy.csv"> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
</None> | ||
<None Update="Examples\keymatch2_model.conf"> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
</None> | ||
<None Update="Examples\keymatch2_policy.csv"> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
</None> | ||
<None Update="Examples\keymatch_custom_model.conf"> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
</None> | ||
<None Update="Examples\keymatch_model.conf"> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
</None> | ||
<None Update="Examples\keymatch_policy.csv"> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
</None> | ||
<None Update="Examples\multiple_type_model.conf"> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
</None> | ||
<None Update="Examples\multiple_type_policy.csv"> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
</None> | ||
<None Update="Examples\priority_explicit_deny_override_model.conf"> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
</None> | ||
<None Update="Examples\priority_explicit_deny_override_policy.csv"> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
</None> | ||
<None Update="Examples\priority_explicit_model.conf"> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
</None> | ||
<None Update="Examples\priority_explicit_policy.csv"> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
</None> | ||
<None Update="Examples\priority_indeterminate_policy.csv"> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
</None> | ||
<None Update="Examples\priority_model.conf"> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
</None> | ||
<None Update="Examples\priority_policy.csv"> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
</None> | ||
<None Update="Examples\rbac_model.conf"> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
</None> | ||
<None Update="examples\rbac_muitiple_rolemanager_model.conf"> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
</None> | ||
<None Update="examples\rbac_muitiple_rolemanager_model.csv"> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
</None> | ||
<None Update="Examples\rbac_multiple_eval_model.conf"> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
</None> | ||
<None Update="Examples\rbac_multiple_eval_policy.csv"> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
</None> | ||
<None Update="Examples\rbac_multiple_rolemanager_model.conf"> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
</None> | ||
<None Update="Examples\rbac_multiple_rolemanager_policy.csv"> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
</None> | ||
<None Update="Examples\rbac_policy.csv"> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
</None> | ||
<None Update="Examples\rbac_policy_for_async_watcher_test.csv"> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
</None> | ||
<None Update="Examples\rbac_policy_for_watcher_test.csv"> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
</None> | ||
<None Update="Examples\rbac_with_deny_model.conf"> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
</None> | ||
<None Update="Examples\rbac_with_deny_policy.csv"> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
</None> | ||
<None Update="Examples\rbac_with_domains_model.conf"> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
</None> | ||
<None Update="Examples\rbac_with_domains_policy.csv"> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
</None> | ||
<None Update="Examples\rbac_with_domains_policy2.csv"> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
</None> | ||
<None Update="Examples\rbac_with_hierarchy_policy.csv"> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
</None> | ||
<None Update="Examples\rbac_with_hierarchy_with_domains_policy.csv"> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
</None> | ||
<None Update="Examples\rbac_with_not_deny_model.conf"> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
</None> | ||
<None Update="Examples\rbac_with_resource_roles_model.conf"> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
</None> | ||
<None Update="Examples\rbac_with_resource_roles_policy.csv"> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
</None> | ||
<None Update="Examples\subject_priority_model.conf"> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
</None> | ||
<None Update="Examples\subject_priority_policy.csv"> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
</None> | ||
<None Update="Examples\subject_priority_model_with_domain.conf"> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
</None> | ||
<None Update="Examples\subject_priority_policy_with_domain.csv"> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
</None> | ||
<None Update="Examples\support_count_model.conf"> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
</None> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Folder Include="Mock\"/> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using Casbin.UnitTests.Fixtures; | ||
using Xunit; | ||
|
||
namespace Casbin.UnitTests.Collections; | ||
|
||
[CollectionDefinition("Model collection")] | ||
public class ModelCollection : ICollectionFixture<TestModelFixture> | ||
{ | ||
// This class has no code, and is never created. Its purpose is simply | ||
// to be the place to apply [CollectionDefinition] and all the | ||
// ICollectionFixture<> interfaces. | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
using System.IO; | ||
using System.Text; | ||
using Casbin.Adapter.File; | ||
using Casbin.Model; | ||
|
||
namespace Casbin.UnitTests.Fixtures; | ||
|
||
public class TestModelFixture | ||
{ | ||
internal readonly string _abacModelText = ReadTestFile("abac_model.conf"); | ||
internal readonly string _abacWithEvalModelText = ReadTestFile("abac_rule_model.conf"); | ||
|
||
internal readonly string _abacWithEvalPolicyText = ReadTestFile("abac_rule_policy.csv"); | ||
internal readonly string _basicModelText = ReadTestFile("basic_model.conf"); | ||
internal readonly string _basicPolicyText = ReadTestFile("basic_policy.csv"); | ||
internal readonly string _basicWithoutResourceModelText = ReadTestFile("basic_without_resources_model.conf"); | ||
internal readonly string _basicWithoutResourcePolicyText = ReadTestFile("basic_without_resources_policy.csv"); | ||
internal readonly string _basicWithoutUserModelText = ReadTestFile("basic_without_users_model.conf"); | ||
internal readonly string _basicWithoutUserPolicyText = ReadTestFile("basic_without_users_policy.csv"); | ||
internal readonly string _basicWithRootModelText = ReadTestFile("basic_with_root_model.conf"); | ||
internal readonly string _ipMatchModelText = ReadTestFile("ipmatch_model.conf"); | ||
internal readonly string _ipMatchPolicyText = ReadTestFile("ipmatch_policy.csv"); | ||
internal readonly string _keyMatch2ModelText = ReadTestFile("keymatch2_model.conf"); | ||
internal readonly string _keyMatch2PolicyText = ReadTestFile("keymatch2_policy.csv"); | ||
internal readonly string _keyMatchCustomModelText = ReadTestFile("keymatch_custom_model.conf"); | ||
internal readonly string _keyMatchModelText = ReadTestFile("keymatch_model.conf"); | ||
internal readonly string _keyMatchPolicyText = ReadTestFile("keymatch_policy.csv"); | ||
|
||
// https://github.com/casbin/Casbin.NET/issues/134 | ||
internal readonly string _multipleTypeModelText = ReadTestFile("multiple_type_model.conf"); | ||
internal readonly string _multipleTypePolicyText = ReadTestFile("multiple_type_policy.csv"); | ||
|
||
// https://github.com/casbin/Casbin.NET/issues/188 | ||
internal readonly string _priorityExplicitDenyOverrideModelText = | ||
ReadTestFile("priority_explicit_deny_override_model.conf"); | ||
|
||
internal readonly string _priorityExplicitDenyOverridePolicyText = | ||
ReadTestFile("priority_explicit_deny_override_policy.csv"); | ||
|
||
internal readonly string _priorityExplicitModelText = ReadTestFile("priority_explicit_model.conf"); | ||
internal readonly string _priorityExplicitPolicyText = ReadTestFile("priority_explicit_policy.csv"); | ||
internal readonly string _priorityIndeterminatePolicyText = ReadTestFile("priority_indeterminate_policy.csv"); | ||
internal readonly string _priorityModelText = ReadTestFile("priority_model.conf"); | ||
internal readonly string _priorityPolicyText = ReadTestFile("priority_policy.csv"); | ||
internal readonly string _rbacModelText = ReadTestFile("rbac_model.conf"); | ||
|
||
// https://github.com/casbin/Casbin.NET/issues/106 | ||
internal readonly string _rbacMultipleEvalModelText = ReadTestFile("rbac_multiple_eval_model.conf"); | ||
internal readonly string _rbacMultipleEvalPolicyText = ReadTestFile("rbac_multiple_eval_policy.csv"); | ||
|
||
// https://github.com/casbin/Casbin.NET/issues/154 | ||
internal readonly string _rbacMultipleModelText = ReadTestFile("rbac_multiple_rolemanager_model.conf"); | ||
internal readonly string _rbacMultiplePolicyText = ReadTestFile("rbac_multiple_rolemanager_policy.csv"); | ||
internal readonly string _rbacPolicyText = ReadTestFile("rbac_policy.csv"); | ||
internal readonly string _rbacWithDenyModelText = ReadTestFile("rbac_with_deny_model.conf"); | ||
internal readonly string _rbacWithDenyPolicyText = ReadTestFile("rbac_with_deny_policy.csv"); | ||
internal readonly string _rbacWithDomainsModelText = ReadTestFile("rbac_with_domains_model.conf"); | ||
internal readonly string _rbacWithDomainsPolicy2Text = ReadTestFile("rbac_with_domains_policy2.csv"); | ||
internal readonly string _rbacWithDomainsPolicyText = ReadTestFile("rbac_with_domains_policy.csv"); | ||
internal readonly string _rbacWithHierarchyPolicyText = ReadTestFile("rbac_with_hierarchy_policy.csv"); | ||
|
||
internal readonly string _rbacWithHierarchyWithDomainsPolicyText = | ||
ReadTestFile("rbac_with_hierarchy_with_domains_policy.csv"); | ||
|
||
internal readonly string _rbacWithNotDenyModelText = ReadTestFile("rbac_with_not_deny_model.conf"); | ||
internal readonly string _rbacWithResourceRoleModelText = ReadTestFile("rbac_with_resource_roles_model.conf"); | ||
|
||
internal readonly string _rbacWithResourceRolePolicyText = ReadTestFile("rbac_with_resource_roles_policy.csv"); | ||
internal readonly string _subjectPriorityModelText = ReadTestFile("subject_priority_model.conf"); | ||
internal readonly string _subjectPriorityPolicyText = ReadTestFile("subject_priority_policy.csv"); | ||
|
||
internal readonly string _subjectPriorityWithDomainModelText = | ||
ReadTestFile("subject_priority_model_with_domain.conf"); | ||
|
||
internal readonly string _subjectPriorityWithDomainPolicyText = | ||
ReadTestFile("subject_priority_policy_with_domain.csv"); | ||
|
||
// https://github.com/casbin/Casbin.NET/issues/229 | ||
internal readonly string _supportCountModelText = ReadTestFile("support_count_model.conf"); | ||
|
||
public IModel GetNewAbacModel() => GetNewTestModel(_abacModelText); | ||
|
||
public IModel GetNewAbacWithEvalModel() => GetNewTestModel(_abacWithEvalModelText, _abacWithEvalPolicyText); | ||
|
||
public IModel GetBasicTestModel() => GetNewTestModel(_basicModelText, _basicPolicyText); | ||
|
||
public IModel GetBasicWithoutResourceTestModel() => | ||
GetNewTestModel(_basicWithoutResourceModelText, _basicWithoutResourcePolicyText); | ||
|
||
public IModel GetBasicWithoutUserTestModel() => | ||
GetNewTestModel(_basicWithoutUserModelText, _basicWithoutUserPolicyText); | ||
|
||
public IModel GetNewKeyMatchTestModel() => GetNewTestModel(_keyMatchModelText, _keyMatchPolicyText); | ||
|
||
public IModel GetNewKeyMatch2TestModel() => GetNewTestModel(_keyMatch2ModelText, _keyMatch2PolicyText); | ||
|
||
public IModel GetNewPriorityTestModel() => GetNewTestModel(_priorityModelText, _priorityPolicyText); | ||
|
||
public IModel GetNewPriorityExplicitTestModel() => | ||
GetNewTestModel(_priorityExplicitModelText, _priorityExplicitPolicyText); | ||
|
||
public IModel GetNewPriorityExplicitDenyOverrideModel() => GetNewTestModel(_priorityExplicitDenyOverrideModelText, | ||
_priorityExplicitDenyOverridePolicyText); | ||
|
||
public IModel GetNewRbacTestModel() => GetNewTestModel(_rbacModelText, _rbacPolicyText); | ||
|
||
public IModel GetNewRbacWithDenyTestModel() => GetNewTestModel(_rbacWithDenyModelText, _rbacWithDenyPolicyText); | ||
|
||
public IModel GetNewRbacWithDomainsTestModel() => | ||
GetNewTestModel(_rbacWithDomainsModelText, _rbacWithDomainsPolicyText); | ||
|
||
public IModel GetNewRbacWithResourceRoleTestModel() => | ||
GetNewTestModel(_rbacWithResourceRoleModelText, _rbacWithResourceRolePolicyText); | ||
|
||
public IModel GetNewMultipleTypeTestModel() => GetNewTestModel(_multipleTypeModelText, _multipleTypePolicyText); | ||
|
||
public static IModel GetNewTestModel(string modelText) => DefaultModel.CreateFromText(modelText); | ||
|
||
public static IModel GetNewTestModel(string modelText, string policyText) => | ||
LoadModelFromMemory(GetNewTestModel(modelText), policyText); | ||
|
||
public static string GetTestFile(string fileName) => Path.Combine("Examples", fileName); | ||
|
||
private static IModel LoadModelFromMemory(IModel model, string policy) | ||
{ | ||
model.ClearPolicy(); | ||
using (MemoryStream ms = new(Encoding.UTF8.GetBytes(policy))) | ||
{ | ||
FileAdapter fileAdapter = new(ms); | ||
fileAdapter.LoadPolicy(model); | ||
} | ||
|
||
model.RefreshPolicyStringSet(); | ||
model.SortPoliciesByPriority(); | ||
return model; | ||
} | ||
|
||
private static string ReadTestFile(string fileName) => File.ReadAllText(GetTestFile(fileName)); | ||
} |
Oops, something went wrong.