You've already forked linux-packaging-mono
acceptance-tests
data
debian
docs
external
ikvm-native
llvm
m4
man
mcs
build
class
Accessibility
Commons.Xml.Relaxng
Cscompmgd
CustomMarshalers
Facades
I18N
IBM.Data.DB2
ICSharpCode.SharpZipLib
Microsoft.Build
Microsoft.Build.Engine
Microsoft.Build.Framework
Microsoft.Build.Tasks
Microsoft.Build.Utilities
Microsoft.CSharp
Microsoft.NuGet.Build.Tasks
Microsoft.VisualC
Microsoft.Web.Infrastructure
MicrosoftAjaxLibrary
Mono.Btls.Interface
Mono.C5
Mono.CSharp
Mono.Cairo
Mono.Cecil
Mono.Cecil.Mdb
Mono.CodeContracts
Mono.CompilerServices.SymbolWriter
Mono.Data.Sqlite
Mono.Data.Tds
Mono.Debugger.Soft
Mono.Http
Mono.Management
Mono.Messaging
Mono.Messaging.RabbitMQ
Mono.Options
Mono.Parallel
Mono.Posix
Mono.Profiler.Log
Mono.Runtime.Tests
Mono.Security
Mono.Security.Win32
Mono.Simd
Mono.Tasklets
Mono.WebBrowser
Mono.XBuild.Tasks
Novell.Directory.Ldap
PEAPI
RabbitMQ.Client
SMDiagnostics
System
System.ComponentModel.Composition.4.5
System.ComponentModel.DataAnnotations
System.Configuration
System.Configuration.Install
System.Core
System.Data
System.Data.DataSetExtensions
System.Data.Entity
System.Data.Linq
System.Data.OracleClient
System.Data.Services
System.Data.Services.Client
System.Deployment
System.Design
System.DirectoryServices
System.DirectoryServices.Protocols
System.Drawing
System.Drawing.Design
System.Dynamic
System.EnterpriseServices
System.IO.Compression
System.IO.Compression.FileSystem
System.IdentityModel
System.IdentityModel.Selectors
System.Json
System.Json.Microsoft
System.Management
System.Messaging
System.Net
System.Net.Http
System.Net.Http.Formatting
System.Net.Http.WebRequest
System.Net.Http.WinHttpHandler
System.Numerics
System.Numerics.Vectors
System.Reactive.Core
System.Reactive.Debugger
System.Reactive.Experimental
System.Reactive.Interfaces
System.Reactive.Linq
System.Reactive.Observable.Aliases
System.Reactive.PlatformServices
System.Reactive.Providers
System.Reactive.Runtime.Remoting
System.Reactive.Windows.Forms
System.Reactive.Windows.Threading
System.Reflection.Context
System.Runtime.Caching
System.Runtime.CompilerServices.Unsafe
System.Runtime.DurableInstancing
System.Runtime.Remoting
System.Runtime.Serialization
System.Runtime.Serialization.Formatters.Soap
System.Security
System.ServiceModel
System.ServiceModel.Activation
System.ServiceModel.Discovery
System.ServiceModel.Internals
System.ServiceModel.Routing
System.ServiceModel.Web
System.ServiceProcess
System.Threading.Tasks.Dataflow
System.Transactions
System.Web
System.Web.Abstractions
System.Web.ApplicationServices
System.Web.DynamicData
System.Web.Extensions
System.Web.Extensions.Design
System.Web.Http
System.Web.Http.SelfHost
System.Web.Http.WebHost
System.Web.Mobile
System.Web.Mvc3
System.Web.Razor
System.Web.RegularExpressions
System.Web.Routing
System.Web.Services
System.Web.WebPages
System.Web.WebPages.Deployment
System.Web.WebPages.Razor
System.Windows
System.Windows.Forms
System.Windows.Forms.DataVisualization
System.Workflow.Activities
System.Workflow.ComponentModel
System.Workflow.Runtime
System.XML
System.Xaml
System.Xml.Linq
System.Xml.Serialization
SystemWebTestShim
WebMatrix.Data
WindowsBase
aot-compiler
corlib
Assembly
CommonCrypto
CoreFoundation
Documentation
LinkerDescriptor
Microsoft.Win32
Mono
Mono.Globalization.Unicode
Mono.Interop
Mono.Security
Mono.Security.Cryptography
Mono.Xml
ReferenceSources
System
System.Configuration.Assemblies
System.Deployment.Internal
System.Diagnostics
System.Diagnostics.SymbolStore
System.Diagnostics.Tracing
System.Globalization
System.IO
System.IO.Enumeration
System.IO.IsolatedStorage
System.Reflection
System.Reflection.Emit
System.Reflection.Metadata
System.Resources
System.Runtime
System.Runtime.CompilerServices
System.Runtime.Hosting
System.Runtime.InteropServices
System.Runtime.InteropServices.RuntimeInformation
System.Runtime.InteropServices.WindowsRuntime
System.Runtime.Remoting
System.Runtime.Remoting.Activation
System.Runtime.Remoting.Channels
System.Runtime.Remoting.Contexts
System.Runtime.Remoting.Lifetime
System.Runtime.Remoting.Messaging
System.Runtime.Remoting.Metadata
System.Runtime.Remoting.Metadata.W3cXsd2001
System.Runtime.Remoting.Proxies
System.Runtime.Remoting.Services
System.Runtime.Versioning
System.Security
System.Security.AccessControl
System.Security.Cryptography
System.Security.Cryptography.X509Certificates
System.Security.Permissions
System.Security.Policy
System.Security.Principal
System.Text
System.Threading
Test
Microsoft.Win32
Mono
System
System.Collections
System.Collections.Concurrent
System.Collections.Generic
System.Collections.ObjectModel
System.Diagnostics
System.Diagnostics.Contracts
System.Globalization
System.IO
System.IO.IsolatedStorage
System.Reflection
System.Reflection.Emit
System.Resources
System.Runtime.CompilerServices
System.Runtime.ExceptionServices
System.Runtime.InteropServices
System.Runtime.Remoting
System.Runtime.Remoting.Channels
System.Runtime.Remoting.Contexts
System.Runtime.Remoting.Messaging
System.Runtime.Remoting.Metadata.W3cXsd2001
System.Runtime.Remoting.Proxies
System.Runtime.Serialization
System.Runtime.Serialization.Formatters.Binary
System.Runtime.Versioning
System.Security
System.Security.AccessControl
AuthorizationRuleTest.cs
CommonAceTest.cs
CommonAclTest.cs
CommonObjectSecurityTest.cs
CommonSecurityDescriptorTest.cs
CryptoKeyAccessRuleTest.cs
DirectoryObjectSecurityTest.cs
DirectorySecurityTest.cs
DiscretionaryAclTest.cs
EventWaitHandleSecurityTest.cs
FileSecurityTest.cs
MutexAccessRuleTest.cs
MutexSecurityTest.cs
ObjectAceTest.cs
ObjectSecurityTest.cs
ObjectSecurity_TTest.cs
RawAclTest.cs
RawSecurityDescriptorTest.cs
RegistrySecurityTest.cs
SystemAclTest.cs
System.Security.Claims
System.Security.Cryptography
System.Security.Cryptography.X509Certificates
System.Security.Permissions
System.Security.Policy
System.Security.Principal
System.Text
System.Threading
System.Threading.Tasks
resources
coreclr
corefx
corert
il
legacy
resources
Makefile
System.IO.platformnotsupported.sources
corlib.dll.sources.REMOVED.git-id
corlib_test.dll.sources
corlib_xtest.dll.sources
linux_build_corlib.dll.exclude.sources
linux_build_corlib.dll.sources
linux_net_4_x_corlib.dll.exclude.sources
linux_net_4_x_corlib.dll.sources
macos_build_corlib.dll.exclude.sources
macos_build_corlib.dll.sources
macos_net_4_x_corlib.dll.exclude.sources
macos_net_4_x_corlib.dll.sources
mobile_tests.exclude.sources
monodroid_corlib.dll.exclude.sources
monodroid_corlib.dll.sources
monodroid_corlib_test.dll.exclude.sources
monodroid_corlib_xtest.dll.exclude.sources
monotouch_corlib.dll.exclude.sources
monotouch_corlib.dll.sources
monotouch_corlib_test.dll.exclude.sources
monotouch_corlib_xtest.dll.exclude.sources
monotouch_runtime_corlib.dll.exclude.sources
monotouch_runtime_corlib.dll.sources
monotouch_tv_corlib.dll.exclude.sources
monotouch_tv_corlib.dll.sources
monotouch_tv_corlib_test.dll.exclude.sources
monotouch_tv_corlib_xtest.dll.exclude.sources
monotouch_tv_runtime_corlib.dll.exclude.sources
monotouch_tv_runtime_corlib.dll.sources
monotouch_watch_corlib.dll.exclude.sources
monotouch_watch_corlib.dll.sources
monotouch_watch_corlib_test.dll.exclude.sources
monotouch_watch_corlib_xtest.dll.exclude.sources
monotouch_watch_runtime_corlib.dll.exclude.sources
monotouch_watch_runtime_corlib.dll.sources
net_4_x_corlib.dll.sources
orbis_corlib.dll.exclude.sources
orbis_corlib.dll.sources
orbis_corlib_test.dll.exclude.sources
testing_aot_common_corlib.dll.exclude.sources
testing_aot_common_corlib.dll.sources
testing_aot_common_corlib_test.dll.exclude.sources
testing_aot_full_corlib.dll.exclude.sources
testing_aot_full_corlib.dll.sources
testing_aot_full_corlib_test.dll.exclude.sources
testing_aot_full_interp_corlib.dll.exclude.sources
testing_aot_full_interp_corlib.dll.sources
testing_aot_full_interp_corlib_test.dll.exclude.sources
testing_aot_hybrid_corlib.dll.exclude.sources
testing_aot_hybrid_corlib.dll.sources
testing_aot_hybrid_corlib_test.dll.exclude.sources
testing_winaot_interp_corlib.dll.exclude.sources
testing_winaot_interp_corlib.dll.sources
testing_winaot_interp_corlib_test.dll.exclude.sources
testing_winaot_interp_corlib_test.dll.sources
unix_build_corlib.dll.exclude.sources
unix_build_corlib.dll.sources
unix_net_4_x_corlib.dll.exclude.sources
unix_net_4_x_corlib.dll.sources
unreal_corlib.dll.exclude.sources
unreal_corlib.dll.sources
wasm_corlib.dll.exclude.sources
wasm_corlib.dll.sources
wasm_corlib_test.dll.exclude.sources
wasm_corlib_xtest.dll.exclude.sources
win32_build_corlib.dll.exclude.sources
win32_build_corlib.dll.sources
win32_monodroid_corlib.dll.exclude.sources
win32_monodroid_corlib.dll.sources
win32_monodroid_corlib_test.dll.exclude.sources
win32_net_4_x_corlib.dll.exclude.sources
win32_net_4_x_corlib.dll.sources
win32_net_4_x_corlib_test.dll.exclude.sources
win32_net_4_x_corlib_test.dll.sources
win32_net_4_x_corlib_xtest.dll.sources
winaot_corlib.dll.exclude.sources
winaot_corlib.dll.sources
winaot_corlib_test.dll.exclude.sources
winaot_corlib_test.dll.sources
xammac_corlib.dll.exclude.sources
xammac_corlib.dll.sources
xammac_corlib_test.dll.exclude.sources
xammac_corlib_xtest.dll.exclude.sources
xammac_net_4_5_corlib.dll.exclude.sources
xammac_net_4_5_corlib.dll.sources
dlr
doc
legacy
lib
monodoc
notes
reference-assemblies
referencesource
test-helpers
LICENSE
Makefile
Open.snk
README
ecma.pub
mono.pub
mono.snk
msfinal.pub
reactive.pub
silverlight.pub
winfx.pub
winfx3.pub
docs
errors
ilasm
jay
mcs
packages
tests
tools
AUTHORS
COPYING
INSTALL.txt
Makefile
MonoIcon.png
README
ScalableMonoIcon.svg
mkinstalldirs
mk
mono
msvc
netcore
po
runtime
samples
scripts
support
tools
COPYING.LIB
LICENSE
Makefile.am
Makefile.in
NEWS
README.md
acinclude.m4
aclocal.m4
autogen.sh
code_of_conduct.md
compile
config.guess
config.h.in
config.rpath
config.sub
configure.REMOVED.git-id
configure.ac.REMOVED.git-id
depcomp
install-sh
ltmain.sh.REMOVED.git-id
missing
mkinstalldirs
mono-uninstalled.pc.in
test-driver
winconfig.h
254 lines
8.5 KiB
C#
254 lines
8.5 KiB
C#
![]() |
// CommonObjectSecurityTest.cs - NUnit Test Cases for CommonObjectSecurity
|
||
|
//
|
||
|
// Authors:
|
||
|
// James Bellinger <jfb@zer7.com>
|
||
|
//
|
||
|
// Copyright (C) 2012 James Bellinger
|
||
|
|
||
|
using System;
|
||
|
using System.Collections.Generic;
|
||
|
using System.Security.AccessControl;
|
||
|
using System.Security.Principal;
|
||
|
using NUnit.Framework;
|
||
|
|
||
|
namespace MonoTests.System.Security.AccessControl
|
||
|
{
|
||
|
[TestFixture]
|
||
|
public class CommonObjectSecurityTest
|
||
|
{
|
||
|
[Test]
|
||
|
public void Defaults ()
|
||
|
{
|
||
|
TestSecurity security;
|
||
|
|
||
|
security = new TestSecurity (false);
|
||
|
Assert.IsFalse (security.IsContainerTest);
|
||
|
Assert.IsFalse (security.IsDSTest);
|
||
|
|
||
|
security = new TestSecurity (true);
|
||
|
Assert.IsTrue (security.IsContainerTest);
|
||
|
Assert.IsFalse (security.IsDSTest);
|
||
|
}
|
||
|
|
||
|
[Test]
|
||
|
public void AddAndGetAccessRulesWorkAndMergeCorrectly ()
|
||
|
{
|
||
|
var security = new TestSecurity (false);
|
||
|
|
||
|
// CommonObjectSecurity does not appear to care at all about types on MS.NET.
|
||
|
// It just uses AccessMask, and then GetAccessRules uses the factory methods.
|
||
|
// So, the whole API is a mess of strong typing and repeated code backed by nothing.
|
||
|
Assert.IsFalse (security.modify_access_called);
|
||
|
|
||
|
SecurityIdentifier sid = new SecurityIdentifier (WellKnownSidType.WorldSid, null);
|
||
|
security.AddAccessRuleTest (new TestAccessRule<int> (sid, 2, AccessControlType.Allow));
|
||
|
security.AddAccessRuleTest (new TestAccessRule<TestRights> (sid, TestRights.One, AccessControlType.Allow));
|
||
|
security.AddAccessRuleTest (new TestAccessRule<int> (sid, 4, AccessControlType.Allow));
|
||
|
|
||
|
Assert.IsTrue (security.modify_access_called);
|
||
|
Assert.IsFalse (security.modify_access_rule_called);
|
||
|
Assert.IsFalse (security.modify_audit_called);
|
||
|
|
||
|
Assert.IsFalse (security.access_rule_factory_called);
|
||
|
AuthorizationRuleCollection rules1 = security.GetAccessRules (false, true, typeof (SecurityIdentifier));
|
||
|
Assert.IsFalse (security.access_rule_factory_called);
|
||
|
Assert.AreEqual (0, rules1.Count);
|
||
|
|
||
|
Assert.IsFalse (security.access_rule_factory_called);
|
||
|
AuthorizationRuleCollection rules2 = security.GetAccessRules (true, true, typeof (SecurityIdentifier));
|
||
|
Assert.IsTrue (security.access_rule_factory_called);
|
||
|
Assert.AreEqual (1, rules2.Count);
|
||
|
|
||
|
Assert.IsInstanceOfType (typeof (TestAccessRule<TestRights>), rules2[0]);
|
||
|
TestAccessRule<TestRights> rule = (TestAccessRule<TestRights>)rules2[0];
|
||
|
Assert.AreEqual ((TestRights)7, rule.Rights);
|
||
|
}
|
||
|
|
||
|
[Test]
|
||
|
public void AddAndPurgeWorks ()
|
||
|
{
|
||
|
TestSecurity security = new TestSecurity (false);
|
||
|
|
||
|
NTAccount nta1 = new NTAccount(@"BUILTIN\Users");
|
||
|
NTAccount nta2 = new NTAccount(@"BUILTIN\Administrators");
|
||
|
security.AddAccessRuleTest (new TestAccessRule<TestRights> (nta1, TestRights.One,
|
||
|
AccessControlType.Allow));
|
||
|
security.AddAccessRuleTest (new TestAccessRule<TestRights> (nta2, TestRights.One,
|
||
|
AccessControlType.Allow));
|
||
|
|
||
|
AuthorizationRuleCollection rules1 = security.GetAccessRules (true, true, typeof (NTAccount));
|
||
|
Assert.AreEqual (2, rules1.Count);
|
||
|
|
||
|
security.PurgeAccessRules (nta1);
|
||
|
AuthorizationRuleCollection rules2 = security.GetAccessRules (true, true, typeof (NTAccount));
|
||
|
Assert.AreEqual (1, rules2.Count);
|
||
|
Assert.IsInstanceOfType (typeof (TestAccessRule<TestRights>), rules2[0]);
|
||
|
TestAccessRule<TestRights> rule = (TestAccessRule<TestRights>)rules2[0];
|
||
|
Assert.AreEqual (nta2, rule.IdentityReference);
|
||
|
}
|
||
|
|
||
|
[Test]
|
||
|
public void ResetAccessRuleCausesExactlyOneModifyAccessCall ()
|
||
|
{
|
||
|
TestSecurity security = new TestSecurity (false);
|
||
|
SecurityIdentifier sid = new SecurityIdentifier ("WD");
|
||
|
security.ResetAccessRuleTest (new TestAccessRule<TestRights> (sid, TestRights.One,
|
||
|
AccessControlType.Allow));
|
||
|
Assert.AreEqual (1, security.modify_access_called_count);
|
||
|
}
|
||
|
|
||
|
class TestAccessRule<T> : AccessRule
|
||
|
{
|
||
|
public TestAccessRule (IdentityReference identity, T rules,
|
||
|
AccessControlType type)
|
||
|
: this (identity, rules, InheritanceFlags.None, PropagationFlags.None, type)
|
||
|
{
|
||
|
}
|
||
|
|
||
|
public TestAccessRule (IdentityReference identity, T rules,
|
||
|
InheritanceFlags inheritanceFlags, PropagationFlags propagationFlags,
|
||
|
AccessControlType type)
|
||
|
: base (identity, (int)(object)rules, false, inheritanceFlags, propagationFlags, type)
|
||
|
{
|
||
|
}
|
||
|
|
||
|
public T Rights {
|
||
|
get { return (T)(object)AccessMask; }
|
||
|
}
|
||
|
}
|
||
|
|
||
|
class TestAuditRule<T> : AuditRule
|
||
|
{
|
||
|
public TestAuditRule (IdentityReference identity, T rules,
|
||
|
InheritanceFlags inheritanceFlags, PropagationFlags propagationFlags,
|
||
|
AuditFlags auditFlags)
|
||
|
: base (identity, (int)(object)rules, false, inheritanceFlags, propagationFlags, auditFlags)
|
||
|
{
|
||
|
}
|
||
|
}
|
||
|
|
||
|
enum TestRights
|
||
|
{
|
||
|
One = 1
|
||
|
}
|
||
|
|
||
|
class TestSecurity : CommonObjectSecurity
|
||
|
{
|
||
|
public bool access_rule_factory_called;
|
||
|
public bool audit_rule_factory_called;
|
||
|
public bool modify_access_called;
|
||
|
public int modify_access_called_count;
|
||
|
public bool modify_access_rule_called;
|
||
|
public bool modify_audit_called;
|
||
|
public bool modify_audit_rule_called;
|
||
|
|
||
|
public TestSecurity (bool isContainer)
|
||
|
: base (isContainer)
|
||
|
{
|
||
|
}
|
||
|
|
||
|
public bool IsContainerTest {
|
||
|
get { return IsContainer; }
|
||
|
}
|
||
|
|
||
|
public bool IsDSTest {
|
||
|
get { return IsDS; }
|
||
|
}
|
||
|
|
||
|
public void AddAccessRuleTest (AccessRule rule)
|
||
|
{
|
||
|
AddAccessRule (rule);
|
||
|
}
|
||
|
|
||
|
public void AddAuditRuleTest (AuditRule rule)
|
||
|
{
|
||
|
AddAuditRule (rule);
|
||
|
}
|
||
|
|
||
|
public bool RemoveAccessRuleTest (AccessRule rule)
|
||
|
{
|
||
|
return RemoveAccessRule (rule);
|
||
|
}
|
||
|
|
||
|
public void RemoveAccessRuleAllTest (AccessRule rule)
|
||
|
{
|
||
|
RemoveAccessRuleAll (rule);
|
||
|
}
|
||
|
|
||
|
public void RemoveAccessRuleSpecificTest (AccessRule rule)
|
||
|
{
|
||
|
RemoveAccessRuleSpecific (rule);
|
||
|
}
|
||
|
|
||
|
public void ResetAccessRuleTest (AccessRule rule)
|
||
|
{
|
||
|
ResetAccessRule (rule);
|
||
|
}
|
||
|
|
||
|
public override AccessRule AccessRuleFactory (IdentityReference identityReference,
|
||
|
int accessMask, bool isInherited,
|
||
|
InheritanceFlags inheritanceFlags,
|
||
|
PropagationFlags propagationFlags,
|
||
|
AccessControlType type)
|
||
|
{
|
||
|
access_rule_factory_called = true;
|
||
|
return new TestAccessRule<TestRights> (identityReference, (TestRights)accessMask,
|
||
|
inheritanceFlags, propagationFlags, type);
|
||
|
}
|
||
|
|
||
|
public override AuditRule AuditRuleFactory (IdentityReference identityReference,
|
||
|
int accessMask, bool isInherited,
|
||
|
InheritanceFlags inheritanceFlags,
|
||
|
PropagationFlags propagationFlags,
|
||
|
AuditFlags flags)
|
||
|
{
|
||
|
audit_rule_factory_called = true;
|
||
|
return new TestAuditRule<TestRights> (identityReference, (TestRights)accessMask,
|
||
|
inheritanceFlags, propagationFlags, flags);
|
||
|
}
|
||
|
|
||
|
public override bool ModifyAccessRule (AccessControlModification modification,
|
||
|
AccessRule rule, out bool modified)
|
||
|
{
|
||
|
modify_access_rule_called = true;
|
||
|
return base.ModifyAccessRule (modification, rule, out modified);
|
||
|
}
|
||
|
|
||
|
protected override bool ModifyAccess (AccessControlModification modification,
|
||
|
AccessRule rule, out bool modified)
|
||
|
{
|
||
|
modify_access_called = true;
|
||
|
modify_access_called_count ++;
|
||
|
return base.ModifyAccess (modification, rule, out modified);
|
||
|
}
|
||
|
|
||
|
public override bool ModifyAuditRule (AccessControlModification modification,
|
||
|
AuditRule rule, out bool modified)
|
||
|
{
|
||
|
modify_audit_rule_called = true;
|
||
|
return base.ModifyAuditRule (modification, rule, out modified);
|
||
|
}
|
||
|
|
||
|
protected override bool ModifyAudit (AccessControlModification modification,
|
||
|
AuditRule rule, out bool modified)
|
||
|
{
|
||
|
modify_audit_called = true;
|
||
|
return base.ModifyAudit (modification, rule, out modified);
|
||
|
}
|
||
|
|
||
|
public override Type AccessRightType {
|
||
|
get { return typeof (TestRights); }
|
||
|
}
|
||
|
|
||
|
public override Type AccessRuleType {
|
||
|
get { return typeof (TestAccessRule<TestRights>); }
|
||
|
}
|
||
|
|
||
|
public override Type AuditRuleType {
|
||
|
get { return typeof (TestAuditRule<TestRights>); }
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|